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