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