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