ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3283
Committed: Tue Apr 8 16:39:50 2014 UTC (11 years, 4 months ago) by michael
Content type: text/x-csrc
File size: 46153 byte(s)
Log Message:
- Style corrections/constification

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

Properties

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