ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/src/channel_mode.c
Revision: 4816
Committed: Sat Nov 1 15:29:49 2014 UTC (9 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 42545 byte(s)
Log Message:
- Renamed variables

File Contents

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

Properties

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