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