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