Kill more local channel code.
[seven-1.x.git] / src / chmode.c
blob643aba943faad76ddf4866e582ca9a25f074ef41
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
25 * $Id: chmode.c 146 2006-11-13 10:45:22Z spb $
28 #include "stdinc.h"
29 #include "tools.h"
30 #include "channel.h"
31 #include "client.h"
32 #include "common.h"
33 #include "hash.h"
34 #include "hook.h"
35 #include "irc_string.h"
36 #include "sprintf_irc.h"
37 #include "ircd.h"
38 #include "numeric.h"
39 #include "s_serv.h" /* captab */
40 #include "s_user.h"
41 #include "send.h"
42 #include "whowas.h"
43 #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */
44 #include "s_newconf.h"
45 #include "event.h"
46 #include "memory.h"
47 #include "balloc.h"
48 #include "s_log.h"
50 /* bitmasks for error returns, so we send once per call */
51 #define SM_ERR_NOTS 0x00000001 /* No TS on channel */
52 #define SM_ERR_NOOPS 0x00000002 /* No chan ops */
53 #define SM_ERR_UNKNOWN 0x00000004
54 #define SM_ERR_RPL_C 0x00000008
55 #define SM_ERR_RPL_B 0x00000010
56 #define SM_ERR_RPL_E 0x00000020
57 #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */
58 #define SM_ERR_RPL_I 0x00000100
59 #define SM_ERR_RPL_D 0x00000200
60 #define SM_ERR_NOPRIVS 0x00000400
61 #define SM_ERR_RPL_Q 0x00000800
62 #define SM_ERR_RPL_F 0x00001000
64 void set_channel_mode(struct Client *, struct Client *,
65 struct Channel *, struct membership *, int, const char **);
67 int add_id(struct Client *source_p, struct Channel *chptr,
68 const char *banid, dlink_list * list, long mode_type);
70 static struct ChModeChange mode_changes[BUFSIZE];
71 static int mode_count;
72 static int mode_limit;
73 static int mask_pos;
75 int
76 get_channel_access(struct Client *source_p, struct membership *msptr)
78 if(!MyClient(source_p) || is_chanop(msptr))
79 return CHFL_CHANOP;
81 return CHFL_PEON;
84 /* add_id()
86 * inputs - client, channel, id to add, type
87 * outputs - 0 on failure, 1 on success
88 * side effects - given id is added to the appropriate list
90 int
91 add_id(struct Client *source_p, struct Channel *chptr, const char *banid,
92 dlink_list * list, long mode_type)
94 struct Ban *actualBan;
95 static char who[BANLEN];
96 char *realban = LOCAL_COPY(banid);
97 dlink_node *ptr;
99 /* dont let local clients overflow the banlist, or set redundant
100 * bans
102 if(MyClient(source_p))
104 if(chptr->num_mask >= (chptr->mode.banlimit > 0 ? chptr->mode.banlimit : ConfigChannel.max_bans))
106 sendto_one(source_p, form_str(ERR_BANLISTFULL),
107 me.name, source_p->name, chptr->chname, realban);
108 return 0;
111 collapse(realban);
113 DLINK_FOREACH(ptr, list->head)
115 actualBan = ptr->data;
116 if(match(actualBan->banstr, realban))
117 return 0;
120 /* dont let remotes set duplicates */
121 else
123 DLINK_FOREACH(ptr, list->head)
125 actualBan = ptr->data;
126 if(!irccmp(actualBan->banstr, realban))
127 return 0;
132 if(IsPerson(source_p))
133 ircsprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host);
134 else
135 strlcpy(who, source_p->name, sizeof(who));
137 actualBan = allocate_ban(realban, who);
138 actualBan->when = CurrentTime;
140 dlinkAdd(actualBan, &actualBan->node, list);
141 chptr->num_mask++;
143 /* invalidate the can_send() cache */
144 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
145 chptr->bants++;
147 return 1;
150 /* del_id()
152 * inputs - channel, id to remove, type
153 * outputs - 0 on failure, 1 on success
154 * side effects - given id is removed from the appropriate list
157 del_id(struct Channel *chptr, const char *banid, dlink_list * list, long mode_type)
159 dlink_node *ptr;
160 struct Ban *banptr;
162 if(EmptyString(banid))
163 return 0;
165 DLINK_FOREACH(ptr, list->head)
167 banptr = ptr->data;
169 if(irccmp(banid, banptr->banstr) == 0)
171 dlinkDelete(&banptr->node, list);
172 free_ban(banptr);
174 /* num_mask should never be < 0 */
175 if(chptr->num_mask > 0)
176 chptr->num_mask--;
177 else
178 chptr->num_mask = 0;
180 /* invalidate the can_send() cache */
181 if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION)
182 chptr->bants++;
184 return 1;
188 return 0;
191 /* check_string()
193 * input - string to check
194 * output - pointer to 'fixed' string, or "*" if empty
195 * side effects - any white space found becomes \0
197 static char *
198 check_string(char *s)
200 char *str = s;
201 static char splat[] = "*";
202 if(!(s && *s))
203 return splat;
205 for(; *s; ++s)
207 if(IsSpace(*s))
209 *s = '\0';
210 break;
213 return str;
216 /* pretty_mask()
218 * inputs - mask to pretty
219 * outputs - better version of the mask
220 * side effects - mask is chopped to limits, and transformed:
221 * x!y@z => x!y@z
222 * y@z => *!y@z
223 * x!y => x!y@*
224 * x => x!*@*
225 * z.d => *!*@z.d
227 static char *
228 pretty_mask(const char *idmask)
230 static char mask_buf[BUFSIZE];
231 int old_mask_pos;
232 char *nick, *user, *host;
233 char splat[] = "*";
234 char *t, *at, *ex;
235 char ne = 0, ue = 0, he = 0; /* save values at nick[NICKLEN], et all */
236 char *mask;
238 mask = LOCAL_COPY(idmask);
239 mask = check_string(mask);
240 collapse(mask);
242 nick = user = host = splat;
244 if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5)
245 return NULL;
247 old_mask_pos = mask_pos;
249 if (*mask == '$')
251 mask_pos += ircsprintf(mask_buf + mask_pos, "%s", mask) + 1;
252 t = mask_buf + old_mask_pos + 1;
253 if (*t == '!')
254 *t = '~';
255 if (*t == '~')
256 t++;
257 *t = ToLower(*t);
258 return mask_buf + old_mask_pos;
261 at = ex = NULL;
262 if((t = strchr(mask, '@')) != NULL)
264 at = t;
265 *t++ = '\0';
266 if(*t != '\0')
267 host = t;
269 if((t = strchr(mask, '!')) != NULL)
271 ex = t;
272 *t++ = '\0';
273 if(*t != '\0')
274 user = t;
275 if(*mask != '\0')
276 nick = mask;
278 else
280 if(*mask != '\0')
281 user = mask;
284 else if((t = strchr(mask, '!')) != NULL)
286 ex = t;
287 *t++ = '\0';
288 if(*mask != '\0')
289 nick = mask;
290 if(*t != '\0')
291 user = t;
293 else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL)
295 if(*mask != '\0')
296 host = mask;
298 else
300 if(*mask != '\0')
301 nick = mask;
304 /* truncate values to max lengths */
305 if(strlen(nick) > NICKLEN - 1)
307 ne = nick[NICKLEN - 1];
308 nick[NICKLEN - 1] = '\0';
310 if(strlen(user) > USERLEN)
312 ue = user[USERLEN];
313 user[USERLEN] = '\0';
315 if(strlen(host) > HOSTLEN)
317 he = host[HOSTLEN];
318 host[HOSTLEN] = '\0';
321 mask_pos += ircsprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1;
323 /* restore mask, since we may need to use it again later */
324 if(at)
325 *at = '@';
326 if(ex)
327 *ex = '!';
328 if(ne)
329 nick[NICKLEN - 1] = ne;
330 if(ue)
331 user[USERLEN] = ue;
332 if(he)
333 host[HOSTLEN] = he;
335 return mask_buf + old_mask_pos;
338 /* fix_key()
340 * input - key to fix
341 * output - the same key, fixed
342 * side effects - anything below ascii 13 is discarded, ':' discarded,
343 * high ascii is dropped to lower half of ascii table
345 static char *
346 fix_key(char *arg)
348 u_char *s, *t, c;
350 for(s = t = (u_char *) arg; (c = *s); s++)
352 c &= 0x7f;
353 if(c != ':' && c != ',' && c > ' ')
354 *t++ = c;
357 *t = '\0';
358 return arg;
361 /* fix_key_remote()
363 * input - key to fix
364 * ouput - the same key, fixed
365 * side effects - high ascii dropped to lower half of table,
366 * CR/LF/':' are dropped
368 static char *
369 fix_key_remote(char *arg)
371 u_char *s, *t, c;
373 for(s = t = (u_char *) arg; (c = *s); s++)
375 c &= 0x7f;
376 if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' '))
377 *t++ = c;
380 *t = '\0';
381 return arg;
384 /* chm_*()
386 * The handlers for each specific mode.
388 void
389 chm_nosuch(struct Client *source_p, struct Channel *chptr,
390 int alevel, int parc, int *parn,
391 const char **parv, int *errors, int dir, char c, long mode_type)
393 if(*errors & SM_ERR_UNKNOWN)
394 return;
395 *errors |= SM_ERR_UNKNOWN;
396 sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c);
399 void
400 chm_simple(struct Client *source_p, struct Channel *chptr,
401 int alevel, int parc, int *parn,
402 const char **parv, int *errors, int dir, char c, long mode_type)
404 if(alevel != CHFL_CHANOP)
406 if(!(*errors & SM_ERR_NOOPS))
407 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
408 me.name, source_p->name, chptr->chname);
409 *errors |= SM_ERR_NOOPS;
410 return;
414 * XXX: This needs 'fixing'; hard coding magic numbers like this is fucking
415 * silly...
418 /* +ntspmaikl == 9 + MAXMODEPARAMS (4 * +o) */
419 if(MyClient(source_p) && (++mode_limit > (9 + MAXMODEPARAMS)))
420 return;
422 /* setting + */
423 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
425 chptr->mode.mode |= mode_type;
427 mode_changes[mode_count].letter = c;
428 mode_changes[mode_count].dir = MODE_ADD;
429 mode_changes[mode_count].caps = 0;
430 mode_changes[mode_count].nocaps = 0;
431 mode_changes[mode_count].id = NULL;
432 mode_changes[mode_count].mems = ALL_MEMBERS;
433 mode_changes[mode_count++].arg = NULL;
435 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
437 chptr->mode.mode &= ~mode_type;
439 mode_changes[mode_count].letter = c;
440 mode_changes[mode_count].dir = MODE_DEL;
441 mode_changes[mode_count].caps = 0;
442 mode_changes[mode_count].nocaps = 0;
443 mode_changes[mode_count].mems = ALL_MEMBERS;
444 mode_changes[mode_count].id = NULL;
445 mode_changes[mode_count++].arg = NULL;
449 void
450 chm_staff(struct Client *source_p, struct Channel *chptr,
451 int alevel, int parc, int *parn,
452 const char **parv, int *errors, int dir, char c, long mode_type)
454 if(!IsServer(source_p) && MyClient(source_p) && !IsOperCModes(source_p))
456 if(!(*errors & SM_ERR_NOPRIVS))
458 if(IsOper(source_p))
459 sendto_one(source_p, form_str(ERR_NOPRIVS),
460 me.name, source_p->name, "set_cmode");
461 else
462 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
464 *errors |= SM_ERR_NOPRIVS;
465 return;
468 /* setting + */
469 if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type))
471 chptr->mode.mode |= mode_type;
473 mode_changes[mode_count].letter = c;
474 mode_changes[mode_count].dir = MODE_ADD;
475 mode_changes[mode_count].caps = 0;
476 mode_changes[mode_count].nocaps = 0;
477 mode_changes[mode_count].id = NULL;
478 mode_changes[mode_count].mems = ALL_MEMBERS;
479 mode_changes[mode_count++].arg = NULL;
481 else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type))
483 chptr->mode.mode &= ~mode_type;
485 mode_changes[mode_count].letter = c;
486 mode_changes[mode_count].dir = MODE_DEL;
487 mode_changes[mode_count].caps = 0;
488 mode_changes[mode_count].nocaps = 0;
489 mode_changes[mode_count].mems = ALL_MEMBERS;
490 mode_changes[mode_count].id = NULL;
491 mode_changes[mode_count++].arg = NULL;
495 void
496 chm_ban(struct Client *source_p, struct Channel *chptr,
497 int alevel, int parc, int *parn,
498 const char **parv, int *errors, int dir, char c, long mode_type)
500 const char *mask;
501 const char *raw_mask;
502 dlink_list *list;
503 dlink_node *ptr;
504 struct Ban *banptr;
505 int errorval;
506 int rpl_list;
507 int rpl_endlist;
508 int caps;
509 int mems;
511 switch (mode_type)
513 case CHFL_BAN:
514 list = &chptr->banlist;
515 errorval = SM_ERR_RPL_B;
516 rpl_list = RPL_BANLIST;
517 rpl_endlist = RPL_ENDOFBANLIST;
518 mems = ALL_MEMBERS;
519 caps = 0;
520 break;
522 case CHFL_EXCEPTION:
523 /* if +e is disabled, allow all but +e locally */
524 if(!ConfigChannel.use_except && MyClient(source_p) &&
525 ((dir == MODE_ADD) && (parc > *parn)))
526 return;
528 list = &chptr->exceptlist;
529 errorval = SM_ERR_RPL_E;
530 rpl_list = RPL_EXCEPTLIST;
531 rpl_endlist = RPL_ENDOFEXCEPTLIST;
532 caps = CAP_EX;
534 if(ConfigChannel.use_except || (dir == MODE_DEL))
535 mems = ONLY_CHANOPS;
536 else
537 mems = ONLY_SERVERS;
538 break;
540 case CHFL_INVEX:
541 /* if +I is disabled, allow all but +I locally */
542 if(!ConfigChannel.use_invex && MyClient(source_p) &&
543 (dir == MODE_ADD) && (parc > *parn))
544 return;
546 list = &chptr->invexlist;
547 errorval = SM_ERR_RPL_I;
548 rpl_list = RPL_INVITELIST;
549 rpl_endlist = RPL_ENDOFINVITELIST;
550 caps = CAP_IE;
552 if(ConfigChannel.use_invex || (dir == MODE_DEL))
553 mems = ONLY_CHANOPS;
554 else
555 mems = ONLY_SERVERS;
556 break;
558 case CHFL_QUIET:
559 list = &chptr->quietlist;
560 errorval = SM_ERR_RPL_Q;
561 rpl_list = RPL_BANLIST;
562 rpl_endlist = RPL_ENDOFBANLIST;
563 mems = ALL_MEMBERS;
564 caps = 0;
565 break;
567 default:
568 sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!");
569 return;
570 break;
573 if(dir == 0 || parc <= *parn)
575 if((*errors & errorval) != 0)
576 return;
577 *errors |= errorval;
579 /* non-ops cant see +eI lists.. */
580 if(alevel != CHFL_CHANOP && mode_type != CHFL_BAN &&
581 mode_type != CHFL_QUIET)
583 if(!(*errors & SM_ERR_NOOPS))
584 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
585 me.name, source_p->name, chptr->chname);
586 *errors |= SM_ERR_NOOPS;
587 return;
590 DLINK_FOREACH(ptr, list->head)
592 banptr = ptr->data;
593 sendto_one(source_p, form_str(rpl_list),
594 me.name, source_p->name, chptr->chname,
595 banptr->banstr, banptr->who, banptr->when);
597 sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname);
598 return;
601 if(alevel != CHFL_CHANOP)
603 if(!(*errors & SM_ERR_NOOPS))
604 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
605 me.name, source_p->name, chptr->chname);
606 *errors |= SM_ERR_NOOPS;
607 return;
610 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
611 return;
613 raw_mask = parv[(*parn)];
614 (*parn)++;
616 /* empty ban, or starts with ':' which messes up s2s, ignore it */
617 if(EmptyString(raw_mask) || *raw_mask == ':')
618 return;
620 if(!MyClient(source_p))
622 if(strchr(raw_mask, ' '))
623 return;
625 mask = raw_mask;
627 else
628 mask = pretty_mask(raw_mask);
630 /* we'd have problems parsing this, hyb6 does it too */
631 if(strlen(mask) > (MODEBUFLEN - 2))
632 return;
634 /* if we're adding a NEW id */
635 if(dir == MODE_ADD)
637 if (*mask == '$' && MyClient(source_p))
639 if (!valid_extban(mask, source_p, chptr, mode_type))
640 /* XXX perhaps return an error message here */
641 return;
644 /* dont allow local clients to overflow the banlist, dont
645 * let remote servers set duplicate bans
647 if(!add_id(source_p, chptr, mask, list, mode_type))
648 return;
650 mode_changes[mode_count].letter = c;
651 mode_changes[mode_count].dir = MODE_ADD;
652 mode_changes[mode_count].caps = caps;
653 mode_changes[mode_count].nocaps = 0;
654 mode_changes[mode_count].mems = mems;
655 mode_changes[mode_count].id = NULL;
656 mode_changes[mode_count++].arg = mask;
658 else if(dir == MODE_DEL)
660 if(del_id(chptr, mask, list, mode_type) == 0)
662 /* mask isn't a valid ban, check raw_mask */
663 if(del_id(chptr, raw_mask, list, mode_type))
664 mask = raw_mask;
667 mode_changes[mode_count].letter = c;
668 mode_changes[mode_count].dir = MODE_DEL;
669 mode_changes[mode_count].caps = caps;
670 mode_changes[mode_count].nocaps = 0;
671 mode_changes[mode_count].mems = mems;
672 mode_changes[mode_count].id = NULL;
673 mode_changes[mode_count++].arg = mask;
677 void
678 chm_op(struct Client *source_p, struct Channel *chptr,
679 int alevel, int parc, int *parn,
680 const char **parv, int *errors, int dir, char c, long mode_type)
682 struct membership *mstptr;
683 const char *opnick;
684 struct Client *targ_p;
686 if(alevel != CHFL_CHANOP)
688 if(!(*errors & SM_ERR_NOOPS))
689 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
690 me.name, source_p->name, chptr->chname);
691 *errors |= SM_ERR_NOOPS;
692 return;
695 if((dir == MODE_QUERY) || (parc <= *parn))
696 return;
698 opnick = parv[(*parn)];
699 (*parn)++;
701 /* empty nick */
702 if(EmptyString(opnick))
704 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
705 return;
708 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
710 return;
713 mstptr = find_channel_membership(chptr, targ_p);
715 if(mstptr == NULL)
717 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
718 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
719 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
720 *errors |= SM_ERR_NOTONCHANNEL;
721 return;
724 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
725 return;
727 if(dir == MODE_ADD)
730 * This breaks oper-override users opping themselves.
731 * Presumably a reason though?
732 if(targ_p == source_p)
733 return;
736 mode_changes[mode_count].letter = c;
737 mode_changes[mode_count].dir = MODE_ADD;
738 mode_changes[mode_count].caps = 0;
739 mode_changes[mode_count].nocaps = 0;
740 mode_changes[mode_count].mems = ALL_MEMBERS;
741 mode_changes[mode_count].id = targ_p->id;
742 mode_changes[mode_count].arg = targ_p->name;
743 mode_changes[mode_count++].client = targ_p;
745 mstptr->flags |= CHFL_CHANOP;
746 mstptr->flags &= ~CHFL_DEOPPED;
748 else
750 if(MyClient(source_p) && IsService(targ_p))
752 sendto_one(source_p, form_str(ERR_ISCHANSERVICE),
753 me.name, source_p->name, targ_p->name, chptr->chname);
754 return;
757 mode_changes[mode_count].letter = c;
758 mode_changes[mode_count].dir = MODE_DEL;
759 mode_changes[mode_count].caps = 0;
760 mode_changes[mode_count].nocaps = 0;
761 mode_changes[mode_count].mems = ALL_MEMBERS;
762 mode_changes[mode_count].id = targ_p->id;
763 mode_changes[mode_count].arg = targ_p->name;
764 mode_changes[mode_count++].client = targ_p;
766 mstptr->flags &= ~CHFL_CHANOP;
770 void
771 chm_voice(struct Client *source_p, struct Channel *chptr,
772 int alevel, int parc, int *parn,
773 const char **parv, int *errors, int dir, char c, long mode_type)
775 struct membership *mstptr;
776 const char *opnick;
777 struct Client *targ_p;
779 if(alevel != CHFL_CHANOP)
781 if(!(*errors & SM_ERR_NOOPS))
782 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
783 me.name, source_p->name, chptr->chname);
784 *errors |= SM_ERR_NOOPS;
785 return;
788 if((dir == MODE_QUERY) || parc <= *parn)
789 return;
791 opnick = parv[(*parn)];
792 (*parn)++;
794 /* empty nick */
795 if(EmptyString(opnick))
797 sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*");
798 return;
801 if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL)
803 return;
806 mstptr = find_channel_membership(chptr, targ_p);
808 if(mstptr == NULL)
810 if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p))
811 sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL,
812 form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname);
813 *errors |= SM_ERR_NOTONCHANNEL;
814 return;
817 if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
818 return;
820 if(dir == MODE_ADD)
822 mode_changes[mode_count].letter = c;
823 mode_changes[mode_count].dir = MODE_ADD;
824 mode_changes[mode_count].caps = 0;
825 mode_changes[mode_count].nocaps = 0;
826 mode_changes[mode_count].mems = ALL_MEMBERS;
827 mode_changes[mode_count].id = targ_p->id;
828 mode_changes[mode_count].arg = targ_p->name;
829 mode_changes[mode_count++].client = targ_p;
831 mstptr->flags |= CHFL_VOICE;
833 else
835 mode_changes[mode_count].letter = 'v';
836 mode_changes[mode_count].dir = MODE_DEL;
837 mode_changes[mode_count].caps = 0;
838 mode_changes[mode_count].nocaps = 0;
839 mode_changes[mode_count].mems = ALL_MEMBERS;
840 mode_changes[mode_count].id = targ_p->id;
841 mode_changes[mode_count].arg = targ_p->name;
842 mode_changes[mode_count++].client = targ_p;
844 mstptr->flags &= ~CHFL_VOICE;
848 void
849 chm_limit(struct Client *source_p, struct Channel *chptr,
850 int alevel, int parc, int *parn,
851 const char **parv, int *errors, int dir, char c, long mode_type)
853 const char *lstr;
854 static char limitstr[30];
855 int limit;
857 if(alevel != CHFL_CHANOP)
859 if(!(*errors & SM_ERR_NOOPS))
860 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
861 me.name, source_p->name, chptr->chname);
862 *errors |= SM_ERR_NOOPS;
863 return;
866 if(dir == MODE_QUERY)
867 return;
869 if((dir == MODE_ADD) && parc > *parn)
871 lstr = parv[(*parn)];
872 (*parn)++;
874 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
875 return;
877 ircsprintf(limitstr, "%d", limit);
879 mode_changes[mode_count].letter = c;
880 mode_changes[mode_count].dir = MODE_ADD;
881 mode_changes[mode_count].caps = 0;
882 mode_changes[mode_count].nocaps = 0;
883 mode_changes[mode_count].mems = ALL_MEMBERS;
884 mode_changes[mode_count].id = NULL;
885 mode_changes[mode_count++].arg = limitstr;
887 chptr->mode.limit = limit;
889 else if(dir == MODE_DEL)
891 if(!chptr->mode.limit)
892 return;
894 chptr->mode.limit = 0;
896 mode_changes[mode_count].letter = c;
897 mode_changes[mode_count].dir = MODE_DEL;
898 mode_changes[mode_count].caps = 0;
899 mode_changes[mode_count].nocaps = 0;
900 mode_changes[mode_count].mems = ALL_MEMBERS;
901 mode_changes[mode_count].id = NULL;
902 mode_changes[mode_count++].arg = NULL;
906 void
907 chm_banlimit(struct Client *source_p, struct Channel *chptr,
908 int alevel, int parc, int *parn,
909 const char **parv, int *errors, int dir, char c, long mode_type)
911 const char *lstr;
912 static char limitstr[30];
913 int limit;
915 if(!IsServer(source_p) && MyClient(source_p) && !IsOperCModes(source_p))
917 if(!(*errors & SM_ERR_NOPRIVS))
919 if(IsOper(source_p))
920 sendto_one(source_p, form_str(ERR_NOPRIVS),
921 me.name, source_p->name, "set_cmode");
922 else
923 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
925 *errors |= SM_ERR_NOPRIVS;
926 return;
929 if(dir == MODE_QUERY)
930 return;
932 if((dir == MODE_ADD) && parc > *parn)
934 lstr = parv[(*parn)];
935 (*parn)++;
937 if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
938 return;
940 ircsprintf(limitstr, "%d", limit);
942 mode_changes[mode_count].letter = c;
943 mode_changes[mode_count].dir = MODE_ADD;
944 mode_changes[mode_count].caps = 0;
945 mode_changes[mode_count].nocaps = 0;
946 mode_changes[mode_count].mems = ALL_MEMBERS;
947 mode_changes[mode_count].id = NULL;
948 mode_changes[mode_count++].arg = limitstr;
950 chptr->mode.banlimit = limit;
952 else if(dir == MODE_DEL)
954 if(!chptr->mode.banlimit)
955 return;
957 chptr->mode.banlimit = 0;
959 mode_changes[mode_count].letter = c;
960 mode_changes[mode_count].dir = MODE_DEL;
961 mode_changes[mode_count].caps = 0;
962 mode_changes[mode_count].nocaps = 0;
963 mode_changes[mode_count].mems = ALL_MEMBERS;
964 mode_changes[mode_count].id = NULL;
965 mode_changes[mode_count++].arg = NULL;
969 void
970 chm_throttle(struct Client *source_p, struct Channel *chptr,
971 int alevel, int parc, int *parn,
972 const char **parv, int *errors, int dir, char c, long mode_type)
974 int joins = 0, timeslice = 0;
976 if(alevel != CHFL_CHANOP)
978 if(!(*errors & SM_ERR_NOOPS))
979 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
980 me.name, source_p->name, chptr->chname);
981 *errors |= SM_ERR_NOOPS;
982 return;
985 if(dir == MODE_QUERY)
986 return;
988 if((dir == MODE_ADD) && parc > *parn)
990 sscanf(parv[(*parn)], "%d:%d", &joins, &timeslice);
992 if(!joins || !timeslice)
993 return;
995 mode_changes[mode_count].letter = c;
996 mode_changes[mode_count].dir = MODE_ADD;
997 mode_changes[mode_count].caps = 0;
998 mode_changes[mode_count].nocaps = 0;
999 mode_changes[mode_count].mems = ALL_MEMBERS;
1000 mode_changes[mode_count].id = NULL;
1001 mode_changes[mode_count++].arg = parv[(*parn)];
1003 (*parn)++;
1005 chptr->mode.join_num = joins;
1006 chptr->mode.join_time = timeslice;
1008 else if(dir == MODE_DEL)
1010 if(!chptr->mode.join_num)
1011 return;
1013 chptr->mode.join_num = 0;
1014 chptr->mode.join_time = 0;
1015 chptr->join_count = 0;
1016 chptr->join_delta = 0;
1018 mode_changes[mode_count].letter = c;
1019 mode_changes[mode_count].dir = MODE_DEL;
1020 mode_changes[mode_count].caps = 0;
1021 mode_changes[mode_count].nocaps = 0;
1022 mode_changes[mode_count].mems = ALL_MEMBERS;
1023 mode_changes[mode_count].id = NULL;
1024 mode_changes[mode_count++].arg = NULL;
1028 void
1029 chm_forward(struct Client *source_p, struct Channel *chptr,
1030 int alevel, int parc, int *parn,
1031 const char **parv, int *errors, int dir, char c, long mode_type)
1033 struct Channel *targptr = NULL;
1034 struct membership *msptr;
1035 const char *forward;
1037 if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn))
1039 if (!(*errors & SM_ERR_RPL_F))
1041 if (*chptr->mode.forward == '\0')
1042 sendto_one(source_p, ":%s NOTICE %s :%s has no forward channel", me.name, source_p->name, chptr->chname);
1043 else
1044 sendto_one(source_p, ":%s NOTICE %s :%s forward channel is %s", me.name, source_p->name, chptr->chname, chptr->mode.forward);
1045 *errors |= SM_ERR_RPL_F;
1047 return;
1050 #ifndef FORWARD_OPERONLY
1051 if(alevel != CHFL_CHANOP)
1053 if(!(*errors & SM_ERR_NOOPS))
1054 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1055 me.name, source_p->name, chptr->chname);
1056 *errors |= SM_ERR_NOOPS;
1057 return;
1059 #else
1060 if(!IsOperCModes(source_p) && !IsServer(source_p))
1062 if(!(*errors & SM_ERR_NOPRIVS))
1063 sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES));
1064 *errors |= SM_ERR_NOPRIVS;
1065 return;
1067 #endif
1069 if(dir == MODE_ADD && parc > *parn)
1071 forward = parv[(*parn)];
1072 (*parn)++;
1074 if(EmptyString(forward))
1075 return;
1076 if(!check_channel_name(forward) ||
1077 (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward))))
1079 sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward);
1080 return;
1082 if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL)
1084 sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL,
1085 form_str(ERR_NOSUCHCHANNEL), forward);
1086 return;
1088 if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET))
1090 if((msptr = find_channel_membership(targptr, source_p)) == NULL ||
1091 get_channel_access(source_p, msptr) != CHFL_CHANOP)
1093 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1094 me.name, source_p->name, targptr->chname);
1095 return;
1099 strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward));
1101 mode_changes[mode_count].letter = c;
1102 mode_changes[mode_count].dir = MODE_ADD;
1103 mode_changes[mode_count].caps = 0;
1104 mode_changes[mode_count].nocaps = 0;
1105 mode_changes[mode_count].mems = ALL_MEMBERS;
1106 mode_changes[mode_count].id = NULL;
1107 mode_changes[mode_count++].arg = forward;
1109 else if(dir == MODE_DEL)
1111 if(!(*chptr->mode.forward))
1112 return;
1114 *chptr->mode.forward = '\0';
1116 mode_changes[mode_count].letter = c;
1117 mode_changes[mode_count].dir = MODE_DEL;
1118 mode_changes[mode_count].caps = 0;
1119 mode_changes[mode_count].nocaps = 0;
1120 mode_changes[mode_count].mems = ALL_MEMBERS;
1121 mode_changes[mode_count].id = NULL;
1122 mode_changes[mode_count++].arg = NULL;
1126 void
1127 chm_key(struct Client *source_p, struct Channel *chptr,
1128 int alevel, int parc, int *parn,
1129 const char **parv, int *errors, int dir, char c, long mode_type)
1131 char *key;
1133 if(alevel != CHFL_CHANOP)
1135 if(!(*errors & SM_ERR_NOOPS))
1136 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1137 me.name, source_p->name, chptr->chname);
1138 *errors |= SM_ERR_NOOPS;
1139 return;
1142 if(dir == MODE_QUERY)
1143 return;
1145 if((dir == MODE_ADD) && parc > *parn)
1147 key = LOCAL_COPY(parv[(*parn)]);
1148 (*parn)++;
1150 if(MyClient(source_p))
1151 fix_key(key);
1152 else
1153 fix_key_remote(key);
1155 if(EmptyString(key))
1156 return;
1158 s_assert(key[0] != ' ');
1159 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1161 mode_changes[mode_count].letter = c;
1162 mode_changes[mode_count].dir = MODE_ADD;
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 = chptr->mode.key;
1169 else if(dir == MODE_DEL)
1171 static char splat[] = "*";
1172 int i;
1174 if(parc > *parn)
1175 (*parn)++;
1177 if(!(*chptr->mode.key))
1178 return;
1180 /* hack time. when we get a +k-k mode, the +k arg is
1181 * chptr->mode.key, which the -k sets to \0, so hunt for a
1182 * +k when we get a -k, and set the arg to splat. --anfl
1184 for(i = 0; i < mode_count; i++)
1186 if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD)
1187 mode_changes[i].arg = splat;
1190 *chptr->mode.key = 0;
1192 mode_changes[mode_count].letter = c;
1193 mode_changes[mode_count].dir = MODE_DEL;
1194 mode_changes[mode_count].caps = 0;
1195 mode_changes[mode_count].nocaps = 0;
1196 mode_changes[mode_count].mems = ALL_MEMBERS;
1197 mode_changes[mode_count].id = NULL;
1198 mode_changes[mode_count++].arg = "*";
1202 void
1203 chm_regonly(struct Client *source_p, struct Channel *chptr,
1204 int alevel, int parc, int *parn,
1205 const char **parv, int *errors, int dir, char c, long mode_type)
1207 if(alevel != CHFL_CHANOP)
1209 if(!(*errors & SM_ERR_NOOPS))
1210 sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED),
1211 me.name, source_p->name, chptr->chname);
1212 *errors |= SM_ERR_NOOPS;
1213 return;
1216 if(dir == MODE_QUERY)
1217 return;
1219 if(((dir == MODE_ADD) && (chptr->mode.mode & mode_type)) ||
1220 ((dir == MODE_DEL) && !(chptr->mode.mode & mode_type)))
1221 return;
1223 if(dir == MODE_ADD)
1224 chptr->mode.mode |= mode_type;
1225 else
1226 chptr->mode.mode &= ~mode_type;
1228 mode_changes[mode_count].letter = c;
1229 mode_changes[mode_count].dir = dir;
1230 mode_changes[mode_count].caps = CAP_SERVICE;
1231 mode_changes[mode_count].nocaps = 0;
1232 mode_changes[mode_count].mems = ALL_MEMBERS;
1233 mode_changes[mode_count].id = NULL;
1234 mode_changes[mode_count++].arg = NULL;
1237 /* *INDENT-OFF* */
1238 struct ChannelMode chmode_table[256] =
1240 {chm_nosuch, 0 }, /* 0x00 */
1241 {chm_nosuch, 0 }, /* 0x01 */
1242 {chm_nosuch, 0 }, /* 0x02 */
1243 {chm_nosuch, 0 }, /* 0x03 */
1244 {chm_nosuch, 0 }, /* 0x04 */
1245 {chm_nosuch, 0 }, /* 0x05 */
1246 {chm_nosuch, 0 }, /* 0x06 */
1247 {chm_nosuch, 0 }, /* 0x07 */
1248 {chm_nosuch, 0 }, /* 0x08 */
1249 {chm_nosuch, 0 }, /* 0x09 */
1250 {chm_nosuch, 0 }, /* 0x0a */
1251 {chm_nosuch, 0 }, /* 0x0b */
1252 {chm_nosuch, 0 }, /* 0x0c */
1253 {chm_nosuch, 0 }, /* 0x0d */
1254 {chm_nosuch, 0 }, /* 0x0e */
1255 {chm_nosuch, 0 }, /* 0x0f */
1256 {chm_nosuch, 0 }, /* 0x10 */
1257 {chm_nosuch, 0 }, /* 0x11 */
1258 {chm_nosuch, 0 }, /* 0x12 */
1259 {chm_nosuch, 0 }, /* 0x13 */
1260 {chm_nosuch, 0 }, /* 0x14 */
1261 {chm_nosuch, 0 }, /* 0x15 */
1262 {chm_nosuch, 0 }, /* 0x16 */
1263 {chm_nosuch, 0 }, /* 0x17 */
1264 {chm_nosuch, 0 }, /* 0x18 */
1265 {chm_nosuch, 0 }, /* 0x19 */
1266 {chm_nosuch, 0 }, /* 0x1a */
1267 {chm_nosuch, 0 }, /* 0x1b */
1268 {chm_nosuch, 0 }, /* 0x1c */
1269 {chm_nosuch, 0 }, /* 0x1d */
1270 {chm_nosuch, 0 }, /* 0x1e */
1271 {chm_nosuch, 0 }, /* 0x1f */
1272 {chm_nosuch, 0 }, /* 0x20 */
1273 {chm_nosuch, 0 }, /* 0x21 */
1274 {chm_nosuch, 0 }, /* 0x22 */
1275 {chm_nosuch, 0 }, /* 0x23 */
1276 {chm_nosuch, 0 }, /* 0x24 */
1277 {chm_nosuch, 0 }, /* 0x25 */
1278 {chm_nosuch, 0 }, /* 0x26 */
1279 {chm_nosuch, 0 }, /* 0x27 */
1280 {chm_nosuch, 0 }, /* 0x28 */
1281 {chm_nosuch, 0 }, /* 0x29 */
1282 {chm_nosuch, 0 }, /* 0x2a */
1283 {chm_nosuch, 0 }, /* 0x2b */
1284 {chm_nosuch, 0 }, /* 0x2c */
1285 {chm_nosuch, 0 }, /* 0x2d */
1286 {chm_nosuch, 0 }, /* 0x2e */
1287 {chm_nosuch, 0 }, /* 0x2f */
1288 {chm_nosuch, 0 }, /* 0x30 */
1289 {chm_nosuch, 0 }, /* 0x31 */
1290 {chm_nosuch, 0 }, /* 0x32 */
1291 {chm_nosuch, 0 }, /* 0x33 */
1292 {chm_nosuch, 0 }, /* 0x34 */
1293 {chm_nosuch, 0 }, /* 0x35 */
1294 {chm_nosuch, 0 }, /* 0x36 */
1295 {chm_nosuch, 0 }, /* 0x37 */
1296 {chm_nosuch, 0 }, /* 0x38 */
1297 {chm_nosuch, 0 }, /* 0x39 */
1298 {chm_nosuch, 0 }, /* 0x3a */
1299 {chm_nosuch, 0 }, /* 0x3b */
1300 {chm_nosuch, 0 }, /* 0x3c */
1301 {chm_nosuch, 0 }, /* 0x3d */
1302 {chm_nosuch, 0 }, /* 0x3e */
1303 {chm_nosuch, 0 }, /* 0x3f */
1305 {chm_nosuch, 0 }, /* @ */
1306 {chm_nosuch, 0 }, /* A */
1307 {chm_nosuch, 0 }, /* B */
1308 {chm_nosuch, 0 }, /* C */
1309 {chm_nosuch, 0 }, /* D */
1310 {chm_nosuch, 0 }, /* E */
1311 {chm_simple, MODE_FREETARGET }, /* F */
1312 {chm_nosuch, 0 }, /* G */
1313 {chm_nosuch, 0 }, /* H */
1314 {chm_ban, CHFL_INVEX }, /* I */
1315 {chm_nosuch, 0 }, /* J */
1316 {chm_nosuch, 0 }, /* K */
1317 {chm_banlimit,0 }, /* L */
1318 {chm_nosuch, 0 }, /* M */
1319 {chm_nosuch, 0 }, /* N */
1320 {chm_nosuch, 0 }, /* O */
1321 {chm_staff, MODE_PERMANENT }, /* P */
1322 {chm_simple, MODE_DISFORWARD }, /* Q */
1323 {chm_simple, MODE_QUIETUNID }, /* R */
1324 {chm_nosuch, 0 }, /* S */
1325 {chm_nosuch, 0 }, /* T */
1326 {chm_nosuch, 0 }, /* U */
1327 {chm_nosuch, 0 }, /* V */
1328 {chm_nosuch, 0 }, /* W */
1329 {chm_nosuch, 0 }, /* X */
1330 {chm_nosuch, 0 }, /* Y */
1331 {chm_nosuch, 0 }, /* Z */
1332 {chm_nosuch, 0 },
1333 {chm_nosuch, 0 },
1334 {chm_nosuch, 0 },
1335 {chm_nosuch, 0 },
1336 {chm_nosuch, 0 },
1337 {chm_nosuch, 0 },
1338 {chm_nosuch, 0 }, /* a */
1339 {chm_ban, CHFL_BAN }, /* b */
1340 {chm_simple, MODE_NOCOLOR }, /* c */
1341 {chm_nosuch, 0 }, /* d */
1342 {chm_ban, CHFL_EXCEPTION }, /* e */
1343 {chm_forward, 0 }, /* f */
1344 {chm_simple, MODE_FREEINVITE }, /* g */
1345 {chm_nosuch, 0 }, /* h */
1346 {chm_simple, MODE_INVITEONLY }, /* i */
1347 {chm_throttle, 0 }, /* j */
1348 {chm_key, 0 }, /* k */
1349 {chm_limit, 0 }, /* l */
1350 {chm_simple, MODE_MODERATED }, /* m */
1351 {chm_simple, MODE_NOPRIVMSGS }, /* n */
1352 {chm_op, 0 }, /* o */
1353 {chm_simple, MODE_PRIVATE }, /* p */
1354 {chm_ban, CHFL_QUIET }, /* q */
1355 {chm_regonly, MODE_REGONLY }, /* r */
1356 {chm_simple, MODE_SECRET }, /* s */
1357 {chm_simple, MODE_TOPICLIMIT }, /* t */
1358 {chm_nosuch, 0 }, /* u */
1359 {chm_voice, 0 }, /* v */
1360 {chm_nosuch, 0 }, /* w */
1361 {chm_nosuch, 0 }, /* x */
1362 {chm_nosuch, 0 }, /* y */
1363 {chm_simple, MODE_OPMODERATE }, /* z */
1365 {chm_nosuch, 0 }, /* 0x7b */
1366 {chm_nosuch, 0 }, /* 0x7c */
1367 {chm_nosuch, 0 }, /* 0x7d */
1368 {chm_nosuch, 0 }, /* 0x7e */
1369 {chm_nosuch, 0 }, /* 0x7f */
1371 {chm_nosuch, 0 }, /* 0x80 */
1372 {chm_nosuch, 0 }, /* 0x81 */
1373 {chm_nosuch, 0 }, /* 0x82 */
1374 {chm_nosuch, 0 }, /* 0x83 */
1375 {chm_nosuch, 0 }, /* 0x84 */
1376 {chm_nosuch, 0 }, /* 0x85 */
1377 {chm_nosuch, 0 }, /* 0x86 */
1378 {chm_nosuch, 0 }, /* 0x87 */
1379 {chm_nosuch, 0 }, /* 0x88 */
1380 {chm_nosuch, 0 }, /* 0x89 */
1381 {chm_nosuch, 0 }, /* 0x8a */
1382 {chm_nosuch, 0 }, /* 0x8b */
1383 {chm_nosuch, 0 }, /* 0x8c */
1384 {chm_nosuch, 0 }, /* 0x8d */
1385 {chm_nosuch, 0 }, /* 0x8e */
1386 {chm_nosuch, 0 }, /* 0x8f */
1388 {chm_nosuch, 0 }, /* 0x90 */
1389 {chm_nosuch, 0 }, /* 0x91 */
1390 {chm_nosuch, 0 }, /* 0x92 */
1391 {chm_nosuch, 0 }, /* 0x93 */
1392 {chm_nosuch, 0 }, /* 0x94 */
1393 {chm_nosuch, 0 }, /* 0x95 */
1394 {chm_nosuch, 0 }, /* 0x96 */
1395 {chm_nosuch, 0 }, /* 0x97 */
1396 {chm_nosuch, 0 }, /* 0x98 */
1397 {chm_nosuch, 0 }, /* 0x99 */
1398 {chm_nosuch, 0 }, /* 0x9a */
1399 {chm_nosuch, 0 }, /* 0x9b */
1400 {chm_nosuch, 0 }, /* 0x9c */
1401 {chm_nosuch, 0 }, /* 0x9d */
1402 {chm_nosuch, 0 }, /* 0x9e */
1403 {chm_nosuch, 0 }, /* 0x9f */
1405 {chm_nosuch, 0 }, /* 0xa0 */
1406 {chm_nosuch, 0 }, /* 0xa1 */
1407 {chm_nosuch, 0 }, /* 0xa2 */
1408 {chm_nosuch, 0 }, /* 0xa3 */
1409 {chm_nosuch, 0 }, /* 0xa4 */
1410 {chm_nosuch, 0 }, /* 0xa5 */
1411 {chm_nosuch, 0 }, /* 0xa6 */
1412 {chm_nosuch, 0 }, /* 0xa7 */
1413 {chm_nosuch, 0 }, /* 0xa8 */
1414 {chm_nosuch, 0 }, /* 0xa9 */
1415 {chm_nosuch, 0 }, /* 0xaa */
1416 {chm_nosuch, 0 }, /* 0xab */
1417 {chm_nosuch, 0 }, /* 0xac */
1418 {chm_nosuch, 0 }, /* 0xad */
1419 {chm_nosuch, 0 }, /* 0xae */
1420 {chm_nosuch, 0 }, /* 0xaf */
1422 {chm_nosuch, 0 }, /* 0xb0 */
1423 {chm_nosuch, 0 }, /* 0xb1 */
1424 {chm_nosuch, 0 }, /* 0xb2 */
1425 {chm_nosuch, 0 }, /* 0xb3 */
1426 {chm_nosuch, 0 }, /* 0xb4 */
1427 {chm_nosuch, 0 }, /* 0xb5 */
1428 {chm_nosuch, 0 }, /* 0xb6 */
1429 {chm_nosuch, 0 }, /* 0xb7 */
1430 {chm_nosuch, 0 }, /* 0xb8 */
1431 {chm_nosuch, 0 }, /* 0xb9 */
1432 {chm_nosuch, 0 }, /* 0xba */
1433 {chm_nosuch, 0 }, /* 0xbb */
1434 {chm_nosuch, 0 }, /* 0xbc */
1435 {chm_nosuch, 0 }, /* 0xbd */
1436 {chm_nosuch, 0 }, /* 0xbe */
1437 {chm_nosuch, 0 }, /* 0xbf */
1439 {chm_nosuch, 0 }, /* 0xc0 */
1440 {chm_nosuch, 0 }, /* 0xc1 */
1441 {chm_nosuch, 0 }, /* 0xc2 */
1442 {chm_nosuch, 0 }, /* 0xc3 */
1443 {chm_nosuch, 0 }, /* 0xc4 */
1444 {chm_nosuch, 0 }, /* 0xc5 */
1445 {chm_nosuch, 0 }, /* 0xc6 */
1446 {chm_nosuch, 0 }, /* 0xc7 */
1447 {chm_nosuch, 0 }, /* 0xc8 */
1448 {chm_nosuch, 0 }, /* 0xc9 */
1449 {chm_nosuch, 0 }, /* 0xca */
1450 {chm_nosuch, 0 }, /* 0xcb */
1451 {chm_nosuch, 0 }, /* 0xcc */
1452 {chm_nosuch, 0 }, /* 0xcd */
1453 {chm_nosuch, 0 }, /* 0xce */
1454 {chm_nosuch, 0 }, /* 0xcf */
1456 {chm_nosuch, 0 }, /* 0xd0 */
1457 {chm_nosuch, 0 }, /* 0xd1 */
1458 {chm_nosuch, 0 }, /* 0xd2 */
1459 {chm_nosuch, 0 }, /* 0xd3 */
1460 {chm_nosuch, 0 }, /* 0xd4 */
1461 {chm_nosuch, 0 }, /* 0xd5 */
1462 {chm_nosuch, 0 }, /* 0xd6 */
1463 {chm_nosuch, 0 }, /* 0xd7 */
1464 {chm_nosuch, 0 }, /* 0xd8 */
1465 {chm_nosuch, 0 }, /* 0xd9 */
1466 {chm_nosuch, 0 }, /* 0xda */
1467 {chm_nosuch, 0 }, /* 0xdb */
1468 {chm_nosuch, 0 }, /* 0xdc */
1469 {chm_nosuch, 0 }, /* 0xdd */
1470 {chm_nosuch, 0 }, /* 0xde */
1471 {chm_nosuch, 0 }, /* 0xdf */
1473 {chm_nosuch, 0 }, /* 0xe0 */
1474 {chm_nosuch, 0 }, /* 0xe1 */
1475 {chm_nosuch, 0 }, /* 0xe2 */
1476 {chm_nosuch, 0 }, /* 0xe3 */
1477 {chm_nosuch, 0 }, /* 0xe4 */
1478 {chm_nosuch, 0 }, /* 0xe5 */
1479 {chm_nosuch, 0 }, /* 0xe6 */
1480 {chm_nosuch, 0 }, /* 0xe7 */
1481 {chm_nosuch, 0 }, /* 0xe8 */
1482 {chm_nosuch, 0 }, /* 0xe9 */
1483 {chm_nosuch, 0 }, /* 0xea */
1484 {chm_nosuch, 0 }, /* 0xeb */
1485 {chm_nosuch, 0 }, /* 0xec */
1486 {chm_nosuch, 0 }, /* 0xed */
1487 {chm_nosuch, 0 }, /* 0xee */
1488 {chm_nosuch, 0 }, /* 0xef */
1490 {chm_nosuch, 0 }, /* 0xf0 */
1491 {chm_nosuch, 0 }, /* 0xf1 */
1492 {chm_nosuch, 0 }, /* 0xf2 */
1493 {chm_nosuch, 0 }, /* 0xf3 */
1494 {chm_nosuch, 0 }, /* 0xf4 */
1495 {chm_nosuch, 0 }, /* 0xf5 */
1496 {chm_nosuch, 0 }, /* 0xf6 */
1497 {chm_nosuch, 0 }, /* 0xf7 */
1498 {chm_nosuch, 0 }, /* 0xf8 */
1499 {chm_nosuch, 0 }, /* 0xf9 */
1500 {chm_nosuch, 0 }, /* 0xfa */
1501 {chm_nosuch, 0 }, /* 0xfb */
1502 {chm_nosuch, 0 }, /* 0xfc */
1503 {chm_nosuch, 0 }, /* 0xfd */
1504 {chm_nosuch, 0 }, /* 0xfe */
1505 {chm_nosuch, 0 }, /* 0xff */
1508 /* *INDENT-ON* */
1510 /* set_channel_mode()
1512 * inputs - client, source, channel, membership pointer, params
1513 * output -
1514 * side effects - channel modes/memberships are changed, MODE is issued
1516 * Extensively modified to be hotpluggable, 03/09/06 -- nenolod
1518 void
1519 set_channel_mode(struct Client *client_p, struct Client *source_p,
1520 struct Channel *chptr, struct membership *msptr, int parc, const char *parv[])
1522 static char modebuf[BUFSIZE];
1523 static char parabuf[BUFSIZE];
1524 char *mbuf;
1525 char *pbuf;
1526 int cur_len, mlen, paralen, paracount, arglen, len;
1527 int i, j, flags;
1528 int dir = MODE_ADD;
1529 int parn = 1;
1530 int errors = 0;
1531 int alevel;
1532 const char *ml = parv[0];
1533 char c;
1534 struct Client *fakesource_p;
1536 mask_pos = 0;
1537 mode_count = 0;
1538 mode_limit = 0;
1540 alevel = get_channel_access(source_p, msptr);
1542 /* Hide connecting server on netburst -- jilles */
1543 if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p))
1544 fakesource_p = &me;
1545 else
1546 fakesource_p = source_p;
1548 for(; (c = *ml) != 0; ml++)
1550 switch (c)
1552 case '+':
1553 dir = MODE_ADD;
1554 break;
1555 case '-':
1556 dir = MODE_DEL;
1557 break;
1558 case '=':
1559 dir = MODE_QUERY;
1560 break;
1561 default:
1562 chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel,
1563 parc, &parn, parv,
1564 &errors, dir, c,
1565 chmode_table[(unsigned char) c].mode_type);
1566 break;
1570 /* bail out if we have nothing to do... */
1571 if(!mode_count)
1572 return;
1574 if(IsServer(source_p))
1575 mlen = ircsprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname);
1576 else
1577 mlen = ircsprintf(modebuf, ":%s!%s@%s MODE %s ",
1578 source_p->name, source_p->username,
1579 source_p->host, chptr->chname);
1581 for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS)
1583 cur_len = mlen;
1584 mbuf = modebuf + mlen;
1585 pbuf = parabuf;
1586 parabuf[0] = '\0';
1587 paracount = paralen = 0;
1588 dir = MODE_QUERY;
1590 for(i = 0; i < mode_count; i++)
1592 if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags)
1593 continue;
1595 if(mode_changes[i].arg != NULL)
1597 arglen = strlen(mode_changes[i].arg);
1599 if(arglen > MODEBUFLEN - 5)
1600 continue;
1602 else
1603 arglen = 0;
1605 /* if we're creeping over MAXMODEPARAMSSERV, or over
1606 * bufsize (4 == +/-,modechar,two spaces) send now.
1608 if(mode_changes[i].arg != NULL &&
1609 ((paracount == MAXMODEPARAMSSERV) ||
1610 ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3))))
1612 *mbuf = '\0';
1614 if(cur_len > mlen)
1615 sendto_channel_local(flags, chptr, "%s %s", modebuf,
1616 parabuf);
1617 else
1618 continue;
1620 paracount = paralen = 0;
1621 cur_len = mlen;
1622 mbuf = modebuf + mlen;
1623 pbuf = parabuf;
1624 parabuf[0] = '\0';
1625 dir = MODE_QUERY;
1628 if(dir != mode_changes[i].dir)
1630 *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1631 cur_len++;
1632 dir = mode_changes[i].dir;
1635 *mbuf++ = mode_changes[i].letter;
1636 cur_len++;
1638 if(mode_changes[i].arg != NULL)
1640 paracount++;
1641 len = ircsprintf(pbuf, "%s ", mode_changes[i].arg);
1642 pbuf += len;
1643 paralen += len;
1647 if(paralen && parabuf[paralen - 1] == ' ')
1648 parabuf[paralen - 1] = '\0';
1650 *mbuf = '\0';
1651 if(cur_len > mlen)
1652 sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf);
1655 /* only propagate modes originating locally, or if we're hubbing */
1656 if(MyClient(source_p) || dlink_list_length(&serv_list) > 1)
1657 send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count);