ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/chanserv/fflags.C
Revision: 1.10
Committed: Sat Sep 22 14:27:27 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * fflags.C: This file contains code for the ChanServ FFLAGS functions.
3 *
4 * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team
5 * Rights to this code are as documented in COPYING.
6 *
7 *
8 * Portions of this file were derived from sources bearing the following license:
9 * Copyright © 2005-2006 William Pitcock, et al.
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: fflags.C,v 1.9 2007-09-16 18:54:42 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include <ermyth/module.h>
17 #include <account/mychan.h>
18 #include <account/myuser.h>
19 #include <account/chanacs.h>
20 #include "template.h"
21
22 static char const rcsid[] = "$Id: fflags.C,v 1.9 2007-09-16 18:54:42 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/fflags", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 static void cs_cmd_fflags (sourceinfo_t *si, int parc, char *parv[]);
27
28 command_t const cs_fflags = { "FFLAGS", N_("Forces a flags change on a channel."), PRIV_CHAN_ADMIN, 3, cs_cmd_fflags };
29
30 E cmdvec cs_cmdtree;
31 E helpvec cs_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 cs_cmdtree << cs_fflags;
37 help_addentry (cs_helptree, "FFLAGS", "help/chanserv/fflags", NULL);
38
39 return true;
40 }
41
42 void
43 _moddeinit ()
44 {
45 cs_cmdtree >> cs_fflags;
46 help_delentry (cs_helptree, "FFLAGS");
47 }
48
49 /* FFLAGS <channel> <user> <flags> */
50 static void
51 cs_cmd_fflags (sourceinfo_t *si, int parc, char *parv[])
52 {
53 chanacs_t *ca;
54 char *channel = parv[0];
55 char *target = parv[1];
56 char *flagstr = parv[2];
57 mychan_t *mc = mychan_t::find (channel);
58 myuser_t *tmu;
59 unsigned int addflags, removeflags;
60
61 if (parc < 3)
62 {
63 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "FFLAGS");
64 command_fail (si, fault::needmoreparams, _("Syntax: FFLAGS <channel> <target> <flags>"));
65 return;
66 }
67
68
69 if (!mc)
70 {
71 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), channel);
72 return;
73 }
74
75 if (*flagstr == '+' || *flagstr == '-' || *flagstr == '=')
76 {
77 flags_make_bitmasks (flagstr, chanacs_flags, &addflags, &removeflags);
78 if (addflags == 0 && removeflags == 0)
79 {
80 command_fail (si, fault::badparams, _("No valid flags given, use /%s%s HELP FLAGS for a list"), ircd->uses_rcommand ? "" : "msg ", chansvs.disp);
81 return;
82 }
83 }
84 else
85 {
86 addflags = get_template_flags (mc, flagstr);
87 if (addflags == 0)
88 {
89 /* Hack -- jilles */
90 if (*target == '+' || *target == '-' || *target == '=')
91 command_fail (si, fault::badparams, _("Usage: FFLAGS %s <target> <flags>"), mc->name);
92 else
93 command_fail (si, fault::badparams, _("Invalid template name given, use /%s%s TEMPLATE %s for a list"), ircd->uses_rcommand ? "" : "msg ", chansvs.disp, mc->name);
94 return;
95 }
96 removeflags = ca_all & ~addflags;
97 }
98
99 if (!validhostmask (target))
100 {
101 if (!(tmu = myuser_t::find_ext (target)))
102 {
103 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
104 return;
105 }
106 target = tmu->name;
107
108 /* XXX this should be more like flags.c */
109 if (removeflags & CA_FLAGS)
110 removeflags |= CA_FOUNDER, addflags &= ~CA_FOUNDER;
111 else if (addflags & CA_FOUNDER)
112 addflags |= CA_FLAGS, removeflags &= ~CA_FLAGS;
113 if (tmu->is_founder (mc) && removeflags & CA_FOUNDER && mc->num_founders () == 1)
114 {
115 command_fail (si, fault::noprivs, _("You may not remove the last founder."));
116 return;
117 }
118
119 /* If NEVEROP is set, don't allow adding new entries
120 * except sole +b. Adding flags if the current level
121 * is +b counts as adding an entry.
122 * -- jilles */
123 if (tmu->flags & MU_NEVEROP && addflags != CA_AKICK && addflags != 0 && ((ca = chanacs_find (mc, tmu, 0)) == NULL || ca->level == CA_AKICK))
124 {
125 command_fail (si, fault::noprivs, _("\2%s\2 does not wish to be added to access lists (NEVEROP set)."), tmu->name);
126 return;
127 }
128
129 if (!chanacs_change (mc, tmu, NULL, &addflags, &removeflags, ca_all))
130 {
131 /* this shouldn't happen */
132 command_fail (si, fault::noprivs, _("You are not allowed to set \2%s\2 on \2%s\2 in \2%s\2."), bitmask_to_flags2 (addflags, removeflags, chanacs_flags), tmu->name, mc->name);
133 return;
134 }
135 }
136 else
137 {
138 if (addflags & CA_FOUNDER)
139 {
140 command_fail (si, fault::badparams, _("You may not set founder status on a hostmask."));
141 return;
142 }
143 if (!chanacs_change (mc, NULL, target, &addflags, &removeflags, ca_all))
144 {
145 /* this shouldn't happen */
146 command_fail (si, fault::noprivs, _("You are not allowed to set \2%s\2 on \2%s\2 in \2%s\2."), bitmask_to_flags2 (addflags, removeflags, chanacs_flags), target, mc->name);
147 return;
148 }
149 }
150
151 if ((addflags | removeflags) == 0)
152 {
153 command_fail (si, fault::nochange, _("Channel access to \2%s\2 for \2%s\2 unchanged."), channel, target);
154 return;
155 }
156 flagstr = bitmask_to_flags2 (addflags, removeflags, chanacs_flags);
157 wallops ("\2%s\2 is forcing flags change \2%s\2 on \2%s\2 in \2%s\2.", get_oper_name (si), flagstr, target, mc->name);
158 snoop ("FFLAGS: \2%s\2 \2%s\2 \2%s\2 by \2%s\2", channel, target, flagstr, get_oper_name (si));
159 command_success_nodata (si, _("Flags \2%s\2 were set on \2%s\2 in \2%s\2."), flagstr, target, channel);
160 logcommand (si, CMDLOG_ADMIN, "%s FFLAGS %s %s", mc->name, target, flagstr);
161 verbose (mc, "\2%s\2 forced flags change \2%s\2 on \2%s\2.", get_source_name (si), flagstr, target);
162 }