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