… | |
… | |
3 | * Rights to this code are documented in doc/pod/license.pod. |
3 | * Rights to this code are documented in doc/pod/license.pod. |
4 | * |
4 | * |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
5 | * Copyright © 2005-2007 Atheme Project (http://www.atheme.org) |
6 | */ |
6 | */ |
7 | |
7 | |
8 | static char const rcsid[] = "$Id: cmode.C,v 1.5 2007/08/30 19:56:24 pippijn Exp $"; |
8 | static char const rcsid[] = "$Id: cmode.C,v 1.6 2007/09/05 11:23:15 pippijn Exp $"; |
9 | |
9 | |
10 | #include "atheme.h" |
10 | #include "atheme.h" |
11 | #include <account/chanacs.h> |
11 | #include <account/chanacs.h> |
12 | #include <account/mychan.h> |
12 | #include <account/mychan.h> |
13 | |
13 | |
… | |
… | |
46 | void |
46 | void |
47 | channel_mode (user_t *source, channel_t *chan, int parc, char const * const parv[]) |
47 | channel_mode (user_t *source, channel_t *chan, int parc, char const * const parv[]) |
48 | { |
48 | { |
49 | bool matched = false; |
49 | bool matched = false; |
50 | bool simple_modes_changed = false; |
50 | bool simple_modes_changed = false; |
51 | int i, parpos = 0, whatt = MTYPE_NUL; |
51 | int i, parpos = 0; |
|
|
52 | mtype whatt = MTYPE_NUL; |
52 | unsigned int newlimit; |
53 | unsigned int newlimit; |
53 | char const *pos = parv[0]; |
54 | char const *pos = parv[0]; |
54 | mychan_t *mc; |
55 | mychan_t *mc; |
55 | chanuser_t *cu = NULL; |
56 | chanuser_t *cu = NULL; |
56 | user_t *first_deopped_service = NULL; |
57 | user_t *first_deopped_service = NULL; |
… | |
… | |
454 | static void |
455 | static void |
455 | modestack_flush (struct modestackdata *md) |
456 | modestack_flush (struct modestackdata *md) |
456 | { |
457 | { |
457 | char buf[512]; |
458 | char buf[512]; |
458 | char *end, *p; |
459 | char *end, *p; |
459 | int dir = MTYPE_NUL; |
460 | mtype dir = MTYPE_NUL; |
460 | int i; |
461 | int i; |
461 | |
462 | |
462 | p = buf; |
463 | p = buf; |
463 | end = buf + sizeof buf; |
464 | end = buf + sizeof buf; |
464 | |
465 | |
… | |
… | |
559 | modestackdata.channel = channel; |
560 | modestackdata.channel = channel; |
560 | return &modestackdata; |
561 | return &modestackdata; |
561 | } |
562 | } |
562 | |
563 | |
563 | static void |
564 | static void |
564 | modestack_add_simple (struct modestackdata *md, int dir, int flags) |
565 | modestack_add_simple (struct modestackdata *md, mtype dir, int flags) |
565 | { |
566 | { |
566 | if (dir == MTYPE_ADD) |
567 | if (dir == MTYPE_ADD) |
567 | md->modes_on |= flags, md->modes_off &= ~flags; |
568 | md->modes_on |= flags, md->modes_off &= ~flags; |
568 | else if (dir == MTYPE_DEL) |
569 | else if (dir == MTYPE_DEL) |
569 | md->modes_off |= flags, md->modes_on &= ~flags; |
570 | md->modes_off |= flags, md->modes_on &= ~flags; |
570 | else |
571 | else |
571 | slog (LG_ERROR, "modestack_add_simple(): invalid direction"); |
572 | slog (LG_ERROR, "modestack_add_simple(): invalid direction"); |
572 | } |
573 | } |
573 | |
574 | |
574 | static void |
575 | static void |
575 | modestack_add_limit (struct modestackdata *md, int dir, unsigned int limit) |
576 | modestack_add_limit (struct modestackdata *md, mtype dir, unsigned int limit) |
576 | { |
577 | { |
577 | md->limitused = 0; |
578 | md->limitused = 0; |
578 | modestack_calclen (md); |
579 | modestack_calclen (md); |
579 | if (md->paramcount >= MAXMODES) |
580 | if (md->paramcount >= MAXMODES) |
580 | modestack_flush (md); |
581 | modestack_flush (md); |
… | |
… | |
590 | slog (LG_ERROR, "modestack_add_limit(): invalid direction"); |
591 | slog (LG_ERROR, "modestack_add_limit(): invalid direction"); |
591 | md->limitused = 1; |
592 | md->limitused = 1; |
592 | } |
593 | } |
593 | |
594 | |
594 | static void |
595 | static void |
595 | modestack_add_ext (struct modestackdata *md, int dir, int i, char const * const value) |
596 | modestack_add_ext (struct modestackdata *md, mtype dir, int i, char const * const value) |
596 | { |
597 | { |
597 | md->extmodesused[i] = 0; |
598 | md->extmodesused[i] = 0; |
598 | modestack_calclen (md); |
599 | modestack_calclen (md); |
599 | if (md->paramcount >= MAXMODES) |
600 | if (md->paramcount >= MAXMODES) |
600 | modestack_flush (md); |
601 | modestack_flush (md); |
… | |
… | |
610 | slog (LG_ERROR, "modestack_add_ext(): invalid direction"); |
611 | slog (LG_ERROR, "modestack_add_ext(): invalid direction"); |
611 | md->extmodesused[i] = 1; |
612 | md->extmodesused[i] = 1; |
612 | } |
613 | } |
613 | |
614 | |
614 | static void |
615 | static void |
615 | modestack_add_param (struct modestackdata *md, int dir, char type, char const * const value) |
616 | modestack_add_param (struct modestackdata *md, mtype dir, char type, char const * const value) |
616 | { |
617 | { |
617 | char *p; |
618 | char *p; |
618 | int n = 0, i; |
619 | int n = 0, i; |
619 | char dir2 = MTYPE_NUL; |
620 | char dir2 = MTYPE_NUL; |
620 | char str[3]; |
621 | char str[3]; |
… | |
… | |
702 | } |
703 | } |
703 | } |
704 | } |
704 | |
705 | |
705 | /* stack simple modes without parameters */ |
706 | /* stack simple modes without parameters */ |
706 | void |
707 | void |
707 | modestack_mode_simple (char *source, channel_t *channel, int dir, int flags) |
708 | modestack_mode_simple (char *source, channel_t *channel, mtype dir, int flags) |
708 | { |
709 | { |
709 | struct modestackdata *md; |
710 | struct modestackdata *md; |
710 | |
711 | |
711 | if (flags == 0) |
712 | if (flags == 0) |
712 | return; |
713 | return; |
… | |
… | |
716 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
717 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
717 | } |
718 | } |
718 | |
719 | |
719 | /* stack a limit */ |
720 | /* stack a limit */ |
720 | void |
721 | void |
721 | modestack_mode_limit (char *source, channel_t *channel, int dir, unsigned int limit) |
722 | modestack_mode_limit (char *source, channel_t *channel, mtype dir, unsigned int limit) |
722 | { |
723 | { |
723 | struct modestackdata *md; |
724 | struct modestackdata *md; |
724 | |
725 | |
725 | md = modestack_init (source, channel); |
726 | md = modestack_init (source, channel); |
726 | modestack_add_limit (md, dir, limit); |
727 | modestack_add_limit (md, dir, limit); |
… | |
… | |
728 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
729 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
729 | } |
730 | } |
730 | |
731 | |
731 | /* stack a non-standard type C mode */ |
732 | /* stack a non-standard type C mode */ |
732 | void |
733 | void |
733 | modestack_mode_ext (char *source, channel_t *channel, int dir, int i, char const * const value) |
734 | modestack_mode_ext (char *source, channel_t *channel, mtype dir, int i, char const * const value) |
734 | { |
735 | { |
735 | struct modestackdata *md; |
736 | struct modestackdata *md; |
736 | |
737 | |
737 | md = modestack_init (source, channel); |
738 | md = modestack_init (source, channel); |
738 | if (i < 0 || i >= MAXEXTMODES) |
739 | if (i < 0 || i >= MAXEXTMODES) |
… | |
… | |
745 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
746 | md->event = event_add_once ("flush_cmode_callback", modestack_flush_callback, md, 0); |
746 | } |
747 | } |
747 | |
748 | |
748 | /* stack a type A, B or E mode */ |
749 | /* stack a type A, B or E mode */ |
749 | void |
750 | void |
750 | modestack_mode_param (char *source, channel_t *channel, int dir, char type, char const * const value) |
751 | modestack_mode_param (char *source, channel_t *channel, mtype dir, char type, char const * const value) |
751 | { |
752 | { |
752 | struct modestackdata *md; |
753 | struct modestackdata *md; |
753 | |
754 | |
754 | md = modestack_init (source, channel); |
755 | md = modestack_init (source, channel); |
755 | modestack_add_param (md, dir, type, value); |
756 | modestack_add_param (md, dir, type, value); |
… | |
… | |
838 | void |
839 | void |
839 | check_modes (mychan_t *mychan, bool sendnow) |
840 | check_modes (mychan_t *mychan, bool sendnow) |
840 | { |
841 | { |
841 | int modes; |
842 | int modes; |
842 | int i; |
843 | int i; |
843 | metadata::item *md; |
844 | metadata *md; |
844 | char *p, *q; |
845 | char *p, *q; |
845 | char str2[512]; |
846 | char str2[512]; |
846 | |
847 | |
847 | if (!mychan || !mychan->chan) |
848 | if (!mychan || !mychan->chan) |
848 | return; |
849 | return; |