]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* modules/m_tb.c |
55abcbb2 | 2 | * |
212380e3 AC |
3 | * Copyright (C) 2003 Lee Hardy <lee@leeh.co.uk> |
4 | * Copyright (C) 2003-2005 ircd-ratbox development team | |
5 | * | |
6 | * Redistribution and use in source and binary forms, with or without | |
7 | * modification, are permitted provided that the following conditions are | |
8 | * met: | |
9 | * | |
10 | * 1.Redistributions of source code must retain the above copyright notice, | |
11 | * this list of conditions and the following disclaimer. | |
12 | * 2.Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | |
15 | * 3.The name of the author may not be used to endorse or promote products | |
16 | * derived from this software without specific prior written permission. | |
17 | * | |
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | |
22 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |
26 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | |
27 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
28 | * POSSIBILITY OF SUCH DAMAGE. | |
212380e3 AC |
29 | */ |
30 | ||
31 | #include "stdinc.h" | |
212380e3 AC |
32 | #include "send.h" |
33 | #include "channel.h" | |
34 | #include "client.h" | |
35 | #include "common.h" | |
36 | #include "config.h" | |
37 | #include "ircd.h" | |
4562c604 | 38 | #include "match.h" |
212380e3 AC |
39 | #include "s_conf.h" |
40 | #include "msg.h" | |
41 | #include "modules.h" | |
42 | #include "hash.h" | |
43 | #include "s_serv.h" | |
44 | ||
be9c3979 AW |
45 | static const char tb_desc[] = |
46 | "Provides TS6 TB and ETB commands for topic bursting between servers"; | |
212380e3 | 47 | |
3c7d6fcc EM |
48 | static void ms_tb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); |
49 | static void ms_etb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
eeabf33a | 50 | |
212380e3 | 51 | struct Message tb_msgtab = { |
7baa37a9 | 52 | "TB", 0, 0, 0, 0, |
212380e3 AC |
53 | {mg_unreg, mg_ignore, mg_ignore, {ms_tb, 4}, mg_ignore, mg_ignore} |
54 | }; | |
55 | ||
2ae93813 | 56 | struct Message etb_msgtab = { |
7baa37a9 | 57 | "ETB", 0, 0, 0, 0, |
2ae93813 JT |
58 | {mg_unreg, mg_ignore, {ms_etb, 5}, {ms_etb, 5}, mg_ignore, mg_ignore} |
59 | }; | |
60 | ||
61 | mapi_clist_av1 tb_clist[] = { &tb_msgtab, &etb_msgtab, NULL }; | |
be9c3979 | 62 | DECLARE_MODULE_AV2(tb, NULL, NULL, tb_clist, NULL, NULL, NULL, NULL, tb_desc); |
212380e3 AC |
63 | |
64 | /* m_tb() | |
65 | * | |
66 | * parv[1] - channel | |
67 | * parv[2] - topic ts | |
68 | * parv[3] - optional topicwho/topic | |
69 | * parv[4] - topic | |
70 | */ | |
3c7d6fcc | 71 | static void |
428ca87b | 72 | ms_tb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
73 | { |
74 | struct Channel *chptr; | |
75 | const char *newtopic; | |
76 | const char *newtopicwho; | |
77 | time_t newtopicts; | |
78 | struct Client *fakesource_p; | |
79 | ||
80 | chptr = find_channel(parv[1]); | |
81 | ||
82 | if(chptr == NULL) | |
3c7d6fcc | 83 | return; |
212380e3 AC |
84 | |
85 | newtopicts = atol(parv[2]); | |
86 | ||
87 | /* Hide connecting server on netburst -- jilles */ | |
88 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
89 | fakesource_p = &me; | |
90 | else | |
91 | fakesource_p = source_p; | |
92 | ||
93 | if(parc == 5) | |
94 | { | |
95 | newtopic = parv[4]; | |
96 | newtopicwho = parv[3]; | |
97 | } | |
98 | else | |
99 | { | |
100 | newtopic = parv[3]; | |
101 | newtopicwho = fakesource_p->name; | |
102 | } | |
103 | ||
104 | if (EmptyString(newtopic)) | |
3c7d6fcc | 105 | return; |
212380e3 AC |
106 | |
107 | if(chptr->topic == NULL || chptr->topic_time > newtopicts) | |
108 | { | |
109 | /* its possible the topicts is a few seconds out on some | |
110 | * servers, due to lag when propagating it, so if theyre the | |
111 | * same topic just drop the message --fl | |
112 | */ | |
113 | if(chptr->topic != NULL && strcmp(chptr->topic, newtopic) == 0) | |
3c7d6fcc | 114 | return; |
212380e3 AC |
115 | |
116 | set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); | |
117 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", | |
118 | fakesource_p->name, chptr->chname, newtopic); | |
119 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, NOCAPS, | |
120 | ":%s TB %s %ld %s%s:%s", | |
121 | use_id(source_p), chptr->chname, (long) chptr->topic_time, | |
122 | ConfigChannel.burst_topicwho ? chptr->topic_info : "", | |
123 | ConfigChannel.burst_topicwho ? " " : "", chptr->topic); | |
212380e3 | 124 | } |
212380e3 | 125 | } |
2ae93813 JT |
126 | |
127 | /* ms_etb() | |
128 | * | |
129 | * parv[1] - channel ts | |
130 | * parv[2] - channel | |
131 | * parv[3] - topic ts | |
132 | * parv[4] - topicwho | |
133 | * parv[5] - topic | |
134 | */ | |
3c7d6fcc | 135 | static void |
428ca87b | 136 | ms_etb(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
2ae93813 JT |
137 | { |
138 | struct Channel *chptr; | |
139 | const char *newtopic; | |
140 | const char *newtopicwho; | |
141 | time_t channelts, newtopicts; | |
142 | struct Client *fakesource_p, *source_server_p; | |
143 | int textchange, can_use_tb, member; | |
144 | ||
145 | channelts = atol(parv[1]); | |
146 | chptr = find_channel(parv[2]); | |
147 | ||
148 | if(chptr == NULL) | |
3c7d6fcc | 149 | return; |
2ae93813 JT |
150 | |
151 | newtopicts = atol(parv[3]); | |
152 | ||
153 | /* Hide connecting server on netburst -- jilles */ | |
154 | if (IsServer(source_p) && ConfigServerHide.flatten_links && | |
155 | !HasSentEob(source_p)) | |
156 | fakesource_p = &me; | |
157 | else | |
158 | fakesource_p = source_p; | |
159 | ||
160 | newtopicwho = parv[4]; | |
161 | newtopic = parv[parc - 1]; | |
162 | ||
163 | if(chptr->topic == NULL || chptr->channelts > channelts || | |
164 | (chptr->channelts == channelts && chptr->topic_time < newtopicts)) | |
165 | { | |
166 | textchange = chptr->topic == NULL || strcmp(chptr->topic, newtopic); | |
167 | can_use_tb = textchange && !EmptyString(newtopic) && | |
168 | (chptr->topic == NULL || chptr->topic_time > newtopicts); | |
169 | ||
170 | set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); | |
171 | newtopic = chptr->topic ? chptr->topic : ""; | |
172 | if (chptr->topic_info) | |
173 | newtopicwho = chptr->topic_info; | |
174 | ||
175 | /* Do not send a textually identical topic to clients, | |
176 | * but do propagate the new topicts/topicwho to servers. | |
177 | */ | |
178 | if(textchange) | |
f4d319c7 JT |
179 | { |
180 | if (IsPerson(fakesource_p)) | |
181 | sendto_channel_local(ALL_MEMBERS, chptr, | |
182 | ":%s!%s@%s TOPIC %s :%s", | |
183 | fakesource_p->name, | |
184 | fakesource_p->username, | |
185 | fakesource_p->host, | |
186 | chptr->chname, | |
187 | newtopic); | |
188 | else | |
189 | sendto_channel_local(ALL_MEMBERS, chptr, | |
190 | ":%s TOPIC %s :%s", | |
191 | fakesource_p->name, | |
192 | chptr->chname, newtopic); | |
193 | } | |
2ae93813 JT |
194 | /* Propagate channelts as given, because an older channelts |
195 | * forces any change. | |
196 | */ | |
197 | sendto_server(client_p, chptr, CAP_EOPMOD|CAP_TS6, NOCAPS, | |
198 | ":%s ETB %ld %s %ld %s :%s", | |
199 | use_id(source_p), (long)channelts, chptr->chname, | |
200 | (long)newtopicts, newtopicwho, newtopic); | |
201 | source_server_p = IsServer(source_p) ? source_p : source_p->servptr; | |
202 | if (can_use_tb) | |
203 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, | |
204 | ":%s TB %s %ld %s :%s", | |
205 | use_id(source_server_p), | |
206 | chptr->chname, (long)newtopicts, | |
207 | newtopicwho, newtopic); | |
208 | else if (IsPerson(source_p) && textchange) | |
209 | { | |
210 | member = IsMember(source_p, chptr); | |
211 | if (!member) | |
212 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
213 | ":%s SJOIN %ld %s + :@%s", | |
214 | use_id(source_server_p), | |
215 | (long)chptr->channelts, | |
216 | chptr->chname, use_id(source_p)); | |
217 | if (EmptyString(newtopic) || | |
218 | newtopicts >= rb_current_time() - 60) | |
219 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
220 | ":%s TOPIC %s :%s", | |
221 | use_id(source_p), | |
222 | chptr->chname, newtopic); | |
223 | else | |
224 | { | |
225 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
226 | ":%s TOPIC %s :%s", | |
227 | use_id(source_p), | |
228 | chptr->chname, ""); | |
229 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, | |
230 | ":%s TB %s %ld %s :%s", | |
231 | use_id(source_server_p), | |
232 | chptr->chname, (long)newtopicts, | |
233 | newtopicwho, newtopic); | |
234 | } | |
235 | if (!member) | |
236 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
237 | ":%s PART %s :Topic set for %s", | |
238 | use_id(source_p), | |
239 | chptr->chname, newtopicwho); | |
240 | } | |
241 | else if (textchange) | |
242 | { | |
243 | /* Should not send :server ETB if not all servers | |
244 | * support EOPMOD. | |
245 | */ | |
246 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
247 | ":%s NOTICE %s :*** Notice -- Dropping topic change for %s", | |
248 | me.id, chptr->chname, chptr->chname); | |
249 | } | |
250 | } | |
2ae93813 | 251 | } |