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