1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2006-2009 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains routines to handle the CService SET LIMITFLAGS command.
7 *
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/set_limitflags", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void cs_cmd_set_limitflags(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_set_limitflags = { "LIMITFLAGS", N_("Limits the power of the +f flag."), AC_NONE, 2, cs_cmd_set_limitflags, { .path = "cservice/set_limitflags" } };
22
23 mowgli_patricia_t **cs_set_cmdtree;
24
_modinit(module_t * m)25 void _modinit(module_t *m)
26 {
27 MODULE_TRY_REQUEST_SYMBOL(m, cs_set_cmdtree, "chanserv/set_core", "cs_set_cmdtree");
28
29 command_add(&cs_set_limitflags, *cs_set_cmdtree);
30
31 use_limitflags++;
32 }
33
_moddeinit(module_unload_intent_t intent)34 void _moddeinit(module_unload_intent_t intent)
35 {
36 command_delete(&cs_set_limitflags, *cs_set_cmdtree);
37
38 use_limitflags--;
39 }
40
cs_cmd_set_limitflags(sourceinfo_t * si,int parc,char * parv[])41 static void cs_cmd_set_limitflags(sourceinfo_t *si, int parc, char *parv[])
42 {
43 mychan_t *mc;
44
45 if (!(mc = mychan_find(parv[0])))
46 {
47 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]);
48 return;
49 }
50
51 if (!parv[1])
52 {
53 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET LIMITFLAGS");
54 return;
55 }
56
57 if ((chanacs_source_flags(mc, si) & CA_HIGHPRIVS) != CA_HIGHPRIVS)
58 {
59 command_fail(si, fault_noprivs, _("You are not authorized to perform this command."));
60 return;
61 }
62
63 if (!strcasecmp("ON", parv[1]))
64 {
65 if (MC_LIMITFLAGS & mc->flags)
66 {
67 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for \2%s\2."), "LIMITFLAGS", mc->name);
68 return;
69 }
70
71 logcommand(si, CMDLOG_SET, "SET:LIMITFLAGS:ON: \2%s\2", mc->name);
72 verbose(mc, _("\2%s\2 enabled the LIMITFLAGS flag"), get_source_name(si));
73
74 mc->flags |= MC_LIMITFLAGS;
75
76 command_success_nodata(si, _("The \2%s\2 flag has been set for \2%s\2."), "LIMITFLAGS", mc->name);
77
78 return;
79 }
80
81 else if (!strcasecmp("OFF", parv[1]))
82 {
83 if (!(MC_LIMITFLAGS & mc->flags))
84 {
85 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for \2%s\2."), "LIMITFLAGS", mc->name);
86 return;
87 }
88
89 logcommand(si, CMDLOG_SET, "SET:LIMITFLAGS:OFF: \2%s\2", mc->name);
90 verbose(mc, _("\2%s\2 disabled the LIMITFLAGS flag"), get_source_name(si));
91
92 mc->flags &= ~MC_LIMITFLAGS;
93
94 command_success_nodata(si, _("The \2%s\2 flag has been removed for \2%s\2."), "LIMITFLAGS", mc->name);
95
96 return;
97 }
98
99 else
100 {
101 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "LIMITFLAGS");
102 return;
103 }
104 }
105
106 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
107 * vim:ts=8
108 * vim:sw=8
109 * vim:noexpandtab
110 */
111