1 |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
3 |
* channel_mode.c: Controls modes on channels. |
4 |
* |
5 |
* Copyright (C) 2005 by the past and present ircd coders, and others. |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
9 |
* the Free Software Foundation; either version 2 of the License, or |
10 |
* (at your option) any later version. |
11 |
* |
12 |
* This program is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
21 |
* |
22 |
* $Id$ |
23 |
*/ |
24 |
|
25 |
#include "stdinc.h" |
26 |
#include "list.h" |
27 |
#include "channel.h" |
28 |
#include "channel_mode.h" |
29 |
#include "client.h" |
30 |
#include "hash.h" |
31 |
#include "conf.h" |
32 |
#include "hostmask.h" |
33 |
#include "irc_string.h" |
34 |
#include "ircd.h" |
35 |
#include "numeric.h" |
36 |
#include "s_serv.h" /* captab */ |
37 |
#include "s_user.h" |
38 |
#include "send.h" |
39 |
#include "whowas.h" |
40 |
#include "memory.h" |
41 |
#include "mempool.h" |
42 |
#include "log.h" |
43 |
#include "parse.h" |
44 |
#include "xsnprintf.h" |
45 |
|
46 |
/* some small utility functions */ |
47 |
static char *check_string(char *); |
48 |
static char *fix_key(char *); |
49 |
static char *fix_key_old(char *); |
50 |
static void chm_nosuch(struct Client *, struct Client *, |
51 |
struct Channel *, int, int *, char **, int *, int, |
52 |
int, char, void *, const char *); |
53 |
static void chm_simple(struct Client *, struct Client *, struct Channel *, |
54 |
int, int *, char **, int *, int, int, char, void *, |
55 |
const char *); |
56 |
static void chm_registered(struct Client *, struct Client *, struct Channel *, |
57 |
int, int *, char **, int *, int, int, char, void *, |
58 |
const char *); |
59 |
static void chm_limit(struct Client *, struct Client *, struct Channel *, |
60 |
int, int *, char **, int *, int, int, char, void *, |
61 |
const char *); |
62 |
static void chm_key(struct Client *, struct Client *, struct Channel *, |
63 |
int, int *, char **, int *, int, int, char, void *, |
64 |
const char *); |
65 |
static void chm_op(struct Client *, struct Client *, struct Channel *, int, |
66 |
int *, char **, int *, int, int, char, void *, |
67 |
const char *); |
68 |
#ifdef HALFOPS |
69 |
static void chm_hop(struct Client *, struct Client *, struct Channel *, int, |
70 |
int *, char **, int *, int, int, char, void *, |
71 |
const char *); |
72 |
#endif |
73 |
static void chm_voice(struct Client *, struct Client *, struct Channel *, |
74 |
int, int *, char **, int *, int, int, char, void *, |
75 |
const char *); |
76 |
static void chm_ban(struct Client *, struct Client *, struct Channel *, int, |
77 |
int *, char **, int *, int, int, char, void *, |
78 |
const char *); |
79 |
static void chm_except(struct Client *, struct Client *, struct Channel *, |
80 |
int, int *, char **, int *, int, int, char, void *, |
81 |
const char *); |
82 |
static void chm_invex(struct Client *, struct Client *, struct Channel *, |
83 |
int, int *, char **, int *, int, int, char, void *, |
84 |
const char *); |
85 |
static void send_cap_mode_changes(struct Client *, struct Client *, |
86 |
struct Channel *, unsigned int, unsigned int); |
87 |
static void send_mode_changes(struct Client *, struct Client *, |
88 |
struct Channel *, char *); |
89 |
|
90 |
/* 10 is a magic number in hybrid 6 NFI where it comes from -db */ |
91 |
#define BAN_FUDGE 10 |
92 |
#define NCHCAPS (sizeof(channel_capabs)/sizeof(int)) |
93 |
#define NCHCAP_COMBOS (1 << NCHCAPS) |
94 |
|
95 |
static char nuh_mask[MAXPARA][IRCD_BUFSIZE]; |
96 |
/* some buffers for rebuilding channel/nick lists with ,'s */ |
97 |
static char modebuf[IRCD_BUFSIZE]; |
98 |
static char parabuf[MODEBUFLEN]; |
99 |
static struct ChModeChange mode_changes[IRCD_BUFSIZE]; |
100 |
static int mode_count; |
101 |
static int mode_limit; /* number of modes set other than simple */ |
102 |
static int simple_modes_mask; /* bit mask of simple modes already set */ |
103 |
#ifdef HALFOPS |
104 |
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6, CAP_HOPS }; |
105 |
#else |
106 |
static int channel_capabs[] = { CAP_EX, CAP_IE, CAP_TS6 }; |
107 |
#endif |
108 |
static struct ChCapCombo chcap_combos[NCHCAP_COMBOS]; |
109 |
extern mp_pool_t *ban_pool; |
110 |
|
111 |
|
112 |
/* check_string() |
113 |
* |
114 |
* inputs - string to check |
115 |
* output - pointer to modified string |
116 |
* side effects - Fixes a string so that the first white space found |
117 |
* becomes an end of string marker (`\0`). |
118 |
* returns the 'fixed' string or "*" if the string |
119 |
* was NULL length or a NULL pointer. |
120 |
*/ |
121 |
static char * |
122 |
check_string(char *s) |
123 |
{ |
124 |
char *str = s; |
125 |
static char star[] = "*"; |
126 |
|
127 |
if (EmptyString(str)) |
128 |
return star; |
129 |
|
130 |
for (; *s; ++s) |
131 |
{ |
132 |
if (IsSpace(*s)) |
133 |
{ |
134 |
*s = '\0'; |
135 |
break; |
136 |
} |
137 |
} |
138 |
|
139 |
return EmptyString(str) ? star : str; |
140 |
} |
141 |
|
142 |
/* |
143 |
* Ban functions to work with mode +b/e/d/I |
144 |
*/ |
145 |
/* add the specified ID to the channel.. |
146 |
* -is 8/9/00 |
147 |
*/ |
148 |
|
149 |
int |
150 |
add_id(struct Client *client_p, struct Channel *chptr, char *banid, int type) |
151 |
{ |
152 |
dlink_list *list = NULL; |
153 |
dlink_node *ban = NULL; |
154 |
size_t len = 0; |
155 |
struct Ban *ban_p = NULL; |
156 |
unsigned int num_mask; |
157 |
char name[NICKLEN + 1]; |
158 |
char user[USERLEN + 1]; |
159 |
char host[HOSTLEN + 1]; |
160 |
struct split_nuh_item nuh; |
161 |
|
162 |
/* dont let local clients overflow the b/e/I lists */ |
163 |
if (MyClient(client_p)) |
164 |
{ |
165 |
num_mask = dlink_list_length(&chptr->banlist) + |
166 |
dlink_list_length(&chptr->exceptlist) + |
167 |
dlink_list_length(&chptr->invexlist); |
168 |
|
169 |
if (num_mask >= ConfigChannel.max_bans) |
170 |
{ |
171 |
sendto_one(client_p, form_str(ERR_BANLISTFULL), |
172 |
me.name, client_p->name, chptr->chname, banid); |
173 |
return 0; |
174 |
} |
175 |
|
176 |
collapse(banid); |
177 |
} |
178 |
|
179 |
nuh.nuhmask = check_string(banid); |
180 |
nuh.nickptr = name; |
181 |
nuh.userptr = user; |
182 |
nuh.hostptr = host; |
183 |
|
184 |
nuh.nicksize = sizeof(name); |
185 |
nuh.usersize = sizeof(user); |
186 |
nuh.hostsize = sizeof(host); |
187 |
|
188 |
split_nuh(&nuh); |
189 |
|
190 |
/* |
191 |
* Re-assemble a new n!u@h and print it back to banid for sending |
192 |
* the mode to the channel. |
193 |
*/ |
194 |
len = sprintf(banid, "%s!%s@%s", name, user, host); |
195 |
|
196 |
switch (type) |
197 |
{ |
198 |
case CHFL_BAN: |
199 |
list = &chptr->banlist; |
200 |
clear_ban_cache(chptr); |
201 |
break; |
202 |
case CHFL_EXCEPTION: |
203 |
list = &chptr->exceptlist; |
204 |
clear_ban_cache(chptr); |
205 |
break; |
206 |
case CHFL_INVEX: |
207 |
list = &chptr->invexlist; |
208 |
break; |
209 |
default: |
210 |
assert(0); |
211 |
return 0; |
212 |
} |
213 |
|
214 |
DLINK_FOREACH(ban, list->head) |
215 |
{ |
216 |
ban_p = ban->data; |
217 |
if (!irccmp(ban_p->name, name) && |
218 |
!irccmp(ban_p->user, user) && |
219 |
!irccmp(ban_p->host, host)) |
220 |
{ |
221 |
return 0; |
222 |
} |
223 |
} |
224 |
|
225 |
ban_p = mp_pool_get(ban_pool); |
226 |
memset(ban_p, 0, sizeof(*ban_p)); |
227 |
ban_p->name = xstrdup(name); |
228 |
ban_p->user = xstrdup(user); |
229 |
ban_p->host = xstrdup(host); |
230 |
ban_p->when = CurrentTime; |
231 |
ban_p->len = len - 2; /* -2 for @ and ! */ |
232 |
ban_p->type = parse_netmask(host, &ban_p->addr, &ban_p->bits); |
233 |
|
234 |
if (IsClient(client_p)) |
235 |
{ |
236 |
ban_p->who = MyMalloc(strlen(client_p->name) + |
237 |
strlen(client_p->username) + |
238 |
strlen(client_p->host) + 3); |
239 |
sprintf(ban_p->who, "%s!%s@%s", client_p->name, |
240 |
client_p->username, client_p->host); |
241 |
} |
242 |
else if (IsHidden(client_p) || (IsServer(client_p) && ConfigServerHide.hide_servers)) |
243 |
ban_p->who = xstrdup(me.name); |
244 |
else |
245 |
ban_p->who = xstrdup(client_p->name); |
246 |
|
247 |
dlinkAdd(ban_p, &ban_p->node, list); |
248 |
|
249 |
return 1; |
250 |
} |
251 |
|
252 |
/* |
253 |
* inputs - pointer to channel |
254 |
* - pointer to ban id |
255 |
* - type of ban, i.e. ban, exception, invex |
256 |
* output - 0 for failure, 1 for success |
257 |
* side effects - |
258 |
*/ |
259 |
static int |
260 |
del_id(struct Channel *chptr, char *banid, int type) |
261 |
{ |
262 |
dlink_list *list; |
263 |
dlink_node *ban; |
264 |
struct Ban *banptr; |
265 |
char name[NICKLEN + 1]; |
266 |
char user[USERLEN + 1]; |
267 |
char host[HOSTLEN + 1]; |
268 |
struct split_nuh_item nuh; |
269 |
|
270 |
if (banid == NULL) |
271 |
return 0; |
272 |
|
273 |
nuh.nuhmask = check_string(banid); |
274 |
nuh.nickptr = name; |
275 |
nuh.userptr = user; |
276 |
nuh.hostptr = host; |
277 |
|
278 |
nuh.nicksize = sizeof(name); |
279 |
nuh.usersize = sizeof(user); |
280 |
nuh.hostsize = sizeof(host); |
281 |
|
282 |
split_nuh(&nuh); |
283 |
|
284 |
/* |
285 |
* Re-assemble a new n!u@h and print it back to banid for sending |
286 |
* the mode to the channel. |
287 |
*/ |
288 |
sprintf(banid, "%s!%s@%s", name, user, host); |
289 |
|
290 |
switch (type) |
291 |
{ |
292 |
case CHFL_BAN: |
293 |
list = &chptr->banlist; |
294 |
clear_ban_cache(chptr); |
295 |
break; |
296 |
case CHFL_EXCEPTION: |
297 |
list = &chptr->exceptlist; |
298 |
clear_ban_cache(chptr); |
299 |
break; |
300 |
case CHFL_INVEX: |
301 |
list = &chptr->invexlist; |
302 |
break; |
303 |
default: |
304 |
sendto_realops_flags(UMODE_ALL, L_ALL, SEND_NOTICE, |
305 |
"del_id() called with unknown ban type %d!", type); |
306 |
return 0; |
307 |
} |
308 |
|
309 |
DLINK_FOREACH(ban, list->head) |
310 |
{ |
311 |
banptr = ban->data; |
312 |
|
313 |
if (!irccmp(name, banptr->name) && |
314 |
!irccmp(user, banptr->user) && |
315 |
!irccmp(host, banptr->host)) |
316 |
{ |
317 |
remove_ban(banptr, list); |
318 |
return 1; |
319 |
} |
320 |
} |
321 |
|
322 |
return 0; |
323 |
} |
324 |
|
325 |
const struct mode_letter chan_modes[] = { |
326 |
{ MODE_NOCTRL, 'c' }, |
327 |
{ MODE_INVITEONLY, 'i' }, |
328 |
{ MODE_MODERATED, 'm' }, |
329 |
{ MODE_NOPRIVMSGS, 'n' }, |
330 |
{ MODE_PRIVATE, 'p' }, |
331 |
{ MODE_REGISTERED, 'r' }, |
332 |
{ MODE_SECRET, 's' }, |
333 |
{ MODE_TOPICLIMIT, 't' }, |
334 |
{ MODE_MODREG, 'M' }, |
335 |
{ MODE_OPERONLY, 'O' }, |
336 |
{ MODE_REGONLY, 'R' }, |
337 |
{ MODE_SSLONLY, 'S' }, |
338 |
{ 0, '\0' } |
339 |
}; |
340 |
|
341 |
/* channel_modes() |
342 |
* |
343 |
* inputs - pointer to channel |
344 |
* - pointer to client |
345 |
* - pointer to mode buf |
346 |
* - pointer to parameter buf |
347 |
* output - NONE |
348 |
* side effects - write the "simple" list of channel modes for channel |
349 |
* chptr onto buffer mbuf with the parameters in pbuf. |
350 |
*/ |
351 |
void |
352 |
channel_modes(struct Channel *chptr, struct Client *client_p, |
353 |
char *mbuf, char *pbuf) |
354 |
{ |
355 |
const struct mode_letter *tab = chan_modes; |
356 |
|
357 |
*mbuf++ = '+'; |
358 |
*pbuf = '\0'; |
359 |
|
360 |
for (; tab->mode; ++tab) |
361 |
if (chptr->mode.mode & tab->mode) |
362 |
*mbuf++ = tab->letter; |
363 |
|
364 |
if (chptr->mode.limit) |
365 |
{ |
366 |
*mbuf++ = 'l'; |
367 |
|
368 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr)) |
369 |
pbuf += sprintf(pbuf, "%d ", chptr->mode.limit); |
370 |
} |
371 |
|
372 |
if (chptr->mode.key[0]) |
373 |
{ |
374 |
*mbuf++ = 'k'; |
375 |
|
376 |
if (IsServer(client_p) || HasFlag(client_p, FLAGS_SERVICE) || IsMember(client_p, chptr)) |
377 |
sprintf(pbuf, "%s ", chptr->mode.key); |
378 |
} |
379 |
|
380 |
*mbuf = '\0'; |
381 |
} |
382 |
|
383 |
/* fix_key() |
384 |
* |
385 |
* inputs - pointer to key to clean up |
386 |
* output - pointer to cleaned up key |
387 |
* side effects - input string is modified |
388 |
* |
389 |
* stolen from Undernet's ircd -orabidoo |
390 |
*/ |
391 |
static char * |
392 |
fix_key(char *arg) |
393 |
{ |
394 |
unsigned char *s, *t, c; |
395 |
|
396 |
for (s = t = (unsigned char *)arg; (c = *s); s++) |
397 |
{ |
398 |
c &= 0x7f; |
399 |
if (c != ':' && c > ' ' && c != ',') |
400 |
*t++ = c; |
401 |
} |
402 |
|
403 |
*t = '\0'; |
404 |
return(arg); |
405 |
} |
406 |
|
407 |
/* fix_key_old() |
408 |
* |
409 |
* inputs - pointer to key to clean up |
410 |
* output - pointer to cleaned up key |
411 |
* side effects - input string is modifed |
412 |
* |
413 |
* Here we attempt to be compatible with older non-hybrid servers. |
414 |
* We can't back down from the ':' issue however. --Rodder |
415 |
*/ |
416 |
static char * |
417 |
fix_key_old(char *arg) |
418 |
{ |
419 |
unsigned char *s, *t, c; |
420 |
|
421 |
for (s = t = (unsigned char *)arg; (c = *s); s++) |
422 |
{ |
423 |
c &= 0x7f; |
424 |
if ((c != 0x0a) && (c != ':') && (c != 0x0d) && (c != ',')) |
425 |
*t++ = c; |
426 |
} |
427 |
|
428 |
*t = '\0'; |
429 |
return(arg); |
430 |
} |
431 |
|
432 |
/* bitmasks for various error returns that set_channel_mode should only return |
433 |
* once per call -orabidoo |
434 |
*/ |
435 |
|
436 |
#define SM_ERR_NOTS 0x00000001 /* No TS on channel */ |
437 |
#define SM_ERR_NOOPS 0x00000002 /* No chan ops */ |
438 |
#define SM_ERR_UNKNOWN 0x00000004 |
439 |
#define SM_ERR_RPL_B 0x00000008 |
440 |
#define SM_ERR_RPL_E 0x00000010 |
441 |
#define SM_ERR_NOTONCHANNEL 0x00000020 /* Not on channel */ |
442 |
#define SM_ERR_RPL_I 0x00000040 |
443 |
#define SM_ERR_NOTOPER 0x00000080 |
444 |
#define SM_ERR_ONLYSERVER 0x00000100 |
445 |
|
446 |
/* Now lets do some stuff to keep track of what combinations of |
447 |
* servers exist... |
448 |
* Note that the number of combinations doubles each time you add |
449 |
* something to this list. Each one is only quick if no servers use that |
450 |
* combination, but if the numbers get too high here MODE will get too |
451 |
* slow. I suggest if you get more than 7 here, you consider getting rid |
452 |
* of some and merging or something. If it wasn't for irc+cs we would |
453 |
* probably not even need to bother about most of these, but unfortunately |
454 |
* we do. -A1kmm |
455 |
*/ |
456 |
|
457 |
/* void init_chcap_usage_counts(void) |
458 |
* |
459 |
* Inputs - none |
460 |
* Output - none |
461 |
* Side-effects - Initialises the usage counts to zero. Fills in the |
462 |
* chcap_yes and chcap_no combination tables. |
463 |
*/ |
464 |
void |
465 |
init_chcap_usage_counts(void) |
466 |
{ |
467 |
unsigned long m, c, y, n; |
468 |
|
469 |
memset(chcap_combos, 0, sizeof(chcap_combos)); |
470 |
|
471 |
/* For every possible combination */ |
472 |
for (m = 0; m < NCHCAP_COMBOS; m++) |
473 |
{ |
474 |
/* Check each capab */ |
475 |
for (c = y = n = 0; c < NCHCAPS; c++) |
476 |
{ |
477 |
if ((m & (1 << c)) == 0) |
478 |
n |= channel_capabs[c]; |
479 |
else |
480 |
y |= channel_capabs[c]; |
481 |
} |
482 |
chcap_combos[m].cap_yes = y; |
483 |
chcap_combos[m].cap_no = n; |
484 |
} |
485 |
} |
486 |
|
487 |
/* void set_chcap_usage_counts(struct Client *serv_p) |
488 |
* Input: serv_p; The client whose capabs to register. |
489 |
* Output: none |
490 |
* Side-effects: Increments the usage counts for the correct capab |
491 |
* combination. |
492 |
*/ |
493 |
void |
494 |
set_chcap_usage_counts(struct Client *serv_p) |
495 |
{ |
496 |
int n; |
497 |
|
498 |
for (n = 0; n < NCHCAP_COMBOS; n++) |
499 |
{ |
500 |
if (((serv_p->localClient->caps & chcap_combos[n].cap_yes) == |
501 |
chcap_combos[n].cap_yes) && |
502 |
((serv_p->localClient->caps & chcap_combos[n].cap_no) == 0)) |
503 |
{ |
504 |
chcap_combos[n].count++; |
505 |
return; |
506 |
} |
507 |
} |
508 |
|
509 |
/* This should be impossible -A1kmm. */ |
510 |
assert(0); |
511 |
} |
512 |
|
513 |
/* void set_chcap_usage_counts(struct Client *serv_p) |
514 |
* |
515 |
* Inputs - serv_p; The client whose capabs to register. |
516 |
* Output - none |
517 |
* Side-effects - Decrements the usage counts for the correct capab |
518 |
* combination. |
519 |
*/ |
520 |
void |
521 |
unset_chcap_usage_counts(struct Client *serv_p) |
522 |
{ |
523 |
int n; |
524 |
|
525 |
for (n = 0; n < NCHCAP_COMBOS; n++) |
526 |
{ |
527 |
if ((serv_p->localClient->caps & chcap_combos[n].cap_yes) == |
528 |
chcap_combos[n].cap_yes && |
529 |
(serv_p->localClient->caps & chcap_combos[n].cap_no) == 0) |
530 |
{ |
531 |
/* Hopefully capabs can't change dynamically or anything... */ |
532 |
assert(chcap_combos[n].count > 0); |
533 |
chcap_combos[n].count--; |
534 |
return; |
535 |
} |
536 |
} |
537 |
|
538 |
/* This should be impossible -A1kmm. */ |
539 |
assert(0); |
540 |
} |
541 |
|
542 |
/* Mode functions handle mode changes for a particular mode... */ |
543 |
static void |
544 |
chm_nosuch(struct Client *client_p, struct Client *source_p, |
545 |
struct Channel *chptr, int parc, int *parn, |
546 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
547 |
const char *chname) |
548 |
{ |
549 |
if (*errors & SM_ERR_UNKNOWN) |
550 |
return; |
551 |
|
552 |
*errors |= SM_ERR_UNKNOWN; |
553 |
sendto_one(source_p, form_str(ERR_UNKNOWNMODE), me.name, |
554 |
source_p->name, c); |
555 |
} |
556 |
|
557 |
static void |
558 |
chm_simple(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
559 |
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
560 |
char c, void *d, const char *chname) |
561 |
{ |
562 |
long mode_type; |
563 |
|
564 |
mode_type = (long)d; |
565 |
|
566 |
if ((alev < CHACCESS_HALFOP) || |
567 |
((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
568 |
{ |
569 |
if (!(*errors & SM_ERR_NOOPS)) |
570 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
571 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
572 |
me.name, source_p->name, chname); |
573 |
*errors |= SM_ERR_NOOPS; |
574 |
return; |
575 |
} |
576 |
|
577 |
/* If have already dealt with this simple mode, ignore it */ |
578 |
if (simple_modes_mask & mode_type) |
579 |
return; |
580 |
|
581 |
simple_modes_mask |= mode_type; |
582 |
|
583 |
/* setting + */ |
584 |
/* Apparently, (though no one has ever told the hybrid group directly) |
585 |
* admins don't like redundant mode checking. ok. It would have been nice |
586 |
* if you had have told us directly. I've left the original code snippets |
587 |
* in place. |
588 |
* |
589 |
* -Dianora |
590 |
*/ |
591 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
592 |
{ |
593 |
chptr->mode.mode |= mode_type; |
594 |
|
595 |
mode_changes[mode_count].letter = c; |
596 |
mode_changes[mode_count].dir = MODE_ADD; |
597 |
mode_changes[mode_count].caps = 0; |
598 |
mode_changes[mode_count].nocaps = 0; |
599 |
mode_changes[mode_count].id = NULL; |
600 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
601 |
mode_changes[mode_count++].arg = NULL; |
602 |
} |
603 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
604 |
{ |
605 |
/* setting - */ |
606 |
|
607 |
chptr->mode.mode &= ~mode_type; |
608 |
|
609 |
mode_changes[mode_count].letter = c; |
610 |
mode_changes[mode_count].dir = MODE_DEL; |
611 |
mode_changes[mode_count].caps = 0; |
612 |
mode_changes[mode_count].nocaps = 0; |
613 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
614 |
mode_changes[mode_count].id = NULL; |
615 |
mode_changes[mode_count++].arg = NULL; |
616 |
} |
617 |
} |
618 |
|
619 |
static void |
620 |
chm_registered(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
621 |
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
622 |
char c, void *d, const char *chname) |
623 |
{ |
624 |
long mode_type; |
625 |
|
626 |
mode_type = (long)d; |
627 |
|
628 |
|
629 |
if (!IsServer(source_p) && !HasFlag(source_p, FLAGS_SERVICE)) |
630 |
{ |
631 |
if (!(*errors & SM_ERR_ONLYSERVER)) |
632 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
633 |
ERR_NOTONCHANNEL : ERR_ONLYSERVERSCANCHANGE), |
634 |
me.name, source_p->name, chname); |
635 |
*errors |= SM_ERR_ONLYSERVER; |
636 |
return; |
637 |
} |
638 |
|
639 |
/* If have already dealt with this simple mode, ignore it */ |
640 |
if (simple_modes_mask & mode_type) |
641 |
return; |
642 |
|
643 |
simple_modes_mask |= mode_type; |
644 |
|
645 |
/* setting + */ |
646 |
/* Apparently, (though no one has ever told the hybrid group directly) |
647 |
* admins don't like redundant mode checking. ok. It would have been nice |
648 |
* if you had have told us directly. I've left the original code snippets |
649 |
* in place. |
650 |
* |
651 |
* -Dianora |
652 |
*/ |
653 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
654 |
{ |
655 |
chptr->mode.mode |= mode_type; |
656 |
|
657 |
mode_changes[mode_count].letter = c; |
658 |
mode_changes[mode_count].dir = MODE_ADD; |
659 |
mode_changes[mode_count].caps = 0; |
660 |
mode_changes[mode_count].nocaps = 0; |
661 |
mode_changes[mode_count].id = NULL; |
662 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
663 |
mode_changes[mode_count++].arg = NULL; |
664 |
} |
665 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
666 |
{ |
667 |
/* setting - */ |
668 |
|
669 |
chptr->mode.mode &= ~mode_type; |
670 |
|
671 |
mode_changes[mode_count].letter = c; |
672 |
mode_changes[mode_count].dir = MODE_DEL; |
673 |
mode_changes[mode_count].caps = 0; |
674 |
mode_changes[mode_count].nocaps = 0; |
675 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
676 |
mode_changes[mode_count].id = NULL; |
677 |
mode_changes[mode_count++].arg = NULL; |
678 |
} |
679 |
} |
680 |
|
681 |
static void |
682 |
chm_operonly(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
683 |
int parc, int *parn, char **parv, int *errors, int alev, int dir, |
684 |
char c, void *d, const char *chname) |
685 |
{ |
686 |
long mode_type; |
687 |
|
688 |
mode_type = (long)d; |
689 |
|
690 |
if ((alev < CHACCESS_HALFOP) || |
691 |
((mode_type == MODE_PRIVATE) && (alev < CHACCESS_CHANOP))) |
692 |
{ |
693 |
if (!(*errors & SM_ERR_NOOPS)) |
694 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
695 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
696 |
me.name, source_p->name, chname); |
697 |
*errors |= SM_ERR_NOOPS; |
698 |
return; |
699 |
} |
700 |
else if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER)) |
701 |
{ |
702 |
if (!(*errors & SM_ERR_NOTOPER)) |
703 |
{ |
704 |
if (alev == CHACCESS_NOTONCHAN) |
705 |
sendto_one(source_p, form_str(ERR_NOTONCHANNEL), |
706 |
me.name, source_p->name, chname); |
707 |
else |
708 |
sendto_one(source_p, form_str(ERR_NOPRIVILEGES), |
709 |
me.name, source_p->name); |
710 |
} |
711 |
|
712 |
*errors |= SM_ERR_NOTOPER; |
713 |
return; |
714 |
} |
715 |
|
716 |
/* If have already dealt with this simple mode, ignore it */ |
717 |
if (simple_modes_mask & mode_type) |
718 |
return; |
719 |
|
720 |
simple_modes_mask |= mode_type; |
721 |
|
722 |
if (dir == MODE_ADD) /* && !(chptr->mode.mode & mode_type)) */ |
723 |
{ |
724 |
chptr->mode.mode |= mode_type; |
725 |
|
726 |
mode_changes[mode_count].letter = c; |
727 |
mode_changes[mode_count].dir = MODE_ADD; |
728 |
mode_changes[mode_count].caps = 0; |
729 |
mode_changes[mode_count].nocaps = 0; |
730 |
mode_changes[mode_count].id = NULL; |
731 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
732 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
733 |
mode_changes[mode_count++].arg = NULL; |
734 |
} |
735 |
else if (dir == MODE_DEL) /* && (chptr->mode.mode & mode_type)) */ |
736 |
{ |
737 |
/* setting - */ |
738 |
|
739 |
chptr->mode.mode &= ~mode_type; |
740 |
|
741 |
mode_changes[mode_count].letter = c; |
742 |
mode_changes[mode_count].dir = MODE_DEL; |
743 |
mode_changes[mode_count].caps = 0; |
744 |
mode_changes[mode_count].nocaps = 0; |
745 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
746 |
mode_changes[mode_count].id = NULL; |
747 |
mode_changes[mode_count++].arg = NULL; |
748 |
} |
749 |
} |
750 |
|
751 |
static void |
752 |
chm_ban(struct Client *client_p, struct Client *source_p, |
753 |
struct Channel *chptr, int parc, int *parn, |
754 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
755 |
const char *chname) |
756 |
{ |
757 |
char *mask = NULL; |
758 |
|
759 |
if (dir == MODE_QUERY || parc <= *parn) |
760 |
{ |
761 |
dlink_node *ptr = NULL; |
762 |
|
763 |
if (*errors & SM_ERR_RPL_B) |
764 |
return; |
765 |
|
766 |
*errors |= SM_ERR_RPL_B; |
767 |
|
768 |
DLINK_FOREACH(ptr, chptr->banlist.head) |
769 |
{ |
770 |
const struct Ban *banptr = ptr->data; |
771 |
sendto_one(client_p, form_str(RPL_BANLIST), |
772 |
me.name, client_p->name, chname, |
773 |
banptr->name, banptr->user, banptr->host, |
774 |
banptr->who, banptr->when); |
775 |
} |
776 |
|
777 |
sendto_one(source_p, form_str(RPL_ENDOFBANLIST), me.name, |
778 |
source_p->name, chname); |
779 |
return; |
780 |
} |
781 |
|
782 |
if (alev < CHACCESS_HALFOP) |
783 |
{ |
784 |
if (!(*errors & SM_ERR_NOOPS)) |
785 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
786 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
787 |
me.name, source_p->name, chname); |
788 |
*errors |= SM_ERR_NOOPS; |
789 |
return; |
790 |
} |
791 |
|
792 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
793 |
return; |
794 |
|
795 |
mask = nuh_mask[*parn]; |
796 |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
797 |
++*parn; |
798 |
|
799 |
if (IsServer(client_p)) |
800 |
if (strchr(mask, ' ')) |
801 |
return; |
802 |
|
803 |
switch (dir) |
804 |
{ |
805 |
case MODE_ADD: |
806 |
if (!add_id(source_p, chptr, mask, CHFL_BAN)) |
807 |
return; |
808 |
break; |
809 |
case MODE_DEL: |
810 |
if (!del_id(chptr, mask, CHFL_BAN)) |
811 |
return; |
812 |
break; |
813 |
default: |
814 |
assert(0); |
815 |
} |
816 |
|
817 |
mode_changes[mode_count].letter = c; |
818 |
mode_changes[mode_count].dir = dir; |
819 |
mode_changes[mode_count].caps = 0; |
820 |
mode_changes[mode_count].nocaps = 0; |
821 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
822 |
mode_changes[mode_count].id = NULL; |
823 |
mode_changes[mode_count++].arg = mask; |
824 |
} |
825 |
|
826 |
static void |
827 |
chm_except(struct Client *client_p, struct Client *source_p, |
828 |
struct Channel *chptr, int parc, int *parn, |
829 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
830 |
const char *chname) |
831 |
{ |
832 |
char *mask = NULL; |
833 |
|
834 |
if (alev < CHACCESS_HALFOP) |
835 |
{ |
836 |
if (!(*errors & SM_ERR_NOOPS)) |
837 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
838 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
839 |
me.name, source_p->name, chname); |
840 |
*errors |= SM_ERR_NOOPS; |
841 |
return; |
842 |
} |
843 |
|
844 |
if (dir == MODE_QUERY || parc <= *parn) |
845 |
{ |
846 |
dlink_node *ptr = NULL; |
847 |
|
848 |
if (*errors & SM_ERR_RPL_E) |
849 |
return; |
850 |
|
851 |
*errors |= SM_ERR_RPL_E; |
852 |
|
853 |
DLINK_FOREACH(ptr, chptr->exceptlist.head) |
854 |
{ |
855 |
const struct Ban *banptr = ptr->data; |
856 |
sendto_one(client_p, form_str(RPL_EXCEPTLIST), |
857 |
me.name, client_p->name, chname, |
858 |
banptr->name, banptr->user, banptr->host, |
859 |
banptr->who, banptr->when); |
860 |
} |
861 |
|
862 |
sendto_one(source_p, form_str(RPL_ENDOFEXCEPTLIST), me.name, |
863 |
source_p->name, chname); |
864 |
return; |
865 |
} |
866 |
|
867 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
868 |
return; |
869 |
|
870 |
mask = nuh_mask[*parn]; |
871 |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
872 |
++*parn; |
873 |
|
874 |
if (IsServer(client_p)) |
875 |
if (strchr(mask, ' ')) |
876 |
return; |
877 |
|
878 |
switch (dir) |
879 |
{ |
880 |
case MODE_ADD: |
881 |
if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION)) |
882 |
return; |
883 |
break; |
884 |
case MODE_DEL: |
885 |
if (!del_id(chptr, mask, CHFL_EXCEPTION)) |
886 |
return; |
887 |
break; |
888 |
default: |
889 |
assert(0); |
890 |
} |
891 |
|
892 |
mode_changes[mode_count].letter = c; |
893 |
mode_changes[mode_count].dir = dir; |
894 |
mode_changes[mode_count].caps = 0; |
895 |
mode_changes[mode_count].nocaps = 0; |
896 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
897 |
mode_changes[mode_count].id = NULL; |
898 |
mode_changes[mode_count++].arg = mask; |
899 |
} |
900 |
|
901 |
static void |
902 |
chm_invex(struct Client *client_p, struct Client *source_p, |
903 |
struct Channel *chptr, int parc, int *parn, |
904 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
905 |
const char *chname) |
906 |
{ |
907 |
char *mask = NULL; |
908 |
|
909 |
if (alev < CHACCESS_HALFOP) |
910 |
{ |
911 |
if (!(*errors & SM_ERR_NOOPS)) |
912 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
913 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
914 |
me.name, source_p->name, chname); |
915 |
*errors |= SM_ERR_NOOPS; |
916 |
return; |
917 |
} |
918 |
|
919 |
if (dir == MODE_QUERY || parc <= *parn) |
920 |
{ |
921 |
dlink_node *ptr = NULL; |
922 |
|
923 |
if (*errors & SM_ERR_RPL_I) |
924 |
return; |
925 |
|
926 |
*errors |= SM_ERR_RPL_I; |
927 |
|
928 |
DLINK_FOREACH(ptr, chptr->invexlist.head) |
929 |
{ |
930 |
const struct Ban *banptr = ptr->data; |
931 |
sendto_one(client_p, form_str(RPL_INVITELIST), me.name, |
932 |
client_p->name, chname, |
933 |
banptr->name, banptr->user, banptr->host, |
934 |
banptr->who, banptr->when); |
935 |
} |
936 |
|
937 |
sendto_one(source_p, form_str(RPL_ENDOFINVITELIST), me.name, |
938 |
source_p->name, chname); |
939 |
return; |
940 |
} |
941 |
|
942 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
943 |
return; |
944 |
|
945 |
mask = nuh_mask[*parn]; |
946 |
memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn])); |
947 |
++*parn; |
948 |
|
949 |
if (IsServer(client_p)) |
950 |
if (strchr(mask, ' ')) |
951 |
return; |
952 |
|
953 |
switch (dir) |
954 |
{ |
955 |
case MODE_ADD: |
956 |
if (!add_id(source_p, chptr, mask, CHFL_INVEX)) |
957 |
return; |
958 |
break; |
959 |
case MODE_DEL: |
960 |
if (!del_id(chptr, mask, CHFL_INVEX)) |
961 |
return; |
962 |
break; |
963 |
default: |
964 |
assert(0); |
965 |
} |
966 |
|
967 |
mode_changes[mode_count].letter = c; |
968 |
mode_changes[mode_count].dir = dir; |
969 |
mode_changes[mode_count].caps = 0; |
970 |
mode_changes[mode_count].nocaps = 0; |
971 |
mode_changes[mode_count].mems = ONLY_CHANOPS; |
972 |
mode_changes[mode_count].id = NULL; |
973 |
mode_changes[mode_count++].arg = mask; |
974 |
} |
975 |
|
976 |
/* |
977 |
* inputs - pointer to channel |
978 |
* output - none |
979 |
* side effects - clear ban cache |
980 |
*/ |
981 |
void |
982 |
clear_ban_cache(struct Channel *chptr) |
983 |
{ |
984 |
dlink_node *ptr = NULL; |
985 |
|
986 |
DLINK_FOREACH(ptr, chptr->members.head) |
987 |
{ |
988 |
struct Membership *ms = ptr->data; |
989 |
|
990 |
if (MyConnect(ms->client_p)) |
991 |
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
992 |
} |
993 |
} |
994 |
|
995 |
void |
996 |
clear_ban_cache_client(struct Client *client_p) |
997 |
{ |
998 |
dlink_node *ptr = NULL; |
999 |
|
1000 |
DLINK_FOREACH(ptr, client_p->channel.head) |
1001 |
{ |
1002 |
struct Membership *ms = ptr->data; |
1003 |
ms->flags &= ~(CHFL_BAN_SILENCED|CHFL_BAN_CHECKED); |
1004 |
} |
1005 |
} |
1006 |
|
1007 |
static void |
1008 |
chm_op(struct Client *client_p, struct Client *source_p, |
1009 |
struct Channel *chptr, int parc, int *parn, |
1010 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
1011 |
const char *chname) |
1012 |
{ |
1013 |
char *opnick; |
1014 |
struct Client *targ_p; |
1015 |
struct Membership *member; |
1016 |
int caps = 0; |
1017 |
|
1018 |
if (alev < CHACCESS_CHANOP) |
1019 |
{ |
1020 |
if (!(*errors & SM_ERR_NOOPS)) |
1021 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1022 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1023 |
me.name, source_p->name, chname); |
1024 |
*errors |= SM_ERR_NOOPS; |
1025 |
return; |
1026 |
} |
1027 |
|
1028 |
if ((dir == MODE_QUERY) || (parc <= *parn)) |
1029 |
return; |
1030 |
|
1031 |
opnick = parv[(*parn)++]; |
1032 |
|
1033 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1034 |
return; |
1035 |
if (!IsClient(targ_p)) |
1036 |
return; |
1037 |
|
1038 |
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1039 |
{ |
1040 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1041 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1042 |
me.name, source_p->name, opnick, chname); |
1043 |
*errors |= SM_ERR_NOTONCHANNEL; |
1044 |
return; |
1045 |
} |
1046 |
|
1047 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1048 |
return; |
1049 |
|
1050 |
/* no redundant mode changes */ |
1051 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP)) |
1052 |
return; |
1053 |
if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP)) |
1054 |
{ |
1055 |
#ifdef HALFOPS |
1056 |
if (has_member_flags(member, CHFL_HALFOP)) |
1057 |
{ |
1058 |
--*parn; |
1059 |
chm_hop(client_p, source_p, chptr, parc, parn, parv, errors, alev, |
1060 |
dir, c, d, chname); |
1061 |
} |
1062 |
#endif |
1063 |
return; |
1064 |
} |
1065 |
|
1066 |
#ifdef HALFOPS |
1067 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP)) |
1068 |
{ |
1069 |
/* promoting from % to @ is visible only to CAP_HOPS servers */ |
1070 |
mode_changes[mode_count].letter = 'h'; |
1071 |
mode_changes[mode_count].dir = MODE_DEL; |
1072 |
mode_changes[mode_count].caps = caps = CAP_HOPS; |
1073 |
mode_changes[mode_count].nocaps = 0; |
1074 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1075 |
mode_changes[mode_count].id = NULL; |
1076 |
mode_changes[mode_count].arg = targ_p->name; |
1077 |
mode_changes[mode_count++].client = targ_p; |
1078 |
} |
1079 |
#endif |
1080 |
|
1081 |
mode_changes[mode_count].letter = 'o'; |
1082 |
mode_changes[mode_count].dir = dir; |
1083 |
mode_changes[mode_count].caps = caps; |
1084 |
mode_changes[mode_count].nocaps = 0; |
1085 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1086 |
mode_changes[mode_count].id = targ_p->id; |
1087 |
mode_changes[mode_count].arg = targ_p->name; |
1088 |
mode_changes[mode_count++].client = targ_p; |
1089 |
|
1090 |
if (dir == MODE_ADD) |
1091 |
{ |
1092 |
AddMemberFlag(member, CHFL_CHANOP); |
1093 |
DelMemberFlag(member, CHFL_DEOPPED | CHFL_HALFOP); |
1094 |
} |
1095 |
else |
1096 |
DelMemberFlag(member, CHFL_CHANOP); |
1097 |
} |
1098 |
|
1099 |
#ifdef HALFOPS |
1100 |
static void |
1101 |
chm_hop(struct Client *client_p, struct Client *source_p, |
1102 |
struct Channel *chptr, int parc, int *parn, |
1103 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
1104 |
const char *chname) |
1105 |
{ |
1106 |
char *opnick; |
1107 |
struct Client *targ_p; |
1108 |
struct Membership *member; |
1109 |
|
1110 |
/* *sigh* - dont allow halfops to set +/-h, they could fully control a |
1111 |
* channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE |
1112 |
* when used with MODE_SECRET is paranoid - cant use +p |
1113 |
* |
1114 |
* it needs to be optional per channel - but not via +p, that or remove |
1115 |
* paranoid.. -- fl_ |
1116 |
* |
1117 |
* +p means paranoid, it is useless for anything else on modern IRC, as |
1118 |
* list isn't really usable. If you want to have a private channel these |
1119 |
* days, you set it +s. Halfops can no longer remove simple modes when |
1120 |
* +p is set (although they can set +p) so it is safe to use this to |
1121 |
* control whether they can (de)halfop... |
1122 |
*/ |
1123 |
if (alev < |
1124 |
((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP)) |
1125 |
{ |
1126 |
if (!(*errors & SM_ERR_NOOPS)) |
1127 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1128 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1129 |
me.name, source_p->name, chname); |
1130 |
*errors |= SM_ERR_NOOPS; |
1131 |
return; |
1132 |
} |
1133 |
|
1134 |
if ((dir == MODE_QUERY) || (parc <= *parn)) |
1135 |
return; |
1136 |
|
1137 |
opnick = parv[(*parn)++]; |
1138 |
|
1139 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1140 |
return; |
1141 |
if (!IsClient(targ_p)) |
1142 |
return; |
1143 |
|
1144 |
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1145 |
{ |
1146 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1147 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1148 |
me.name, source_p->name, opnick, chname); |
1149 |
*errors |= SM_ERR_NOTONCHANNEL; |
1150 |
return; |
1151 |
} |
1152 |
|
1153 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1154 |
return; |
1155 |
|
1156 |
/* no redundant mode changes */ |
1157 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP | CHFL_CHANOP)) |
1158 |
return; |
1159 |
if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP)) |
1160 |
return; |
1161 |
|
1162 |
mode_changes[mode_count].letter = 'h'; |
1163 |
mode_changes[mode_count].dir = dir; |
1164 |
mode_changes[mode_count].caps = CAP_HOPS; |
1165 |
mode_changes[mode_count].nocaps = 0; |
1166 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1167 |
mode_changes[mode_count].id = targ_p->id; |
1168 |
mode_changes[mode_count].arg = targ_p->name; |
1169 |
mode_changes[mode_count++].client = targ_p; |
1170 |
|
1171 |
mode_changes[mode_count].letter = 'o'; |
1172 |
mode_changes[mode_count].dir = dir; |
1173 |
mode_changes[mode_count].caps = 0; |
1174 |
mode_changes[mode_count].nocaps = CAP_HOPS; |
1175 |
mode_changes[mode_count].mems = ONLY_SERVERS; |
1176 |
mode_changes[mode_count].id = targ_p->id; |
1177 |
mode_changes[mode_count].arg = targ_p->name; |
1178 |
mode_changes[mode_count++].client = targ_p; |
1179 |
|
1180 |
if (dir == MODE_ADD) |
1181 |
{ |
1182 |
AddMemberFlag(member, CHFL_HALFOP); |
1183 |
DelMemberFlag(member, CHFL_DEOPPED); |
1184 |
} |
1185 |
else |
1186 |
DelMemberFlag(member, CHFL_HALFOP); |
1187 |
} |
1188 |
#endif |
1189 |
|
1190 |
static void |
1191 |
chm_voice(struct Client *client_p, struct Client *source_p, |
1192 |
struct Channel *chptr, int parc, int *parn, |
1193 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
1194 |
const char *chname) |
1195 |
{ |
1196 |
char *opnick; |
1197 |
struct Client *targ_p; |
1198 |
struct Membership *member; |
1199 |
|
1200 |
if (alev < CHACCESS_HALFOP) |
1201 |
{ |
1202 |
if (!(*errors & SM_ERR_NOOPS)) |
1203 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1204 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1205 |
me.name, source_p->name, chname); |
1206 |
*errors |= SM_ERR_NOOPS; |
1207 |
return; |
1208 |
} |
1209 |
|
1210 |
if ((dir == MODE_QUERY) || parc <= *parn) |
1211 |
return; |
1212 |
|
1213 |
opnick = parv[(*parn)++]; |
1214 |
|
1215 |
if ((targ_p = find_chasing(source_p, opnick, NULL)) == NULL) |
1216 |
return; |
1217 |
if (!IsClient(targ_p)) |
1218 |
return; |
1219 |
|
1220 |
if ((member = find_channel_link(targ_p, chptr)) == NULL) |
1221 |
{ |
1222 |
if (!(*errors & SM_ERR_NOTONCHANNEL)) |
1223 |
sendto_one(source_p, form_str(ERR_USERNOTINCHANNEL), |
1224 |
me.name, source_p->name, opnick, chname); |
1225 |
*errors |= SM_ERR_NOTONCHANNEL; |
1226 |
return; |
1227 |
} |
1228 |
|
1229 |
if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS)) |
1230 |
return; |
1231 |
|
1232 |
/* no redundant mode changes */ |
1233 |
if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE)) |
1234 |
return; |
1235 |
if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE)) |
1236 |
return; |
1237 |
|
1238 |
mode_changes[mode_count].letter = 'v'; |
1239 |
mode_changes[mode_count].dir = dir; |
1240 |
mode_changes[mode_count].caps = 0; |
1241 |
mode_changes[mode_count].nocaps = 0; |
1242 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1243 |
mode_changes[mode_count].id = targ_p->id; |
1244 |
mode_changes[mode_count].arg = targ_p->name; |
1245 |
mode_changes[mode_count++].client = targ_p; |
1246 |
|
1247 |
if (dir == MODE_ADD) |
1248 |
AddMemberFlag(member, CHFL_VOICE); |
1249 |
else |
1250 |
DelMemberFlag(member, CHFL_VOICE); |
1251 |
} |
1252 |
|
1253 |
static void |
1254 |
chm_limit(struct Client *client_p, struct Client *source_p, |
1255 |
struct Channel *chptr, int parc, int *parn, |
1256 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
1257 |
const char *chname) |
1258 |
{ |
1259 |
int i, limit; |
1260 |
char *lstr; |
1261 |
|
1262 |
if (alev < CHACCESS_HALFOP) |
1263 |
{ |
1264 |
if (!(*errors & SM_ERR_NOOPS)) |
1265 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1266 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1267 |
me.name, source_p->name, chname); |
1268 |
*errors |= SM_ERR_NOOPS; |
1269 |
return; |
1270 |
} |
1271 |
|
1272 |
if (dir == MODE_QUERY) |
1273 |
return; |
1274 |
|
1275 |
if ((dir == MODE_ADD) && parc > *parn) |
1276 |
{ |
1277 |
lstr = parv[(*parn)++]; |
1278 |
|
1279 |
if ((limit = atoi(lstr)) <= 0) |
1280 |
return; |
1281 |
|
1282 |
sprintf(lstr, "%d", limit); |
1283 |
|
1284 |
/* if somebody sets MODE #channel +ll 1 2, accept latter --fl */ |
1285 |
for (i = 0; i < mode_count; i++) |
1286 |
{ |
1287 |
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1288 |
mode_changes[i].letter = 0; |
1289 |
} |
1290 |
|
1291 |
mode_changes[mode_count].letter = c; |
1292 |
mode_changes[mode_count].dir = MODE_ADD; |
1293 |
mode_changes[mode_count].caps = 0; |
1294 |
mode_changes[mode_count].nocaps = 0; |
1295 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1296 |
mode_changes[mode_count].id = NULL; |
1297 |
mode_changes[mode_count++].arg = lstr; |
1298 |
|
1299 |
chptr->mode.limit = limit; |
1300 |
} |
1301 |
else if (dir == MODE_DEL) |
1302 |
{ |
1303 |
if (!chptr->mode.limit) |
1304 |
return; |
1305 |
|
1306 |
chptr->mode.limit = 0; |
1307 |
|
1308 |
mode_changes[mode_count].letter = c; |
1309 |
mode_changes[mode_count].dir = MODE_DEL; |
1310 |
mode_changes[mode_count].caps = 0; |
1311 |
mode_changes[mode_count].nocaps = 0; |
1312 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1313 |
mode_changes[mode_count].id = NULL; |
1314 |
mode_changes[mode_count++].arg = NULL; |
1315 |
} |
1316 |
} |
1317 |
|
1318 |
static void |
1319 |
chm_key(struct Client *client_p, struct Client *source_p, |
1320 |
struct Channel *chptr, int parc, int *parn, |
1321 |
char **parv, int *errors, int alev, int dir, char c, void *d, |
1322 |
const char *chname) |
1323 |
{ |
1324 |
int i; |
1325 |
char *key; |
1326 |
|
1327 |
if (alev < CHACCESS_HALFOP) |
1328 |
{ |
1329 |
if (!(*errors & SM_ERR_NOOPS)) |
1330 |
sendto_one(source_p, form_str(alev == CHACCESS_NOTONCHAN ? |
1331 |
ERR_NOTONCHANNEL : ERR_CHANOPRIVSNEEDED), |
1332 |
me.name, source_p->name, chname); |
1333 |
*errors |= SM_ERR_NOOPS; |
1334 |
return; |
1335 |
} |
1336 |
|
1337 |
if (dir == MODE_QUERY) |
1338 |
return; |
1339 |
|
1340 |
if ((dir == MODE_ADD) && parc > *parn) |
1341 |
{ |
1342 |
key = parv[(*parn)++]; |
1343 |
|
1344 |
if (MyClient(source_p)) |
1345 |
fix_key(key); |
1346 |
else |
1347 |
fix_key_old(key); |
1348 |
|
1349 |
if (*key == '\0') |
1350 |
return; |
1351 |
|
1352 |
assert(key[0] != ' '); |
1353 |
strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key)); |
1354 |
|
1355 |
/* if somebody does MODE #channel +kk a b, accept latter --fl */ |
1356 |
for (i = 0; i < mode_count; i++) |
1357 |
{ |
1358 |
if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD) |
1359 |
mode_changes[i].letter = 0; |
1360 |
} |
1361 |
|
1362 |
mode_changes[mode_count].letter = c; |
1363 |
mode_changes[mode_count].dir = MODE_ADD; |
1364 |
mode_changes[mode_count].caps = 0; |
1365 |
mode_changes[mode_count].nocaps = 0; |
1366 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1367 |
mode_changes[mode_count].id = NULL; |
1368 |
mode_changes[mode_count++].arg = chptr->mode.key; |
1369 |
} |
1370 |
else if (dir == MODE_DEL) |
1371 |
{ |
1372 |
if (parc > *parn) |
1373 |
(*parn)++; |
1374 |
|
1375 |
if (chptr->mode.key[0] == '\0') |
1376 |
return; |
1377 |
|
1378 |
chptr->mode.key[0] = '\0'; |
1379 |
|
1380 |
mode_changes[mode_count].letter = c; |
1381 |
mode_changes[mode_count].dir = MODE_DEL; |
1382 |
mode_changes[mode_count].caps = 0; |
1383 |
mode_changes[mode_count].nocaps = 0; |
1384 |
mode_changes[mode_count].mems = ALL_MEMBERS; |
1385 |
mode_changes[mode_count].id = NULL; |
1386 |
mode_changes[mode_count++].arg = "*"; |
1387 |
} |
1388 |
} |
1389 |
|
1390 |
struct ChannelMode |
1391 |
{ |
1392 |
void (*func) (struct Client *client_p, struct Client *source_p, |
1393 |
struct Channel *chptr, int parc, int *parn, char **parv, |
1394 |
int *errors, int alev, int dir, char c, void *d, |
1395 |
const char *chname); |
1396 |
void *d; |
1397 |
}; |
1398 |
|
1399 |
static struct ChannelMode ModeTable[255] = |
1400 |
{ |
1401 |
{chm_nosuch, NULL}, |
1402 |
{chm_nosuch, NULL}, /* A */ |
1403 |
{chm_nosuch, NULL}, /* B */ |
1404 |
{chm_nosuch, NULL}, /* C */ |
1405 |
{chm_nosuch, NULL}, /* D */ |
1406 |
{chm_nosuch, NULL}, /* E */ |
1407 |
{chm_nosuch, NULL}, /* F */ |
1408 |
{chm_nosuch, NULL}, /* G */ |
1409 |
{chm_nosuch, NULL}, /* H */ |
1410 |
{chm_invex, NULL}, /* I */ |
1411 |
{chm_nosuch, NULL}, /* J */ |
1412 |
{chm_nosuch, NULL}, /* K */ |
1413 |
{chm_nosuch, NULL}, /* L */ |
1414 |
{chm_simple, (void *)MODE_MODREG}, /* M */ |
1415 |
{chm_nosuch, NULL}, /* N */ |
1416 |
{chm_operonly, (void *) MODE_OPERONLY}, /* O */ |
1417 |
{chm_nosuch, NULL}, /* P */ |
1418 |
{chm_nosuch, NULL}, /* Q */ |
1419 |
{chm_simple, (void *) MODE_REGONLY}, /* R */ |
1420 |
{chm_simple, (void *) MODE_SSLONLY}, /* S */ |
1421 |
{chm_nosuch, NULL}, /* T */ |
1422 |
{chm_nosuch, NULL}, /* U */ |
1423 |
{chm_nosuch, NULL}, /* V */ |
1424 |
{chm_nosuch, NULL}, /* W */ |
1425 |
{chm_nosuch, NULL}, /* X */ |
1426 |
{chm_nosuch, NULL}, /* Y */ |
1427 |
{chm_nosuch, NULL}, /* Z */ |
1428 |
{chm_nosuch, NULL}, |
1429 |
{chm_nosuch, NULL}, |
1430 |
{chm_nosuch, NULL}, |
1431 |
{chm_nosuch, NULL}, |
1432 |
{chm_nosuch, NULL}, |
1433 |
{chm_nosuch, NULL}, |
1434 |
{chm_nosuch, NULL}, /* a */ |
1435 |
{chm_ban, NULL}, /* b */ |
1436 |
{chm_simple, (void *) MODE_NOCTRL}, /* c */ |
1437 |
{chm_nosuch, NULL}, /* d */ |
1438 |
{chm_except, NULL}, /* e */ |
1439 |
{chm_nosuch, NULL}, /* f */ |
1440 |
{chm_nosuch, NULL}, /* g */ |
1441 |
#ifdef HALFOPS |
1442 |
{chm_hop, NULL}, /* h */ |
1443 |
#else |
1444 |
{chm_nosuch, NULL}, /* h */ |
1445 |
#endif |
1446 |
{chm_simple, (void *) MODE_INVITEONLY}, /* i */ |
1447 |
{chm_nosuch, NULL}, /* j */ |
1448 |
{chm_key, NULL}, /* k */ |
1449 |
{chm_limit, NULL}, /* l */ |
1450 |
{chm_simple, (void *) MODE_MODERATED}, /* m */ |
1451 |
{chm_simple, (void *) MODE_NOPRIVMSGS}, /* n */ |
1452 |
{chm_op, NULL}, /* o */ |
1453 |
{chm_simple, (void *) MODE_PRIVATE}, /* p */ |
1454 |
{chm_nosuch, NULL}, /* q */ |
1455 |
{chm_registered, (void *) MODE_REGISTERED}, /* r */ |
1456 |
{chm_simple, (void *) MODE_SECRET}, /* s */ |
1457 |
{chm_simple, (void *) MODE_TOPICLIMIT}, /* t */ |
1458 |
{chm_nosuch, NULL}, /* u */ |
1459 |
{chm_voice, NULL}, /* v */ |
1460 |
{chm_nosuch, NULL}, /* w */ |
1461 |
{chm_nosuch, NULL}, /* x */ |
1462 |
{chm_nosuch, NULL}, /* y */ |
1463 |
{chm_nosuch, NULL}, /* z */ |
1464 |
}; |
1465 |
|
1466 |
/* get_channel_access() |
1467 |
* |
1468 |
* inputs - pointer to Client struct |
1469 |
* - pointer to Membership struct |
1470 |
* output - CHACCESS_CHANOP if we should let them have |
1471 |
* chanop level access, 0 for peon level access. |
1472 |
* side effects - NONE |
1473 |
*/ |
1474 |
static int |
1475 |
get_channel_access(struct Client *source_p, struct Membership *member) |
1476 |
{ |
1477 |
/* Let hacked servers in for now... */ |
1478 |
if (!MyClient(source_p)) |
1479 |
return CHACCESS_CHANOP; |
1480 |
|
1481 |
if (member == NULL) |
1482 |
return CHACCESS_NOTONCHAN; |
1483 |
|
1484 |
/* just to be sure.. */ |
1485 |
assert(source_p == member->client_p); |
1486 |
|
1487 |
if (has_member_flags(member, CHFL_CHANOP)) |
1488 |
return CHACCESS_CHANOP; |
1489 |
|
1490 |
#ifdef HALFOPS |
1491 |
if (has_member_flags(member, CHFL_HALFOP)) |
1492 |
return CHACCESS_HALFOP; |
1493 |
#endif |
1494 |
|
1495 |
return CHACCESS_PEON; |
1496 |
} |
1497 |
|
1498 |
/* void send_cap_mode_changes(struct Client *client_p, |
1499 |
* struct Client *source_p, |
1500 |
* struct Channel *chptr, int cap, int nocap) |
1501 |
* Input: The client sending(client_p), the source client(source_p), |
1502 |
* the channel to send mode changes for(chptr) |
1503 |
* Output: None. |
1504 |
* Side-effects: Sends the appropriate mode changes to capable servers. |
1505 |
* |
1506 |
* send_cap_mode_changes() will loop the server list itself, because |
1507 |
* at this point in time we have 4 capabs for channels, CAP_IE, CAP_EX, |
1508 |
* and a server could support any number of these.. |
1509 |
* so we make the modebufs per server, tailoring them to each servers |
1510 |
* specific demand. Its not very pretty, but its one of the few realistic |
1511 |
* ways to handle having this many capabs for channel modes.. --fl_ |
1512 |
* |
1513 |
* Reverted back to my original design, except that we now keep a count |
1514 |
* of the number of servers which each combination as an optimisation, so |
1515 |
* the capabs combinations which are not needed are not worked out. -A1kmm |
1516 |
*/ |
1517 |
/* rewritten to ensure parabuf < MODEBUFLEN -db */ |
1518 |
|
1519 |
static void |
1520 |
send_cap_mode_changes(struct Client *client_p, struct Client *source_p, |
1521 |
struct Channel *chptr, unsigned int cap, unsigned int nocap) |
1522 |
{ |
1523 |
int i, mbl, pbl, arglen, nc, mc; |
1524 |
int len; |
1525 |
const char *arg = NULL; |
1526 |
char *parptr; |
1527 |
int dir = MODE_QUERY; |
1528 |
|
1529 |
mc = 0; |
1530 |
nc = 0; |
1531 |
pbl = 0; |
1532 |
|
1533 |
parabuf[0] = '\0'; |
1534 |
parptr = parabuf; |
1535 |
|
1536 |
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1537 |
mbl = xsnprintf(NULL, modebuf, sizeof(modebuf), ":%s TMODE %Tu %s ", source_p->id, |
1538 |
chptr->channelts, chptr->chname); |
1539 |
else |
1540 |
mbl = xsnprintf(NULL, modebuf, sizeof(modebuf), ":%s MODE %s ", source_p->name, |
1541 |
chptr->chname); |
1542 |
|
1543 |
/* loop the list of - modes we have */ |
1544 |
for (i = 0; i < mode_count; i++) |
1545 |
{ |
1546 |
/* if they dont support the cap we need, or they do support a cap they |
1547 |
* cant have, then dont add it to the modebuf.. that way they wont see |
1548 |
* the mode |
1549 |
*/ |
1550 |
if ((mode_changes[i].letter == 0) || |
1551 |
((cap & mode_changes[i].caps) != mode_changes[i].caps) |
1552 |
|| ((nocap & mode_changes[i].nocaps) != mode_changes[i].nocaps)) |
1553 |
continue; |
1554 |
|
1555 |
arg = ""; |
1556 |
|
1557 |
if ((cap & CAP_TS6) && mode_changes[i].id) |
1558 |
arg = mode_changes[i].id; |
1559 |
if (*arg == '\0') |
1560 |
arg = mode_changes[i].arg; |
1561 |
|
1562 |
/* if we're creeping past the buf size, we need to send it and make |
1563 |
* another line for the other modes |
1564 |
* XXX - this could give away server topology with uids being |
1565 |
* different lengths, but not much we can do, except possibly break |
1566 |
* them as if they were the longest of the nick or uid at all times, |
1567 |
* which even then won't work as we don't always know the uid -A1kmm. |
1568 |
*/ |
1569 |
if (arg != NULL) |
1570 |
arglen = strlen(arg); |
1571 |
else |
1572 |
arglen = 0; |
1573 |
|
1574 |
if ((mc == MAXMODEPARAMS) || |
1575 |
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1576 |
(pbl + arglen + BAN_FUDGE) >= MODEBUFLEN) |
1577 |
{ |
1578 |
if (nc != 0) |
1579 |
sendto_server(client_p, cap, nocap, |
1580 |
"%s %s", |
1581 |
modebuf, parabuf); |
1582 |
nc = 0; |
1583 |
mc = 0; |
1584 |
|
1585 |
if ((cap & CAP_TS6) && source_p->id[0] != '\0') |
1586 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->id, |
1587 |
chptr->chname); |
1588 |
else |
1589 |
mbl = sprintf(modebuf, ":%s MODE %s ", source_p->name, |
1590 |
chptr->chname); |
1591 |
|
1592 |
pbl = 0; |
1593 |
parabuf[0] = '\0'; |
1594 |
parptr = parabuf; |
1595 |
dir = MODE_QUERY; |
1596 |
} |
1597 |
|
1598 |
if (dir != mode_changes[i].dir) |
1599 |
{ |
1600 |
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1601 |
dir = mode_changes[i].dir; |
1602 |
} |
1603 |
|
1604 |
modebuf[mbl++] = mode_changes[i].letter; |
1605 |
modebuf[mbl] = '\0'; |
1606 |
nc++; |
1607 |
|
1608 |
if (arg != NULL) |
1609 |
{ |
1610 |
len = sprintf(parptr, "%s ", arg); |
1611 |
pbl += len; |
1612 |
parptr += len; |
1613 |
mc++; |
1614 |
} |
1615 |
} |
1616 |
|
1617 |
if (pbl && parabuf[pbl - 1] == ' ') |
1618 |
parabuf[pbl - 1] = 0; |
1619 |
|
1620 |
if (nc != 0) |
1621 |
sendto_server(client_p, cap, nocap, |
1622 |
"%s %s", modebuf, parabuf); |
1623 |
} |
1624 |
|
1625 |
/* void send_mode_changes(struct Client *client_p, |
1626 |
* struct Client *source_p, |
1627 |
* struct Channel *chptr) |
1628 |
* Input: The client sending(client_p), the source client(source_p), |
1629 |
* the channel to send mode changes for(chptr), |
1630 |
* mode change globals. |
1631 |
* Output: None. |
1632 |
* Side-effects: Sends the appropriate mode changes to other clients |
1633 |
* and propagates to servers. |
1634 |
*/ |
1635 |
/* ensure parabuf < MODEBUFLEN -db */ |
1636 |
static void |
1637 |
send_mode_changes(struct Client *client_p, struct Client *source_p, |
1638 |
struct Channel *chptr, char *chname) |
1639 |
{ |
1640 |
int i, mbl, pbl, arglen, nc, mc; |
1641 |
int len; |
1642 |
const char *arg = NULL; |
1643 |
char *parptr; |
1644 |
int dir = MODE_QUERY; |
1645 |
|
1646 |
/* bail out if we have nothing to do... */ |
1647 |
if (!mode_count) |
1648 |
return; |
1649 |
|
1650 |
if (IsServer(source_p)) |
1651 |
mbl = sprintf(modebuf, ":%s MODE %s ", (IsHidden(source_p) || |
1652 |
ConfigServerHide.hide_servers) ? |
1653 |
me.name : source_p->name, chname); |
1654 |
else |
1655 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1656 |
source_p->username, source_p->host, chname); |
1657 |
|
1658 |
mc = 0; |
1659 |
nc = 0; |
1660 |
pbl = 0; |
1661 |
|
1662 |
parabuf[0] = '\0'; |
1663 |
parptr = parabuf; |
1664 |
|
1665 |
for (i = 0; i < mode_count; i++) |
1666 |
{ |
1667 |
if (mode_changes[i].letter == 0 || |
1668 |
mode_changes[i].mems == NON_CHANOPS || |
1669 |
mode_changes[i].mems == ONLY_SERVERS) |
1670 |
continue; |
1671 |
|
1672 |
arg = mode_changes[i].arg; |
1673 |
if (arg != NULL) |
1674 |
arglen = strlen(arg); |
1675 |
else |
1676 |
arglen = 0; |
1677 |
|
1678 |
if ((mc == MAXMODEPARAMS) || |
1679 |
((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) || |
1680 |
((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN)) |
1681 |
{ |
1682 |
if (mbl && modebuf[mbl - 1] == '-') |
1683 |
modebuf[mbl - 1] = '\0'; |
1684 |
|
1685 |
if (nc != 0) |
1686 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1687 |
|
1688 |
nc = 0; |
1689 |
mc = 0; |
1690 |
|
1691 |
if (IsServer(source_p)) |
1692 |
mbl = sprintf(modebuf, ":%s MODE %s ", me.name, chname); |
1693 |
else |
1694 |
mbl = sprintf(modebuf, ":%s!%s@%s MODE %s ", source_p->name, |
1695 |
source_p->username, source_p->host, chname); |
1696 |
|
1697 |
pbl = 0; |
1698 |
parabuf[0] = '\0'; |
1699 |
parptr = parabuf; |
1700 |
dir = MODE_QUERY; |
1701 |
} |
1702 |
|
1703 |
if (dir != mode_changes[i].dir) |
1704 |
{ |
1705 |
modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-'; |
1706 |
dir = mode_changes[i].dir; |
1707 |
} |
1708 |
|
1709 |
modebuf[mbl++] = mode_changes[i].letter; |
1710 |
modebuf[mbl] = '\0'; |
1711 |
nc++; |
1712 |
|
1713 |
if (arg != NULL) |
1714 |
{ |
1715 |
len = sprintf(parptr, "%s ", arg); |
1716 |
pbl += len; |
1717 |
parptr += len; |
1718 |
mc++; |
1719 |
} |
1720 |
} |
1721 |
|
1722 |
if (pbl && parabuf[pbl - 1] == ' ') |
1723 |
parabuf[pbl - 1] = 0; |
1724 |
|
1725 |
if (nc != 0) |
1726 |
sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf); |
1727 |
|
1728 |
nc = 0; |
1729 |
mc = 0; |
1730 |
|
1731 |
/* Now send to servers... */ |
1732 |
for (i = 0; i < NCHCAP_COMBOS; i++) |
1733 |
if (chcap_combos[i].count != 0) |
1734 |
send_cap_mode_changes(client_p, source_p, chptr, |
1735 |
chcap_combos[i].cap_yes, |
1736 |
chcap_combos[i].cap_no); |
1737 |
} |
1738 |
|
1739 |
/* void set_channel_mode(struct Client *client_p, struct Client *source_p, |
1740 |
* struct Channel *chptr, int parc, char **parv, |
1741 |
* char *chname) |
1742 |
* Input: The client we received this from, the client this originated |
1743 |
* from, the channel, the parameter count starting at the modes, |
1744 |
* the parameters, the channel name. |
1745 |
* Output: None. |
1746 |
* Side-effects: Changes the channel membership and modes appropriately, |
1747 |
* sends the appropriate MODE messages to the appropriate |
1748 |
* clients. |
1749 |
*/ |
1750 |
void |
1751 |
set_channel_mode(struct Client *client_p, struct Client *source_p, struct Channel *chptr, |
1752 |
struct Membership *member, int parc, char *parv[], char *chname) |
1753 |
{ |
1754 |
int dir = MODE_ADD; |
1755 |
int parn = 1; |
1756 |
int alevel, errors = 0; |
1757 |
char *ml = parv[0], c; |
1758 |
int table_position; |
1759 |
|
1760 |
mode_count = 0; |
1761 |
mode_limit = 0; |
1762 |
simple_modes_mask = 0; |
1763 |
|
1764 |
alevel = get_channel_access(source_p, member); |
1765 |
|
1766 |
for (; (c = *ml) != '\0'; ml++) |
1767 |
{ |
1768 |
#if 0 |
1769 |
if(mode_count > 20) |
1770 |
break; |
1771 |
#endif |
1772 |
switch (c) |
1773 |
{ |
1774 |
case '+': |
1775 |
dir = MODE_ADD; |
1776 |
break; |
1777 |
case '-': |
1778 |
dir = MODE_DEL; |
1779 |
break; |
1780 |
case '=': |
1781 |
dir = MODE_QUERY; |
1782 |
break; |
1783 |
default: |
1784 |
if (c < 'A' || c > 'z') |
1785 |
table_position = 0; |
1786 |
else |
1787 |
table_position = c - 'A' + 1; |
1788 |
ModeTable[table_position].func(client_p, source_p, chptr, |
1789 |
parc, &parn, |
1790 |
parv, &errors, alevel, dir, c, |
1791 |
ModeTable[table_position].d, |
1792 |
chname); |
1793 |
break; |
1794 |
} |
1795 |
} |
1796 |
|
1797 |
send_mode_changes(client_p, source_p, chptr, chname); |
1798 |
} |