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