ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3704
Committed: Fri May 30 16:14:30 2014 UTC (11 years, 3 months ago) by michael
Content type: text/x-csrc
File size: 45380 byte(s)
Log Message:
- channel_mode.c:send_mode_changes(): removed anonops leftovers

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 1997-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file channel_mode.c
23 * \brief Controls modes on channels.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "list.h"
29 #include "channel.h"
30 #include "channel_mode.h"
31 #include "client.h"
32 #include "conf.h"
33 #include "hostmask.h"
34 #include "irc_string.h"
35 #include "ircd.h"
36 #include "numeric.h"
37 #include "server.h"
38 #include "send.h"
39 #include "memory.h"
40 #include "mempool.h"
41 #include "parse.h"
42
43 /* 10 is a magic number in hybrid 6 NFI where it comes from -db */
44 #define BAN_FUDGE 10
45
46 static char nuh_mask[MAXPARA][IRCD_BUFSIZE];
47 /* some buffers for rebuilding channel/nick lists with ,'s */
48 static char modebuf[IRCD_BUFSIZE];
49 static char parabuf[MODEBUFLEN];
50 static struct ChModeChange mode_changes[IRCD_BUFSIZE];
51 static unsigned int mode_count;
52 static unsigned int mode_limit; /* number of modes set other than simple */
53 static unsigned int simple_modes_mask; /* bit mask of simple modes already set */
54 extern mp_pool_t *ban_pool;
55
56 const struct mode_letter chan_modes[] =
57 {
58 { MODE_NOCTRL, 'c' },
59 { MODE_INVITEONLY, 'i' },
60 { MODE_MODERATED, 'm' },
61 { MODE_NOPRIVMSGS, 'n' },
62 { MODE_PRIVATE, 'p' },
63 { MODE_REGISTERED, 'r' },
64 { MODE_SECRET, 's' },
65 { MODE_TOPICLIMIT, 't' },
66 { MODE_MODREG, 'M' },
67 { MODE_OPERONLY, 'O' },
68 { MODE_REGONLY, 'R' },
69 { MODE_SSLONLY, 'S' },
70 { 0, '\0' }
71 };
72
73
74 /* check_string()
75 *
76 * inputs - string to check
77 * output - pointer to modified string
78 * side effects - Fixes a string so that the first white space found
79 * becomes an end of string marker (`\0`).
80 * returns the 'fixed' string or "*" if the string
81 * was NULL length or a NULL pointer.
82 */
83 static char *
84 check_string(char *s)
85 {
86 char *str = s;
87 static char star[] = "*";
88
89 if (EmptyString(str))
90 return star;
91
92 for (; *s; ++s)
93 {
94 if (IsSpace(*s))
95 {
96 *s = '\0';
97 break;
98 }
99 }
100
101 return EmptyString(str) ? star : str;
102 }
103
104 /*
105 * Ban functions to work with mode +b/e/d/I
106 */
107 /* add the specified ID to the channel.
108 * -is 8/9/00
109 */
110
111 int
112 add_id(struct Client *client_p, struct Channel *chptr, char *banid, unsigned int type)
113 {
114 dlink_list *list = NULL;
115 dlink_node *ptr = NULL;
116 struct Ban *banptr = NULL;
117 size_t len = 0;
118 char name[NICKLEN + 1] = "";
119 char user[USERLEN + 1] = "";
120 char host[HOSTLEN + 1] = "";
121 struct split_nuh_item nuh;
122
123 /* Don't let local clients overflow the b/e/I lists */
124 if (MyClient(client_p))
125 {
126 unsigned int num_mask = dlink_list_length(&chptr->banlist) +
127 dlink_list_length(&chptr->exceptlist) +
128 dlink_list_length(&chptr->invexlist);
129
130 if (num_mask >= ConfigChannel.max_bans)
131 {
132 sendto_one_numeric(client_p, &me, ERR_BANLISTFULL, chptr->chname, banid);
133 return 0;
134 }
135
136 collapse(banid);
137 }
138
139 nuh.nuhmask = check_string(banid);
140 nuh.nickptr = name;
141 nuh.userptr = user;
142 nuh.hostptr = host;
143
144 nuh.nicksize = sizeof(name);
145 nuh.usersize = sizeof(user);
146 nuh.hostsize = sizeof(host);
147
148 split_nuh(&nuh);
149
150 /*
151 * Re-assemble a new n!u@h and print it back to banid for sending
152 * the mode to the channel.
153 */
154 len = sprintf(banid, "%s!%s@%s", name, user, host);
155
156 switch (type)
157 {
158 case CHFL_BAN:
159 list = &chptr->banlist;
160 clear_ban_cache(chptr);
161 break;
162 case CHFL_EXCEPTION:
163 list = &chptr->exceptlist;
164 clear_ban_cache(chptr);
165 break;
166 case CHFL_INVEX:
167 list = &chptr->invexlist;
168 break;
169 default:
170 assert(0);
171 return 0;
172 }
173
174 DLINK_FOREACH(ptr, list->head)
175 {
176 banptr = ptr->data;
177
178 if (!irccmp(banptr->name, name) &&
179 !irccmp(banptr->user, user) &&
180 !irccmp(banptr->host, host))
181 return 0;
182 }
183
184 banptr = mp_pool_get(ban_pool);
185 memset(banptr, 0, sizeof(*banptr));
186
187 banptr->name = xstrdup(name);
188 banptr->user = xstrdup(user);
189 banptr->host = xstrdup(host);
190 banptr->when = CurrentTime;
191 banptr->len = len - 2; /* -2 for @ and ! */
192 banptr->type = parse_netmask(host, &banptr->addr, &banptr->bits);
193
194 if (IsClient(client_p))
195 {
196 banptr->who = MyCalloc(strlen(client_p->name) +
197 strlen(client_p->username) +
198 strlen(client_p->host) + 3);
199 sprintf(banptr->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 banptr->who = xstrdup(me.name);
204 else
205 banptr->who = xstrdup(client_p->name);
206
207 dlinkAdd(banptr, &banptr->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 *ptr = 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(ptr, list->head)
267 {
268 struct Ban *banptr = ptr->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, int parc, int *parn,
539 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
540 {
541 if (alev < CHACCESS_HALFOP)
542 {
543 if (!(*errors & SM_ERR_NOOPS))
544 sendto_one_numeric(source_p, &me,
545 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
546 ERR_CHANOPRIVSNEEDED, chptr->chname);
547
548 *errors |= SM_ERR_NOOPS;
549 return;
550 }
551
552 if (MyClient(source_p) && !HasUMode(source_p, UMODE_OPER))
553 {
554 if (!(*errors & SM_ERR_NOTOPER))
555 sendto_one_numeric(source_p, &me, ERR_NOPRIVILEGES);
556
557 *errors |= SM_ERR_NOTOPER;
558 return;
559 }
560
561 /* If have already dealt with this simple mode, ignore it */
562 if (simple_modes_mask & d)
563 return;
564
565 simple_modes_mask |= d;
566
567 if (dir == MODE_ADD) /* && !(chptr->mode.mode & d)) */
568 {
569 chptr->mode.mode |= d;
570
571 mode_changes[mode_count].letter = c;
572 mode_changes[mode_count].dir = MODE_ADD;
573 mode_changes[mode_count].id = NULL;
574 mode_changes[mode_count].mems = ALL_MEMBERS;
575 mode_changes[mode_count++].arg = NULL;
576 }
577 else if (dir == MODE_DEL) /* && (chptr->mode.mode & d)) */
578 {
579 /* setting - */
580
581 chptr->mode.mode &= ~d;
582
583 mode_changes[mode_count].letter = c;
584 mode_changes[mode_count].dir = MODE_DEL;
585 mode_changes[mode_count].mems = ALL_MEMBERS;
586 mode_changes[mode_count].id = NULL;
587 mode_changes[mode_count++].arg = NULL;
588 }
589 }
590
591 static void
592 chm_ban(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
593 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
594 {
595 char *mask = NULL;
596
597 if (dir == MODE_QUERY || parc <= *parn)
598 {
599 dlink_node *ptr = NULL;
600
601 if (*errors & SM_ERR_RPL_B)
602 return;
603
604 *errors |= SM_ERR_RPL_B;
605
606 DLINK_FOREACH(ptr, chptr->banlist.head)
607 {
608 const struct Ban *banptr = ptr->data;
609 sendto_one_numeric(source_p, &me, RPL_BANLIST, chptr->chname,
610 banptr->name, banptr->user, banptr->host,
611 banptr->who, banptr->when);
612 }
613
614 sendto_one_numeric(source_p, &me, RPL_ENDOFBANLIST, chptr->chname);
615 return;
616 }
617
618 if (alev < CHACCESS_HALFOP)
619 {
620 if (!(*errors & SM_ERR_NOOPS))
621 sendto_one_numeric(source_p, &me,
622 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
623 ERR_CHANOPRIVSNEEDED, chptr->chname);
624 *errors |= SM_ERR_NOOPS;
625 return;
626 }
627
628 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
629 return;
630
631 mask = nuh_mask[*parn];
632 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
633 ++*parn;
634
635 if (!MyConnect(source_p))
636 if (strchr(mask, ' '))
637 return;
638
639 switch (dir)
640 {
641 case MODE_ADD:
642 if (!add_id(source_p, chptr, mask, CHFL_BAN))
643 return;
644 break;
645 case MODE_DEL:
646 if (!del_id(chptr, mask, CHFL_BAN))
647 return;
648 break;
649 default:
650 assert(0);
651 }
652
653 mode_changes[mode_count].letter = c;
654 mode_changes[mode_count].dir = dir;
655 mode_changes[mode_count].mems = ALL_MEMBERS;
656 mode_changes[mode_count].id = NULL;
657 mode_changes[mode_count++].arg = mask;
658 }
659
660 static void
661 chm_except(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
662 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
663 {
664 char *mask = NULL;
665
666 if (alev < CHACCESS_HALFOP)
667 {
668 if (!(*errors & SM_ERR_NOOPS))
669 sendto_one_numeric(source_p, &me,
670 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
671 ERR_CHANOPRIVSNEEDED, chptr->chname);
672 *errors |= SM_ERR_NOOPS;
673 return;
674 }
675
676 if (dir == MODE_QUERY || parc <= *parn)
677 {
678 dlink_node *ptr = NULL;
679
680 if (*errors & SM_ERR_RPL_E)
681 return;
682
683 *errors |= SM_ERR_RPL_E;
684
685 DLINK_FOREACH(ptr, chptr->exceptlist.head)
686 {
687 const struct Ban *banptr = ptr->data;
688
689 sendto_one_numeric(source_p, &me, RPL_EXCEPTLIST, chptr->chname,
690 banptr->name, banptr->user, banptr->host,
691 banptr->who, banptr->when);
692 }
693
694 sendto_one_numeric(source_p, &me, RPL_ENDOFEXCEPTLIST, chptr->chname);
695 return;
696 }
697
698 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
699 return;
700
701 mask = nuh_mask[*parn];
702 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
703 ++*parn;
704
705 if (!MyConnect(source_p))
706 if (strchr(mask, ' '))
707 return;
708
709 switch (dir)
710 {
711 case MODE_ADD:
712 if (!add_id(source_p, chptr, mask, CHFL_EXCEPTION))
713 return;
714 break;
715 case MODE_DEL:
716 if (!del_id(chptr, mask, CHFL_EXCEPTION))
717 return;
718 break;
719 default:
720 assert(0);
721 }
722
723 mode_changes[mode_count].letter = c;
724 mode_changes[mode_count].dir = dir;
725 mode_changes[mode_count].mems = ONLY_CHANOPS;
726 mode_changes[mode_count].id = NULL;
727 mode_changes[mode_count++].arg = mask;
728 }
729
730 static void
731 chm_invex(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
732 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
733 {
734 char *mask = NULL;
735
736 if (alev < CHACCESS_HALFOP)
737 {
738 if (!(*errors & SM_ERR_NOOPS))
739 sendto_one_numeric(source_p, &me,
740 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
741 ERR_CHANOPRIVSNEEDED, chptr->chname);
742 *errors |= SM_ERR_NOOPS;
743 return;
744 }
745
746 if (dir == MODE_QUERY || parc <= *parn)
747 {
748 dlink_node *ptr = NULL;
749
750 if (*errors & SM_ERR_RPL_I)
751 return;
752
753 *errors |= SM_ERR_RPL_I;
754
755 DLINK_FOREACH(ptr, chptr->invexlist.head)
756 {
757 const struct Ban *banptr = ptr->data;
758
759 sendto_one_numeric(source_p, &me, RPL_INVITELIST, chptr->chname,
760 banptr->name, banptr->user, banptr->host,
761 banptr->who, banptr->when);
762 }
763
764 sendto_one_numeric(source_p, &me, RPL_ENDOFINVITELIST, chptr->chname);
765 return;
766 }
767
768 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
769 return;
770
771 mask = nuh_mask[*parn];
772 memcpy(mask, parv[*parn], sizeof(nuh_mask[*parn]));
773 ++*parn;
774
775 if (!MyConnect(source_p))
776 if (strchr(mask, ' '))
777 return;
778
779 switch (dir)
780 {
781 case MODE_ADD:
782 if (!add_id(source_p, chptr, mask, CHFL_INVEX))
783 return;
784 break;
785 case MODE_DEL:
786 if (!del_id(chptr, mask, CHFL_INVEX))
787 return;
788 break;
789 default:
790 assert(0);
791 }
792
793 mode_changes[mode_count].letter = c;
794 mode_changes[mode_count].dir = dir;
795 mode_changes[mode_count].mems = ONLY_CHANOPS;
796 mode_changes[mode_count].id = NULL;
797 mode_changes[mode_count++].arg = mask;
798 }
799
800 static void
801 chm_voice(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
802 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
803 {
804 struct Client *target_p;
805 struct Membership *member;
806
807 if (alev < CHACCESS_HALFOP)
808 {
809 if (!(*errors & SM_ERR_NOOPS))
810 sendto_one_numeric(source_p, &me,
811 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
812 ERR_CHANOPRIVSNEEDED, chptr->chname);
813 *errors |= SM_ERR_NOOPS;
814 return;
815 }
816
817 if (dir == MODE_QUERY || parc <= *parn)
818 return;
819
820 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
821 return;
822
823 if ((member = find_channel_link(target_p, chptr)) == NULL)
824 {
825 if (!(*errors & SM_ERR_NOTONCHANNEL))
826 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->chname);
827 *errors |= SM_ERR_NOTONCHANNEL;
828 return;
829 }
830
831 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
832 return;
833
834 /* no redundant mode changes */
835 if (dir == MODE_ADD && has_member_flags(member, CHFL_VOICE))
836 return;
837 if (dir == MODE_DEL && !has_member_flags(member, CHFL_VOICE))
838 return;
839
840 mode_changes[mode_count].letter = 'v';
841 mode_changes[mode_count].dir = dir;
842 mode_changes[mode_count].mems = ALL_MEMBERS;
843 mode_changes[mode_count].id = target_p->id;
844 mode_changes[mode_count].arg = target_p->name;
845 mode_changes[mode_count++].client = target_p;
846
847 if (dir == MODE_ADD)
848 AddMemberFlag(member, CHFL_VOICE);
849 else
850 DelMemberFlag(member, CHFL_VOICE);
851 }
852
853 #ifdef HALFOPS
854 static void
855 chm_hop(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
856 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
857 {
858 struct Client *target_p;
859 struct Membership *member;
860
861 /* *sigh* - dont allow halfops to set +/-h, they could fully control a
862 * channel if there were no ops - it doesnt solve anything.. MODE_PRIVATE
863 * when used with MODE_SECRET is paranoid - cant use +p
864 *
865 * it needs to be optional per channel - but not via +p, that or remove
866 * paranoid.. -- fl_
867 *
868 * +p means paranoid, it is useless for anything else on modern IRC, as
869 * list isn't really usable. If you want to have a private channel these
870 * days, you set it +s. Halfops can no longer remove simple modes when
871 * +p is set (although they can set +p) so it is safe to use this to
872 * control whether they can (de)halfop...
873 */
874 if (alev <
875 ((chptr->mode.mode & MODE_PRIVATE) ? CHACCESS_CHANOP : CHACCESS_HALFOP))
876 {
877 if (!(*errors & SM_ERR_NOOPS))
878 sendto_one_numeric(source_p, &me,
879 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
880 ERR_CHANOPRIVSNEEDED, chptr->chname);
881 *errors |= SM_ERR_NOOPS;
882 return;
883 }
884
885 if (dir == MODE_QUERY || parc <= *parn)
886 return;
887
888 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
889 return;
890
891 if ((member = find_channel_link(target_p, chptr)) == NULL)
892 {
893 if (!(*errors & SM_ERR_NOTONCHANNEL))
894 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->chname);
895 *errors |= SM_ERR_NOTONCHANNEL;
896 return;
897 }
898
899 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
900 return;
901
902 /* no redundant mode changes */
903 if (dir == MODE_ADD && has_member_flags(member, CHFL_HALFOP))
904 return;
905 if (dir == MODE_DEL && !has_member_flags(member, CHFL_HALFOP))
906 return;
907
908 mode_changes[mode_count].letter = 'h';
909 mode_changes[mode_count].dir = dir;
910 mode_changes[mode_count].mems = ALL_MEMBERS;
911 mode_changes[mode_count].id = target_p->id;
912 mode_changes[mode_count].arg = target_p->name;
913 mode_changes[mode_count++].client = target_p;
914
915 if (dir == MODE_ADD)
916 AddMemberFlag(member, CHFL_HALFOP);
917 else
918 DelMemberFlag(member, CHFL_HALFOP);
919 }
920 #endif
921
922 static void
923 chm_op(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
924 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
925 {
926 struct Client *target_p;
927 struct Membership *member;
928
929 if (alev < CHACCESS_CHANOP)
930 {
931 if (!(*errors & SM_ERR_NOOPS))
932 sendto_one_numeric(source_p, &me,
933 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
934 ERR_CHANOPRIVSNEEDED, chptr->chname);
935 *errors |= SM_ERR_NOOPS;
936 return;
937 }
938
939 if (dir == MODE_QUERY || parc <= *parn)
940 return;
941
942 if ((target_p = find_chasing(source_p, parv[(*parn)++])) == NULL)
943 return;
944
945 if ((member = find_channel_link(target_p, chptr)) == NULL)
946 {
947 if (!(*errors & SM_ERR_NOTONCHANNEL))
948 sendto_one_numeric(source_p, &me, ERR_USERNOTINCHANNEL, target_p->name, chptr->chname);
949 *errors |= SM_ERR_NOTONCHANNEL;
950 return;
951 }
952
953 if (MyClient(source_p) && (++mode_limit > MAXMODEPARAMS))
954 return;
955
956 /* no redundant mode changes */
957 if (dir == MODE_ADD && has_member_flags(member, CHFL_CHANOP))
958 return;
959 if (dir == MODE_DEL && !has_member_flags(member, CHFL_CHANOP))
960 return;
961
962 mode_changes[mode_count].letter = 'o';
963 mode_changes[mode_count].dir = dir;
964 mode_changes[mode_count].mems = ALL_MEMBERS;
965 mode_changes[mode_count].id = target_p->id;
966 mode_changes[mode_count].arg = target_p->name;
967 mode_changes[mode_count++].client = target_p;
968
969 if (dir == MODE_ADD)
970 AddMemberFlag(member, CHFL_CHANOP);
971 else
972 DelMemberFlag(member, CHFL_CHANOP);
973 }
974
975 static void
976 chm_limit(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
977 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
978 {
979 int limit = 0;
980
981 if (alev < CHACCESS_HALFOP)
982 {
983 if (!(*errors & SM_ERR_NOOPS))
984 sendto_one_numeric(source_p, &me,
985 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
986 ERR_CHANOPRIVSNEEDED, chptr->chname);
987 *errors |= SM_ERR_NOOPS;
988 return;
989 }
990
991 if (dir == MODE_QUERY)
992 return;
993
994 if (dir == MODE_ADD && parc > *parn)
995 {
996 char *lstr = parv[(*parn)++];
997
998 if (EmptyString(lstr) || (limit = atoi(lstr)) <= 0)
999 return;
1000
1001 sprintf(lstr, "%d", limit);
1002
1003 /* If somebody sets MODE #channel +ll 1 2, accept latter --fl */
1004 for (unsigned int i = 0; i < mode_count; ++i)
1005 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1006 mode_changes[i].letter = 0;
1007
1008 mode_changes[mode_count].letter = c;
1009 mode_changes[mode_count].dir = MODE_ADD;
1010 mode_changes[mode_count].mems = ALL_MEMBERS;
1011 mode_changes[mode_count].id = NULL;
1012 mode_changes[mode_count++].arg = lstr;
1013
1014 chptr->mode.limit = limit;
1015 }
1016 else if (dir == MODE_DEL)
1017 {
1018 if (!chptr->mode.limit)
1019 return;
1020
1021 chptr->mode.limit = 0;
1022
1023 mode_changes[mode_count].letter = c;
1024 mode_changes[mode_count].dir = MODE_DEL;
1025 mode_changes[mode_count].mems = ALL_MEMBERS;
1026 mode_changes[mode_count].id = NULL;
1027 mode_changes[mode_count++].arg = NULL;
1028 }
1029 }
1030
1031 static void
1032 chm_key(struct Client *source_p, struct Channel *chptr, int parc, int *parn,
1033 char **parv, int *errors, int alev, int dir, char c, unsigned int d)
1034 {
1035 if (alev < CHACCESS_HALFOP)
1036 {
1037 if (!(*errors & SM_ERR_NOOPS))
1038 sendto_one_numeric(source_p, &me,
1039 alev == CHACCESS_NOTONCHAN ? ERR_NOTONCHANNEL :
1040 ERR_CHANOPRIVSNEEDED, chptr->chname);
1041 *errors |= SM_ERR_NOOPS;
1042 return;
1043 }
1044
1045 if (dir == MODE_QUERY)
1046 return;
1047
1048 if (dir == MODE_ADD && parc > *parn)
1049 {
1050 char *key = parv[(*parn)++];
1051
1052 if (MyClient(source_p))
1053 fix_key(key);
1054 else
1055 fix_key_old(key);
1056
1057 if (EmptyString(key))
1058 return;
1059
1060 assert(key[0] != ' ');
1061 strlcpy(chptr->mode.key, key, sizeof(chptr->mode.key));
1062
1063 /* If somebody does MODE #channel +kk a b, accept latter --fl */
1064 for (unsigned int i = 0; i < mode_count; ++i)
1065 if (mode_changes[i].letter == c && mode_changes[i].dir == MODE_ADD)
1066 mode_changes[i].letter = 0;
1067
1068 mode_changes[mode_count].letter = c;
1069 mode_changes[mode_count].dir = MODE_ADD;
1070 mode_changes[mode_count].mems = ALL_MEMBERS;
1071 mode_changes[mode_count].id = NULL;
1072 mode_changes[mode_count++].arg = chptr->mode.key;
1073 }
1074 else if (dir == MODE_DEL)
1075 {
1076 if (parc > *parn)
1077 (*parn)++;
1078
1079 if (chptr->mode.key[0] == '\0')
1080 return;
1081
1082 chptr->mode.key[0] = '\0';
1083
1084 mode_changes[mode_count].letter = c;
1085 mode_changes[mode_count].dir = MODE_DEL;
1086 mode_changes[mode_count].mems = ALL_MEMBERS;
1087 mode_changes[mode_count].id = NULL;
1088 mode_changes[mode_count++].arg = "*";
1089 }
1090 }
1091
1092 struct ChannelMode
1093 {
1094 void (*func)(struct Client *,
1095 struct Channel *, int, int *, char **,
1096 int *, int, int, char, unsigned int);
1097 unsigned int d;
1098 };
1099
1100 static struct ChannelMode ModeTable[256] =
1101 {
1102 { chm_nosuch, 0 }, /* 0x00 */
1103 { chm_nosuch, 0 }, /* 0x01 */
1104 { chm_nosuch, 0 }, /* 0x02 */
1105 { chm_nosuch, 0 }, /* 0x03 */
1106 { chm_nosuch, 0 }, /* 0x04 */
1107 { chm_nosuch, 0 }, /* 0x05 */
1108 { chm_nosuch, 0 }, /* 0x06 */
1109 { chm_nosuch, 0 }, /* 0x07 */
1110 { chm_nosuch, 0 }, /* 0x08 */
1111 { chm_nosuch, 0 }, /* 0x09 */
1112 { chm_nosuch, 0 }, /* 0x0a */
1113 { chm_nosuch, 0 }, /* 0x0b */
1114 { chm_nosuch, 0 }, /* 0x0c */
1115 { chm_nosuch, 0 }, /* 0x0d */
1116 { chm_nosuch, 0 }, /* 0x0e */
1117 { chm_nosuch, 0 }, /* 0x0f */
1118 { chm_nosuch, 0 }, /* 0x10 */
1119 { chm_nosuch, 0 }, /* 0x11 */
1120 { chm_nosuch, 0 }, /* 0x12 */
1121 { chm_nosuch, 0 }, /* 0x13 */
1122 { chm_nosuch, 0 }, /* 0x14 */
1123 { chm_nosuch, 0 }, /* 0x15 */
1124 { chm_nosuch, 0 }, /* 0x16 */
1125 { chm_nosuch, 0 }, /* 0x17 */
1126 { chm_nosuch, 0 }, /* 0x18 */
1127 { chm_nosuch, 0 }, /* 0x19 */
1128 { chm_nosuch, 0 }, /* 0x1a */
1129 { chm_nosuch, 0 }, /* 0x1b */
1130 { chm_nosuch, 0 }, /* 0x1c */
1131 { chm_nosuch, 0 }, /* 0x1d */
1132 { chm_nosuch, 0 }, /* 0x1e */
1133 { chm_nosuch, 0 }, /* 0x1f */
1134 { chm_nosuch, 0 }, /* 0x20 */
1135 { chm_nosuch, 0 }, /* 0x21 */
1136 { chm_nosuch, 0 }, /* 0x22 */
1137 { chm_nosuch, 0 }, /* 0x23 */
1138 { chm_nosuch, 0 }, /* 0x24 */
1139 { chm_nosuch, 0 }, /* 0x25 */
1140 { chm_nosuch, 0 }, /* 0x26 */
1141 { chm_nosuch, 0 }, /* 0x27 */
1142 { chm_nosuch, 0 }, /* 0x28 */
1143 { chm_nosuch, 0 }, /* 0x29 */
1144 { chm_nosuch, 0 }, /* 0x2a */
1145 { chm_nosuch, 0 }, /* 0x2b */
1146 { chm_nosuch, 0 }, /* 0x2c */
1147 { chm_nosuch, 0 }, /* 0x2d */
1148 { chm_nosuch, 0 }, /* 0x2e */
1149 { chm_nosuch, 0 }, /* 0x2f */
1150 { chm_nosuch, 0 }, /* 0x30 */
1151 { chm_nosuch, 0 }, /* 0x31 */
1152 { chm_nosuch, 0 }, /* 0x32 */
1153 { chm_nosuch, 0 }, /* 0x33 */
1154 { chm_nosuch, 0 }, /* 0x34 */
1155 { chm_nosuch, 0 }, /* 0x35 */
1156 { chm_nosuch, 0 }, /* 0x36 */
1157 { chm_nosuch, 0 }, /* 0x37 */
1158 { chm_nosuch, 0 }, /* 0x38 */
1159 { chm_nosuch, 0 }, /* 0x39 */
1160 { chm_nosuch, 0 }, /* 0x3a */
1161 { chm_nosuch, 0 }, /* 0x3b */
1162 { chm_nosuch, 0 }, /* 0x3c */
1163 { chm_nosuch, 0 }, /* 0x3d */
1164 { chm_nosuch, 0 }, /* 0x3e */
1165 { chm_nosuch, 0 }, /* 0x3f */
1166 { chm_nosuch, 0 }, /* @ */
1167 { chm_nosuch, 0 }, /* A */
1168 { chm_nosuch, 0 }, /* B */
1169 { chm_nosuch, 0 }, /* C */
1170 { chm_nosuch, 0 }, /* D */
1171 { chm_nosuch, 0 }, /* E */
1172 { chm_nosuch, 0 }, /* F */
1173 { chm_nosuch, 0 }, /* G */
1174 { chm_nosuch, 0 }, /* H */
1175 { chm_invex, 0 }, /* I */
1176 { chm_nosuch, 0 }, /* J */
1177 { chm_nosuch, 0 }, /* K */
1178 { chm_nosuch, 0 }, /* L */
1179 { chm_simple, MODE_MODREG}, /* M */
1180 { chm_nosuch, 0 }, /* N */
1181 { chm_operonly, MODE_OPERONLY}, /* O */
1182 { chm_nosuch, 0 }, /* P */
1183 { chm_nosuch, 0 }, /* Q */
1184 { chm_simple, MODE_REGONLY}, /* R */
1185 { chm_simple, MODE_SSLONLY}, /* S */
1186 { chm_nosuch, 0 }, /* T */
1187 { chm_nosuch, 0 }, /* U */
1188 { chm_nosuch, 0 }, /* V */
1189 { chm_nosuch, 0 }, /* W */
1190 { chm_nosuch, 0 }, /* X */
1191 { chm_nosuch, 0 }, /* Y */
1192 { chm_nosuch, 0 }, /* Z */
1193 { chm_nosuch, 0 },
1194 { chm_nosuch, 0 },
1195 { chm_nosuch, 0 },
1196 { chm_nosuch, 0 },
1197 { chm_nosuch, 0 },
1198 { chm_nosuch, 0 },
1199 { chm_nosuch, 0 }, /* a */
1200 { chm_ban, 0 }, /* b */
1201 { chm_simple, MODE_NOCTRL}, /* c */
1202 { chm_nosuch, 0 }, /* d */
1203 { chm_except, 0 }, /* e */
1204 { chm_nosuch, 0 }, /* f */
1205 { chm_nosuch, 0 }, /* g */
1206 #ifdef HALFOPS
1207 { chm_hop, 0 }, /* h */
1208 #else
1209 { chm_nosuch, 0 }, /* h */
1210 #endif
1211 { chm_simple, MODE_INVITEONLY }, /* i */
1212 { chm_nosuch, 0 }, /* j */
1213 { chm_key, 0 }, /* k */
1214 { chm_limit, 0 }, /* l */
1215 { chm_simple, MODE_MODERATED }, /* m */
1216 { chm_simple, MODE_NOPRIVMSGS }, /* n */
1217 { chm_op, 0 }, /* o */
1218 { chm_simple, MODE_PRIVATE }, /* p */
1219 { chm_nosuch, 0 }, /* q */
1220 { chm_registered, MODE_REGISTERED }, /* r */
1221 { chm_simple, MODE_SECRET }, /* s */
1222 { chm_simple, MODE_TOPICLIMIT }, /* t */
1223 { chm_nosuch, 0 }, /* u */
1224 { chm_voice, 0 }, /* v */
1225 { chm_nosuch, 0 }, /* w */
1226 { chm_nosuch, 0 }, /* x */
1227 { chm_nosuch, 0 }, /* y */
1228 { chm_nosuch, 0 }, /* z */
1229 { chm_nosuch, 0 }, /* 0x7b */
1230 { chm_nosuch, 0 }, /* 0x7c */
1231 { chm_nosuch, 0 }, /* 0x7d */
1232 { chm_nosuch, 0 }, /* 0x7e */
1233 { chm_nosuch, 0 }, /* 0x7f */
1234 { chm_nosuch, 0 }, /* 0x80 */
1235 { chm_nosuch, 0 }, /* 0x81 */
1236 { chm_nosuch, 0 }, /* 0x82 */
1237 { chm_nosuch, 0 }, /* 0x83 */
1238 { chm_nosuch, 0 }, /* 0x84 */
1239 { chm_nosuch, 0 }, /* 0x85 */
1240 { chm_nosuch, 0 }, /* 0x86 */
1241 { chm_nosuch, 0 }, /* 0x87 */
1242 { chm_nosuch, 0 }, /* 0x88 */
1243 { chm_nosuch, 0 }, /* 0x89 */
1244 { chm_nosuch, 0 }, /* 0x8a */
1245 { chm_nosuch, 0 }, /* 0x8b */
1246 { chm_nosuch, 0 }, /* 0x8c */
1247 { chm_nosuch, 0 }, /* 0x8d */
1248 { chm_nosuch, 0 }, /* 0x8e */
1249 { chm_nosuch, 0 }, /* 0x8f */
1250 { chm_nosuch, 0 }, /* 0x90 */
1251 { chm_nosuch, 0 }, /* 0x91 */
1252 { chm_nosuch, 0 }, /* 0x92 */
1253 { chm_nosuch, 0 }, /* 0x93 */
1254 { chm_nosuch, 0 }, /* 0x94 */
1255 { chm_nosuch, 0 }, /* 0x95 */
1256 { chm_nosuch, 0 }, /* 0x96 */
1257 { chm_nosuch, 0 }, /* 0x97 */
1258 { chm_nosuch, 0 }, /* 0x98 */
1259 { chm_nosuch, 0 }, /* 0x99 */
1260 { chm_nosuch, 0 }, /* 0x9a */
1261 { chm_nosuch, 0 }, /* 0x9b */
1262 { chm_nosuch, 0 }, /* 0x9c */
1263 { chm_nosuch, 0 }, /* 0x9d */
1264 { chm_nosuch, 0 }, /* 0x9e */
1265 { chm_nosuch, 0 }, /* 0x9f */
1266 { chm_nosuch, 0 }, /* 0xa0 */
1267 { chm_nosuch, 0 }, /* 0xa1 */
1268 { chm_nosuch, 0 }, /* 0xa2 */
1269 { chm_nosuch, 0 }, /* 0xa3 */
1270 { chm_nosuch, 0 }, /* 0xa4 */
1271 { chm_nosuch, 0 }, /* 0xa5 */
1272 { chm_nosuch, 0 }, /* 0xa6 */
1273 { chm_nosuch, 0 }, /* 0xa7 */
1274 { chm_nosuch, 0 }, /* 0xa8 */
1275 { chm_nosuch, 0 }, /* 0xa9 */
1276 { chm_nosuch, 0 }, /* 0xaa */
1277 { chm_nosuch, 0 }, /* 0xab */
1278 { chm_nosuch, 0 }, /* 0xac */
1279 { chm_nosuch, 0 }, /* 0xad */
1280 { chm_nosuch, 0 }, /* 0xae */
1281 { chm_nosuch, 0 }, /* 0xaf */
1282 { chm_nosuch, 0 }, /* 0xb0 */
1283 { chm_nosuch, 0 }, /* 0xb1 */
1284 { chm_nosuch, 0 }, /* 0xb2 */
1285 { chm_nosuch, 0 }, /* 0xb3 */
1286 { chm_nosuch, 0 }, /* 0xb4 */
1287 { chm_nosuch, 0 }, /* 0xb5 */
1288 { chm_nosuch, 0 }, /* 0xb6 */
1289 { chm_nosuch, 0 }, /* 0xb7 */
1290 { chm_nosuch, 0 }, /* 0xb8 */
1291 { chm_nosuch, 0 }, /* 0xb9 */
1292 { chm_nosuch, 0 }, /* 0xba */
1293 { chm_nosuch, 0 }, /* 0xbb */
1294 { chm_nosuch, 0 }, /* 0xbc */
1295 { chm_nosuch, 0 }, /* 0xbd */
1296 { chm_nosuch, 0 }, /* 0xbe */
1297 { chm_nosuch, 0 }, /* 0xbf */
1298 { chm_nosuch, 0 }, /* 0xc0 */
1299 { chm_nosuch, 0 }, /* 0xc1 */
1300 { chm_nosuch, 0 }, /* 0xc2 */
1301 { chm_nosuch, 0 }, /* 0xc3 */
1302 { chm_nosuch, 0 }, /* 0xc4 */
1303 { chm_nosuch, 0 }, /* 0xc5 */
1304 { chm_nosuch, 0 }, /* 0xc6 */
1305 { chm_nosuch, 0 }, /* 0xc7 */
1306 { chm_nosuch, 0 }, /* 0xc8 */
1307 { chm_nosuch, 0 }, /* 0xc9 */
1308 { chm_nosuch, 0 }, /* 0xca */
1309 { chm_nosuch, 0 }, /* 0xcb */
1310 { chm_nosuch, 0 }, /* 0xcc */
1311 { chm_nosuch, 0 }, /* 0xcd */
1312 { chm_nosuch, 0 }, /* 0xce */
1313 { chm_nosuch, 0 }, /* 0xcf */
1314 { chm_nosuch, 0 }, /* 0xd0 */
1315 { chm_nosuch, 0 }, /* 0xd1 */
1316 { chm_nosuch, 0 }, /* 0xd2 */
1317 { chm_nosuch, 0 }, /* 0xd3 */
1318 { chm_nosuch, 0 }, /* 0xd4 */
1319 { chm_nosuch, 0 }, /* 0xd5 */
1320 { chm_nosuch, 0 }, /* 0xd6 */
1321 { chm_nosuch, 0 }, /* 0xd7 */
1322 { chm_nosuch, 0 }, /* 0xd8 */
1323 { chm_nosuch, 0 }, /* 0xd9 */
1324 { chm_nosuch, 0 }, /* 0xda */
1325 { chm_nosuch, 0 }, /* 0xdb */
1326 { chm_nosuch, 0 }, /* 0xdc */
1327 { chm_nosuch, 0 }, /* 0xdd */
1328 { chm_nosuch, 0 }, /* 0xde */
1329 { chm_nosuch, 0 }, /* 0xdf */
1330 { chm_nosuch, 0 }, /* 0xe0 */
1331 { chm_nosuch, 0 }, /* 0xe1 */
1332 { chm_nosuch, 0 }, /* 0xe2 */
1333 { chm_nosuch, 0 }, /* 0xe3 */
1334 { chm_nosuch, 0 }, /* 0xe4 */
1335 { chm_nosuch, 0 }, /* 0xe5 */
1336 { chm_nosuch, 0 }, /* 0xe6 */
1337 { chm_nosuch, 0 }, /* 0xe7 */
1338 { chm_nosuch, 0 }, /* 0xe8 */
1339 { chm_nosuch, 0 }, /* 0xe9 */
1340 { chm_nosuch, 0 }, /* 0xea */
1341 { chm_nosuch, 0 }, /* 0xeb */
1342 { chm_nosuch, 0 }, /* 0xec */
1343 { chm_nosuch, 0 }, /* 0xed */
1344 { chm_nosuch, 0 }, /* 0xee */
1345 { chm_nosuch, 0 }, /* 0xef */
1346 { chm_nosuch, 0 }, /* 0xf0 */
1347 { chm_nosuch, 0 }, /* 0xf1 */
1348 { chm_nosuch, 0 }, /* 0xf2 */
1349 { chm_nosuch, 0 }, /* 0xf3 */
1350 { chm_nosuch, 0 }, /* 0xf4 */
1351 { chm_nosuch, 0 }, /* 0xf5 */
1352 { chm_nosuch, 0 }, /* 0xf6 */
1353 { chm_nosuch, 0 }, /* 0xf7 */
1354 { chm_nosuch, 0 }, /* 0xf8 */
1355 { chm_nosuch, 0 }, /* 0xf9 */
1356 { chm_nosuch, 0 }, /* 0xfa */
1357 { chm_nosuch, 0 }, /* 0xfb */
1358 { chm_nosuch, 0 }, /* 0xfc */
1359 { chm_nosuch, 0 }, /* 0xfd */
1360 { chm_nosuch, 0 }, /* 0xfe */
1361 { chm_nosuch, 0 }, /* 0xff */
1362 };
1363
1364 /* get_channel_access()
1365 *
1366 * inputs - pointer to Client struct
1367 * - pointer to Membership struct
1368 * output - CHACCESS_CHANOP if we should let them have
1369 * chanop level access, 0 for peon level access.
1370 * side effects - NONE
1371 */
1372 static int
1373 get_channel_access(const struct Client *source_p,
1374 const struct Membership *member)
1375 {
1376 /* Let hacked servers in for now... */
1377 if (!MyClient(source_p))
1378 return CHACCESS_CHANOP;
1379
1380 if (!member)
1381 return CHACCESS_NOTONCHAN;
1382
1383 /* Just to be sure.. */
1384 assert(source_p == member->client_p);
1385
1386 if (has_member_flags(member, CHFL_CHANOP))
1387 return CHACCESS_CHANOP;
1388
1389 #ifdef HALFOPS
1390 if (has_member_flags(member, CHFL_HALFOP))
1391 return CHACCESS_HALFOP;
1392 #endif
1393
1394 return CHACCESS_PEON;
1395 }
1396
1397 /* send_mode_changes_server()
1398 * Input: the source client(source_p),
1399 * the channel to send mode changes for(chptr)
1400 * Output: None.
1401 * Side-effects: Sends the appropriate mode changes to servers.
1402 *
1403 */
1404 static void
1405 send_mode_changes_server(struct Client *source_p, struct Channel *chptr)
1406 {
1407 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1408 int len = 0;
1409 int dir = MODE_QUERY;
1410 const char *arg = NULL;
1411 char *parptr = NULL;
1412
1413 parabuf[0] = '\0';
1414 parptr = parabuf;
1415
1416 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1417 (unsigned long)chptr->channelts, chptr->chname);
1418
1419 /* Loop the list of modes we have */
1420 for (unsigned i = 0; i < mode_count; ++i)
1421 {
1422 if (mode_changes[i].letter == 0)
1423 continue;
1424
1425 if (mode_changes[i].id)
1426 arg = mode_changes[i].id;
1427 else
1428 arg = mode_changes[i].arg;
1429
1430 if (arg)
1431 arglen = strlen(arg);
1432 else
1433 arglen = 0;
1434
1435 /*
1436 * If we're creeping past the buf size, we need to send it and make
1437 * another line for the other modes
1438 */
1439 if ((mc == MAXMODEPARAMS) ||
1440 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1441 (pbl + arglen + BAN_FUDGE) >= MODEBUFLEN)
1442 {
1443 if (nc)
1444 sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1445
1446 nc = 0;
1447 mc = 0;
1448
1449 mbl = snprintf(modebuf, sizeof(modebuf), ":%s TMODE %lu %s ", source_p->id,
1450 (unsigned long)chptr->channelts, chptr->chname);
1451
1452 pbl = 0;
1453 parabuf[0] = '\0';
1454 parptr = parabuf;
1455 dir = MODE_QUERY;
1456 }
1457
1458 if (dir != mode_changes[i].dir)
1459 {
1460 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1461 dir = mode_changes[i].dir;
1462 }
1463
1464 modebuf[mbl++] = mode_changes[i].letter;
1465 modebuf[mbl] = '\0';
1466 nc++;
1467
1468 if (arg)
1469 {
1470 len = sprintf(parptr, "%s ", arg);
1471 pbl += len;
1472 parptr += len;
1473 mc++;
1474 }
1475 }
1476
1477 if (pbl && parabuf[pbl - 1] == ' ')
1478 parabuf[pbl - 1] = '\0';
1479
1480 if (nc)
1481 sendto_server(source_p, NOCAPS, NOCAPS, "%s %s", modebuf, parabuf);
1482 }
1483
1484 /* void send_mode_changes(struct Client *client_p,
1485 * struct Client *source_p,
1486 * struct Channel *chptr)
1487 * Input: The client sending(client_p), the source client(source_p),
1488 * the channel to send mode changes for(chptr),
1489 * mode change globals.
1490 * Output: None.
1491 * Side-effects: Sends the appropriate mode changes to other clients
1492 * and propagates to servers.
1493 */
1494 /* ensure parabuf < MODEBUFLEN -db */
1495 static void
1496 send_mode_changes(struct Client *source_p, struct Channel *chptr)
1497 {
1498 int mbl = 0, pbl = 0, arglen = 0, nc = 0, mc = 0;
1499 int len = 0;
1500 int dir = MODE_QUERY;
1501 const char *arg = NULL;
1502 char *parptr = NULL;
1503
1504 /* Bail out if we have nothing to do... */
1505 if (!mode_count)
1506 return;
1507
1508 if (IsServer(source_p))
1509 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1510 ConfigServerHide.hide_servers) ?
1511 me.name : source_p->name, chptr->chname);
1512 else
1513 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1514 source_p->username, source_p->host, chptr->chname);
1515
1516 parabuf[0] = '\0';
1517 parptr = parabuf;
1518
1519 for (unsigned int i = 0; i < mode_count; ++i)
1520 {
1521 if (mode_changes[i].letter == 0 ||
1522 mode_changes[i].mems == ONLY_SERVERS)
1523 continue;
1524
1525 arg = mode_changes[i].arg;
1526 if (arg)
1527 arglen = strlen(arg);
1528 else
1529 arglen = 0;
1530
1531 if ((mc == MAXMODEPARAMS) ||
1532 ((arglen + mbl + pbl + 2) > IRCD_BUFSIZE) ||
1533 ((arglen + pbl + BAN_FUDGE) >= MODEBUFLEN))
1534 {
1535 if (mbl && modebuf[mbl - 1] == '-')
1536 modebuf[mbl - 1] = '\0';
1537
1538 if (nc)
1539 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1540
1541 nc = 0;
1542 mc = 0;
1543
1544 if (IsServer(source_p))
1545 mbl = snprintf(modebuf, sizeof(modebuf), ":%s MODE %s ", (IsHidden(source_p) ||
1546 ConfigServerHide.hide_servers) ?
1547 me.name : source_p->name, chptr->chname);
1548 else
1549 mbl = snprintf(modebuf, sizeof(modebuf), ":%s!%s@%s MODE %s ", source_p->name,
1550 source_p->username, source_p->host, chptr->chname);
1551
1552 pbl = 0;
1553 parabuf[0] = '\0';
1554 parptr = parabuf;
1555 dir = MODE_QUERY;
1556 }
1557
1558 if (dir != mode_changes[i].dir)
1559 {
1560 modebuf[mbl++] = (mode_changes[i].dir == MODE_ADD) ? '+' : '-';
1561 dir = mode_changes[i].dir;
1562 }
1563
1564 modebuf[mbl++] = mode_changes[i].letter;
1565 modebuf[mbl] = '\0';
1566 nc++;
1567
1568 if (arg)
1569 {
1570 len = sprintf(parptr, "%s ", arg);
1571 pbl += len;
1572 parptr += len;
1573 mc++;
1574 }
1575 }
1576
1577 if (pbl && parabuf[pbl - 1] == ' ')
1578 parabuf[pbl - 1] = '\0';
1579
1580 if (nc)
1581 sendto_channel_local(ALL_MEMBERS, 0, chptr, "%s %s", modebuf, parabuf);
1582
1583 send_mode_changes_server(source_p, chptr);
1584 }
1585
1586 /*
1587 * Input: The the client this originated
1588 * from, the channel, the parameter count starting at the modes,
1589 * the parameters, the channel name.
1590 * Output: None.
1591 * Side-effects: Changes the channel membership and modes appropriately,
1592 * sends the appropriate MODE messages to the appropriate
1593 * clients.
1594 */
1595 void
1596 set_channel_mode(struct Client *source_p, struct Channel *chptr,
1597 struct Membership *member, int parc, char *parv[])
1598 {
1599 int dir = MODE_ADD;
1600 int parn = 1;
1601 int alevel = 0, errors = 0;
1602
1603 mode_count = 0;
1604 mode_limit = 0;
1605 simple_modes_mask = 0;
1606
1607 alevel = get_channel_access(source_p, member);
1608
1609 for (const char *ml = parv[0]; *ml; ++ml)
1610 {
1611 switch (*ml)
1612 {
1613 case '+':
1614 dir = MODE_ADD;
1615 break;
1616 case '-':
1617 dir = MODE_DEL;
1618 break;
1619 case '=':
1620 dir = MODE_QUERY;
1621 break;
1622 default:
1623 {
1624 struct ChannelMode *tptr = &ModeTable[(unsigned char)*ml];
1625
1626 tptr->func(source_p, chptr, parc, &parn, parv,
1627 &errors, alevel, dir, *ml, tptr->d);
1628 break;
1629 }
1630 }
1631 }
1632
1633 send_mode_changes(source_p, chptr);
1634 }

Properties

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