ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3504
Committed: Sat May 10 19:51:29 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 46059 byte(s)
Log Message:
- Renamed MyMalloc() to MyCalloc()

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

Properties

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