ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel_mode.c
Revision: 8050
Committed: Sun Mar 19 11:25:27 2017 UTC (7 years ago) by michael
Content type: text/x-csrc
File size: 43629 byte(s)
Log Message:
- channel_mode.c: constification; remove useless comments

File Contents

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

Properties

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