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