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