]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* modules/m_tb.c |
2 | * | |
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. | |
29 | * | |
30 | * $Id: m_tb.c 1349 2006-05-17 17:37:46Z jilles $ | |
31 | */ | |
32 | ||
33 | #include "stdinc.h" | |
212380e3 AC |
34 | #include "send.h" |
35 | #include "channel.h" | |
36 | #include "client.h" | |
37 | #include "common.h" | |
38 | #include "config.h" | |
39 | #include "ircd.h" | |
4562c604 | 40 | #include "match.h" |
212380e3 AC |
41 | #include "s_conf.h" |
42 | #include "msg.h" | |
43 | #include "modules.h" | |
44 | #include "hash.h" | |
45 | #include "s_serv.h" | |
46 | ||
47 | static int ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
2ae93813 | 48 | static int ms_etb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); |
212380e3 AC |
49 | |
50 | struct Message tb_msgtab = { | |
51 | "TB", 0, 0, 0, MFLG_SLOW, | |
52 | {mg_unreg, mg_ignore, mg_ignore, {ms_tb, 4}, mg_ignore, mg_ignore} | |
53 | }; | |
54 | ||
2ae93813 JT |
55 | struct Message etb_msgtab = { |
56 | "ETB", 0, 0, 0, MFLG_SLOW, | |
57 | {mg_unreg, mg_ignore, {ms_etb, 5}, {ms_etb, 5}, mg_ignore, mg_ignore} | |
58 | }; | |
59 | ||
60 | mapi_clist_av1 tb_clist[] = { &tb_msgtab, &etb_msgtab, NULL }; | |
212380e3 AC |
61 | DECLARE_MODULE_AV1(tb, NULL, NULL, tb_clist, NULL, NULL, "$Revision: 1349 $"); |
62 | ||
63 | /* m_tb() | |
64 | * | |
65 | * parv[1] - channel | |
66 | * parv[2] - topic ts | |
67 | * parv[3] - optional topicwho/topic | |
68 | * parv[4] - topic | |
69 | */ | |
70 | static int | |
71 | ms_tb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
72 | { | |
73 | struct Channel *chptr; | |
74 | const char *newtopic; | |
75 | const char *newtopicwho; | |
76 | time_t newtopicts; | |
77 | struct Client *fakesource_p; | |
78 | ||
79 | chptr = find_channel(parv[1]); | |
80 | ||
81 | if(chptr == NULL) | |
82 | return 0; | |
83 | ||
84 | newtopicts = atol(parv[2]); | |
85 | ||
86 | /* Hide connecting server on netburst -- jilles */ | |
87 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
88 | fakesource_p = &me; | |
89 | else | |
90 | fakesource_p = source_p; | |
91 | ||
92 | if(parc == 5) | |
93 | { | |
94 | newtopic = parv[4]; | |
95 | newtopicwho = parv[3]; | |
96 | } | |
97 | else | |
98 | { | |
99 | newtopic = parv[3]; | |
100 | newtopicwho = fakesource_p->name; | |
101 | } | |
102 | ||
103 | if (EmptyString(newtopic)) | |
104 | return 0; | |
105 | ||
106 | if(chptr->topic == NULL || chptr->topic_time > newtopicts) | |
107 | { | |
108 | /* its possible the topicts is a few seconds out on some | |
109 | * servers, due to lag when propagating it, so if theyre the | |
110 | * same topic just drop the message --fl | |
111 | */ | |
112 | if(chptr->topic != NULL && strcmp(chptr->topic, newtopic) == 0) | |
113 | return 0; | |
114 | ||
115 | set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); | |
116 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s TOPIC %s :%s", | |
117 | fakesource_p->name, chptr->chname, newtopic); | |
118 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, NOCAPS, | |
119 | ":%s TB %s %ld %s%s:%s", | |
120 | use_id(source_p), chptr->chname, (long) chptr->topic_time, | |
121 | ConfigChannel.burst_topicwho ? chptr->topic_info : "", | |
122 | ConfigChannel.burst_topicwho ? " " : "", chptr->topic); | |
212380e3 AC |
123 | } |
124 | ||
125 | return 0; | |
126 | } | |
2ae93813 JT |
127 | |
128 | /* ms_etb() | |
129 | * | |
130 | * parv[1] - channel ts | |
131 | * parv[2] - channel | |
132 | * parv[3] - topic ts | |
133 | * parv[4] - topicwho | |
134 | * parv[5] - topic | |
135 | */ | |
136 | static int | |
137 | ms_etb(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
138 | { | |
139 | struct Channel *chptr; | |
140 | const char *newtopic; | |
141 | const char *newtopicwho; | |
142 | time_t channelts, newtopicts; | |
143 | struct Client *fakesource_p, *source_server_p; | |
144 | int textchange, can_use_tb, member; | |
145 | ||
146 | channelts = atol(parv[1]); | |
147 | chptr = find_channel(parv[2]); | |
148 | ||
149 | if(chptr == NULL) | |
150 | return 0; | |
151 | ||
152 | newtopicts = atol(parv[3]); | |
153 | ||
154 | /* Hide connecting server on netburst -- jilles */ | |
155 | if (IsServer(source_p) && ConfigServerHide.flatten_links && | |
156 | !HasSentEob(source_p)) | |
157 | fakesource_p = &me; | |
158 | else | |
159 | fakesource_p = source_p; | |
160 | ||
161 | newtopicwho = parv[4]; | |
162 | newtopic = parv[parc - 1]; | |
163 | ||
164 | if(chptr->topic == NULL || chptr->channelts > channelts || | |
165 | (chptr->channelts == channelts && chptr->topic_time < newtopicts)) | |
166 | { | |
167 | textchange = chptr->topic == NULL || strcmp(chptr->topic, newtopic); | |
168 | can_use_tb = textchange && !EmptyString(newtopic) && | |
169 | (chptr->topic == NULL || chptr->topic_time > newtopicts); | |
170 | ||
171 | set_channel_topic(chptr, newtopic, newtopicwho, newtopicts); | |
172 | newtopic = chptr->topic ? chptr->topic : ""; | |
173 | if (chptr->topic_info) | |
174 | newtopicwho = chptr->topic_info; | |
175 | ||
176 | /* Do not send a textually identical topic to clients, | |
177 | * but do propagate the new topicts/topicwho to servers. | |
178 | */ | |
179 | if(textchange) | |
f4d319c7 JT |
180 | { |
181 | if (IsPerson(fakesource_p)) | |
182 | sendto_channel_local(ALL_MEMBERS, chptr, | |
183 | ":%s!%s@%s TOPIC %s :%s", | |
184 | fakesource_p->name, | |
185 | fakesource_p->username, | |
186 | fakesource_p->host, | |
187 | chptr->chname, | |
188 | newtopic); | |
189 | else | |
190 | sendto_channel_local(ALL_MEMBERS, chptr, | |
191 | ":%s TOPIC %s :%s", | |
192 | fakesource_p->name, | |
193 | chptr->chname, newtopic); | |
194 | } | |
2ae93813 JT |
195 | /* Propagate channelts as given, because an older channelts |
196 | * forces any change. | |
197 | */ | |
198 | sendto_server(client_p, chptr, CAP_EOPMOD|CAP_TS6, NOCAPS, | |
199 | ":%s ETB %ld %s %ld %s :%s", | |
200 | use_id(source_p), (long)channelts, chptr->chname, | |
201 | (long)newtopicts, newtopicwho, newtopic); | |
202 | source_server_p = IsServer(source_p) ? source_p : source_p->servptr; | |
203 | if (can_use_tb) | |
204 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, | |
205 | ":%s TB %s %ld %s :%s", | |
206 | use_id(source_server_p), | |
207 | chptr->chname, (long)newtopicts, | |
208 | newtopicwho, newtopic); | |
209 | else if (IsPerson(source_p) && textchange) | |
210 | { | |
211 | member = IsMember(source_p, chptr); | |
212 | if (!member) | |
213 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
214 | ":%s SJOIN %ld %s + :@%s", | |
215 | use_id(source_server_p), | |
216 | (long)chptr->channelts, | |
217 | chptr->chname, use_id(source_p)); | |
218 | if (EmptyString(newtopic) || | |
219 | newtopicts >= rb_current_time() - 60) | |
220 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
221 | ":%s TOPIC %s :%s", | |
222 | use_id(source_p), | |
223 | chptr->chname, newtopic); | |
224 | else | |
225 | { | |
226 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
227 | ":%s TOPIC %s :%s", | |
228 | use_id(source_p), | |
229 | chptr->chname, ""); | |
230 | sendto_server(client_p, chptr, CAP_TB|CAP_TS6, CAP_EOPMOD, | |
231 | ":%s TB %s %ld %s :%s", | |
232 | use_id(source_server_p), | |
233 | chptr->chname, (long)newtopicts, | |
234 | newtopicwho, newtopic); | |
235 | } | |
236 | if (!member) | |
237 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
238 | ":%s PART %s :Topic set for %s", | |
239 | use_id(source_p), | |
240 | chptr->chname, newtopicwho); | |
241 | } | |
242 | else if (textchange) | |
243 | { | |
244 | /* Should not send :server ETB if not all servers | |
245 | * support EOPMOD. | |
246 | */ | |
247 | sendto_server(client_p, chptr, CAP_TS6, CAP_EOPMOD, | |
248 | ":%s NOTICE %s :*** Notice -- Dropping topic change for %s", | |
249 | me.id, chptr->chname, chptr->chname); | |
250 | } | |
251 | } | |
252 | ||
253 | return 0; | |
254 | } |