]>
Commit | Line | Data |
---|---|---|
212380e3 | 1 | /* |
2 | * charybdis: A slightly useful ircd. | |
3 | * chmode.c: channel mode management | |
4 | * | |
5 | * Copyright (C) 1990 Jarkko Oikarinen and University of Oulu, Co Center | |
6 | * Copyright (C) 1996-2002 Hybrid Development Team | |
7 | * Copyright (C) 2002-2005 ircd-ratbox development team | |
8 | * Copyright (C) 2005-2006 charybdis development team | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
23 | * USA | |
24 | * | |
83294285 | 25 | * $Id: chmode.c 3580 2007-11-07 23:45:14Z jilles $ |
212380e3 | 26 | */ |
27 | ||
28 | #include "stdinc.h" | |
212380e3 | 29 | #include "channel.h" |
30 | #include "client.h" | |
31 | #include "common.h" | |
32 | #include "hash.h" | |
33 | #include "hook.h" | |
13ae2f4b | 34 | #include "match.h" |
212380e3 | 35 | #include "ircd.h" |
36 | #include "numeric.h" | |
37 | #include "s_serv.h" /* captab */ | |
38 | #include "s_user.h" | |
39 | #include "send.h" | |
40 | #include "whowas.h" | |
41 | #include "s_conf.h" /* ConfigFileEntry, ConfigChannel */ | |
42 | #include "s_newconf.h" | |
d3455e2c | 43 | #include "logger.h" |
b5482c91 | 44 | #include "chmode.h" |
a039358e | 45 | #include "irc_dictionary.h" |
212380e3 | 46 | |
47 | /* bitmasks for error returns, so we send once per call */ | |
48 | #define SM_ERR_NOTS 0x00000001 /* No TS on channel */ | |
49 | #define SM_ERR_NOOPS 0x00000002 /* No chan ops */ | |
50 | #define SM_ERR_UNKNOWN 0x00000004 | |
51 | #define SM_ERR_RPL_C 0x00000008 | |
52 | #define SM_ERR_RPL_B 0x00000010 | |
53 | #define SM_ERR_RPL_E 0x00000020 | |
54 | #define SM_ERR_NOTONCHANNEL 0x00000040 /* Not on channel */ | |
55 | #define SM_ERR_RPL_I 0x00000100 | |
56 | #define SM_ERR_RPL_D 0x00000200 | |
57 | #define SM_ERR_NOPRIVS 0x00000400 | |
58 | #define SM_ERR_RPL_Q 0x00000800 | |
59 | #define SM_ERR_RPL_F 0x00001000 | |
60 | ||
c08f4515 JT |
61 | #define MAXMODES_SIMPLE 46 /* a-zA-Z except bqeIov */ |
62 | ||
212380e3 | 63 | static struct ChModeChange mode_changes[BUFSIZE]; |
64 | static int mode_count; | |
65 | static int mode_limit; | |
c08f4515 | 66 | static int mode_limit_simple; |
212380e3 | 67 | static int mask_pos; |
4ed822ed | 68 | static int no_override_deop; |
212380e3 | 69 | |
2392eb24 VY |
70 | char cflagsbuf[256]; |
71 | char cflagsmyinfo[256]; | |
72 | ||
75818939 | 73 | int chmode_flags[256]; |
7608ef49 | 74 | |
57d299ac | 75 | /* OPTIMIZE ME! -- dwr */ |
75818939 VY |
76 | void |
77 | construct_noparam_modes(void) | |
78 | { | |
79 | int i; | |
2392eb24 VY |
80 | char *ptr = cflagsbuf; |
81 | char *ptr2 = cflagsmyinfo; | |
57d299ac | 82 | static int prev_chmode_flags[256]; |
2392eb24 VY |
83 | |
84 | *ptr = '\0'; | |
85 | *ptr2 = '\0'; | |
75818939 VY |
86 | |
87 | for(i = 0; i < 256; i++) | |
88 | { | |
6b3b07a8 VY |
89 | if( !(chmode_table[i].set_func == chm_ban) && |
90 | !(chmode_table[i].set_func == chm_forward) && | |
91 | !(chmode_table[i].set_func == chm_throttle) && | |
92 | !(chmode_table[i].set_func == chm_key) && | |
93 | !(chmode_table[i].set_func == chm_limit) && | |
82f8e812 | 94 | !(chmode_table[i].set_func == chm_owner) && |
6b3b07a8 | 95 | !(chmode_table[i].set_func == chm_op) && |
82f8e812 | 96 | !(chmode_table[i].set_func == chm_halfop) && |
6b3b07a8 | 97 | !(chmode_table[i].set_func == chm_voice)) |
75818939 VY |
98 | { |
99 | chmode_flags[i] = chmode_table[i].mode_type; | |
100 | } | |
101 | else | |
102 | { | |
103 | chmode_flags[i] = 0; | |
104 | } | |
57d299ac VY |
105 | |
106 | if (prev_chmode_flags[i] != 0 && prev_chmode_flags[i] != chmode_flags[i]) | |
107 | { | |
108 | if (chmode_flags[i] == 0) | |
109 | { | |
110 | chmode_table[i].set_func = chm_orphaned; | |
111 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Cmode +%c is now orphaned", i); | |
112 | } | |
113 | else | |
114 | { | |
115 | sendto_realops_snomask(SNO_DEBUG, L_ALL, "Orphaned cmode +%c is picked up by module", i); | |
116 | } | |
117 | chmode_flags[i] = prev_chmode_flags[i]; | |
118 | } | |
119 | else | |
120 | prev_chmode_flags[i] = chmode_flags[i]; | |
2392eb24 VY |
121 | |
122 | switch (chmode_flags[i]) | |
123 | { | |
124 | case MODE_EXLIMIT: | |
125 | case MODE_DISFORWARD: | |
126 | if(ConfigChannel.use_forward) | |
127 | { | |
128 | *ptr++ = (char) i; | |
129 | } | |
130 | ||
131 | break; | |
132 | case MODE_REGONLY: | |
133 | if(rb_dlink_list_length(&service_list)) | |
134 | { | |
135 | *ptr++ = (char) i; | |
136 | } | |
137 | ||
138 | break; | |
139 | default: | |
140 | if(chmode_flags[i] != 0) | |
141 | { | |
142 | *ptr++ = (char) i; | |
143 | } | |
144 | } | |
145 | ||
146 | /* Should we leave orphaned check here? -- dwr */ | |
147 | if(!(chmode_table[i].set_func == chm_nosuch) && !(chmode_table[i].set_func == chm_orphaned)) | |
148 | { | |
149 | *ptr2++ = (char) i; | |
150 | } | |
75818939 | 151 | } |
2392eb24 VY |
152 | |
153 | *ptr++ = '\0'; | |
154 | *ptr2++ = '\0'; | |
73de5d22 VY |
155 | } |
156 | ||
157 | /* | |
158 | * find_umode_slot | |
159 | * | |
160 | * inputs - NONE | |
161 | * outputs - an available cflag bitmask or | |
162 | * 0 if no cflags are available | |
163 | * side effects - NONE | |
164 | */ | |
165 | unsigned int | |
166 | find_cflag_slot(void) | |
167 | { | |
168 | unsigned int all_cflags = 0, my_cflag = 0, i; | |
169 | ||
170 | for (i = 0; i < 256; i++) | |
171 | all_cflags |= chmode_flags[i]; | |
172 | ||
173 | for (my_cflag = 1; my_cflag && (all_cflags & my_cflag); | |
174 | my_cflag <<= 1); | |
175 | ||
176 | return my_cflag; | |
75818939 VY |
177 | } |
178 | ||
aa65834c | 179 | static int |
212380e3 | 180 | get_channel_access(struct Client *source_p, struct membership *msptr) |
181 | { | |
82f8e812 G |
182 | if(!MyClient(source_p) || is_owner(msptr)) |
183 | return CHFL_OWNER; | |
184 | else if(is_chanop(msptr)) | |
212380e3 | 185 | return CHFL_CHANOP; |
82f8e812 G |
186 | else if(is_halfop(msptr)) |
187 | return CHFL_HALFOP; | |
212380e3 | 188 | |
189 | return CHFL_PEON; | |
190 | } | |
191 | ||
192 | /* add_id() | |
193 | * | |
194 | * inputs - client, channel, id to add, type | |
195 | * outputs - 0 on failure, 1 on success | |
196 | * side effects - given id is added to the appropriate list | |
197 | */ | |
198 | int | |
199 | add_id(struct Client *source_p, struct Channel *chptr, const char *banid, | |
af81d5a0 | 200 | rb_dlink_list * list, long mode_type) |
212380e3 | 201 | { |
202 | struct Ban *actualBan; | |
83294285 | 203 | static char who[USERHOST_REPLYLEN]; |
212380e3 | 204 | char *realban = LOCAL_COPY(banid); |
af81d5a0 | 205 | rb_dlink_node *ptr; |
212380e3 | 206 | |
207 | /* dont let local clients overflow the banlist, or set redundant | |
208 | * bans | |
209 | */ | |
210 | if(MyClient(source_p)) | |
211 | { | |
af81d5a0 | 212 | 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 | 213 | { |
214 | sendto_one(source_p, form_str(ERR_BANLISTFULL), | |
215 | me.name, source_p->name, chptr->chname, realban); | |
216 | return 0; | |
217 | } | |
218 | ||
8e69bb4e | 219 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 220 | { |
221 | actualBan = ptr->data; | |
fd488ac1 | 222 | if(mask_match(actualBan->banstr, realban)) |
212380e3 | 223 | return 0; |
224 | } | |
225 | } | |
226 | /* dont let remotes set duplicates */ | |
227 | else | |
228 | { | |
8e69bb4e | 229 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 230 | { |
231 | actualBan = ptr->data; | |
232 | if(!irccmp(actualBan->banstr, realban)) | |
233 | return 0; | |
234 | } | |
235 | } | |
236 | ||
237 | ||
238 | if(IsPerson(source_p)) | |
38e6acdd | 239 | rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); |
212380e3 | 240 | else |
907468c4 | 241 | rb_strlcpy(who, source_p->name, sizeof(who)); |
212380e3 | 242 | |
243 | actualBan = allocate_ban(realban, who); | |
9f6bbe3c | 244 | actualBan->when = rb_current_time(); |
212380e3 | 245 | |
af81d5a0 | 246 | rb_dlinkAdd(actualBan, &actualBan->node, list); |
212380e3 | 247 | |
248 | /* invalidate the can_send() cache */ | |
249 | if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) | |
250 | chptr->bants++; | |
251 | ||
252 | return 1; | |
253 | } | |
254 | ||
255 | /* del_id() | |
256 | * | |
257 | * inputs - channel, id to remove, type | |
258 | * outputs - 0 on failure, 1 on success | |
259 | * side effects - given id is removed from the appropriate list | |
260 | */ | |
261 | int | |
af81d5a0 | 262 | del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type) |
212380e3 | 263 | { |
af81d5a0 | 264 | rb_dlink_node *ptr; |
212380e3 | 265 | struct Ban *banptr; |
266 | ||
267 | if(EmptyString(banid)) | |
268 | return 0; | |
269 | ||
8e69bb4e | 270 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 271 | { |
272 | banptr = ptr->data; | |
273 | ||
274 | if(irccmp(banid, banptr->banstr) == 0) | |
275 | { | |
af81d5a0 | 276 | rb_dlinkDelete(&banptr->node, list); |
212380e3 | 277 | free_ban(banptr); |
278 | ||
279 | /* invalidate the can_send() cache */ | |
280 | if(mode_type == CHFL_BAN || mode_type == CHFL_QUIET || mode_type == CHFL_EXCEPTION) | |
281 | chptr->bants++; | |
282 | ||
283 | return 1; | |
284 | } | |
285 | } | |
286 | ||
287 | return 0; | |
288 | } | |
289 | ||
290 | /* check_string() | |
291 | * | |
292 | * input - string to check | |
293 | * output - pointer to 'fixed' string, or "*" if empty | |
294 | * side effects - any white space found becomes \0 | |
295 | */ | |
296 | static char * | |
297 | check_string(char *s) | |
298 | { | |
299 | char *str = s; | |
300 | static char splat[] = "*"; | |
301 | if(!(s && *s)) | |
302 | return splat; | |
303 | ||
304 | for(; *s; ++s) | |
305 | { | |
306 | if(IsSpace(*s)) | |
307 | { | |
308 | *s = '\0'; | |
309 | break; | |
310 | } | |
311 | } | |
312 | return str; | |
313 | } | |
314 | ||
315 | /* pretty_mask() | |
316 | * | |
317 | * inputs - mask to pretty | |
318 | * outputs - better version of the mask | |
319 | * side effects - mask is chopped to limits, and transformed: | |
320 | * x!y@z => x!y@z | |
321 | * y@z => *!y@z | |
322 | * x!y => x!y@* | |
323 | * x => x!*@* | |
324 | * z.d => *!*@z.d | |
325 | */ | |
326 | static char * | |
327 | pretty_mask(const char *idmask) | |
328 | { | |
329 | static char mask_buf[BUFSIZE]; | |
330 | int old_mask_pos; | |
331 | char *nick, *user, *host; | |
332 | char splat[] = "*"; | |
333 | char *t, *at, *ex; | |
334 | char ne = 0, ue = 0, he = 0; /* save values at nick[NICKLEN], et all */ | |
335 | char *mask; | |
336 | ||
337 | mask = LOCAL_COPY(idmask); | |
338 | mask = check_string(mask); | |
339 | collapse(mask); | |
340 | ||
341 | nick = user = host = splat; | |
342 | ||
343 | if((size_t) BUFSIZE - mask_pos < strlen(mask) + 5) | |
344 | return NULL; | |
345 | ||
346 | old_mask_pos = mask_pos; | |
347 | ||
348 | if (*mask == '$') | |
349 | { | |
38e6acdd | 350 | mask_pos += rb_sprintf(mask_buf + mask_pos, "%s", mask) + 1; |
212380e3 | 351 | t = mask_buf + old_mask_pos + 1; |
352 | if (*t == '!') | |
353 | *t = '~'; | |
354 | if (*t == '~') | |
355 | t++; | |
356 | *t = ToLower(*t); | |
357 | return mask_buf + old_mask_pos; | |
358 | } | |
359 | ||
360 | at = ex = NULL; | |
361 | if((t = strchr(mask, '@')) != NULL) | |
362 | { | |
363 | at = t; | |
364 | *t++ = '\0'; | |
365 | if(*t != '\0') | |
366 | host = t; | |
367 | ||
368 | if((t = strchr(mask, '!')) != NULL) | |
369 | { | |
370 | ex = t; | |
371 | *t++ = '\0'; | |
372 | if(*t != '\0') | |
373 | user = t; | |
374 | if(*mask != '\0') | |
375 | nick = mask; | |
376 | } | |
377 | else | |
378 | { | |
379 | if(*mask != '\0') | |
380 | user = mask; | |
381 | } | |
382 | } | |
383 | else if((t = strchr(mask, '!')) != NULL) | |
384 | { | |
385 | ex = t; | |
386 | *t++ = '\0'; | |
387 | if(*mask != '\0') | |
388 | nick = mask; | |
389 | if(*t != '\0') | |
390 | user = t; | |
391 | } | |
1229514e | 392 | else if(strchr(mask, '.') != NULL || strchr(mask, ':') != NULL || strchr(mask, '/') != NULL) |
212380e3 | 393 | { |
394 | if(*mask != '\0') | |
395 | host = mask; | |
396 | } | |
397 | else | |
398 | { | |
399 | if(*mask != '\0') | |
400 | nick = mask; | |
401 | } | |
402 | ||
403 | /* truncate values to max lengths */ | |
404 | if(strlen(nick) > NICKLEN - 1) | |
405 | { | |
406 | ne = nick[NICKLEN - 1]; | |
407 | nick[NICKLEN - 1] = '\0'; | |
408 | } | |
409 | if(strlen(user) > USERLEN) | |
410 | { | |
411 | ue = user[USERLEN]; | |
412 | user[USERLEN] = '\0'; | |
413 | } | |
414 | if(strlen(host) > HOSTLEN) | |
415 | { | |
416 | he = host[HOSTLEN]; | |
417 | host[HOSTLEN] = '\0'; | |
418 | } | |
419 | ||
38e6acdd | 420 | mask_pos += rb_sprintf(mask_buf + mask_pos, "%s!%s@%s", nick, user, host) + 1; |
212380e3 | 421 | |
422 | /* restore mask, since we may need to use it again later */ | |
423 | if(at) | |
424 | *at = '@'; | |
425 | if(ex) | |
426 | *ex = '!'; | |
427 | if(ne) | |
428 | nick[NICKLEN - 1] = ne; | |
429 | if(ue) | |
430 | user[USERLEN] = ue; | |
431 | if(he) | |
432 | host[HOSTLEN] = he; | |
433 | ||
434 | return mask_buf + old_mask_pos; | |
435 | } | |
436 | ||
437 | /* fix_key() | |
438 | * | |
439 | * input - key to fix | |
440 | * output - the same key, fixed | |
441 | * side effects - anything below ascii 13 is discarded, ':' discarded, | |
442 | * high ascii is dropped to lower half of ascii table | |
443 | */ | |
444 | static char * | |
445 | fix_key(char *arg) | |
446 | { | |
447 | u_char *s, *t, c; | |
448 | ||
449 | for(s = t = (u_char *) arg; (c = *s); s++) | |
450 | { | |
451 | c &= 0x7f; | |
452 | if(c != ':' && c != ',' && c > ' ') | |
453 | *t++ = c; | |
454 | } | |
455 | ||
456 | *t = '\0'; | |
457 | return arg; | |
458 | } | |
459 | ||
460 | /* fix_key_remote() | |
461 | * | |
462 | * input - key to fix | |
463 | * ouput - the same key, fixed | |
464 | * side effects - high ascii dropped to lower half of table, | |
465 | * CR/LF/':' are dropped | |
466 | */ | |
467 | static char * | |
468 | fix_key_remote(char *arg) | |
469 | { | |
470 | u_char *s, *t, c; | |
471 | ||
472 | for(s = t = (u_char *) arg; (c = *s); s++) | |
473 | { | |
474 | c &= 0x7f; | |
475 | if((c != 0x0a) && (c != ':') && (c != ',') && (c != 0x0d) && (c != ' ')) | |
476 | *t++ = c; | |
477 | } | |
478 | ||
479 | *t = '\0'; | |
480 | return arg; | |
481 | } | |
482 | ||
483 | /* chm_*() | |
484 | * | |
485 | * The handlers for each specific mode. | |
486 | */ | |
487 | void | |
488 | chm_nosuch(struct Client *source_p, struct Channel *chptr, | |
489 | int alevel, int parc, int *parn, | |
490 | const char **parv, int *errors, int dir, char c, long mode_type) | |
491 | { | |
492 | if(*errors & SM_ERR_UNKNOWN) | |
493 | return; | |
494 | *errors |= SM_ERR_UNKNOWN; | |
495 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
496 | } | |
497 | ||
498 | void | |
499 | chm_simple(struct Client *source_p, struct Channel *chptr, | |
500 | int alevel, int parc, int *parn, | |
501 | const char **parv, int *errors, int dir, char c, long mode_type) | |
502 | { | |
eccd1c58 JH |
503 | |
504 | int override = 0; | |
d3b90aaa G |
505 | struct Metadata *md; |
506 | struct DictionaryIter iter; | |
eccd1c58 | 507 | |
82f8e812 | 508 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 509 | { |
eccd1c58 JH |
510 | if (IsOverride(source_p)) |
511 | override = 1; | |
512 | else | |
513 | { | |
514 | if(!(*errors & SM_ERR_NOOPS)) | |
515 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
516 | me.name, source_p->name, chptr->chname); | |
517 | *errors |= SM_ERR_NOOPS; | |
518 | return; | |
519 | } | |
212380e3 | 520 | } |
521 | ||
c08f4515 | 522 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
212380e3 | 523 | return; |
524 | ||
525 | /* setting + */ | |
526 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
527 | { | |
528 | /* if +f is disabled, ignore an attempt to set +QF locally */ | |
529 | if(!ConfigChannel.use_forward && MyClient(source_p) && | |
530 | (c == 'Q' || c == 'F')) | |
531 | return; | |
532 | ||
533 | chptr->mode.mode |= mode_type; | |
534 | ||
535 | mode_changes[mode_count].letter = c; | |
536 | mode_changes[mode_count].dir = MODE_ADD; | |
537 | mode_changes[mode_count].caps = 0; | |
538 | mode_changes[mode_count].nocaps = 0; | |
539 | mode_changes[mode_count].id = NULL; | |
540 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
eccd1c58 | 541 | mode_changes[mode_count].override = override; |
058aa02c VY |
542 | mode_changes[mode_count++].arg = NULL; |
543 | } | |
544 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
545 | { | |
8e3b2b85 | 546 | /* cleanup metadata when the related mode is removed */ |
d3b90aaa G |
547 | if(c == 'J') |
548 | { | |
549 | DICTIONARY_FOREACH(md, &iter, chptr->metadata) | |
550 | { | |
bc4764ae | 551 | if(!strcmp(md->value, "KICKNOREJOIN")) |
d3b90aaa G |
552 | channel_metadata_delete(chptr, md->name, 0); |
553 | } | |
554 | } | |
8e3b2b85 | 555 | if(c == 'K') |
67cecc2b | 556 | channel_metadata_delete(chptr, "NOREPEAT", 0); |
d3b90aaa | 557 | |
058aa02c VY |
558 | chptr->mode.mode &= ~mode_type; |
559 | ||
560 | mode_changes[mode_count].letter = c; | |
561 | mode_changes[mode_count].dir = MODE_DEL; | |
562 | mode_changes[mode_count].caps = 0; | |
563 | mode_changes[mode_count].nocaps = 0; | |
564 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
565 | mode_changes[mode_count].id = NULL; | |
eccd1c58 | 566 | mode_changes[mode_count].override = override; |
058aa02c VY |
567 | mode_changes[mode_count++].arg = NULL; |
568 | } | |
569 | } | |
570 | ||
571 | void | |
572 | chm_orphaned(struct Client *source_p, struct Channel *chptr, | |
573 | int alevel, int parc, int *parn, | |
574 | const char **parv, int *errors, int dir, char c, long mode_type) | |
575 | { | |
576 | if(MyClient(source_p)) | |
577 | return; | |
578 | ||
579 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
580 | { | |
581 | chptr->mode.mode |= mode_type; | |
582 | ||
583 | mode_changes[mode_count].letter = c; | |
584 | mode_changes[mode_count].dir = MODE_ADD; | |
585 | mode_changes[mode_count].caps = 0; | |
586 | mode_changes[mode_count].nocaps = 0; | |
587 | mode_changes[mode_count].id = NULL; | |
588 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
212380e3 | 589 | mode_changes[mode_count++].arg = NULL; |
590 | } | |
591 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
592 | { | |
593 | chptr->mode.mode &= ~mode_type; | |
594 | ||
595 | mode_changes[mode_count].letter = c; | |
596 | mode_changes[mode_count].dir = MODE_DEL; | |
597 | mode_changes[mode_count].caps = 0; | |
598 | mode_changes[mode_count].nocaps = 0; | |
599 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
600 | mode_changes[mode_count].id = NULL; | |
601 | mode_changes[mode_count++].arg = NULL; | |
602 | } | |
603 | } | |
604 | ||
1cdd8fdf JH |
605 | void |
606 | chm_hidden(struct Client *source_p, struct Channel *chptr, | |
607 | int alevel, int parc, int *parn, | |
608 | const char **parv, int *errors, int dir, char c, long mode_type) | |
609 | { | |
610 | if(!IsOper(source_p) && !IsServer(source_p)) | |
611 | { | |
612 | if(!(*errors & SM_ERR_NOPRIVS)) | |
613 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
614 | *errors |= SM_ERR_NOPRIVS; | |
615 | return; | |
616 | } | |
617 | if(MyClient(source_p) && !IsOperAdmin(source_p)) | |
618 | { | |
619 | if(!(*errors & SM_ERR_NOPRIVS)) | |
620 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, | |
621 | source_p->name, "cmodes"); | |
622 | *errors |= SM_ERR_NOPRIVS; | |
623 | return; | |
624 | } | |
625 | ||
626 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) | |
627 | return; | |
628 | ||
629 | /* setting + */ | |
630 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
631 | { | |
632 | chptr->mode.mode |= mode_type; | |
633 | ||
634 | mode_changes[mode_count].letter = c; | |
635 | mode_changes[mode_count].dir = MODE_ADD; | |
636 | mode_changes[mode_count].caps = 0; | |
637 | mode_changes[mode_count].nocaps = 0; | |
638 | mode_changes[mode_count].id = NULL; | |
639 | mode_changes[mode_count].mems = ONLY_OPERS; | |
640 | mode_changes[mode_count].override = 0; | |
641 | mode_changes[mode_count++].arg = NULL; | |
642 | } | |
643 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
644 | { | |
645 | chptr->mode.mode &= ~mode_type; | |
646 | ||
647 | mode_changes[mode_count].letter = c; | |
648 | mode_changes[mode_count].dir = MODE_DEL; | |
649 | mode_changes[mode_count].caps = 0; | |
650 | mode_changes[mode_count].nocaps = 0; | |
651 | mode_changes[mode_count].mems = ONLY_OPERS; | |
652 | mode_changes[mode_count].id = NULL; | |
653 | mode_changes[mode_count].override = 0; | |
654 | mode_changes[mode_count++].arg = NULL; | |
655 | } | |
656 | } | |
657 | ||
212380e3 | 658 | void |
659 | chm_staff(struct Client *source_p, struct Channel *chptr, | |
660 | int alevel, int parc, int *parn, | |
661 | const char **parv, int *errors, int dir, char c, long mode_type) | |
662 | { | |
663 | if(!IsOper(source_p) && !IsServer(source_p)) | |
664 | { | |
665 | if(!(*errors & SM_ERR_NOPRIVS)) | |
666 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
667 | *errors |= SM_ERR_NOPRIVS; | |
668 | return; | |
669 | } | |
1ef5b430 JT |
670 | if(MyClient(source_p) && !IsOperResv(source_p)) |
671 | { | |
672 | if(!(*errors & SM_ERR_NOPRIVS)) | |
673 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, | |
674 | source_p->name, "resv"); | |
675 | *errors |= SM_ERR_NOPRIVS; | |
676 | return; | |
677 | } | |
212380e3 | 678 | |
c08f4515 JT |
679 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
680 | return; | |
681 | ||
212380e3 | 682 | /* setting + */ |
683 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
684 | { | |
685 | chptr->mode.mode |= mode_type; | |
686 | ||
687 | mode_changes[mode_count].letter = c; | |
688 | mode_changes[mode_count].dir = MODE_ADD; | |
689 | mode_changes[mode_count].caps = 0; | |
690 | mode_changes[mode_count].nocaps = 0; | |
691 | mode_changes[mode_count].id = NULL; | |
692 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
4ed822ed | 693 | mode_changes[mode_count].override = 0; |
212380e3 | 694 | mode_changes[mode_count++].arg = NULL; |
695 | } | |
696 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
697 | { | |
698 | chptr->mode.mode &= ~mode_type; | |
699 | ||
700 | mode_changes[mode_count].letter = c; | |
701 | mode_changes[mode_count].dir = MODE_DEL; | |
702 | mode_changes[mode_count].caps = 0; | |
703 | mode_changes[mode_count].nocaps = 0; | |
704 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
4ed822ed | 705 | mode_changes[mode_count].override = 0; |
212380e3 | 706 | mode_changes[mode_count].id = NULL; |
707 | mode_changes[mode_count++].arg = NULL; | |
708 | } | |
709 | } | |
710 | ||
711 | void | |
712 | chm_ban(struct Client *source_p, struct Channel *chptr, | |
713 | int alevel, int parc, int *parn, | |
714 | const char **parv, int *errors, int dir, char c, long mode_type) | |
715 | { | |
716 | const char *mask; | |
717 | const char *raw_mask; | |
af81d5a0 WP |
718 | rb_dlink_list *list; |
719 | rb_dlink_node *ptr; | |
212380e3 | 720 | struct Ban *banptr; |
721 | int errorval; | |
722 | int rpl_list; | |
723 | int rpl_endlist; | |
724 | int caps; | |
725 | int mems; | |
4ed822ed | 726 | int override = 0; |
212380e3 | 727 | |
728 | switch (mode_type) | |
729 | { | |
730 | case CHFL_BAN: | |
731 | list = &chptr->banlist; | |
732 | errorval = SM_ERR_RPL_B; | |
733 | rpl_list = RPL_BANLIST; | |
734 | rpl_endlist = RPL_ENDOFBANLIST; | |
735 | mems = ALL_MEMBERS; | |
736 | caps = 0; | |
737 | break; | |
738 | ||
739 | case CHFL_EXCEPTION: | |
740 | /* if +e is disabled, allow all but +e locally */ | |
741 | if(!ConfigChannel.use_except && MyClient(source_p) && | |
742 | ((dir == MODE_ADD) && (parc > *parn))) | |
743 | return; | |
744 | ||
745 | list = &chptr->exceptlist; | |
746 | errorval = SM_ERR_RPL_E; | |
747 | rpl_list = RPL_EXCEPTLIST; | |
748 | rpl_endlist = RPL_ENDOFEXCEPTLIST; | |
749 | caps = CAP_EX; | |
750 | ||
751 | if(ConfigChannel.use_except || (dir == MODE_DEL)) | |
752 | mems = ONLY_CHANOPS; | |
753 | else | |
754 | mems = ONLY_SERVERS; | |
755 | break; | |
756 | ||
757 | case CHFL_INVEX: | |
758 | /* if +I is disabled, allow all but +I locally */ | |
759 | if(!ConfigChannel.use_invex && MyClient(source_p) && | |
760 | (dir == MODE_ADD) && (parc > *parn)) | |
761 | return; | |
762 | ||
763 | list = &chptr->invexlist; | |
764 | errorval = SM_ERR_RPL_I; | |
765 | rpl_list = RPL_INVITELIST; | |
766 | rpl_endlist = RPL_ENDOFINVITELIST; | |
767 | caps = CAP_IE; | |
768 | ||
769 | if(ConfigChannel.use_invex || (dir == MODE_DEL)) | |
770 | mems = ONLY_CHANOPS; | |
771 | else | |
772 | mems = ONLY_SERVERS; | |
773 | break; | |
774 | ||
775 | case CHFL_QUIET: | |
776 | list = &chptr->quietlist; | |
777 | errorval = SM_ERR_RPL_Q; | |
778 | rpl_list = RPL_BANLIST; | |
779 | rpl_endlist = RPL_ENDOFBANLIST; | |
780 | mems = ALL_MEMBERS; | |
781 | caps = 0; | |
782 | break; | |
783 | ||
784 | default: | |
785 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!"); | |
786 | return; | |
787 | break; | |
788 | } | |
789 | ||
790 | if(dir == 0 || parc <= *parn) | |
791 | { | |
792 | if((*errors & errorval) != 0) | |
793 | return; | |
794 | *errors |= errorval; | |
795 | ||
796 | /* non-ops cant see +eI lists.. */ | |
82f8e812 | 797 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP && mode_type != CHFL_BAN && |
212380e3 | 798 | mode_type != CHFL_QUIET) |
799 | { | |
4ed822ed | 800 | if(IsOverride(source_p)) |
cb097b88 | 801 | { |
34d8ef4d | 802 | sendto_wallops_flags(UMODE_WALLOP, &me, |
cb097b88 | 803 | "%s is overriding modes on %s: (%s list)", |
34d8ef4d JH |
804 | get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); |
805 | sendto_server(NULL, chptr, NOCAPS, NOCAPS, | |
806 | ":%s WALLOPS :%s is overriding modes on %s: (%s list)", | |
807 | use_id(source_p), get_oper_name(source_p), chptr->chname, mode_type == CHFL_INVEX ? "invex" : "exempt"); | |
cb097b88 | 808 | } |
4ed822ed JH |
809 | else |
810 | { | |
811 | ||
812 | if(!(*errors & SM_ERR_NOOPS)) | |
813 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
814 | me.name, source_p->name, chptr->chname); | |
815 | *errors |= SM_ERR_NOOPS; | |
816 | return; | |
817 | } | |
212380e3 | 818 | } |
819 | ||
8e69bb4e | 820 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 821 | { |
822 | banptr = ptr->data; | |
823 | sendto_one(source_p, form_str(rpl_list), | |
824 | me.name, source_p->name, chptr->chname, | |
825 | banptr->banstr, banptr->who, banptr->when); | |
826 | } | |
11781253 | 827 | if (mode_type == CHFL_QUIET) |
828 | sendto_one(source_p, ":%s %d %s %s :End of Channel Quiet List", me.name, rpl_endlist, source_p->name, chptr->chname); | |
829 | else | |
830 | sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname); | |
212380e3 | 831 | return; |
832 | } | |
833 | ||
82f8e812 | 834 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 835 | { |
4ed822ed JH |
836 | if(IsOverride(source_p)) |
837 | override = 1; | |
838 | else | |
839 | { | |
840 | ||
841 | if(!(*errors & SM_ERR_NOOPS)) | |
842 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
843 | me.name, source_p->name, chptr->chname); | |
844 | *errors |= SM_ERR_NOOPS; | |
845 | return; | |
846 | } | |
212380e3 | 847 | } |
848 | ||
849 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
850 | return; | |
851 | ||
852 | raw_mask = parv[(*parn)]; | |
853 | (*parn)++; | |
854 | ||
855 | /* empty ban, or starts with ':' which messes up s2s, ignore it */ | |
856 | if(EmptyString(raw_mask) || *raw_mask == ':') | |
857 | return; | |
858 | ||
859 | if(!MyClient(source_p)) | |
860 | { | |
861 | if(strchr(raw_mask, ' ')) | |
862 | return; | |
863 | ||
864 | mask = raw_mask; | |
865 | } | |
866 | else | |
867 | mask = pretty_mask(raw_mask); | |
868 | ||
83294285 | 869 | /* we'd have problems parsing this, hyb6 does it too |
870 | * also make sure it will always fit on a line with channel | |
871 | * name etc. | |
872 | */ | |
873 | if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) | |
212380e3 | 874 | return; |
875 | ||
876 | /* if we're adding a NEW id */ | |
877 | if(dir == MODE_ADD) | |
878 | { | |
879 | if (*mask == '$' && MyClient(source_p)) | |
880 | { | |
881 | if (!valid_extban(mask, source_p, chptr, mode_type)) | |
882 | /* XXX perhaps return an error message here */ | |
883 | return; | |
884 | } | |
885 | ||
886 | /* dont allow local clients to overflow the banlist, dont | |
887 | * let remote servers set duplicate bans | |
888 | */ | |
889 | if(!add_id(source_p, chptr, mask, list, mode_type)) | |
890 | return; | |
891 | ||
892 | mode_changes[mode_count].letter = c; | |
893 | mode_changes[mode_count].dir = MODE_ADD; | |
894 | mode_changes[mode_count].caps = caps; | |
895 | mode_changes[mode_count].nocaps = 0; | |
896 | mode_changes[mode_count].mems = mems; | |
897 | mode_changes[mode_count].id = NULL; | |
4ed822ed | 898 | mode_changes[mode_count].override = override; |
212380e3 | 899 | mode_changes[mode_count++].arg = mask; |
900 | } | |
901 | else if(dir == MODE_DEL) | |
902 | { | |
903 | if(del_id(chptr, mask, list, mode_type) == 0) | |
904 | { | |
905 | /* mask isn't a valid ban, check raw_mask */ | |
906 | if(del_id(chptr, raw_mask, list, mode_type)) | |
907 | mask = raw_mask; | |
908 | } | |
909 | ||
910 | mode_changes[mode_count].letter = c; | |
911 | mode_changes[mode_count].dir = MODE_DEL; | |
912 | mode_changes[mode_count].caps = caps; | |
913 | mode_changes[mode_count].nocaps = 0; | |
914 | mode_changes[mode_count].mems = mems; | |
915 | mode_changes[mode_count].id = NULL; | |
4ed822ed | 916 | mode_changes[mode_count].override = override; |
212380e3 | 917 | mode_changes[mode_count++].arg = mask; |
918 | } | |
919 | } | |
920 | ||
82f8e812 G |
921 | void |
922 | chm_owner(struct Client *source_p, struct Channel *chptr, | |
923 | int alevel, int parc, int *parn, | |
924 | const char **parv, int *errors, int dir, char c, long mode_type) | |
925 | { | |
926 | struct membership *mstptr; | |
927 | const char *ownernick; | |
928 | struct Client *targ_p; | |
4ed822ed | 929 | int override = 0; |
82f8e812 G |
930 | |
931 | if(!ConfigChannel.use_owner) | |
932 | { | |
933 | if(*errors & SM_ERR_UNKNOWN) | |
934 | return; | |
935 | *errors |= SM_ERR_UNKNOWN; | |
936 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
937 | return; | |
938 | } | |
939 | ||
940 | if(alevel != CHFL_OWNER) | |
941 | { | |
4ed822ed JH |
942 | if(IsOverride(source_p)) |
943 | override = 1; | |
944 | else | |
945 | { | |
946 | ||
947 | if(!(*errors & SM_ERR_NOOPS)) | |
c809010b | 948 | sendto_one(source_p, ":%s 482 %s %s :You're not a channel administrator", me.name, source_p->name, chptr->chname); |
4ed822ed JH |
949 | *errors |= SM_ERR_NOOPS; |
950 | return; | |
951 | } | |
82f8e812 G |
952 | } |
953 | ||
954 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
955 | return; | |
956 | ||
957 | ownernick = parv[(*parn)]; | |
958 | (*parn)++; | |
959 | ||
960 | /* empty nick */ | |
961 | if(EmptyString(ownernick)) | |
962 | { | |
963 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
964 | return; | |
965 | } | |
966 | ||
967 | if((targ_p = find_chasing(source_p, ownernick, NULL)) == NULL) | |
968 | { | |
969 | return; | |
970 | } | |
971 | ||
972 | mstptr = find_channel_membership(chptr, targ_p); | |
973 | ||
974 | if(mstptr == NULL) | |
975 | { | |
976 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
977 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
978 | form_str(ERR_USERNOTINCHANNEL), ownernick, chptr->chname); | |
979 | *errors |= SM_ERR_NOTONCHANNEL; | |
980 | return; | |
981 | } | |
982 | ||
983 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
984 | return; | |
985 | ||
986 | if(dir == MODE_ADD) | |
987 | { | |
988 | if(targ_p == source_p) | |
4ed822ed JH |
989 | { |
990 | no_override_deop = 1; | |
cb097b88 JH |
991 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
992 | * legitimate from a remote override oper. | |
4ed822ed JH |
993 | if(!override) |
994 | return; | |
cb097b88 | 995 | */ |
4ed822ed | 996 | } |
82f8e812 G |
997 | |
998 | mode_changes[mode_count].letter = c; | |
999 | mode_changes[mode_count].dir = MODE_ADD; | |
1000 | mode_changes[mode_count].caps = 0; | |
1001 | mode_changes[mode_count].nocaps = 0; | |
1002 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1003 | mode_changes[mode_count].id = targ_p->id; | |
1004 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1005 | mode_changes[mode_count].override = override; |
82f8e812 G |
1006 | mode_changes[mode_count++].client = targ_p; |
1007 | ||
1008 | mstptr->flags |= CHFL_OWNER; | |
1009 | } | |
1010 | else | |
1011 | { | |
1012 | if(MyClient(source_p) && IsService(targ_p)) | |
1013 | { | |
1014 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1015 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1016 | return; | |
1017 | } | |
1018 | ||
1019 | mode_changes[mode_count].letter = c; | |
1020 | mode_changes[mode_count].dir = MODE_DEL; | |
1021 | mode_changes[mode_count].caps = 0; | |
1022 | mode_changes[mode_count].nocaps = 0; | |
1023 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1024 | mode_changes[mode_count].id = targ_p->id; | |
1025 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1026 | mode_changes[mode_count].override = override; |
82f8e812 G |
1027 | mode_changes[mode_count++].client = targ_p; |
1028 | ||
1029 | mstptr->flags &= ~CHFL_OWNER; | |
1030 | } | |
1031 | } | |
1032 | ||
212380e3 | 1033 | void |
1034 | chm_op(struct Client *source_p, struct Channel *chptr, | |
1035 | int alevel, int parc, int *parn, | |
1036 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1037 | { | |
1038 | struct membership *mstptr; | |
1039 | const char *opnick; | |
1040 | struct Client *targ_p; | |
4ed822ed | 1041 | int override = 0; |
212380e3 | 1042 | |
82f8e812 | 1043 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER) |
212380e3 | 1044 | { |
4ed822ed JH |
1045 | if(IsOverride(source_p)) |
1046 | override = 1; | |
1047 | else | |
1048 | { | |
1049 | ||
1050 | if(!(*errors & SM_ERR_NOOPS)) | |
1051 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1052 | me.name, source_p->name, chptr->chname); | |
1053 | *errors |= SM_ERR_NOOPS; | |
1054 | return; | |
1055 | } | |
212380e3 | 1056 | } |
1057 | ||
1058 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
1059 | return; | |
1060 | ||
1061 | opnick = parv[(*parn)]; | |
1062 | (*parn)++; | |
1063 | ||
1064 | /* empty nick */ | |
1065 | if(EmptyString(opnick)) | |
1066 | { | |
1067 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1068 | return; | |
1069 | } | |
1070 | ||
1071 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
1072 | { | |
1073 | return; | |
1074 | } | |
1075 | ||
1076 | mstptr = find_channel_membership(chptr, targ_p); | |
1077 | ||
1078 | if(mstptr == NULL) | |
1079 | { | |
1080 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1081 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1082 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
1083 | *errors |= SM_ERR_NOTONCHANNEL; | |
1084 | return; | |
1085 | } | |
1086 | ||
1087 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1088 | return; | |
1089 | ||
1090 | if(dir == MODE_ADD) | |
1091 | { | |
1092 | if(targ_p == source_p) | |
4ed822ed JH |
1093 | { |
1094 | no_override_deop = 1; | |
cb097b88 JH |
1095 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
1096 | * legitimate from a remote override oper. | |
4ed822ed JH |
1097 | if(!override) |
1098 | return; | |
cb097b88 | 1099 | */ |
4ed822ed | 1100 | } |
212380e3 | 1101 | |
1102 | mode_changes[mode_count].letter = c; | |
1103 | mode_changes[mode_count].dir = MODE_ADD; | |
1104 | mode_changes[mode_count].caps = 0; | |
1105 | mode_changes[mode_count].nocaps = 0; | |
1106 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1107 | mode_changes[mode_count].id = targ_p->id; | |
1108 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1109 | mode_changes[mode_count].override = override; |
212380e3 | 1110 | mode_changes[mode_count++].client = targ_p; |
1111 | ||
1112 | mstptr->flags |= CHFL_CHANOP; | |
212380e3 | 1113 | } |
1114 | else | |
1115 | { | |
1116 | if(MyClient(source_p) && IsService(targ_p)) | |
1117 | { | |
1118 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1119 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1120 | return; | |
1121 | } | |
1122 | ||
1123 | mode_changes[mode_count].letter = c; | |
1124 | mode_changes[mode_count].dir = MODE_DEL; | |
1125 | mode_changes[mode_count].caps = 0; | |
1126 | mode_changes[mode_count].nocaps = 0; | |
1127 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1128 | mode_changes[mode_count].id = targ_p->id; | |
1129 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1130 | mode_changes[mode_count].override = override; |
212380e3 | 1131 | mode_changes[mode_count++].client = targ_p; |
1132 | ||
1133 | mstptr->flags &= ~CHFL_CHANOP; | |
1134 | } | |
1135 | } | |
1136 | ||
82f8e812 G |
1137 | void |
1138 | chm_halfop(struct Client *source_p, struct Channel *chptr, | |
1139 | int alevel, int parc, int *parn, | |
1140 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1141 | { | |
1142 | struct membership *mstptr; | |
1143 | const char *halfopnick; | |
1144 | struct Client *targ_p; | |
4ed822ed | 1145 | int override = 0; |
82f8e812 G |
1146 | |
1147 | if(!ConfigChannel.use_halfop) | |
1148 | { | |
1149 | if(*errors & SM_ERR_UNKNOWN) | |
1150 | return; | |
1151 | *errors |= SM_ERR_UNKNOWN; | |
1152 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
1153 | return; | |
1154 | } | |
1155 | ||
1a9821cd | 1156 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER) |
82f8e812 | 1157 | { |
4ed822ed JH |
1158 | if(IsOverride(source_p)) |
1159 | override = 1; | |
1160 | else | |
1161 | { | |
1162 | ||
1163 | if(!(*errors & SM_ERR_NOOPS)) | |
1164 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1165 | me.name, source_p->name, chptr->chname); | |
1166 | *errors |= SM_ERR_NOOPS; | |
1167 | return; | |
1168 | } | |
82f8e812 G |
1169 | } |
1170 | ||
1171 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
1172 | return; | |
1173 | ||
1174 | halfopnick = parv[(*parn)]; | |
1175 | (*parn)++; | |
1176 | ||
1177 | /* empty nick */ | |
1178 | if(EmptyString(halfopnick)) | |
1179 | { | |
1180 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1181 | return; | |
1182 | } | |
1183 | ||
1184 | if((targ_p = find_chasing(source_p, halfopnick, NULL)) == NULL) | |
1185 | { | |
1186 | return; | |
1187 | } | |
1188 | ||
1189 | mstptr = find_channel_membership(chptr, targ_p); | |
1190 | ||
1191 | if(mstptr == NULL) | |
1192 | { | |
1193 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1194 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1195 | form_str(ERR_USERNOTINCHANNEL), halfopnick, chptr->chname); | |
1196 | *errors |= SM_ERR_NOTONCHANNEL; | |
1197 | return; | |
1198 | } | |
1199 | ||
1200 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1201 | return; | |
1202 | ||
1203 | if(dir == MODE_ADD) | |
1204 | { | |
1205 | if(targ_p == source_p) | |
4ed822ed JH |
1206 | { |
1207 | no_override_deop = 1; | |
cb097b88 JH |
1208 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
1209 | * legitimate from a remote override oper. | |
4ed822ed JH |
1210 | if(!override) |
1211 | return; | |
cb097b88 | 1212 | */ |
4ed822ed | 1213 | } |
82f8e812 G |
1214 | |
1215 | mode_changes[mode_count].letter = c; | |
1216 | mode_changes[mode_count].dir = MODE_ADD; | |
1217 | mode_changes[mode_count].caps = 0; | |
1218 | mode_changes[mode_count].nocaps = 0; | |
1219 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1220 | mode_changes[mode_count].id = targ_p->id; | |
1221 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1222 | mode_changes[mode_count].override = override; |
82f8e812 G |
1223 | mode_changes[mode_count++].client = targ_p; |
1224 | ||
1225 | mstptr->flags |= CHFL_HALFOP; | |
1226 | } | |
1227 | else | |
1228 | { | |
1229 | if(MyClient(source_p) && IsService(targ_p)) | |
1230 | { | |
1231 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1232 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1233 | return; | |
1234 | } | |
1235 | ||
1236 | mode_changes[mode_count].letter = c; | |
1237 | mode_changes[mode_count].dir = MODE_DEL; | |
1238 | mode_changes[mode_count].caps = 0; | |
1239 | mode_changes[mode_count].nocaps = 0; | |
1240 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1241 | mode_changes[mode_count].id = targ_p->id; | |
1242 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1243 | mode_changes[mode_count].override = override; |
82f8e812 G |
1244 | mode_changes[mode_count++].client = targ_p; |
1245 | ||
1246 | mstptr->flags &= ~CHFL_HALFOP; | |
1247 | } | |
1248 | } | |
1249 | ||
212380e3 | 1250 | void |
1251 | chm_voice(struct Client *source_p, struct Channel *chptr, | |
1252 | int alevel, int parc, int *parn, | |
1253 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1254 | { | |
1255 | struct membership *mstptr; | |
1256 | const char *opnick; | |
1257 | struct Client *targ_p; | |
4ed822ed | 1258 | int override = 0; |
212380e3 | 1259 | |
82f8e812 | 1260 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1261 | { |
4ed822ed JH |
1262 | if(IsOverride(source_p)) |
1263 | override = 1; | |
1264 | else | |
1265 | { | |
1266 | ||
1267 | if(!(*errors & SM_ERR_NOOPS)) | |
1268 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1269 | me.name, source_p->name, chptr->chname); | |
1270 | *errors |= SM_ERR_NOOPS; | |
1271 | return; | |
1272 | } | |
212380e3 | 1273 | } |
1274 | ||
1275 | if((dir == MODE_QUERY) || parc <= *parn) | |
1276 | return; | |
1277 | ||
1278 | opnick = parv[(*parn)]; | |
1279 | (*parn)++; | |
1280 | ||
1281 | /* empty nick */ | |
1282 | if(EmptyString(opnick)) | |
1283 | { | |
1284 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1285 | return; | |
1286 | } | |
1287 | ||
1288 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
1289 | { | |
1290 | return; | |
1291 | } | |
1292 | ||
1293 | mstptr = find_channel_membership(chptr, targ_p); | |
1294 | ||
1295 | if(mstptr == NULL) | |
1296 | { | |
1297 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1298 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1299 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
1300 | *errors |= SM_ERR_NOTONCHANNEL; | |
1301 | return; | |
1302 | } | |
1303 | ||
1304 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1305 | return; | |
1306 | ||
1307 | if(dir == MODE_ADD) | |
1308 | { | |
1309 | mode_changes[mode_count].letter = c; | |
1310 | mode_changes[mode_count].dir = MODE_ADD; | |
1311 | mode_changes[mode_count].caps = 0; | |
1312 | mode_changes[mode_count].nocaps = 0; | |
1313 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1314 | mode_changes[mode_count].id = targ_p->id; | |
1315 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1316 | mode_changes[mode_count].override = override; |
212380e3 | 1317 | mode_changes[mode_count++].client = targ_p; |
1318 | ||
1319 | mstptr->flags |= CHFL_VOICE; | |
1320 | } | |
1321 | else | |
1322 | { | |
1323 | mode_changes[mode_count].letter = 'v'; | |
1324 | mode_changes[mode_count].dir = MODE_DEL; | |
1325 | mode_changes[mode_count].caps = 0; | |
1326 | mode_changes[mode_count].nocaps = 0; | |
1327 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1328 | mode_changes[mode_count].id = targ_p->id; | |
1329 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1330 | mode_changes[mode_count].override = override; |
212380e3 | 1331 | mode_changes[mode_count++].client = targ_p; |
1332 | ||
1333 | mstptr->flags &= ~CHFL_VOICE; | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | void | |
1338 | chm_limit(struct Client *source_p, struct Channel *chptr, | |
1339 | int alevel, int parc, int *parn, | |
1340 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1341 | { | |
1342 | const char *lstr; | |
1343 | static char limitstr[30]; | |
1344 | int limit; | |
b869e117 | 1345 | int override = 0; |
212380e3 | 1346 | |
82f8e812 | 1347 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1348 | { |
b869e117 JH |
1349 | if(IsOverride(source_p)) |
1350 | override = 1; | |
1351 | else | |
1352 | { | |
1353 | if(!(*errors & SM_ERR_NOOPS)) | |
1354 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1355 | me.name, source_p->name, chptr->chname); | |
1356 | *errors |= SM_ERR_NOOPS; | |
1357 | return; | |
1358 | } | |
212380e3 | 1359 | } |
1360 | ||
1361 | if(dir == MODE_QUERY) | |
1362 | return; | |
1363 | ||
c08f4515 JT |
1364 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1365 | return; | |
1366 | ||
212380e3 | 1367 | if((dir == MODE_ADD) && parc > *parn) |
1368 | { | |
1369 | lstr = parv[(*parn)]; | |
1370 | (*parn)++; | |
1371 | ||
1372 | if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0) | |
1373 | return; | |
1374 | ||
38e6acdd | 1375 | rb_sprintf(limitstr, "%d", limit); |
212380e3 | 1376 | |
1377 | mode_changes[mode_count].letter = c; | |
1378 | mode_changes[mode_count].dir = MODE_ADD; | |
1379 | mode_changes[mode_count].caps = 0; | |
1380 | mode_changes[mode_count].nocaps = 0; | |
1381 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1382 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1383 | mode_changes[mode_count].override = override; |
212380e3 | 1384 | mode_changes[mode_count++].arg = limitstr; |
1385 | ||
1386 | chptr->mode.limit = limit; | |
1387 | } | |
1388 | else if(dir == MODE_DEL) | |
1389 | { | |
1390 | if(!chptr->mode.limit) | |
1391 | return; | |
1392 | ||
1393 | chptr->mode.limit = 0; | |
1394 | ||
1395 | mode_changes[mode_count].letter = c; | |
1396 | mode_changes[mode_count].dir = MODE_DEL; | |
1397 | mode_changes[mode_count].caps = 0; | |
1398 | mode_changes[mode_count].nocaps = 0; | |
1399 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1400 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1401 | mode_changes[mode_count].override = override; |
212380e3 | 1402 | mode_changes[mode_count++].arg = NULL; |
1403 | } | |
1404 | } | |
1405 | ||
1406 | void | |
1407 | chm_throttle(struct Client *source_p, struct Channel *chptr, | |
1408 | int alevel, int parc, int *parn, | |
1409 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1410 | { | |
1411 | int joins = 0, timeslice = 0; | |
b869e117 | 1412 | int override = 0; |
212380e3 | 1413 | |
82f8e812 | 1414 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1415 | { |
b869e117 JH |
1416 | if(IsOverride(source_p)) |
1417 | override = 1; | |
1418 | else | |
1419 | { | |
1420 | ||
1421 | if(!(*errors & SM_ERR_NOOPS)) | |
1422 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1423 | me.name, source_p->name, chptr->chname); | |
1424 | *errors |= SM_ERR_NOOPS; | |
1425 | return; | |
1426 | } | |
212380e3 | 1427 | } |
1428 | ||
1429 | if(dir == MODE_QUERY) | |
1430 | return; | |
1431 | ||
c08f4515 JT |
1432 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1433 | return; | |
1434 | ||
212380e3 | 1435 | if((dir == MODE_ADD) && parc > *parn) |
1436 | { | |
1437 | sscanf(parv[(*parn)], "%d:%d", &joins, ×lice); | |
1438 | ||
1439 | if(!joins || !timeslice) | |
1440 | return; | |
1441 | ||
1442 | mode_changes[mode_count].letter = c; | |
1443 | mode_changes[mode_count].dir = MODE_ADD; | |
1444 | mode_changes[mode_count].caps = 0; | |
1445 | mode_changes[mode_count].nocaps = 0; | |
1446 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1447 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1448 | mode_changes[mode_count].override = override; |
212380e3 | 1449 | mode_changes[mode_count++].arg = parv[(*parn)]; |
1450 | ||
1451 | (*parn)++; | |
1452 | ||
1453 | chptr->mode.join_num = joins; | |
1454 | chptr->mode.join_time = timeslice; | |
1455 | } | |
1456 | else if(dir == MODE_DEL) | |
1457 | { | |
1458 | if(!chptr->mode.join_num) | |
1459 | return; | |
1460 | ||
1461 | chptr->mode.join_num = 0; | |
1462 | chptr->mode.join_time = 0; | |
1463 | chptr->join_count = 0; | |
1464 | chptr->join_delta = 0; | |
1465 | ||
1466 | mode_changes[mode_count].letter = c; | |
1467 | mode_changes[mode_count].dir = MODE_DEL; | |
1468 | mode_changes[mode_count].caps = 0; | |
1469 | mode_changes[mode_count].nocaps = 0; | |
1470 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1471 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1472 | mode_changes[mode_count].override = override; |
212380e3 | 1473 | mode_changes[mode_count++].arg = NULL; |
1474 | } | |
1475 | } | |
1476 | ||
1477 | void | |
1478 | chm_forward(struct Client *source_p, struct Channel *chptr, | |
1479 | int alevel, int parc, int *parn, | |
1480 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1481 | { | |
1482 | struct Channel *targptr = NULL; | |
1483 | struct membership *msptr; | |
1484 | const char *forward; | |
b869e117 | 1485 | int override = 0; |
212380e3 | 1486 | |
1487 | /* if +f is disabled, ignore local attempts to set it */ | |
1488 | if(!ConfigChannel.use_forward && MyClient(source_p) && | |
1489 | (dir == MODE_ADD) && (parc > *parn)) | |
1490 | return; | |
1491 | ||
1492 | if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn)) | |
1493 | { | |
1494 | if (!(*errors & SM_ERR_RPL_F)) | |
1495 | { | |
1496 | if (*chptr->mode.forward == '\0') | |
5366977b | 1497 | sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); |
212380e3 | 1498 | else |
5366977b | 1499 | sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); |
212380e3 | 1500 | *errors |= SM_ERR_RPL_F; |
1501 | } | |
1502 | return; | |
1503 | } | |
1504 | ||
1505 | #ifndef FORWARD_OPERONLY | |
82f8e812 | 1506 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1507 | { |
b869e117 JH |
1508 | if(IsOverride(source_p)) |
1509 | override = 1; | |
1510 | else | |
1511 | { | |
1512 | if(!(*errors & SM_ERR_NOOPS)) | |
1513 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1514 | me.name, source_p->name, chptr->chname); | |
1515 | *errors |= SM_ERR_NOOPS; | |
1516 | return; | |
1517 | } | |
212380e3 | 1518 | } |
1519 | #else | |
1520 | if(!IsOper(source_p) && !IsServer(source_p)) | |
1521 | { | |
1522 | if(!(*errors & SM_ERR_NOPRIVS)) | |
1523 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
1524 | *errors |= SM_ERR_NOPRIVS; | |
1525 | return; | |
1526 | } | |
1527 | #endif | |
1528 | ||
c08f4515 JT |
1529 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1530 | return; | |
1531 | ||
212380e3 | 1532 | if(dir == MODE_ADD && parc > *parn) |
1533 | { | |
1534 | forward = parv[(*parn)]; | |
1535 | (*parn)++; | |
1536 | ||
1537 | if(EmptyString(forward)) | |
1538 | return; | |
1539 | if(!check_channel_name(forward) || | |
1540 | (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) | |
1541 | { | |
1542 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); | |
1543 | return; | |
1544 | } | |
1545 | /* don't forward to inconsistent target -- jilles */ | |
1546 | if(chptr->chname[0] == '#' && forward[0] == '&') | |
1547 | { | |
1548 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
1549 | form_str(ERR_BADCHANNAME), forward); | |
1550 | return; | |
1551 | } | |
1552 | if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) | |
1553 | { | |
1554 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
1555 | form_str(ERR_NOSUCHCHANNEL), forward); | |
1556 | return; | |
1557 | } | |
1558 | if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) | |
1559 | { | |
1560 | if((msptr = find_channel_membership(targptr, source_p)) == NULL || | |
15476006 | 1561 | is_any_op(msptr)) |
212380e3 | 1562 | { |
b869e117 JH |
1563 | if(IsOverride(source_p)) |
1564 | override = 1; | |
1565 | else | |
1566 | { | |
1567 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1568 | me.name, source_p->name, targptr->chname); | |
1569 | return; | |
1570 | } | |
212380e3 | 1571 | } |
1572 | } | |
1573 | ||
907468c4 | 1574 | rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward)); |
212380e3 | 1575 | |
1576 | mode_changes[mode_count].letter = c; | |
1577 | mode_changes[mode_count].dir = MODE_ADD; | |
1578 | mode_changes[mode_count].caps = 0; | |
1579 | mode_changes[mode_count].nocaps = 0; | |
1580 | mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; | |
1581 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1582 | mode_changes[mode_count].override = override; |
212380e3 | 1583 | mode_changes[mode_count++].arg = forward; |
1584 | } | |
1585 | else if(dir == MODE_DEL) | |
1586 | { | |
1587 | if(!(*chptr->mode.forward)) | |
1588 | return; | |
1589 | ||
1590 | *chptr->mode.forward = '\0'; | |
1591 | ||
1592 | mode_changes[mode_count].letter = c; | |
1593 | mode_changes[mode_count].dir = MODE_DEL; | |
1594 | mode_changes[mode_count].caps = 0; | |
1595 | mode_changes[mode_count].nocaps = 0; | |
1596 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1597 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1598 | mode_changes[mode_count].override = override; |
212380e3 | 1599 | mode_changes[mode_count++].arg = NULL; |
1600 | } | |
1601 | } | |
1602 | ||
1603 | void | |
1604 | chm_key(struct Client *source_p, struct Channel *chptr, | |
1605 | int alevel, int parc, int *parn, | |
1606 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1607 | { | |
1608 | char *key; | |
b869e117 | 1609 | int override = 0; |
212380e3 | 1610 | |
82f8e812 | 1611 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1612 | { |
b869e117 JH |
1613 | if(IsOverride(source_p)) |
1614 | override = 1; | |
1615 | else | |
1616 | { | |
1617 | if(!(*errors & SM_ERR_NOOPS)) | |
1618 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1619 | me.name, source_p->name, chptr->chname); | |
1620 | *errors |= SM_ERR_NOOPS; | |
1621 | return; | |
1622 | } | |
212380e3 | 1623 | } |
1624 | ||
1625 | if(dir == MODE_QUERY) | |
1626 | return; | |
1627 | ||
c08f4515 JT |
1628 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1629 | return; | |
1630 | ||
212380e3 | 1631 | if((dir == MODE_ADD) && parc > *parn) |
1632 | { | |
1633 | key = LOCAL_COPY(parv[(*parn)]); | |
1634 | (*parn)++; | |
1635 | ||
1636 | if(MyClient(source_p)) | |
1637 | fix_key(key); | |
1638 | else | |
1639 | fix_key_remote(key); | |
1640 | ||
1641 | if(EmptyString(key)) | |
1642 | return; | |
1643 | ||
1644 | s_assert(key[0] != ' '); | |
907468c4 | 1645 | rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
212380e3 | 1646 | |
1647 | mode_changes[mode_count].letter = c; | |
1648 | mode_changes[mode_count].dir = MODE_ADD; | |
1649 | mode_changes[mode_count].caps = 0; | |
1650 | mode_changes[mode_count].nocaps = 0; | |
1651 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1652 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1653 | mode_changes[mode_count].override = override; |
212380e3 | 1654 | mode_changes[mode_count++].arg = chptr->mode.key; |
1655 | } | |
1656 | else if(dir == MODE_DEL) | |
1657 | { | |
1658 | static char splat[] = "*"; | |
1659 | int i; | |
1660 | ||
1661 | if(parc > *parn) | |
1662 | (*parn)++; | |
1663 | ||
1664 | if(!(*chptr->mode.key)) | |
1665 | return; | |
1666 | ||
1667 | /* hack time. when we get a +k-k mode, the +k arg is | |
1668 | * chptr->mode.key, which the -k sets to \0, so hunt for a | |
1669 | * +k when we get a -k, and set the arg to splat. --anfl | |
1670 | */ | |
1671 | for(i = 0; i < mode_count; i++) | |
1672 | { | |
1673 | if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) | |
1674 | mode_changes[i].arg = splat; | |
1675 | } | |
1676 | ||
1677 | *chptr->mode.key = 0; | |
1678 | ||
1679 | mode_changes[mode_count].letter = c; | |
1680 | mode_changes[mode_count].dir = MODE_DEL; | |
1681 | mode_changes[mode_count].caps = 0; | |
1682 | mode_changes[mode_count].nocaps = 0; | |
1683 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1684 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1685 | mode_changes[mode_count].override = override; |
212380e3 | 1686 | mode_changes[mode_count++].arg = "*"; |
1687 | } | |
1688 | } | |
1689 | ||
1690 | void | |
1691 | chm_regonly(struct Client *source_p, struct Channel *chptr, | |
1692 | int alevel, int parc, int *parn, | |
1693 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1694 | { | |
b869e117 JH |
1695 | int override = 0; |
1696 | ||
82f8e812 | 1697 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1698 | { |
b869e117 JH |
1699 | if(IsOverride(source_p)) |
1700 | override = 1; | |
1701 | else | |
1702 | { | |
1703 | if(!(*errors & SM_ERR_NOOPS)) | |
1704 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1705 | me.name, source_p->name, chptr->chname); | |
1706 | *errors |= SM_ERR_NOOPS; | |
1707 | return; | |
1708 | } | |
212380e3 | 1709 | } |
1710 | ||
1711 | if(dir == MODE_QUERY) | |
1712 | return; | |
1713 | ||
040c4408 JT |
1714 | if(((dir == MODE_ADD) && (chptr->mode.mode & mode_type)) || |
1715 | ((dir == MODE_DEL) && !(chptr->mode.mode & mode_type))) | |
212380e3 | 1716 | return; |
1717 | ||
c08f4515 JT |
1718 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1719 | return; | |
1720 | ||
212380e3 | 1721 | if(dir == MODE_ADD) |
040c4408 | 1722 | chptr->mode.mode |= mode_type; |
212380e3 | 1723 | else |
040c4408 | 1724 | chptr->mode.mode &= ~mode_type; |
212380e3 | 1725 | |
1726 | mode_changes[mode_count].letter = c; | |
1727 | mode_changes[mode_count].dir = dir; | |
1728 | mode_changes[mode_count].caps = CAP_SERVICE; | |
1729 | mode_changes[mode_count].nocaps = 0; | |
1730 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1731 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1732 | mode_changes[mode_count].override = override; |
212380e3 | 1733 | mode_changes[mode_count++].arg = NULL; |
1734 | } | |
1735 | ||
1736 | /* *INDENT-OFF* */ | |
1737 | struct ChannelMode chmode_table[256] = | |
1738 | { | |
1739 | {chm_nosuch, 0 }, /* 0x00 */ | |
1740 | {chm_nosuch, 0 }, /* 0x01 */ | |
1741 | {chm_nosuch, 0 }, /* 0x02 */ | |
1742 | {chm_nosuch, 0 }, /* 0x03 */ | |
1743 | {chm_nosuch, 0 }, /* 0x04 */ | |
1744 | {chm_nosuch, 0 }, /* 0x05 */ | |
1745 | {chm_nosuch, 0 }, /* 0x06 */ | |
1746 | {chm_nosuch, 0 }, /* 0x07 */ | |
1747 | {chm_nosuch, 0 }, /* 0x08 */ | |
1748 | {chm_nosuch, 0 }, /* 0x09 */ | |
1749 | {chm_nosuch, 0 }, /* 0x0a */ | |
1750 | {chm_nosuch, 0 }, /* 0x0b */ | |
1751 | {chm_nosuch, 0 }, /* 0x0c */ | |
1752 | {chm_nosuch, 0 }, /* 0x0d */ | |
1753 | {chm_nosuch, 0 }, /* 0x0e */ | |
1754 | {chm_nosuch, 0 }, /* 0x0f */ | |
1755 | {chm_nosuch, 0 }, /* 0x10 */ | |
1756 | {chm_nosuch, 0 }, /* 0x11 */ | |
1757 | {chm_nosuch, 0 }, /* 0x12 */ | |
1758 | {chm_nosuch, 0 }, /* 0x13 */ | |
1759 | {chm_nosuch, 0 }, /* 0x14 */ | |
1760 | {chm_nosuch, 0 }, /* 0x15 */ | |
1761 | {chm_nosuch, 0 }, /* 0x16 */ | |
1762 | {chm_nosuch, 0 }, /* 0x17 */ | |
1763 | {chm_nosuch, 0 }, /* 0x18 */ | |
1764 | {chm_nosuch, 0 }, /* 0x19 */ | |
1765 | {chm_nosuch, 0 }, /* 0x1a */ | |
1766 | {chm_nosuch, 0 }, /* 0x1b */ | |
1767 | {chm_nosuch, 0 }, /* 0x1c */ | |
1768 | {chm_nosuch, 0 }, /* 0x1d */ | |
1769 | {chm_nosuch, 0 }, /* 0x1e */ | |
1770 | {chm_nosuch, 0 }, /* 0x1f */ | |
1771 | {chm_nosuch, 0 }, /* 0x20 */ | |
1772 | {chm_nosuch, 0 }, /* 0x21 */ | |
1773 | {chm_nosuch, 0 }, /* 0x22 */ | |
1774 | {chm_nosuch, 0 }, /* 0x23 */ | |
1775 | {chm_nosuch, 0 }, /* 0x24 */ | |
1776 | {chm_nosuch, 0 }, /* 0x25 */ | |
1777 | {chm_nosuch, 0 }, /* 0x26 */ | |
1778 | {chm_nosuch, 0 }, /* 0x27 */ | |
1779 | {chm_nosuch, 0 }, /* 0x28 */ | |
1780 | {chm_nosuch, 0 }, /* 0x29 */ | |
1781 | {chm_nosuch, 0 }, /* 0x2a */ | |
1782 | {chm_nosuch, 0 }, /* 0x2b */ | |
1783 | {chm_nosuch, 0 }, /* 0x2c */ | |
1784 | {chm_nosuch, 0 }, /* 0x2d */ | |
1785 | {chm_nosuch, 0 }, /* 0x2e */ | |
1786 | {chm_nosuch, 0 }, /* 0x2f */ | |
1787 | {chm_nosuch, 0 }, /* 0x30 */ | |
1788 | {chm_nosuch, 0 }, /* 0x31 */ | |
1789 | {chm_nosuch, 0 }, /* 0x32 */ | |
1790 | {chm_nosuch, 0 }, /* 0x33 */ | |
1791 | {chm_nosuch, 0 }, /* 0x34 */ | |
1792 | {chm_nosuch, 0 }, /* 0x35 */ | |
1793 | {chm_nosuch, 0 }, /* 0x36 */ | |
1794 | {chm_nosuch, 0 }, /* 0x37 */ | |
1795 | {chm_nosuch, 0 }, /* 0x38 */ | |
1796 | {chm_nosuch, 0 }, /* 0x39 */ | |
1797 | {chm_nosuch, 0 }, /* 0x3a */ | |
1798 | {chm_nosuch, 0 }, /* 0x3b */ | |
1799 | {chm_nosuch, 0 }, /* 0x3c */ | |
1800 | {chm_nosuch, 0 }, /* 0x3d */ | |
1801 | {chm_nosuch, 0 }, /* 0x3e */ | |
1802 | {chm_nosuch, 0 }, /* 0x3f */ | |
1803 | ||
1804 | {chm_nosuch, 0 }, /* @ */ | |
1805 | {chm_nosuch, 0 }, /* A */ | |
1806 | {chm_nosuch, 0 }, /* B */ | |
92a79951 | 1807 | {chm_simple, MODE_NOCTCP }, /* C */ |
7e6c9180 | 1808 | {chm_simple, MODE_NOACTION }, /* D */ |
f9e91ece | 1809 | {chm_simple, MODE_NOKICK }, /* E */ |
212380e3 | 1810 | {chm_simple, MODE_FREETARGET }, /* F */ |
2b3c7c29 | 1811 | {chm_simple, MODE_NOCAPS }, /* G */ |
212380e3 | 1812 | {chm_nosuch, 0 }, /* H */ |
1813 | {chm_ban, CHFL_INVEX }, /* I */ | |
846aa234 | 1814 | {chm_simple, MODE_NOREJOIN }, /* J */ |
23b98f3f | 1815 | {chm_simple, MODE_NOREPEAT }, /* K */ |
212380e3 | 1816 | {chm_staff, MODE_EXLIMIT }, /* L */ |
1cdd8fdf | 1817 | {chm_hidden, MODE_NOOPERKICK }, /* M */ |
afd4834b | 1818 | {chm_simple, MODE_NONICK }, /* N */ |
212380e3 | 1819 | {chm_nosuch, 0 }, /* O */ |
1820 | {chm_staff, MODE_PERMANENT }, /* P */ | |
1821 | {chm_simple, MODE_DISFORWARD }, /* Q */ | |
1822 | {chm_nosuch, 0 }, /* R */ | |
1823 | {chm_nosuch, 0 }, /* S */ | |
6afd4b91 | 1824 | {chm_simple, MODE_NONOTICE }, /* T */ |
212380e3 | 1825 | {chm_nosuch, 0 }, /* U */ |
1826 | {chm_nosuch, 0 }, /* V */ | |
1827 | {chm_nosuch, 0 }, /* W */ | |
1828 | {chm_nosuch, 0 }, /* X */ | |
1829 | {chm_nosuch, 0 }, /* Y */ | |
1830 | {chm_nosuch, 0 }, /* Z */ | |
1831 | {chm_nosuch, 0 }, | |
1832 | {chm_nosuch, 0 }, | |
1833 | {chm_nosuch, 0 }, | |
1834 | {chm_nosuch, 0 }, | |
1835 | {chm_nosuch, 0 }, | |
1836 | {chm_nosuch, 0 }, | |
82f8e812 | 1837 | {chm_owner, 0 }, /* a */ |
212380e3 | 1838 | {chm_ban, CHFL_BAN }, /* b */ |
1839 | {chm_simple, MODE_NOCOLOR }, /* c */ | |
1840 | {chm_nosuch, 0 }, /* d */ | |
1841 | {chm_ban, CHFL_EXCEPTION }, /* e */ | |
1842 | {chm_forward, 0 }, /* f */ | |
1843 | {chm_simple, MODE_FREEINVITE }, /* g */ | |
82f8e812 | 1844 | {chm_halfop, 0 }, /* h */ |
212380e3 | 1845 | {chm_simple, MODE_INVITEONLY }, /* i */ |
1846 | {chm_throttle, 0 }, /* j */ | |
1847 | {chm_key, 0 }, /* k */ | |
1848 | {chm_limit, 0 }, /* l */ | |
1849 | {chm_simple, MODE_MODERATED }, /* m */ | |
1850 | {chm_simple, MODE_NOPRIVMSGS }, /* n */ | |
1851 | {chm_op, 0 }, /* o */ | |
1852 | {chm_simple, MODE_PRIVATE }, /* p */ | |
1853 | {chm_ban, CHFL_QUIET }, /* q */ | |
040c4408 | 1854 | {chm_regonly, MODE_REGONLY }, /* r */ |
212380e3 | 1855 | {chm_simple, MODE_SECRET }, /* s */ |
1856 | {chm_simple, MODE_TOPICLIMIT }, /* t */ | |
1857 | {chm_nosuch, 0 }, /* u */ | |
1858 | {chm_voice, 0 }, /* v */ | |
1859 | {chm_nosuch, 0 }, /* w */ | |
1860 | {chm_nosuch, 0 }, /* x */ | |
1861 | {chm_nosuch, 0 }, /* y */ | |
1862 | {chm_simple, MODE_OPMODERATE }, /* z */ | |
1863 | ||
1864 | {chm_nosuch, 0 }, /* 0x7b */ | |
1865 | {chm_nosuch, 0 }, /* 0x7c */ | |
1866 | {chm_nosuch, 0 }, /* 0x7d */ | |
1867 | {chm_nosuch, 0 }, /* 0x7e */ | |
1868 | {chm_nosuch, 0 }, /* 0x7f */ | |
1869 | ||
1870 | {chm_nosuch, 0 }, /* 0x80 */ | |
1871 | {chm_nosuch, 0 }, /* 0x81 */ | |
1872 | {chm_nosuch, 0 }, /* 0x82 */ | |
1873 | {chm_nosuch, 0 }, /* 0x83 */ | |
1874 | {chm_nosuch, 0 }, /* 0x84 */ | |
1875 | {chm_nosuch, 0 }, /* 0x85 */ | |
1876 | {chm_nosuch, 0 }, /* 0x86 */ | |
1877 | {chm_nosuch, 0 }, /* 0x87 */ | |
1878 | {chm_nosuch, 0 }, /* 0x88 */ | |
1879 | {chm_nosuch, 0 }, /* 0x89 */ | |
1880 | {chm_nosuch, 0 }, /* 0x8a */ | |
1881 | {chm_nosuch, 0 }, /* 0x8b */ | |
1882 | {chm_nosuch, 0 }, /* 0x8c */ | |
1883 | {chm_nosuch, 0 }, /* 0x8d */ | |
1884 | {chm_nosuch, 0 }, /* 0x8e */ | |
1885 | {chm_nosuch, 0 }, /* 0x8f */ | |
1886 | ||
1887 | {chm_nosuch, 0 }, /* 0x90 */ | |
1888 | {chm_nosuch, 0 }, /* 0x91 */ | |
1889 | {chm_nosuch, 0 }, /* 0x92 */ | |
1890 | {chm_nosuch, 0 }, /* 0x93 */ | |
1891 | {chm_nosuch, 0 }, /* 0x94 */ | |
1892 | {chm_nosuch, 0 }, /* 0x95 */ | |
1893 | {chm_nosuch, 0 }, /* 0x96 */ | |
1894 | {chm_nosuch, 0 }, /* 0x97 */ | |
1895 | {chm_nosuch, 0 }, /* 0x98 */ | |
1896 | {chm_nosuch, 0 }, /* 0x99 */ | |
1897 | {chm_nosuch, 0 }, /* 0x9a */ | |
1898 | {chm_nosuch, 0 }, /* 0x9b */ | |
1899 | {chm_nosuch, 0 }, /* 0x9c */ | |
1900 | {chm_nosuch, 0 }, /* 0x9d */ | |
1901 | {chm_nosuch, 0 }, /* 0x9e */ | |
1902 | {chm_nosuch, 0 }, /* 0x9f */ | |
1903 | ||
1904 | {chm_nosuch, 0 }, /* 0xa0 */ | |
1905 | {chm_nosuch, 0 }, /* 0xa1 */ | |
1906 | {chm_nosuch, 0 }, /* 0xa2 */ | |
1907 | {chm_nosuch, 0 }, /* 0xa3 */ | |
1908 | {chm_nosuch, 0 }, /* 0xa4 */ | |
1909 | {chm_nosuch, 0 }, /* 0xa5 */ | |
1910 | {chm_nosuch, 0 }, /* 0xa6 */ | |
1911 | {chm_nosuch, 0 }, /* 0xa7 */ | |
1912 | {chm_nosuch, 0 }, /* 0xa8 */ | |
1913 | {chm_nosuch, 0 }, /* 0xa9 */ | |
1914 | {chm_nosuch, 0 }, /* 0xaa */ | |
1915 | {chm_nosuch, 0 }, /* 0xab */ | |
1916 | {chm_nosuch, 0 }, /* 0xac */ | |
1917 | {chm_nosuch, 0 }, /* 0xad */ | |
1918 | {chm_nosuch, 0 }, /* 0xae */ | |
1919 | {chm_nosuch, 0 }, /* 0xaf */ | |
1920 | ||
1921 | {chm_nosuch, 0 }, /* 0xb0 */ | |
1922 | {chm_nosuch, 0 }, /* 0xb1 */ | |
1923 | {chm_nosuch, 0 }, /* 0xb2 */ | |
1924 | {chm_nosuch, 0 }, /* 0xb3 */ | |
1925 | {chm_nosuch, 0 }, /* 0xb4 */ | |
1926 | {chm_nosuch, 0 }, /* 0xb5 */ | |
1927 | {chm_nosuch, 0 }, /* 0xb6 */ | |
1928 | {chm_nosuch, 0 }, /* 0xb7 */ | |
1929 | {chm_nosuch, 0 }, /* 0xb8 */ | |
1930 | {chm_nosuch, 0 }, /* 0xb9 */ | |
1931 | {chm_nosuch, 0 }, /* 0xba */ | |
1932 | {chm_nosuch, 0 }, /* 0xbb */ | |
1933 | {chm_nosuch, 0 }, /* 0xbc */ | |
1934 | {chm_nosuch, 0 }, /* 0xbd */ | |
1935 | {chm_nosuch, 0 }, /* 0xbe */ | |
1936 | {chm_nosuch, 0 }, /* 0xbf */ | |
1937 | ||
1938 | {chm_nosuch, 0 }, /* 0xc0 */ | |
1939 | {chm_nosuch, 0 }, /* 0xc1 */ | |
1940 | {chm_nosuch, 0 }, /* 0xc2 */ | |
1941 | {chm_nosuch, 0 }, /* 0xc3 */ | |
1942 | {chm_nosuch, 0 }, /* 0xc4 */ | |
1943 | {chm_nosuch, 0 }, /* 0xc5 */ | |
1944 | {chm_nosuch, 0 }, /* 0xc6 */ | |
1945 | {chm_nosuch, 0 }, /* 0xc7 */ | |
1946 | {chm_nosuch, 0 }, /* 0xc8 */ | |
1947 | {chm_nosuch, 0 }, /* 0xc9 */ | |
1948 | {chm_nosuch, 0 }, /* 0xca */ | |
1949 | {chm_nosuch, 0 }, /* 0xcb */ | |
1950 | {chm_nosuch, 0 }, /* 0xcc */ | |
1951 | {chm_nosuch, 0 }, /* 0xcd */ | |
1952 | {chm_nosuch, 0 }, /* 0xce */ | |
1953 | {chm_nosuch, 0 }, /* 0xcf */ | |
1954 | ||
1955 | {chm_nosuch, 0 }, /* 0xd0 */ | |
1956 | {chm_nosuch, 0 }, /* 0xd1 */ | |
1957 | {chm_nosuch, 0 }, /* 0xd2 */ | |
1958 | {chm_nosuch, 0 }, /* 0xd3 */ | |
1959 | {chm_nosuch, 0 }, /* 0xd4 */ | |
1960 | {chm_nosuch, 0 }, /* 0xd5 */ | |
1961 | {chm_nosuch, 0 }, /* 0xd6 */ | |
1962 | {chm_nosuch, 0 }, /* 0xd7 */ | |
1963 | {chm_nosuch, 0 }, /* 0xd8 */ | |
1964 | {chm_nosuch, 0 }, /* 0xd9 */ | |
1965 | {chm_nosuch, 0 }, /* 0xda */ | |
1966 | {chm_nosuch, 0 }, /* 0xdb */ | |
1967 | {chm_nosuch, 0 }, /* 0xdc */ | |
1968 | {chm_nosuch, 0 }, /* 0xdd */ | |
1969 | {chm_nosuch, 0 }, /* 0xde */ | |
1970 | {chm_nosuch, 0 }, /* 0xdf */ | |
1971 | ||
1972 | {chm_nosuch, 0 }, /* 0xe0 */ | |
1973 | {chm_nosuch, 0 }, /* 0xe1 */ | |
1974 | {chm_nosuch, 0 }, /* 0xe2 */ | |
1975 | {chm_nosuch, 0 }, /* 0xe3 */ | |
1976 | {chm_nosuch, 0 }, /* 0xe4 */ | |
1977 | {chm_nosuch, 0 }, /* 0xe5 */ | |
1978 | {chm_nosuch, 0 }, /* 0xe6 */ | |
1979 | {chm_nosuch, 0 }, /* 0xe7 */ | |
1980 | {chm_nosuch, 0 }, /* 0xe8 */ | |
1981 | {chm_nosuch, 0 }, /* 0xe9 */ | |
1982 | {chm_nosuch, 0 }, /* 0xea */ | |
1983 | {chm_nosuch, 0 }, /* 0xeb */ | |
1984 | {chm_nosuch, 0 }, /* 0xec */ | |
1985 | {chm_nosuch, 0 }, /* 0xed */ | |
1986 | {chm_nosuch, 0 }, /* 0xee */ | |
1987 | {chm_nosuch, 0 }, /* 0xef */ | |
1988 | ||
1989 | {chm_nosuch, 0 }, /* 0xf0 */ | |
1990 | {chm_nosuch, 0 }, /* 0xf1 */ | |
1991 | {chm_nosuch, 0 }, /* 0xf2 */ | |
1992 | {chm_nosuch, 0 }, /* 0xf3 */ | |
1993 | {chm_nosuch, 0 }, /* 0xf4 */ | |
1994 | {chm_nosuch, 0 }, /* 0xf5 */ | |
1995 | {chm_nosuch, 0 }, /* 0xf6 */ | |
1996 | {chm_nosuch, 0 }, /* 0xf7 */ | |
1997 | {chm_nosuch, 0 }, /* 0xf8 */ | |
1998 | {chm_nosuch, 0 }, /* 0xf9 */ | |
1999 | {chm_nosuch, 0 }, /* 0xfa */ | |
2000 | {chm_nosuch, 0 }, /* 0xfb */ | |
2001 | {chm_nosuch, 0 }, /* 0xfc */ | |
2002 | {chm_nosuch, 0 }, /* 0xfd */ | |
2003 | {chm_nosuch, 0 }, /* 0xfe */ | |
2004 | {chm_nosuch, 0 }, /* 0xff */ | |
2005 | }; | |
2006 | ||
2007 | /* *INDENT-ON* */ | |
2008 | ||
2009 | /* set_channel_mode() | |
2010 | * | |
2011 | * inputs - client, source, channel, membership pointer, params | |
2012 | * output - | |
2013 | * side effects - channel modes/memberships are changed, MODE is issued | |
2014 | * | |
2015 | * Extensively modified to be hotpluggable, 03/09/06 -- nenolod | |
2016 | */ | |
2017 | void | |
2018 | set_channel_mode(struct Client *client_p, struct Client *source_p, | |
2019 | struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) | |
2020 | { | |
eccd1c58 | 2021 | static char cmdbuf[BUFSIZE]; |
212380e3 | 2022 | static char modebuf[BUFSIZE]; |
2023 | static char parabuf[BUFSIZE]; | |
2024 | char *mbuf; | |
2025 | char *pbuf; | |
2026 | int cur_len, mlen, paralen, paracount, arglen, len; | |
eccd1c58 | 2027 | int i, j, flags, override; |
212380e3 | 2028 | int dir = MODE_ADD; |
2029 | int parn = 1; | |
2030 | int errors = 0; | |
2031 | int alevel; | |
2032 | const char *ml = parv[0]; | |
2033 | char c; | |
2034 | struct Client *fakesource_p; | |
1cdd8fdf | 2035 | int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; |
212380e3 | 2036 | |
2037 | mask_pos = 0; | |
2038 | mode_count = 0; | |
2039 | mode_limit = 0; | |
c08f4515 | 2040 | mode_limit_simple = 0; |
212380e3 | 2041 | |
2042 | alevel = get_channel_access(source_p, msptr); | |
2043 | ||
b869e117 JH |
2044 | no_override_deop = 0; |
2045 | ||
212380e3 | 2046 | /* Hide connecting server on netburst -- jilles */ |
2047 | if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) | |
2048 | fakesource_p = &me; | |
2049 | else | |
2050 | fakesource_p = source_p; | |
2051 | ||
2052 | for(; (c = *ml) != 0; ml++) | |
2053 | { | |
2054 | switch (c) | |
2055 | { | |
2056 | case '+': | |
2057 | dir = MODE_ADD; | |
2058 | break; | |
2059 | case '-': | |
2060 | dir = MODE_DEL; | |
2061 | break; | |
2062 | case '=': | |
2063 | dir = MODE_QUERY; | |
2064 | break; | |
2065 | default: | |
2066 | chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, | |
2067 | parc, &parn, parv, | |
2068 | &errors, dir, c, | |
2069 | chmode_table[(unsigned char) c].mode_type); | |
2070 | break; | |
2071 | } | |
2072 | } | |
2073 | ||
2074 | /* bail out if we have nothing to do... */ | |
2075 | if(!mode_count) | |
2076 | return; | |
2077 | ||
2078 | if(IsServer(source_p)) | |
eccd1c58 | 2079 | rb_sprintf(cmdbuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); |
212380e3 | 2080 | else |
eccd1c58 | 2081 | rb_sprintf(cmdbuf, ":%s!%s@%s MODE %s ", |
212380e3 | 2082 | source_p->name, source_p->username, |
2083 | source_p->host, chptr->chname); | |
2084 | ||
e853274c JH |
2085 | mlen = 0; |
2086 | ||
cb097b88 | 2087 | for (override = 0; override < (IsOverride(source_p) && alevel != CHFL_CHANOP ? 2 : 1); ++override) |
212380e3 | 2088 | { |
eccd1c58 | 2089 | int was_on_chan = 0; |
b869e117 | 2090 | |
eccd1c58 | 2091 | if(override) |
212380e3 | 2092 | { |
eccd1c58 | 2093 | if(msptr) |
b869e117 | 2094 | { |
eccd1c58 | 2095 | was_on_chan = 1; |
b869e117 JH |
2096 | msptr->flags |= CHFL_CHANOP; |
2097 | } | |
eccd1c58 | 2098 | else |
b869e117 | 2099 | add_user_to_channel(chptr, source_p, CHFL_CHANOP); |
eccd1c58 | 2100 | } |
212380e3 | 2101 | |
1cdd8fdf | 2102 | for(j = 0, flags = flags_list[0]; j < 3; j++, flags = flags_list[j]) |
eccd1c58 JH |
2103 | { |
2104 | cur_len = mlen; | |
2105 | mbuf = modebuf + mlen; | |
2106 | pbuf = parabuf; | |
2107 | parabuf[0] = '\0'; | |
2108 | paracount = paralen = 0; | |
2109 | dir = MODE_QUERY; | |
212380e3 | 2110 | |
eccd1c58 | 2111 | for(i = 0; i < mode_count; i++) |
212380e3 | 2112 | { |
eccd1c58 | 2113 | if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) |
2f39232f | 2114 | continue; |
212380e3 | 2115 | |
eccd1c58 | 2116 | if(mode_changes[i].override != override) |
212380e3 | 2117 | continue; |
2118 | ||
eccd1c58 JH |
2119 | if(mode_changes[i].arg != NULL) |
2120 | { | |
2121 | arglen = strlen(mode_changes[i].arg); | |
212380e3 | 2122 | |
eccd1c58 JH |
2123 | if(arglen > MODEBUFLEN - 5) |
2124 | continue; | |
2125 | } | |
2126 | else | |
2127 | arglen = 0; | |
2128 | ||
2129 | /* if we're creeping over MAXMODEPARAMSSERV, or over | |
2130 | * bufsize (4 == +/-,modechar,two spaces) send now. | |
2131 | */ | |
2132 | if(mode_changes[i].arg != NULL && | |
2f39232f G |
2133 | ((paracount == MAXMODEPARAMSSERV) || |
2134 | ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) | |
eccd1c58 JH |
2135 | { |
2136 | *mbuf = '\0'; | |
2137 | ||
2138 | if(cur_len > mlen) | |
2139 | { | |
2140 | sendto_channel_local(flags, chptr, "%s%s %s", | |
2f39232f | 2141 | cmdbuf, modebuf, parabuf); |
eccd1c58 | 2142 | if(override) |
34d8ef4d JH |
2143 | { |
2144 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
eccd1c58 | 2145 | "%s is overriding modes on %s: %s %s", |
34d8ef4d JH |
2146 | get_oper_name(source_p), chptr->chname, modebuf, parabuf); |
2147 | sendto_server(NULL, chptr, NOCAPS, NOCAPS, | |
2148 | ":%s WALLOPS :%s is overriding modes on %s: %s %s", | |
2149 | use_id(source_p), get_oper_name(source_p), chptr->chname, modebuf, parabuf); | |
2150 | } | |
eccd1c58 JH |
2151 | } |
2152 | else | |
2153 | continue; | |
2154 | ||
2155 | paracount = paralen = 0; | |
2156 | cur_len = mlen; | |
2157 | mbuf = modebuf + mlen; | |
2158 | pbuf = parabuf; | |
2159 | parabuf[0] = '\0'; | |
2160 | dir = MODE_QUERY; | |
2161 | } | |
2162 | ||
2163 | if(dir != mode_changes[i].dir) | |
2164 | { | |
2165 | *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
2166 | cur_len++; | |
2167 | dir = mode_changes[i].dir; | |
2168 | } | |
2169 | ||
2170 | *mbuf++ = mode_changes[i].letter; | |
212380e3 | 2171 | cur_len++; |
212380e3 | 2172 | |
eccd1c58 JH |
2173 | if(mode_changes[i].arg != NULL) |
2174 | { | |
2175 | paracount++; | |
2176 | len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg); | |
2177 | pbuf += len; | |
2178 | paralen += len; | |
2179 | } | |
212380e3 | 2180 | } |
212380e3 | 2181 | |
3da167f2 JH |
2182 | if(paralen && parabuf[paralen - 1] == ' ') |
2183 | parabuf[paralen - 1] = '\0'; | |
2184 | ||
2185 | *mbuf = '\0'; | |
2186 | if(cur_len > mlen) | |
b869e117 | 2187 | { |
3da167f2 JH |
2188 | sendto_channel_local(flags, chptr, "%s%s %s", cmdbuf, modebuf, parabuf); |
2189 | if(override) | |
34d8ef4d JH |
2190 | { |
2191 | sendto_wallops_flags(UMODE_WALLOP, &me, | |
3da167f2 | 2192 | "%s is overriding modes on %s: %s %s", |
34d8ef4d JH |
2193 | get_oper_name(source_p), chptr->chname, modebuf, parabuf); |
2194 | sendto_server(NULL, chptr, NOCAPS, NOCAPS, | |
2195 | ":%s WALLOPS :%s is overriding modes on %s: %s %s", | |
2196 | use_id(source_p), get_oper_name(source_p), chptr->chname, modebuf, parabuf); | |
2197 | } | |
b869e117 | 2198 | } |
3da167f2 JH |
2199 | } |
2200 | if(override) | |
2201 | { | |
2202 | if(!was_on_chan) | |
2203 | remove_user_from_channel(find_channel_membership(chptr, source_p)); | |
2204 | else if (!no_override_deop) | |
2205 | msptr->flags &= ~CHFL_CHANOP; | |
2206 | } | |
212380e3 | 2207 | } |
2f39232f | 2208 | |
212380e3 | 2209 | /* only propagate modes originating locally, or if we're hubbing */ |
af81d5a0 | 2210 | if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) |
212380e3 | 2211 | send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); |
2212 | } |