ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/src/channel_mode.c
Revision: 227
Committed: Thu Nov 3 18:29:22 2005 UTC (19 years, 9 months ago) by db
Content type: text/x-csrc
File size: 46604 byte(s)
Log Message:
- replace all MODE_PRIVATE with MODE_PARANOID
- Can't use make_dlink_node() too early in startup or it will core


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

Properties

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