ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/src/channel_mode.c
Revision: 3724
Committed: Sat May 31 16:27:09 2014 UTC (11 years, 2 months ago) by michael
Content type: text/x-csrc
File size: 44342 byte(s)
Log Message:
- Halfops are now part of the ircd core and enabled by default

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

Properties

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