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