ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 7668
Committed: Wed Jul 20 17:09:49 2016 UTC (9 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 42745 byte(s)
Log Message:
- Fixed svn properties

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2016 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, "%u ", 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 if (dir == MODE_QUERY || parc <= *parn)
557 {
558 dlink_node *node = NULL;
559
560 if (*errors & SM_ERR_RPL_B)
561 return;
562
563 *errors |= SM_ERR_RPL_B;
564
565 DLINK_FOREACH(node, chptr->banlist.head)
566 {
567 const struct Ban *ban = node->data;
568 sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->name,
569 ban->name, ban->user, ban->host,
570 ban->who, ban->when);
571 }
572
573 sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->name);
574 return;
575 }
576
577 if (alev < CHACCESS_HALFOP)
578 {
579 if (!(*errors & SM_ERR_NOOPS))
580 sendto_one_numeric(source_p, &me,
581 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
582 ERR_CHANOPRIVSNEEDED, chptr->name);
583
584 *errors |= SM_ERR_NOOPS;
585 return;
586 }
587
588 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
589 return;
590
591 char *mask = nuh_mask[*parn];
592 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
593 ++(*parn);
594
595 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
596 return;
597
598 switch (dir)
599 {
600 case MODE_ADD:
601 if (!add_id(source_p, chptr, mask, CHFL_BAN))
602 return;
603 break;
604 case MODE_DEL:
605 if (!del_id(chptr, mask, CHFL_BAN))
606 return;
607 break;
608 default:
609 assert(0);
610 }
611
612 mode_changes[mode_count].letter = c;
613 mode_changes[mode_count].arg = mask;
614 mode_changes[mode_count].id = NULL;
615 mode_changes[mode_count++].dir = dir;
616 }
617
618 static void
619 chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
620 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
621 {
622 if (dir == MODE_QUERY || parc <= *parn)
623 {
624 dlink_node *node = NULL;
625
626 if (*errors & SM_ERR_RPL_E)
627 return;
628
629 *errors |= SM_ERR_RPL_E;
630
631 DLINK_FOREACH(node, chptr->exceptlist.head)
632 {
633 const struct Ban *ban = node->data;
634 sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->name,
635 ban->name, ban->user, ban->host,
636 ban->who, ban->when);
637 }
638
639 sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->name);
640 return;
641 }
642
643 if (alev < CHACCESS_HALFOP)
644 {
645 if (!(*errors & SM_ERR_NOOPS))
646 sendto_one_numeric(source_p, &me,
647 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
648 ERR_CHANOPRIVSNEEDED, chptr->name);
649
650 *errors |= SM_ERR_NOOPS;
651 return;
652 }
653
654 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
655 return;
656
657 char *mask = nuh_mask[*parn];
658 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
659 ++(*parn);
660
661 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
662 return;
663
664 switch (dir)
665 {
666 case MODE_ADD:
667 if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
668 return;
669 break;
670 case MODE_DEL:
671 if (!del_id(chptr, mask, CHFL_EXCEPTION))
672 return;
673 break;
674 default:
675 assert(0);
676 }
677
678 mode_changes[mode_count].letter = c;
679 mode_changes[mode_count].arg = mask;
680 mode_changes[mode_count].id = NULL;
681 mode_changes[mode_count++].dir = dir;
682 }
683
684 static void
685 chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
686 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
687 {
688 if (dir == MODE_QUERY || parc <= *parn)
689 {
690 dlink_node *node = NULL;
691
692 if (*errors & SM_ERR_RPL_I)
693 return;
694
695 *errors |= SM_ERR_RPL_I;
696
697 DLINK_FOREACH(node, chptr->invexlist.head)
698 {
699 const struct Ban *ban = node->data;
700 sendto_one_numeric(source_p, &me, RPL_INVEXLIST, chptr->name,
701 ban->name, ban->user, ban->host,
702 ban->who, ban->when);
703 }
704
705 sendto_one_numeric(source_p, &me, RPL_ENDOFINVEXLIST, chptr->name);
706 return;
707 }
708
709 if (alev < CHACCESS_HALFOP)
710 {
711 if (!(*errors & SM_ERR_NOOPS))
712 sendto_one_numeric(source_p, &me,
713 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
714 ERR_CHANOPRIVSNEEDED, chptr->name);
715
716 *errors |= SM_ERR_NOOPS;
717 return;
718 }
719
720 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
721 return;
722
723 char *mask = nuh_mask[*parn];
724 strlcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
725 ++(*parn);
726
727 if (*mask == ':' || (!MyConnect(source_p) && strchr(mask, ' ')))
728 return;
729
730 switch (dir)
731 {
732 case MODE_ADD:
733 if (!add_id(source_p, chptr, mask, CHFL_INVEX))
734 return;
735 break;
736 case MODE_DEL:
737 if (!del_id(chptr, mask, CHFL_INVEX))
738 return;
739 break;
740 default:
741 assert(0);
742 }
743
744 mode_changes[mode_count].letter = c;
745 mode_changes[mode_count].arg = mask;
746 mode_changes[mode_count].id = NULL;
747 mode_changes[mode_count++].dir = dir;
748 }
749
750 static void
751 chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
752 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
753 {
754 struct Client *target_p;
755 struct Membership *member;
756
757 if (alev < CHACCESS_HALFOP)
758 {
759 if (!(*errors & SM_ERR_NOOPS))
760 sendto_one_numeric(source_p, &me,
761 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
762 ERR_CHANOPRIVSNEEDED, chptr->name);
763
764 *errors |= SM_ERR_NOOPS;
765 return;
766 }
767
768 if (dir == MODE_QUERY || parc <= *parn)
769 return;
770
771 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
772 return; /* find_chasing sends ERR_NOSUCHNICK */
773
774 if ((member = find_channel_link(target_p, chptr)) == NULL)
775 {
776 if (!(*errors & SM_ERR_NOTONCHANNEL))
777 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
778
779 *errors |= SM_ERR_NOTONCHANNEL;
780 return;
781 }
782
783 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
784 return;
785
786 switch (dir)
787 {
788 case MODE_ADD:
789 if (has_member_flags(member, CHFL_VOICE))
790 return; /* No redundant mode changes */
791
792 AddMemberFlag(member, CHFL_VOICE);
793 break;
794 case MODE_DEL:
795 if (!has_member_flags(member, CHFL_VOICE))
796 return; /* No redundant mode changes */
797
798 DelMemberFlag(member, CHFL_VOICE);
799 break;
800 }
801
802 mode_changes[mode_count].letter = c;
803 mode_changes[mode_count].arg = target_p->name;
804 mode_changes[mode_count].id = target_p->id;
805 mode_changes[mode_count++].dir = dir;
806 }
807
808 static void
809 chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
810 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
811 {
812 struct Client *target_p;
813 struct Membership *member;
814
815 if (alev < CHACCESS_CHANOP)
816 {
817 if (!(*errors & SM_ERR_NOOPS))
818 sendto_one_numeric(source_p, &me,
819 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
820 ERR_CHANOPRIVSNEEDED, chptr->name);
821
822 *errors |= SM_ERR_NOOPS;
823 return;
824 }
825
826 if (dir == MODE_QUERY || parc <= *parn)
827 return;
828
829 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
830 return; /* find_chasing sends ERR_NOSUCHNICK */
831
832 if ((member = find_channel_link(target_p, chptr)) == NULL)
833 {
834 if (!(*errors & SM_ERR_NOTONCHANNEL))
835 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
836
837 *errors |= SM_ERR_NOTONCHANNEL;
838 return;
839 }
840
841 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
842 return;
843
844 switch (dir)
845 {
846 case MODE_ADD:
847 if (has_member_flags(member, CHFL_HALFOP))
848 return; /* No redundant mode changes */
849
850 AddMemberFlag(member, CHFL_HALFOP);
851 break;
852 case MODE_DEL:
853 if (!has_member_flags(member, CHFL_HALFOP))
854 return; /* No redundant mode changes */
855
856 DelMemberFlag(member, CHFL_HALFOP);
857 break;
858 }
859
860 mode_changes[mode_count].letter = c;
861 mode_changes[mode_count].arg = target_p->name;
862 mode_changes[mode_count].id = target_p->id;
863 mode_changes[mode_count++].dir = dir;
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 switch (dir)
903 {
904 case MODE_ADD:
905 if (has_member_flags(member, CHFL_CHANOP))
906 return; /* No redundant mode changes */
907
908 AddMemberFlag(member, CHFL_CHANOP);
909 break;
910 case MODE_DEL:
911 if (!has_member_flags(member, CHFL_CHANOP))
912 return; /* No redundant mode changes */
913
914 DelMemberFlag(member, CHFL_CHANOP);
915 break;
916 }
917
918 mode_changes[mode_count].letter = c;
919 mode_changes[mode_count].arg = target_p->name;
920 mode_changes[mode_count].id = target_p->id;
921 mode_changes[mode_count++].dir = dir;
922 }
923
924 static void
925 chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
926 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
927 {
928 if (alev < CHACCESS_HALFOP)
929 {
930 if (!(*errors & SM_ERR_NOOPS))
931 sendto_one_numeric(source_p, &me,
932 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
933 ERR_CHANOPRIVSNEEDED, chptr->name);
934 *errors |= SM_ERR_NOOPS;
935 return;
936 }
937
938 if (dir == MODE_QUERY)
939 return;
940
941 if (dir == MODE_ADD && parc > *parn)
942 {
943 char *const lstr = parv[(*parn)++];
944 int limit = 0;
945
946 if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
947 return;
948
949 sprintf(lstr, "%d", limit);
950
951 /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
952 for (unsigned int i = 0; i < mode_count; ++i)
953 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
954 mode_changes[i].letter = 0;
955
956 mode_changes[mode_count].letter = c;
957 mode_changes[mode_count].arg = lstr;
958 mode_changes[mode_count].id = NULL;
959 mode_changes[mode_count++].dir = dir;
960
961 chptr->mode.limit = limit;
962 }
963 else if (dir == MODE_DEL)
964 {
965 if (!chptr->mode.limit)
966 return;
967
968 chptr->mode.limit = 0;
969
970 mode_changes[mode_count].letter = c;
971 mode_changes[mode_count].arg = NULL;
972 mode_changes[mode_count].id = NULL;
973 mode_changes[mode_count++].dir = dir;
974 }
975 }
976
977 static void
978 chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
979 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
980 {
981 if (alev < CHACCESS_HALFOP)
982 {
983 if (!(*errors & SM_ERR_NOOPS))
984 sendto_one_numeric(source_p, &me,
985 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
986 ERR_CHANOPRIVSNEEDED, chptr->name);
987 *errors |= SM_ERR_NOOPS;
988 return;
989 }
990
991 if (dir == MODE_QUERY)
992 return;
993
994 if (dir == MODE_ADD && parc > *parn)
995 {
996 char *const key = fix_key(parv[(*parn)++]);
997
998 if (EmptyString(key))
999 return;
1000
1001 assert(key[0] != ' ');
1002 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1003
1004 /* If somebody does MODE #channel +kk a b, accept latter --fl */
1005 for (unsigned int i = 0; i < mode_count; ++i)
1006 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1007 mode_changes[i].letter = 0;
1008
1009 mode_changes[mode_count].letter = c;
1010 mode_changes[mode_count].arg = chptr->mode.key;
1011 mode_changes[mode_count].id = NULL;
1012 mode_changes[mode_count++].dir = dir;
1013 }
1014 else if (dir == MODE_DEL)
1015 {
1016 if (parc > *parn)
1017 ++(*parn);
1018
1019 if (chptr->mode.key[0] == '\0')
1020 return;
1021
1022 chptr->mode.key[0] = '\0';
1023
1024 mode_changes[mode_count].letter = c;
1025 mode_changes[mode_count].arg = "*";
1026 mode_changes[mode_count].id = NULL;
1027 mode_changes[mode_count++].dir = dir;
1028 }
1029 }
1030
1031 const struct ChannelMode ModeTable[256] =
1032 {
1033 { chm_nosuch, 0 }, /* 0x00 */
1034 { chm_nosuch, 0 }, /* 0x01 */
1035 { chm_nosuch, 0 }, /* 0x02 */
1036 { chm_nosuch, 0 }, /* 0x03 */
1037 { chm_nosuch, 0 }, /* 0x04 */
1038 { chm_nosuch, 0 }, /* 0x05 */
1039 { chm_nosuch, 0 }, /* 0x06 */
1040 { chm_nosuch, 0 }, /* 0x07 */
1041 { chm_nosuch, 0 }, /* 0x08 */
1042 { chm_nosuch, 0 }, /* 0x09 */
1043 { chm_nosuch, 0 }, /* 0x0a */
1044 { chm_nosuch, 0 }, /* 0x0b */
1045 { chm_nosuch, 0 }, /* 0x0c */
1046 { chm_nosuch, 0 }, /* 0x0d */
1047 { chm_nosuch, 0 }, /* 0x0e */
1048 { chm_nosuch, 0 }, /* 0x0f */
1049 { chm_nosuch, 0 }, /* 0x10 */
1050 { chm_nosuch, 0 }, /* 0x11 */
1051 { chm_nosuch, 0 }, /* 0x12 */
1052 { chm_nosuch, 0 }, /* 0x13 */
1053 { chm_nosuch, 0 }, /* 0x14 */
1054 { chm_nosuch, 0 }, /* 0x15 */
1055 { chm_nosuch, 0 }, /* 0x16 */
1056 { chm_nosuch, 0 }, /* 0x17 */
1057 { chm_nosuch, 0 }, /* 0x18 */
1058 { chm_nosuch, 0 }, /* 0x19 */
1059 { chm_nosuch, 0 }, /* 0x1a */
1060 { chm_nosuch, 0 }, /* 0x1b */
1061 { chm_nosuch, 0 }, /* 0x1c */
1062 { chm_nosuch, 0 }, /* 0x1d */
1063 { chm_nosuch, 0 }, /* 0x1e */
1064 { chm_nosuch, 0 }, /* 0x1f */
1065 { chm_nosuch, 0 }, /* 0x20 */
1066 { chm_nosuch, 0 }, /* 0x21 */
1067 { chm_nosuch, 0 }, /* 0x22 */
1068 { chm_nosuch, 0 }, /* 0x23 */
1069 { chm_nosuch, 0 }, /* 0x24 */
1070 { chm_nosuch, 0 }, /* 0x25 */
1071 { chm_nosuch, 0 }, /* 0x26 */
1072 { chm_nosuch, 0 }, /* 0x27 */
1073 { chm_nosuch, 0 }, /* 0x28 */
1074 { chm_nosuch, 0 }, /* 0x29 */
1075 { chm_nosuch, 0 }, /* 0x2a */
1076 { chm_nosuch, 0 }, /* 0x2b */
1077 { chm_nosuch, 0 }, /* 0x2c */
1078 { chm_nosuch, 0 }, /* 0x2d */
1079 { chm_nosuch, 0 }, /* 0x2e */
1080 { chm_nosuch, 0 }, /* 0x2f */
1081 { chm_nosuch, 0 }, /* 0x30 */
1082 { chm_nosuch, 0 }, /* 0x31 */
1083 { chm_nosuch, 0 }, /* 0x32 */
1084 { chm_nosuch, 0 }, /* 0x33 */
1085 { chm_nosuch, 0 }, /* 0x34 */
1086 { chm_nosuch, 0 }, /* 0x35 */
1087 { chm_nosuch, 0 }, /* 0x36 */
1088 { chm_nosuch, 0 }, /* 0x37 */
1089 { chm_nosuch, 0 }, /* 0x38 */
1090 { chm_nosuch, 0 }, /* 0x39 */
1091 { chm_nosuch, 0 }, /* 0x3a */
1092 { chm_nosuch, 0 }, /* 0x3b */
1093 { chm_nosuch, 0 }, /* 0x3c */
1094 { chm_nosuch, 0 }, /* 0x3d */
1095 { chm_nosuch, 0 }, /* 0x3e */
1096 { chm_nosuch, 0 }, /* 0x3f */
1097 { chm_nosuch, 0 }, /* @ */
1098 { chm_nosuch, 0 }, /* A */
1099 { chm_nosuch, 0 }, /* B */
1100 { chm_simple, MODE_NOCTCP }, /* C */
1101 { chm_nosuch, 0 }, /* D */
1102 { chm_nosuch, 0 }, /* E */
1103 { chm_nosuch, 0 }, /* F */
1104 { chm_nosuch, 0 }, /* G */
1105 { chm_nosuch, 0 }, /* H */
1106 { chm_invex, 0 }, /* I */
1107 { chm_nosuch, 0 }, /* J */
1108 { chm_nosuch, 0 }, /* K */
1109 { chm_nosuch, 0 }, /* L */
1110 { chm_simple, MODE_MODREG}, /* M */
1111 { chm_nosuch, 0 }, /* N */
1112 { chm_operonly, MODE_OPERONLY}, /* O */
1113 { chm_nosuch, 0 }, /* P */
1114 { chm_nosuch, 0 }, /* Q */
1115 { chm_simple, MODE_REGONLY}, /* R */
1116 { chm_simple, MODE_SSLONLY}, /* S */
1117 { chm_simple, MODE_NONOTICE}, /* T */
1118 { chm_nosuch, 0 }, /* U */
1119 { chm_nosuch, 0 }, /* V */
1120 { chm_nosuch, 0 }, /* W */
1121 { chm_nosuch, 0 }, /* X */
1122 { chm_nosuch, 0 }, /* Y */
1123 { chm_nosuch, 0 }, /* Z */
1124 { chm_nosuch, 0 },
1125 { chm_nosuch, 0 },
1126 { chm_nosuch, 0 },
1127 { chm_nosuch, 0 },
1128 { chm_nosuch, 0 },
1129 { chm_nosuch, 0 },
1130 { chm_nosuch, 0 }, /* a */
1131 { chm_ban, 0 }, /* b */
1132 { chm_simple, MODE_NOCTRL}, /* c */
1133 { chm_nosuch, 0 }, /* d */
1134 { chm_except, 0 }, /* e */
1135 { chm_nosuch, 0 }, /* f */
1136 { chm_nosuch, 0 }, /* g */
1137 { chm_hop, 0 }, /* h */
1138 { chm_simple, MODE_INVITEONLY }, /* i */
1139 { chm_nosuch, 0 }, /* j */
1140 { chm_key, 0 }, /* k */
1141 { chm_limit, 0 }, /* l */
1142 { chm_simple, MODE_MODERATED }, /* m */
1143 { chm_simple, MODE_NOPRIVMSGS }, /* n */
1144 { chm_op, 0 }, /* o */
1145 { chm_simple, MODE_PRIVATE }, /* p */
1146 { chm_nosuch, 0 }, /* q */
1147 { chm_registered, MODE_REGISTERED }, /* r */
1148 { chm_simple, MODE_SECRET }, /* s */
1149 { chm_simple, MODE_TOPICLIMIT }, /* t */
1150 { chm_nosuch, 0 }, /* u */
1151 { chm_voice, 0 }, /* v */
1152 { chm_nosuch, 0 }, /* w */
1153 { chm_nosuch, 0 }, /* x */
1154 { chm_nosuch, 0 }, /* y */
1155 { chm_nosuch, 0 }, /* z */
1156 { chm_nosuch, 0 }, /* 0x7b */
1157 { chm_nosuch, 0 }, /* 0x7c */
1158 { chm_nosuch, 0 }, /* 0x7d */
1159 { chm_nosuch, 0 }, /* 0x7e */
1160 { chm_nosuch, 0 }, /* 0x7f */
1161 { chm_nosuch, 0 }, /* 0x80 */
1162 { chm_nosuch, 0 }, /* 0x81 */
1163 { chm_nosuch, 0 }, /* 0x82 */
1164 { chm_nosuch, 0 }, /* 0x83 */
1165 { chm_nosuch, 0 }, /* 0x84 */
1166 { chm_nosuch, 0 }, /* 0x85 */
1167 { chm_nosuch, 0 }, /* 0x86 */
1168 { chm_nosuch, 0 }, /* 0x87 */
1169 { chm_nosuch, 0 }, /* 0x88 */
1170 { chm_nosuch, 0 }, /* 0x89 */
1171 { chm_nosuch, 0 }, /* 0x8a */
1172 { chm_nosuch, 0 }, /* 0x8b */
1173 { chm_nosuch, 0 }, /* 0x8c */
1174 { chm_nosuch, 0 }, /* 0x8d */
1175 { chm_nosuch, 0 }, /* 0x8e */
1176 { chm_nosuch, 0 }, /* 0x8f */
1177 { chm_nosuch, 0 }, /* 0x90 */
1178 { chm_nosuch, 0 }, /* 0x91 */
1179 { chm_nosuch, 0 }, /* 0x92 */
1180 { chm_nosuch, 0 }, /* 0x93 */
1181 { chm_nosuch, 0 }, /* 0x94 */
1182 { chm_nosuch, 0 }, /* 0x95 */
1183 { chm_nosuch, 0 }, /* 0x96 */
1184 { chm_nosuch, 0 }, /* 0x97 */
1185 { chm_nosuch, 0 }, /* 0x98 */
1186 { chm_nosuch, 0 }, /* 0x99 */
1187 { chm_nosuch, 0 }, /* 0x9a */
1188 { chm_nosuch, 0 }, /* 0x9b */
1189 { chm_nosuch, 0 }, /* 0x9c */
1190 { chm_nosuch, 0 }, /* 0x9d */
1191 { chm_nosuch, 0 }, /* 0x9e */
1192 { chm_nosuch, 0 }, /* 0x9f */
1193 { chm_nosuch, 0 }, /* 0xa0 */
1194 { chm_nosuch, 0 }, /* 0xa1 */
1195 { chm_nosuch, 0 }, /* 0xa2 */
1196 { chm_nosuch, 0 }, /* 0xa3 */
1197 { chm_nosuch, 0 }, /* 0xa4 */
1198 { chm_nosuch, 0 }, /* 0xa5 */
1199 { chm_nosuch, 0 }, /* 0xa6 */
1200 { chm_nosuch, 0 }, /* 0xa7 */
1201 { chm_nosuch, 0 }, /* 0xa8 */
1202 { chm_nosuch, 0 }, /* 0xa9 */
1203 { chm_nosuch, 0 }, /* 0xaa */
1204 { chm_nosuch, 0 }, /* 0xab */
1205 { chm_nosuch, 0 }, /* 0xac */
1206 { chm_nosuch, 0 }, /* 0xad */
1207 { chm_nosuch, 0 }, /* 0xae */
1208 { chm_nosuch, 0 }, /* 0xaf */
1209 { chm_nosuch, 0 }, /* 0xb0 */
1210 { chm_nosuch, 0 }, /* 0xb1 */
1211 { chm_nosuch, 0 }, /* 0xb2 */
1212 { chm_nosuch, 0 }, /* 0xb3 */
1213 { chm_nosuch, 0 }, /* 0xb4 */
1214 { chm_nosuch, 0 }, /* 0xb5 */
1215 { chm_nosuch, 0 }, /* 0xb6 */
1216 { chm_nosuch, 0 }, /* 0xb7 */
1217 { chm_nosuch, 0 }, /* 0xb8 */
1218 { chm_nosuch, 0 }, /* 0xb9 */
1219 { chm_nosuch, 0 }, /* 0xba */
1220 { chm_nosuch, 0 }, /* 0xbb */
1221 { chm_nosuch, 0 }, /* 0xbc */
1222 { chm_nosuch, 0 }, /* 0xbd */
1223 { chm_nosuch, 0 }, /* 0xbe */
1224 { chm_nosuch, 0 }, /* 0xbf */
1225 { chm_nosuch, 0 }, /* 0xc0 */
1226 { chm_nosuch, 0 }, /* 0xc1 */
1227 { chm_nosuch, 0 }, /* 0xc2 */
1228 { chm_nosuch, 0 }, /* 0xc3 */
1229 { chm_nosuch, 0 }, /* 0xc4 */
1230 { chm_nosuch, 0 }, /* 0xc5 */
1231 { chm_nosuch, 0 }, /* 0xc6 */
1232 { chm_nosuch, 0 }, /* 0xc7 */
1233 { chm_nosuch, 0 }, /* 0xc8 */
1234 { chm_nosuch, 0 }, /* 0xc9 */
1235 { chm_nosuch, 0 }, /* 0xca */
1236 { chm_nosuch, 0 }, /* 0xcb */
1237 { chm_nosuch, 0 }, /* 0xcc */
1238 { chm_nosuch, 0 }, /* 0xcd */
1239 { chm_nosuch, 0 }, /* 0xce */
1240 { chm_nosuch, 0 }, /* 0xcf */
1241 { chm_nosuch, 0 }, /* 0xd0 */
1242 { chm_nosuch, 0 }, /* 0xd1 */
1243 { chm_nosuch, 0 }, /* 0xd2 */
1244 { chm_nosuch, 0 }, /* 0xd3 */
1245 { chm_nosuch, 0 }, /* 0xd4 */
1246 { chm_nosuch, 0 }, /* 0xd5 */
1247 { chm_nosuch, 0 }, /* 0xd6 */
1248 { chm_nosuch, 0 }, /* 0xd7 */
1249 { chm_nosuch, 0 }, /* 0xd8 */
1250 { chm_nosuch, 0 }, /* 0xd9 */
1251 { chm_nosuch, 0 }, /* 0xda */
1252 { chm_nosuch, 0 }, /* 0xdb */
1253 { chm_nosuch, 0 }, /* 0xdc */
1254 { chm_nosuch, 0 }, /* 0xdd */
1255 { chm_nosuch, 0 }, /* 0xde */
1256 { chm_nosuch, 0 }, /* 0xdf */
1257 { chm_nosuch, 0 }, /* 0xe0 */
1258 { chm_nosuch, 0 }, /* 0xe1 */
1259 { chm_nosuch, 0 }, /* 0xe2 */
1260 { chm_nosuch, 0 }, /* 0xe3 */
1261 { chm_nosuch, 0 }, /* 0xe4 */
1262 { chm_nosuch, 0 }, /* 0xe5 */
1263 { chm_nosuch, 0 }, /* 0xe6 */
1264 { chm_nosuch, 0 }, /* 0xe7 */
1265 { chm_nosuch, 0 }, /* 0xe8 */
1266 { chm_nosuch, 0 }, /* 0xe9 */
1267 { chm_nosuch, 0 }, /* 0xea */
1268 { chm_nosuch, 0 }, /* 0xeb */
1269 { chm_nosuch, 0 }, /* 0xec */
1270 { chm_nosuch, 0 }, /* 0xed */
1271 { chm_nosuch, 0 }, /* 0xee */
1272 { chm_nosuch, 0 }, /* 0xef */
1273 { chm_nosuch, 0 }, /* 0xf0 */
1274 { chm_nosuch, 0 }, /* 0xf1 */
1275 { chm_nosuch, 0 }, /* 0xf2 */
1276 { chm_nosuch, 0 }, /* 0xf3 */
1277 { chm_nosuch, 0 }, /* 0xf4 */
1278 { chm_nosuch, 0 }, /* 0xf5 */
1279 { chm_nosuch, 0 }, /* 0xf6 */
1280 { chm_nosuch, 0 }, /* 0xf7 */
1281 { chm_nosuch, 0 }, /* 0xf8 */
1282 { chm_nosuch, 0 }, /* 0xf9 */
1283 { chm_nosuch, 0 }, /* 0xfa */
1284 { chm_nosuch, 0 }, /* 0xfb */
1285 { chm_nosuch, 0 }, /* 0xfc */
1286 { chm_nosuch, 0 }, /* 0xfd */
1287 { chm_nosuch, 0 }, /* 0xfe */
1288 { chm_nosuch, 0 }, /* 0xff */
1289 };
1290
1291 /* get_channel_access()
1292 *
1293 * inputs - pointer to Client struct
1294 * - pointer to Membership struct
1295 * output - CHACCESS_CHANOP if we should let them have
1296 * chanop level access, 0 for peon level access.
1297 * side effects - NONE
1298 */
1299 static int
1300 get_channel_access(const struct Client *source_p,
1301 const struct Membership *member)
1302 {
1303 /* Let hacked servers in for now... */
1304 if (!MyClient(source_p))
1305 return CHACCESS_REMOTE;
1306
1307 if (!member)
1308 return CHACCESS_NOTONCHAN;
1309
1310 /* Just to be sure.. */
1311 assert(source_p == member->client_p);
1312
1313 if (has_member_flags(member, CHFL_CHANOP))
1314 return CHACCESS_CHANOP;
1315
1316 if (has_member_flags(member, CHFL_HALFOP))
1317 return CHACCESS_HALFOP;
1318
1319 return CHACCESS_PEON;
1320 }
1321
1322 /* send_mode_changes_server()
1323 * Input: the source client(source_p),
1324 * the channel to send mode changes for(chptr)
1325 * Output: None.
1326 * Side-effects: Sends the appropriate mode changes to servers.
1327 *
1328 */
1329 static void
1330 send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1331 {
1332 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1333 int len = 0;
1334 int dir = MODE_QUERY;
1335 const char *arg = NULL;
1336 char *parptr = NULL;
1337
1338 parabuf[0] = '\0';
1339 parptr = parabuf;
1340
1341 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", source_p->id,
1342 chptr->creationtime, chptr->name);
1343
1344 /* Loop the list of modes we have */
1345 for (unsigned int i = 0; i < mode_count; ++i)
1346 {
1347 if (mode_changes[i].letter == 0)
1348 continue;
1349
1350 if (mode_changes[i].id)
1351 arg = mode_changes[i].id;
1352 else
1353 arg = mode_changes[i].arg;
1354
1355 if (arg)
1356 arglen = strlen(arg);
1357 else
1358 arglen = 0;
1359
1360 /*
1361 * If we're creeping past the buf size, we need to send it and make
1362 * another line for the other modes
1363 */
1364 if ((mc == MAXMODEPARAMS) ||
1365 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1366 (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1367 {
1368 if (nc)
1369 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1370
1371 nc = 0;
1372 mc = 0;
1373
1374 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", source_p->id,
1375 chptr->creationtime, chptr->name);
1376
1377 pbl = 0;
1378 parabuf[0] = '\0';
1379 parptr = parabuf;
1380 dir = MODE_QUERY;
1381 }
1382
1383 if (dir != mode_changes[i].dir)
1384 {
1385 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1386 dir = mode_changes[i].dir;
1387 }
1388
1389 modebuf[mbl++] = mode_changes[i].letter;
1390 modebuf[mbl] = '\0';
1391 ++nc;
1392
1393 if (arg)
1394 {
1395 len = sprintf(parptr, "%s ", arg);
1396 pbl += len;
1397 parptr += len;
1398 ++mc;
1399 }
1400 }
1401
1402 if (pbl && parabuf[pbl - 1] == ' ')
1403 parabuf[pbl - 1] = '\0';
1404
1405 if (nc)
1406 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1407 }
1408
1409 /* void send_mode_changes(struct Client *client_p,
1410 * struct Client *source_p,
1411 * struct Channel *chptr)
1412 * Input: The client sending(client_p), the source client(source_p),
1413 * the channel to send mode changes for(chptr),
1414 * mode change globals.
1415 * Output: None.
1416 * Side-effects: Sends the appropriate mode changes to other clients
1417 * and propagates to servers.
1418 */
1419 /* ensure parabuf < MODEBUFLEN -db */
1420 static void
1421 send_mode_changes_client(struct Client *source_p, struct Channel *chptr)
1422 {
1423 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1424 int len = 0;
1425 int dir = MODE_QUERY;
1426 const char *arg = NULL;
1427 char *parptr = NULL;
1428
1429 if (IsServer(source_p))
1430 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1431 ConfigServerHide.hide_servers) ?
1432 me.name : source_p->name, chptr->name);
1433 else
1434 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1435 source_p->username, source_p->host, chptr->name);
1436
1437 parabuf[0] = '\0';
1438 parptr = parabuf;
1439
1440 for (unsigned int i = 0; i < mode_count; ++i)
1441 {
1442 if (mode_changes[i].letter == 0)
1443 continue;
1444
1445 arg = mode_changes[i].arg;
1446 if (arg)
1447 arglen = strlen(arg);
1448 else
1449 arglen = 0;
1450
1451 if ((mc == MAXMODEPARAMS) ||
1452 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1453 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1454 {
1455 if (mbl && modebuf[mbl - 1] == '-')
1456 modebuf[mbl - 1] = '\0';
1457
1458 if (nc)
1459 sendto_channel_local(NULL, chptr, 0, 0, 0, "%s %s", modebuf, parabuf);
1460
1461 nc = 0;
1462 mc = 0;
1463
1464 if (IsServer(source_p))
1465 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1466 ConfigServerHide.hide_servers) ?
1467 me.name : source_p->name, chptr->name);
1468 else
1469 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1470 source_p->username, source_p->host, chptr->name);
1471
1472 pbl = 0;
1473 parabuf[0] = '\0';
1474 parptr = parabuf;
1475 dir = MODE_QUERY;
1476 }
1477
1478 if (dir != mode_changes[i].dir)
1479 {
1480 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1481 dir = mode_changes[i].dir;
1482 }
1483
1484 modebuf[mbl++] = mode_changes[i].letter;
1485 modebuf[mbl] = '\0';
1486 ++nc;
1487
1488 if (arg)
1489 {
1490 len = sprintf(parptr, "%s ", arg);
1491 pbl += len;
1492 parptr += len;
1493 ++mc;
1494 }
1495 }
1496
1497 if (pbl && parabuf[pbl - 1] == ' ')
1498 parabuf[pbl - 1] = '\0';
1499
1500 if (nc)
1501 sendto_channel_local(NULL, chptr, 0, 0, 0, "%s %s", modebuf, parabuf);
1502 }
1503
1504 /*
1505 * Input: The the client this originated
1506 * from, the channel, the parameter count starting at the modes,
1507 * the parameters, the channel name.
1508 * Output: None.
1509 * Side-effects: Changes the channel membership and modes appropriately,
1510 * sends the appropriate MODE messages to the appropriate
1511 * clients.
1512 */
1513 void
1514 set_channel_mode(struct Client *source_p, struct Channel *chptr,
1515 struct Membership *member, int parc, char *parv[])
1516 {
1517 int dir = MODE_ADD;
1518 int parn = 1;
1519 int alevel = 0, errors = 0;
1520
1521 mode_count = 0;
1522 mode_limit = 0;
1523 simple_modes_mask = 0;
1524
1525 alevel = get_channel_access(source_p, member);
1526
1527 for (const char *ml = parv[0]; *ml; ++ml)
1528 {
1529 switch (*ml)
1530 {
1531 case '+':
1532 dir = MODE_ADD;
1533 break;
1534 case '-':
1535 dir = MODE_DEL;
1536 break;
1537 case '=':
1538 dir = MODE_QUERY;
1539 break;
1540 default:
1541 {
1542 const struct ChannelMode *tptr = &ModeTable[(unsigned char)*ml];
1543
1544 tptr->func(source_p, chptr, parc, &parn, parv,
1545 &errors, alevel, dir, *ml, tptr->d);
1546 break;
1547 }
1548 }
1549 }
1550
1551 /* Bail out if we have nothing to do... */
1552 if (!mode_count)
1553 return;
1554
1555 send_mode_changes_client(source_p, chptr);
1556 send_mode_changes_server(source_p, chptr);
1557 }

Properties

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