]> jfr.im git - irc/rqf/shadowircd.git/blob - modules/core/m_join.c
Merge.
[irc/rqf/shadowircd.git] / modules / core / m_join.c
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 return 0;
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 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
326 source_p->name,
327 source_p->username, source_p->host, chptr->chname);
328
329 /* its a new channel, set +nt and burst. */
330 if(flags & CHFL_CHANOP)
331 {
332 chptr->channelts = rb_current_time();
333 chptr->mode.mode |= MODE_TOPICLIMIT;
334 chptr->mode.mode |= MODE_NOPRIVMSGS;
335 modes = channel_modes(chptr, &me);
336
337 sendto_channel_local(ONLY_CHANOPS, chptr, ":%s MODE %s %s",
338 me.name, chptr->chname, modes);
339
340 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
341 ":%s SJOIN %ld %s %s :@%s",
342 me.id, (long) chptr->channelts,
343 chptr->chname, modes, source_p->id);
344 }
345 else
346 {
347 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
348 ":%s JOIN %ld %s +",
349 use_id(source_p), (long) chptr->channelts,
350 chptr->chname);
351 }
352
353 del_invite(chptr, source_p);
354
355 if(chptr->topic != NULL)
356 {
357 sendto_one(source_p, form_str(RPL_TOPIC), me.name,
358 source_p->name, chptr->chname, chptr->topic);
359
360 sendto_one(source_p, form_str(RPL_TOPICWHOTIME),
361 me.name, source_p->name, chptr->chname,
362 chptr->topic_info, chptr->topic_time);
363 }
364
365 channel_member_names(chptr, source_p, 1);
366
367 hook_info.client = source_p;
368 hook_info.chptr = chptr;
369 hook_info.key = key;
370 call_hook(h_channel_join, &hook_info);
371 }
372
373 return 0;
374 }
375
376 /*
377 * ms_join
378 * parv[1] = channel TS
379 * parv[2] = channel
380 * parv[3] = "+", formerly channel modes but now unused
381 * alternatively, a single "0" parameter parts all channels
382 */
383 static int
384 ms_join(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
385 {
386 struct Channel *chptr;
387 static struct Mode mode;
388 time_t oldts;
389 time_t newts;
390 int isnew;
391 int keep_our_modes = YES;
392 int keep_new_modes = YES;
393 rb_dlink_node *ptr, *next_ptr;
394
395 /* special case for join 0 */
396 if((parv[1][0] == '0') && (parv[1][1] == '\0') && parc == 2)
397 {
398 do_join_0(client_p, source_p);
399 return 0;
400 }
401
402 if(parc < 4)
403 return 0;
404
405 if(!IsChannelName(parv[2]) || !check_channel_name(parv[2]))
406 return 0;
407
408 /* joins for local channels cant happen. */
409 if(parv[2][0] == '&')
410 return 0;
411
412 mbuf = modebuf;
413 mode.key[0] = mode.forward[0] = '\0';
414 mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
415
416 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
417 return 0;
418
419 newts = atol(parv[1]);
420 oldts = chptr->channelts;
421
422 #ifdef IGNORE_BOGUS_TS
423 if(newts < 800000000)
424 {
425 sendto_realops_snomask(SNO_DEBUG, L_ALL,
426 "*** Bogus TS %ld on %s ignored from %s",
427 (long) newts, chptr->chname, client_p->name);
428 newts = (oldts == 0) ? oldts : 800000000;
429 }
430 #else
431 /* making a channel TS0 */
432 if(!isnew && !newts && oldts)
433 {
434 sendto_channel_local(ALL_MEMBERS, chptr,
435 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to 0",
436 me.name, chptr->chname, chptr->chname, (long) oldts);
437 sendto_realops_snomask(SNO_GENERAL, L_ALL,
438 "Server %s changing TS on %s from %ld to 0",
439 source_p->name, chptr->chname, (long) oldts);
440 }
441 #endif
442
443 if(isnew)
444 chptr->channelts = newts;
445 else if(newts == 0 || oldts == 0)
446 chptr->channelts = 0;
447 else if(newts == oldts)
448 ;
449 else if(newts < oldts)
450 {
451 keep_our_modes = NO;
452 chptr->channelts = newts;
453 }
454 else
455 keep_new_modes = NO;
456
457 /* Lost the TS, other side wins, so remove modes on this side */
458 if(!keep_our_modes)
459 {
460 set_final_mode(&mode, &chptr->mode);
461 chptr->mode = mode;
462 remove_our_modes(chptr, source_p);
463 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
464 {
465 del_invite(chptr, ptr->data);
466 }
467 /* If setting -j, clear join throttle state -- jilles */
468 chptr->join_count = chptr->join_delta = 0;
469 sendto_channel_local(ALL_MEMBERS, chptr,
470 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
471 me.name, chptr->chname, chptr->chname,
472 (long) oldts, (long) newts);
473 /* Update capitalization in channel name, this makes the
474 * capitalization timestamped like modes are -- jilles */
475 strcpy(chptr->chname, parv[2]);
476 if(*modebuf != '\0')
477 sendto_channel_local(ALL_MEMBERS, chptr,
478 ":%s MODE %s %s %s",
479 source_p->servptr->name,
480 chptr->chname, modebuf, parabuf);
481 *modebuf = *parabuf = '\0';
482 }
483
484 if(!IsMember(source_p, chptr))
485 {
486 add_user_to_channel(chptr, source_p, CHFL_PEON);
487 if (chptr->mode.join_num &&
488 rb_current_time() - chptr->join_delta >= chptr->mode.join_time)
489 {
490 chptr->join_count = 0;
491 chptr->join_delta = rb_current_time();
492 }
493 chptr->join_count++;
494 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
495 source_p->name, source_p->username,
496 source_p->host, chptr->chname);
497 }
498
499 sendto_server(client_p, chptr, CAP_TS6, NOCAPS,
500 ":%s JOIN %ld %s +",
501 source_p->id, (long) chptr->channelts, chptr->chname);
502 return 0;
503 }
504
505 static int
506 ms_sjoin(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
507 {
508 static char buf_uid[BUFSIZE];
509 static const char empty_modes[] = "0";
510 struct Channel *chptr;
511 struct Client *target_p, *fakesource_p;
512 time_t newts;
513 time_t oldts;
514 static struct Mode mode, *oldmode;
515 const char *modes;
516 int args = 0;
517 int keep_our_modes = 1;
518 int keep_new_modes = 1;
519 int fl;
520 int isnew;
521 int mlen_uid;
522 int len_nick;
523 int len_uid;
524 int len;
525 int joins = 0;
526 const char *s;
527 char *ptr_uid;
528 char *p;
529 int i, joinc = 0, timeslice = 0;
530 static char empty[] = "";
531 rb_dlink_node *ptr, *next_ptr;
532
533 if(!IsChannelName(parv[2]) || !check_channel_name(parv[2]))
534 return 0;
535
536 /* SJOIN's for local channels can't happen. */
537 if(*parv[2] == '&')
538 return 0;
539
540 modebuf[0] = parabuf[0] = mode.key[0] = mode.forward[0] = '\0';
541 pargs = mode.mode = mode.limit = mode.join_num = mode.join_time = 0;
542
543 /* Hide connecting server on netburst -- jilles */
544 if (ConfigServerHide.flatten_links && !HasSentEob(source_p))
545 fakesource_p = &me;
546 else
547 fakesource_p = source_p;
548
549 mbuf = modebuf;
550 newts = atol(parv[1]);
551
552 s = parv[3];
553 while (*s)
554 {
555 switch (*(s++))
556 {
557 case 'f':
558 rb_strlcpy(mode.forward, parv[4 + args], sizeof(mode.forward));
559 args++;
560 if(parc < 5 + args)
561 return 0;
562 break;
563 case 'j':
564 sscanf(parv[4 + args], "%d:%d", &joinc, &timeslice);
565 args++;
566 mode.join_num = joinc;
567 mode.join_time = timeslice;
568 if(parc < 5 + args)
569 return 0;
570 break;
571 case 'k':
572 rb_strlcpy(mode.key, parv[4 + args], sizeof(mode.key));
573 args++;
574 if(parc < 5 + args)
575 return 0;
576 break;
577 case 'l':
578 mode.limit = atoi(parv[4 + args]);
579 args++;
580 if(parc < 5 + args)
581 return 0;
582 break;
583 default:
584 if(chmode_flags[(int) *s] != 0)
585 {
586 mode.mode |= chmode_flags[(int) *s];
587 }
588 }
589 }
590
591 if(parv[args + 4])
592 {
593 s = parv[args + 4];
594
595 /* remove any leading spaces */
596 while (*s == ' ')
597 s++;
598 }
599 else
600 s = "";
601
602 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
603 return 0; /* channel name too long? */
604
605
606 oldts = chptr->channelts;
607 oldmode = &chptr->mode;
608
609 #ifdef IGNORE_BOGUS_TS
610 if(newts < 800000000)
611 {
612 sendto_realops_snomask(SNO_DEBUG, L_ALL,
613 "*** Bogus TS %ld on %s ignored from %s",
614 (long) newts, chptr->chname, client_p->name);
615
616 newts = (oldts == 0) ? oldts : 800000000;
617 }
618 #else
619 if(!isnew && !newts && oldts)
620 {
621 sendto_channel_local(ALL_MEMBERS, chptr,
622 ":%s NOTICE %s :*** Notice -- TS for %s "
623 "changed from %ld to 0",
624 me.name, chptr->chname, chptr->chname, (long) oldts);
625 sendto_realops_snomask(SNO_GENERAL, L_ALL,
626 "Server %s changing TS on %s from %ld to 0",
627 source_p->name, chptr->chname, (long) oldts);
628 }
629 #endif
630
631 if(isnew)
632 chptr->channelts = newts;
633
634 else if(newts == 0 || oldts == 0)
635 chptr->channelts = 0;
636 else if(newts == oldts)
637 ;
638 else if(newts < oldts)
639 {
640 /* If configured, kick people trying to join +i/+k
641 * channels by recreating them on split servers.
642 * Don't kick if the source has sent EOB (services
643 * deopping everyone by TS-1 SJOIN).
644 * -- jilles */
645 if (ConfigChannel.kick_on_split_riding &&
646 !HasSentEob(source_p) &&
647 ((mode.mode & MODE_INVITEONLY) ||
648 (mode.key[0] != 0 && irccmp(mode.key, oldmode->key) != 0)))
649 {
650 struct membership *msptr;
651 struct Client *who;
652 int l = rb_dlink_list_length(&chptr->members);
653
654 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->locmembers.head)
655 {
656 msptr = ptr->data;
657 who = msptr->client_p;
658 sendto_one(who, ":%s KICK %s %s :Net Rider",
659 me.name, chptr->chname, who->name);
660
661 sendto_server(NULL, chptr, CAP_TS6, NOCAPS,
662 ":%s KICK %s %s :Net Rider",
663 me.id, chptr->chname,
664 who->id);
665 remove_user_from_channel(msptr);
666 if (--l == 0)
667 break;
668 }
669 if (l == 0)
670 {
671 /* Channel was emptied, create a new one */
672 if((chptr = get_or_create_channel(source_p, parv[2], &isnew)) == NULL)
673 return 0; /* oops! */
674
675 oldmode = &chptr->mode;
676 }
677 }
678 keep_our_modes = NO;
679 chptr->channelts = newts;
680 }
681 else
682 keep_new_modes = NO;
683
684 if(!keep_new_modes)
685 mode = *oldmode;
686 else if(keep_our_modes)
687 {
688 mode.mode |= oldmode->mode;
689 if(oldmode->limit > mode.limit)
690 mode.limit = oldmode->limit;
691 if(strcmp(mode.key, oldmode->key) < 0)
692 strcpy(mode.key, oldmode->key);
693 if(oldmode->join_num > mode.join_num ||
694 (oldmode->join_num == mode.join_num &&
695 oldmode->join_time > mode.join_time))
696 {
697 mode.join_num = oldmode->join_num;
698 mode.join_time = oldmode->join_time;
699 }
700 if(irccmp(mode.forward, oldmode->forward) < 0)
701 strcpy(mode.forward, oldmode->forward);
702 }
703 else
704 {
705 /* If setting -j, clear join throttle state -- jilles */
706 if (!mode.join_num)
707 chptr->join_count = chptr->join_delta = 0;
708 }
709
710 set_final_mode(&mode, oldmode);
711 chptr->mode = mode;
712
713 /* Lost the TS, other side wins, so remove modes on this side */
714 if(!keep_our_modes)
715 {
716 remove_our_modes(chptr, fakesource_p);
717 RB_DLINK_FOREACH_SAFE(ptr, next_ptr, chptr->invites.head)
718 {
719 del_invite(chptr, ptr->data);
720 }
721
722 if(rb_dlink_list_length(&chptr->banlist) > 0)
723 remove_ban_list(chptr, fakesource_p, &chptr->banlist, 'b', ALL_MEMBERS);
724 if(rb_dlink_list_length(&chptr->exceptlist) > 0)
725 remove_ban_list(chptr, fakesource_p, &chptr->exceptlist,
726 'e', ONLY_CHANOPS);
727 if(rb_dlink_list_length(&chptr->invexlist) > 0)
728 remove_ban_list(chptr, fakesource_p, &chptr->invexlist,
729 'I', ONLY_CHANOPS);
730 if(rb_dlink_list_length(&chptr->quietlist) > 0)
731 remove_ban_list(chptr, fakesource_p, &chptr->quietlist,
732 'q', ALL_MEMBERS);
733 chptr->bants++;
734
735 sendto_channel_local(ALL_MEMBERS, chptr,
736 ":%s NOTICE %s :*** Notice -- TS for %s changed from %ld to %ld",
737 me.name, chptr->chname, chptr->chname,
738 (long) oldts, (long) newts);
739 /* Update capitalization in channel name, this makes the
740 * capitalization timestamped like modes are -- jilles */
741 strcpy(chptr->chname, parv[2]);
742 }
743
744 if(*modebuf != '\0')
745 sendto_channel_local(ALL_MEMBERS, chptr, ":%s MODE %s %s %s",
746 fakesource_p->name, chptr->chname, modebuf, parabuf);
747
748 *modebuf = *parabuf = '\0';
749
750 if(parv[3][0] != '0' && keep_new_modes)
751 modes = channel_modes(chptr, source_p);
752 else
753 modes = empty_modes;
754
755 mlen_uid = rb_sprintf(buf_uid, ":%s SJOIN %ld %s %s :",
756 use_id(source_p), (long) chptr->channelts, parv[2], modes);
757 ptr_uid = buf_uid + mlen_uid;
758
759 mbuf = modebuf;
760 para[0] = para[1] = para[2] = para[3] = empty;
761 pargs = 0;
762 len_nick = len_uid = 0;
763
764 /* if theres a space, theres going to be more than one nick, change the
765 * first space to \0, so s is just the first nick, and point p to the
766 * second nick
767 */
768 if((p = strchr(s, ' ')) != NULL)
769 {
770 *p++ = '\0';
771 }
772
773 *mbuf++ = '+';
774
775 while (s)
776 {
777 fl = 0;
778
779 for (i = 0; i < 2; i++)
780 {
781 if(*s == '@')
782 {
783 fl |= CHFL_CHANOP;
784 s++;
785 }
786 else if(*s == '+')
787 {
788 fl |= CHFL_VOICE;
789 s++;
790 }
791 }
792
793 /* if the client doesnt exist or is fake direction, skip. */
794 if(!(target_p = find_client(s)) ||
795 (target_p->from != client_p) || !IsPerson(target_p))
796 goto nextnick;
797
798 /* we assume for these we can fit at least one nick/uid in.. */
799
800 /* check we can fit another status+nick+space into a buffer */
801 if((mlen_uid + len_uid + IDLEN + 3) > (BUFSIZE - 3))
802 {
803 *(ptr_uid - 1) = '\0';
804 sendto_server(client_p->from, NULL, CAP_TS6, NOCAPS, "%s", buf_uid);
805 ptr_uid = buf_uid + mlen_uid;
806 len_uid = 0;
807 }
808
809 if(keep_new_modes)
810 {
811 if(fl & CHFL_CHANOP)
812 {
813 *ptr_uid++ = '@';
814 len_nick++;
815 len_uid++;
816 }
817 if(fl & CHFL_VOICE)
818 {
819 *ptr_uid++ = '+';
820 len_nick++;
821 len_uid++;
822 }
823 }
824
825 /* copy the nick to the two buffers */
826 len = rb_sprintf(ptr_uid, "%s ", use_id(target_p));
827 ptr_uid += len;
828 len_uid += len;
829
830 if(!keep_new_modes)
831 fl = 0;
832
833 if(!IsMember(target_p, chptr))
834 {
835 add_user_to_channel(chptr, target_p, fl);
836 sendto_channel_local(ALL_MEMBERS, chptr, ":%s!%s@%s JOIN :%s",
837 target_p->name,
838 target_p->username, target_p->host, parv[2]);
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 }