]>
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 JH |
801 | { |
802 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
803 | "%s is overriding modes on %s: (%s list)", | |
804 | get_oper_name(source_p), chptr->chname, | |
805 | mode_type == CHFL_INVEX ? "invex" : "exempt"); | |
806 | } | |
4ed822ed JH |
807 | else |
808 | { | |
809 | ||
810 | if(!(*errors & SM_ERR_NOOPS)) | |
811 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
812 | me.name, source_p->name, chptr->chname); | |
813 | *errors |= SM_ERR_NOOPS; | |
814 | return; | |
815 | } | |
212380e3 | 816 | } |
817 | ||
8e69bb4e | 818 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 819 | { |
820 | banptr = ptr->data; | |
821 | sendto_one(source_p, form_str(rpl_list), | |
822 | me.name, source_p->name, chptr->chname, | |
823 | banptr->banstr, banptr->who, banptr->when); | |
824 | } | |
11781253 | 825 | if (mode_type == CHFL_QUIET) |
826 | sendto_one(source_p, ":%s %d %s %s :End of Channel Quiet List", me.name, rpl_endlist, source_p->name, chptr->chname); | |
827 | else | |
828 | sendto_one(source_p, form_str(rpl_endlist), me.name, source_p->name, chptr->chname); | |
212380e3 | 829 | return; |
830 | } | |
831 | ||
82f8e812 | 832 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 833 | { |
4ed822ed JH |
834 | if(IsOverride(source_p)) |
835 | override = 1; | |
836 | else | |
837 | { | |
838 | ||
839 | if(!(*errors & SM_ERR_NOOPS)) | |
840 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
841 | me.name, source_p->name, chptr->chname); | |
842 | *errors |= SM_ERR_NOOPS; | |
843 | return; | |
844 | } | |
212380e3 | 845 | } |
846 | ||
847 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
848 | return; | |
849 | ||
850 | raw_mask = parv[(*parn)]; | |
851 | (*parn)++; | |
852 | ||
853 | /* empty ban, or starts with ':' which messes up s2s, ignore it */ | |
854 | if(EmptyString(raw_mask) || *raw_mask == ':') | |
855 | return; | |
856 | ||
857 | if(!MyClient(source_p)) | |
858 | { | |
859 | if(strchr(raw_mask, ' ')) | |
860 | return; | |
861 | ||
862 | mask = raw_mask; | |
863 | } | |
864 | else | |
865 | mask = pretty_mask(raw_mask); | |
866 | ||
83294285 | 867 | /* we'd have problems parsing this, hyb6 does it too |
868 | * also make sure it will always fit on a line with channel | |
869 | * name etc. | |
870 | */ | |
871 | if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) | |
212380e3 | 872 | return; |
873 | ||
874 | /* if we're adding a NEW id */ | |
875 | if(dir == MODE_ADD) | |
876 | { | |
877 | if (*mask == '$' && MyClient(source_p)) | |
878 | { | |
879 | if (!valid_extban(mask, source_p, chptr, mode_type)) | |
880 | /* XXX perhaps return an error message here */ | |
881 | return; | |
882 | } | |
883 | ||
884 | /* dont allow local clients to overflow the banlist, dont | |
885 | * let remote servers set duplicate bans | |
886 | */ | |
887 | if(!add_id(source_p, chptr, mask, list, mode_type)) | |
888 | return; | |
889 | ||
890 | mode_changes[mode_count].letter = c; | |
891 | mode_changes[mode_count].dir = MODE_ADD; | |
892 | mode_changes[mode_count].caps = caps; | |
893 | mode_changes[mode_count].nocaps = 0; | |
894 | mode_changes[mode_count].mems = mems; | |
895 | mode_changes[mode_count].id = NULL; | |
4ed822ed | 896 | mode_changes[mode_count].override = override; |
212380e3 | 897 | mode_changes[mode_count++].arg = mask; |
898 | } | |
899 | else if(dir == MODE_DEL) | |
900 | { | |
901 | if(del_id(chptr, mask, list, mode_type) == 0) | |
902 | { | |
903 | /* mask isn't a valid ban, check raw_mask */ | |
904 | if(del_id(chptr, raw_mask, list, mode_type)) | |
905 | mask = raw_mask; | |
906 | } | |
907 | ||
908 | mode_changes[mode_count].letter = c; | |
909 | mode_changes[mode_count].dir = MODE_DEL; | |
910 | mode_changes[mode_count].caps = caps; | |
911 | mode_changes[mode_count].nocaps = 0; | |
912 | mode_changes[mode_count].mems = mems; | |
913 | mode_changes[mode_count].id = NULL; | |
4ed822ed | 914 | mode_changes[mode_count].override = override; |
212380e3 | 915 | mode_changes[mode_count++].arg = mask; |
916 | } | |
917 | } | |
918 | ||
82f8e812 G |
919 | void |
920 | chm_owner(struct Client *source_p, struct Channel *chptr, | |
921 | int alevel, int parc, int *parn, | |
922 | const char **parv, int *errors, int dir, char c, long mode_type) | |
923 | { | |
924 | struct membership *mstptr; | |
925 | const char *ownernick; | |
926 | struct Client *targ_p; | |
4ed822ed | 927 | int override = 0; |
82f8e812 G |
928 | |
929 | if(!ConfigChannel.use_owner) | |
930 | { | |
931 | if(*errors & SM_ERR_UNKNOWN) | |
932 | return; | |
933 | *errors |= SM_ERR_UNKNOWN; | |
934 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
935 | return; | |
936 | } | |
937 | ||
938 | if(alevel != CHFL_OWNER) | |
939 | { | |
4ed822ed JH |
940 | if(IsOverride(source_p)) |
941 | override = 1; | |
942 | else | |
943 | { | |
944 | ||
945 | if(!(*errors & SM_ERR_NOOPS)) | |
946 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
947 | me.name, source_p->name, chptr->chname); | |
948 | *errors |= SM_ERR_NOOPS; | |
949 | return; | |
950 | } | |
82f8e812 G |
951 | } |
952 | ||
953 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
954 | return; | |
955 | ||
956 | ownernick = parv[(*parn)]; | |
957 | (*parn)++; | |
958 | ||
959 | /* empty nick */ | |
960 | if(EmptyString(ownernick)) | |
961 | { | |
962 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
963 | return; | |
964 | } | |
965 | ||
966 | if((targ_p = find_chasing(source_p, ownernick, NULL)) == NULL) | |
967 | { | |
968 | return; | |
969 | } | |
970 | ||
971 | mstptr = find_channel_membership(chptr, targ_p); | |
972 | ||
973 | if(mstptr == NULL) | |
974 | { | |
975 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
976 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
977 | form_str(ERR_USERNOTINCHANNEL), ownernick, chptr->chname); | |
978 | *errors |= SM_ERR_NOTONCHANNEL; | |
979 | return; | |
980 | } | |
981 | ||
982 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
983 | return; | |
984 | ||
985 | if(dir == MODE_ADD) | |
986 | { | |
987 | if(targ_p == source_p) | |
4ed822ed JH |
988 | { |
989 | no_override_deop = 1; | |
cb097b88 JH |
990 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
991 | * legitimate from a remote override oper. | |
4ed822ed JH |
992 | if(!override) |
993 | return; | |
cb097b88 | 994 | */ |
4ed822ed | 995 | } |
82f8e812 G |
996 | |
997 | mode_changes[mode_count].letter = c; | |
998 | mode_changes[mode_count].dir = MODE_ADD; | |
999 | mode_changes[mode_count].caps = 0; | |
1000 | mode_changes[mode_count].nocaps = 0; | |
1001 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1002 | mode_changes[mode_count].id = targ_p->id; | |
1003 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1004 | mode_changes[mode_count].override = override; |
82f8e812 G |
1005 | mode_changes[mode_count++].client = targ_p; |
1006 | ||
1007 | mstptr->flags |= CHFL_OWNER; | |
1008 | } | |
1009 | else | |
1010 | { | |
1011 | if(MyClient(source_p) && IsService(targ_p)) | |
1012 | { | |
1013 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1014 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1015 | return; | |
1016 | } | |
1017 | ||
1018 | mode_changes[mode_count].letter = c; | |
1019 | mode_changes[mode_count].dir = MODE_DEL; | |
1020 | mode_changes[mode_count].caps = 0; | |
1021 | mode_changes[mode_count].nocaps = 0; | |
1022 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1023 | mode_changes[mode_count].id = targ_p->id; | |
1024 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1025 | mode_changes[mode_count].override = override; |
82f8e812 G |
1026 | mode_changes[mode_count++].client = targ_p; |
1027 | ||
1028 | mstptr->flags &= ~CHFL_OWNER; | |
1029 | } | |
1030 | } | |
1031 | ||
212380e3 | 1032 | void |
1033 | chm_op(struct Client *source_p, struct Channel *chptr, | |
1034 | int alevel, int parc, int *parn, | |
1035 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1036 | { | |
1037 | struct membership *mstptr; | |
1038 | const char *opnick; | |
1039 | struct Client *targ_p; | |
4ed822ed | 1040 | int override = 0; |
212380e3 | 1041 | |
82f8e812 | 1042 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER) |
212380e3 | 1043 | { |
4ed822ed JH |
1044 | if(IsOverride(source_p)) |
1045 | override = 1; | |
1046 | else | |
1047 | { | |
1048 | ||
1049 | if(!(*errors & SM_ERR_NOOPS)) | |
1050 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1051 | me.name, source_p->name, chptr->chname); | |
1052 | *errors |= SM_ERR_NOOPS; | |
1053 | return; | |
1054 | } | |
212380e3 | 1055 | } |
1056 | ||
1057 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
1058 | return; | |
1059 | ||
1060 | opnick = parv[(*parn)]; | |
1061 | (*parn)++; | |
1062 | ||
1063 | /* empty nick */ | |
1064 | if(EmptyString(opnick)) | |
1065 | { | |
1066 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1067 | return; | |
1068 | } | |
1069 | ||
1070 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
1071 | { | |
1072 | return; | |
1073 | } | |
1074 | ||
1075 | mstptr = find_channel_membership(chptr, targ_p); | |
1076 | ||
1077 | if(mstptr == NULL) | |
1078 | { | |
1079 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1080 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1081 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
1082 | *errors |= SM_ERR_NOTONCHANNEL; | |
1083 | return; | |
1084 | } | |
1085 | ||
1086 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1087 | return; | |
1088 | ||
1089 | if(dir == MODE_ADD) | |
1090 | { | |
1091 | if(targ_p == source_p) | |
4ed822ed JH |
1092 | { |
1093 | no_override_deop = 1; | |
cb097b88 JH |
1094 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
1095 | * legitimate from a remote override oper. | |
4ed822ed JH |
1096 | if(!override) |
1097 | return; | |
cb097b88 | 1098 | */ |
4ed822ed | 1099 | } |
212380e3 | 1100 | |
1101 | mode_changes[mode_count].letter = c; | |
1102 | mode_changes[mode_count].dir = MODE_ADD; | |
1103 | mode_changes[mode_count].caps = 0; | |
1104 | mode_changes[mode_count].nocaps = 0; | |
1105 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1106 | mode_changes[mode_count].id = targ_p->id; | |
1107 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1108 | mode_changes[mode_count].override = override; |
212380e3 | 1109 | mode_changes[mode_count++].client = targ_p; |
1110 | ||
1111 | mstptr->flags |= CHFL_CHANOP; | |
212380e3 | 1112 | } |
1113 | else | |
1114 | { | |
1115 | if(MyClient(source_p) && IsService(targ_p)) | |
1116 | { | |
1117 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1118 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1119 | return; | |
1120 | } | |
1121 | ||
1122 | mode_changes[mode_count].letter = c; | |
1123 | mode_changes[mode_count].dir = MODE_DEL; | |
1124 | mode_changes[mode_count].caps = 0; | |
1125 | mode_changes[mode_count].nocaps = 0; | |
1126 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1127 | mode_changes[mode_count].id = targ_p->id; | |
1128 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1129 | mode_changes[mode_count].override = override; |
212380e3 | 1130 | mode_changes[mode_count++].client = targ_p; |
1131 | ||
1132 | mstptr->flags &= ~CHFL_CHANOP; | |
1133 | } | |
1134 | } | |
1135 | ||
82f8e812 G |
1136 | void |
1137 | chm_halfop(struct Client *source_p, struct Channel *chptr, | |
1138 | int alevel, int parc, int *parn, | |
1139 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1140 | { | |
1141 | struct membership *mstptr; | |
1142 | const char *halfopnick; | |
1143 | struct Client *targ_p; | |
4ed822ed | 1144 | int override = 0; |
82f8e812 G |
1145 | |
1146 | if(!ConfigChannel.use_halfop) | |
1147 | { | |
1148 | if(*errors & SM_ERR_UNKNOWN) | |
1149 | return; | |
1150 | *errors |= SM_ERR_UNKNOWN; | |
1151 | sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, source_p->name, c); | |
1152 | return; | |
1153 | } | |
1154 | ||
1a9821cd | 1155 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER) |
82f8e812 | 1156 | { |
4ed822ed JH |
1157 | if(IsOverride(source_p)) |
1158 | override = 1; | |
1159 | else | |
1160 | { | |
1161 | ||
1162 | if(!(*errors & SM_ERR_NOOPS)) | |
1163 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1164 | me.name, source_p->name, chptr->chname); | |
1165 | *errors |= SM_ERR_NOOPS; | |
1166 | return; | |
1167 | } | |
82f8e812 G |
1168 | } |
1169 | ||
1170 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
1171 | return; | |
1172 | ||
1173 | halfopnick = parv[(*parn)]; | |
1174 | (*parn)++; | |
1175 | ||
1176 | /* empty nick */ | |
1177 | if(EmptyString(halfopnick)) | |
1178 | { | |
1179 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1180 | return; | |
1181 | } | |
1182 | ||
1183 | if((targ_p = find_chasing(source_p, halfopnick, NULL)) == NULL) | |
1184 | { | |
1185 | return; | |
1186 | } | |
1187 | ||
1188 | mstptr = find_channel_membership(chptr, targ_p); | |
1189 | ||
1190 | if(mstptr == NULL) | |
1191 | { | |
1192 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1193 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1194 | form_str(ERR_USERNOTINCHANNEL), halfopnick, chptr->chname); | |
1195 | *errors |= SM_ERR_NOTONCHANNEL; | |
1196 | return; | |
1197 | } | |
1198 | ||
1199 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1200 | return; | |
1201 | ||
1202 | if(dir == MODE_ADD) | |
1203 | { | |
1204 | if(targ_p == source_p) | |
4ed822ed JH |
1205 | { |
1206 | no_override_deop = 1; | |
cb097b88 JH |
1207 | /* Don't reject modes from remote. It desyncs, and this is perfectly |
1208 | * legitimate from a remote override oper. | |
4ed822ed JH |
1209 | if(!override) |
1210 | return; | |
cb097b88 | 1211 | */ |
4ed822ed | 1212 | } |
82f8e812 G |
1213 | |
1214 | mode_changes[mode_count].letter = c; | |
1215 | mode_changes[mode_count].dir = MODE_ADD; | |
1216 | mode_changes[mode_count].caps = 0; | |
1217 | mode_changes[mode_count].nocaps = 0; | |
1218 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1219 | mode_changes[mode_count].id = targ_p->id; | |
1220 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1221 | mode_changes[mode_count].override = override; |
82f8e812 G |
1222 | mode_changes[mode_count++].client = targ_p; |
1223 | ||
1224 | mstptr->flags |= CHFL_HALFOP; | |
1225 | } | |
1226 | else | |
1227 | { | |
1228 | if(MyClient(source_p) && IsService(targ_p)) | |
1229 | { | |
1230 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1231 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1232 | return; | |
1233 | } | |
1234 | ||
1235 | mode_changes[mode_count].letter = c; | |
1236 | mode_changes[mode_count].dir = MODE_DEL; | |
1237 | mode_changes[mode_count].caps = 0; | |
1238 | mode_changes[mode_count].nocaps = 0; | |
1239 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1240 | mode_changes[mode_count].id = targ_p->id; | |
1241 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1242 | mode_changes[mode_count].override = override; |
82f8e812 G |
1243 | mode_changes[mode_count++].client = targ_p; |
1244 | ||
1245 | mstptr->flags &= ~CHFL_HALFOP; | |
1246 | } | |
1247 | } | |
1248 | ||
212380e3 | 1249 | void |
1250 | chm_voice(struct Client *source_p, struct Channel *chptr, | |
1251 | int alevel, int parc, int *parn, | |
1252 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1253 | { | |
1254 | struct membership *mstptr; | |
1255 | const char *opnick; | |
1256 | struct Client *targ_p; | |
4ed822ed | 1257 | int override = 0; |
212380e3 | 1258 | |
82f8e812 | 1259 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1260 | { |
4ed822ed JH |
1261 | if(IsOverride(source_p)) |
1262 | override = 1; | |
1263 | else | |
1264 | { | |
1265 | ||
1266 | if(!(*errors & SM_ERR_NOOPS)) | |
1267 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1268 | me.name, source_p->name, chptr->chname); | |
1269 | *errors |= SM_ERR_NOOPS; | |
1270 | return; | |
1271 | } | |
212380e3 | 1272 | } |
1273 | ||
1274 | if((dir == MODE_QUERY) || parc <= *parn) | |
1275 | return; | |
1276 | ||
1277 | opnick = parv[(*parn)]; | |
1278 | (*parn)++; | |
1279 | ||
1280 | /* empty nick */ | |
1281 | if(EmptyString(opnick)) | |
1282 | { | |
1283 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1284 | return; | |
1285 | } | |
1286 | ||
1287 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
1288 | { | |
1289 | return; | |
1290 | } | |
1291 | ||
1292 | mstptr = find_channel_membership(chptr, targ_p); | |
1293 | ||
1294 | if(mstptr == NULL) | |
1295 | { | |
1296 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1297 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1298 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
1299 | *errors |= SM_ERR_NOTONCHANNEL; | |
1300 | return; | |
1301 | } | |
1302 | ||
1303 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1304 | return; | |
1305 | ||
1306 | if(dir == MODE_ADD) | |
1307 | { | |
1308 | mode_changes[mode_count].letter = c; | |
1309 | mode_changes[mode_count].dir = MODE_ADD; | |
1310 | mode_changes[mode_count].caps = 0; | |
1311 | mode_changes[mode_count].nocaps = 0; | |
1312 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1313 | mode_changes[mode_count].id = targ_p->id; | |
1314 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1315 | mode_changes[mode_count].override = override; |
212380e3 | 1316 | mode_changes[mode_count++].client = targ_p; |
1317 | ||
1318 | mstptr->flags |= CHFL_VOICE; | |
1319 | } | |
1320 | else | |
1321 | { | |
1322 | mode_changes[mode_count].letter = 'v'; | |
1323 | mode_changes[mode_count].dir = MODE_DEL; | |
1324 | mode_changes[mode_count].caps = 0; | |
1325 | mode_changes[mode_count].nocaps = 0; | |
1326 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1327 | mode_changes[mode_count].id = targ_p->id; | |
1328 | mode_changes[mode_count].arg = targ_p->name; | |
4ed822ed | 1329 | mode_changes[mode_count].override = override; |
212380e3 | 1330 | mode_changes[mode_count++].client = targ_p; |
1331 | ||
1332 | mstptr->flags &= ~CHFL_VOICE; | |
1333 | } | |
1334 | } | |
1335 | ||
1336 | void | |
1337 | chm_limit(struct Client *source_p, struct Channel *chptr, | |
1338 | int alevel, int parc, int *parn, | |
1339 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1340 | { | |
1341 | const char *lstr; | |
1342 | static char limitstr[30]; | |
1343 | int limit; | |
b869e117 | 1344 | int override = 0; |
212380e3 | 1345 | |
82f8e812 | 1346 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1347 | { |
b869e117 JH |
1348 | if(IsOverride(source_p)) |
1349 | override = 1; | |
1350 | else | |
1351 | { | |
1352 | if(!(*errors & SM_ERR_NOOPS)) | |
1353 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1354 | me.name, source_p->name, chptr->chname); | |
1355 | *errors |= SM_ERR_NOOPS; | |
1356 | return; | |
1357 | } | |
212380e3 | 1358 | } |
1359 | ||
1360 | if(dir == MODE_QUERY) | |
1361 | return; | |
1362 | ||
c08f4515 JT |
1363 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1364 | return; | |
1365 | ||
212380e3 | 1366 | if((dir == MODE_ADD) && parc > *parn) |
1367 | { | |
1368 | lstr = parv[(*parn)]; | |
1369 | (*parn)++; | |
1370 | ||
1371 | if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0) | |
1372 | return; | |
1373 | ||
38e6acdd | 1374 | rb_sprintf(limitstr, "%d", limit); |
212380e3 | 1375 | |
1376 | mode_changes[mode_count].letter = c; | |
1377 | mode_changes[mode_count].dir = MODE_ADD; | |
1378 | mode_changes[mode_count].caps = 0; | |
1379 | mode_changes[mode_count].nocaps = 0; | |
1380 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1381 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1382 | mode_changes[mode_count].override = override; |
212380e3 | 1383 | mode_changes[mode_count++].arg = limitstr; |
1384 | ||
1385 | chptr->mode.limit = limit; | |
1386 | } | |
1387 | else if(dir == MODE_DEL) | |
1388 | { | |
1389 | if(!chptr->mode.limit) | |
1390 | return; | |
1391 | ||
1392 | chptr->mode.limit = 0; | |
1393 | ||
1394 | mode_changes[mode_count].letter = c; | |
1395 | mode_changes[mode_count].dir = MODE_DEL; | |
1396 | mode_changes[mode_count].caps = 0; | |
1397 | mode_changes[mode_count].nocaps = 0; | |
1398 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1399 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1400 | mode_changes[mode_count].override = override; |
212380e3 | 1401 | mode_changes[mode_count++].arg = NULL; |
1402 | } | |
1403 | } | |
1404 | ||
1405 | void | |
1406 | chm_throttle(struct Client *source_p, struct Channel *chptr, | |
1407 | int alevel, int parc, int *parn, | |
1408 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1409 | { | |
1410 | int joins = 0, timeslice = 0; | |
b869e117 | 1411 | int override = 0; |
212380e3 | 1412 | |
82f8e812 | 1413 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1414 | { |
b869e117 JH |
1415 | if(IsOverride(source_p)) |
1416 | override = 1; | |
1417 | else | |
1418 | { | |
1419 | ||
1420 | if(!(*errors & SM_ERR_NOOPS)) | |
1421 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1422 | me.name, source_p->name, chptr->chname); | |
1423 | *errors |= SM_ERR_NOOPS; | |
1424 | return; | |
1425 | } | |
212380e3 | 1426 | } |
1427 | ||
1428 | if(dir == MODE_QUERY) | |
1429 | return; | |
1430 | ||
c08f4515 JT |
1431 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1432 | return; | |
1433 | ||
212380e3 | 1434 | if((dir == MODE_ADD) && parc > *parn) |
1435 | { | |
1436 | sscanf(parv[(*parn)], "%d:%d", &joins, ×lice); | |
1437 | ||
1438 | if(!joins || !timeslice) | |
1439 | return; | |
1440 | ||
1441 | mode_changes[mode_count].letter = c; | |
1442 | mode_changes[mode_count].dir = MODE_ADD; | |
1443 | mode_changes[mode_count].caps = 0; | |
1444 | mode_changes[mode_count].nocaps = 0; | |
1445 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1446 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1447 | mode_changes[mode_count].override = override; |
212380e3 | 1448 | mode_changes[mode_count++].arg = parv[(*parn)]; |
1449 | ||
1450 | (*parn)++; | |
1451 | ||
1452 | chptr->mode.join_num = joins; | |
1453 | chptr->mode.join_time = timeslice; | |
1454 | } | |
1455 | else if(dir == MODE_DEL) | |
1456 | { | |
1457 | if(!chptr->mode.join_num) | |
1458 | return; | |
1459 | ||
1460 | chptr->mode.join_num = 0; | |
1461 | chptr->mode.join_time = 0; | |
1462 | chptr->join_count = 0; | |
1463 | chptr->join_delta = 0; | |
1464 | ||
1465 | mode_changes[mode_count].letter = c; | |
1466 | mode_changes[mode_count].dir = MODE_DEL; | |
1467 | mode_changes[mode_count].caps = 0; | |
1468 | mode_changes[mode_count].nocaps = 0; | |
1469 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1470 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1471 | mode_changes[mode_count].override = override; |
212380e3 | 1472 | mode_changes[mode_count++].arg = NULL; |
1473 | } | |
1474 | } | |
1475 | ||
1476 | void | |
1477 | chm_forward(struct Client *source_p, struct Channel *chptr, | |
1478 | int alevel, int parc, int *parn, | |
1479 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1480 | { | |
1481 | struct Channel *targptr = NULL; | |
1482 | struct membership *msptr; | |
1483 | const char *forward; | |
b869e117 | 1484 | int override = 0; |
212380e3 | 1485 | |
1486 | /* if +f is disabled, ignore local attempts to set it */ | |
1487 | if(!ConfigChannel.use_forward && MyClient(source_p) && | |
1488 | (dir == MODE_ADD) && (parc > *parn)) | |
1489 | return; | |
1490 | ||
1491 | if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn)) | |
1492 | { | |
1493 | if (!(*errors & SM_ERR_RPL_F)) | |
1494 | { | |
1495 | if (*chptr->mode.forward == '\0') | |
5366977b | 1496 | sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); |
212380e3 | 1497 | else |
5366977b | 1498 | sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); |
212380e3 | 1499 | *errors |= SM_ERR_RPL_F; |
1500 | } | |
1501 | return; | |
1502 | } | |
1503 | ||
1504 | #ifndef FORWARD_OPERONLY | |
82f8e812 | 1505 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1506 | { |
b869e117 JH |
1507 | if(IsOverride(source_p)) |
1508 | override = 1; | |
1509 | else | |
1510 | { | |
1511 | if(!(*errors & SM_ERR_NOOPS)) | |
1512 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1513 | me.name, source_p->name, chptr->chname); | |
1514 | *errors |= SM_ERR_NOOPS; | |
1515 | return; | |
1516 | } | |
212380e3 | 1517 | } |
1518 | #else | |
1519 | if(!IsOper(source_p) && !IsServer(source_p)) | |
1520 | { | |
1521 | if(!(*errors & SM_ERR_NOPRIVS)) | |
1522 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
1523 | *errors |= SM_ERR_NOPRIVS; | |
1524 | return; | |
1525 | } | |
1526 | #endif | |
1527 | ||
c08f4515 JT |
1528 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1529 | return; | |
1530 | ||
212380e3 | 1531 | if(dir == MODE_ADD && parc > *parn) |
1532 | { | |
1533 | forward = parv[(*parn)]; | |
1534 | (*parn)++; | |
1535 | ||
1536 | if(EmptyString(forward)) | |
1537 | return; | |
1538 | if(!check_channel_name(forward) || | |
1539 | (MyClient(source_p) && (strlen(forward) > LOC_CHANNELLEN || hash_find_resv(forward)))) | |
1540 | { | |
1541 | sendto_one_numeric(source_p, ERR_BADCHANNAME, form_str(ERR_BADCHANNAME), forward); | |
1542 | return; | |
1543 | } | |
1544 | /* don't forward to inconsistent target -- jilles */ | |
1545 | if(chptr->chname[0] == '#' && forward[0] == '&') | |
1546 | { | |
1547 | sendto_one_numeric(source_p, ERR_BADCHANNAME, | |
1548 | form_str(ERR_BADCHANNAME), forward); | |
1549 | return; | |
1550 | } | |
1551 | if(MyClient(source_p) && (targptr = find_channel(forward)) == NULL) | |
1552 | { | |
1553 | sendto_one_numeric(source_p, ERR_NOSUCHCHANNEL, | |
1554 | form_str(ERR_NOSUCHCHANNEL), forward); | |
1555 | return; | |
1556 | } | |
1557 | if(MyClient(source_p) && !(targptr->mode.mode & MODE_FREETARGET)) | |
1558 | { | |
1559 | if((msptr = find_channel_membership(targptr, source_p)) == NULL || | |
15476006 | 1560 | is_any_op(msptr)) |
212380e3 | 1561 | { |
b869e117 JH |
1562 | if(IsOverride(source_p)) |
1563 | override = 1; | |
1564 | else | |
1565 | { | |
1566 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1567 | me.name, source_p->name, targptr->chname); | |
1568 | return; | |
1569 | } | |
212380e3 | 1570 | } |
1571 | } | |
1572 | ||
907468c4 | 1573 | rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward)); |
212380e3 | 1574 | |
1575 | mode_changes[mode_count].letter = c; | |
1576 | mode_changes[mode_count].dir = MODE_ADD; | |
1577 | mode_changes[mode_count].caps = 0; | |
1578 | mode_changes[mode_count].nocaps = 0; | |
1579 | mode_changes[mode_count].mems = ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; | |
1580 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1581 | mode_changes[mode_count].override = override; |
212380e3 | 1582 | mode_changes[mode_count++].arg = forward; |
1583 | } | |
1584 | else if(dir == MODE_DEL) | |
1585 | { | |
1586 | if(!(*chptr->mode.forward)) | |
1587 | return; | |
1588 | ||
1589 | *chptr->mode.forward = '\0'; | |
1590 | ||
1591 | mode_changes[mode_count].letter = c; | |
1592 | mode_changes[mode_count].dir = MODE_DEL; | |
1593 | mode_changes[mode_count].caps = 0; | |
1594 | mode_changes[mode_count].nocaps = 0; | |
1595 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1596 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1597 | mode_changes[mode_count].override = override; |
212380e3 | 1598 | mode_changes[mode_count++].arg = NULL; |
1599 | } | |
1600 | } | |
1601 | ||
1602 | void | |
1603 | chm_key(struct Client *source_p, struct Channel *chptr, | |
1604 | int alevel, int parc, int *parn, | |
1605 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1606 | { | |
1607 | char *key; | |
b869e117 | 1608 | int override = 0; |
212380e3 | 1609 | |
82f8e812 | 1610 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1611 | { |
b869e117 JH |
1612 | if(IsOverride(source_p)) |
1613 | override = 1; | |
1614 | else | |
1615 | { | |
1616 | if(!(*errors & SM_ERR_NOOPS)) | |
1617 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1618 | me.name, source_p->name, chptr->chname); | |
1619 | *errors |= SM_ERR_NOOPS; | |
1620 | return; | |
1621 | } | |
212380e3 | 1622 | } |
1623 | ||
1624 | if(dir == MODE_QUERY) | |
1625 | return; | |
1626 | ||
c08f4515 JT |
1627 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1628 | return; | |
1629 | ||
212380e3 | 1630 | if((dir == MODE_ADD) && parc > *parn) |
1631 | { | |
1632 | key = LOCAL_COPY(parv[(*parn)]); | |
1633 | (*parn)++; | |
1634 | ||
1635 | if(MyClient(source_p)) | |
1636 | fix_key(key); | |
1637 | else | |
1638 | fix_key_remote(key); | |
1639 | ||
1640 | if(EmptyString(key)) | |
1641 | return; | |
1642 | ||
1643 | s_assert(key[0] != ' '); | |
907468c4 | 1644 | rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
212380e3 | 1645 | |
1646 | mode_changes[mode_count].letter = c; | |
1647 | mode_changes[mode_count].dir = MODE_ADD; | |
1648 | mode_changes[mode_count].caps = 0; | |
1649 | mode_changes[mode_count].nocaps = 0; | |
1650 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1651 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1652 | mode_changes[mode_count].override = override; |
212380e3 | 1653 | mode_changes[mode_count++].arg = chptr->mode.key; |
1654 | } | |
1655 | else if(dir == MODE_DEL) | |
1656 | { | |
1657 | static char splat[] = "*"; | |
1658 | int i; | |
1659 | ||
1660 | if(parc > *parn) | |
1661 | (*parn)++; | |
1662 | ||
1663 | if(!(*chptr->mode.key)) | |
1664 | return; | |
1665 | ||
1666 | /* hack time. when we get a +k-k mode, the +k arg is | |
1667 | * chptr->mode.key, which the -k sets to \0, so hunt for a | |
1668 | * +k when we get a -k, and set the arg to splat. --anfl | |
1669 | */ | |
1670 | for(i = 0; i < mode_count; i++) | |
1671 | { | |
1672 | if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) | |
1673 | mode_changes[i].arg = splat; | |
1674 | } | |
1675 | ||
1676 | *chptr->mode.key = 0; | |
1677 | ||
1678 | mode_changes[mode_count].letter = c; | |
1679 | mode_changes[mode_count].dir = MODE_DEL; | |
1680 | mode_changes[mode_count].caps = 0; | |
1681 | mode_changes[mode_count].nocaps = 0; | |
1682 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1683 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1684 | mode_changes[mode_count].override = override; |
212380e3 | 1685 | mode_changes[mode_count++].arg = "*"; |
1686 | } | |
1687 | } | |
1688 | ||
1689 | void | |
1690 | chm_regonly(struct Client *source_p, struct Channel *chptr, | |
1691 | int alevel, int parc, int *parn, | |
1692 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1693 | { | |
b869e117 JH |
1694 | int override = 0; |
1695 | ||
82f8e812 | 1696 | if(alevel != CHFL_CHANOP && alevel != CHFL_OWNER && alevel != CHFL_HALFOP) |
212380e3 | 1697 | { |
b869e117 JH |
1698 | if(IsOverride(source_p)) |
1699 | override = 1; | |
1700 | else | |
1701 | { | |
1702 | if(!(*errors & SM_ERR_NOOPS)) | |
1703 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
1704 | me.name, source_p->name, chptr->chname); | |
1705 | *errors |= SM_ERR_NOOPS; | |
1706 | return; | |
1707 | } | |
212380e3 | 1708 | } |
1709 | ||
1710 | if(dir == MODE_QUERY) | |
1711 | return; | |
1712 | ||
040c4408 JT |
1713 | if(((dir == MODE_ADD) && (chptr->mode.mode & mode_type)) || |
1714 | ((dir == MODE_DEL) && !(chptr->mode.mode & mode_type))) | |
212380e3 | 1715 | return; |
1716 | ||
c08f4515 JT |
1717 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1718 | return; | |
1719 | ||
212380e3 | 1720 | if(dir == MODE_ADD) |
040c4408 | 1721 | chptr->mode.mode |= mode_type; |
212380e3 | 1722 | else |
040c4408 | 1723 | chptr->mode.mode &= ~mode_type; |
212380e3 | 1724 | |
1725 | mode_changes[mode_count].letter = c; | |
1726 | mode_changes[mode_count].dir = dir; | |
1727 | mode_changes[mode_count].caps = CAP_SERVICE; | |
1728 | mode_changes[mode_count].nocaps = 0; | |
1729 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
1730 | mode_changes[mode_count].id = NULL; | |
b869e117 | 1731 | mode_changes[mode_count].override = override; |
212380e3 | 1732 | mode_changes[mode_count++].arg = NULL; |
1733 | } | |
1734 | ||
1735 | /* *INDENT-OFF* */ | |
1736 | struct ChannelMode chmode_table[256] = | |
1737 | { | |
1738 | {chm_nosuch, 0 }, /* 0x00 */ | |
1739 | {chm_nosuch, 0 }, /* 0x01 */ | |
1740 | {chm_nosuch, 0 }, /* 0x02 */ | |
1741 | {chm_nosuch, 0 }, /* 0x03 */ | |
1742 | {chm_nosuch, 0 }, /* 0x04 */ | |
1743 | {chm_nosuch, 0 }, /* 0x05 */ | |
1744 | {chm_nosuch, 0 }, /* 0x06 */ | |
1745 | {chm_nosuch, 0 }, /* 0x07 */ | |
1746 | {chm_nosuch, 0 }, /* 0x08 */ | |
1747 | {chm_nosuch, 0 }, /* 0x09 */ | |
1748 | {chm_nosuch, 0 }, /* 0x0a */ | |
1749 | {chm_nosuch, 0 }, /* 0x0b */ | |
1750 | {chm_nosuch, 0 }, /* 0x0c */ | |
1751 | {chm_nosuch, 0 }, /* 0x0d */ | |
1752 | {chm_nosuch, 0 }, /* 0x0e */ | |
1753 | {chm_nosuch, 0 }, /* 0x0f */ | |
1754 | {chm_nosuch, 0 }, /* 0x10 */ | |
1755 | {chm_nosuch, 0 }, /* 0x11 */ | |
1756 | {chm_nosuch, 0 }, /* 0x12 */ | |
1757 | {chm_nosuch, 0 }, /* 0x13 */ | |
1758 | {chm_nosuch, 0 }, /* 0x14 */ | |
1759 | {chm_nosuch, 0 }, /* 0x15 */ | |
1760 | {chm_nosuch, 0 }, /* 0x16 */ | |
1761 | {chm_nosuch, 0 }, /* 0x17 */ | |
1762 | {chm_nosuch, 0 }, /* 0x18 */ | |
1763 | {chm_nosuch, 0 }, /* 0x19 */ | |
1764 | {chm_nosuch, 0 }, /* 0x1a */ | |
1765 | {chm_nosuch, 0 }, /* 0x1b */ | |
1766 | {chm_nosuch, 0 }, /* 0x1c */ | |
1767 | {chm_nosuch, 0 }, /* 0x1d */ | |
1768 | {chm_nosuch, 0 }, /* 0x1e */ | |
1769 | {chm_nosuch, 0 }, /* 0x1f */ | |
1770 | {chm_nosuch, 0 }, /* 0x20 */ | |
1771 | {chm_nosuch, 0 }, /* 0x21 */ | |
1772 | {chm_nosuch, 0 }, /* 0x22 */ | |
1773 | {chm_nosuch, 0 }, /* 0x23 */ | |
1774 | {chm_nosuch, 0 }, /* 0x24 */ | |
1775 | {chm_nosuch, 0 }, /* 0x25 */ | |
1776 | {chm_nosuch, 0 }, /* 0x26 */ | |
1777 | {chm_nosuch, 0 }, /* 0x27 */ | |
1778 | {chm_nosuch, 0 }, /* 0x28 */ | |
1779 | {chm_nosuch, 0 }, /* 0x29 */ | |
1780 | {chm_nosuch, 0 }, /* 0x2a */ | |
1781 | {chm_nosuch, 0 }, /* 0x2b */ | |
1782 | {chm_nosuch, 0 }, /* 0x2c */ | |
1783 | {chm_nosuch, 0 }, /* 0x2d */ | |
1784 | {chm_nosuch, 0 }, /* 0x2e */ | |
1785 | {chm_nosuch, 0 }, /* 0x2f */ | |
1786 | {chm_nosuch, 0 }, /* 0x30 */ | |
1787 | {chm_nosuch, 0 }, /* 0x31 */ | |
1788 | {chm_nosuch, 0 }, /* 0x32 */ | |
1789 | {chm_nosuch, 0 }, /* 0x33 */ | |
1790 | {chm_nosuch, 0 }, /* 0x34 */ | |
1791 | {chm_nosuch, 0 }, /* 0x35 */ | |
1792 | {chm_nosuch, 0 }, /* 0x36 */ | |
1793 | {chm_nosuch, 0 }, /* 0x37 */ | |
1794 | {chm_nosuch, 0 }, /* 0x38 */ | |
1795 | {chm_nosuch, 0 }, /* 0x39 */ | |
1796 | {chm_nosuch, 0 }, /* 0x3a */ | |
1797 | {chm_nosuch, 0 }, /* 0x3b */ | |
1798 | {chm_nosuch, 0 }, /* 0x3c */ | |
1799 | {chm_nosuch, 0 }, /* 0x3d */ | |
1800 | {chm_nosuch, 0 }, /* 0x3e */ | |
1801 | {chm_nosuch, 0 }, /* 0x3f */ | |
1802 | ||
1803 | {chm_nosuch, 0 }, /* @ */ | |
1804 | {chm_nosuch, 0 }, /* A */ | |
1805 | {chm_nosuch, 0 }, /* B */ | |
92a79951 | 1806 | {chm_simple, MODE_NOCTCP }, /* C */ |
7e6c9180 | 1807 | {chm_simple, MODE_NOACTION }, /* D */ |
f9e91ece | 1808 | {chm_simple, MODE_NOKICK }, /* E */ |
212380e3 | 1809 | {chm_simple, MODE_FREETARGET }, /* F */ |
2b3c7c29 | 1810 | {chm_simple, MODE_NOCAPS }, /* G */ |
212380e3 | 1811 | {chm_nosuch, 0 }, /* H */ |
1812 | {chm_ban, CHFL_INVEX }, /* I */ | |
846aa234 | 1813 | {chm_simple, MODE_NOREJOIN }, /* J */ |
23b98f3f | 1814 | {chm_simple, MODE_NOREPEAT }, /* K */ |
212380e3 | 1815 | {chm_staff, MODE_EXLIMIT }, /* L */ |
1cdd8fdf | 1816 | {chm_hidden, MODE_NOOPERKICK }, /* M */ |
afd4834b | 1817 | {chm_simple, MODE_NONICK }, /* N */ |
212380e3 | 1818 | {chm_nosuch, 0 }, /* O */ |
1819 | {chm_staff, MODE_PERMANENT }, /* P */ | |
1820 | {chm_simple, MODE_DISFORWARD }, /* Q */ | |
1821 | {chm_nosuch, 0 }, /* R */ | |
1822 | {chm_nosuch, 0 }, /* S */ | |
6afd4b91 | 1823 | {chm_simple, MODE_NONOTICE }, /* T */ |
212380e3 | 1824 | {chm_nosuch, 0 }, /* U */ |
1825 | {chm_nosuch, 0 }, /* V */ | |
1826 | {chm_nosuch, 0 }, /* W */ | |
1827 | {chm_nosuch, 0 }, /* X */ | |
1828 | {chm_nosuch, 0 }, /* Y */ | |
1829 | {chm_nosuch, 0 }, /* Z */ | |
1830 | {chm_nosuch, 0 }, | |
1831 | {chm_nosuch, 0 }, | |
1832 | {chm_nosuch, 0 }, | |
1833 | {chm_nosuch, 0 }, | |
1834 | {chm_nosuch, 0 }, | |
1835 | {chm_nosuch, 0 }, | |
82f8e812 | 1836 | {chm_owner, 0 }, /* a */ |
212380e3 | 1837 | {chm_ban, CHFL_BAN }, /* b */ |
1838 | {chm_simple, MODE_NOCOLOR }, /* c */ | |
1839 | {chm_nosuch, 0 }, /* d */ | |
1840 | {chm_ban, CHFL_EXCEPTION }, /* e */ | |
1841 | {chm_forward, 0 }, /* f */ | |
1842 | {chm_simple, MODE_FREEINVITE }, /* g */ | |
82f8e812 | 1843 | {chm_halfop, 0 }, /* h */ |
212380e3 | 1844 | {chm_simple, MODE_INVITEONLY }, /* i */ |
1845 | {chm_throttle, 0 }, /* j */ | |
1846 | {chm_key, 0 }, /* k */ | |
1847 | {chm_limit, 0 }, /* l */ | |
1848 | {chm_simple, MODE_MODERATED }, /* m */ | |
1849 | {chm_simple, MODE_NOPRIVMSGS }, /* n */ | |
1850 | {chm_op, 0 }, /* o */ | |
1851 | {chm_simple, MODE_PRIVATE }, /* p */ | |
1852 | {chm_ban, CHFL_QUIET }, /* q */ | |
040c4408 | 1853 | {chm_regonly, MODE_REGONLY }, /* r */ |
212380e3 | 1854 | {chm_simple, MODE_SECRET }, /* s */ |
1855 | {chm_simple, MODE_TOPICLIMIT }, /* t */ | |
1856 | {chm_nosuch, 0 }, /* u */ | |
1857 | {chm_voice, 0 }, /* v */ | |
1858 | {chm_nosuch, 0 }, /* w */ | |
1859 | {chm_nosuch, 0 }, /* x */ | |
1860 | {chm_nosuch, 0 }, /* y */ | |
1861 | {chm_simple, MODE_OPMODERATE }, /* z */ | |
1862 | ||
1863 | {chm_nosuch, 0 }, /* 0x7b */ | |
1864 | {chm_nosuch, 0 }, /* 0x7c */ | |
1865 | {chm_nosuch, 0 }, /* 0x7d */ | |
1866 | {chm_nosuch, 0 }, /* 0x7e */ | |
1867 | {chm_nosuch, 0 }, /* 0x7f */ | |
1868 | ||
1869 | {chm_nosuch, 0 }, /* 0x80 */ | |
1870 | {chm_nosuch, 0 }, /* 0x81 */ | |
1871 | {chm_nosuch, 0 }, /* 0x82 */ | |
1872 | {chm_nosuch, 0 }, /* 0x83 */ | |
1873 | {chm_nosuch, 0 }, /* 0x84 */ | |
1874 | {chm_nosuch, 0 }, /* 0x85 */ | |
1875 | {chm_nosuch, 0 }, /* 0x86 */ | |
1876 | {chm_nosuch, 0 }, /* 0x87 */ | |
1877 | {chm_nosuch, 0 }, /* 0x88 */ | |
1878 | {chm_nosuch, 0 }, /* 0x89 */ | |
1879 | {chm_nosuch, 0 }, /* 0x8a */ | |
1880 | {chm_nosuch, 0 }, /* 0x8b */ | |
1881 | {chm_nosuch, 0 }, /* 0x8c */ | |
1882 | {chm_nosuch, 0 }, /* 0x8d */ | |
1883 | {chm_nosuch, 0 }, /* 0x8e */ | |
1884 | {chm_nosuch, 0 }, /* 0x8f */ | |
1885 | ||
1886 | {chm_nosuch, 0 }, /* 0x90 */ | |
1887 | {chm_nosuch, 0 }, /* 0x91 */ | |
1888 | {chm_nosuch, 0 }, /* 0x92 */ | |
1889 | {chm_nosuch, 0 }, /* 0x93 */ | |
1890 | {chm_nosuch, 0 }, /* 0x94 */ | |
1891 | {chm_nosuch, 0 }, /* 0x95 */ | |
1892 | {chm_nosuch, 0 }, /* 0x96 */ | |
1893 | {chm_nosuch, 0 }, /* 0x97 */ | |
1894 | {chm_nosuch, 0 }, /* 0x98 */ | |
1895 | {chm_nosuch, 0 }, /* 0x99 */ | |
1896 | {chm_nosuch, 0 }, /* 0x9a */ | |
1897 | {chm_nosuch, 0 }, /* 0x9b */ | |
1898 | {chm_nosuch, 0 }, /* 0x9c */ | |
1899 | {chm_nosuch, 0 }, /* 0x9d */ | |
1900 | {chm_nosuch, 0 }, /* 0x9e */ | |
1901 | {chm_nosuch, 0 }, /* 0x9f */ | |
1902 | ||
1903 | {chm_nosuch, 0 }, /* 0xa0 */ | |
1904 | {chm_nosuch, 0 }, /* 0xa1 */ | |
1905 | {chm_nosuch, 0 }, /* 0xa2 */ | |
1906 | {chm_nosuch, 0 }, /* 0xa3 */ | |
1907 | {chm_nosuch, 0 }, /* 0xa4 */ | |
1908 | {chm_nosuch, 0 }, /* 0xa5 */ | |
1909 | {chm_nosuch, 0 }, /* 0xa6 */ | |
1910 | {chm_nosuch, 0 }, /* 0xa7 */ | |
1911 | {chm_nosuch, 0 }, /* 0xa8 */ | |
1912 | {chm_nosuch, 0 }, /* 0xa9 */ | |
1913 | {chm_nosuch, 0 }, /* 0xaa */ | |
1914 | {chm_nosuch, 0 }, /* 0xab */ | |
1915 | {chm_nosuch, 0 }, /* 0xac */ | |
1916 | {chm_nosuch, 0 }, /* 0xad */ | |
1917 | {chm_nosuch, 0 }, /* 0xae */ | |
1918 | {chm_nosuch, 0 }, /* 0xaf */ | |
1919 | ||
1920 | {chm_nosuch, 0 }, /* 0xb0 */ | |
1921 | {chm_nosuch, 0 }, /* 0xb1 */ | |
1922 | {chm_nosuch, 0 }, /* 0xb2 */ | |
1923 | {chm_nosuch, 0 }, /* 0xb3 */ | |
1924 | {chm_nosuch, 0 }, /* 0xb4 */ | |
1925 | {chm_nosuch, 0 }, /* 0xb5 */ | |
1926 | {chm_nosuch, 0 }, /* 0xb6 */ | |
1927 | {chm_nosuch, 0 }, /* 0xb7 */ | |
1928 | {chm_nosuch, 0 }, /* 0xb8 */ | |
1929 | {chm_nosuch, 0 }, /* 0xb9 */ | |
1930 | {chm_nosuch, 0 }, /* 0xba */ | |
1931 | {chm_nosuch, 0 }, /* 0xbb */ | |
1932 | {chm_nosuch, 0 }, /* 0xbc */ | |
1933 | {chm_nosuch, 0 }, /* 0xbd */ | |
1934 | {chm_nosuch, 0 }, /* 0xbe */ | |
1935 | {chm_nosuch, 0 }, /* 0xbf */ | |
1936 | ||
1937 | {chm_nosuch, 0 }, /* 0xc0 */ | |
1938 | {chm_nosuch, 0 }, /* 0xc1 */ | |
1939 | {chm_nosuch, 0 }, /* 0xc2 */ | |
1940 | {chm_nosuch, 0 }, /* 0xc3 */ | |
1941 | {chm_nosuch, 0 }, /* 0xc4 */ | |
1942 | {chm_nosuch, 0 }, /* 0xc5 */ | |
1943 | {chm_nosuch, 0 }, /* 0xc6 */ | |
1944 | {chm_nosuch, 0 }, /* 0xc7 */ | |
1945 | {chm_nosuch, 0 }, /* 0xc8 */ | |
1946 | {chm_nosuch, 0 }, /* 0xc9 */ | |
1947 | {chm_nosuch, 0 }, /* 0xca */ | |
1948 | {chm_nosuch, 0 }, /* 0xcb */ | |
1949 | {chm_nosuch, 0 }, /* 0xcc */ | |
1950 | {chm_nosuch, 0 }, /* 0xcd */ | |
1951 | {chm_nosuch, 0 }, /* 0xce */ | |
1952 | {chm_nosuch, 0 }, /* 0xcf */ | |
1953 | ||
1954 | {chm_nosuch, 0 }, /* 0xd0 */ | |
1955 | {chm_nosuch, 0 }, /* 0xd1 */ | |
1956 | {chm_nosuch, 0 }, /* 0xd2 */ | |
1957 | {chm_nosuch, 0 }, /* 0xd3 */ | |
1958 | {chm_nosuch, 0 }, /* 0xd4 */ | |
1959 | {chm_nosuch, 0 }, /* 0xd5 */ | |
1960 | {chm_nosuch, 0 }, /* 0xd6 */ | |
1961 | {chm_nosuch, 0 }, /* 0xd7 */ | |
1962 | {chm_nosuch, 0 }, /* 0xd8 */ | |
1963 | {chm_nosuch, 0 }, /* 0xd9 */ | |
1964 | {chm_nosuch, 0 }, /* 0xda */ | |
1965 | {chm_nosuch, 0 }, /* 0xdb */ | |
1966 | {chm_nosuch, 0 }, /* 0xdc */ | |
1967 | {chm_nosuch, 0 }, /* 0xdd */ | |
1968 | {chm_nosuch, 0 }, /* 0xde */ | |
1969 | {chm_nosuch, 0 }, /* 0xdf */ | |
1970 | ||
1971 | {chm_nosuch, 0 }, /* 0xe0 */ | |
1972 | {chm_nosuch, 0 }, /* 0xe1 */ | |
1973 | {chm_nosuch, 0 }, /* 0xe2 */ | |
1974 | {chm_nosuch, 0 }, /* 0xe3 */ | |
1975 | {chm_nosuch, 0 }, /* 0xe4 */ | |
1976 | {chm_nosuch, 0 }, /* 0xe5 */ | |
1977 | {chm_nosuch, 0 }, /* 0xe6 */ | |
1978 | {chm_nosuch, 0 }, /* 0xe7 */ | |
1979 | {chm_nosuch, 0 }, /* 0xe8 */ | |
1980 | {chm_nosuch, 0 }, /* 0xe9 */ | |
1981 | {chm_nosuch, 0 }, /* 0xea */ | |
1982 | {chm_nosuch, 0 }, /* 0xeb */ | |
1983 | {chm_nosuch, 0 }, /* 0xec */ | |
1984 | {chm_nosuch, 0 }, /* 0xed */ | |
1985 | {chm_nosuch, 0 }, /* 0xee */ | |
1986 | {chm_nosuch, 0 }, /* 0xef */ | |
1987 | ||
1988 | {chm_nosuch, 0 }, /* 0xf0 */ | |
1989 | {chm_nosuch, 0 }, /* 0xf1 */ | |
1990 | {chm_nosuch, 0 }, /* 0xf2 */ | |
1991 | {chm_nosuch, 0 }, /* 0xf3 */ | |
1992 | {chm_nosuch, 0 }, /* 0xf4 */ | |
1993 | {chm_nosuch, 0 }, /* 0xf5 */ | |
1994 | {chm_nosuch, 0 }, /* 0xf6 */ | |
1995 | {chm_nosuch, 0 }, /* 0xf7 */ | |
1996 | {chm_nosuch, 0 }, /* 0xf8 */ | |
1997 | {chm_nosuch, 0 }, /* 0xf9 */ | |
1998 | {chm_nosuch, 0 }, /* 0xfa */ | |
1999 | {chm_nosuch, 0 }, /* 0xfb */ | |
2000 | {chm_nosuch, 0 }, /* 0xfc */ | |
2001 | {chm_nosuch, 0 }, /* 0xfd */ | |
2002 | {chm_nosuch, 0 }, /* 0xfe */ | |
2003 | {chm_nosuch, 0 }, /* 0xff */ | |
2004 | }; | |
2005 | ||
2006 | /* *INDENT-ON* */ | |
2007 | ||
2008 | /* set_channel_mode() | |
2009 | * | |
2010 | * inputs - client, source, channel, membership pointer, params | |
2011 | * output - | |
2012 | * side effects - channel modes/memberships are changed, MODE is issued | |
2013 | * | |
2014 | * Extensively modified to be hotpluggable, 03/09/06 -- nenolod | |
2015 | */ | |
2016 | void | |
2017 | set_channel_mode(struct Client *client_p, struct Client *source_p, | |
2018 | struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) | |
2019 | { | |
eccd1c58 | 2020 | static char cmdbuf[BUFSIZE]; |
212380e3 | 2021 | static char modebuf[BUFSIZE]; |
2022 | static char parabuf[BUFSIZE]; | |
2023 | char *mbuf; | |
2024 | char *pbuf; | |
2025 | int cur_len, mlen, paralen, paracount, arglen, len; | |
eccd1c58 | 2026 | int i, j, flags, override; |
212380e3 | 2027 | int dir = MODE_ADD; |
2028 | int parn = 1; | |
2029 | int errors = 0; | |
2030 | int alevel; | |
2031 | const char *ml = parv[0]; | |
2032 | char c; | |
2033 | struct Client *fakesource_p; | |
1cdd8fdf | 2034 | int flags_list[3] = { ALL_MEMBERS, ONLY_CHANOPS, ONLY_OPERS }; |
212380e3 | 2035 | |
2036 | mask_pos = 0; | |
2037 | mode_count = 0; | |
2038 | mode_limit = 0; | |
c08f4515 | 2039 | mode_limit_simple = 0; |
212380e3 | 2040 | |
2041 | alevel = get_channel_access(source_p, msptr); | |
2042 | ||
b869e117 JH |
2043 | no_override_deop = 0; |
2044 | ||
212380e3 | 2045 | /* Hide connecting server on netburst -- jilles */ |
2046 | if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) | |
2047 | fakesource_p = &me; | |
2048 | else | |
2049 | fakesource_p = source_p; | |
2050 | ||
2051 | for(; (c = *ml) != 0; ml++) | |
2052 | { | |
2053 | switch (c) | |
2054 | { | |
2055 | case '+': | |
2056 | dir = MODE_ADD; | |
2057 | break; | |
2058 | case '-': | |
2059 | dir = MODE_DEL; | |
2060 | break; | |
2061 | case '=': | |
2062 | dir = MODE_QUERY; | |
2063 | break; | |
2064 | default: | |
2065 | chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, | |
2066 | parc, &parn, parv, | |
2067 | &errors, dir, c, | |
2068 | chmode_table[(unsigned char) c].mode_type); | |
2069 | break; | |
2070 | } | |
2071 | } | |
2072 | ||
2073 | /* bail out if we have nothing to do... */ | |
2074 | if(!mode_count) | |
2075 | return; | |
2076 | ||
2077 | if(IsServer(source_p)) | |
eccd1c58 | 2078 | rb_sprintf(cmdbuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); |
212380e3 | 2079 | else |
eccd1c58 | 2080 | rb_sprintf(cmdbuf, ":%s!%s@%s MODE %s ", |
212380e3 | 2081 | source_p->name, source_p->username, |
2082 | source_p->host, chptr->chname); | |
2083 | ||
e853274c JH |
2084 | mlen = 0; |
2085 | ||
cb097b88 | 2086 | for (override = 0; override < (IsOverride(source_p) && alevel != CHFL_CHANOP ? 2 : 1); ++override) |
212380e3 | 2087 | { |
eccd1c58 | 2088 | int was_on_chan = 0; |
b869e117 | 2089 | |
eccd1c58 | 2090 | if(override) |
212380e3 | 2091 | { |
eccd1c58 | 2092 | if(msptr) |
b869e117 | 2093 | { |
eccd1c58 | 2094 | was_on_chan = 1; |
b869e117 JH |
2095 | msptr->flags |= CHFL_CHANOP; |
2096 | } | |
eccd1c58 | 2097 | else |
b869e117 | 2098 | add_user_to_channel(chptr, source_p, CHFL_CHANOP); |
eccd1c58 | 2099 | } |
212380e3 | 2100 | |
1cdd8fdf | 2101 | for(j = 0, flags = flags_list[0]; j < 3; j++, flags = flags_list[j]) |
eccd1c58 JH |
2102 | { |
2103 | cur_len = mlen; | |
2104 | mbuf = modebuf + mlen; | |
2105 | pbuf = parabuf; | |
2106 | parabuf[0] = '\0'; | |
2107 | paracount = paralen = 0; | |
2108 | dir = MODE_QUERY; | |
212380e3 | 2109 | |
eccd1c58 | 2110 | for(i = 0; i < mode_count; i++) |
212380e3 | 2111 | { |
eccd1c58 | 2112 | if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) |
2f39232f | 2113 | continue; |
212380e3 | 2114 | |
eccd1c58 | 2115 | if(mode_changes[i].override != override) |
212380e3 | 2116 | continue; |
2117 | ||
eccd1c58 JH |
2118 | if(mode_changes[i].arg != NULL) |
2119 | { | |
2120 | arglen = strlen(mode_changes[i].arg); | |
212380e3 | 2121 | |
eccd1c58 JH |
2122 | if(arglen > MODEBUFLEN - 5) |
2123 | continue; | |
2124 | } | |
2125 | else | |
2126 | arglen = 0; | |
2127 | ||
2128 | /* if we're creeping over MAXMODEPARAMSSERV, or over | |
2129 | * bufsize (4 == +/-,modechar,two spaces) send now. | |
2130 | */ | |
2131 | if(mode_changes[i].arg != NULL && | |
2f39232f G |
2132 | ((paracount == MAXMODEPARAMSSERV) || |
2133 | ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) | |
eccd1c58 JH |
2134 | { |
2135 | *mbuf = '\0'; | |
2136 | ||
2137 | if(cur_len > mlen) | |
2138 | { | |
2139 | sendto_channel_local(flags, chptr, "%s%s %s", | |
2f39232f | 2140 | cmdbuf, modebuf, parabuf); |
eccd1c58 JH |
2141 | if(override) |
2142 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
2143 | "%s is overriding modes on %s: %s %s", | |
2144 | get_oper_name(source_p), chptr->chname, | |
2145 | modebuf, parabuf); | |
2146 | } | |
2147 | else | |
2148 | continue; | |
2149 | ||
2150 | paracount = paralen = 0; | |
2151 | cur_len = mlen; | |
2152 | mbuf = modebuf + mlen; | |
2153 | pbuf = parabuf; | |
2154 | parabuf[0] = '\0'; | |
2155 | dir = MODE_QUERY; | |
2156 | } | |
2157 | ||
2158 | if(dir != mode_changes[i].dir) | |
2159 | { | |
2160 | *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
2161 | cur_len++; | |
2162 | dir = mode_changes[i].dir; | |
2163 | } | |
2164 | ||
2165 | *mbuf++ = mode_changes[i].letter; | |
212380e3 | 2166 | cur_len++; |
212380e3 | 2167 | |
eccd1c58 JH |
2168 | if(mode_changes[i].arg != NULL) |
2169 | { | |
2170 | paracount++; | |
2171 | len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg); | |
2172 | pbuf += len; | |
2173 | paralen += len; | |
2174 | } | |
212380e3 | 2175 | } |
212380e3 | 2176 | |
3da167f2 JH |
2177 | if(paralen && parabuf[paralen - 1] == ' ') |
2178 | parabuf[paralen - 1] = '\0'; | |
2179 | ||
2180 | *mbuf = '\0'; | |
2181 | if(cur_len > mlen) | |
b869e117 | 2182 | { |
3da167f2 JH |
2183 | sendto_channel_local(flags, chptr, "%s%s %s", cmdbuf, modebuf, parabuf); |
2184 | if(override) | |
2185 | sendto_realops_snomask(SNO_GENERAL, L_NETWIDE, | |
2186 | "%s is overriding modes on %s: %s %s", | |
2187 | get_oper_name(source_p), chptr->chname, | |
2188 | modebuf, parabuf); | |
b869e117 | 2189 | } |
3da167f2 JH |
2190 | } |
2191 | if(override) | |
2192 | { | |
2193 | if(!was_on_chan) | |
2194 | remove_user_from_channel(find_channel_membership(chptr, source_p)); | |
2195 | else if (!no_override_deop) | |
2196 | msptr->flags &= ~CHFL_CHANOP; | |
2197 | } | |
212380e3 | 2198 | } |
2f39232f | 2199 | |
212380e3 | 2200 | /* only propagate modes originating locally, or if we're hubbing */ |
af81d5a0 | 2201 | if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) |
212380e3 | 2202 | send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); |
2203 | } |