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