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