ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 4176
Committed: Sat Jul 5 17:41:13 2014 UTC (11 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 43534 byte(s)
Log Message:
- channel_mode.c:clear_ban_cache(): use locmembers list

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

Properties

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