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