]> jfr.im git - solanum.git/blob - src/chmode.c
Remove s_assert definition from ircd_defs.h and add it to its own header.
[solanum.git] / src / chmode.c
1 /*
2 * charybdis: A slightly useful ircd.
3 * chmode.c: channel mode management
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 * Copyright (C) 2005-2006 charybdis development team
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * $Id: chmode.c 3580 2007-11-07 23:45:14Z jilles $
26 */
27
28 #include "stdinc.h"
29 #include "channel.h"
30 #include "client.h"
31 #include "common.h"
32 #include "hash.h"
33 #include "hook.h"
34 #include "match.h"
35 #include "ircd.h"
36 #include "numeric.h"
37 #include "s_serv.h" /* captab */
38 #include "s_user.h"
39 #include "send.h"
40 #include "whowas.h"
41 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
42 #include "s_newconf.h"
43 #include "logger.h"
44 #include "chmode.h"
45 #include "s_assert.h"
46
47 /* bitmasks for error returns, so we send once per call */
48 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
49 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
50 #define SM_ERR_UNKNOWN 0x00000004
51 #define SM_ERR_RPL_C 0x00000008
52 #define SM_ERR_RPL_B 0x00000010
53 #define SM_ERR_RPL_E 0x00000020
54 #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
55 #define SM_ERR_RPL_I 0x00000100
56 #define SM_ERR_RPL_D 0x00000200
57 #define SM_ERR_NOPRIVS 0x00000400
58 #define SM_ERR_RPL_Q 0x00000800
59 #define SM_ERR_RPL_F 0x00001000
60 #define SM_ERR_MLOCK 0x00002000
61
62 #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */
63
64 static struct ChModeChange mode_changes[BUFSIZE];
65 static int mode_count;
66 static int mode_limit;
67 static int mode_limit_simple;
68 static int mask_pos;
69 static int removed_mask_pos;
70
71 char cflagsbuf[256];
72 char cflagsmyinfo[256];
73
74 int chmode_flags[256];
75
76 extern int h_get_channel_access;
77
78 /* OPTIMIZE ME! -- dwr */
79 void
80 construct_cflags_strings(void)
81 {
82 int i;
83 char *ptr = cflagsbuf;
84 char *ptr2 = cflagsmyinfo;
85
86 *ptr = '\0';
87 *ptr2 = '\0';
88
89 for(i = 0; i < 256; i++)
90 {
91 if( !(chmode_table[i].set_func == chm_ban) &&
92 !(chmode_table[i].set_func == chm_forward) &&
93 !(chmode_table[i].set_func == chm_throttle) &&
94 !(chmode_table[i].set_func == chm_key) &&
95 !(chmode_table[i].set_func == chm_limit) &&
96 !(chmode_table[i].set_func == chm_op) &&
97 !(chmode_table[i].set_func == chm_voice))
98 {
99 chmode_flags[i] = chmode_table[i].mode_type;
100 }
101 else
102 {
103 chmode_flags[i] = 0;
104 }
105
106 switch (chmode_flags[i])
107 {
108 case MODE_FREETARGET:
109 case MODE_DISFORWARD:
110 if(ConfigChannel.use_forward)
111 *ptr++ = (char) i;
112 break;
113 default:
114 if(chmode_flags[i] != 0)
115 {
116 *ptr++ = (char) i;
117 }
118 }
119
120 /* Should we leave orphaned check here? -- dwr */
121 if(!(chmode_table[i].set_func == chm_nosuch) && !(chmode_table[i].set_func == chm_orphaned))
122 {
123 *ptr2++ = (char) i;
124 }
125 }
126
127 *ptr++ = '\0';
128 *ptr2++ = '\0';
129 }
130
131 /*
132 * find_umode_slot
133 *
134 * inputs - NONE
135 * outputs - an available cflag bitmask or
136 * 0 if no cflags are available
137 * side effects - NONE
138 */
139 static unsigned int
140 find_cflag_slot(void)
141 {
142 unsigned int all_cflags = 0, my_cflag = 0, i;
143
144 for (i = 0; i < 256; i++)
145 all_cflags |= chmode_flags[i];
146
147 for (my_cflag = 1; my_cflag && (all_cflags & my_cflag);
148 my_cflag <<= 1);
149
150 return my_cflag;
151 }
152
153 unsigned int
154 cflag_add(char c_, ChannelModeFunc function)
155 {
156 int c = (unsigned char)c_;
157
158 if (chmode_table[c].set_func != chm_nosuch &&
159 chmode_table[c].set_func != chm_orphaned)
160 return 0;
161
162 if (chmode_table[c].set_func == chm_nosuch)
163 chmode_table[c].mode_type = find_cflag_slot();
164 if (chmode_table[c].mode_type == 0)
165 return 0;
166 chmode_table[c].set_func = function;
167 construct_cflags_strings();
168 return chmode_table[c].mode_type;
169 }
170
171 void
172 cflag_orphan(char c_)
173 {
174 int c = (unsigned char)c_;
175
176 s_assert(chmode_flags[c] != 0);
177 chmode_table[c].set_func = chm_orphaned;
178 construct_cflags_strings();
179 }
180
181 int
182 get_channel_access(struct Client *source_p, struct membership *msptr)
183 {
184 hook_data_channel_approval moduledata;
185
186 if(!MyClient(source_p))
187 return CHFL_CHANOP;
188
189 if (msptr == NULL)
190 return CHFL_PEON;
191
192 moduledata.client = source_p;
193 moduledata.chptr = msptr->chptr;
194 moduledata.msptr = msptr;
195 moduledata.target = NULL;
196 moduledata.approved = is_chanop(msptr) ? CHFL_CHANOP : CHFL_PEON;
197
198 call_hook(h_get_channel_access, &moduledata);
199
200 return moduledata.approved;
201 }
202
203 /* allow_mode_change()
204 *
205 * Checks if mlock and chanops permit a mode change.
206 *
207 * inputs - client, channel, access level, errors pointer, mode char
208 * outputs - 0 on failure, 1 on success
209 * side effects - error message sent on failure
210 */
211 static int
212 allow_mode_change(struct Client *source_p, struct Channel *chptr, int alevel,
213 int *errors, char c)
214 {
215 /* If this mode char is locked, don't allow local users to change it. */
216 if (MyClient(source_p) && chptr->mode_lock && strchr(chptr->mode_lock, c))
217 {
218 if (!(*errors & SM_ERR_MLOCK))
219 sendto_one_numeric(source_p,
220 ERR_MLOCKRESTRICTED,
221 form_str(ERR_MLOCKRESTRICTED),
222 chptr->chname,
223 c,
224 chptr->mode_lock);
225 *errors |= SM_ERR_MLOCK;
226 return 0;
227 }
228 if(alevel != CHFL_CHANOP)
229 {
230 if(!(*errors & SM_ERR_NOOPS))
231 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
232 me.name, source_p->name, chptr->chname);
233 *errors |= SM_ERR_NOOPS;
234 return 0;
235 }
236 return 1;
237 }
238
239 /* add_id()
240 *
241 * inputs - client, channel, id to add, type, forward
242 * outputs - 0 on failure, 1 on success
243 * side effects - given id is added to the appropriate list
244 */
245 int
246 add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward,
247 rb_dlink_list * list, long mode_type)
248 {
249 struct Ban *actualBan;
250 static char who[USERHOST_REPLYLEN];
251 char *realban = LOCAL_COPY(banid);
252 rb_dlink_node *ptr;
253
254 /* dont let local clients overflow the banlist, or set redundant
255 * bans
256 */
257 if(MyClient(source_p))
258 {
259 if((rb_dlink_list_length(&chptr->banlist) + rb_dlink_list_length(&chptr->exceptlist) + rb_dlink_list_length(&chptr->invexlist) + rb_dlink_list_length(&chptr->quietlist)) >= (chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans))
260 {
261 sendto_one(source_p, form_str(ERR_BANLISTFULL),
262 me.name, source_p->name, chptr->chname, realban);
263 return 0;
264 }
265
266 RB_DLINK_FOREACH(ptr, list->head)
267 {
268 actualBan = ptr->data;
269 if(mask_match(actualBan->banstr, realban))
270 return 0;
271 }
272 }
273 /* dont let remotes set duplicates */
274 else
275 {
276 RB_DLINK_FOREACH(ptr, list->head)
277 {
278 actualBan = ptr->data;
279 if(!irccmp(actualBan->banstr, realban))
280 return 0;
281 }
282 }
283
284
285 if(IsPerson(source_p))
286 rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
287 else
288 rb_strlcpy(who, source_p->name, sizeof(who));
289
290 actualBan = allocate_ban(realban, who, forward);
291 actualBan->when = rb_current_time();
292
293 rb_dlinkAdd(actualBan, &actualBan->node, list);
294
295 /* invalidate the can_send() cache */
296 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
297 chptr->bants++;
298
299 return 1;
300 }
301
302 /* del_id()
303 *
304 * inputs - channel, id to remove, type
305 * outputs - pointer to ban that was removed, if any
306 * side effects - given id is removed from the appropriate list and returned
307 */
308 struct Ban *
309 del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type)
310 {
311 rb_dlink_node *ptr;
312 struct Ban *banptr;
313
314 if(EmptyString(banid))
315 return NULL;
316
317 RB_DLINK_FOREACH(ptr, list->head)
318 {
319 banptr = ptr->data;
320
321 if(irccmp(banid, banptr->banstr) == 0)
322 {
323 rb_dlinkDelete(&banptr->node, list);
324
325 /* invalidate the can_send() cache */
326 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
327 chptr->bants++;
328
329 return banptr;
330 }
331 }
332
333 return NULL;
334 }
335
336 /* check_string()
337 *
338 * input - string to check
339 * output - pointer to 'fixed' string, or "*" if empty
340 * side effects - any white space found becomes \0
341 */
342 static char *
343 check_string(char *s)
344 {
345 char *str = s;
346 static char splat[] = "*";
347 if(!(s && *s))
348 return splat;
349
350 for(; *s; ++s)
351 {
352 if(IsSpace(*s))
353 {
354 *s = '\0';
355 break;
356 }
357 }
358 return str;
359 }
360
361 /* pretty_mask()
362 *
363 * inputs - mask to pretty
364 * outputs - better version of the mask
365 * side effects - mask is chopped to limits, and transformed:
366 * x!y@z => x!y@z
367 * y@z => *!y@z
368 * x!y => x!y@*
369 * x => x!*@*
370 * z.d => *!*@z.d
371 */
372 static char *
373 pretty_mask(const char *idmask)
374 {
375 static char mask_buf[BUFSIZE];
376 int old_mask_pos;
377 char *nick, *user, *host, *forward = NULL;
378 char splat[] = "*";
379 char *t, *at, *ex, *ex2;
380 char ne = 0, ue = 0, he = 0, fe = 0; /* save values at nick[NICKLEN], et all */
381 char e2 = 0; /* save value that delimits forward channel */
382 char *mask;
383
384 mask = LOCAL_COPY(idmask);
385 mask = check_string(mask);
386 collapse(mask);
387
388 nick = user = host = splat;
389
390 if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5)
391 return NULL;
392
393 old_mask_pos = mask_pos;
394
395 if (*mask == '$')
396 {
397 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s", mask) + 1;
398 t = mask_buf + old_mask_pos + 1;
399 if (*t == '!')
400 *t = '~';
401 if (*t == '~')
402 t++;
403 *t = ToLower(*t);
404 return mask_buf + old_mask_pos;
405 }
406
407 at = ex = ex2 = NULL;
408 if((t = strchr(mask, '@')) != NULL)
409 {
410 at = t;
411 *t++ = '\0';
412 if(*t != '\0')
413 host = t;
414
415 if((t = strchr(mask, '!')) != NULL)
416 {
417 ex = t;
418 *t++ = '\0';
419 if(*t != '\0')
420 user = t;
421 if(*mask != '\0')
422 nick = mask;
423 }
424 else
425 {
426 if(*mask != '\0')
427 user = mask;
428 }
429
430 if((t = strchr(host, '!')) != NULL || (t = strchr(host, '$')) != NULL)
431 {
432 ex2 = t;
433 e2 = *t;
434 *t++= '\0';
435 if (*t != '\0')
436 forward = t;
437 }
438 }
439 else if((t = strchr(mask, '!')) != NULL)
440 {
441 ex = t;
442 *t++ = '\0';
443 if(*mask != '\0')
444 nick = mask;
445 if(*t != '\0')
446 user = t;
447 }
448 else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
449 {
450 if(*mask != '\0')
451 host = mask;
452 }
453 else
454 {
455 if(*mask != '\0')
456 nick = mask;
457 }
458
459 /* truncate values to max lengths */
460 if(strlen(nick) > NICKLEN - 1)
461 {
462 ne = nick[NICKLEN - 1];
463 nick[NICKLEN - 1] = '\0';
464 }
465 if(strlen(user) > USERLEN)
466 {
467 ue = user[USERLEN];
468 user[USERLEN] = '\0';
469 }
470 if(strlen(host) > HOSTLEN)
471 {
472 he = host[HOSTLEN];
473 host[HOSTLEN] = '\0';
474 }
475 if(forward && strlen(forward) > CHANNELLEN)
476 {
477 fe = forward[CHANNELLEN];
478 forward[CHANNELLEN] = '\0';
479 }
480
481 if (forward)
482 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s$%s", nick, user, host, forward) + 1;
483 else
484 mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
485
486 /* restore mask, since we may need to use it again later */
487 if(at)
488 *at = '@';
489 if(ex)
490 *ex = '!';
491 if(ex2)
492 *ex2 = e2;
493 if(ne)
494 nick[NICKLEN - 1] = ne;
495 if(ue)
496 user[USERLEN] = ue;
497 if(he)
498 host[HOSTLEN] = he;
499 if(fe)
500 forward[CHANNELLEN] = fe;
501
502 return mask_buf + old_mask_pos;
503 }
504
505 /* check_forward()
506 *
507 * input - client, channel to set mode on, target channel name
508 * output - true if forwarding should be allowed
509 * side effects - numeric sent if not allowed
510 */
511 static int
512 check_forward(struct Client *source_p, struct Channel *chptr,
513 const char *forward)
514 {
515 struct Channel *targptr;
516 struct membership *msptr;
517
518 if(!check_channel_name(forward) ||
519 (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
520 {
521 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
522 return 0;
523 }
524 /* don't forward to inconsistent target -- jilles */
525 if(chptr->chname[0] == '#' && forward[0] == '&')
526 {
527 sendto_one_numeric(source_p, ERR_BADCHANNAME,
528 form_str(ERR_BADCHANNAME), forward);
529 return 0;
530 }
531 if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
532 {
533 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
534 form_str(ERR_NOSUCHCHANNEL), forward);
535 return 0;
536 }
537 if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
538 {
539 if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
540 get_channel_access(source_p, msptr) != CHFL_CHANOP)
541 {
542 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
543 me.name, source_p->name, targptr->chname);
544 return 0;
545 }
546 }
547 return 1;
548 }
549
550 /* fix_key()
551 *
552 * input - key to fix
553 * output - the same key, fixed
554 * side effects - anything below ascii 13 is discarded, ':' discarded,
555 * high ascii is dropped to lower half of ascii table
556 */
557 static char *
558 fix_key(char *arg)
559 {
560 u_char *s, *t, c;
561
562 for(s = t = (u_char *) arg; (c = *s); s++)
563 {
564 c &= 0x7f;
565 if(c != ':' && c != ',' && c > ' ')
566 *t++ = c;
567 }
568
569 *t = '\0';
570 return arg;
571 }
572
573 /* fix_key_remote()
574 *
575 * input - key to fix
576 * ouput - the same key, fixed
577 * side effects - high ascii dropped to lower half of table,
578 * CR/LF/':' are dropped
579 */
580 static char *
581 fix_key_remote(char *arg)
582 {
583 u_char *s, *t, c;
584
585 for(s = t = (u_char *) arg; (c = *s); s++)
586 {
587 c &= 0x7f;
588 if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
589 *t++ = c;
590 }
591
592 *t = '\0';
593 return arg;
594 }
595
596 /* chm_*()
597 *
598 * The handlers for each specific mode.
599 */
600 void
601 chm_nosuch(struct Client *source_p, struct Channel *chptr,
602 int alevel, int parc, int *parn,
603 const char **parv, int *errors, int dir, char c, long mode_type)
604 {
605 if(*errors & SM_ERR_UNKNOWN)
606 return;
607 *errors |= SM_ERR_UNKNOWN;
608 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
609 }
610
611 void
612 chm_simple(struct Client *source_p, struct Channel *chptr,
613 int alevel, int parc, int *parn,
614 const char **parv, int *errors, int dir, char c, long mode_type)
615 {
616 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
617 return;
618
619 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
620 return;
621
622 /* setting + */
623 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
624 {
625 /* if +f is disabled, ignore an attempt to set +QF locally */
626 if(!ConfigChannel.use_forward && MyClient(source_p) &&
627 (c == 'Q' || c == 'F'))
628 return;
629
630 chptr->mode.mode |= mode_type;
631
632 mode_changes[mode_count].letter = c;
633 mode_changes[mode_count].dir = MODE_ADD;
634 mode_changes[mode_count].caps = 0;
635 mode_changes[mode_count].nocaps = 0;
636 mode_changes[mode_count].id = NULL;
637 mode_changes[mode_count].mems = ALL_MEMBERS;
638 mode_changes[mode_count++].arg = NULL;
639 }
640 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
641 {
642 chptr->mode.mode &= ~mode_type;
643
644 mode_changes[mode_count].letter = c;
645 mode_changes[mode_count].dir = MODE_DEL;
646 mode_changes[mode_count].caps = 0;
647 mode_changes[mode_count].nocaps = 0;
648 mode_changes[mode_count].mems = ALL_MEMBERS;
649 mode_changes[mode_count].id = NULL;
650 mode_changes[mode_count++].arg = NULL;
651 }
652 }
653
654 void
655 chm_orphaned(struct Client *source_p, struct Channel *chptr,
656 int alevel, int parc, int *parn,
657 const char **parv, int *errors, int dir, char c, long mode_type)
658 {
659 if(MyClient(source_p))
660 return;
661
662 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
663 {
664 chptr->mode.mode |= mode_type;
665
666 mode_changes[mode_count].letter = c;
667 mode_changes[mode_count].dir = MODE_ADD;
668 mode_changes[mode_count].caps = 0;
669 mode_changes[mode_count].nocaps = 0;
670 mode_changes[mode_count].id = NULL;
671 mode_changes[mode_count].mems = ALL_MEMBERS;
672 mode_changes[mode_count++].arg = NULL;
673 }
674 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
675 {
676 chptr->mode.mode &= ~mode_type;
677
678 mode_changes[mode_count].letter = c;
679 mode_changes[mode_count].dir = MODE_DEL;
680 mode_changes[mode_count].caps = 0;
681 mode_changes[mode_count].nocaps = 0;
682 mode_changes[mode_count].mems = ALL_MEMBERS;
683 mode_changes[mode_count].id = NULL;
684 mode_changes[mode_count++].arg = NULL;
685 }
686 }
687
688 void
689 chm_staff(struct Client *source_p, struct Channel *chptr,
690 int alevel, int parc, int *parn,
691 const char **parv, int *errors, int dir, char c, long mode_type)
692 {
693 if(!IsOper(source_p) && !IsServer(source_p))
694 {
695 if(!(*errors & SM_ERR_NOPRIVS))
696 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
697 *errors |= SM_ERR_NOPRIVS;
698 return;
699 }
700 if(MyClient(source_p) && !IsOperResv(source_p))
701 {
702 if(!(*errors & SM_ERR_NOPRIVS))
703 sendto_one(source_p, form_str(ERR_NOPRIVS), me.name,
704 source_p->name, "resv");
705 *errors |= SM_ERR_NOPRIVS;
706 return;
707 }
708
709 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
710 return;
711
712 /* setting + */
713 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
714 {
715 chptr->mode.mode |= mode_type;
716
717 mode_changes[mode_count].letter = c;
718 mode_changes[mode_count].dir = MODE_ADD;
719 mode_changes[mode_count].caps = 0;
720 mode_changes[mode_count].nocaps = 0;
721 mode_changes[mode_count].id = NULL;
722 mode_changes[mode_count].mems = ALL_MEMBERS;
723 mode_changes[mode_count++].arg = NULL;
724 }
725 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
726 {
727 chptr->mode.mode &= ~mode_type;
728
729 mode_changes[mode_count].letter = c;
730 mode_changes[mode_count].dir = MODE_DEL;
731 mode_changes[mode_count].caps = 0;
732 mode_changes[mode_count].nocaps = 0;
733 mode_changes[mode_count].mems = ALL_MEMBERS;
734 mode_changes[mode_count].id = NULL;
735 mode_changes[mode_count++].arg = NULL;
736 }
737 }
738
739 void
740 chm_ban(struct Client *source_p, struct Channel *chptr,
741 int alevel, int parc, int *parn,
742 const char **parv, int *errors, int dir, char c, long mode_type)
743 {
744 char *mask, *raw_mask, *forward;
745 rb_dlink_list *list;
746 rb_dlink_node *ptr;
747 struct Ban *banptr;
748 int errorval;
749 const char *rpl_list_p;
750 const char *rpl_endlist_p;
751 int caps;
752 int mems;
753
754 switch (mode_type)
755 {
756 case CHFL_BAN:
757 list = &chptr->banlist;
758 errorval = SM_ERR_RPL_B;
759 rpl_list_p = form_str(RPL_BANLIST);
760 rpl_endlist_p = form_str(RPL_ENDOFBANLIST);
761 mems = ALL_MEMBERS;
762 caps = 0;
763 break;
764
765 case CHFL_EXCEPTION:
766 /* if +e is disabled, allow all but +e locally */
767 if(!ConfigChannel.use_except && MyClient(source_p) &&
768 ((dir == MODE_ADD) && (parc > *parn)))
769 return;
770
771 list = &chptr->exceptlist;
772 errorval = SM_ERR_RPL_E;
773 rpl_list_p = form_str(RPL_EXCEPTLIST);
774 rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST);
775 caps = CAP_EX;
776
777 if(ConfigChannel.use_except || (dir == MODE_DEL))
778 mems = ONLY_CHANOPS;
779 else
780 mems = ONLY_SERVERS;
781 break;
782
783 case CHFL_INVEX:
784 /* if +I is disabled, allow all but +I locally */
785 if(!ConfigChannel.use_invex && MyClient(source_p) &&
786 (dir == MODE_ADD) && (parc > *parn))
787 return;
788
789 list = &chptr->invexlist;
790 errorval = SM_ERR_RPL_I;
791 rpl_list_p = form_str(RPL_INVITELIST);
792 rpl_endlist_p = form_str(RPL_ENDOFINVITELIST);
793 caps = CAP_IE;
794
795 if(ConfigChannel.use_invex || (dir == MODE_DEL))
796 mems = ONLY_CHANOPS;
797 else
798 mems = ONLY_SERVERS;
799 break;
800
801 case CHFL_QUIET:
802 list = &chptr->quietlist;
803 errorval = SM_ERR_RPL_Q;
804 rpl_list_p = form_str(RPL_QUIETLIST);
805 rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST);
806 mems = ALL_MEMBERS;
807 caps = 0;
808 break;
809
810 default:
811 sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
812 return;
813 break;
814 }
815
816 if(dir == 0 || parc <= *parn)
817 {
818 if((*errors & errorval) != 0)
819 return;
820 *errors |= errorval;
821
822 /* non-ops cant see +eI lists.. */
823 /* note that this is still permitted if +e/+I are mlocked. */
824 if(alevel != CHFL_CHANOP && mode_type != CHFL_BAN &&
825 mode_type != CHFL_QUIET)
826 {
827 if(!(*errors & SM_ERR_NOOPS))
828 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
829 me.name, source_p->name, chptr->chname);
830 *errors |= SM_ERR_NOOPS;
831 return;
832 }
833
834 RB_DLINK_FOREACH(ptr, list->head)
835 {
836 char buf[BANLEN];
837 banptr = ptr->data;
838 if(banptr->forward)
839 rb_snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward);
840 else
841 rb_strlcpy(buf, banptr->banstr, sizeof(buf));
842
843 sendto_one(source_p, rpl_list_p,
844 me.name, source_p->name, chptr->chname,
845 buf, banptr->who, banptr->when);
846 }
847 sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->chname);
848 return;
849 }
850
851 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
852 return;
853
854
855 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
856 return;
857
858 raw_mask = parv[(*parn)];
859 (*parn)++;
860
861 /* empty ban, or starts with ':' which messes up s2s, ignore it */
862 if(EmptyString(raw_mask) || *raw_mask == ':')
863 return;
864
865 if(!MyClient(source_p))
866 {
867 if(strchr(raw_mask, ' '))
868 return;
869
870 mask = raw_mask;
871 }
872 else
873 mask = pretty_mask(raw_mask);
874
875 /* we'd have problems parsing this, hyb6 does it too
876 * also make sure it will always fit on a line with channel
877 * name etc.
878 */
879 if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5))
880 {
881 sendto_one_numeric(source_p, ERR_INVALIDBAN,
882 form_str(ERR_INVALIDBAN),
883 chptr->chname, c, raw_mask);
884 return;
885 }
886
887 /* Look for a $ after the first character.
888 * As the first character, it marks an extban; afterwards
889 * it delimits a forward channel.
890 */
891 if ((forward = strchr(mask+1, '$')) != NULL)
892 {
893 *forward++ = '\0';
894 if (*forward == '\0')
895 forward = NULL;
896 }
897
898 /* if we're adding a NEW id */
899 if(dir == MODE_ADD)
900 {
901 if (*mask == '$' && MyClient(source_p))
902 {
903 if (!valid_extban(mask, source_p, chptr, mode_type))
904 {
905 sendto_one_numeric(source_p, ERR_INVALIDBAN,
906 form_str(ERR_INVALIDBAN),
907 chptr->chname, c, raw_mask);
908 return;
909 }
910 }
911
912 /* For compatibility, only check the forward channel from
913 * local clients. Accept any forward channel from servers.
914 */
915 if(forward != NULL && MyClient(source_p))
916 {
917 /* For simplicity and future flexibility, do not
918 * allow '$' in forwarding targets.
919 */
920 if(!ConfigChannel.use_forward ||
921 strchr(forward, '$') != NULL)
922 {
923 sendto_one_numeric(source_p, ERR_INVALIDBAN,
924 form_str(ERR_INVALIDBAN),
925 chptr->chname, c, raw_mask);
926 return;
927 }
928 /* check_forward() sends its own error message */
929 if(!check_forward(source_p, chptr, forward))
930 return;
931 /* Forwards only make sense for bans. */
932 if(mode_type != CHFL_BAN)
933 {
934 sendto_one_numeric(source_p, ERR_INVALIDBAN,
935 form_str(ERR_INVALIDBAN),
936 chptr->chname, c, raw_mask);
937 return;
938 }
939 }
940
941 /* dont allow local clients to overflow the banlist, dont
942 * let remote servers set duplicate bans
943 */
944 if(!add_id(source_p, chptr, mask, forward, list, mode_type))
945 return;
946
947 if(forward)
948 forward[-1]= '$';
949
950 mode_changes[mode_count].letter = c;
951 mode_changes[mode_count].dir = MODE_ADD;
952 mode_changes[mode_count].caps = caps;
953 mode_changes[mode_count].nocaps = 0;
954 mode_changes[mode_count].mems = mems;
955 mode_changes[mode_count].id = NULL;
956 mode_changes[mode_count++].arg = mask;
957 }
958 else if(dir == MODE_DEL)
959 {
960 struct Ban *removed;
961 static char buf[BANLEN * MAXMODEPARAMS];
962 int old_removed_mask_pos = removed_mask_pos;
963 if((removed = del_id(chptr, mask, list, mode_type)) == NULL)
964 {
965 /* mask isn't a valid ban, check raw_mask */
966 if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL)
967 mask = raw_mask;
968 }
969
970 if(removed && removed->forward)
971 removed_mask_pos += rb_snprintf(buf + old_removed_mask_pos, sizeof(buf), "%s$%s", removed->banstr, removed->forward) + 1;
972 else
973 removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, mask, sizeof(buf)) + 1;
974 if(removed)
975 {
976 free_ban(removed);
977 removed = NULL;
978 }
979
980 mode_changes[mode_count].letter = c;
981 mode_changes[mode_count].dir = MODE_DEL;
982 mode_changes[mode_count].caps = caps;
983 mode_changes[mode_count].nocaps = 0;
984 mode_changes[mode_count].mems = mems;
985 mode_changes[mode_count].id = NULL;
986 mode_changes[mode_count++].arg = buf + old_removed_mask_pos;
987 }
988 }
989
990 void
991 chm_op(struct Client *source_p, struct Channel *chptr,
992 int alevel, int parc, int *parn,
993 const char **parv, int *errors, int dir, char c, long mode_type)
994 {
995 struct membership *mstptr;
996 const char *opnick;
997 struct Client *targ_p;
998
999 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1000 return;
1001
1002 if((dir == MODE_QUERY) || (parc <= *parn))
1003 return;
1004
1005 opnick = parv[(*parn)];
1006 (*parn)++;
1007
1008 /* empty nick */
1009 if(EmptyString(opnick))
1010 {
1011 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
1012 return;
1013 }
1014
1015 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1016 {
1017 return;
1018 }
1019
1020 mstptr = find_channel_membership(chptr, targ_p);
1021
1022 if(mstptr == NULL)
1023 {
1024 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
1025 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
1026 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
1027 *errors |= SM_ERR_NOTONCHANNEL;
1028 return;
1029 }
1030
1031 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1032 return;
1033
1034 if(dir == MODE_ADD)
1035 {
1036 if(targ_p == source_p && mstptr->flags & CHFL_CHANOP)
1037 return;
1038
1039 mode_changes[mode_count].letter = c;
1040 mode_changes[mode_count].dir = MODE_ADD;
1041 mode_changes[mode_count].caps = 0;
1042 mode_changes[mode_count].nocaps = 0;
1043 mode_changes[mode_count].mems = ALL_MEMBERS;
1044 mode_changes[mode_count].id = targ_p->id;
1045 mode_changes[mode_count].arg = targ_p->name;
1046 mode_changes[mode_count++].client = targ_p;
1047
1048 mstptr->flags |= CHFL_CHANOP;
1049 }
1050 else
1051 {
1052 if(MyClient(source_p) && IsService(targ_p))
1053 {
1054 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
1055 me.name, source_p->name, targ_p->name, chptr->chname);
1056 return;
1057 }
1058
1059 mode_changes[mode_count].letter = c;
1060 mode_changes[mode_count].dir = MODE_DEL;
1061 mode_changes[mode_count].caps = 0;
1062 mode_changes[mode_count].nocaps = 0;
1063 mode_changes[mode_count].mems = ALL_MEMBERS;
1064 mode_changes[mode_count].id = targ_p->id;
1065 mode_changes[mode_count].arg = targ_p->name;
1066 mode_changes[mode_count++].client = targ_p;
1067
1068 mstptr->flags &= ~CHFL_CHANOP;
1069 }
1070 }
1071
1072 void
1073 chm_voice(struct Client *source_p, struct Channel *chptr,
1074 int alevel, int parc, int *parn,
1075 const char **parv, int *errors, int dir, char c, long mode_type)
1076 {
1077 struct membership *mstptr;
1078 const char *opnick;
1079 struct Client *targ_p;
1080
1081 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1082 return;
1083
1084 if((dir == MODE_QUERY) || parc <= *parn)
1085 return;
1086
1087 opnick = parv[(*parn)];
1088 (*parn)++;
1089
1090 /* empty nick */
1091 if(EmptyString(opnick))
1092 {
1093 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
1094 return;
1095 }
1096
1097 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
1098 {
1099 return;
1100 }
1101
1102 mstptr = find_channel_membership(chptr, targ_p);
1103
1104 if(mstptr == NULL)
1105 {
1106 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
1107 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
1108 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
1109 *errors |= SM_ERR_NOTONCHANNEL;
1110 return;
1111 }
1112
1113 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
1114 return;
1115
1116 if(dir == MODE_ADD)
1117 {
1118 mode_changes[mode_count].letter = c;
1119 mode_changes[mode_count].dir = MODE_ADD;
1120 mode_changes[mode_count].caps = 0;
1121 mode_changes[mode_count].nocaps = 0;
1122 mode_changes[mode_count].mems = ALL_MEMBERS;
1123 mode_changes[mode_count].id = targ_p->id;
1124 mode_changes[mode_count].arg = targ_p->name;
1125 mode_changes[mode_count++].client = targ_p;
1126
1127 mstptr->flags |= CHFL_VOICE;
1128 }
1129 else
1130 {
1131 mode_changes[mode_count].letter = 'v';
1132 mode_changes[mode_count].dir = MODE_DEL;
1133 mode_changes[mode_count].caps = 0;
1134 mode_changes[mode_count].nocaps = 0;
1135 mode_changes[mode_count].mems = ALL_MEMBERS;
1136 mode_changes[mode_count].id = targ_p->id;
1137 mode_changes[mode_count].arg = targ_p->name;
1138 mode_changes[mode_count++].client = targ_p;
1139
1140 mstptr->flags &= ~CHFL_VOICE;
1141 }
1142 }
1143
1144 void
1145 chm_limit(struct Client *source_p, struct Channel *chptr,
1146 int alevel, int parc, int *parn,
1147 const char **parv, int *errors, int dir, char c, long mode_type)
1148 {
1149 const char *lstr;
1150 static char limitstr[30];
1151 int limit;
1152
1153 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1154 return;
1155
1156 if(dir == MODE_QUERY)
1157 return;
1158
1159 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1160 return;
1161
1162 if((dir == MODE_ADD) && parc > *parn)
1163 {
1164 lstr = parv[(*parn)];
1165 (*parn)++;
1166
1167 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
1168 return;
1169
1170 rb_sprintf(limitstr, "%d", limit);
1171
1172 mode_changes[mode_count].letter = c;
1173 mode_changes[mode_count].dir = MODE_ADD;
1174 mode_changes[mode_count].caps = 0;
1175 mode_changes[mode_count].nocaps = 0;
1176 mode_changes[mode_count].mems = ALL_MEMBERS;
1177 mode_changes[mode_count].id = NULL;
1178 mode_changes[mode_count++].arg = limitstr;
1179
1180 chptr->mode.limit = limit;
1181 }
1182 else if(dir == MODE_DEL)
1183 {
1184 if(!chptr->mode.limit)
1185 return;
1186
1187 chptr->mode.limit = 0;
1188
1189 mode_changes[mode_count].letter = c;
1190 mode_changes[mode_count].dir = MODE_DEL;
1191 mode_changes[mode_count].caps = 0;
1192 mode_changes[mode_count].nocaps = 0;
1193 mode_changes[mode_count].mems = ALL_MEMBERS;
1194 mode_changes[mode_count].id = NULL;
1195 mode_changes[mode_count++].arg = NULL;
1196 }
1197 }
1198
1199 void
1200 chm_throttle(struct Client *source_p, struct Channel *chptr,
1201 int alevel, int parc, int *parn,
1202 const char **parv, int *errors, int dir, char c, long mode_type)
1203 {
1204 int joins = 0, timeslice = 0;
1205
1206 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1207 return;
1208
1209 if(dir == MODE_QUERY)
1210 return;
1211
1212 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1213 return;
1214
1215 if((dir == MODE_ADD) && parc > *parn)
1216 {
1217 sscanf(parv[(*parn)], "%d:%d", &joins, &timeslice);
1218
1219 if(!joins || !timeslice)
1220 return;
1221
1222 mode_changes[mode_count].letter = c;
1223 mode_changes[mode_count].dir = MODE_ADD;
1224 mode_changes[mode_count].caps = 0;
1225 mode_changes[mode_count].nocaps = 0;
1226 mode_changes[mode_count].mems = ALL_MEMBERS;
1227 mode_changes[mode_count].id = NULL;
1228 mode_changes[mode_count++].arg = parv[(*parn)];
1229
1230 (*parn)++;
1231
1232 chptr->mode.join_num = joins;
1233 chptr->mode.join_time = timeslice;
1234 }
1235 else if(dir == MODE_DEL)
1236 {
1237 if(!chptr->mode.join_num)
1238 return;
1239
1240 chptr->mode.join_num = 0;
1241 chptr->mode.join_time = 0;
1242 chptr->join_count = 0;
1243 chptr->join_delta = 0;
1244
1245 mode_changes[mode_count].letter = c;
1246 mode_changes[mode_count].dir = MODE_DEL;
1247 mode_changes[mode_count].caps = 0;
1248 mode_changes[mode_count].nocaps = 0;
1249 mode_changes[mode_count].mems = ALL_MEMBERS;
1250 mode_changes[mode_count].id = NULL;
1251 mode_changes[mode_count++].arg = NULL;
1252 }
1253 }
1254
1255 void
1256 chm_forward(struct Client *source_p, struct Channel *chptr,
1257 int alevel, int parc, int *parn,
1258 const char **parv, int *errors, int dir, char c, long mode_type)
1259 {
1260 const char *forward;
1261
1262 /* if +f is disabled, ignore local attempts to set it */
1263 if(!ConfigChannel.use_forward && MyClient(source_p) &&
1264 (dir == MODE_ADD) && (parc > *parn))
1265 return;
1266
1267 if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
1268 {
1269 if (!(*errors & SM_ERR_RPL_F))
1270 {
1271 if (*chptr->mode.forward == '\0')
1272 sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname);
1273 else
1274 sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward);
1275 *errors |= SM_ERR_RPL_F;
1276 }
1277 return;
1278 }
1279
1280 #ifndef FORWARD_OPERONLY
1281 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1282 return;
1283 #else
1284 if(!IsOper(source_p) && !IsServer(source_p))
1285 {
1286 if(!(*errors & SM_ERR_NOPRIVS))
1287 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
1288 *errors |= SM_ERR_NOPRIVS;
1289 return;
1290 }
1291 #endif
1292
1293 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1294 return;
1295
1296 if(dir == MODE_ADD && parc > *parn)
1297 {
1298 forward = parv[(*parn)];
1299 (*parn)++;
1300
1301 if(EmptyString(forward))
1302 return;
1303
1304 if(!check_forward(source_p, chptr, forward))
1305 return;
1306
1307 rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
1308
1309 mode_changes[mode_count].letter = c;
1310 mode_changes[mode_count].dir = MODE_ADD;
1311 mode_changes[mode_count].caps = 0;
1312 mode_changes[mode_count].nocaps = 0;
1313 mode_changes[mode_count].mems =
1314 ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS;
1315 mode_changes[mode_count].id = NULL;
1316 mode_changes[mode_count++].arg = forward;
1317 }
1318 else if(dir == MODE_DEL)
1319 {
1320 if(!(*chptr->mode.forward))
1321 return;
1322
1323 *chptr->mode.forward = '\0';
1324
1325 mode_changes[mode_count].letter = c;
1326 mode_changes[mode_count].dir = MODE_DEL;
1327 mode_changes[mode_count].caps = 0;
1328 mode_changes[mode_count].nocaps = 0;
1329 mode_changes[mode_count].mems = ALL_MEMBERS;
1330 mode_changes[mode_count].id = NULL;
1331 mode_changes[mode_count++].arg = NULL;
1332 }
1333 }
1334
1335 void
1336 chm_key(struct Client *source_p, struct Channel *chptr,
1337 int alevel, int parc, int *parn,
1338 const char **parv, int *errors, int dir, char c, long mode_type)
1339 {
1340 char *key;
1341
1342 if(!allow_mode_change(source_p, chptr, alevel, errors, c))
1343 return;
1344
1345 if(dir == MODE_QUERY)
1346 return;
1347
1348 if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE))
1349 return;
1350
1351 if((dir == MODE_ADD) && parc > *parn)
1352 {
1353 key = LOCAL_COPY(parv[(*parn)]);
1354 (*parn)++;
1355
1356 if(MyClient(source_p))
1357 fix_key(key);
1358 else
1359 fix_key_remote(key);
1360
1361 if(EmptyString(key))
1362 return;
1363
1364 s_assert(key[0] != ' ');
1365 rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1366
1367 mode_changes[mode_count].letter = c;
1368 mode_changes[mode_count].dir = MODE_ADD;
1369 mode_changes[mode_count].caps = 0;
1370 mode_changes[mode_count].nocaps = 0;
1371 mode_changes[mode_count].mems = ALL_MEMBERS;
1372 mode_changes[mode_count].id = NULL;
1373 mode_changes[mode_count++].arg = chptr->mode.key;
1374 }
1375 else if(dir == MODE_DEL)
1376 {
1377 static char splat[] = "*";
1378 int i;
1379
1380 if(parc > *parn)
1381 (*parn)++;
1382
1383 if(!(*chptr->mode.key))
1384 return;
1385
1386 /* hack time. when we get a +k-k mode, the +k arg is
1387 * chptr->mode.key, which the -k sets to \0, so hunt for a
1388 * +k when we get a -k, and set the arg to splat. --anfl
1389 */
1390 for(i = 0; i < mode_count; i++)
1391 {
1392 if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
1393 mode_changes[i].arg = splat;
1394 }
1395
1396 *chptr->mode.key = 0;
1397
1398 mode_changes[mode_count].letter = c;
1399 mode_changes[mode_count].dir = MODE_DEL;
1400 mode_changes[mode_count].caps = 0;
1401 mode_changes[mode_count].nocaps = 0;
1402 mode_changes[mode_count].mems = ALL_MEMBERS;
1403 mode_changes[mode_count].id = NULL;
1404 mode_changes[mode_count++].arg = "*";
1405 }
1406 }
1407
1408 /* *INDENT-OFF* */
1409 struct ChannelMode chmode_table[256] =
1410 {
1411 {chm_nosuch, 0 }, /* 0x00 */
1412 {chm_nosuch, 0 }, /* 0x01 */
1413 {chm_nosuch, 0 }, /* 0x02 */
1414 {chm_nosuch, 0 }, /* 0x03 */
1415 {chm_nosuch, 0 }, /* 0x04 */
1416 {chm_nosuch, 0 }, /* 0x05 */
1417 {chm_nosuch, 0 }, /* 0x06 */
1418 {chm_nosuch, 0 }, /* 0x07 */
1419 {chm_nosuch, 0 }, /* 0x08 */
1420 {chm_nosuch, 0 }, /* 0x09 */
1421 {chm_nosuch, 0 }, /* 0x0a */
1422 {chm_nosuch, 0 }, /* 0x0b */
1423 {chm_nosuch, 0 }, /* 0x0c */
1424 {chm_nosuch, 0 }, /* 0x0d */
1425 {chm_nosuch, 0 }, /* 0x0e */
1426 {chm_nosuch, 0 }, /* 0x0f */
1427 {chm_nosuch, 0 }, /* 0x10 */
1428 {chm_nosuch, 0 }, /* 0x11 */
1429 {chm_nosuch, 0 }, /* 0x12 */
1430 {chm_nosuch, 0 }, /* 0x13 */
1431 {chm_nosuch, 0 }, /* 0x14 */
1432 {chm_nosuch, 0 }, /* 0x15 */
1433 {chm_nosuch, 0 }, /* 0x16 */
1434 {chm_nosuch, 0 }, /* 0x17 */
1435 {chm_nosuch, 0 }, /* 0x18 */
1436 {chm_nosuch, 0 }, /* 0x19 */
1437 {chm_nosuch, 0 }, /* 0x1a */
1438 {chm_nosuch, 0 }, /* 0x1b */
1439 {chm_nosuch, 0 }, /* 0x1c */
1440 {chm_nosuch, 0 }, /* 0x1d */
1441 {chm_nosuch, 0 }, /* 0x1e */
1442 {chm_nosuch, 0 }, /* 0x1f */
1443 {chm_nosuch, 0 }, /* 0x20 */
1444 {chm_nosuch, 0 }, /* 0x21 */
1445 {chm_nosuch, 0 }, /* 0x22 */
1446 {chm_nosuch, 0 }, /* 0x23 */
1447 {chm_nosuch, 0 }, /* 0x24 */
1448 {chm_nosuch, 0 }, /* 0x25 */
1449 {chm_nosuch, 0 }, /* 0x26 */
1450 {chm_nosuch, 0 }, /* 0x27 */
1451 {chm_nosuch, 0 }, /* 0x28 */
1452 {chm_nosuch, 0 }, /* 0x29 */
1453 {chm_nosuch, 0 }, /* 0x2a */
1454 {chm_nosuch, 0 }, /* 0x2b */
1455 {chm_nosuch, 0 }, /* 0x2c */
1456 {chm_nosuch, 0 }, /* 0x2d */
1457 {chm_nosuch, 0 }, /* 0x2e */
1458 {chm_nosuch, 0 }, /* 0x2f */
1459 {chm_nosuch, 0 }, /* 0x30 */
1460 {chm_nosuch, 0 }, /* 0x31 */
1461 {chm_nosuch, 0 }, /* 0x32 */
1462 {chm_nosuch, 0 }, /* 0x33 */
1463 {chm_nosuch, 0 }, /* 0x34 */
1464 {chm_nosuch, 0 }, /* 0x35 */
1465 {chm_nosuch, 0 }, /* 0x36 */
1466 {chm_nosuch, 0 }, /* 0x37 */
1467 {chm_nosuch, 0 }, /* 0x38 */
1468 {chm_nosuch, 0 }, /* 0x39 */
1469 {chm_nosuch, 0 }, /* 0x3a */
1470 {chm_nosuch, 0 }, /* 0x3b */
1471 {chm_nosuch, 0 }, /* 0x3c */
1472 {chm_nosuch, 0 }, /* 0x3d */
1473 {chm_nosuch, 0 }, /* 0x3e */
1474 {chm_nosuch, 0 }, /* 0x3f */
1475
1476 {chm_nosuch, 0 }, /* @ */
1477 {chm_nosuch, 0 }, /* A */
1478 {chm_nosuch, 0 }, /* B */
1479 {chm_nosuch, 0 }, /* C */
1480 {chm_nosuch, 0 }, /* D */
1481 {chm_nosuch, 0 }, /* E */
1482 {chm_simple, MODE_FREETARGET }, /* F */
1483 {chm_nosuch, 0 }, /* G */
1484 {chm_nosuch, 0 }, /* H */
1485 {chm_ban, CHFL_INVEX }, /* I */
1486 {chm_nosuch, 0 }, /* J */
1487 {chm_nosuch, 0 }, /* K */
1488 {chm_staff, MODE_EXLIMIT }, /* L */
1489 {chm_nosuch, 0 }, /* M */
1490 {chm_nosuch, 0 }, /* N */
1491 {chm_nosuch, 0 }, /* O */
1492 {chm_staff, MODE_PERMANENT }, /* P */
1493 {chm_simple, MODE_DISFORWARD }, /* Q */
1494 {chm_nosuch, 0 }, /* R */
1495 {chm_nosuch, 0 }, /* S */
1496 {chm_nosuch, 0 }, /* T */
1497 {chm_nosuch, 0 }, /* U */
1498 {chm_nosuch, 0 }, /* V */
1499 {chm_nosuch, 0 }, /* W */
1500 {chm_nosuch, 0 }, /* X */
1501 {chm_nosuch, 0 }, /* Y */
1502 {chm_nosuch, 0 }, /* Z */
1503 {chm_nosuch, 0 },
1504 {chm_nosuch, 0 },
1505 {chm_nosuch, 0 },
1506 {chm_nosuch, 0 },
1507 {chm_nosuch, 0 },
1508 {chm_nosuch, 0 },
1509 {chm_nosuch, 0 }, /* a */
1510 {chm_ban, CHFL_BAN }, /* b */
1511 {chm_nosuch, 0 }, /* c */
1512 {chm_nosuch, 0 }, /* d */
1513 {chm_ban, CHFL_EXCEPTION }, /* e */
1514 {chm_forward, 0 }, /* f */
1515 {chm_simple, MODE_FREEINVITE }, /* g */
1516 {chm_nosuch, 0 }, /* h */
1517 {chm_simple, MODE_INVITEONLY }, /* i */
1518 {chm_throttle, 0 }, /* j */
1519 {chm_key, 0 }, /* k */
1520 {chm_limit, 0 }, /* l */
1521 {chm_simple, MODE_MODERATED }, /* m */
1522 {chm_simple, MODE_NOPRIVMSGS }, /* n */
1523 {chm_op, 0 }, /* o */
1524 {chm_simple, MODE_PRIVATE }, /* p */
1525 {chm_ban, CHFL_QUIET }, /* q */
1526 {chm_simple, MODE_REGONLY }, /* r */
1527 {chm_simple, MODE_SECRET }, /* s */
1528 {chm_simple, MODE_TOPICLIMIT }, /* t */
1529 {chm_nosuch, 0 }, /* u */
1530 {chm_voice, 0 }, /* v */
1531 {chm_nosuch, 0 }, /* w */
1532 {chm_nosuch, 0 }, /* x */
1533 {chm_nosuch, 0 }, /* y */
1534 {chm_simple, MODE_OPMODERATE }, /* z */
1535
1536 {chm_nosuch, 0 }, /* 0x7b */
1537 {chm_nosuch, 0 }, /* 0x7c */
1538 {chm_nosuch, 0 }, /* 0x7d */
1539 {chm_nosuch, 0 }, /* 0x7e */
1540 {chm_nosuch, 0 }, /* 0x7f */
1541
1542 {chm_nosuch, 0 }, /* 0x80 */
1543 {chm_nosuch, 0 }, /* 0x81 */
1544 {chm_nosuch, 0 }, /* 0x82 */
1545 {chm_nosuch, 0 }, /* 0x83 */
1546 {chm_nosuch, 0 }, /* 0x84 */
1547 {chm_nosuch, 0 }, /* 0x85 */
1548 {chm_nosuch, 0 }, /* 0x86 */
1549 {chm_nosuch, 0 }, /* 0x87 */
1550 {chm_nosuch, 0 }, /* 0x88 */
1551 {chm_nosuch, 0 }, /* 0x89 */
1552 {chm_nosuch, 0 }, /* 0x8a */
1553 {chm_nosuch, 0 }, /* 0x8b */
1554 {chm_nosuch, 0 }, /* 0x8c */
1555 {chm_nosuch, 0 }, /* 0x8d */
1556 {chm_nosuch, 0 }, /* 0x8e */
1557 {chm_nosuch, 0 }, /* 0x8f */
1558
1559 {chm_nosuch, 0 }, /* 0x90 */
1560 {chm_nosuch, 0 }, /* 0x91 */
1561 {chm_nosuch, 0 }, /* 0x92 */
1562 {chm_nosuch, 0 }, /* 0x93 */
1563 {chm_nosuch, 0 }, /* 0x94 */
1564 {chm_nosuch, 0 }, /* 0x95 */
1565 {chm_nosuch, 0 }, /* 0x96 */
1566 {chm_nosuch, 0 }, /* 0x97 */
1567 {chm_nosuch, 0 }, /* 0x98 */
1568 {chm_nosuch, 0 }, /* 0x99 */
1569 {chm_nosuch, 0 }, /* 0x9a */
1570 {chm_nosuch, 0 }, /* 0x9b */
1571 {chm_nosuch, 0 }, /* 0x9c */
1572 {chm_nosuch, 0 }, /* 0x9d */
1573 {chm_nosuch, 0 }, /* 0x9e */
1574 {chm_nosuch, 0 }, /* 0x9f */
1575
1576 {chm_nosuch, 0 }, /* 0xa0 */
1577 {chm_nosuch, 0 }, /* 0xa1 */
1578 {chm_nosuch, 0 }, /* 0xa2 */
1579 {chm_nosuch, 0 }, /* 0xa3 */
1580 {chm_nosuch, 0 }, /* 0xa4 */
1581 {chm_nosuch, 0 }, /* 0xa5 */
1582 {chm_nosuch, 0 }, /* 0xa6 */
1583 {chm_nosuch, 0 }, /* 0xa7 */
1584 {chm_nosuch, 0 }, /* 0xa8 */
1585 {chm_nosuch, 0 }, /* 0xa9 */
1586 {chm_nosuch, 0 }, /* 0xaa */
1587 {chm_nosuch, 0 }, /* 0xab */
1588 {chm_nosuch, 0 }, /* 0xac */
1589 {chm_nosuch, 0 }, /* 0xad */
1590 {chm_nosuch, 0 }, /* 0xae */
1591 {chm_nosuch, 0 }, /* 0xaf */
1592
1593 {chm_nosuch, 0 }, /* 0xb0 */
1594 {chm_nosuch, 0 }, /* 0xb1 */
1595 {chm_nosuch, 0 }, /* 0xb2 */
1596 {chm_nosuch, 0 }, /* 0xb3 */
1597 {chm_nosuch, 0 }, /* 0xb4 */
1598 {chm_nosuch, 0 }, /* 0xb5 */
1599 {chm_nosuch, 0 }, /* 0xb6 */
1600 {chm_nosuch, 0 }, /* 0xb7 */
1601 {chm_nosuch, 0 }, /* 0xb8 */
1602 {chm_nosuch, 0 }, /* 0xb9 */
1603 {chm_nosuch, 0 }, /* 0xba */
1604 {chm_nosuch, 0 }, /* 0xbb */
1605 {chm_nosuch, 0 }, /* 0xbc */
1606 {chm_nosuch, 0 }, /* 0xbd */
1607 {chm_nosuch, 0 }, /* 0xbe */
1608 {chm_nosuch, 0 }, /* 0xbf */
1609
1610 {chm_nosuch, 0 }, /* 0xc0 */
1611 {chm_nosuch, 0 }, /* 0xc1 */
1612 {chm_nosuch, 0 }, /* 0xc2 */
1613 {chm_nosuch, 0 }, /* 0xc3 */
1614 {chm_nosuch, 0 }, /* 0xc4 */
1615 {chm_nosuch, 0 }, /* 0xc5 */
1616 {chm_nosuch, 0 }, /* 0xc6 */
1617 {chm_nosuch, 0 }, /* 0xc7 */
1618 {chm_nosuch, 0 }, /* 0xc8 */
1619 {chm_nosuch, 0 }, /* 0xc9 */
1620 {chm_nosuch, 0 }, /* 0xca */
1621 {chm_nosuch, 0 }, /* 0xcb */
1622 {chm_nosuch, 0 }, /* 0xcc */
1623 {chm_nosuch, 0 }, /* 0xcd */
1624 {chm_nosuch, 0 }, /* 0xce */
1625 {chm_nosuch, 0 }, /* 0xcf */
1626
1627 {chm_nosuch, 0 }, /* 0xd0 */
1628 {chm_nosuch, 0 }, /* 0xd1 */
1629 {chm_nosuch, 0 }, /* 0xd2 */
1630 {chm_nosuch, 0 }, /* 0xd3 */
1631 {chm_nosuch, 0 }, /* 0xd4 */
1632 {chm_nosuch, 0 }, /* 0xd5 */
1633 {chm_nosuch, 0 }, /* 0xd6 */
1634 {chm_nosuch, 0 }, /* 0xd7 */
1635 {chm_nosuch, 0 }, /* 0xd8 */
1636 {chm_nosuch, 0 }, /* 0xd9 */
1637 {chm_nosuch, 0 }, /* 0xda */
1638 {chm_nosuch, 0 }, /* 0xdb */
1639 {chm_nosuch, 0 }, /* 0xdc */
1640 {chm_nosuch, 0 }, /* 0xdd */
1641 {chm_nosuch, 0 }, /* 0xde */
1642 {chm_nosuch, 0 }, /* 0xdf */
1643
1644 {chm_nosuch, 0 }, /* 0xe0 */
1645 {chm_nosuch, 0 }, /* 0xe1 */
1646 {chm_nosuch, 0 }, /* 0xe2 */
1647 {chm_nosuch, 0 }, /* 0xe3 */
1648 {chm_nosuch, 0 }, /* 0xe4 */
1649 {chm_nosuch, 0 }, /* 0xe5 */
1650 {chm_nosuch, 0 }, /* 0xe6 */
1651 {chm_nosuch, 0 }, /* 0xe7 */
1652 {chm_nosuch, 0 }, /* 0xe8 */
1653 {chm_nosuch, 0 }, /* 0xe9 */
1654 {chm_nosuch, 0 }, /* 0xea */
1655 {chm_nosuch, 0 }, /* 0xeb */
1656 {chm_nosuch, 0 }, /* 0xec */
1657 {chm_nosuch, 0 }, /* 0xed */
1658 {chm_nosuch, 0 }, /* 0xee */
1659 {chm_nosuch, 0 }, /* 0xef */
1660
1661 {chm_nosuch, 0 }, /* 0xf0 */
1662 {chm_nosuch, 0 }, /* 0xf1 */
1663 {chm_nosuch, 0 }, /* 0xf2 */
1664 {chm_nosuch, 0 }, /* 0xf3 */
1665 {chm_nosuch, 0 }, /* 0xf4 */
1666 {chm_nosuch, 0 }, /* 0xf5 */
1667 {chm_nosuch, 0 }, /* 0xf6 */
1668 {chm_nosuch, 0 }, /* 0xf7 */
1669 {chm_nosuch, 0 }, /* 0xf8 */
1670 {chm_nosuch, 0 }, /* 0xf9 */
1671 {chm_nosuch, 0 }, /* 0xfa */
1672 {chm_nosuch, 0 }, /* 0xfb */
1673 {chm_nosuch, 0 }, /* 0xfc */
1674 {chm_nosuch, 0 }, /* 0xfd */
1675 {chm_nosuch, 0 }, /* 0xfe */
1676 {chm_nosuch, 0 }, /* 0xff */
1677 };
1678
1679 /* *INDENT-ON* */
1680
1681 /* set_channel_mode()
1682 *
1683 * inputs - client, source, channel, membership pointer, params
1684 * output -
1685 * side effects - channel modes/memberships are changed, MODE is issued
1686 *
1687 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1688 */
1689 void
1690 set_channel_mode(struct Client *client_p, struct Client *source_p,
1691 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[])
1692 {
1693 static char modebuf[BUFSIZE];
1694 static char parabuf[BUFSIZE];
1695 char *mbuf;
1696 char *pbuf;
1697 int cur_len, mlen, paralen, paracount, arglen, len;
1698 int i, j, flags;
1699 int dir = MODE_ADD;
1700 int parn = 1;
1701 int errors = 0;
1702 int alevel;
1703 const char *ml = parv[0];
1704 char c;
1705 struct Client *fakesource_p;
1706
1707 mask_pos = 0;
1708 removed_mask_pos = 0;
1709 mode_count = 0;
1710 mode_limit = 0;
1711 mode_limit_simple = 0;
1712
1713 alevel = get_channel_access(source_p, msptr);
1714
1715 /* Hide connecting server on netburst -- jilles */
1716 if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
1717 fakesource_p = &me;
1718 else
1719 fakesource_p = source_p;
1720
1721 for(; (c = *ml) != 0; ml++)
1722 {
1723 switch (c)
1724 {
1725 case '+':
1726 dir = MODE_ADD;
1727 break;
1728 case '-':
1729 dir = MODE_DEL;
1730 break;
1731 case '=':
1732 dir = MODE_QUERY;
1733 break;
1734 default:
1735 chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel,
1736 parc, &parn, parv,
1737 &errors, dir, c,
1738 chmode_table[(unsigned char) c].mode_type);
1739 break;
1740 }
1741 }
1742
1743 /* bail out if we have nothing to do... */
1744 if(!mode_count)
1745 return;
1746
1747 if(IsServer(source_p))
1748 mlen = rb_sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname);
1749 else
1750 mlen = rb_sprintf(modebuf, ":%s!%s@%s MODE %s ",
1751 source_p->name, source_p->username,
1752 source_p->host, chptr->chname);
1753
1754 for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS)
1755 {
1756 cur_len = mlen;
1757 mbuf = modebuf + mlen;
1758 pbuf = parabuf;
1759 parabuf[0] = '\0';
1760 paracount = paralen = 0;
1761 dir = MODE_QUERY;
1762
1763 for(i = 0; i < mode_count; i++)
1764 {
1765 if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
1766 continue;
1767
1768 if(mode_changes[i].arg != NULL)
1769 {
1770 arglen = strlen(mode_changes[i].arg);
1771
1772 if(arglen > MODEBUFLEN - 5)
1773 continue;
1774 }
1775 else
1776 arglen = 0;
1777
1778 /* if we're creeping over MAXMODEPARAMSSERV, or over
1779 * bufsize (4 == +/-,modechar,two spaces) send now.
1780 */
1781 if(mode_changes[i].arg != NULL &&
1782 ((paracount == MAXMODEPARAMSSERV) ||
1783 ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
1784 {
1785 *mbuf = '\0';
1786
1787 if(cur_len > mlen)
1788 sendto_channel_local(flags, chptr, "%s %s", modebuf,
1789 parabuf);
1790 else
1791 continue;
1792
1793 paracount = paralen = 0;
1794 cur_len = mlen;
1795 mbuf = modebuf + mlen;
1796 pbuf = parabuf;
1797 parabuf[0] = '\0';
1798 dir = MODE_QUERY;
1799 }
1800
1801 if(dir != mode_changes[i].dir)
1802 {
1803 *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1804 cur_len++;
1805 dir = mode_changes[i].dir;
1806 }
1807
1808 *mbuf++ = mode_changes[i].letter;
1809 cur_len++;
1810
1811 if(mode_changes[i].arg != NULL)
1812 {
1813 paracount++;
1814 len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg);
1815 pbuf += len;
1816 paralen += len;
1817 }
1818 }
1819
1820 if(paralen && parabuf[paralen - 1] == ' ')
1821 parabuf[paralen - 1] = '\0';
1822
1823 *mbuf = '\0';
1824 if(cur_len > mlen)
1825 sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
1826 }
1827
1828 /* only propagate modes originating locally, or if we're hubbing */
1829 if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1)
1830 send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);
1831 }
1832
1833 /* set_channel_mlock()
1834 *
1835 * inputs - client, source, channel, params
1836 * output -
1837 * side effects - channel mlock is changed / MLOCK is propagated
1838 */
1839 void
1840 set_channel_mlock(struct Client *client_p, struct Client *source_p,
1841 struct Channel *chptr, const char *newmlock, int propagate)
1842 {
1843 rb_free(chptr->mode_lock);
1844 chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL;
1845
1846 if (propagate)
1847 {
1848 sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s",
1849 source_p->id, (long) chptr->channelts, chptr->chname,
1850 chptr->mode_lock ? chptr->mode_lock : "");
1851 }
1852 }