ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 1937
Committed: Sat May 4 20:54:13 2013 UTC (12 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 51489 byte(s)
Log Message:
-  Implemented channel mode +c. Known from other ircds, this mode basically
   prevents users from sending messages including control codes to a channel
   that has this mode set

File Contents

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

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision