ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3143
Committed: Wed Mar 12 19:56:58 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 48024 byte(s)
Log Message:
- channel_mode.c:chm_op, ch_hop, chm_voice: renamed 'targ_p' to 'target_p'

File Contents

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

Properties

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