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