ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 7006
Committed: Fri Jan 1 00:07:54 2016 UTC (9 years, 7 months ago) by michael
Content type: text/x-csrc
File size: 42795 byte(s)
Log Message:
- Update copyright years

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, "%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 switch (dir)
795 {
796 case MODE_ADD:
797 if (has_member_flags(member, CHFL_VOICE))
798 return; /* No redundant mode changes */
799
800 AddMemberFlag(member, CHFL_VOICE);
801 break;
802 case MODE_DEL:
803 if (!has_member_flags(member, CHFL_VOICE))
804 return; /* No redundant mode changes */
805
806 DelMemberFlag(member, CHFL_VOICE);
807 break;
808 }
809
810 mode_changes[mode_count].letter = c;
811 mode_changes[mode_count].arg = target_p->name;
812 mode_changes[mode_count].id = target_p->id;
813 mode_changes[mode_count++].dir = dir;
814 }
815
816 static void
817 chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
818 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
819 {
820 struct Client *target_p;
821 struct Membership *member;
822
823 if (alev < CHACCESS_CHANOP)
824 {
825 if (!(*errors & SM_ERR_NOOPS))
826 sendto_one_numeric(source_p, &me,
827 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
828 ERR_CHANOPRIVSNEEDED, chptr->name);
829
830 *errors |= SM_ERR_NOOPS;
831 return;
832 }
833
834 if (dir == MODE_QUERY || parc <= *parn)
835 return;
836
837 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
838 return; /* find_chasing sends ERR_NOSUCHNICK */
839
840 if ((member = find_channel_link(target_p, chptr)) == NULL)
841 {
842 if (!(*errors & SM_ERR_NOTONCHANNEL))
843 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
844
845 *errors |= SM_ERR_NOTONCHANNEL;
846 return;
847 }
848
849 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
850 return;
851
852 switch (dir)
853 {
854 case MODE_ADD:
855 if (has_member_flags(member, CHFL_HALFOP))
856 return; /* No redundant mode changes */
857
858 AddMemberFlag(member, CHFL_HALFOP);
859 break;
860 case MODE_DEL:
861 if (!has_member_flags(member, CHFL_HALFOP))
862 return; /* No redundant mode changes */
863
864 DelMemberFlag(member, CHFL_HALFOP);
865 break;
866 }
867
868 mode_changes[mode_count].letter = c;
869 mode_changes[mode_count].arg = target_p->name;
870 mode_changes[mode_count].id = target_p->id;
871 mode_changes[mode_count++].dir = dir;
872 }
873
874 static void
875 chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
876 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
877 {
878 struct Client *target_p;
879 struct Membership *member;
880
881 if (alev < CHACCESS_CHANOP)
882 {
883 if (!(*errors & SM_ERR_NOOPS))
884 sendto_one_numeric(source_p, &me,
885 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
886 ERR_CHANOPRIVSNEEDED, chptr->name);
887
888 *errors |= SM_ERR_NOOPS;
889 return;
890 }
891
892 if (dir == MODE_QUERY || parc <= *parn)
893 return;
894
895 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
896 return; /* find_chasing sends ERR_NOSUCHNICK */
897
898 if ((member = find_channel_link(target_p, chptr)) == NULL)
899 {
900 if (!(*errors & SM_ERR_NOTONCHANNEL))
901 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->name);
902
903 *errors |= SM_ERR_NOTONCHANNEL;
904 return;
905 }
906
907 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
908 return;
909
910 switch (dir)
911 {
912 case MODE_ADD:
913 if (has_member_flags(member, CHFL_CHANOP))
914 return; /* No redundant mode changes */
915
916 AddMemberFlag(member, CHFL_CHANOP);
917 break;
918 case MODE_DEL:
919 if (!has_member_flags(member, CHFL_CHANOP))
920 return; /* No redundant mode changes */
921
922 DelMemberFlag(member, CHFL_CHANOP);
923 break;
924 }
925
926 mode_changes[mode_count].letter = c;
927 mode_changes[mode_count].arg = target_p->name;
928 mode_changes[mode_count].id = target_p->id;
929 mode_changes[mode_count++].dir = dir;
930 }
931
932 static void
933 chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
934 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
935 {
936 if (alev < CHACCESS_HALFOP)
937 {
938 if (!(*errors & SM_ERR_NOOPS))
939 sendto_one_numeric(source_p, &me,
940 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
941 ERR_CHANOPRIVSNEEDED, chptr->name);
942 *errors |= SM_ERR_NOOPS;
943 return;
944 }
945
946 if (dir == MODE_QUERY)
947 return;
948
949 if (dir == MODE_ADD && parc > *parn)
950 {
951 char *const lstr = parv[(*parn)++];
952 int limit = 0;
953
954 if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
955 return;
956
957 sprintf(lstr, "%d", limit);
958
959 /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
960 for (unsigned int i = 0; i < mode_count; ++i)
961 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
962 mode_changes[i].letter = 0;
963
964 mode_changes[mode_count].letter = c;
965 mode_changes[mode_count].arg = lstr;
966 mode_changes[mode_count].id = NULL;
967 mode_changes[mode_count++].dir = dir;
968
969 chptr->mode.limit = limit;
970 }
971 else if (dir == MODE_DEL)
972 {
973 if (!chptr->mode.limit)
974 return;
975
976 chptr->mode.limit = 0;
977
978 mode_changes[mode_count].letter = c;
979 mode_changes[mode_count].arg = NULL;
980 mode_changes[mode_count].id = NULL;
981 mode_changes[mode_count++].dir = dir;
982 }
983 }
984
985 static void
986 chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
987 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
988 {
989 if (alev < CHACCESS_HALFOP)
990 {
991 if (!(*errors & SM_ERR_NOOPS))
992 sendto_one_numeric(source_p, &me,
993 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
994 ERR_CHANOPRIVSNEEDED, chptr->name);
995 *errors |= SM_ERR_NOOPS;
996 return;
997 }
998
999 if (dir == MODE_QUERY)
1000 return;
1001
1002 if (dir == MODE_ADD && parc > *parn)
1003 {
1004 char *const key = fix_key(parv[(*parn)++]);
1005
1006 if (EmptyString(key))
1007 return;
1008
1009 assert(key[0] != ' ');
1010 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1011
1012 /* If somebody does MODE #channel +kk a b, accept latter --fl */
1013 for (unsigned int i = 0; i < mode_count; ++i)
1014 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1015 mode_changes[i].letter = 0;
1016
1017 mode_changes[mode_count].letter = c;
1018 mode_changes[mode_count].arg = chptr->mode.key;
1019 mode_changes[mode_count].id = NULL;
1020 mode_changes[mode_count++].dir = dir;
1021 }
1022 else if (dir == MODE_DEL)
1023 {
1024 if (parc > *parn)
1025 ++(*parn);
1026
1027 if (chptr->mode.key[0] == '\0')
1028 return;
1029
1030 chptr->mode.key[0] = '\0';
1031
1032 mode_changes[mode_count].letter = c;
1033 mode_changes[mode_count].arg = "*";
1034 mode_changes[mode_count].id = NULL;
1035 mode_changes[mode_count++].dir = dir;
1036 }
1037 }
1038
1039 const struct ChannelMode ModeTable[256] =
1040 {
1041 { chm_nosuch, 0 }, /* 0x00 */
1042 { chm_nosuch, 0 }, /* 0x01 */
1043 { chm_nosuch, 0 }, /* 0x02 */
1044 { chm_nosuch, 0 }, /* 0x03 */
1045 { chm_nosuch, 0 }, /* 0x04 */
1046 { chm_nosuch, 0 }, /* 0x05 */
1047 { chm_nosuch, 0 }, /* 0x06 */
1048 { chm_nosuch, 0 }, /* 0x07 */
1049 { chm_nosuch, 0 }, /* 0x08 */
1050 { chm_nosuch, 0 }, /* 0x09 */
1051 { chm_nosuch, 0 }, /* 0x0a */
1052 { chm_nosuch, 0 }, /* 0x0b */
1053 { chm_nosuch, 0 }, /* 0x0c */
1054 { chm_nosuch, 0 }, /* 0x0d */
1055 { chm_nosuch, 0 }, /* 0x0e */
1056 { chm_nosuch, 0 }, /* 0x0f */
1057 { chm_nosuch, 0 }, /* 0x10 */
1058 { chm_nosuch, 0 }, /* 0x11 */
1059 { chm_nosuch, 0 }, /* 0x12 */
1060 { chm_nosuch, 0 }, /* 0x13 */
1061 { chm_nosuch, 0 }, /* 0x14 */
1062 { chm_nosuch, 0 }, /* 0x15 */
1063 { chm_nosuch, 0 }, /* 0x16 */
1064 { chm_nosuch, 0 }, /* 0x17 */
1065 { chm_nosuch, 0 }, /* 0x18 */
1066 { chm_nosuch, 0 }, /* 0x19 */
1067 { chm_nosuch, 0 }, /* 0x1a */
1068 { chm_nosuch, 0 }, /* 0x1b */
1069 { chm_nosuch, 0 }, /* 0x1c */
1070 { chm_nosuch, 0 }, /* 0x1d */
1071 { chm_nosuch, 0 }, /* 0x1e */
1072 { chm_nosuch, 0 }, /* 0x1f */
1073 { chm_nosuch, 0 }, /* 0x20 */
1074 { chm_nosuch, 0 }, /* 0x21 */
1075 { chm_nosuch, 0 }, /* 0x22 */
1076 { chm_nosuch, 0 }, /* 0x23 */
1077 { chm_nosuch, 0 }, /* 0x24 */
1078 { chm_nosuch, 0 }, /* 0x25 */
1079 { chm_nosuch, 0 }, /* 0x26 */
1080 { chm_nosuch, 0 }, /* 0x27 */
1081 { chm_nosuch, 0 }, /* 0x28 */
1082 { chm_nosuch, 0 }, /* 0x29 */
1083 { chm_nosuch, 0 }, /* 0x2a */
1084 { chm_nosuch, 0 }, /* 0x2b */
1085 { chm_nosuch, 0 }, /* 0x2c */
1086 { chm_nosuch, 0 }, /* 0x2d */
1087 { chm_nosuch, 0 }, /* 0x2e */
1088 { chm_nosuch, 0 }, /* 0x2f */
1089 { chm_nosuch, 0 }, /* 0x30 */
1090 { chm_nosuch, 0 }, /* 0x31 */
1091 { chm_nosuch, 0 }, /* 0x32 */
1092 { chm_nosuch, 0 }, /* 0x33 */
1093 { chm_nosuch, 0 }, /* 0x34 */
1094 { chm_nosuch, 0 }, /* 0x35 */
1095 { chm_nosuch, 0 }, /* 0x36 */
1096 { chm_nosuch, 0 }, /* 0x37 */
1097 { chm_nosuch, 0 }, /* 0x38 */
1098 { chm_nosuch, 0 }, /* 0x39 */
1099 { chm_nosuch, 0 }, /* 0x3a */
1100 { chm_nosuch, 0 }, /* 0x3b */
1101 { chm_nosuch, 0 }, /* 0x3c */
1102 { chm_nosuch, 0 }, /* 0x3d */
1103 { chm_nosuch, 0 }, /* 0x3e */
1104 { chm_nosuch, 0 }, /* 0x3f */
1105 { chm_nosuch, 0 }, /* @ */
1106 { chm_nosuch, 0 }, /* A */
1107 { chm_nosuch, 0 }, /* B */
1108 { chm_simple, MODE_NOCTCP }, /* C */
1109 { chm_nosuch, 0 }, /* D */
1110 { chm_nosuch, 0 }, /* E */
1111 { chm_nosuch, 0 }, /* F */
1112 { chm_nosuch, 0 }, /* G */
1113 { chm_nosuch, 0 }, /* H */
1114 { chm_invex, 0 }, /* I */
1115 { chm_nosuch, 0 }, /* J */
1116 { chm_nosuch, 0 }, /* K */
1117 { chm_nosuch, 0 }, /* L */
1118 { chm_simple, MODE_MODREG}, /* M */
1119 { chm_nosuch, 0 }, /* N */
1120 { chm_operonly, MODE_OPERONLY}, /* O */
1121 { chm_nosuch, 0 }, /* P */
1122 { chm_nosuch, 0 }, /* Q */
1123 { chm_simple, MODE_REGONLY}, /* R */
1124 { chm_simple, MODE_SSLONLY}, /* S */
1125 { chm_simple, MODE_NONOTICE}, /* T */
1126 { chm_nosuch, 0 }, /* U */
1127 { chm_nosuch, 0 }, /* V */
1128 { chm_nosuch, 0 }, /* W */
1129 { chm_nosuch, 0 }, /* X */
1130 { chm_nosuch, 0 }, /* Y */
1131 { chm_nosuch, 0 }, /* Z */
1132 { chm_nosuch, 0 },
1133 { chm_nosuch, 0 },
1134 { chm_nosuch, 0 },
1135 { chm_nosuch, 0 },
1136 { chm_nosuch, 0 },
1137 { chm_nosuch, 0 },
1138 { chm_nosuch, 0 }, /* a */
1139 { chm_ban, 0 }, /* b */
1140 { chm_simple, MODE_NOCTRL}, /* c */
1141 { chm_nosuch, 0 }, /* d */
1142 { chm_except, 0 }, /* e */
1143 { chm_nosuch, 0 }, /* f */
1144 { chm_nosuch, 0 }, /* g */
1145 { chm_hop, 0 }, /* h */
1146 { chm_simple, MODE_INVITEONLY }, /* i */
1147 { chm_nosuch, 0 }, /* j */
1148 { chm_key, 0 }, /* k */
1149 { chm_limit, 0 }, /* l */
1150 { chm_simple, MODE_MODERATED }, /* m */
1151 { chm_simple, MODE_NOPRIVMSGS }, /* n */
1152 { chm_op, 0 }, /* o */
1153 { chm_simple, MODE_PRIVATE }, /* p */
1154 { chm_nosuch, 0 }, /* q */
1155 { chm_registered, MODE_REGISTERED }, /* r */
1156 { chm_simple, MODE_SECRET }, /* s */
1157 { chm_simple, MODE_TOPICLIMIT }, /* t */
1158 { chm_nosuch, 0 }, /* u */
1159 { chm_voice, 0 }, /* v */
1160 { chm_nosuch, 0 }, /* w */
1161 { chm_nosuch, 0 }, /* x */
1162 { chm_nosuch, 0 }, /* y */
1163 { chm_nosuch, 0 }, /* z */
1164 { chm_nosuch, 0 }, /* 0x7b */
1165 { chm_nosuch, 0 }, /* 0x7c */
1166 { chm_nosuch, 0 }, /* 0x7d */
1167 { chm_nosuch, 0 }, /* 0x7e */
1168 { chm_nosuch, 0 }, /* 0x7f */
1169 { chm_nosuch, 0 }, /* 0x80 */
1170 { chm_nosuch, 0 }, /* 0x81 */
1171 { chm_nosuch, 0 }, /* 0x82 */
1172 { chm_nosuch, 0 }, /* 0x83 */
1173 { chm_nosuch, 0 }, /* 0x84 */
1174 { chm_nosuch, 0 }, /* 0x85 */
1175 { chm_nosuch, 0 }, /* 0x86 */
1176 { chm_nosuch, 0 }, /* 0x87 */
1177 { chm_nosuch, 0 }, /* 0x88 */
1178 { chm_nosuch, 0 }, /* 0x89 */
1179 { chm_nosuch, 0 }, /* 0x8a */
1180 { chm_nosuch, 0 }, /* 0x8b */
1181 { chm_nosuch, 0 }, /* 0x8c */
1182 { chm_nosuch, 0 }, /* 0x8d */
1183 { chm_nosuch, 0 }, /* 0x8e */
1184 { chm_nosuch, 0 }, /* 0x8f */
1185 { chm_nosuch, 0 }, /* 0x90 */
1186 { chm_nosuch, 0 }, /* 0x91 */
1187 { chm_nosuch, 0 }, /* 0x92 */
1188 { chm_nosuch, 0 }, /* 0x93 */
1189 { chm_nosuch, 0 }, /* 0x94 */
1190 { chm_nosuch, 0 }, /* 0x95 */
1191 { chm_nosuch, 0 }, /* 0x96 */
1192 { chm_nosuch, 0 }, /* 0x97 */
1193 { chm_nosuch, 0 }, /* 0x98 */
1194 { chm_nosuch, 0 }, /* 0x99 */
1195 { chm_nosuch, 0 }, /* 0x9a */
1196 { chm_nosuch, 0 }, /* 0x9b */
1197 { chm_nosuch, 0 }, /* 0x9c */
1198 { chm_nosuch, 0 }, /* 0x9d */
1199 { chm_nosuch, 0 }, /* 0x9e */
1200 { chm_nosuch, 0 }, /* 0x9f */
1201 { chm_nosuch, 0 }, /* 0xa0 */
1202 { chm_nosuch, 0 }, /* 0xa1 */
1203 { chm_nosuch, 0 }, /* 0xa2 */
1204 { chm_nosuch, 0 }, /* 0xa3 */
1205 { chm_nosuch, 0 }, /* 0xa4 */
1206 { chm_nosuch, 0 }, /* 0xa5 */
1207 { chm_nosuch, 0 }, /* 0xa6 */
1208 { chm_nosuch, 0 }, /* 0xa7 */
1209 { chm_nosuch, 0 }, /* 0xa8 */
1210 { chm_nosuch, 0 }, /* 0xa9 */
1211 { chm_nosuch, 0 }, /* 0xaa */
1212 { chm_nosuch, 0 }, /* 0xab */
1213 { chm_nosuch, 0 }, /* 0xac */
1214 { chm_nosuch, 0 }, /* 0xad */
1215 { chm_nosuch, 0 }, /* 0xae */
1216 { chm_nosuch, 0 }, /* 0xaf */
1217 { chm_nosuch, 0 }, /* 0xb0 */
1218 { chm_nosuch, 0 }, /* 0xb1 */
1219 { chm_nosuch, 0 }, /* 0xb2 */
1220 { chm_nosuch, 0 }, /* 0xb3 */
1221 { chm_nosuch, 0 }, /* 0xb4 */
1222 { chm_nosuch, 0 }, /* 0xb5 */
1223 { chm_nosuch, 0 }, /* 0xb6 */
1224 { chm_nosuch, 0 }, /* 0xb7 */
1225 { chm_nosuch, 0 }, /* 0xb8 */
1226 { chm_nosuch, 0 }, /* 0xb9 */
1227 { chm_nosuch, 0 }, /* 0xba */
1228 { chm_nosuch, 0 }, /* 0xbb */
1229 { chm_nosuch, 0 }, /* 0xbc */
1230 { chm_nosuch, 0 }, /* 0xbd */
1231 { chm_nosuch, 0 }, /* 0xbe */
1232 { chm_nosuch, 0 }, /* 0xbf */
1233 { chm_nosuch, 0 }, /* 0xc0 */
1234 { chm_nosuch, 0 }, /* 0xc1 */
1235 { chm_nosuch, 0 }, /* 0xc2 */
1236 { chm_nosuch, 0 }, /* 0xc3 */
1237 { chm_nosuch, 0 }, /* 0xc4 */
1238 { chm_nosuch, 0 }, /* 0xc5 */
1239 { chm_nosuch, 0 }, /* 0xc6 */
1240 { chm_nosuch, 0 }, /* 0xc7 */
1241 { chm_nosuch, 0 }, /* 0xc8 */
1242 { chm_nosuch, 0 }, /* 0xc9 */
1243 { chm_nosuch, 0 }, /* 0xca */
1244 { chm_nosuch, 0 }, /* 0xcb */
1245 { chm_nosuch, 0 }, /* 0xcc */
1246 { chm_nosuch, 0 }, /* 0xcd */
1247 { chm_nosuch, 0 }, /* 0xce */
1248 { chm_nosuch, 0 }, /* 0xcf */
1249 { chm_nosuch, 0 }, /* 0xd0 */
1250 { chm_nosuch, 0 }, /* 0xd1 */
1251 { chm_nosuch, 0 }, /* 0xd2 */
1252 { chm_nosuch, 0 }, /* 0xd3 */
1253 { chm_nosuch, 0 }, /* 0xd4 */
1254 { chm_nosuch, 0 }, /* 0xd5 */
1255 { chm_nosuch, 0 }, /* 0xd6 */
1256 { chm_nosuch, 0 }, /* 0xd7 */
1257 { chm_nosuch, 0 }, /* 0xd8 */
1258 { chm_nosuch, 0 }, /* 0xd9 */
1259 { chm_nosuch, 0 }, /* 0xda */
1260 { chm_nosuch, 0 }, /* 0xdb */
1261 { chm_nosuch, 0 }, /* 0xdc */
1262 { chm_nosuch, 0 }, /* 0xdd */
1263 { chm_nosuch, 0 }, /* 0xde */
1264 { chm_nosuch, 0 }, /* 0xdf */
1265 { chm_nosuch, 0 }, /* 0xe0 */
1266 { chm_nosuch, 0 }, /* 0xe1 */
1267 { chm_nosuch, 0 }, /* 0xe2 */
1268 { chm_nosuch, 0 }, /* 0xe3 */
1269 { chm_nosuch, 0 }, /* 0xe4 */
1270 { chm_nosuch, 0 }, /* 0xe5 */
1271 { chm_nosuch, 0 }, /* 0xe6 */
1272 { chm_nosuch, 0 }, /* 0xe7 */
1273 { chm_nosuch, 0 }, /* 0xe8 */
1274 { chm_nosuch, 0 }, /* 0xe9 */
1275 { chm_nosuch, 0 }, /* 0xea */
1276 { chm_nosuch, 0 }, /* 0xeb */
1277 { chm_nosuch, 0 }, /* 0xec */
1278 { chm_nosuch, 0 }, /* 0xed */
1279 { chm_nosuch, 0 }, /* 0xee */
1280 { chm_nosuch, 0 }, /* 0xef */
1281 { chm_nosuch, 0 }, /* 0xf0 */
1282 { chm_nosuch, 0 }, /* 0xf1 */
1283 { chm_nosuch, 0 }, /* 0xf2 */
1284 { chm_nosuch, 0 }, /* 0xf3 */
1285 { chm_nosuch, 0 }, /* 0xf4 */
1286 { chm_nosuch, 0 }, /* 0xf5 */
1287 { chm_nosuch, 0 }, /* 0xf6 */
1288 { chm_nosuch, 0 }, /* 0xf7 */
1289 { chm_nosuch, 0 }, /* 0xf8 */
1290 { chm_nosuch, 0 }, /* 0xf9 */
1291 { chm_nosuch, 0 }, /* 0xfa */
1292 { chm_nosuch, 0 }, /* 0xfb */
1293 { chm_nosuch, 0 }, /* 0xfc */
1294 { chm_nosuch, 0 }, /* 0xfd */
1295 { chm_nosuch, 0 }, /* 0xfe */
1296 { chm_nosuch, 0 }, /* 0xff */
1297 };
1298
1299 /* get_channel_access()
1300 *
1301 * inputs - pointer to Client struct
1302 * - pointer to Membership struct
1303 * output - CHACCESS_CHANOP if we should let them have
1304 * chanop level access, 0 for peon level access.
1305 * side effects - NONE
1306 */
1307 static int
1308 get_channel_access(const struct Client *source_p,
1309 const struct Membership *member)
1310 {
1311 /* Let hacked servers in for now... */
1312 if (!MyClient(source_p))
1313 return CHACCESS_REMOTE;
1314
1315 if (!member)
1316 return CHACCESS_NOTONCHAN;
1317
1318 /* Just to be sure.. */
1319 assert(source_p == member->client_p);
1320
1321 if (has_member_flags(member, CHFL_CHANOP))
1322 return CHACCESS_CHANOP;
1323
1324 if (has_member_flags(member, CHFL_HALFOP))
1325 return CHACCESS_HALFOP;
1326
1327 return CHACCESS_PEON;
1328 }
1329
1330 /* send_mode_changes_server()
1331 * Input: the source client(source_p),
1332 * the channel to send mode changes for(chptr)
1333 * Output: None.
1334 * Side-effects: Sends the appropriate mode changes to servers.
1335 *
1336 */
1337 static void
1338 send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1339 {
1340 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1341 int len = 0;
1342 int dir = MODE_QUERY;
1343 const char *arg = NULL;
1344 char *parptr = NULL;
1345
1346 parabuf[0] = '\0';
1347 parptr = parabuf;
1348
1349 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", source_p->id,
1350 chptr->creationtime, chptr->name);
1351
1352 /* Loop the list of modes we have */
1353 for (unsigned int i = 0; i < mode_count; ++i)
1354 {
1355 if (mode_changes[i].letter == 0)
1356 continue;
1357
1358 if (mode_changes[i].id)
1359 arg = mode_changes[i].id;
1360 else
1361 arg = mode_changes[i].arg;
1362
1363 if (arg)
1364 arglen = strlen(arg);
1365 else
1366 arglen = 0;
1367
1368 /*
1369 * If we're creeping past the buf size, we need to send it and make
1370 * another line for the other modes
1371 */
1372 if ((mc == MAXMODEPARAMS) ||
1373 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1374 (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1375 {
1376 if (nc)
1377 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1378
1379 nc = 0;
1380 mc = 0;
1381
1382 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %ju %s ", source_p->id,
1383 chptr->creationtime, chptr->name);
1384
1385 pbl = 0;
1386 parabuf[0] = '\0';
1387 parptr = parabuf;
1388 dir = MODE_QUERY;
1389 }
1390
1391 if (dir != mode_changes[i].dir)
1392 {
1393 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1394 dir = mode_changes[i].dir;
1395 }
1396
1397 modebuf[mbl++] = mode_changes[i].letter;
1398 modebuf[mbl] = '\0';
1399 ++nc;
1400
1401 if (arg)
1402 {
1403 len = sprintf(parptr, "%s ", arg);
1404 pbl += len;
1405 parptr += len;
1406 ++mc;
1407 }
1408 }
1409
1410 if (pbl && parabuf[pbl - 1] == ' ')
1411 parabuf[pbl - 1] = '\0';
1412
1413 if (nc)
1414 sendto_server(source_p, 0, 0, "%s %s", modebuf, parabuf);
1415 }
1416
1417 /* void send_mode_changes(struct Client *client_p,
1418 * struct Client *source_p,
1419 * struct Channel *chptr)
1420 * Input: The client sending(client_p), the source client(source_p),
1421 * the channel to send mode changes for(chptr),
1422 * mode change globals.
1423 * Output: None.
1424 * Side-effects: Sends the appropriate mode changes to other clients
1425 * and propagates to servers.
1426 */
1427 /* ensure parabuf < MODEBUFLEN -db */
1428 static void
1429 send_mode_changes_client(struct Client *source_p, struct Channel *chptr)
1430 {
1431 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1432 int len = 0;
1433 int dir = MODE_QUERY;
1434 const char *arg = NULL;
1435 char *parptr = NULL;
1436
1437 if (IsServer(source_p))
1438 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1439 ConfigServerHide.hide_servers) ?
1440 me.name : source_p->name, chptr->name);
1441 else
1442 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1443 source_p->username, source_p->host, chptr->name);
1444
1445 parabuf[0] = '\0';
1446 parptr = parabuf;
1447
1448 for (unsigned int i = 0; i < mode_count; ++i)
1449 {
1450 if (mode_changes[i].letter == 0)
1451 continue;
1452
1453 arg = mode_changes[i].arg;
1454 if (arg)
1455 arglen = strlen(arg);
1456 else
1457 arglen = 0;
1458
1459 if ((mc == MAXMODEPARAMS) ||
1460 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1461 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1462 {
1463 if (mbl && modebuf[mbl - 1] == '-')
1464 modebuf[mbl - 1] = '\0';
1465
1466 if (nc)
1467 sendto_channel_local(NULL, chptr, 0, 0, 0, "%s %s", modebuf, parabuf);
1468
1469 nc = 0;
1470 mc = 0;
1471
1472 if (IsServer(source_p))
1473 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1474 ConfigServerHide.hide_servers) ?
1475 me.name : source_p->name, chptr->name);
1476 else
1477 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1478 source_p->username, source_p->host, chptr->name);
1479
1480 pbl = 0;
1481 parabuf[0] = '\0';
1482 parptr = parabuf;
1483 dir = MODE_QUERY;
1484 }
1485
1486 if (dir != mode_changes[i].dir)
1487 {
1488 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1489 dir = mode_changes[i].dir;
1490 }
1491
1492 modebuf[mbl++] = mode_changes[i].letter;
1493 modebuf[mbl] = '\0';
1494 ++nc;
1495
1496 if (arg)
1497 {
1498 len = sprintf(parptr, "%s ", arg);
1499 pbl += len;
1500 parptr += len;
1501 ++mc;
1502 }
1503 }
1504
1505 if (pbl && parabuf[pbl - 1] == ' ')
1506 parabuf[pbl - 1] = '\0';
1507
1508 if (nc)
1509 sendto_channel_local(NULL, chptr, 0, 0, 0, "%s %s", modebuf, parabuf);
1510 }
1511
1512 /*
1513 * Input: The the client this originated
1514 * from, the channel, the parameter count starting at the modes,
1515 * the parameters, the channel name.
1516 * Output: None.
1517 * Side-effects: Changes the channel membership and modes appropriately,
1518 * sends the appropriate MODE messages to the appropriate
1519 * clients.
1520 */
1521 void
1522 set_channel_mode(struct Client *source_p, struct Channel *chptr,
1523 struct Membership *member, int parc, char *parv[])
1524 {
1525 int dir = MODE_ADD;
1526 int parn = 1;
1527 int alevel = 0, errors = 0;
1528
1529 mode_count = 0;
1530 mode_limit = 0;
1531 simple_modes_mask = 0;
1532
1533 alevel = get_channel_access(source_p, member);
1534
1535 for (const char *ml = parv[0]; *ml; ++ml)
1536 {
1537 switch (*ml)
1538 {
1539 case '+':
1540 dir = MODE_ADD;
1541 break;
1542 case '-':
1543 dir = MODE_DEL;
1544 break;
1545 case '=':
1546 dir = MODE_QUERY;
1547 break;
1548 default:
1549 {
1550 const struct ChannelMode *tptr = &ModeTable[(unsigned char)*ml];
1551
1552 tptr->func(source_p, chptr, parc, &parn, parv,
1553 &errors, alevel, dir, *ml, tptr->d);
1554 break;
1555 }
1556 }
1557 }
1558
1559 /* Bail out if we have nothing to do... */
1560 if (!mode_count)
1561 return;
1562
1563 send_mode_changes_client(source_p, chptr);
1564 send_mode_changes_server(source_p, chptr);
1565 }

Properties

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