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