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