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