ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3695
Committed: Thu May 29 19:38:18 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 45456 byte(s)
Log Message:
- Removed CHFL_DEOPPED flags which is no longer needed with TS6

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

Properties

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