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