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