1 |
michael |
325 |
/* 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 |
michael |
335 |
* $Id$ |
29 |
michael |
325 |
*/ |
30 |
|
|
|
31 |
|
|
#include "stdinc.h" |
32 |
|
|
#include "client.h" |
33 |
|
|
#include "ircd.h" |
34 |
|
|
#include "send.h" |
35 |
|
|
#include "modules.h" |
36 |
|
|
#include "hash.h" |
37 |
|
|
#include "s_serv.h" |
38 |
michael |
1309 |
#include "conf.h" |
39 |
michael |
1243 |
#include "parse.h" |
40 |
michael |
325 |
|
41 |
|
|
|
42 |
|
|
/* ms_tburst() |
43 |
|
|
* |
44 |
|
|
* parv[0] = sender prefix |
45 |
|
|
* parv[1] = channel timestamp |
46 |
|
|
* parv[2] = channel |
47 |
|
|
* parv[3] = topic timestamp |
48 |
|
|
* parv[4] = topic setter |
49 |
|
|
* parv[5] = topic |
50 |
|
|
*/ |
51 |
|
|
static void |
52 |
|
|
ms_tburst(struct Client *client_p, struct Client *source_p, |
53 |
|
|
int parc, char *parv[]) |
54 |
|
|
{ |
55 |
|
|
struct Channel *chptr = NULL; |
56 |
michael |
336 |
int accept_remote = 0; |
57 |
|
|
time_t remote_channel_ts = atol(parv[1]); |
58 |
|
|
time_t remote_topic_ts = atol(parv[3]); |
59 |
michael |
1486 |
const char *topic = parv[5]; |
60 |
|
|
const char *setby = parv[4]; |
61 |
michael |
325 |
|
62 |
michael |
336 |
/* |
63 |
|
|
* Do NOT test parv[5] for an empty string and return if true! |
64 |
|
|
* parv[5] CAN be an empty string, i.e. if the other side wants |
65 |
|
|
* to unset our topic. Don't forget: an empty topic is also a |
66 |
|
|
* valid topic. |
67 |
|
|
*/ |
68 |
|
|
|
69 |
|
|
|
70 |
michael |
325 |
if ((chptr = hash_find_channel(parv[2])) == NULL) |
71 |
|
|
return; |
72 |
|
|
|
73 |
michael |
336 |
/* |
74 |
|
|
* The logic for accepting and rejecting channel topics was |
75 |
|
|
* always a bit hairy, so now we got exactly 2 cases where |
76 |
|
|
* we would accept a bursted topic |
77 |
|
|
* |
78 |
|
|
* Case 1: |
79 |
|
|
* The TS of the remote channel is older than ours |
80 |
|
|
* Case 2: |
81 |
|
|
* The TS of the remote channel is equal to ours AND |
82 |
|
|
* the TS of the remote topic is newer than ours |
83 |
michael |
325 |
*/ |
84 |
michael |
1485 |
if (HasFlag(source_p, FLAGS_SERVICE)) |
85 |
michael |
336 |
accept_remote = 1; |
86 |
michael |
1485 |
else if (remote_channel_ts < chptr->channelts) |
87 |
|
|
accept_remote = 1; |
88 |
michael |
336 |
else if (remote_channel_ts == chptr->channelts) |
89 |
|
|
if (remote_topic_ts > chptr->topic_time) |
90 |
|
|
accept_remote = 1; |
91 |
|
|
|
92 |
|
|
if (accept_remote) |
93 |
|
|
{ |
94 |
michael |
1487 |
int topic_differs = strncmp(chptr->topic, topic, sizeof(chptr->topic) - 1); |
95 |
michael |
1615 |
int hidden_server = (ConfigServerHide.hide_servers || IsHidden(source_p)); |
96 |
michael |
1487 |
|
97 |
michael |
1751 |
set_channel_topic(chptr, topic, setby, remote_topic_ts, !!MyClient(source_p)); |
98 |
michael |
336 |
|
99 |
michael |
1615 |
sendto_server(source_p, CAP_TBURST|CAP_TS6, NOCAPS, |
100 |
|
|
":%s TBURST %s %s %s %s :%s", |
101 |
|
|
ID(source_p), parv[1], parv[2], parv[3], setby, topic); |
102 |
|
|
sendto_server(source_p, CAP_TBURST, CAP_TS6, |
103 |
|
|
":%s TBURST %s %s %s %s :%s", |
104 |
|
|
source_p->name, parv[1], parv[2], parv[3], setby, topic); |
105 |
|
|
|
106 |
michael |
1487 |
if (topic_differs) |
107 |
michael |
1243 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, ":%s TOPIC %s :%s", |
108 |
michael |
1615 |
hidden_server ? me.name : source_p->name, |
109 |
michael |
1203 |
chptr->chname, chptr->topic); |
110 |
michael |
336 |
} |
111 |
michael |
325 |
} |
112 |
|
|
|
113 |
michael |
1230 |
static struct Message tburst_msgtab = { |
114 |
michael |
1486 |
"TBURST", 0, 0, 6, MAXPARA, MFLG_SLOW, 0, |
115 |
michael |
1230 |
{ m_ignore, m_ignore, ms_tburst, m_ignore, m_ignore, m_ignore } |
116 |
|
|
}; |
117 |
|
|
|
118 |
michael |
325 |
static void |
119 |
michael |
1230 |
module_init(void) |
120 |
michael |
325 |
{ |
121 |
michael |
1230 |
mod_add_cmd(&tburst_msgtab); |
122 |
|
|
add_capability("TBURST", CAP_TBURST, 1); |
123 |
|
|
} |
124 |
michael |
325 |
|
125 |
michael |
1230 |
static void |
126 |
|
|
module_exit(void) |
127 |
|
|
{ |
128 |
|
|
mod_del_cmd(&tburst_msgtab); |
129 |
|
|
delete_capability("TBURST"); |
130 |
michael |
325 |
} |
131 |
michael |
1230 |
|
132 |
|
|
struct module module_entry = { |
133 |
|
|
.node = { NULL, NULL, NULL }, |
134 |
|
|
.name = NULL, |
135 |
|
|
.version = "$Revision$", |
136 |
|
|
.handle = NULL, |
137 |
|
|
.modinit = module_init, |
138 |
|
|
.modexit = module_exit, |
139 |
|
|
.flags = 0 |
140 |
|
|
}; |