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