ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3150
Committed: Fri Mar 14 14:11:34 2014 UTC (10 years, 1 month ago) by michael
Content type: text/x-csrc
File size: 47579 byte(s)
Log Message:
- Removed unused client_p pointer from all chm_* channel mode handlers

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

Properties

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