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