ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 1011
Committed: Fri Sep 18 10:14:09 2009 UTC (14 years, 7 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.2/src/channel_mode.c
File size: 48324 byte(s)
Log Message:
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

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

Properties

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