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