| 1 |
/* modules/m_tburst.c |
| 2 |
* Copyright (C) 2002, 2003, 2004, 2005 Hybrid Development Team |
| 3 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions are |
| 6 |
* met: |
| 7 |
* |
| 8 |
* 1.Redistributions of source code must retain the above copyright notice, |
| 9 |
* this list of conditions and the following disclaimer. |
| 10 |
* 2.Redistributions in binary form must reproduce the above copyright |
| 11 |
* notice, this list of conditions and the following disclaimer in the |
| 12 |
* documentation and/or other materials provided with the distribution. |
| 13 |
* 3.The name of the author may not be used to endorse or promote products |
| 14 |
* derived from this software without specific prior written permission. |
| 15 |
* |
| 16 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 20 |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 24 |
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 25 |
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 26 |
* POSSIBILITY OF SUCH DAMAGE. |
| 27 |
* |
| 28 |
* $Id: m_tb.c,v 1.25 2005/06/23 16:04:39 michael Exp $ |
| 29 |
*/ |
| 30 |
|
| 31 |
#include "stdinc.h" |
| 32 |
#include "handlers.h" |
| 33 |
#include "client.h" |
| 34 |
#include "common.h" |
| 35 |
#include "ircd.h" |
| 36 |
#include "send.h" |
| 37 |
#include "msg.h" |
| 38 |
#include "modules.h" |
| 39 |
#include "hook.h" |
| 40 |
#include "hash.h" |
| 41 |
#include "s_serv.h" |
| 42 |
#include "s_conf.h" |
| 43 |
|
| 44 |
|
| 45 |
static void ms_tburst(struct Client *, struct Client *, int, char *[]); |
| 46 |
static void set_topic(struct Client *, struct Channel *, time_t, char *, char *); |
| 47 |
int send_tburst(struct hook_burst_channel *); |
| 48 |
|
| 49 |
struct Message tburst_msgtab = { |
| 50 |
"TBURST", 0, 0, 6, 0, MFLG_SLOW, 0, |
| 51 |
{m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore} |
| 52 |
}; |
| 53 |
|
| 54 |
#ifndef STATIC_MODULES |
| 55 |
void |
| 56 |
_modinit(void) |
| 57 |
{ |
| 58 |
mod_add_cmd(&tburst_msgtab); |
| 59 |
hook_add_hook("burst_channel", (hookfn *)send_tburst); |
| 60 |
add_capability("TBURST", CAP_TBURST, 1); |
| 61 |
} |
| 62 |
|
| 63 |
void |
| 64 |
_moddeinit(void) |
| 65 |
{ |
| 66 |
mod_del_cmd(&tburst_msgtab); |
| 67 |
hook_del_hook("burst_channel", (hookfn *)send_tburst); |
| 68 |
delete_capability("TBURST"); |
| 69 |
} |
| 70 |
|
| 71 |
const char *_version = "$Revision: 1.25 $"; |
| 72 |
#endif /* !STATIC_MODULES */ |
| 73 |
|
| 74 |
|
| 75 |
/* ms_tburst() |
| 76 |
* |
| 77 |
* parv[0] = sender prefix |
| 78 |
* parv[1] = channel timestamp |
| 79 |
* parv[2] = channel |
| 80 |
* parv[3] = topic timestamp |
| 81 |
* parv[4] = topic setter |
| 82 |
* parv[5] = topic |
| 83 |
*/ |
| 84 |
static void |
| 85 |
ms_tburst(struct Client *client_p, struct Client *source_p, |
| 86 |
int parc, char *parv[]) |
| 87 |
{ |
| 88 |
struct Channel *chptr; |
| 89 |
time_t oldchannelts = atol(parv[1]); |
| 90 |
time_t oldtopicts = atol(parv[3]); |
| 91 |
|
| 92 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
| 93 |
return; |
| 94 |
|
| 95 |
/* If the topics are the same (due to lag) ignore it */ |
| 96 |
if ((chptr->topic != NULL) && !strcmp(chptr->topic, parv[5])) |
| 97 |
return; |
| 98 |
|
| 99 |
/* Only allow topic change if we are the newer TS and server |
| 100 |
* sending TBURST has older TS and topicTS on older TS is |
| 101 |
* newer than current topicTS. -metalrock |
| 102 |
*/ |
| 103 |
if ((oldchannelts <= chptr->channelts) && |
| 104 |
((chptr->topic == NULL) || (oldtopicts > chptr->topic_time))) |
| 105 |
set_topic(source_p, chptr, oldtopicts, parv[4], parv[5]); |
| 106 |
} |
| 107 |
|
| 108 |
static void |
| 109 |
set_topic(struct Client *source_p, struct Channel *chptr, |
| 110 |
time_t oldtopicts, char *topicwho, char *topic) |
| 111 |
{ |
| 112 |
set_channel_topic(chptr, topic, topicwho, oldtopicts); |
| 113 |
|
| 114 |
sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", |
| 115 |
ConfigServerHide.hide_servers ? me.name : source_p->name, |
| 116 |
chptr->chname, chptr->topic == NULL ? "" : chptr->topic); |
| 117 |
|
| 118 |
sendto_server(source_p, NULL, chptr, CAP_TBURST, NOCAPS, NOFLAGS, |
| 119 |
":%s TBURST %lu %s %lu %s :%s", |
| 120 |
me.name, (unsigned long)chptr->channelts, chptr->chname, |
| 121 |
(unsigned long)chptr->topic_time, |
| 122 |
chptr->topic_info == NULL ? "" : chptr->topic_info, |
| 123 |
chptr->topic == NULL ? "" : chptr->topic); |
| 124 |
} |
| 125 |
|
| 126 |
int |
| 127 |
send_tburst(struct hook_burst_channel *data) |
| 128 |
{ |
| 129 |
if (data->chptr->topic != NULL && IsCapable(data->client, CAP_TBURST)) |
| 130 |
sendto_one(data->client, ":%s TBURST %lu %s %lu %s :%s", |
| 131 |
me.name, (unsigned long)data->chptr->channelts, data->chptr->chname, |
| 132 |
(unsigned long)data->chptr->topic_time, data->chptr->topic_info, |
| 133 |
data->chptr->topic); |
| 134 |
return(0); |
| 135 |
} |