]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful ircd. | |
3 | * m_join.c: Joins a channel. | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or | |
12 | * (at your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | * GNU General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
22 | * USA | |
212380e3 AC |
23 | */ |
24 | ||
25 | #include "stdinc.h" | |
212380e3 AC |
26 | #include "channel.h" |
27 | #include "client.h" | |
28 | #include "common.h" | |
29 | #include "hash.h" | |
4562c604 | 30 | #include "match.h" |
212380e3 AC |
31 | #include "ircd.h" |
32 | #include "numeric.h" | |
33 | #include "send.h" | |
34 | #include "s_serv.h" | |
35 | #include "s_conf.h" | |
36 | #include "s_newconf.h" | |
37 | #include "msg.h" | |
38 | #include "parse.h" | |
39 | #include "modules.h" | |
212380e3 | 40 | #include "packet.h" |
acdf71d9 | 41 | #include "chmode.h" |
7e132ff0 | 42 | #include "ratelimit.h" |
77d3d2db | 43 | #include "s_assert.h" |
212380e3 | 44 | |
eeabf33a EM |
45 | static const char join_desc[] = "Provides the JOIN and TS6 SJOIN commands to facilitate joining and creating channels"; |
46 | ||
3c7d6fcc EM |
47 | static void m_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **); |
48 | static void ms_join(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
49 | static void ms_sjoin(struct MsgBuf *, struct Client *, struct Client *, int, const char **); | |
212380e3 AC |
50 | |
51 | static int h_can_create_channel; | |
52 | static int h_channel_join; | |
53 | ||
54 | struct Message join_msgtab = { | |
7baa37a9 | 55 | "JOIN", 0, 0, 0, 0, |
212380e3 AC |
56 | {mg_unreg, {m_join, 2}, {ms_join, 2}, mg_ignore, mg_ignore, {m_join, 2}} |
57 | }; | |
58 | ||
8cc12805 | 59 | struct Message sjoin_msgtab = { |
7baa37a9 | 60 | "SJOIN", 0, 0, 0, 0, |
1766edef | 61 | {mg_unreg, mg_ignore, mg_ignore, {ms_sjoin, 4}, mg_ignore, mg_ignore} |
8cc12805 VY |
62 | }; |
63 | ||
64 | mapi_clist_av1 join_clist[] = { &join_msgtab, &sjoin_msgtab, NULL }; | |
212380e3 AC |
65 | |
66 | mapi_hlist_av1 join_hlist[] = { | |
67 | { "can_create_channel", &h_can_create_channel }, | |
68 | { "channel_join", &h_channel_join }, | |
69 | { NULL, NULL }, | |
70 | }; | |
71 | ||
823ab528 | 72 | DECLARE_MODULE_AV2(join, NULL, NULL, join_clist, join_hlist, NULL, NULL, NULL, join_desc); |
212380e3 | 73 | |
f4a80ce6 | 74 | static void do_join_0(struct Client *client_p, struct Client *source_p); |
3c7d6fcc | 75 | static bool check_channel_name_loc(struct Client *source_p, const char *name); |
35bfe0e6 | 76 | static void send_join_error(struct Client *source_p, int numeric, const char *name); |
212380e3 AC |
77 | |
78 | static void set_final_mode(struct Mode *mode, struct Mode *oldmode); | |
79 | static void remove_our_modes(struct Channel *chptr, struct Client *source_p); | |
80 | ||
8cc12805 | 81 | static void remove_ban_list(struct Channel *chptr, struct Client *source_p, |
8afeb720 | 82 | rb_dlink_list * list, char c, int mems); |
8cc12805 | 83 | |
212380e3 AC |
84 | static char modebuf[MODEBUFLEN]; |
85 | static char parabuf[MODEBUFLEN]; | |
8cc12805 | 86 | static const char *para[MAXMODEPARAMS]; |
212380e3 | 87 | static char *mbuf; |
8cc12805 | 88 | static int pargs; |
212380e3 AC |
89 | |
90 | /* Check what we will forward to, without sending any notices to the user | |
91 | * -- jilles | |
92 | */ | |
93 | static struct Channel * | |
94 | check_forward(struct Client *source_p, struct Channel *chptr, | |
765d839d | 95 | char *key, int *err) |
212380e3 AC |
96 | { |
97 | int depth = 0, i; | |
d9af501a | 98 | const char *next = NULL; |
765d839d EM |
99 | |
100 | /* The caller (m_join) is only interested in the reason | |
101 | * for the original channel. | |
102 | */ | |
103 | if ((*err = can_join(source_p, chptr, key, &next)) == 0) | |
104 | return chptr; | |
212380e3 | 105 | |
6a85e665 JT |
106 | /* User is +Q, or forwarding disabled */ |
107 | if (IsNoForward(source_p) || !ConfigChannel.use_forward) | |
212380e3 AC |
108 | return NULL; |
109 | ||
110 | while (depth < 16) | |
111 | { | |
97532cfa JT |
112 | if (next == NULL) |
113 | return NULL; | |
765d839d | 114 | chptr = find_channel(next); |
212380e3 AC |
115 | /* Can only forward to existing channels */ |
116 | if (chptr == NULL) | |
117 | return NULL; | |
118 | /* Already on there, show original error message */ | |
119 | if (IsMember(source_p, chptr)) | |
120 | return NULL; | |
121 | /* Juped. Sending a warning notice would be unfair */ | |
122 | if (hash_find_resv(chptr->chname)) | |
123 | return NULL; | |
124 | /* Don't forward to +Q channel */ | |
125 | if (chptr->mode.mode & MODE_DISFORWARD) | |
126 | return NULL; | |
765d839d | 127 | i = can_join(source_p, chptr, key, &next); |
212380e3 AC |
128 | if (i == 0) |
129 | return chptr; | |
212380e3 AC |
130 | depth++; |
131 | } | |
132 | ||
133 | return NULL; | |
134 | } | |
135 | ||
136 | /* | |
137 | * m_join | |
212380e3 AC |
138 | * parv[1] = channel |
139 | * parv[2] = channel password (key) | |
140 | */ | |
3c7d6fcc | 141 | static void |
428ca87b | 142 | m_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
143 | { |
144 | static char jbuf[BUFSIZE]; | |
765d839d | 145 | struct Channel *chptr = NULL, *chptr2 = NULL; |
212380e3 AC |
146 | struct ConfItem *aconf; |
147 | char *name; | |
148 | char *key = NULL; | |
095efcf0 | 149 | const char *modes; |
212380e3 AC |
150 | int i, flags = 0; |
151 | char *p = NULL, *p2 = NULL; | |
152 | char *chanlist; | |
153 | char *mykey; | |
212380e3 AC |
154 | |
155 | jbuf[0] = '\0'; | |
156 | ||
157 | /* rebuild the list of channels theyre supposed to be joining. | |
158 | * this code has a side effect of losing keys, but.. | |
159 | */ | |
160 | chanlist = LOCAL_COPY(parv[1]); | |
4a2651e5 | 161 | for(name = rb_strtok_r(chanlist, ",", &p); name; name = rb_strtok_r(NULL, ",", &p)) |
212380e3 AC |
162 | { |
163 | /* check the length and name of channel is ok */ | |
164 | if(!check_channel_name_loc(source_p, name) || (strlen(name) > LOC_CHANNELLEN)) | |
165 | { | |
166 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
167 | form_str(ERR_BADCHANNAME), (unsigned char *) name); | |
168 | continue; | |
169 | } | |
170 | ||
f4a80ce6 JT |
171 | /* join 0 parts all channels */ |
172 | if(*name == '0' && (name[1] == ',' || name[1] == '\0') && name == chanlist) | |
173 | { | |
174 | (void) strcpy(jbuf, "0"); | |
175 | continue; | |
176 | } | |
177 | ||
212380e3 | 178 | /* check it begins with # or &, and local chans are disabled */ |
341f971e SB |
179 | else if(!IsChannelName(name) || |
180 | ( ConfigChannel.disable_local_channels && name[0] == '&')) | |
212380e3 AC |
181 | { |
182 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
183 | form_str(ERR_NOSUCHCHANNEL), name); | |
184 | continue; | |
185 | } | |
186 | ||
187 | /* see if its resv'd */ | |
188 | if(!IsExemptResv(source_p) && (aconf = hash_find_resv(name))) | |
189 | { | |
190 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
191 | form_str(ERR_BADCHANNAME), name); | |
192 | ||
193 | /* dont warn for opers */ | |
194 | if(!IsExemptJupe(source_p) && !IsOper(source_p)) | |
195 | sendto_realops_snomask(SNO_SPY, L_NETWIDE, | |
196 | "User %s (%s@%s) is attempting to join locally juped channel %s (%s)", | |
197 | source_p->name, source_p->username, | |
63aecfb9 | 198 | source_p->orighost, name, aconf->passwd); |
212380e3 AC |
199 | /* dont update tracking for jupe exempt users, these |
200 | * are likely to be spamtrap leaves | |
201 | */ | |
202 | else if(IsExemptJupe(source_p)) | |
203 | aconf->port--; | |
204 | ||
205 | continue; | |
206 | } | |
207 | ||
208 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
209 | ConfigChannel.no_join_on_split) | |
210 | { | |
211 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
212 | me.name, source_p->name, name); | |
213 | continue; | |
214 | } | |
215 | ||
216 | if(*jbuf) | |
217 | (void) strcat(jbuf, ","); | |
1f9de103 | 218 | (void) rb_strlcat(jbuf, name, sizeof(jbuf)); |
212380e3 AC |
219 | } |
220 | ||
221 | if(parc > 2) | |
222 | { | |
223 | mykey = LOCAL_COPY(parv[2]); | |
4a2651e5 | 224 | key = rb_strtok_r(mykey, ",", &p2); |
212380e3 AC |
225 | } |
226 | ||
4a2651e5 VY |
227 | for(name = rb_strtok_r(jbuf, ",", &p); name; |
228 | key = (key) ? rb_strtok_r(NULL, ",", &p2) : NULL, name = rb_strtok_r(NULL, ",", &p)) | |
212380e3 AC |
229 | { |
230 | hook_data_channel_activity hook_info; | |
231 | ||
f4a80ce6 JT |
232 | /* JOIN 0 simply parts all channels the user is in */ |
233 | if(*name == '0' && !atoi(name)) | |
234 | { | |
235 | if(source_p->user->channel.head == NULL) | |
236 | continue; | |
237 | ||
238 | do_join_0(&me, source_p); | |
239 | continue; | |
240 | } | |
241 | ||
212380e3 AC |
242 | /* look for the channel */ |
243 | if((chptr = find_channel(name)) != NULL) | |
244 | { | |
245 | if(IsMember(source_p, chptr)) | |
246 | continue; | |
247 | ||
248 | flags = 0; | |
249 | } | |
250 | else | |
251 | { | |
252 | hook_data_client_approval moduledata; | |
253 | ||
254 | moduledata.client = source_p; | |
255 | moduledata.approved = 0; | |
256 | ||
257 | call_hook(h_can_create_channel, &moduledata); | |
258 | ||
544cde90 | 259 | if(moduledata.approved != 0) |
212380e3 | 260 | { |
35bfe0e6 JT |
261 | if(moduledata.approved != ERR_CUSTOM) |
262 | send_join_error(source_p, | |
263 | moduledata.approved, | |
264 | name); | |
212380e3 AC |
265 | continue; |
266 | } | |
267 | ||
268 | if(splitmode && !IsOper(source_p) && (*name != '&') && | |
269 | ConfigChannel.no_create_on_split) | |
270 | { | |
271 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
272 | me.name, source_p->name, name); | |
273 | continue; | |
274 | } | |
275 | ||
276 | flags = CHFL_CHANOP; | |
277 | } | |
278 | ||
5b96d9a6 | 279 | if((rb_dlink_list_length(&source_p->user->channel) >= |
212380e3 | 280 | (unsigned long) ConfigChannel.max_chans_per_user) && |
a4721f5e | 281 | (!IsExtendChans(source_p) || |
5b96d9a6 | 282 | (rb_dlink_list_length(&source_p->user->channel) >= |
a4721f5e | 283 | (unsigned long) ConfigChannel.max_chans_per_user_large))) |
212380e3 AC |
284 | { |
285 | sendto_one(source_p, form_str(ERR_TOOMANYCHANNELS), | |
286 | me.name, source_p->name, name); | |
cddbab51 | 287 | continue; |
212380e3 AC |
288 | } |
289 | ||
212380e3 AC |
290 | if(chptr == NULL) /* If I already have a chptr, no point doing this */ |
291 | { | |
292 | chptr = get_or_create_channel(source_p, name, NULL); | |
293 | ||
294 | if(chptr == NULL) | |
295 | { | |
296 | sendto_one(source_p, form_str(ERR_UNAVAILRESOURCE), | |
297 | me.name, source_p->name, name); | |
212380e3 AC |
298 | continue; |
299 | } | |
300 | } | |
301 | ||
765d839d EM |
302 | /* If check_forward returns NULL, they couldn't join and there wasn't a usable forward channel. */ |
303 | if(!(chptr2 = check_forward(source_p, chptr, key, &i))) | |
212380e3 | 304 | { |
765d839d EM |
305 | /* might be wrong, but is there any other better location for such? |
306 | * see extensions/chm_operonly.c for other comments on this | |
307 | * -- dwr | |
308 | */ | |
309 | if(i != ERR_CUSTOM) | |
35bfe0e6 | 310 | send_join_error(source_p, i, name); |
765d839d | 311 | continue; |
212380e3 | 312 | } |
765d839d EM |
313 | else if(chptr != chptr2) |
314 | sendto_one_numeric(source_p, ERR_LINKCHANNEL, form_str(ERR_LINKCHANNEL), name, chptr2->chname); | |
315 | ||
316 | chptr = chptr2; | |
212380e3 | 317 | |
ff91faaf JT |
318 | if(flags == 0 && |
319 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
cf3564d6 JT |
320 | check_spambot_warning(source_p, name); |
321 | ||
212380e3 AC |
322 | /* add the user to the channel */ |
323 | add_user_to_channel(chptr, source_p, flags); | |
324 | if (chptr->mode.join_num && | |
e3354945 | 325 | rb_current_time() - chptr->join_delta >= chptr->mode.join_time) |
212380e3 AC |
326 | { |
327 | chptr->join_count = 0; | |
e3354945 | 328 | chptr->join_delta = rb_current_time(); |
212380e3 AC |
329 | } |
330 | chptr->join_count++; | |
331 | ||
7e132ff0 KB |
332 | /* credit user for join */ |
333 | credit_client_join(source_p); | |
334 | ||
212380e3 AC |
335 | /* we send the user their join here, because we could have to |
336 | * send a mode out next. | |
337 | */ | |
805cfa5a | 338 | send_channel_join(chptr, source_p); |
212380e3 AC |
339 | |
340 | /* its a new channel, set +nt and burst. */ | |
341 | if(flags & CHFL_CHANOP) | |
342 | { | |
e3354945 | 343 | chptr->channelts = rb_current_time(); |
63eb8567 | 344 | chptr->mode.mode |= ConfigChannel.autochanmodes; |
095efcf0 | 345 | modes = channel_modes(chptr, &me); |
212380e3 | 346 | |
095efcf0 JT |
347 | sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s", |
348 | me.name, chptr->chname, modes); | |
212380e3 | 349 | |
db2545b1 JT |
350 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
351 | ":%s SJOIN %ld %s %s :@%s", | |
352 | me.id, (long) chptr->channelts, | |
353 | chptr->chname, modes, source_p->id); | |
212380e3 AC |
354 | } |
355 | else | |
356 | { | |
212380e3 | 357 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
bee3b671 | 358 | ":%s JOIN %ld %s +", |
212380e3 | 359 | use_id(source_p), (long) chptr->channelts, |
bee3b671 | 360 | chptr->chname); |
212380e3 AC |
361 | } |
362 | ||
363 | del_invite(chptr, source_p); | |
364 | ||
365 | if(chptr->topic != NULL) | |
366 | { | |
367 | sendto_one(source_p, form_str(RPL_TOPIC), me.name, | |
368 | source_p->name, chptr->chname, chptr->topic); | |
369 | ||
370 | sendto_one(source_p, form_str(RPL_TOPICWHOTIME), | |
371 | me.name, source_p->name, chptr->chname, | |
0cce01d3 JT |
372 | chptr->topic_info, |
373 | (unsigned long)chptr->topic_time); | |
212380e3 AC |
374 | } |
375 | ||
376 | channel_member_names(chptr, source_p, 1); | |
377 | ||
212380e3 AC |
378 | hook_info.client = source_p; |
379 | hook_info.chptr = chptr; | |
380 | hook_info.key = key; | |
381 | call_hook(h_channel_join, &hook_info); | |
382 | } | |
212380e3 AC |
383 | } |
384 | ||
385 | /* | |
386 | * ms_join | |
35835646 JT |
387 | * parv[1] = channel TS |
388 | * parv[2] = channel | |
389 | * parv[3] = "+", formerly channel modes but now unused | |
390 | * alternatively, a single "0" parameter parts all channels | |
212380e3 | 391 | */ |
3c7d6fcc | 392 | static void |
428ca87b | 393 | ms_join(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
212380e3 AC |
394 | { |
395 | struct Channel *chptr; | |
bee3b671 | 396 | static struct Mode mode; |
212380e3 AC |
397 | time_t oldts; |
398 | time_t newts; | |
399 | int isnew; | |
3c7d6fcc | 400 | bool keep_our_modes = true; |
637c4932 | 401 | rb_dlink_node *ptr, *next_ptr; |
212380e3 | 402 | |
f4a80ce6 JT |
403 | /* special case for join 0 */ |
404 | if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2) | |
405 | { | |
406 | do_join_0(client_p, source_p); | |
3c7d6fcc | 407 | return; |
f4a80ce6 JT |
408 | } |
409 | ||
212380e3 | 410 | if(parc < 4) |
3c7d6fcc | 411 | return; |
212380e3 AC |
412 | |
413 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) | |
3c7d6fcc | 414 | return; |
212380e3 AC |
415 | |
416 | /* joins for local channels cant happen. */ | |
417 | if(parv[2][0] == '&') | |
3c7d6fcc | 418 | return; |
212380e3 AC |
419 | |
420 | mbuf = modebuf; | |
421 | mode.key[0] = mode.forward[0] = '\0'; | |
422 | mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
423 | ||
212380e3 | 424 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) |
3c7d6fcc | 425 | return; |
212380e3 AC |
426 | |
427 | newts = atol(parv[1]); | |
428 | oldts = chptr->channelts; | |
212380e3 AC |
429 | |
430 | #ifdef IGNORE_BOGUS_TS | |
431 | if(newts < 800000000) | |
432 | { | |
433 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
434 | "*** Bogus TS %ld on %s ignored from %s", | |
435 | (long) newts, chptr->chname, client_p->name); | |
436 | newts = (oldts == 0) ? oldts : 800000000; | |
437 | } | |
438 | #else | |
439 | /* making a channel TS0 */ | |
440 | if(!isnew && !newts && oldts) | |
441 | { | |
442 | sendto_channel_local(ALL_MEMBERS, chptr, | |
443 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0", | |
444 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
445 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
446 | "Server %s changing TS on %s from %ld to 0", | |
447 | source_p->name, chptr->chname, (long) oldts); | |
448 | } | |
449 | #endif | |
450 | ||
451 | if(isnew) | |
452 | chptr->channelts = newts; | |
453 | else if(newts == 0 || oldts == 0) | |
454 | chptr->channelts = 0; | |
455 | else if(newts == oldts) | |
456 | ; | |
457 | else if(newts < oldts) | |
458 | { | |
3c7d6fcc | 459 | keep_our_modes = false; |
212380e3 AC |
460 | chptr->channelts = newts; |
461 | } | |
212380e3 | 462 | |
212380e3 AC |
463 | /* Lost the TS, other side wins, so remove modes on this side */ |
464 | if(!keep_our_modes) | |
465 | { | |
bee3b671 JT |
466 | set_final_mode(&mode, &chptr->mode); |
467 | chptr->mode = mode; | |
212380e3 | 468 | remove_our_modes(chptr, source_p); |
637c4932 | 469 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) |
212380e3 AC |
470 | { |
471 | del_invite(chptr, ptr->data); | |
472 | } | |
bee3b671 JT |
473 | /* If setting -j, clear join throttle state -- jilles */ |
474 | chptr->join_count = chptr->join_delta = 0; | |
212380e3 AC |
475 | sendto_channel_local(ALL_MEMBERS, chptr, |
476 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", | |
477 | me.name, chptr->chname, chptr->chname, | |
478 | (long) oldts, (long) newts); | |
1117fbd3 JT |
479 | /* Update capitalization in channel name, this makes the |
480 | * capitalization timestamped like modes are -- jilles */ | |
481 | strcpy(chptr->chname, parv[2]); | |
bee3b671 JT |
482 | if(*modebuf != '\0') |
483 | sendto_channel_local(ALL_MEMBERS, chptr, | |
484 | ":%s MODE %s %s %s", | |
485 | source_p->servptr->name, | |
486 | chptr->chname, modebuf, parabuf); | |
487 | *modebuf = *parabuf = '\0'; | |
6fb6bd15 AC |
488 | |
489 | /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ | |
07554369 | 490 | set_channel_mlock(client_p, source_p, chptr, NULL, false); |
212380e3 AC |
491 | } |
492 | ||
212380e3 AC |
493 | if(!IsMember(source_p, chptr)) |
494 | { | |
495 | add_user_to_channel(chptr, source_p, CHFL_PEON); | |
496 | if (chptr->mode.join_num && | |
e3354945 | 497 | rb_current_time() - chptr->join_delta >= chptr->mode.join_time) |
212380e3 AC |
498 | { |
499 | chptr->join_count = 0; | |
e3354945 | 500 | chptr->join_delta = rb_current_time(); |
212380e3 AC |
501 | } |
502 | chptr->join_count++; | |
805cfa5a | 503 | send_channel_join(chptr, source_p); |
212380e3 AC |
504 | } |
505 | ||
212380e3 | 506 | sendto_server(client_p, chptr, CAP_TS6, NOCAPS, |
bee3b671 JT |
507 | ":%s JOIN %ld %s +", |
508 | source_p->id, (long) chptr->channelts, chptr->chname); | |
212380e3 AC |
509 | } |
510 | ||
3c7d6fcc | 511 | static void |
428ca87b | 512 | ms_sjoin(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) |
8cc12805 | 513 | { |
8cc12805 VY |
514 | static char buf_uid[BUFSIZE]; |
515 | static const char empty_modes[] = "0"; | |
516 | struct Channel *chptr; | |
517 | struct Client *target_p, *fakesource_p; | |
518 | time_t newts; | |
519 | time_t oldts; | |
520 | static struct Mode mode, *oldmode; | |
521 | const char *modes; | |
522 | int args = 0; | |
3c7d6fcc EM |
523 | bool keep_our_modes = true; |
524 | bool keep_new_modes = true; | |
8cc12805 VY |
525 | int fl; |
526 | int isnew; | |
890423fb | 527 | int mlen_uid; |
8cc12805 VY |
528 | int len_uid; |
529 | int len; | |
530 | int joins = 0; | |
531 | const char *s; | |
8cc12805 VY |
532 | char *ptr_uid; |
533 | char *p; | |
534 | int i, joinc = 0, timeslice = 0; | |
535 | static char empty[] = ""; | |
536 | rb_dlink_node *ptr, *next_ptr; | |
537 | ||
b733b9fa | 538 | if(parc < 5) |
3c7d6fcc | 539 | return; |
b733b9fa | 540 | |
8cc12805 | 541 | if(!IsChannelName(parv[2]) || !check_channel_name(parv[2])) |
3c7d6fcc | 542 | return; |
8cc12805 VY |
543 | |
544 | /* SJOIN's for local channels can't happen. */ | |
545 | if(*parv[2] == '&') | |
3c7d6fcc | 546 | return; |
8cc12805 VY |
547 | |
548 | modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0'; | |
549 | pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0; | |
550 | ||
551 | /* Hide connecting server on netburst -- jilles */ | |
552 | if (ConfigServerHide.flatten_links && !HasSentEob(source_p)) | |
553 | fakesource_p = &me; | |
554 | else | |
555 | fakesource_p = source_p; | |
556 | ||
557 | mbuf = modebuf; | |
558 | newts = atol(parv[1]); | |
559 | ||
560 | s = parv[3]; | |
561 | while (*s) | |
562 | { | |
563 | switch (*(s++)) | |
564 | { | |
8cc12805 | 565 | case 'f': |
f427c8b0 | 566 | rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward)); |
8cc12805 VY |
567 | args++; |
568 | if(parc < 5 + args) | |
3c7d6fcc | 569 | return; |
8cc12805 VY |
570 | break; |
571 | case 'j': | |
572 | sscanf(parv[4 + args], "%d:%d", &joinc, ×lice); | |
573 | args++; | |
574 | mode.join_num = joinc; | |
575 | mode.join_time = timeslice; | |
576 | if(parc < 5 + args) | |
3c7d6fcc | 577 | return; |
8cc12805 VY |
578 | break; |
579 | case 'k': | |
f427c8b0 | 580 | rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key)); |
8cc12805 VY |
581 | args++; |
582 | if(parc < 5 + args) | |
3c7d6fcc | 583 | return; |
8cc12805 VY |
584 | break; |
585 | case 'l': | |
586 | mode.limit = atoi(parv[4 + args]); | |
587 | args++; | |
588 | if(parc < 5 + args) | |
3c7d6fcc | 589 | return; |
8cc12805 | 590 | break; |
efccc22c VY |
591 | default: |
592 | if(chmode_flags[(int) *s] != 0) | |
593 | { | |
594 | mode.mode |= chmode_flags[(int) *s]; | |
595 | } | |
8cc12805 VY |
596 | } |
597 | } | |
598 | ||
599 | if(parv[args + 4]) | |
600 | { | |
601 | s = parv[args + 4]; | |
602 | ||
603 | /* remove any leading spaces */ | |
604 | while (*s == ' ') | |
605 | s++; | |
606 | } | |
607 | else | |
608 | s = ""; | |
609 | ||
610 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
3c7d6fcc | 611 | return; /* channel name too long? */ |
8cc12805 VY |
612 | |
613 | ||
614 | oldts = chptr->channelts; | |
615 | oldmode = &chptr->mode; | |
616 | ||
617 | #ifdef IGNORE_BOGUS_TS | |
618 | if(newts < 800000000) | |
619 | { | |
620 | sendto_realops_snomask(SNO_DEBUG, L_ALL, | |
621 | "*** Bogus TS %ld on %s ignored from %s", | |
622 | (long) newts, chptr->chname, client_p->name); | |
623 | ||
624 | newts = (oldts == 0) ? oldts : 800000000; | |
625 | } | |
626 | #else | |
627 | if(!isnew && !newts && oldts) | |
628 | { | |
629 | sendto_channel_local(ALL_MEMBERS, chptr, | |
630 | ":%s NOTICE %s :*** Notice -- TS for %s " | |
631 | "changed from %ld to 0", | |
632 | me.name, chptr->chname, chptr->chname, (long) oldts); | |
633 | sendto_realops_snomask(SNO_GENERAL, L_ALL, | |
634 | "Server %s changing TS on %s from %ld to 0", | |
635 | source_p->name, chptr->chname, (long) oldts); | |
636 | } | |
637 | #endif | |
638 | ||
639 | if(isnew) | |
640 | chptr->channelts = newts; | |
55abcbb2 | 641 | |
8cc12805 VY |
642 | else if(newts == 0 || oldts == 0) |
643 | chptr->channelts = 0; | |
644 | else if(newts == oldts) | |
645 | ; | |
646 | else if(newts < oldts) | |
647 | { | |
648 | /* If configured, kick people trying to join +i/+k | |
649 | * channels by recreating them on split servers. | |
a1574df4 JT |
650 | * If the source has sent EOB, assume this is some |
651 | * sort of hack by services. If cmode +i is set, | |
652 | * services can send kicks if needed; if the key | |
653 | * differs, services cannot kick in a race-free | |
654 | * manner so do so here. | |
8cc12805 VY |
655 | * -- jilles */ |
656 | if (ConfigChannel.kick_on_split_riding && | |
a1574df4 JT |
657 | ((!HasSentEob(source_p) && |
658 | mode.mode & MODE_INVITEONLY) || | |
8cc12805 VY |
659 | (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0))) |
660 | { | |
661 | struct membership *msptr; | |
662 | struct Client *who; | |
663 | int l = rb_dlink_list_length(&chptr->members); | |
8cc12805 VY |
664 | |
665 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head) | |
666 | { | |
667 | msptr = ptr->data; | |
668 | who = msptr->client_p; | |
669 | sendto_one(who, ":%s KICK %s %s :Net Rider", | |
670 | me.name, chptr->chname, who->name); | |
671 | ||
672 | sendto_server(NULL, chptr, CAP_TS6, NOCAPS, | |
673 | ":%s KICK %s %s :Net Rider", | |
674 | me.id, chptr->chname, | |
675 | who->id); | |
8cc12805 VY |
676 | remove_user_from_channel(msptr); |
677 | if (--l == 0) | |
678 | break; | |
679 | } | |
680 | if (l == 0) | |
681 | { | |
682 | /* Channel was emptied, create a new one */ | |
683 | if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL) | |
3c7d6fcc | 684 | return; /* oops! */ |
8cc12805 | 685 | |
8cc12805 VY |
686 | oldmode = &chptr->mode; |
687 | } | |
688 | } | |
3c7d6fcc | 689 | keep_our_modes = false; |
8cc12805 VY |
690 | chptr->channelts = newts; |
691 | } | |
692 | else | |
3c7d6fcc | 693 | keep_new_modes = false; |
8cc12805 VY |
694 | |
695 | if(!keep_new_modes) | |
696 | mode = *oldmode; | |
697 | else if(keep_our_modes) | |
698 | { | |
699 | mode.mode |= oldmode->mode; | |
700 | if(oldmode->limit > mode.limit) | |
701 | mode.limit = oldmode->limit; | |
702 | if(strcmp(mode.key, oldmode->key) < 0) | |
703 | strcpy(mode.key, oldmode->key); | |
704 | if(oldmode->join_num > mode.join_num || | |
705 | (oldmode->join_num == mode.join_num && | |
706 | oldmode->join_time > mode.join_time)) | |
707 | { | |
708 | mode.join_num = oldmode->join_num; | |
709 | mode.join_time = oldmode->join_time; | |
710 | } | |
711 | if(irccmp(mode.forward, oldmode->forward) < 0) | |
712 | strcpy(mode.forward, oldmode->forward); | |
713 | } | |
714 | else | |
715 | { | |
716 | /* If setting -j, clear join throttle state -- jilles */ | |
717 | if (!mode.join_num) | |
718 | chptr->join_count = chptr->join_delta = 0; | |
719 | } | |
720 | ||
721 | set_final_mode(&mode, oldmode); | |
722 | chptr->mode = mode; | |
723 | ||
724 | /* Lost the TS, other side wins, so remove modes on this side */ | |
725 | if(!keep_our_modes) | |
726 | { | |
727 | remove_our_modes(chptr, fakesource_p); | |
728 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head) | |
729 | { | |
730 | del_invite(chptr, ptr->data); | |
731 | } | |
7b22c84f JT |
732 | |
733 | if(rb_dlink_list_length(&chptr->banlist) > 0) | |
734 | remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS); | |
735 | if(rb_dlink_list_length(&chptr->exceptlist) > 0) | |
736 | remove_ban_list(chptr, fakesource_p, &chptr->exceptlist, | |
737 | 'e', ONLY_CHANOPS); | |
738 | if(rb_dlink_list_length(&chptr->invexlist) > 0) | |
739 | remove_ban_list(chptr, fakesource_p, &chptr->invexlist, | |
740 | 'I', ONLY_CHANOPS); | |
741 | if(rb_dlink_list_length(&chptr->quietlist) > 0) | |
742 | remove_ban_list(chptr, fakesource_p, &chptr->quietlist, | |
743 | 'q', ALL_MEMBERS); | |
744 | chptr->bants++; | |
745 | ||
8cc12805 VY |
746 | sendto_channel_local(ALL_MEMBERS, chptr, |
747 | ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld", | |
748 | me.name, chptr->chname, chptr->chname, | |
749 | (long) oldts, (long) newts); | |
750 | /* Update capitalization in channel name, this makes the | |
751 | * capitalization timestamped like modes are -- jilles */ | |
752 | strcpy(chptr->chname, parv[2]); | |
6fb6bd15 AC |
753 | |
754 | /* since we're dropping our modes, we want to clear the mlock as well. --nenolod */ | |
07554369 | 755 | set_channel_mlock(client_p, source_p, chptr, NULL, false); |
8cc12805 VY |
756 | } |
757 | ||
758 | if(*modebuf != '\0') | |
759 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s", | |
760 | fakesource_p->name, chptr->chname, modebuf, parabuf); | |
761 | ||
762 | *modebuf = *parabuf = '\0'; | |
763 | ||
764 | if(parv[3][0] != '0' && keep_new_modes) | |
765 | modes = channel_modes(chptr, source_p); | |
766 | else | |
767 | modes = empty_modes; | |
768 | ||
5203cba5 | 769 | mlen_uid = sprintf(buf_uid, ":%s SJOIN %ld %s %s :", |
8cc12805 VY |
770 | use_id(source_p), (long) chptr->channelts, parv[2], modes); |
771 | ptr_uid = buf_uid + mlen_uid; | |
772 | ||
773 | mbuf = modebuf; | |
774 | para[0] = para[1] = para[2] = para[3] = empty; | |
775 | pargs = 0; | |
40709472 | 776 | len_uid = 0; |
8cc12805 VY |
777 | |
778 | /* if theres a space, theres going to be more than one nick, change the | |
779 | * first space to \0, so s is just the first nick, and point p to the | |
780 | * second nick | |
781 | */ | |
782 | if((p = strchr(s, ' ')) != NULL) | |
783 | { | |
784 | *p++ = '\0'; | |
785 | } | |
786 | ||
787 | *mbuf++ = '+'; | |
788 | ||
789 | while (s) | |
790 | { | |
791 | fl = 0; | |
792 | ||
793 | for (i = 0; i < 2; i++) | |
794 | { | |
795 | if(*s == '@') | |
796 | { | |
797 | fl |= CHFL_CHANOP; | |
798 | s++; | |
799 | } | |
800 | else if(*s == '+') | |
801 | { | |
802 | fl |= CHFL_VOICE; | |
803 | s++; | |
804 | } | |
805 | } | |
806 | ||
807 | /* if the client doesnt exist or is fake direction, skip. */ | |
808 | if(!(target_p = find_client(s)) || | |
809 | (target_p->from != client_p) || !IsPerson(target_p)) | |
810 | goto nextnick; | |
811 | ||
812 | /* we assume for these we can fit at least one nick/uid in.. */ | |
813 | ||
814 | /* check we can fit another status+nick+space into a buffer */ | |
8cc12805 VY |
815 | if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3)) |
816 | { | |
817 | *(ptr_uid - 1) = '\0'; | |
818 | sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); | |
819 | ptr_uid = buf_uid + mlen_uid; | |
820 | len_uid = 0; | |
821 | } | |
822 | ||
823 | if(keep_new_modes) | |
824 | { | |
825 | if(fl & CHFL_CHANOP) | |
826 | { | |
8cc12805 | 827 | *ptr_uid++ = '@'; |
8cc12805 VY |
828 | len_uid++; |
829 | } | |
830 | if(fl & CHFL_VOICE) | |
831 | { | |
8cc12805 | 832 | *ptr_uid++ = '+'; |
8cc12805 VY |
833 | len_uid++; |
834 | } | |
835 | } | |
836 | ||
837 | /* copy the nick to the two buffers */ | |
5203cba5 | 838 | len = sprintf(ptr_uid, "%s ", use_id(target_p)); |
8cc12805 VY |
839 | ptr_uid += len; |
840 | len_uid += len; | |
841 | ||
842 | if(!keep_new_modes) | |
843 | fl = 0; | |
844 | ||
845 | if(!IsMember(target_p, chptr)) | |
846 | { | |
847 | add_user_to_channel(chptr, target_p, fl); | |
805cfa5a | 848 | send_channel_join(chptr, target_p); |
8cc12805 VY |
849 | joins++; |
850 | } | |
851 | ||
852 | if(fl & CHFL_CHANOP) | |
853 | { | |
854 | *mbuf++ = 'o'; | |
855 | para[pargs++] = target_p->name; | |
856 | ||
857 | /* a +ov user.. bleh */ | |
858 | if(fl & CHFL_VOICE) | |
859 | { | |
860 | /* its possible the +o has filled up MAXMODEPARAMS, if so, start | |
861 | * a new buffer | |
862 | */ | |
863 | if(pargs >= MAXMODEPARAMS) | |
864 | { | |
865 | *mbuf = '\0'; | |
866 | sendto_channel_local(ALL_MEMBERS, chptr, | |
867 | ":%s MODE %s %s %s %s %s %s", | |
868 | fakesource_p->name, chptr->chname, | |
869 | modebuf, | |
870 | para[0], para[1], para[2], para[3]); | |
871 | mbuf = modebuf; | |
872 | *mbuf++ = '+'; | |
873 | para[0] = para[1] = para[2] = para[3] = NULL; | |
874 | pargs = 0; | |
875 | } | |
876 | ||
877 | *mbuf++ = 'v'; | |
878 | para[pargs++] = target_p->name; | |
879 | } | |
880 | } | |
881 | else if(fl & CHFL_VOICE) | |
882 | { | |
883 | *mbuf++ = 'v'; | |
884 | para[pargs++] = target_p->name; | |
885 | } | |
886 | ||
887 | if(pargs >= MAXMODEPARAMS) | |
888 | { | |
889 | *mbuf = '\0'; | |
890 | sendto_channel_local(ALL_MEMBERS, chptr, | |
891 | ":%s MODE %s %s %s %s %s %s", | |
892 | fakesource_p->name, | |
893 | chptr->chname, | |
894 | modebuf, para[0], para[1], para[2], para[3]); | |
895 | mbuf = modebuf; | |
896 | *mbuf++ = '+'; | |
897 | para[0] = para[1] = para[2] = para[3] = NULL; | |
898 | pargs = 0; | |
899 | } | |
900 | ||
901 | nextnick: | |
902 | /* p points to the next nick */ | |
903 | s = p; | |
904 | ||
905 | /* if there was a trailing space and p was pointing to it, then we | |
906 | * need to exit.. this has the side effect of breaking double spaces | |
907 | * in an sjoin.. but that shouldnt happen anyway | |
908 | */ | |
909 | if(s && (*s == '\0')) | |
910 | s = p = NULL; | |
911 | ||
912 | /* if p was NULL due to no spaces, s wont exist due to the above, so | |
913 | * we cant check it for spaces.. if there are no spaces, then when | |
914 | * we next get here, s will be NULL | |
915 | */ | |
916 | if(s && ((p = strchr(s, ' ')) != NULL)) | |
917 | { | |
918 | *p++ = '\0'; | |
919 | } | |
920 | } | |
921 | ||
922 | *mbuf = '\0'; | |
923 | if(pargs) | |
924 | { | |
925 | sendto_channel_local(ALL_MEMBERS, chptr, | |
926 | ":%s MODE %s %s %s %s %s %s", | |
927 | fakesource_p->name, chptr->chname, modebuf, | |
928 | para[0], CheckEmpty(para[1]), | |
929 | CheckEmpty(para[2]), CheckEmpty(para[3])); | |
930 | } | |
931 | ||
932 | if(!joins && !(chptr->mode.mode & MODE_PERMANENT) && isnew) | |
933 | { | |
934 | destroy_channel(chptr); | |
935 | ||
3c7d6fcc | 936 | return; |
8cc12805 VY |
937 | } |
938 | ||
939 | /* Keep the colon if we're sending an SJOIN without nicks -- jilles */ | |
940 | if (joins) | |
941 | { | |
8cc12805 VY |
942 | *(ptr_uid - 1) = '\0'; |
943 | } | |
944 | ||
945 | sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid); | |
8cc12805 VY |
946 | } |
947 | ||
f4a80ce6 JT |
948 | /* |
949 | * do_join_0 | |
950 | * | |
951 | * inputs - pointer to client doing join 0 | |
952 | * output - NONE | |
953 | * side effects - Use has decided to join 0. This is legacy | |
954 | * from the days when channels were numbers not names. *sigh* | |
f4a80ce6 JT |
955 | */ |
956 | static void | |
957 | do_join_0(struct Client *client_p, struct Client *source_p) | |
958 | { | |
959 | struct membership *msptr; | |
960 | struct Channel *chptr = NULL; | |
5b96d9a6 | 961 | rb_dlink_node *ptr; |
f4a80ce6 JT |
962 | |
963 | /* Finish the flood grace period... */ | |
964 | if(MyClient(source_p) && !IsFloodDone(source_p)) | |
965 | flood_endgrace(source_p); | |
966 | ||
f4a80ce6 | 967 | sendto_server(client_p, NULL, CAP_TS6, NOCAPS, ":%s JOIN 0", use_id(source_p)); |
f4a80ce6 | 968 | |
f4a80ce6 JT |
969 | while((ptr = source_p->user->channel.head)) |
970 | { | |
4eb9a3ca JT |
971 | if(MyConnect(source_p) && |
972 | !IsOper(source_p) && !IsExemptSpambot(source_p)) | |
973 | check_spambot_warning(source_p, NULL); | |
974 | ||
f4a80ce6 JT |
975 | msptr = ptr->data; |
976 | chptr = msptr->chptr; | |
977 | sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s PART %s", | |
978 | source_p->name, | |
979 | source_p->username, source_p->host, chptr->chname); | |
980 | remove_user_from_channel(msptr); | |
981 | } | |
982 | } | |
983 | ||
3c7d6fcc | 984 | static bool |
212380e3 AC |
985 | check_channel_name_loc(struct Client *source_p, const char *name) |
986 | { | |
6865c0b0 JT |
987 | const char *p; |
988 | ||
212380e3 AC |
989 | s_assert(name != NULL); |
990 | if(EmptyString(name)) | |
3c7d6fcc | 991 | return false; |
212380e3 AC |
992 | |
993 | if(ConfigFileEntry.disable_fake_channels && !IsOper(source_p)) | |
994 | { | |
6865c0b0 | 995 | for(p = name; *p; ++p) |
212380e3 | 996 | { |
6865c0b0 | 997 | if(!IsChanChar(*p) || IsFakeChanChar(*p)) |
3c7d6fcc | 998 | return false; |
212380e3 AC |
999 | } |
1000 | } | |
1001 | else | |
1002 | { | |
6865c0b0 | 1003 | for(p = name; *p; ++p) |
212380e3 | 1004 | { |
6865c0b0 | 1005 | if(!IsChanChar(*p)) |
3c7d6fcc | 1006 | return false; |
212380e3 AC |
1007 | } |
1008 | } | |
1009 | ||
6865c0b0 JT |
1010 | if(ConfigChannel.only_ascii_channels) |
1011 | { | |
1012 | for(p = name; *p; ++p) | |
1013 | if(*p < 33 || *p > 126) | |
3c7d6fcc | 1014 | return false; |
6865c0b0 JT |
1015 | } |
1016 | ||
3c7d6fcc | 1017 | return true; |
212380e3 AC |
1018 | } |
1019 | ||
35bfe0e6 JT |
1020 | /* send_join_error() |
1021 | * | |
1022 | * input - client to send to, reason, channel name | |
1023 | * output - none | |
1024 | * side effects - error message sent to client | |
1025 | */ | |
1026 | static void | |
1027 | send_join_error(struct Client *source_p, int numeric, const char *name) | |
1028 | { | |
1029 | /* This stuff is necessary because the form_str macro only | |
1030 | * accepts constants. | |
1031 | */ | |
1032 | switch (numeric) | |
1033 | { | |
1034 | #define NORMAL_NUMERIC(i) \ | |
1035 | case i: \ | |
1036 | sendto_one(source_p, form_str(i), \ | |
1037 | me.name, source_p->name, name); \ | |
1038 | break | |
1039 | ||
1040 | NORMAL_NUMERIC(ERR_BANNEDFROMCHAN); | |
1041 | NORMAL_NUMERIC(ERR_INVITEONLYCHAN); | |
1042 | NORMAL_NUMERIC(ERR_BADCHANNELKEY); | |
1043 | NORMAL_NUMERIC(ERR_CHANNELISFULL); | |
1044 | NORMAL_NUMERIC(ERR_NEEDREGGEDNICK); | |
1045 | NORMAL_NUMERIC(ERR_THROTTLE); | |
1046 | ||
1047 | default: | |
1048 | sendto_one_numeric(source_p, numeric, | |
1049 | "%s :Cannot join channel", name); | |
1050 | break; | |
1051 | } | |
1052 | } | |
1053 | ||
212380e3 AC |
1054 | static void |
1055 | set_final_mode(struct Mode *mode, struct Mode *oldmode) | |
1056 | { | |
1057 | int dir = MODE_QUERY; | |
1058 | char *pbuf = parabuf; | |
1059 | int len; | |
1060 | int i; | |
1061 | ||
1062 | /* ok, first get a list of modes we need to add */ | |
efccc22c | 1063 | for (i = 0; i < 256; i++) |
212380e3 | 1064 | { |
efccc22c | 1065 | if((mode->mode & chmode_flags[i]) && !(oldmode->mode & chmode_flags[i])) |
212380e3 AC |
1066 | { |
1067 | if(dir != MODE_ADD) | |
1068 | { | |
1069 | *mbuf++ = '+'; | |
1070 | dir = MODE_ADD; | |
1071 | } | |
efccc22c | 1072 | *mbuf++ = i; |
212380e3 AC |
1073 | } |
1074 | } | |
1075 | ||
1076 | /* now the ones we need to remove. */ | |
efccc22c | 1077 | for (i = 0; i < 256; i++) |
212380e3 | 1078 | { |
efccc22c | 1079 | if((oldmode->mode & chmode_flags[i]) && !(mode->mode & chmode_flags[i])) |
212380e3 AC |
1080 | { |
1081 | if(dir != MODE_DEL) | |
1082 | { | |
1083 | *mbuf++ = '-'; | |
1084 | dir = MODE_DEL; | |
1085 | } | |
efccc22c | 1086 | *mbuf++ = i; |
212380e3 AC |
1087 | } |
1088 | } | |
1089 | ||
1090 | if(oldmode->limit && !mode->limit) | |
1091 | { | |
1092 | if(dir != MODE_DEL) | |
1093 | { | |
1094 | *mbuf++ = '-'; | |
1095 | dir = MODE_DEL; | |
1096 | } | |
1097 | *mbuf++ = 'l'; | |
1098 | } | |
1099 | if(oldmode->key[0] && !mode->key[0]) | |
1100 | { | |
1101 | if(dir != MODE_DEL) | |
1102 | { | |
1103 | *mbuf++ = '-'; | |
1104 | dir = MODE_DEL; | |
1105 | } | |
1106 | *mbuf++ = 'k'; | |
5203cba5 | 1107 | len = sprintf(pbuf, "%s ", oldmode->key); |
212380e3 AC |
1108 | pbuf += len; |
1109 | } | |
1110 | if(oldmode->join_num && !mode->join_num) | |
1111 | { | |
1112 | if(dir != MODE_DEL) | |
1113 | { | |
1114 | *mbuf++ = '-'; | |
1115 | dir = MODE_DEL; | |
1116 | } | |
1117 | *mbuf++ = 'j'; | |
1118 | } | |
1119 | if(oldmode->forward[0] && !mode->forward[0]) | |
1120 | { | |
1121 | if(dir != MODE_DEL) | |
1122 | { | |
1123 | *mbuf++ = '-'; | |
1124 | dir = MODE_DEL; | |
1125 | } | |
1126 | *mbuf++ = 'f'; | |
1127 | } | |
1128 | if(mode->limit && oldmode->limit != mode->limit) | |
1129 | { | |
1130 | if(dir != MODE_ADD) | |
1131 | { | |
1132 | *mbuf++ = '+'; | |
1133 | dir = MODE_ADD; | |
1134 | } | |
1135 | *mbuf++ = 'l'; | |
5203cba5 | 1136 | len = sprintf(pbuf, "%d ", mode->limit); |
212380e3 AC |
1137 | pbuf += len; |
1138 | } | |
1139 | if(mode->key[0] && strcmp(oldmode->key, mode->key)) | |
1140 | { | |
1141 | if(dir != MODE_ADD) | |
1142 | { | |
1143 | *mbuf++ = '+'; | |
1144 | dir = MODE_ADD; | |
1145 | } | |
1146 | *mbuf++ = 'k'; | |
5203cba5 | 1147 | len = sprintf(pbuf, "%s ", mode->key); |
212380e3 AC |
1148 | pbuf += len; |
1149 | } | |
1150 | if(mode->join_num && (oldmode->join_num != mode->join_num || oldmode->join_time != mode->join_time)) | |
1151 | { | |
1152 | if(dir != MODE_ADD) | |
1153 | { | |
1154 | *mbuf++ = '+'; | |
1155 | dir = MODE_ADD; | |
1156 | } | |
1157 | *mbuf++ = 'j'; | |
5203cba5 | 1158 | len = sprintf(pbuf, "%d:%d ", mode->join_num, mode->join_time); |
212380e3 AC |
1159 | pbuf += len; |
1160 | } | |
2da6f6eb JT |
1161 | if(mode->forward[0] && strcmp(oldmode->forward, mode->forward) && |
1162 | ConfigChannel.use_forward) | |
212380e3 AC |
1163 | { |
1164 | if(dir != MODE_ADD) | |
1165 | { | |
1166 | *mbuf++ = '+'; | |
1167 | dir = MODE_ADD; | |
1168 | } | |
1169 | *mbuf++ = 'f'; | |
5203cba5 | 1170 | len = sprintf(pbuf, "%s ", mode->forward); |
212380e3 AC |
1171 | pbuf += len; |
1172 | } | |
1173 | *mbuf = '\0'; | |
1174 | } | |
1175 | ||
1176 | /* | |
1177 | * remove_our_modes | |
1178 | * | |
1179 | * inputs - | |
55abcbb2 KB |
1180 | * output - |
1181 | * side effects - | |
212380e3 AC |
1182 | */ |
1183 | static void | |
1184 | remove_our_modes(struct Channel *chptr, struct Client *source_p) | |
1185 | { | |
1186 | struct membership *msptr; | |
5b96d9a6 | 1187 | rb_dlink_node *ptr; |
212380e3 AC |
1188 | char lmodebuf[MODEBUFLEN]; |
1189 | char *lpara[MAXMODEPARAMS]; | |
1190 | int count = 0; | |
1191 | int i; | |
1192 | ||
1193 | mbuf = lmodebuf; | |
1194 | *mbuf++ = '-'; | |
1195 | ||
1196 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1197 | lpara[i] = NULL; | |
1198 | ||
5b96d9a6 | 1199 | RB_DLINK_FOREACH(ptr, chptr->members.head) |
212380e3 AC |
1200 | { |
1201 | msptr = ptr->data; | |
1202 | ||
1203 | if(is_chanop(msptr)) | |
1204 | { | |
1205 | msptr->flags &= ~CHFL_CHANOP; | |
1206 | lpara[count++] = msptr->client_p->name; | |
1207 | *mbuf++ = 'o'; | |
1208 | ||
1209 | /* +ov, might not fit so check. */ | |
1210 | if(is_voiced(msptr)) | |
1211 | { | |
1212 | if(count >= MAXMODEPARAMS) | |
1213 | { | |
1214 | *mbuf = '\0'; | |
1215 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1216 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1217 | source_p->name, chptr->chname, |
212380e3 AC |
1218 | lmodebuf, lpara[0], lpara[1], |
1219 | lpara[2], lpara[3]); | |
1220 | ||
1221 | /* preserve the initial '-' */ | |
1222 | mbuf = lmodebuf; | |
1223 | *mbuf++ = '-'; | |
1224 | count = 0; | |
1225 | ||
1226 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1227 | lpara[i] = NULL; | |
1228 | } | |
1229 | ||
1230 | msptr->flags &= ~CHFL_VOICE; | |
1231 | lpara[count++] = msptr->client_p->name; | |
1232 | *mbuf++ = 'v'; | |
1233 | } | |
1234 | } | |
1235 | else if(is_voiced(msptr)) | |
1236 | { | |
1237 | msptr->flags &= ~CHFL_VOICE; | |
1238 | lpara[count++] = msptr->client_p->name; | |
1239 | *mbuf++ = 'v'; | |
1240 | } | |
1241 | else | |
1242 | continue; | |
1243 | ||
1244 | if(count >= MAXMODEPARAMS) | |
1245 | { | |
1246 | *mbuf = '\0'; | |
1247 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1248 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1249 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1250 | lpara[0], lpara[1], lpara[2], lpara[3]); |
1251 | mbuf = lmodebuf; | |
1252 | *mbuf++ = '-'; | |
1253 | count = 0; | |
1254 | ||
1255 | for(i = 0; i < MAXMODEPARAMS; i++) | |
1256 | lpara[i] = NULL; | |
1257 | } | |
1258 | } | |
1259 | ||
1260 | if(count != 0) | |
1261 | { | |
1262 | *mbuf = '\0'; | |
1263 | sendto_channel_local(ALL_MEMBERS, chptr, | |
1264 | ":%s MODE %s %s %s %s %s %s", | |
7bf78de0 | 1265 | source_p->name, chptr->chname, lmodebuf, |
212380e3 AC |
1266 | EmptyString(lpara[0]) ? "" : lpara[0], |
1267 | EmptyString(lpara[1]) ? "" : lpara[1], | |
1268 | EmptyString(lpara[2]) ? "" : lpara[2], | |
1269 | EmptyString(lpara[3]) ? "" : lpara[3]); | |
1270 | ||
1271 | } | |
1272 | } | |
8cc12805 VY |
1273 | |
1274 | /* remove_ban_list() | |
1275 | * | |
1276 | * inputs - channel, source, list to remove, char of mode, caps needed | |
1277 | * outputs - | |
1278 | * side effects - given list is removed, with modes issued to local clients | |
8cc12805 VY |
1279 | */ |
1280 | static void | |
1281 | remove_ban_list(struct Channel *chptr, struct Client *source_p, | |
8afeb720 | 1282 | rb_dlink_list * list, char c, int mems) |
8cc12805 VY |
1283 | { |
1284 | static char lmodebuf[BUFSIZE]; | |
1285 | static char lparabuf[BUFSIZE]; | |
1286 | struct Ban *banptr; | |
1287 | rb_dlink_node *ptr; | |
1288 | rb_dlink_node *next_ptr; | |
1289 | char *pbuf; | |
1290 | int count = 0; | |
1291 | int cur_len, mlen, plen; | |
1292 | ||
1293 | pbuf = lparabuf; | |
1294 | ||
5203cba5 | 1295 | cur_len = mlen = sprintf(lmodebuf, ":%s MODE %s -", source_p->name, chptr->chname); |
8cc12805 VY |
1296 | mbuf = lmodebuf + mlen; |
1297 | ||
1298 | RB_DLINK_FOREACH_SAFE(ptr, next_ptr, list->head) | |
1299 | { | |
1300 | banptr = ptr->data; | |
1301 | ||
1302 | /* trailing space, and the mode letter itself */ | |
23f6b63a JT |
1303 | plen = strlen(banptr->banstr) + |
1304 | (banptr->forward ? strlen(banptr->forward) + 1 : 0) + 2; | |
8cc12805 VY |
1305 | |
1306 | if(count >= MAXMODEPARAMS || (cur_len + plen) > BUFSIZE - 4) | |
1307 | { | |
1308 | /* remove trailing space */ | |
1309 | *mbuf = '\0'; | |
1310 | *(pbuf - 1) = '\0'; | |
1311 | ||
1312 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1313 | |
1314 | cur_len = mlen; | |
1315 | mbuf = lmodebuf + mlen; | |
1316 | pbuf = lparabuf; | |
1317 | count = 0; | |
1318 | } | |
1319 | ||
1320 | *mbuf++ = c; | |
1321 | cur_len += plen; | |
23f6b63a | 1322 | if (banptr->forward) |
5203cba5 | 1323 | pbuf += sprintf(pbuf, "%s$%s ", banptr->banstr, banptr->forward); |
23f6b63a | 1324 | else |
5203cba5 | 1325 | pbuf += sprintf(pbuf, "%s ", banptr->banstr); |
8cc12805 VY |
1326 | count++; |
1327 | ||
1328 | free_ban(banptr); | |
1329 | } | |
1330 | ||
1331 | *mbuf = '\0'; | |
1332 | *(pbuf - 1) = '\0'; | |
1333 | sendto_channel_local(mems, chptr, "%s %s", lmodebuf, lparabuf); | |
8cc12805 VY |
1334 | |
1335 | list->head = list->tail = NULL; | |
1336 | list->length = 0; | |
1337 | } |