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