Restore stats_spy hook that was removed in commit 401f2454671ca233e35b0e6e4f3fa4c43cd...
[seven-1.x.git] / src / chmode.c
blob213d9bb881d2979da4f732f2713a426d8b43964e
1 /*
2 * charybdis: A slightly useful ircd.
3 * chmode.c: channel mode management
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
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.
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.
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
26 #include "stdinc.h"
27 #include "tools.h"
28 #include "channel.h"
29 #include "client.h"
30 #include "common.h"
31 #include "hash.h"
32 #include "hook.h"
33 #include "irc_string.h"
34 #include "sprintf_irc.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 "event.h"
44 #include "memory.h"
45 #include "balloc.h"
46 #include "s_log.h"
48 /* bitmasks for error returns, so we send once per call */
49 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
50 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
51 #define SM_ERR_UNKNOWN 0x00000004
52 #define SM_ERR_RPL_C 0x00000008
53 #define SM_ERR_RPL_B 0x00000010
54 #define SM_ERR_RPL_E 0x00000020
55 #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
56 #define SM_ERR_RPL_I 0x00000100
57 #define SM_ERR_RPL_D 0x00000200
58 #define SM_ERR_NOPRIVS 0x00000400
59 #define SM_ERR_RPL_Q 0x00000800
60 #define SM_ERR_RPL_F 0x00001000
62 void set_channel_mode(struct Client *, struct Client *,
63 struct Channel *, struct membership *, int, const char **);
65 int add_id(struct Client *source_p, struct Channel *chptr,
66 const char *banid, dlink_list * list, long mode_type);
68 static struct ChModeChange mode_changes[BUFSIZE];
69 static int mode_count;
70 static int mode_limit;
71 static int mask_pos;
73 int
74 get_channel_access(struct Client *source_p, struct membership *msptr)
76 if(!MyClient(source_p) || is_chanop(msptr))
77 return CHFL_CHANOP;
79 return CHFL_PEON;
82 /* add_id()
84 * inputs - client, channel, id to add, type
85 * outputs - 0 on failure, 1 on success
86 * side effects - given id is added to the appropriate list
88 int
89 add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
90 dlink_list * list, long mode_type)
92 struct Ban *actualBan;
93 static char who[BANLEN];
94 char *realban = LOCAL_COPY(banid);
95 dlink_node *ptr;
97 /* dont let local clients overflow the banlist, or set redundant
98 * bans
100 if(MyClient(source_p))
102 if(chptr->num_mask >= (chptr->mode.banlimit > 0 ? chptr->mode.banlimit : ConfigChannel.max_bans))
104 sendto_one(source_p, form_str(ERR_BANLISTFULL),
105 me.name, source_p->name, chptr->chname, realban);
106 return 0;
109 collapse(realban);
111 DLINK_FOREACH(ptr, list->head)
113 actualBan = ptr->data;
114 if(match(actualBan->banstr, realban))
115 return 0;
118 /* dont let remotes set duplicates */
119 else
121 DLINK_FOREACH(ptr, list->head)
123 actualBan = ptr->data;
124 if(!irccmp(actualBan->banstr, realban))
125 return 0;
130 if(IsPerson(source_p))
131 ircsprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
132 else
133 strlcpy(who, source_p->name, sizeof(who));
135 actualBan = allocate_ban(realban, who);
136 actualBan->when = CurrentTime;
138 dlinkAdd(actualBan, &actualBan->node, list);
139 chptr->num_mask++;
141 /* invalidate the can_send() cache */
142 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
143 chptr->bants++;
145 return 1;
148 /* del_id()
150 * inputs - channel, id to remove, type
151 * outputs - 0 on failure, 1 on success
152 * side effects - given id is removed from the appropriate list
155 del_id(struct Channel *chptr, const char *banid, dlink_list * list, long mode_type)
157 dlink_node *ptr;
158 struct Ban *banptr;
160 if(EmptyString(banid))
161 return 0;
163 DLINK_FOREACH(ptr, list->head)
165 banptr = ptr->data;
167 if(irccmp(banid, banptr->banstr) == 0)
169 dlinkDelete(&banptr->node, list);
170 free_ban(banptr);
172 /* num_mask should never be < 0 */
173 if(chptr->num_mask > 0)
174 chptr->num_mask--;
175 else
176 chptr->num_mask = 0;
178 /* invalidate the can_send() cache */
179 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
180 chptr->bants++;
182 return 1;
186 return 0;
189 /* check_string()
191 * input - string to check
192 * output - pointer to 'fixed' string, or "*" if empty
193 * side effects - any white space found becomes \0
195 static char *
196 check_string(char *s)
198 char *str = s;
199 static char splat[] = "*";
200 if(!(s && *s))
201 return splat;
203 for(; *s; ++s)
205 if(IsSpace(*s))
207 *s = '\0';
208 break;
211 return str;
214 /* pretty_mask()
216 * inputs - mask to pretty
217 * outputs - better version of the mask
218 * side effects - mask is chopped to limits, and transformed:
219 * x!y@z => x!y@z
220 * y@z => *!y@z
221 * x!y => x!y@*
222 * x => x!*@*
223 * z.d => *!*@z.d
225 static char *
226 pretty_mask(const char *idmask)
228 static char mask_buf[BUFSIZE];
229 int old_mask_pos;
230 char *nick, *user, *host;
231 char splat[] = "*";
232 char *t, *at, *ex;
233 char ne = 0, ue = 0, he = 0; /* save values at nick[NICKLEN], et all */
234 char *mask;
236 mask = LOCAL_COPY(idmask);
237 mask = check_string(mask);
238 collapse(mask);
240 nick = user = host = splat;
242 if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5)
243 return NULL;
245 old_mask_pos = mask_pos;
247 if (*mask == '$')
249 mask_pos += ircsprintf(mask_buf + mask_pos, "%s", mask) + 1;
250 t = mask_buf + old_mask_pos + 1;
251 if (*t == '!')
252 *t = '~';
253 if (*t == '~')
254 t++;
255 *t = ToLower(*t);
256 return mask_buf + old_mask_pos;
259 at = ex = NULL;
260 if((t = strchr(mask, '@')) != NULL)
262 at = t;
263 *t++ = '\0';
264 if(*t != '\0')
265 host = t;
267 if((t = strchr(mask, '!')) != NULL)
269 ex = t;
270 *t++ = '\0';
271 if(*t != '\0')
272 user = t;
273 if(*mask != '\0')
274 nick = mask;
276 else
278 if(*mask != '\0')
279 user = mask;
282 else if((t = strchr(mask, '!')) != NULL)
284 ex = t;
285 *t++ = '\0';
286 if(*mask != '\0')
287 nick = mask;
288 if(*t != '\0')
289 user = t;
291 else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
293 if(*mask != '\0')
294 host = mask;
296 else
298 if(*mask != '\0')
299 nick = mask;
302 /* truncate values to max lengths */
303 if(strlen(nick) > NICKLEN - 1)
305 ne = nick[NICKLEN - 1];
306 nick[NICKLEN - 1] = '\0';
308 if(strlen(user) > USERLEN)
310 ue = user[USERLEN];
311 user[USERLEN] = '\0';
313 if(strlen(host) > HOSTLEN)
315 he = host[HOSTLEN];
316 host[HOSTLEN] = '\0';
319 mask_pos += ircsprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
321 /* restore mask, since we may need to use it again later */
322 if(at)
323 *at = '@';
324 if(ex)
325 *ex = '!';
326 if(ne)
327 nick[NICKLEN - 1] = ne;
328 if(ue)
329 user[USERLEN] = ue;
330 if(he)
331 host[HOSTLEN] = he;
333 return mask_buf + old_mask_pos;
336 /* fix_key()
338 * input - key to fix
339 * output - the same key, fixed
340 * side effects - anything below ascii 13 is discarded, ':' discarded,
341 * high ascii is dropped to lower half of ascii table
343 static char *
344 fix_key(char *arg)
346 u_char *s, *t, c;
348 for(s = t = (u_char *) arg; (c = *s); s++)
350 c &= 0x7f;
351 if(c != ':' && c != ',' && c > ' ')
352 *t++ = c;
355 *t = '\0';
356 return arg;
359 /* fix_key_remote()
361 * input - key to fix
362 * ouput - the same key, fixed
363 * side effects - high ascii dropped to lower half of table,
364 * CR/LF/':' are dropped
366 static char *
367 fix_key_remote(char *arg)
369 u_char *s, *t, c;
371 for(s = t = (u_char *) arg; (c = *s); s++)
373 c &= 0x7f;
374 if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
375 *t++ = c;
378 *t = '\0';
379 return arg;
382 /* chm_*()
384 * The handlers for each specific mode.
386 void
387 chm_nosuch(struct Client *source_p, struct Channel *chptr,
388 int alevel, int parc, int *parn,
389 const char **parv, int *errors, int dir, char c, long mode_type)
391 if(*errors & SM_ERR_UNKNOWN)
392 return;
393 *errors |= SM_ERR_UNKNOWN;
394 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
397 void
398 chm_simple(struct Client *source_p, struct Channel *chptr,
399 int alevel, int parc, int *parn,
400 const char **parv, int *errors, int dir, char c, long mode_type)
402 if(alevel != CHFL_CHANOP)
404 if(!(*errors & SM_ERR_NOOPS))
405 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
406 me.name, source_p->name, chptr->chname);
407 *errors |= SM_ERR_NOOPS;
408 return;
412 * XXX: This needs 'fixing'; hard coding magic numbers like this is fucking
413 * silly...
416 /* +ntspmaikl == 9 + MAXMODEPARAMS (4 * +o) */
417 if(MyClient(source_p) && (++mode_limit > (9 + MAXMODEPARAMS)))
418 return;
420 /* setting + */
421 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
423 chptr->mode.mode |= mode_type;
425 mode_changes[mode_count].letter = c;
426 mode_changes[mode_count].dir = MODE_ADD;
427 mode_changes[mode_count].caps = 0;
428 mode_changes[mode_count].nocaps = 0;
429 mode_changes[mode_count].id = NULL;
430 mode_changes[mode_count].mems = ALL_MEMBERS;
431 mode_changes[mode_count++].arg = NULL;
433 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
435 chptr->mode.mode &= ~mode_type;
437 mode_changes[mode_count].letter = c;
438 mode_changes[mode_count].dir = MODE_DEL;
439 mode_changes[mode_count].caps = 0;
440 mode_changes[mode_count].nocaps = 0;
441 mode_changes[mode_count].mems = ALL_MEMBERS;
442 mode_changes[mode_count].id = NULL;
443 mode_changes[mode_count++].arg = NULL;
447 void
448 chm_staff(struct Client *source_p, struct Channel *chptr,
449 int alevel, int parc, int *parn,
450 const char **parv, int *errors, int dir, char c, long mode_type)
452 if(!IsServer(source_p) && MyClient(source_p) && !IsOperCModes(source_p))
454 if(!(*errors & SM_ERR_NOPRIVS))
456 if(IsOper(source_p))
457 sendto_one(source_p, form_str(ERR_NOPRIVS),
458 me.name, source_p->name, "set_cmode");
459 else
460 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
462 *errors |= SM_ERR_NOPRIVS;
463 return;
466 /* setting + */
467 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
469 chptr->mode.mode |= mode_type;
471 mode_changes[mode_count].letter = c;
472 mode_changes[mode_count].dir = MODE_ADD;
473 mode_changes[mode_count].caps = 0;
474 mode_changes[mode_count].nocaps = 0;
475 mode_changes[mode_count].id = NULL;
476 mode_changes[mode_count].mems = ALL_MEMBERS;
477 mode_changes[mode_count++].arg = NULL;
479 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
481 chptr->mode.mode &= ~mode_type;
483 mode_changes[mode_count].letter = c;
484 mode_changes[mode_count].dir = MODE_DEL;
485 mode_changes[mode_count].caps = 0;
486 mode_changes[mode_count].nocaps = 0;
487 mode_changes[mode_count].mems = ALL_MEMBERS;
488 mode_changes[mode_count].id = NULL;
489 mode_changes[mode_count++].arg = NULL;
493 void
494 chm_ban(struct Client *source_p, struct Channel *chptr,
495 int alevel, int parc, int *parn,
496 const char **parv, int *errors, int dir, char c, long mode_type)
498 const char *mask;
499 const char *raw_mask;
500 dlink_list *list;
501 dlink_node *ptr;
502 struct Ban *banptr;
503 int errorval;
504 int rpl_list;
505 int rpl_endlist;
506 int caps;
507 int mems;
509 switch (mode_type)
511 case CHFL_BAN:
512 list = &chptr->banlist;
513 errorval = SM_ERR_RPL_B;
514 rpl_list = RPL_BANLIST;
515 rpl_endlist = RPL_ENDOFBANLIST;
516 mems = ALL_MEMBERS;
517 caps = 0;
518 break;
520 case CHFL_EXCEPTION:
521 /* if +e is disabled, allow all but +e locally */
522 if(!ConfigChannel.use_except && MyClient(source_p) &&
523 ((dir == MODE_ADD) && (parc > *parn)))
524 return;
526 list = &chptr->exceptlist;
527 errorval = SM_ERR_RPL_E;
528 rpl_list = RPL_EXCEPTLIST;
529 rpl_endlist = RPL_ENDOFEXCEPTLIST;
530 caps = CAP_EX;
532 if(ConfigChannel.use_except || (dir == MODE_DEL))
533 mems = ONLY_CHANOPS;
534 else
535 mems = ONLY_SERVERS;
536 break;
538 case CHFL_INVEX:
539 /* if +I is disabled, allow all but +I locally */
540 if(!ConfigChannel.use_invex && MyClient(source_p) &&
541 (dir == MODE_ADD) && (parc > *parn))
542 return;
544 list = &chptr->invexlist;
545 errorval = SM_ERR_RPL_I;
546 rpl_list = RPL_INVITELIST;
547 rpl_endlist = RPL_ENDOFINVITELIST;
548 caps = CAP_IE;
550 if(ConfigChannel.use_invex || (dir == MODE_DEL))
551 mems = ONLY_CHANOPS;
552 else
553 mems = ONLY_SERVERS;
554 break;
556 case CHFL_QUIET:
557 list = &chptr->quietlist;
558 errorval = SM_ERR_RPL_Q;
559 rpl_list = RPL_BANLIST;
560 rpl_endlist = RPL_ENDOFBANLIST;
561 mems = ALL_MEMBERS;
562 caps = 0;
563 break;
565 default:
566 sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
567 return;
568 break;
571 if(dir == 0 || parc <= *parn)
573 if((*errors & errorval) != 0)
574 return;
575 *errors |= errorval;
577 /* non-ops cant see +eI lists.. */
578 if(alevel != CHFL_CHANOP && mode_type != CHFL_BAN &&
579 mode_type != CHFL_QUIET)
581 if(!(*errors & SM_ERR_NOOPS))
582 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
583 me.name, source_p->name, chptr->chname);
584 *errors |= SM_ERR_NOOPS;
585 return;
588 DLINK_FOREACH(ptr, list->head)
590 banptr = ptr->data;
591 sendto_one(source_p, form_str(rpl_list),
592 me.name, source_p->name, chptr->chname,
593 banptr->banstr, banptr->who, banptr->when);
595 sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname);
596 return;
599 if(alevel != CHFL_CHANOP)
601 if(!(*errors & SM_ERR_NOOPS))
602 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
603 me.name, source_p->name, chptr->chname);
604 *errors |= SM_ERR_NOOPS;
605 return;
608 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
609 return;
611 raw_mask = parv[(*parn)];
612 (*parn)++;
614 /* empty ban, or starts with ':' which messes up s2s, ignore it */
615 if(EmptyString(raw_mask) || *raw_mask == ':')
616 return;
618 if(!MyClient(source_p))
620 if(strchr(raw_mask, ' '))
621 return;
623 mask = raw_mask;
625 else
626 mask = pretty_mask(raw_mask);
628 /* we'd have problems parsing this, hyb6 does it too */
629 if(strlen(mask) > (MODEBUFLEN - 2))
630 return;
632 /* if we're adding a NEW id */
633 if(dir == MODE_ADD)
635 if (*mask == '$' && MyClient(source_p))
637 if (!valid_extban(mask, source_p, chptr, mode_type))
638 /* XXX perhaps return an error message here */
639 return;
642 /* dont allow local clients to overflow the banlist, dont
643 * let remote servers set duplicate bans
645 if(!add_id(source_p, chptr, mask, list, mode_type))
646 return;
648 mode_changes[mode_count].letter = c;
649 mode_changes[mode_count].dir = MODE_ADD;
650 mode_changes[mode_count].caps = caps;
651 mode_changes[mode_count].nocaps = 0;
652 mode_changes[mode_count].mems = mems;
653 mode_changes[mode_count].id = NULL;
654 mode_changes[mode_count++].arg = mask;
656 else if(dir == MODE_DEL)
658 if(del_id(chptr, mask, list, mode_type) == 0)
660 /* mask isn't a valid ban, check raw_mask */
661 if(del_id(chptr, raw_mask, list, mode_type))
662 mask = raw_mask;
665 mode_changes[mode_count].letter = c;
666 mode_changes[mode_count].dir = MODE_DEL;
667 mode_changes[mode_count].caps = caps;
668 mode_changes[mode_count].nocaps = 0;
669 mode_changes[mode_count].mems = mems;
670 mode_changes[mode_count].id = NULL;
671 mode_changes[mode_count++].arg = mask;
675 void
676 chm_op(struct Client *source_p, struct Channel *chptr,
677 int alevel, int parc, int *parn,
678 const char **parv, int *errors, int dir, char c, long mode_type)
680 struct membership *mstptr;
681 const char *opnick;
682 struct Client *targ_p;
684 if(alevel != CHFL_CHANOP)
686 if(!(*errors & SM_ERR_NOOPS))
687 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
688 me.name, source_p->name, chptr->chname);
689 *errors |= SM_ERR_NOOPS;
690 return;
693 if((dir == MODE_QUERY) || (parc <= *parn))
694 return;
696 opnick = parv[(*parn)];
697 (*parn)++;
699 /* empty nick */
700 if(EmptyString(opnick))
702 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
703 return;
706 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
708 return;
711 mstptr = find_channel_membership(chptr, targ_p);
713 if(mstptr == NULL)
715 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
716 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
717 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
718 *errors |= SM_ERR_NOTONCHANNEL;
719 return;
722 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
723 return;
725 if(dir == MODE_ADD)
728 * This breaks oper-override users opping themselves.
729 * Presumably a reason though?
730 if(targ_p == source_p)
731 return;
734 mode_changes[mode_count].letter = c;
735 mode_changes[mode_count].dir = MODE_ADD;
736 mode_changes[mode_count].caps = 0;
737 mode_changes[mode_count].nocaps = 0;
738 mode_changes[mode_count].mems = ALL_MEMBERS;
739 mode_changes[mode_count].id = targ_p->id;
740 mode_changes[mode_count].arg = targ_p->name;
741 mode_changes[mode_count++].client = targ_p;
743 mstptr->flags |= CHFL_CHANOP;
744 mstptr->flags &= ~CHFL_DEOPPED;
746 else
748 if(MyClient(source_p) && IsService(targ_p))
750 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
751 me.name, source_p->name, targ_p->name, chptr->chname);
752 return;
755 mode_changes[mode_count].letter = c;
756 mode_changes[mode_count].dir = MODE_DEL;
757 mode_changes[mode_count].caps = 0;
758 mode_changes[mode_count].nocaps = 0;
759 mode_changes[mode_count].mems = ALL_MEMBERS;
760 mode_changes[mode_count].id = targ_p->id;
761 mode_changes[mode_count].arg = targ_p->name;
762 mode_changes[mode_count++].client = targ_p;
764 mstptr->flags &= ~CHFL_CHANOP;
768 void
769 chm_voice(struct Client *source_p, struct Channel *chptr,
770 int alevel, int parc, int *parn,
771 const char **parv, int *errors, int dir, char c, long mode_type)
773 struct membership *mstptr;
774 const char *opnick;
775 struct Client *targ_p;
777 if(alevel != CHFL_CHANOP)
779 if(!(*errors & SM_ERR_NOOPS))
780 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
781 me.name, source_p->name, chptr->chname);
782 *errors |= SM_ERR_NOOPS;
783 return;
786 if((dir == MODE_QUERY) || parc <= *parn)
787 return;
789 opnick = parv[(*parn)];
790 (*parn)++;
792 /* empty nick */
793 if(EmptyString(opnick))
795 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
796 return;
799 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
801 return;
804 mstptr = find_channel_membership(chptr, targ_p);
806 if(mstptr == NULL)
808 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
809 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
810 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
811 *errors |= SM_ERR_NOTONCHANNEL;
812 return;
815 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
816 return;
818 if(dir == MODE_ADD)
820 mode_changes[mode_count].letter = c;
821 mode_changes[mode_count].dir = MODE_ADD;
822 mode_changes[mode_count].caps = 0;
823 mode_changes[mode_count].nocaps = 0;
824 mode_changes[mode_count].mems = ALL_MEMBERS;
825 mode_changes[mode_count].id = targ_p->id;
826 mode_changes[mode_count].arg = targ_p->name;
827 mode_changes[mode_count++].client = targ_p;
829 mstptr->flags |= CHFL_VOICE;
831 else
833 mode_changes[mode_count].letter = 'v';
834 mode_changes[mode_count].dir = MODE_DEL;
835 mode_changes[mode_count].caps = 0;
836 mode_changes[mode_count].nocaps = 0;
837 mode_changes[mode_count].mems = ALL_MEMBERS;
838 mode_changes[mode_count].id = targ_p->id;
839 mode_changes[mode_count].arg = targ_p->name;
840 mode_changes[mode_count++].client = targ_p;
842 mstptr->flags &= ~CHFL_VOICE;
846 void
847 chm_limit(struct Client *source_p, struct Channel *chptr,
848 int alevel, int parc, int *parn,
849 const char **parv, int *errors, int dir, char c, long mode_type)
851 const char *lstr;
852 static char limitstr[30];
853 int limit;
855 if(alevel != CHFL_CHANOP)
857 if(!(*errors & SM_ERR_NOOPS))
858 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
859 me.name, source_p->name, chptr->chname);
860 *errors |= SM_ERR_NOOPS;
861 return;
864 if(dir == MODE_QUERY)
865 return;
867 if((dir == MODE_ADD) && parc > *parn)
869 lstr = parv[(*parn)];
870 (*parn)++;
872 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
873 return;
875 ircsprintf(limitstr, "%d", limit);
877 mode_changes[mode_count].letter = c;
878 mode_changes[mode_count].dir = MODE_ADD;
879 mode_changes[mode_count].caps = 0;
880 mode_changes[mode_count].nocaps = 0;
881 mode_changes[mode_count].mems = ALL_MEMBERS;
882 mode_changes[mode_count].id = NULL;
883 mode_changes[mode_count++].arg = limitstr;
885 chptr->mode.limit = limit;
887 else if(dir == MODE_DEL)
889 if(!chptr->mode.limit)
890 return;
892 chptr->mode.limit = 0;
894 mode_changes[mode_count].letter = c;
895 mode_changes[mode_count].dir = MODE_DEL;
896 mode_changes[mode_count].caps = 0;
897 mode_changes[mode_count].nocaps = 0;
898 mode_changes[mode_count].mems = ALL_MEMBERS;
899 mode_changes[mode_count].id = NULL;
900 mode_changes[mode_count++].arg = NULL;
904 void
905 chm_banlimit(struct Client *source_p, struct Channel *chptr,
906 int alevel, int parc, int *parn,
907 const char **parv, int *errors, int dir, char c, long mode_type)
909 const char *lstr;
910 static char limitstr[30];
911 int limit;
913 if(!IsServer(source_p) && MyClient(source_p) && !IsOperCModes(source_p))
915 if(!(*errors & SM_ERR_NOPRIVS))
917 if(IsOper(source_p))
918 sendto_one(source_p, form_str(ERR_NOPRIVS),
919 me.name, source_p->name, "set_cmode");
920 else
921 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
923 *errors |= SM_ERR_NOPRIVS;
924 return;
927 if(dir == MODE_QUERY)
928 return;
930 if((dir == MODE_ADD) && parc > *parn)
932 lstr = parv[(*parn)];
933 (*parn)++;
935 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
936 return;
938 ircsprintf(limitstr, "%d", limit);
940 mode_changes[mode_count].letter = c;
941 mode_changes[mode_count].dir = MODE_ADD;
942 mode_changes[mode_count].caps = 0;
943 mode_changes[mode_count].nocaps = 0;
944 mode_changes[mode_count].mems = ALL_MEMBERS;
945 mode_changes[mode_count].id = NULL;
946 mode_changes[mode_count++].arg = limitstr;
948 chptr->mode.banlimit = limit;
950 else if(dir == MODE_DEL)
952 if(!chptr->mode.banlimit)
953 return;
955 chptr->mode.banlimit = 0;
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 = NULL;
963 mode_changes[mode_count++].arg = NULL;
967 void
968 chm_throttle(struct Client *source_p, struct Channel *chptr,
969 int alevel, int parc, int *parn,
970 const char **parv, int *errors, int dir, char c, long mode_type)
972 int joins = 0, timeslice = 0;
974 if(alevel != CHFL_CHANOP)
976 if(!(*errors & SM_ERR_NOOPS))
977 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
978 me.name, source_p->name, chptr->chname);
979 *errors |= SM_ERR_NOOPS;
980 return;
983 if(dir == MODE_QUERY)
984 return;
986 if((dir == MODE_ADD) && parc > *parn)
988 sscanf(parv[(*parn)], "%d:%d", &joins, &timeslice);
990 if(!joins || !timeslice)
991 return;
993 mode_changes[mode_count].letter = c;
994 mode_changes[mode_count].dir = MODE_ADD;
995 mode_changes[mode_count].caps = 0;
996 mode_changes[mode_count].nocaps = 0;
997 mode_changes[mode_count].mems = ALL_MEMBERS;
998 mode_changes[mode_count].id = NULL;
999 mode_changes[mode_count++].arg = parv[(*parn)];
1001 (*parn)++;
1003 chptr->mode.join_num = joins;
1004 chptr->mode.join_time = timeslice;
1006 else if(dir == MODE_DEL)
1008 if(!chptr->mode.join_num)
1009 return;
1011 chptr->mode.join_num = 0;
1012 chptr->mode.join_time = 0;
1013 chptr->join_count = 0;
1014 chptr->join_delta = 0;
1016 mode_changes[mode_count].letter = c;
1017 mode_changes[mode_count].dir = MODE_DEL;
1018 mode_changes[mode_count].caps = 0;
1019 mode_changes[mode_count].nocaps = 0;
1020 mode_changes[mode_count].mems = ALL_MEMBERS;
1021 mode_changes[mode_count].id = NULL;
1022 mode_changes[mode_count++].arg = NULL;
1026 void
1027 chm_forward(struct Client *source_p, struct Channel *chptr,
1028 int alevel, int parc, int *parn,
1029 const char **parv, int *errors, int dir, char c, long mode_type)
1031 struct Channel *targptr = NULL;
1032 struct membership *msptr;
1033 const char *forward;
1035 if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
1037 if (!(*errors & SM_ERR_RPL_F))
1039 if (*chptr->mode.forward == '\0')
1040 sendto_one(source_p, ":%s NOTICE %s :%s has no forward channel", me.name, source_p->name, chptr->chname);
1041 else
1042 sendto_one(source_p, ":%s NOTICE %s :%s forward channel is %s", me.name, source_p->name, chptr->chname, chptr->mode.forward);
1043 *errors |= SM_ERR_RPL_F;
1045 return;
1048 #ifndef FORWARD_OPERONLY
1049 if(alevel != CHFL_CHANOP)
1051 if(!(*errors & SM_ERR_NOOPS))
1052 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1053 me.name, source_p->name, chptr->chname);
1054 *errors |= SM_ERR_NOOPS;
1055 return;
1057 #else
1058 if(!IsOperCModes(source_p) && !IsServer(source_p))
1060 if(!(*errors & SM_ERR_NOPRIVS))
1061 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
1062 *errors |= SM_ERR_NOPRIVS;
1063 return;
1065 #endif
1067 if(dir == MODE_ADD && parc > *parn)
1069 forward = parv[(*parn)];
1070 (*parn)++;
1072 if(EmptyString(forward))
1073 return;
1074 if(!check_channel_name(forward) ||
1075 (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
1077 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
1078 return;
1080 if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
1082 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
1083 form_str(ERR_NOSUCHCHANNEL), forward);
1084 return;
1086 if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
1088 if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
1089 get_channel_access(source_p, msptr) != CHFL_CHANOP)
1091 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1092 me.name, source_p->name, targptr->chname);
1093 return;
1097 strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
1099 mode_changes[mode_count].letter = c;
1100 mode_changes[mode_count].dir = MODE_ADD;
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 = forward;
1107 else if(dir == MODE_DEL)
1109 if(!(*chptr->mode.forward))
1110 return;
1112 *chptr->mode.forward = '\0';
1114 mode_changes[mode_count].letter = c;
1115 mode_changes[mode_count].dir = MODE_DEL;
1116 mode_changes[mode_count].caps = 0;
1117 mode_changes[mode_count].nocaps = 0;
1118 mode_changes[mode_count].mems = ALL_MEMBERS;
1119 mode_changes[mode_count].id = NULL;
1120 mode_changes[mode_count++].arg = NULL;
1124 void
1125 chm_key(struct Client *source_p, struct Channel *chptr,
1126 int alevel, int parc, int *parn,
1127 const char **parv, int *errors, int dir, char c, long mode_type)
1129 char *key;
1131 if(alevel != CHFL_CHANOP)
1133 if(!(*errors & SM_ERR_NOOPS))
1134 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1135 me.name, source_p->name, chptr->chname);
1136 *errors |= SM_ERR_NOOPS;
1137 return;
1140 if(dir == MODE_QUERY)
1141 return;
1143 if((dir == MODE_ADD) && parc > *parn)
1145 key = LOCAL_COPY(parv[(*parn)]);
1146 (*parn)++;
1148 if(MyClient(source_p))
1149 fix_key(key);
1150 else
1151 fix_key_remote(key);
1153 if(EmptyString(key))
1154 return;
1156 s_assert(key[0] != ' ');
1157 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1159 mode_changes[mode_count].letter = c;
1160 mode_changes[mode_count].dir = MODE_ADD;
1161 mode_changes[mode_count].caps = 0;
1162 mode_changes[mode_count].nocaps = 0;
1163 mode_changes[mode_count].mems = ALL_MEMBERS;
1164 mode_changes[mode_count].id = NULL;
1165 mode_changes[mode_count++].arg = chptr->mode.key;
1167 else if(dir == MODE_DEL)
1169 static char splat[] = "*";
1170 int i;
1172 if(parc > *parn)
1173 (*parn)++;
1175 if(!(*chptr->mode.key))
1176 return;
1178 /* hack time. when we get a +k-k mode, the +k arg is
1179 * chptr->mode.key, which the -k sets to \0, so hunt for a
1180 * +k when we get a -k, and set the arg to splat. --anfl
1182 for(i = 0; i < mode_count; i++)
1184 if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
1185 mode_changes[i].arg = splat;
1188 *chptr->mode.key = 0;
1190 mode_changes[mode_count].letter = c;
1191 mode_changes[mode_count].dir = MODE_DEL;
1192 mode_changes[mode_count].caps = 0;
1193 mode_changes[mode_count].nocaps = 0;
1194 mode_changes[mode_count].mems = ALL_MEMBERS;
1195 mode_changes[mode_count].id = NULL;
1196 mode_changes[mode_count++].arg = "*";
1200 void
1201 chm_regonly(struct Client *source_p, struct Channel *chptr,
1202 int alevel, int parc, int *parn,
1203 const char **parv, int *errors, int dir, char c, long mode_type)
1205 if(alevel != CHFL_CHANOP)
1207 if(!(*errors & SM_ERR_NOOPS))
1208 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1209 me.name, source_p->name, chptr->chname);
1210 *errors |= SM_ERR_NOOPS;
1211 return;
1214 if(dir == MODE_QUERY)
1215 return;
1217 if(((dir == MODE_ADD) && (chptr->mode.mode & mode_type)) ||
1218 ((dir == MODE_DEL) && !(chptr->mode.mode & mode_type)))
1219 return;
1221 if(dir == MODE_ADD)
1222 chptr->mode.mode |= mode_type;
1223 else
1224 chptr->mode.mode &= ~mode_type;
1226 mode_changes[mode_count].letter = c;
1227 mode_changes[mode_count].dir = dir;
1228 mode_changes[mode_count].caps = CAP_SERVICE;
1229 mode_changes[mode_count].nocaps = 0;
1230 mode_changes[mode_count].mems = ALL_MEMBERS;
1231 mode_changes[mode_count].id = NULL;
1232 mode_changes[mode_count++].arg = NULL;
1235 /* *INDENT-OFF* */
1236 struct ChannelMode chmode_table[256] =
1238 {chm_nosuch, 0 }, /* 0x00 */
1239 {chm_nosuch, 0 }, /* 0x01 */
1240 {chm_nosuch, 0 }, /* 0x02 */
1241 {chm_nosuch, 0 }, /* 0x03 */
1242 {chm_nosuch, 0 }, /* 0x04 */
1243 {chm_nosuch, 0 }, /* 0x05 */
1244 {chm_nosuch, 0 }, /* 0x06 */
1245 {chm_nosuch, 0 }, /* 0x07 */
1246 {chm_nosuch, 0 }, /* 0x08 */
1247 {chm_nosuch, 0 }, /* 0x09 */
1248 {chm_nosuch, 0 }, /* 0x0a */
1249 {chm_nosuch, 0 }, /* 0x0b */
1250 {chm_nosuch, 0 }, /* 0x0c */
1251 {chm_nosuch, 0 }, /* 0x0d */
1252 {chm_nosuch, 0 }, /* 0x0e */
1253 {chm_nosuch, 0 }, /* 0x0f */
1254 {chm_nosuch, 0 }, /* 0x10 */
1255 {chm_nosuch, 0 }, /* 0x11 */
1256 {chm_nosuch, 0 }, /* 0x12 */
1257 {chm_nosuch, 0 }, /* 0x13 */
1258 {chm_nosuch, 0 }, /* 0x14 */
1259 {chm_nosuch, 0 }, /* 0x15 */
1260 {chm_nosuch, 0 }, /* 0x16 */
1261 {chm_nosuch, 0 }, /* 0x17 */
1262 {chm_nosuch, 0 }, /* 0x18 */
1263 {chm_nosuch, 0 }, /* 0x19 */
1264 {chm_nosuch, 0 }, /* 0x1a */
1265 {chm_nosuch, 0 }, /* 0x1b */
1266 {chm_nosuch, 0 }, /* 0x1c */
1267 {chm_nosuch, 0 }, /* 0x1d */
1268 {chm_nosuch, 0 }, /* 0x1e */
1269 {chm_nosuch, 0 }, /* 0x1f */
1270 {chm_nosuch, 0 }, /* 0x20 */
1271 {chm_nosuch, 0 }, /* 0x21 */
1272 {chm_nosuch, 0 }, /* 0x22 */
1273 {chm_nosuch, 0 }, /* 0x23 */
1274 {chm_nosuch, 0 }, /* 0x24 */
1275 {chm_nosuch, 0 }, /* 0x25 */
1276 {chm_nosuch, 0 }, /* 0x26 */
1277 {chm_nosuch, 0 }, /* 0x27 */
1278 {chm_nosuch, 0 }, /* 0x28 */
1279 {chm_nosuch, 0 }, /* 0x29 */
1280 {chm_nosuch, 0 }, /* 0x2a */
1281 {chm_nosuch, 0 }, /* 0x2b */
1282 {chm_nosuch, 0 }, /* 0x2c */
1283 {chm_nosuch, 0 }, /* 0x2d */
1284 {chm_nosuch, 0 }, /* 0x2e */
1285 {chm_nosuch, 0 }, /* 0x2f */
1286 {chm_nosuch, 0 }, /* 0x30 */
1287 {chm_nosuch, 0 }, /* 0x31 */
1288 {chm_nosuch, 0 }, /* 0x32 */
1289 {chm_nosuch, 0 }, /* 0x33 */
1290 {chm_nosuch, 0 }, /* 0x34 */
1291 {chm_nosuch, 0 }, /* 0x35 */
1292 {chm_nosuch, 0 }, /* 0x36 */
1293 {chm_nosuch, 0 }, /* 0x37 */
1294 {chm_nosuch, 0 }, /* 0x38 */
1295 {chm_nosuch, 0 }, /* 0x39 */
1296 {chm_nosuch, 0 }, /* 0x3a */
1297 {chm_nosuch, 0 }, /* 0x3b */
1298 {chm_nosuch, 0 }, /* 0x3c */
1299 {chm_nosuch, 0 }, /* 0x3d */
1300 {chm_nosuch, 0 }, /* 0x3e */
1301 {chm_nosuch, 0 }, /* 0x3f */
1303 {chm_nosuch, 0 }, /* @ */
1304 {chm_nosuch, 0 }, /* A */
1305 {chm_nosuch, 0 }, /* B */
1306 {chm_nosuch, 0 }, /* C */
1307 {chm_nosuch, 0 }, /* D */
1308 {chm_nosuch, 0 }, /* E */
1309 {chm_simple, MODE_FREETARGET }, /* F */
1310 {chm_nosuch, 0 }, /* G */
1311 {chm_nosuch, 0 }, /* H */
1312 {chm_ban, CHFL_INVEX }, /* I */
1313 {chm_nosuch, 0 }, /* J */
1314 {chm_nosuch, 0 }, /* K */
1315 {chm_banlimit,0 }, /* L */
1316 {chm_nosuch, 0 }, /* M */
1317 {chm_nosuch, 0 }, /* N */
1318 {chm_nosuch, 0 }, /* O */
1319 {chm_staff, MODE_PERMANENT }, /* P */
1320 {chm_simple, MODE_DISFORWARD }, /* Q */
1321 {chm_simple, MODE_QUIETUNID }, /* R */
1322 {chm_nosuch, 0 }, /* S */
1323 {chm_nosuch, 0 }, /* T */
1324 {chm_nosuch, 0 }, /* U */
1325 {chm_nosuch, 0 }, /* V */
1326 {chm_nosuch, 0 }, /* W */
1327 {chm_nosuch, 0 }, /* X */
1328 {chm_nosuch, 0 }, /* Y */
1329 {chm_nosuch, 0 }, /* Z */
1330 {chm_nosuch, 0 },
1331 {chm_nosuch, 0 },
1332 {chm_nosuch, 0 },
1333 {chm_nosuch, 0 },
1334 {chm_nosuch, 0 },
1335 {chm_nosuch, 0 },
1336 {chm_nosuch, 0 }, /* a */
1337 {chm_ban, CHFL_BAN }, /* b */
1338 {chm_simple, MODE_NOCOLOR }, /* c */
1339 {chm_nosuch, 0 }, /* d */
1340 {chm_ban, CHFL_EXCEPTION }, /* e */
1341 {chm_forward, 0 }, /* f */
1342 {chm_simple, MODE_FREEINVITE }, /* g */
1343 {chm_nosuch, 0 }, /* h */
1344 {chm_simple, MODE_INVITEONLY }, /* i */
1345 {chm_throttle, 0 }, /* j */
1346 {chm_key, 0 }, /* k */
1347 {chm_limit, 0 }, /* l */
1348 {chm_simple, MODE_MODERATED }, /* m */
1349 {chm_simple, MODE_NOPRIVMSGS }, /* n */
1350 {chm_op, 0 }, /* o */
1351 {chm_simple, MODE_PRIVATE }, /* p */
1352 {chm_ban, CHFL_QUIET }, /* q */
1353 {chm_regonly, MODE_REGONLY }, /* r */
1354 {chm_simple, MODE_SECRET }, /* s */
1355 {chm_simple, MODE_TOPICLIMIT }, /* t */
1356 {chm_nosuch, 0 }, /* u */
1357 {chm_voice, 0 }, /* v */
1358 {chm_nosuch, 0 }, /* w */
1359 {chm_nosuch, 0 }, /* x */
1360 {chm_nosuch, 0 }, /* y */
1361 {chm_simple, MODE_OPMODERATE }, /* z */
1363 {chm_nosuch, 0 }, /* 0x7b */
1364 {chm_nosuch, 0 }, /* 0x7c */
1365 {chm_nosuch, 0 }, /* 0x7d */
1366 {chm_nosuch, 0 }, /* 0x7e */
1367 {chm_nosuch, 0 }, /* 0x7f */
1369 {chm_nosuch, 0 }, /* 0x80 */
1370 {chm_nosuch, 0 }, /* 0x81 */
1371 {chm_nosuch, 0 }, /* 0x82 */
1372 {chm_nosuch, 0 }, /* 0x83 */
1373 {chm_nosuch, 0 }, /* 0x84 */
1374 {chm_nosuch, 0 }, /* 0x85 */
1375 {chm_nosuch, 0 }, /* 0x86 */
1376 {chm_nosuch, 0 }, /* 0x87 */
1377 {chm_nosuch, 0 }, /* 0x88 */
1378 {chm_nosuch, 0 }, /* 0x89 */
1379 {chm_nosuch, 0 }, /* 0x8a */
1380 {chm_nosuch, 0 }, /* 0x8b */
1381 {chm_nosuch, 0 }, /* 0x8c */
1382 {chm_nosuch, 0 }, /* 0x8d */
1383 {chm_nosuch, 0 }, /* 0x8e */
1384 {chm_nosuch, 0 }, /* 0x8f */
1386 {chm_nosuch, 0 }, /* 0x90 */
1387 {chm_nosuch, 0 }, /* 0x91 */
1388 {chm_nosuch, 0 }, /* 0x92 */
1389 {chm_nosuch, 0 }, /* 0x93 */
1390 {chm_nosuch, 0 }, /* 0x94 */
1391 {chm_nosuch, 0 }, /* 0x95 */
1392 {chm_nosuch, 0 }, /* 0x96 */
1393 {chm_nosuch, 0 }, /* 0x97 */
1394 {chm_nosuch, 0 }, /* 0x98 */
1395 {chm_nosuch, 0 }, /* 0x99 */
1396 {chm_nosuch, 0 }, /* 0x9a */
1397 {chm_nosuch, 0 }, /* 0x9b */
1398 {chm_nosuch, 0 }, /* 0x9c */
1399 {chm_nosuch, 0 }, /* 0x9d */
1400 {chm_nosuch, 0 }, /* 0x9e */
1401 {chm_nosuch, 0 }, /* 0x9f */
1403 {chm_nosuch, 0 }, /* 0xa0 */
1404 {chm_nosuch, 0 }, /* 0xa1 */
1405 {chm_nosuch, 0 }, /* 0xa2 */
1406 {chm_nosuch, 0 }, /* 0xa3 */
1407 {chm_nosuch, 0 }, /* 0xa4 */
1408 {chm_nosuch, 0 }, /* 0xa5 */
1409 {chm_nosuch, 0 }, /* 0xa6 */
1410 {chm_nosuch, 0 }, /* 0xa7 */
1411 {chm_nosuch, 0 }, /* 0xa8 */
1412 {chm_nosuch, 0 }, /* 0xa9 */
1413 {chm_nosuch, 0 }, /* 0xaa */
1414 {chm_nosuch, 0 }, /* 0xab */
1415 {chm_nosuch, 0 }, /* 0xac */
1416 {chm_nosuch, 0 }, /* 0xad */
1417 {chm_nosuch, 0 }, /* 0xae */
1418 {chm_nosuch, 0 }, /* 0xaf */
1420 {chm_nosuch, 0 }, /* 0xb0 */
1421 {chm_nosuch, 0 }, /* 0xb1 */
1422 {chm_nosuch, 0 }, /* 0xb2 */
1423 {chm_nosuch, 0 }, /* 0xb3 */
1424 {chm_nosuch, 0 }, /* 0xb4 */
1425 {chm_nosuch, 0 }, /* 0xb5 */
1426 {chm_nosuch, 0 }, /* 0xb6 */
1427 {chm_nosuch, 0 }, /* 0xb7 */
1428 {chm_nosuch, 0 }, /* 0xb8 */
1429 {chm_nosuch, 0 }, /* 0xb9 */
1430 {chm_nosuch, 0 }, /* 0xba */
1431 {chm_nosuch, 0 }, /* 0xbb */
1432 {chm_nosuch, 0 }, /* 0xbc */
1433 {chm_nosuch, 0 }, /* 0xbd */
1434 {chm_nosuch, 0 }, /* 0xbe */
1435 {chm_nosuch, 0 }, /* 0xbf */
1437 {chm_nosuch, 0 }, /* 0xc0 */
1438 {chm_nosuch, 0 }, /* 0xc1 */
1439 {chm_nosuch, 0 }, /* 0xc2 */
1440 {chm_nosuch, 0 }, /* 0xc3 */
1441 {chm_nosuch, 0 }, /* 0xc4 */
1442 {chm_nosuch, 0 }, /* 0xc5 */
1443 {chm_nosuch, 0 }, /* 0xc6 */
1444 {chm_nosuch, 0 }, /* 0xc7 */
1445 {chm_nosuch, 0 }, /* 0xc8 */
1446 {chm_nosuch, 0 }, /* 0xc9 */
1447 {chm_nosuch, 0 }, /* 0xca */
1448 {chm_nosuch, 0 }, /* 0xcb */
1449 {chm_nosuch, 0 }, /* 0xcc */
1450 {chm_nosuch, 0 }, /* 0xcd */
1451 {chm_nosuch, 0 }, /* 0xce */
1452 {chm_nosuch, 0 }, /* 0xcf */
1454 {chm_nosuch, 0 }, /* 0xd0 */
1455 {chm_nosuch, 0 }, /* 0xd1 */
1456 {chm_nosuch, 0 }, /* 0xd2 */
1457 {chm_nosuch, 0 }, /* 0xd3 */
1458 {chm_nosuch, 0 }, /* 0xd4 */
1459 {chm_nosuch, 0 }, /* 0xd5 */
1460 {chm_nosuch, 0 }, /* 0xd6 */
1461 {chm_nosuch, 0 }, /* 0xd7 */
1462 {chm_nosuch, 0 }, /* 0xd8 */
1463 {chm_nosuch, 0 }, /* 0xd9 */
1464 {chm_nosuch, 0 }, /* 0xda */
1465 {chm_nosuch, 0 }, /* 0xdb */
1466 {chm_nosuch, 0 }, /* 0xdc */
1467 {chm_nosuch, 0 }, /* 0xdd */
1468 {chm_nosuch, 0 }, /* 0xde */
1469 {chm_nosuch, 0 }, /* 0xdf */
1471 {chm_nosuch, 0 }, /* 0xe0 */
1472 {chm_nosuch, 0 }, /* 0xe1 */
1473 {chm_nosuch, 0 }, /* 0xe2 */
1474 {chm_nosuch, 0 }, /* 0xe3 */
1475 {chm_nosuch, 0 }, /* 0xe4 */
1476 {chm_nosuch, 0 }, /* 0xe5 */
1477 {chm_nosuch, 0 }, /* 0xe6 */
1478 {chm_nosuch, 0 }, /* 0xe7 */
1479 {chm_nosuch, 0 }, /* 0xe8 */
1480 {chm_nosuch, 0 }, /* 0xe9 */
1481 {chm_nosuch, 0 }, /* 0xea */
1482 {chm_nosuch, 0 }, /* 0xeb */
1483 {chm_nosuch, 0 }, /* 0xec */
1484 {chm_nosuch, 0 }, /* 0xed */
1485 {chm_nosuch, 0 }, /* 0xee */
1486 {chm_nosuch, 0 }, /* 0xef */
1488 {chm_nosuch, 0 }, /* 0xf0 */
1489 {chm_nosuch, 0 }, /* 0xf1 */
1490 {chm_nosuch, 0 }, /* 0xf2 */
1491 {chm_nosuch, 0 }, /* 0xf3 */
1492 {chm_nosuch, 0 }, /* 0xf4 */
1493 {chm_nosuch, 0 }, /* 0xf5 */
1494 {chm_nosuch, 0 }, /* 0xf6 */
1495 {chm_nosuch, 0 }, /* 0xf7 */
1496 {chm_nosuch, 0 }, /* 0xf8 */
1497 {chm_nosuch, 0 }, /* 0xf9 */
1498 {chm_nosuch, 0 }, /* 0xfa */
1499 {chm_nosuch, 0 }, /* 0xfb */
1500 {chm_nosuch, 0 }, /* 0xfc */
1501 {chm_nosuch, 0 }, /* 0xfd */
1502 {chm_nosuch, 0 }, /* 0xfe */
1503 {chm_nosuch, 0 }, /* 0xff */
1506 /* *INDENT-ON* */
1508 /* set_channel_mode()
1510 * inputs - client, source, channel, membership pointer, params
1511 * output -
1512 * side effects - channel modes/memberships are changed, MODE is issued
1514 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1516 void
1517 set_channel_mode(struct Client *client_p, struct Client *source_p,
1518 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[])
1520 static char modebuf[BUFSIZE];
1521 static char parabuf[BUFSIZE];
1522 char *mbuf;
1523 char *pbuf;
1524 int cur_len, mlen, paralen, paracount, arglen, len;
1525 int i, j, flags;
1526 int dir = MODE_ADD;
1527 int parn = 1;
1528 int errors = 0;
1529 int alevel;
1530 const char *ml = parv[0];
1531 char c;
1532 struct Client *fakesource_p;
1534 mask_pos = 0;
1535 mode_count = 0;
1536 mode_limit = 0;
1538 alevel = get_channel_access(source_p, msptr);
1540 /* Hide connecting server on netburst -- jilles */
1541 if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
1542 fakesource_p = &me;
1543 else
1544 fakesource_p = source_p;
1546 for(; (c = *ml) != 0; ml++)
1548 switch (c)
1550 case '+':
1551 dir = MODE_ADD;
1552 break;
1553 case '-':
1554 dir = MODE_DEL;
1555 break;
1556 case '=':
1557 dir = MODE_QUERY;
1558 break;
1559 default:
1560 chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel,
1561 parc, &parn, parv,
1562 &errors, dir, c,
1563 chmode_table[(unsigned char) c].mode_type);
1564 break;
1568 /* bail out if we have nothing to do... */
1569 if(!mode_count)
1570 return;
1572 if(IsServer(source_p))
1573 mlen = ircsprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname);
1574 else
1575 mlen = ircsprintf(modebuf, ":%s!%s@%s MODE %s ",
1576 source_p->name, source_p->username,
1577 source_p->host, chptr->chname);
1579 for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS)
1581 cur_len = mlen;
1582 mbuf = modebuf + mlen;
1583 pbuf = parabuf;
1584 parabuf[0] = '\0';
1585 paracount = paralen = 0;
1586 dir = MODE_QUERY;
1588 for(i = 0; i < mode_count; i++)
1590 if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
1591 continue;
1593 if(mode_changes[i].arg != NULL)
1595 arglen = strlen(mode_changes[i].arg);
1597 if(arglen > MODEBUFLEN - 5)
1598 continue;
1600 else
1601 arglen = 0;
1603 /* if we're creeping over MAXMODEPARAMSSERV, or over
1604 * bufsize (4 == +/-,modechar,two spaces) send now.
1606 if(mode_changes[i].arg != NULL &&
1607 ((paracount == MAXMODEPARAMSSERV) ||
1608 ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
1610 *mbuf = '\0';
1612 if(cur_len > mlen)
1613 sendto_channel_local(flags, chptr, "%s %s", modebuf,
1614 parabuf);
1615 else
1616 continue;
1618 paracount = paralen = 0;
1619 cur_len = mlen;
1620 mbuf = modebuf + mlen;
1621 pbuf = parabuf;
1622 parabuf[0] = '\0';
1623 dir = MODE_QUERY;
1626 if(dir != mode_changes[i].dir)
1628 *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1629 cur_len++;
1630 dir = mode_changes[i].dir;
1633 *mbuf++ = mode_changes[i].letter;
1634 cur_len++;
1636 if(mode_changes[i].arg != NULL)
1638 paracount++;
1639 len = ircsprintf(pbuf, "%s ", mode_changes[i].arg);
1640 pbuf += len;
1641 paralen += len;
1645 if(paralen && parabuf[paralen - 1] == ' ')
1646 parabuf[paralen - 1] = '\0';
1648 *mbuf = '\0';
1649 if(cur_len > mlen)
1650 sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
1653 /* only propagate modes originating locally, or if we're hubbing */
1654 if(MyClient(source_p) || dlink_list_length(&serv_list) > 1)
1655 send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);