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