ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 6858
Committed: Sun Nov 29 18:28:53 2015 UTC (9 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 42584 byte(s)
Log Message:
- Added channel mode +T which forbids NOTICEs to be sent to a channel

File Contents

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

Properties

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