]>
Commit | Line | Data |
---|---|---|
25ea5d2f EM |
1 | /* |
2 | * charybdis: A slightly useful ircd. | |
3 | * chmode.c: channel mode management | |
4 | * | |
55abcbb2 KB |
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 | |
25ea5d2f EM |
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" | |
77d3d2db | 45 | #include "s_assert.h" |
25ea5d2f EM |
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]; | |
acdf71d9 | 75 | |
749d8c11 AC |
76 | extern int h_get_channel_access; |
77 | ||
9bec26cc | 78 | /* OPTIMIZE ME! -- dwr */ |
efccc22c | 79 | void |
19716b9f | 80 | construct_cflags_strings(void) |
efccc22c VY |
81 | { |
82 | int i; | |
c18cb68b VY |
83 | char *ptr = cflagsbuf; |
84 | char *ptr2 = cflagsmyinfo; | |
55abcbb2 | 85 | |
c18cb68b VY |
86 | *ptr = '\0'; |
87 | *ptr2 = '\0'; | |
efccc22c VY |
88 | |
89 | for(i = 0; i < 256; i++) | |
90 | { | |
55abcbb2 | 91 | if( !(chmode_table[i].set_func == chm_ban) && |
f588b956 VY |
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)) | |
efccc22c VY |
98 | { |
99 | chmode_flags[i] = chmode_table[i].mode_type; | |
100 | } | |
101 | else | |
102 | { | |
103 | chmode_flags[i] = 0; | |
104 | } | |
55abcbb2 | 105 | |
c18cb68b VY |
106 | switch (chmode_flags[i]) |
107 | { | |
c55b2782 | 108 | case MODE_FREETARGET: |
73d0f900 | 109 | case MODE_DISFORWARD: |
2da6f6eb JT |
110 | if(ConfigChannel.use_forward) |
111 | *ptr++ = (char) i; | |
112 | break; | |
c18cb68b VY |
113 | default: |
114 | if(chmode_flags[i] != 0) | |
115 | { | |
116 | *ptr++ = (char) i; | |
117 | } | |
118 | } | |
55abcbb2 | 119 | |
c18cb68b VY |
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 | } | |
efccc22c | 125 | } |
55abcbb2 | 126 | |
c18cb68b VY |
127 | *ptr++ = '\0'; |
128 | *ptr2++ = '\0'; | |
46d59e11 VY |
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 | */ | |
19716b9f | 139 | static unsigned int |
46d59e11 VY |
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; | |
efccc22c VY |
151 | } |
152 | ||
19716b9f JT |
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 | ||
3c52f289 | 181 | int |
7eec45bc | 182 | get_channel_access(struct Client *source_p, struct membership *msptr) |
212380e3 | 183 | { |
749d8c11 AC |
184 | hook_data_channel_approval moduledata; |
185 | ||
186 | if(!MyClient(source_p)) | |
212380e3 AC |
187 | return CHFL_CHANOP; |
188 | ||
96d26127 AC |
189 | if (msptr == NULL) |
190 | return CHFL_PEON; | |
191 | ||
749d8c11 AC |
192 | moduledata.client = source_p; |
193 | moduledata.chptr = msptr->chptr; | |
194 | moduledata.msptr = msptr; | |
195 | moduledata.target = NULL; | |
7eec45bc | 196 | moduledata.approved = is_chanop(msptr) ? CHFL_CHANOP : CHFL_PEON; |
8aabb973 | 197 | |
749d8c11 AC |
198 | call_hook(h_get_channel_access, &moduledata); |
199 | ||
200 | return moduledata.approved; | |
212380e3 AC |
201 | } |
202 | ||
f3b3ad0b JT |
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 | ||
212380e3 AC |
239 | /* add_id() |
240 | * | |
765d839d | 241 | * inputs - client, channel, id to add, type, forward |
212380e3 AC |
242 | * outputs - 0 on failure, 1 on success |
243 | * side effects - given id is added to the appropriate list | |
244 | */ | |
245 | int | |
765d839d | 246 | add_id(struct Client *source_p, struct Channel *chptr, const char *banid, const char *forward, |
330fc5c1 | 247 | rb_dlink_list * list, long mode_type) |
212380e3 AC |
248 | { |
249 | struct Ban *actualBan; | |
83294285 | 250 | static char who[USERHOST_REPLYLEN]; |
212380e3 | 251 | char *realban = LOCAL_COPY(banid); |
330fc5c1 | 252 | rb_dlink_node *ptr; |
212380e3 AC |
253 | |
254 | /* dont let local clients overflow the banlist, or set redundant | |
255 | * bans | |
256 | */ | |
257 | if(MyClient(source_p)) | |
258 | { | |
330fc5c1 | 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)) >= (chptr->mode.mode & MODE_EXLIMIT ? ConfigChannel.max_bans_large : ConfigChannel.max_bans)) |
212380e3 AC |
260 | { |
261 | sendto_one(source_p, form_str(ERR_BANLISTFULL), | |
262 | me.name, source_p->name, chptr->chname, realban); | |
263 | return 0; | |
264 | } | |
265 | ||
5cefa1d6 | 266 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
267 | { |
268 | actualBan = ptr->data; | |
fd488ac1 | 269 | if(mask_match(actualBan->banstr, realban)) |
212380e3 AC |
270 | return 0; |
271 | } | |
272 | } | |
273 | /* dont let remotes set duplicates */ | |
274 | else | |
275 | { | |
5cefa1d6 | 276 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
277 | { |
278 | actualBan = ptr->data; | |
279 | if(!irccmp(actualBan->banstr, realban)) | |
280 | return 0; | |
281 | } | |
282 | } | |
283 | ||
284 | ||
285 | if(IsPerson(source_p)) | |
b2f0da88 | 286 | rb_sprintf(who, "%s!%s@%s", source_p->name, source_p->username, source_p->host); |
212380e3 | 287 | else |
f427c8b0 | 288 | rb_strlcpy(who, source_p->name, sizeof(who)); |
212380e3 | 289 | |
765d839d | 290 | actualBan = allocate_ban(realban, who, forward); |
e3354945 | 291 | actualBan->when = rb_current_time(); |
212380e3 | 292 | |
330fc5c1 | 293 | rb_dlinkAdd(actualBan, &actualBan->node, list); |
212380e3 AC |
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 | |
765d839d EM |
305 | * outputs - pointer to ban that was removed, if any |
306 | * side effects - given id is removed from the appropriate list and returned | |
212380e3 | 307 | */ |
765d839d | 308 | struct Ban * |
330fc5c1 | 309 | del_id(struct Channel *chptr, const char *banid, rb_dlink_list * list, long mode_type) |
212380e3 | 310 | { |
330fc5c1 | 311 | rb_dlink_node *ptr; |
212380e3 AC |
312 | struct Ban *banptr; |
313 | ||
314 | if(EmptyString(banid)) | |
765d839d | 315 | return NULL; |
212380e3 | 316 | |
5cefa1d6 | 317 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 AC |
318 | { |
319 | banptr = ptr->data; | |
320 | ||
321 | if(irccmp(banid, banptr->banstr) == 0) | |
322 | { | |
330fc5c1 | 323 | rb_dlinkDelete(&banptr->node, list); |
212380e3 AC |
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 | ||
765d839d | 329 | return banptr; |
212380e3 AC |
330 | } |
331 | } | |
332 | ||
765d839d | 333 | return NULL; |
212380e3 AC |
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; | |
f4e893b5 | 377 | const char *nick, *user, *host, *forward = NULL; |
74b2fb72 | 378 | char *t, *at, *ex; |
f4e893b5 | 379 | int nl, ul, hl, fl; |
212380e3 | 380 | char *mask; |
74b2fb72 | 381 | size_t masklen; |
212380e3 AC |
382 | |
383 | mask = LOCAL_COPY(idmask); | |
384 | mask = check_string(mask); | |
385 | collapse(mask); | |
74b2fb72 | 386 | masklen = strlen(mask); |
212380e3 | 387 | |
f4e893b5 | 388 | nick = user = host = "*"; |
74b2fb72 JT |
389 | nl = ul = hl = 1; |
390 | fl = 0; | |
212380e3 | 391 | |
74b2fb72 | 392 | if((size_t) BUFSIZE - mask_pos < masklen + 5) |
212380e3 AC |
393 | return NULL; |
394 | ||
395 | old_mask_pos = mask_pos; | |
396 | ||
397 | if (*mask == '$') | |
398 | { | |
74b2fb72 JT |
399 | memcpy(mask_buf + mask_pos, mask, masklen + 1); |
400 | mask_pos += masklen + 1; | |
212380e3 AC |
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 | ||
74b2fb72 JT |
410 | at = ex = NULL; |
411 | if((t = memchr(mask, '@', masklen)) != NULL) | |
212380e3 AC |
412 | { |
413 | at = t; | |
74b2fb72 | 414 | t++; |
212380e3 | 415 | if(*t != '\0') |
74b2fb72 | 416 | host = t, hl = strlen(t); |
212380e3 | 417 | |
74b2fb72 | 418 | if((t = memchr(mask, '!', at - mask)) != NULL) |
212380e3 AC |
419 | { |
420 | ex = t; | |
74b2fb72 JT |
421 | t++; |
422 | if(at != t) | |
423 | user = t, ul = at - t; | |
424 | if(ex != mask) | |
425 | nick = mask, nl = ex - mask; | |
212380e3 AC |
426 | } |
427 | else | |
428 | { | |
74b2fb72 JT |
429 | if(at != mask) |
430 | user = mask, ul = at - mask; | |
212380e3 | 431 | } |
765d839d | 432 | |
74b2fb72 JT |
433 | if((t = memchr(host, '!', hl)) != NULL || |
434 | (t = memchr(host, '$', hl)) != NULL) | |
765d839d | 435 | { |
74b2fb72 JT |
436 | t++; |
437 | if (host + hl != t) | |
438 | forward = t, fl = host + hl - t; | |
439 | hl = t - 1 - host; | |
765d839d | 440 | } |
212380e3 | 441 | } |
74b2fb72 | 442 | else if((t = memchr(mask, '!', masklen)) != NULL) |
212380e3 AC |
443 | { |
444 | ex = t; | |
74b2fb72 JT |
445 | t++; |
446 | if(ex != mask) | |
447 | nick = mask, nl = ex - mask; | |
212380e3 | 448 | if(*t != '\0') |
74b2fb72 | 449 | user = t, ul = strlen(t); |
212380e3 | 450 | } |
74b2fb72 JT |
451 | else if(memchr(mask, '.', masklen) != NULL || |
452 | memchr(mask, ':', masklen) != NULL) | |
212380e3 | 453 | { |
74b2fb72 | 454 | host = mask, hl = masklen; |
212380e3 AC |
455 | } |
456 | else | |
457 | { | |
74b2fb72 JT |
458 | if(masklen > 0) |
459 | nick = mask, nl = masklen; | |
212380e3 AC |
460 | } |
461 | ||
462 | /* truncate values to max lengths */ | |
f4e893b5 JT |
463 | if(nl > NICKLEN - 1) |
464 | nl = NICKLEN - 1; | |
f4e893b5 JT |
465 | if(ul > USERLEN) |
466 | ul = USERLEN; | |
f4e893b5 JT |
467 | if(hl > HOSTLEN) |
468 | hl = HOSTLEN; | |
f4e893b5 JT |
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; | |
212380e3 | 480 | } |
f4e893b5 | 481 | mask_buf[mask_pos++] = '\0'; |
212380e3 | 482 | |
212380e3 AC |
483 | return mask_buf + old_mask_pos; |
484 | } | |
485 | ||
0c730321 JT |
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, msptr) != 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 | ||
212380e3 AC |
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 | { | |
f3b3ad0b | 597 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 598 | return; |
212380e3 | 599 | |
84c9a8c7 | 600 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
212380e3 AC |
601 | return; |
602 | ||
603 | /* setting + */ | |
78e6b731 | 604 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) |
212380e3 | 605 | { |
2da6f6eb JT |
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 | ||
212380e3 AC |
611 | chptr->mode.mode |= mode_type; |
612 | ||
613 | mode_changes[mode_count].letter = c; | |
614 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
615 | mode_changes[mode_count].id = NULL; |
616 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
cbed45a2 VY |
617 | mode_changes[mode_count++].arg = NULL; |
618 | } | |
78e6b731 | 619 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) |
cbed45a2 VY |
620 | { |
621 | chptr->mode.mode &= ~mode_type; | |
622 | ||
623 | mode_changes[mode_count].letter = c; | |
624 | mode_changes[mode_count].dir = MODE_DEL; | |
cbed45a2 VY |
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; | |
55abcbb2 | 638 | |
cbed45a2 VY |
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; | |
cbed45a2 VY |
645 | mode_changes[mode_count].id = NULL; |
646 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
212380e3 AC |
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; | |
212380e3 AC |
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_staff(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 | } | |
1ef5b430 JT |
673 | if(MyClient(source_p) && !IsOperResv(source_p)) |
674 | { | |
675 | if(!(*errors & SM_ERR_NOPRIVS)) | |
676 | sendto_one(source_p, form_str(ERR_NOPRIVS), me.name, | |
677 | source_p->name, "resv"); | |
678 | *errors |= SM_ERR_NOPRIVS; | |
679 | return; | |
680 | } | |
212380e3 | 681 | |
aea6c4f9 JT |
682 | if(!allow_mode_change(source_p, chptr, CHFL_CHANOP, errors, c)) |
683 | return; | |
684 | ||
84c9a8c7 JT |
685 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
686 | return; | |
687 | ||
212380e3 AC |
688 | /* setting + */ |
689 | if((dir == MODE_ADD) && !(chptr->mode.mode & mode_type)) | |
690 | { | |
691 | chptr->mode.mode |= mode_type; | |
692 | ||
693 | mode_changes[mode_count].letter = c; | |
694 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
695 | mode_changes[mode_count].id = NULL; |
696 | mode_changes[mode_count].mems = ALL_MEMBERS; | |
697 | mode_changes[mode_count++].arg = NULL; | |
698 | } | |
699 | else if((dir == MODE_DEL) && (chptr->mode.mode & mode_type)) | |
700 | { | |
701 | chptr->mode.mode &= ~mode_type; | |
702 | ||
703 | mode_changes[mode_count].letter = c; | |
704 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
705 | mode_changes[mode_count].mems = ALL_MEMBERS; |
706 | mode_changes[mode_count].id = NULL; | |
707 | mode_changes[mode_count++].arg = NULL; | |
708 | } | |
709 | } | |
710 | ||
711 | void | |
712 | chm_ban(struct Client *source_p, struct Channel *chptr, | |
713 | int alevel, int parc, int *parn, | |
714 | const char **parv, int *errors, int dir, char c, long mode_type) | |
715 | { | |
cea0689e DF |
716 | const char *mask, *raw_mask; |
717 | char *forward; | |
330fc5c1 AC |
718 | rb_dlink_list *list; |
719 | rb_dlink_node *ptr; | |
212380e3 AC |
720 | struct Ban *banptr; |
721 | int errorval; | |
6f7b36d5 AC |
722 | const char *rpl_list_p; |
723 | const char *rpl_endlist_p; | |
212380e3 AC |
724 | int mems; |
725 | ||
726 | switch (mode_type) | |
727 | { | |
728 | case CHFL_BAN: | |
729 | list = &chptr->banlist; | |
730 | errorval = SM_ERR_RPL_B; | |
6f7b36d5 AC |
731 | rpl_list_p = form_str(RPL_BANLIST); |
732 | rpl_endlist_p = form_str(RPL_ENDOFBANLIST); | |
212380e3 | 733 | mems = ALL_MEMBERS; |
212380e3 AC |
734 | break; |
735 | ||
736 | case CHFL_EXCEPTION: | |
737 | /* if +e is disabled, allow all but +e locally */ | |
738 | if(!ConfigChannel.use_except && MyClient(source_p) && | |
739 | ((dir == MODE_ADD) && (parc > *parn))) | |
740 | return; | |
741 | ||
742 | list = &chptr->exceptlist; | |
743 | errorval = SM_ERR_RPL_E; | |
6f7b36d5 AC |
744 | rpl_list_p = form_str(RPL_EXCEPTLIST); |
745 | rpl_endlist_p = form_str(RPL_ENDOFEXCEPTLIST); | |
212380e3 AC |
746 | |
747 | if(ConfigChannel.use_except || (dir == MODE_DEL)) | |
748 | mems = ONLY_CHANOPS; | |
749 | else | |
750 | mems = ONLY_SERVERS; | |
751 | break; | |
752 | ||
753 | case CHFL_INVEX: | |
754 | /* if +I is disabled, allow all but +I locally */ | |
755 | if(!ConfigChannel.use_invex && MyClient(source_p) && | |
756 | (dir == MODE_ADD) && (parc > *parn)) | |
757 | return; | |
758 | ||
759 | list = &chptr->invexlist; | |
760 | errorval = SM_ERR_RPL_I; | |
6f7b36d5 AC |
761 | rpl_list_p = form_str(RPL_INVITELIST); |
762 | rpl_endlist_p = form_str(RPL_ENDOFINVITELIST); | |
212380e3 AC |
763 | |
764 | if(ConfigChannel.use_invex || (dir == MODE_DEL)) | |
765 | mems = ONLY_CHANOPS; | |
766 | else | |
767 | mems = ONLY_SERVERS; | |
768 | break; | |
769 | ||
770 | case CHFL_QUIET: | |
771 | list = &chptr->quietlist; | |
772 | errorval = SM_ERR_RPL_Q; | |
6f7b36d5 AC |
773 | rpl_list_p = form_str(RPL_QUIETLIST); |
774 | rpl_endlist_p = form_str(RPL_ENDOFQUIETLIST); | |
212380e3 | 775 | mems = ALL_MEMBERS; |
212380e3 AC |
776 | break; |
777 | ||
778 | default: | |
779 | sendto_realops_snomask(SNO_GENERAL, L_ALL, "chm_ban() called with unknown type!"); | |
780 | return; | |
781 | break; | |
782 | } | |
783 | ||
784 | if(dir == 0 || parc <= *parn) | |
785 | { | |
786 | if((*errors & errorval) != 0) | |
787 | return; | |
788 | *errors |= errorval; | |
789 | ||
790 | /* non-ops cant see +eI lists.. */ | |
f3b3ad0b | 791 | /* note that this is still permitted if +e/+I are mlocked. */ |
212380e3 AC |
792 | if(alevel != CHFL_CHANOP && mode_type != CHFL_BAN && |
793 | mode_type != CHFL_QUIET) | |
794 | { | |
795 | if(!(*errors & SM_ERR_NOOPS)) | |
796 | sendto_one(source_p, form_str(ERR_CHANOPRIVSNEEDED), | |
797 | me.name, source_p->name, chptr->chname); | |
798 | *errors |= SM_ERR_NOOPS; | |
799 | return; | |
800 | } | |
801 | ||
5cefa1d6 | 802 | RB_DLINK_FOREACH(ptr, list->head) |
212380e3 | 803 | { |
765d839d | 804 | char buf[BANLEN]; |
212380e3 | 805 | banptr = ptr->data; |
765d839d EM |
806 | if(banptr->forward) |
807 | rb_snprintf(buf, sizeof(buf), "%s$%s", banptr->banstr, banptr->forward); | |
808 | else | |
809 | rb_strlcpy(buf, banptr->banstr, sizeof(buf)); | |
810 | ||
6f7b36d5 | 811 | sendto_one(source_p, rpl_list_p, |
212380e3 | 812 | me.name, source_p->name, chptr->chname, |
765d839d | 813 | buf, banptr->who, banptr->when); |
212380e3 | 814 | } |
6f7b36d5 | 815 | sendto_one(source_p, rpl_endlist_p, me.name, source_p->name, chptr->chname); |
212380e3 AC |
816 | return; |
817 | } | |
818 | ||
f3b3ad0b | 819 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 820 | return; |
f3b3ad0b | 821 | |
212380e3 AC |
822 | |
823 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
824 | return; | |
825 | ||
826 | raw_mask = parv[(*parn)]; | |
827 | (*parn)++; | |
828 | ||
829 | /* empty ban, or starts with ':' which messes up s2s, ignore it */ | |
830 | if(EmptyString(raw_mask) || *raw_mask == ':') | |
831 | return; | |
832 | ||
833 | if(!MyClient(source_p)) | |
834 | { | |
835 | if(strchr(raw_mask, ' ')) | |
836 | return; | |
837 | ||
838 | mask = raw_mask; | |
839 | } | |
840 | else | |
841 | mask = pretty_mask(raw_mask); | |
842 | ||
1aa35c8a JT |
843 | /* we'd have problems parsing this, hyb6 does it too |
844 | * also make sure it will always fit on a line with channel | |
845 | * name etc. | |
846 | */ | |
847 | if(strlen(mask) > IRCD_MIN(BANLEN, MODEBUFLEN - 5)) | |
be0365e1 JT |
848 | { |
849 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
850 | form_str(ERR_INVALIDBAN), | |
851 | chptr->chname, c, raw_mask); | |
1aa35c8a | 852 | return; |
be0365e1 | 853 | } |
1aa35c8a | 854 | |
765d839d EM |
855 | /* Look for a $ after the first character. |
856 | * As the first character, it marks an extban; afterwards | |
857 | * it delimits a forward channel. | |
858 | */ | |
859 | if ((forward = strchr(mask+1, '$')) != NULL) | |
860 | { | |
861 | *forward++ = '\0'; | |
862 | if (*forward == '\0') | |
863 | forward = NULL; | |
864 | } | |
865 | ||
212380e3 AC |
866 | /* if we're adding a NEW id */ |
867 | if(dir == MODE_ADD) | |
868 | { | |
869 | if (*mask == '$' && MyClient(source_p)) | |
870 | { | |
871 | if (!valid_extban(mask, source_p, chptr, mode_type)) | |
be0365e1 JT |
872 | { |
873 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
874 | form_str(ERR_INVALIDBAN), | |
875 | chptr->chname, c, raw_mask); | |
212380e3 | 876 | return; |
be0365e1 | 877 | } |
212380e3 AC |
878 | } |
879 | ||
e1dc9e54 JT |
880 | /* For compatibility, only check the forward channel from |
881 | * local clients. Accept any forward channel from servers. | |
882 | */ | |
883 | if(forward != NULL && MyClient(source_p)) | |
884 | { | |
f2edb2be JT |
885 | /* For simplicity and future flexibility, do not |
886 | * allow '$' in forwarding targets. | |
887 | */ | |
be0365e1 JT |
888 | if(!ConfigChannel.use_forward || |
889 | strchr(forward, '$') != NULL) | |
890 | { | |
891 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
892 | form_str(ERR_INVALIDBAN), | |
893 | chptr->chname, c, raw_mask); | |
894 | return; | |
895 | } | |
896 | /* check_forward() sends its own error message */ | |
897 | if(!check_forward(source_p, chptr, forward)) | |
f2edb2be | 898 | return; |
5efa7ef6 JT |
899 | /* Forwards only make sense for bans. */ |
900 | if(mode_type != CHFL_BAN) | |
be0365e1 JT |
901 | { |
902 | sendto_one_numeric(source_p, ERR_INVALIDBAN, | |
903 | form_str(ERR_INVALIDBAN), | |
904 | chptr->chname, c, raw_mask); | |
5efa7ef6 | 905 | return; |
be0365e1 | 906 | } |
e1dc9e54 | 907 | } |
2da6f6eb | 908 | |
212380e3 AC |
909 | /* dont allow local clients to overflow the banlist, dont |
910 | * let remote servers set duplicate bans | |
911 | */ | |
765d839d | 912 | if(!add_id(source_p, chptr, mask, forward, list, mode_type)) |
212380e3 AC |
913 | return; |
914 | ||
765d839d EM |
915 | if(forward) |
916 | forward[-1]= '$'; | |
917 | ||
212380e3 AC |
918 | mode_changes[mode_count].letter = c; |
919 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
920 | mode_changes[mode_count].mems = mems; |
921 | mode_changes[mode_count].id = NULL; | |
922 | mode_changes[mode_count++].arg = mask; | |
923 | } | |
924 | else if(dir == MODE_DEL) | |
925 | { | |
765d839d EM |
926 | struct Ban *removed; |
927 | static char buf[BANLEN * MAXMODEPARAMS]; | |
928 | int old_removed_mask_pos = removed_mask_pos; | |
929 | if((removed = del_id(chptr, mask, list, mode_type)) == NULL) | |
212380e3 AC |
930 | { |
931 | /* mask isn't a valid ban, check raw_mask */ | |
765d839d | 932 | if((removed = del_id(chptr, raw_mask, list, mode_type)) != NULL) |
212380e3 AC |
933 | mask = raw_mask; |
934 | } | |
935 | ||
765d839d | 936 | if(removed && removed->forward) |
3e910a18 | 937 | removed_mask_pos += rb_snprintf(buf + old_removed_mask_pos, sizeof(buf), "%s$%s", removed->banstr, removed->forward) + 1; |
765d839d | 938 | else |
3e910a18 | 939 | removed_mask_pos += rb_strlcpy(buf + old_removed_mask_pos, mask, sizeof(buf)) + 1; |
765d839d EM |
940 | if(removed) |
941 | { | |
942 | free_ban(removed); | |
943 | removed = NULL; | |
944 | } | |
945 | ||
212380e3 AC |
946 | mode_changes[mode_count].letter = c; |
947 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
948 | mode_changes[mode_count].mems = mems; |
949 | mode_changes[mode_count].id = NULL; | |
765d839d | 950 | mode_changes[mode_count++].arg = buf + old_removed_mask_pos; |
212380e3 AC |
951 | } |
952 | } | |
953 | ||
954 | void | |
955 | chm_op(struct Client *source_p, struct Channel *chptr, | |
956 | int alevel, int parc, int *parn, | |
957 | const char **parv, int *errors, int dir, char c, long mode_type) | |
958 | { | |
959 | struct membership *mstptr; | |
960 | const char *opnick; | |
961 | struct Client *targ_p; | |
962 | ||
f3b3ad0b | 963 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 964 | return; |
212380e3 AC |
965 | |
966 | if((dir == MODE_QUERY) || (parc <= *parn)) | |
967 | return; | |
968 | ||
969 | opnick = parv[(*parn)]; | |
970 | (*parn)++; | |
971 | ||
972 | /* empty nick */ | |
973 | if(EmptyString(opnick)) | |
974 | { | |
975 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
976 | return; | |
977 | } | |
978 | ||
979 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
980 | { | |
981 | return; | |
982 | } | |
983 | ||
984 | mstptr = find_channel_membership(chptr, targ_p); | |
985 | ||
986 | if(mstptr == NULL) | |
987 | { | |
988 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
989 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
990 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
991 | *errors |= SM_ERR_NOTONCHANNEL; | |
992 | return; | |
993 | } | |
994 | ||
995 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
996 | return; | |
997 | ||
998 | if(dir == MODE_ADD) | |
999 | { | |
fa0e2152 JT |
1000 | if(targ_p == source_p && mstptr->flags & CHFL_CHANOP) |
1001 | return; | |
1002 | ||
212380e3 AC |
1003 | mode_changes[mode_count].letter = c; |
1004 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
1005 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1006 | mode_changes[mode_count].id = targ_p->id; | |
0f8db055 | 1007 | mode_changes[mode_count++].arg = targ_p->name; |
212380e3 AC |
1008 | |
1009 | mstptr->flags |= CHFL_CHANOP; | |
212380e3 AC |
1010 | } |
1011 | else | |
1012 | { | |
1013 | if(MyClient(source_p) && IsService(targ_p)) | |
1014 | { | |
1015 | sendto_one(source_p, form_str(ERR_ISCHANSERVICE), | |
1016 | me.name, source_p->name, targ_p->name, chptr->chname); | |
1017 | return; | |
1018 | } | |
1019 | ||
1020 | mode_changes[mode_count].letter = c; | |
1021 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1022 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1023 | mode_changes[mode_count].id = targ_p->id; | |
0f8db055 | 1024 | mode_changes[mode_count++].arg = targ_p->name; |
212380e3 AC |
1025 | |
1026 | mstptr->flags &= ~CHFL_CHANOP; | |
1027 | } | |
1028 | } | |
1029 | ||
1030 | void | |
1031 | chm_voice(struct Client *source_p, struct Channel *chptr, | |
1032 | int alevel, int parc, int *parn, | |
1033 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1034 | { | |
1035 | struct membership *mstptr; | |
1036 | const char *opnick; | |
1037 | struct Client *targ_p; | |
1038 | ||
f3b3ad0b | 1039 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 1040 | return; |
212380e3 AC |
1041 | |
1042 | if((dir == MODE_QUERY) || parc <= *parn) | |
1043 | return; | |
1044 | ||
1045 | opnick = parv[(*parn)]; | |
1046 | (*parn)++; | |
1047 | ||
1048 | /* empty nick */ | |
1049 | if(EmptyString(opnick)) | |
1050 | { | |
1051 | sendto_one_numeric(source_p, ERR_NOSUCHNICK, form_str(ERR_NOSUCHNICK), "*"); | |
1052 | return; | |
1053 | } | |
1054 | ||
1055 | if((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) | |
1056 | { | |
1057 | return; | |
1058 | } | |
1059 | ||
1060 | mstptr = find_channel_membership(chptr, targ_p); | |
1061 | ||
1062 | if(mstptr == NULL) | |
1063 | { | |
1064 | if(!(*errors & SM_ERR_NOTONCHANNEL) && MyClient(source_p)) | |
1065 | sendto_one_numeric(source_p, ERR_USERNOTINCHANNEL, | |
1066 | form_str(ERR_USERNOTINCHANNEL), opnick, chptr->chname); | |
1067 | *errors |= SM_ERR_NOTONCHANNEL; | |
1068 | return; | |
1069 | } | |
1070 | ||
1071 | if(MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) | |
1072 | return; | |
1073 | ||
1074 | if(dir == MODE_ADD) | |
1075 | { | |
1076 | mode_changes[mode_count].letter = c; | |
1077 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
1078 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1079 | mode_changes[mode_count].id = targ_p->id; | |
0f8db055 | 1080 | mode_changes[mode_count++].arg = targ_p->name; |
212380e3 AC |
1081 | |
1082 | mstptr->flags |= CHFL_VOICE; | |
1083 | } | |
1084 | else | |
1085 | { | |
1086 | mode_changes[mode_count].letter = 'v'; | |
1087 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1088 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1089 | mode_changes[mode_count].id = targ_p->id; | |
0f8db055 | 1090 | mode_changes[mode_count++].arg = targ_p->name; |
212380e3 AC |
1091 | |
1092 | mstptr->flags &= ~CHFL_VOICE; | |
1093 | } | |
1094 | } | |
1095 | ||
1096 | void | |
1097 | chm_limit(struct Client *source_p, struct Channel *chptr, | |
1098 | int alevel, int parc, int *parn, | |
1099 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1100 | { | |
1101 | const char *lstr; | |
1102 | static char limitstr[30]; | |
1103 | int limit; | |
1104 | ||
f3b3ad0b | 1105 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 1106 | return; |
212380e3 AC |
1107 | |
1108 | if(dir == MODE_QUERY) | |
1109 | return; | |
1110 | ||
84c9a8c7 JT |
1111 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1112 | return; | |
1113 | ||
212380e3 AC |
1114 | if((dir == MODE_ADD) && parc > *parn) |
1115 | { | |
1116 | lstr = parv[(*parn)]; | |
1117 | (*parn)++; | |
1118 | ||
1119 | if(EmptyString(lstr) || (limit = atoi(lstr)) <= 0) | |
1120 | return; | |
1121 | ||
b2f0da88 | 1122 | rb_sprintf(limitstr, "%d", limit); |
212380e3 AC |
1123 | |
1124 | mode_changes[mode_count].letter = c; | |
1125 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
1126 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1127 | mode_changes[mode_count].id = NULL; | |
1128 | mode_changes[mode_count++].arg = limitstr; | |
1129 | ||
1130 | chptr->mode.limit = limit; | |
1131 | } | |
1132 | else if(dir == MODE_DEL) | |
1133 | { | |
1134 | if(!chptr->mode.limit) | |
1135 | return; | |
1136 | ||
1137 | chptr->mode.limit = 0; | |
1138 | ||
1139 | mode_changes[mode_count].letter = c; | |
1140 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1141 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1142 | mode_changes[mode_count].id = NULL; | |
1143 | mode_changes[mode_count++].arg = NULL; | |
1144 | } | |
1145 | } | |
1146 | ||
1147 | void | |
1148 | chm_throttle(struct Client *source_p, struct Channel *chptr, | |
1149 | int alevel, int parc, int *parn, | |
1150 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1151 | { | |
1152 | int joins = 0, timeslice = 0; | |
1153 | ||
f3b3ad0b | 1154 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 1155 | return; |
212380e3 AC |
1156 | |
1157 | if(dir == MODE_QUERY) | |
1158 | return; | |
1159 | ||
84c9a8c7 JT |
1160 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1161 | return; | |
1162 | ||
212380e3 AC |
1163 | if((dir == MODE_ADD) && parc > *parn) |
1164 | { | |
1165 | sscanf(parv[(*parn)], "%d:%d", &joins, ×lice); | |
1166 | ||
1167 | if(!joins || !timeslice) | |
1168 | return; | |
1169 | ||
1170 | mode_changes[mode_count].letter = c; | |
1171 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
1172 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1173 | mode_changes[mode_count].id = NULL; | |
1174 | mode_changes[mode_count++].arg = parv[(*parn)]; | |
1175 | ||
1176 | (*parn)++; | |
1177 | ||
1178 | chptr->mode.join_num = joins; | |
1179 | chptr->mode.join_time = timeslice; | |
1180 | } | |
1181 | else if(dir == MODE_DEL) | |
1182 | { | |
1183 | if(!chptr->mode.join_num) | |
1184 | return; | |
1185 | ||
1186 | chptr->mode.join_num = 0; | |
1187 | chptr->mode.join_time = 0; | |
1188 | chptr->join_count = 0; | |
1189 | chptr->join_delta = 0; | |
1190 | ||
1191 | mode_changes[mode_count].letter = c; | |
1192 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1193 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1194 | mode_changes[mode_count].id = NULL; | |
1195 | mode_changes[mode_count++].arg = NULL; | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | void | |
1200 | chm_forward(struct Client *source_p, struct Channel *chptr, | |
1201 | int alevel, int parc, int *parn, | |
1202 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1203 | { | |
212380e3 AC |
1204 | const char *forward; |
1205 | ||
2da6f6eb JT |
1206 | /* if +f is disabled, ignore local attempts to set it */ |
1207 | if(!ConfigChannel.use_forward && MyClient(source_p) && | |
1208 | (dir == MODE_ADD) && (parc > *parn)) | |
1209 | return; | |
1210 | ||
212380e3 AC |
1211 | if(dir == MODE_QUERY || (dir == MODE_ADD && parc <= *parn)) |
1212 | { | |
1213 | if (!(*errors & SM_ERR_RPL_F)) | |
1214 | { | |
1215 | if (*chptr->mode.forward == '\0') | |
5366977b | 1216 | sendto_one_notice(source_p, ":%s has no forward channel", chptr->chname); |
212380e3 | 1217 | else |
5366977b | 1218 | sendto_one_notice(source_p, ":%s forward channel is %s", chptr->chname, chptr->mode.forward); |
212380e3 AC |
1219 | *errors |= SM_ERR_RPL_F; |
1220 | } | |
1221 | return; | |
1222 | } | |
1223 | ||
1224 | #ifndef FORWARD_OPERONLY | |
f3b3ad0b | 1225 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 1226 | return; |
212380e3 AC |
1227 | #else |
1228 | if(!IsOper(source_p) && !IsServer(source_p)) | |
1229 | { | |
1230 | if(!(*errors & SM_ERR_NOPRIVS)) | |
1231 | sendto_one_numeric(source_p, ERR_NOPRIVILEGES, form_str(ERR_NOPRIVILEGES)); | |
1232 | *errors |= SM_ERR_NOPRIVS; | |
1233 | return; | |
1234 | } | |
1235 | #endif | |
1236 | ||
84c9a8c7 JT |
1237 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1238 | return; | |
1239 | ||
212380e3 AC |
1240 | if(dir == MODE_ADD && parc > *parn) |
1241 | { | |
1242 | forward = parv[(*parn)]; | |
1243 | (*parn)++; | |
1244 | ||
1245 | if(EmptyString(forward)) | |
1246 | return; | |
0c730321 JT |
1247 | |
1248 | if(!check_forward(source_p, chptr, forward)) | |
212380e3 | 1249 | return; |
212380e3 | 1250 | |
f427c8b0 | 1251 | rb_strlcpy(chptr->mode.forward, forward, sizeof(chptr->mode.forward)); |
212380e3 AC |
1252 | |
1253 | mode_changes[mode_count].letter = c; | |
1254 | mode_changes[mode_count].dir = MODE_ADD; | |
2da6f6eb JT |
1255 | mode_changes[mode_count].mems = |
1256 | ConfigChannel.use_forward ? ALL_MEMBERS : ONLY_SERVERS; | |
212380e3 AC |
1257 | mode_changes[mode_count].id = NULL; |
1258 | mode_changes[mode_count++].arg = forward; | |
1259 | } | |
1260 | else if(dir == MODE_DEL) | |
1261 | { | |
1262 | if(!(*chptr->mode.forward)) | |
1263 | return; | |
1264 | ||
1265 | *chptr->mode.forward = '\0'; | |
1266 | ||
1267 | mode_changes[mode_count].letter = c; | |
1268 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1269 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1270 | mode_changes[mode_count].id = NULL; | |
1271 | mode_changes[mode_count++].arg = NULL; | |
1272 | } | |
1273 | } | |
1274 | ||
1275 | void | |
1276 | chm_key(struct Client *source_p, struct Channel *chptr, | |
1277 | int alevel, int parc, int *parn, | |
1278 | const char **parv, int *errors, int dir, char c, long mode_type) | |
1279 | { | |
1280 | char *key; | |
1281 | ||
f3b3ad0b | 1282 | if(!allow_mode_change(source_p, chptr, alevel, errors, c)) |
212380e3 | 1283 | return; |
212380e3 AC |
1284 | |
1285 | if(dir == MODE_QUERY) | |
1286 | return; | |
1287 | ||
84c9a8c7 JT |
1288 | if(MyClient(source_p) && (++mode_limit_simple > MAXMODES_SIMPLE)) |
1289 | return; | |
1290 | ||
212380e3 AC |
1291 | if((dir == MODE_ADD) && parc > *parn) |
1292 | { | |
1293 | key = LOCAL_COPY(parv[(*parn)]); | |
1294 | (*parn)++; | |
1295 | ||
1296 | if(MyClient(source_p)) | |
1297 | fix_key(key); | |
1298 | else | |
1299 | fix_key_remote(key); | |
1300 | ||
1301 | if(EmptyString(key)) | |
1302 | return; | |
1303 | ||
1304 | s_assert(key[0] != ' '); | |
f427c8b0 | 1305 | rb_strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
212380e3 AC |
1306 | |
1307 | mode_changes[mode_count].letter = c; | |
1308 | mode_changes[mode_count].dir = MODE_ADD; | |
212380e3 AC |
1309 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1310 | mode_changes[mode_count].id = NULL; | |
1311 | mode_changes[mode_count++].arg = chptr->mode.key; | |
1312 | } | |
1313 | else if(dir == MODE_DEL) | |
1314 | { | |
1315 | static char splat[] = "*"; | |
1316 | int i; | |
1317 | ||
1318 | if(parc > *parn) | |
1319 | (*parn)++; | |
1320 | ||
1321 | if(!(*chptr->mode.key)) | |
1322 | return; | |
1323 | ||
1324 | /* hack time. when we get a +k-k mode, the +k arg is | |
1325 | * chptr->mode.key, which the -k sets to \0, so hunt for a | |
1326 | * +k when we get a -k, and set the arg to splat. --anfl | |
1327 | */ | |
1328 | for(i = 0; i < mode_count; i++) | |
1329 | { | |
1330 | if(mode_changes[i].letter == 'k' && mode_changes[i].dir == MODE_ADD) | |
1331 | mode_changes[i].arg = splat; | |
1332 | } | |
1333 | ||
1334 | *chptr->mode.key = 0; | |
1335 | ||
1336 | mode_changes[mode_count].letter = c; | |
1337 | mode_changes[mode_count].dir = MODE_DEL; | |
212380e3 AC |
1338 | mode_changes[mode_count].mems = ALL_MEMBERS; |
1339 | mode_changes[mode_count].id = NULL; | |
1340 | mode_changes[mode_count++].arg = "*"; | |
1341 | } | |
1342 | } | |
1343 | ||
212380e3 AC |
1344 | /* *INDENT-OFF* */ |
1345 | struct ChannelMode chmode_table[256] = | |
1346 | { | |
1347 | {chm_nosuch, 0 }, /* 0x00 */ | |
1348 | {chm_nosuch, 0 }, /* 0x01 */ | |
1349 | {chm_nosuch, 0 }, /* 0x02 */ | |
1350 | {chm_nosuch, 0 }, /* 0x03 */ | |
1351 | {chm_nosuch, 0 }, /* 0x04 */ | |
1352 | {chm_nosuch, 0 }, /* 0x05 */ | |
1353 | {chm_nosuch, 0 }, /* 0x06 */ | |
1354 | {chm_nosuch, 0 }, /* 0x07 */ | |
1355 | {chm_nosuch, 0 }, /* 0x08 */ | |
1356 | {chm_nosuch, 0 }, /* 0x09 */ | |
1357 | {chm_nosuch, 0 }, /* 0x0a */ | |
1358 | {chm_nosuch, 0 }, /* 0x0b */ | |
1359 | {chm_nosuch, 0 }, /* 0x0c */ | |
1360 | {chm_nosuch, 0 }, /* 0x0d */ | |
1361 | {chm_nosuch, 0 }, /* 0x0e */ | |
1362 | {chm_nosuch, 0 }, /* 0x0f */ | |
1363 | {chm_nosuch, 0 }, /* 0x10 */ | |
1364 | {chm_nosuch, 0 }, /* 0x11 */ | |
1365 | {chm_nosuch, 0 }, /* 0x12 */ | |
1366 | {chm_nosuch, 0 }, /* 0x13 */ | |
1367 | {chm_nosuch, 0 }, /* 0x14 */ | |
1368 | {chm_nosuch, 0 }, /* 0x15 */ | |
1369 | {chm_nosuch, 0 }, /* 0x16 */ | |
1370 | {chm_nosuch, 0 }, /* 0x17 */ | |
1371 | {chm_nosuch, 0 }, /* 0x18 */ | |
1372 | {chm_nosuch, 0 }, /* 0x19 */ | |
1373 | {chm_nosuch, 0 }, /* 0x1a */ | |
1374 | {chm_nosuch, 0 }, /* 0x1b */ | |
1375 | {chm_nosuch, 0 }, /* 0x1c */ | |
1376 | {chm_nosuch, 0 }, /* 0x1d */ | |
1377 | {chm_nosuch, 0 }, /* 0x1e */ | |
1378 | {chm_nosuch, 0 }, /* 0x1f */ | |
1379 | {chm_nosuch, 0 }, /* 0x20 */ | |
1380 | {chm_nosuch, 0 }, /* 0x21 */ | |
1381 | {chm_nosuch, 0 }, /* 0x22 */ | |
1382 | {chm_nosuch, 0 }, /* 0x23 */ | |
1383 | {chm_nosuch, 0 }, /* 0x24 */ | |
1384 | {chm_nosuch, 0 }, /* 0x25 */ | |
1385 | {chm_nosuch, 0 }, /* 0x26 */ | |
1386 | {chm_nosuch, 0 }, /* 0x27 */ | |
1387 | {chm_nosuch, 0 }, /* 0x28 */ | |
1388 | {chm_nosuch, 0 }, /* 0x29 */ | |
1389 | {chm_nosuch, 0 }, /* 0x2a */ | |
1390 | {chm_nosuch, 0 }, /* 0x2b */ | |
1391 | {chm_nosuch, 0 }, /* 0x2c */ | |
1392 | {chm_nosuch, 0 }, /* 0x2d */ | |
1393 | {chm_nosuch, 0 }, /* 0x2e */ | |
1394 | {chm_nosuch, 0 }, /* 0x2f */ | |
1395 | {chm_nosuch, 0 }, /* 0x30 */ | |
1396 | {chm_nosuch, 0 }, /* 0x31 */ | |
1397 | {chm_nosuch, 0 }, /* 0x32 */ | |
1398 | {chm_nosuch, 0 }, /* 0x33 */ | |
1399 | {chm_nosuch, 0 }, /* 0x34 */ | |
1400 | {chm_nosuch, 0 }, /* 0x35 */ | |
1401 | {chm_nosuch, 0 }, /* 0x36 */ | |
1402 | {chm_nosuch, 0 }, /* 0x37 */ | |
1403 | {chm_nosuch, 0 }, /* 0x38 */ | |
1404 | {chm_nosuch, 0 }, /* 0x39 */ | |
1405 | {chm_nosuch, 0 }, /* 0x3a */ | |
1406 | {chm_nosuch, 0 }, /* 0x3b */ | |
1407 | {chm_nosuch, 0 }, /* 0x3c */ | |
1408 | {chm_nosuch, 0 }, /* 0x3d */ | |
1409 | {chm_nosuch, 0 }, /* 0x3e */ | |
1410 | {chm_nosuch, 0 }, /* 0x3f */ | |
1411 | ||
1412 | {chm_nosuch, 0 }, /* @ */ | |
1413 | {chm_nosuch, 0 }, /* A */ | |
1414 | {chm_nosuch, 0 }, /* B */ | |
f30a5ee4 | 1415 | {chm_nosuch, 0 }, /* C */ |
212380e3 AC |
1416 | {chm_nosuch, 0 }, /* D */ |
1417 | {chm_nosuch, 0 }, /* E */ | |
1418 | {chm_simple, MODE_FREETARGET }, /* F */ | |
1419 | {chm_nosuch, 0 }, /* G */ | |
1420 | {chm_nosuch, 0 }, /* H */ | |
1421 | {chm_ban, CHFL_INVEX }, /* I */ | |
1422 | {chm_nosuch, 0 }, /* J */ | |
1423 | {chm_nosuch, 0 }, /* K */ | |
1424 | {chm_staff, MODE_EXLIMIT }, /* L */ | |
1425 | {chm_nosuch, 0 }, /* M */ | |
1426 | {chm_nosuch, 0 }, /* N */ | |
1427 | {chm_nosuch, 0 }, /* O */ | |
1428 | {chm_staff, MODE_PERMANENT }, /* P */ | |
1429 | {chm_simple, MODE_DISFORWARD }, /* Q */ | |
1430 | {chm_nosuch, 0 }, /* R */ | |
1431 | {chm_nosuch, 0 }, /* S */ | |
1432 | {chm_nosuch, 0 }, /* T */ | |
1433 | {chm_nosuch, 0 }, /* U */ | |
1434 | {chm_nosuch, 0 }, /* V */ | |
1435 | {chm_nosuch, 0 }, /* W */ | |
1436 | {chm_nosuch, 0 }, /* X */ | |
1437 | {chm_nosuch, 0 }, /* Y */ | |
1438 | {chm_nosuch, 0 }, /* Z */ | |
1439 | {chm_nosuch, 0 }, | |
1440 | {chm_nosuch, 0 }, | |
1441 | {chm_nosuch, 0 }, | |
1442 | {chm_nosuch, 0 }, | |
1443 | {chm_nosuch, 0 }, | |
1444 | {chm_nosuch, 0 }, | |
1445 | {chm_nosuch, 0 }, /* a */ | |
1446 | {chm_ban, CHFL_BAN }, /* b */ | |
67aeaba5 | 1447 | {chm_nosuch, 0 }, /* c */ |
212380e3 AC |
1448 | {chm_nosuch, 0 }, /* d */ |
1449 | {chm_ban, CHFL_EXCEPTION }, /* e */ | |
1450 | {chm_forward, 0 }, /* f */ | |
1451 | {chm_simple, MODE_FREEINVITE }, /* g */ | |
1452 | {chm_nosuch, 0 }, /* h */ | |
1453 | {chm_simple, MODE_INVITEONLY }, /* i */ | |
1454 | {chm_throttle, 0 }, /* j */ | |
1455 | {chm_key, 0 }, /* k */ | |
1456 | {chm_limit, 0 }, /* l */ | |
1457 | {chm_simple, MODE_MODERATED }, /* m */ | |
1458 | {chm_simple, MODE_NOPRIVMSGS }, /* n */ | |
1459 | {chm_op, 0 }, /* o */ | |
1460 | {chm_simple, MODE_PRIVATE }, /* p */ | |
1461 | {chm_ban, CHFL_QUIET }, /* q */ | |
83b72f91 | 1462 | {chm_simple, MODE_REGONLY }, /* r */ |
212380e3 AC |
1463 | {chm_simple, MODE_SECRET }, /* s */ |
1464 | {chm_simple, MODE_TOPICLIMIT }, /* t */ | |
1465 | {chm_nosuch, 0 }, /* u */ | |
1466 | {chm_voice, 0 }, /* v */ | |
1467 | {chm_nosuch, 0 }, /* w */ | |
1468 | {chm_nosuch, 0 }, /* x */ | |
1469 | {chm_nosuch, 0 }, /* y */ | |
1470 | {chm_simple, MODE_OPMODERATE }, /* z */ | |
1471 | ||
1472 | {chm_nosuch, 0 }, /* 0x7b */ | |
1473 | {chm_nosuch, 0 }, /* 0x7c */ | |
1474 | {chm_nosuch, 0 }, /* 0x7d */ | |
1475 | {chm_nosuch, 0 }, /* 0x7e */ | |
1476 | {chm_nosuch, 0 }, /* 0x7f */ | |
1477 | ||
1478 | {chm_nosuch, 0 }, /* 0x80 */ | |
1479 | {chm_nosuch, 0 }, /* 0x81 */ | |
1480 | {chm_nosuch, 0 }, /* 0x82 */ | |
1481 | {chm_nosuch, 0 }, /* 0x83 */ | |
1482 | {chm_nosuch, 0 }, /* 0x84 */ | |
1483 | {chm_nosuch, 0 }, /* 0x85 */ | |
1484 | {chm_nosuch, 0 }, /* 0x86 */ | |
1485 | {chm_nosuch, 0 }, /* 0x87 */ | |
1486 | {chm_nosuch, 0 }, /* 0x88 */ | |
1487 | {chm_nosuch, 0 }, /* 0x89 */ | |
1488 | {chm_nosuch, 0 }, /* 0x8a */ | |
1489 | {chm_nosuch, 0 }, /* 0x8b */ | |
1490 | {chm_nosuch, 0 }, /* 0x8c */ | |
1491 | {chm_nosuch, 0 }, /* 0x8d */ | |
1492 | {chm_nosuch, 0 }, /* 0x8e */ | |
1493 | {chm_nosuch, 0 }, /* 0x8f */ | |
1494 | ||
1495 | {chm_nosuch, 0 }, /* 0x90 */ | |
1496 | {chm_nosuch, 0 }, /* 0x91 */ | |
1497 | {chm_nosuch, 0 }, /* 0x92 */ | |
1498 | {chm_nosuch, 0 }, /* 0x93 */ | |
1499 | {chm_nosuch, 0 }, /* 0x94 */ | |
1500 | {chm_nosuch, 0 }, /* 0x95 */ | |
1501 | {chm_nosuch, 0 }, /* 0x96 */ | |
1502 | {chm_nosuch, 0 }, /* 0x97 */ | |
1503 | {chm_nosuch, 0 }, /* 0x98 */ | |
1504 | {chm_nosuch, 0 }, /* 0x99 */ | |
1505 | {chm_nosuch, 0 }, /* 0x9a */ | |
1506 | {chm_nosuch, 0 }, /* 0x9b */ | |
1507 | {chm_nosuch, 0 }, /* 0x9c */ | |
1508 | {chm_nosuch, 0 }, /* 0x9d */ | |
1509 | {chm_nosuch, 0 }, /* 0x9e */ | |
1510 | {chm_nosuch, 0 }, /* 0x9f */ | |
1511 | ||
1512 | {chm_nosuch, 0 }, /* 0xa0 */ | |
1513 | {chm_nosuch, 0 }, /* 0xa1 */ | |
1514 | {chm_nosuch, 0 }, /* 0xa2 */ | |
1515 | {chm_nosuch, 0 }, /* 0xa3 */ | |
1516 | {chm_nosuch, 0 }, /* 0xa4 */ | |
1517 | {chm_nosuch, 0 }, /* 0xa5 */ | |
1518 | {chm_nosuch, 0 }, /* 0xa6 */ | |
1519 | {chm_nosuch, 0 }, /* 0xa7 */ | |
1520 | {chm_nosuch, 0 }, /* 0xa8 */ | |
1521 | {chm_nosuch, 0 }, /* 0xa9 */ | |
1522 | {chm_nosuch, 0 }, /* 0xaa */ | |
1523 | {chm_nosuch, 0 }, /* 0xab */ | |
1524 | {chm_nosuch, 0 }, /* 0xac */ | |
1525 | {chm_nosuch, 0 }, /* 0xad */ | |
1526 | {chm_nosuch, 0 }, /* 0xae */ | |
1527 | {chm_nosuch, 0 }, /* 0xaf */ | |
1528 | ||
1529 | {chm_nosuch, 0 }, /* 0xb0 */ | |
1530 | {chm_nosuch, 0 }, /* 0xb1 */ | |
1531 | {chm_nosuch, 0 }, /* 0xb2 */ | |
1532 | {chm_nosuch, 0 }, /* 0xb3 */ | |
1533 | {chm_nosuch, 0 }, /* 0xb4 */ | |
1534 | {chm_nosuch, 0 }, /* 0xb5 */ | |
1535 | {chm_nosuch, 0 }, /* 0xb6 */ | |
1536 | {chm_nosuch, 0 }, /* 0xb7 */ | |
1537 | {chm_nosuch, 0 }, /* 0xb8 */ | |
1538 | {chm_nosuch, 0 }, /* 0xb9 */ | |
1539 | {chm_nosuch, 0 }, /* 0xba */ | |
1540 | {chm_nosuch, 0 }, /* 0xbb */ | |
1541 | {chm_nosuch, 0 }, /* 0xbc */ | |
1542 | {chm_nosuch, 0 }, /* 0xbd */ | |
1543 | {chm_nosuch, 0 }, /* 0xbe */ | |
1544 | {chm_nosuch, 0 }, /* 0xbf */ | |
1545 | ||
1546 | {chm_nosuch, 0 }, /* 0xc0 */ | |
1547 | {chm_nosuch, 0 }, /* 0xc1 */ | |
1548 | {chm_nosuch, 0 }, /* 0xc2 */ | |
1549 | {chm_nosuch, 0 }, /* 0xc3 */ | |
1550 | {chm_nosuch, 0 }, /* 0xc4 */ | |
1551 | {chm_nosuch, 0 }, /* 0xc5 */ | |
1552 | {chm_nosuch, 0 }, /* 0xc6 */ | |
1553 | {chm_nosuch, 0 }, /* 0xc7 */ | |
1554 | {chm_nosuch, 0 }, /* 0xc8 */ | |
1555 | {chm_nosuch, 0 }, /* 0xc9 */ | |
1556 | {chm_nosuch, 0 }, /* 0xca */ | |
1557 | {chm_nosuch, 0 }, /* 0xcb */ | |
1558 | {chm_nosuch, 0 }, /* 0xcc */ | |
1559 | {chm_nosuch, 0 }, /* 0xcd */ | |
1560 | {chm_nosuch, 0 }, /* 0xce */ | |
1561 | {chm_nosuch, 0 }, /* 0xcf */ | |
1562 | ||
1563 | {chm_nosuch, 0 }, /* 0xd0 */ | |
1564 | {chm_nosuch, 0 }, /* 0xd1 */ | |
1565 | {chm_nosuch, 0 }, /* 0xd2 */ | |
1566 | {chm_nosuch, 0 }, /* 0xd3 */ | |
1567 | {chm_nosuch, 0 }, /* 0xd4 */ | |
1568 | {chm_nosuch, 0 }, /* 0xd5 */ | |
1569 | {chm_nosuch, 0 }, /* 0xd6 */ | |
1570 | {chm_nosuch, 0 }, /* 0xd7 */ | |
1571 | {chm_nosuch, 0 }, /* 0xd8 */ | |
1572 | {chm_nosuch, 0 }, /* 0xd9 */ | |
1573 | {chm_nosuch, 0 }, /* 0xda */ | |
1574 | {chm_nosuch, 0 }, /* 0xdb */ | |
1575 | {chm_nosuch, 0 }, /* 0xdc */ | |
1576 | {chm_nosuch, 0 }, /* 0xdd */ | |
1577 | {chm_nosuch, 0 }, /* 0xde */ | |
1578 | {chm_nosuch, 0 }, /* 0xdf */ | |
1579 | ||
1580 | {chm_nosuch, 0 }, /* 0xe0 */ | |
1581 | {chm_nosuch, 0 }, /* 0xe1 */ | |
1582 | {chm_nosuch, 0 }, /* 0xe2 */ | |
1583 | {chm_nosuch, 0 }, /* 0xe3 */ | |
1584 | {chm_nosuch, 0 }, /* 0xe4 */ | |
1585 | {chm_nosuch, 0 }, /* 0xe5 */ | |
1586 | {chm_nosuch, 0 }, /* 0xe6 */ | |
1587 | {chm_nosuch, 0 }, /* 0xe7 */ | |
1588 | {chm_nosuch, 0 }, /* 0xe8 */ | |
1589 | {chm_nosuch, 0 }, /* 0xe9 */ | |
1590 | {chm_nosuch, 0 }, /* 0xea */ | |
1591 | {chm_nosuch, 0 }, /* 0xeb */ | |
1592 | {chm_nosuch, 0 }, /* 0xec */ | |
1593 | {chm_nosuch, 0 }, /* 0xed */ | |
1594 | {chm_nosuch, 0 }, /* 0xee */ | |
1595 | {chm_nosuch, 0 }, /* 0xef */ | |
1596 | ||
1597 | {chm_nosuch, 0 }, /* 0xf0 */ | |
1598 | {chm_nosuch, 0 }, /* 0xf1 */ | |
1599 | {chm_nosuch, 0 }, /* 0xf2 */ | |
1600 | {chm_nosuch, 0 }, /* 0xf3 */ | |
1601 | {chm_nosuch, 0 }, /* 0xf4 */ | |
1602 | {chm_nosuch, 0 }, /* 0xf5 */ | |
1603 | {chm_nosuch, 0 }, /* 0xf6 */ | |
1604 | {chm_nosuch, 0 }, /* 0xf7 */ | |
1605 | {chm_nosuch, 0 }, /* 0xf8 */ | |
1606 | {chm_nosuch, 0 }, /* 0xf9 */ | |
1607 | {chm_nosuch, 0 }, /* 0xfa */ | |
1608 | {chm_nosuch, 0 }, /* 0xfb */ | |
1609 | {chm_nosuch, 0 }, /* 0xfc */ | |
1610 | {chm_nosuch, 0 }, /* 0xfd */ | |
1611 | {chm_nosuch, 0 }, /* 0xfe */ | |
1612 | {chm_nosuch, 0 }, /* 0xff */ | |
1613 | }; | |
1614 | ||
1615 | /* *INDENT-ON* */ | |
1616 | ||
1617 | /* set_channel_mode() | |
1618 | * | |
1619 | * inputs - client, source, channel, membership pointer, params | |
55abcbb2 | 1620 | * output - |
212380e3 AC |
1621 | * side effects - channel modes/memberships are changed, MODE is issued |
1622 | * | |
1623 | * Extensively modified to be hotpluggable, 03/09/06 -- nenolod | |
1624 | */ | |
1625 | void | |
1626 | set_channel_mode(struct Client *client_p, struct Client *source_p, | |
1627 | struct Channel *chptr, struct membership *msptr, int parc, const char *parv[]) | |
1628 | { | |
1629 | static char modebuf[BUFSIZE]; | |
1630 | static char parabuf[BUFSIZE]; | |
1631 | char *mbuf; | |
1632 | char *pbuf; | |
1633 | int cur_len, mlen, paralen, paracount, arglen, len; | |
1634 | int i, j, flags; | |
1635 | int dir = MODE_ADD; | |
1636 | int parn = 1; | |
1637 | int errors = 0; | |
1638 | int alevel; | |
1639 | const char *ml = parv[0]; | |
1640 | char c; | |
1641 | struct Client *fakesource_p; | |
1642 | ||
1643 | mask_pos = 0; | |
765d839d | 1644 | removed_mask_pos = 0; |
212380e3 AC |
1645 | mode_count = 0; |
1646 | mode_limit = 0; | |
84c9a8c7 | 1647 | mode_limit_simple = 0; |
212380e3 | 1648 | |
7eec45bc | 1649 | alevel = get_channel_access(source_p, msptr); |
212380e3 AC |
1650 | |
1651 | /* Hide connecting server on netburst -- jilles */ | |
1652 | if (ConfigServerHide.flatten_links && IsServer(source_p) && !has_id(source_p) && !HasSentEob(source_p)) | |
1653 | fakesource_p = &me; | |
1654 | else | |
1655 | fakesource_p = source_p; | |
1656 | ||
1657 | for(; (c = *ml) != 0; ml++) | |
1658 | { | |
1659 | switch (c) | |
1660 | { | |
1661 | case '+': | |
1662 | dir = MODE_ADD; | |
1663 | break; | |
1664 | case '-': | |
1665 | dir = MODE_DEL; | |
1666 | break; | |
1667 | case '=': | |
1668 | dir = MODE_QUERY; | |
1669 | break; | |
1670 | default: | |
1671 | chmode_table[(unsigned char) c].set_func(fakesource_p, chptr, alevel, | |
1672 | parc, &parn, parv, | |
1673 | &errors, dir, c, | |
1674 | chmode_table[(unsigned char) c].mode_type); | |
1675 | break; | |
1676 | } | |
1677 | } | |
1678 | ||
1679 | /* bail out if we have nothing to do... */ | |
1680 | if(!mode_count) | |
1681 | return; | |
1682 | ||
1683 | if(IsServer(source_p)) | |
b2f0da88 | 1684 | mlen = rb_sprintf(modebuf, ":%s MODE %s ", fakesource_p->name, chptr->chname); |
212380e3 | 1685 | else |
b2f0da88 | 1686 | mlen = rb_sprintf(modebuf, ":%s!%s@%s MODE %s ", |
212380e3 AC |
1687 | source_p->name, source_p->username, |
1688 | source_p->host, chptr->chname); | |
1689 | ||
1690 | for(j = 0, flags = ALL_MEMBERS; j < 2; j++, flags = ONLY_CHANOPS) | |
1691 | { | |
1692 | cur_len = mlen; | |
1693 | mbuf = modebuf + mlen; | |
1694 | pbuf = parabuf; | |
1695 | parabuf[0] = '\0'; | |
1696 | paracount = paralen = 0; | |
1697 | dir = MODE_QUERY; | |
1698 | ||
1699 | for(i = 0; i < mode_count; i++) | |
1700 | { | |
1701 | if(mode_changes[i].letter == 0 || mode_changes[i].mems != flags) | |
1702 | continue; | |
1703 | ||
1704 | if(mode_changes[i].arg != NULL) | |
1705 | { | |
1706 | arglen = strlen(mode_changes[i].arg); | |
1707 | ||
1708 | if(arglen > MODEBUFLEN - 5) | |
1709 | continue; | |
1710 | } | |
1711 | else | |
1712 | arglen = 0; | |
1713 | ||
1714 | /* if we're creeping over MAXMODEPARAMSSERV, or over | |
1715 | * bufsize (4 == +/-,modechar,two spaces) send now. | |
1716 | */ | |
1717 | if(mode_changes[i].arg != NULL && | |
1718 | ((paracount == MAXMODEPARAMSSERV) || | |
1719 | ((cur_len + paralen + arglen + 4) > (BUFSIZE - 3)))) | |
1720 | { | |
1721 | *mbuf = '\0'; | |
1722 | ||
1723 | if(cur_len > mlen) | |
1724 | sendto_channel_local(flags, chptr, "%s %s", modebuf, | |
1725 | parabuf); | |
1726 | else | |
1727 | continue; | |
1728 | ||
1729 | paracount = paralen = 0; | |
1730 | cur_len = mlen; | |
1731 | mbuf = modebuf + mlen; | |
1732 | pbuf = parabuf; | |
1733 | parabuf[0] = '\0'; | |
1734 | dir = MODE_QUERY; | |
1735 | } | |
1736 | ||
1737 | if(dir != mode_changes[i].dir) | |
1738 | { | |
1739 | *mbuf++ = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; | |
1740 | cur_len++; | |
1741 | dir = mode_changes[i].dir; | |
1742 | } | |
1743 | ||
1744 | *mbuf++ = mode_changes[i].letter; | |
1745 | cur_len++; | |
1746 | ||
1747 | if(mode_changes[i].arg != NULL) | |
1748 | { | |
1749 | paracount++; | |
b2f0da88 | 1750 | len = rb_sprintf(pbuf, "%s ", mode_changes[i].arg); |
212380e3 AC |
1751 | pbuf += len; |
1752 | paralen += len; | |
1753 | } | |
1754 | } | |
1755 | ||
1756 | if(paralen && parabuf[paralen - 1] == ' ') | |
1757 | parabuf[paralen - 1] = '\0'; | |
1758 | ||
1759 | *mbuf = '\0'; | |
1760 | if(cur_len > mlen) | |
1761 | sendto_channel_local(flags, chptr, "%s %s", modebuf, parabuf); | |
1762 | } | |
1763 | ||
1764 | /* only propagate modes originating locally, or if we're hubbing */ | |
330fc5c1 | 1765 | if(MyClient(source_p) || rb_dlink_list_length(&serv_list) > 1) |
212380e3 AC |
1766 | send_cap_mode_changes(client_p, source_p, chptr, mode_changes, mode_count); |
1767 | } | |
8727cbe8 AC |
1768 | |
1769 | /* set_channel_mlock() | |
1770 | * | |
1771 | * inputs - client, source, channel, params | |
55abcbb2 | 1772 | * output - |
8727cbe8 AC |
1773 | * side effects - channel mlock is changed / MLOCK is propagated |
1774 | */ | |
1775 | void | |
1776 | set_channel_mlock(struct Client *client_p, struct Client *source_p, | |
6fb6bd15 | 1777 | struct Channel *chptr, const char *newmlock, int propagate) |
8727cbe8 | 1778 | { |
78e6b731 | 1779 | rb_free(chptr->mode_lock); |
6b8db2da | 1780 | chptr->mode_lock = newmlock ? rb_strdup(newmlock) : NULL; |
8727cbe8 | 1781 | |
6fb6bd15 AC |
1782 | if (propagate) |
1783 | { | |
1784 | sendto_server(client_p, NULL, CAP_TS6 | CAP_MLOCK, NOCAPS, ":%s MLOCK %ld %s :%s", | |
1785 | source_p->id, (long) chptr->channelts, chptr->chname, | |
1786 | chptr->mode_lock ? chptr->mode_lock : ""); | |
1787 | } | |
8727cbe8 | 1788 | } |