Debian Codegraph @

modules/chanserv/set_guard.c

raw
1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2006-2010 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains routines to handle the CService SET GUARD command.
7 *
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/set_guard", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void cs_set_guard_config_ready(void *unused);
20
21 static void cs_cmd_set_guard(sourceinfo_t *si, int parc, char *parv[]);
22
23 command_t cs_set_guard = { "GUARD", N_("Sets whether or not services will inhabit the channel."), AC_NONE, 2, cs_cmd_set_guard, { .path = "cservice/set_guard" } };
24
25 mowgli_patricia_t **cs_set_cmdtree;
26
27 void _modinit(module_t *m)
28 {
29 MODULE_TRY_REQUEST_SYMBOL(m, cs_set_cmdtree, "chanserv/set_core", "cs_set_cmdtree");
30
31 command_add(&cs_set_guard, *cs_set_cmdtree);
32
33 hook_add_event("config_ready");
34 hook_add_config_ready(cs_set_guard_config_ready);
35 }
36
37 void _moddeinit(module_unload_intent_t intent)
38 {
39 command_delete(&cs_set_guard, *cs_set_cmdtree);
40
41 hook_del_config_ready(cs_set_guard_config_ready);
42 }
43
44 static void cs_set_guard_config_ready(void *unused)
45 {
46 if (config_options.join_chans)
47 cs_set_guard.access = NULL;
48 else
49 cs_set_guard.access = PRIV_ADMIN;
50 }
51
52 static void cs_cmd_set_guard(sourceinfo_t *si, int parc, char *parv[])
53 {
54 mychan_t *mc;
55
56 if (!(mc = mychan_find(parv[0])))
57 {
58 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]);
59 return;
60 }
61
62 if (!parv[1])
63 {
64 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET GUARD");
65 return;
66 }
67
68 if (!chanacs_source_has_flag(mc, si, CA_SET))
69 {
70 command_fail(si, fault_noprivs, _("You are not authorized to perform this command."));
71 return;
72 }
73
74 if (!strcasecmp("ON", parv[1]))
75 {
76 if (MC_GUARD & mc->flags)
77 {
78 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for channel \2%s\2."), "GUARD", mc->name);
79 return;
80 }
81 if (metadata_find(mc, "private:botserv:bot-assigned") &&
82 module_find_published("botserv/main"))
83 {
84 command_fail(si, fault_noprivs, _("Channel \2%s\2 already has a BotServ bot assigned to it. You need to unassign it first."), mc->name);
85 return;
86 }
87
88 logcommand(si, CMDLOG_SET, "SET:GUARD:ON: \2%s\2", mc->name);
89 verbose(mc, _("\2%s\2 enabled the GUARD flag"), get_source_name(si));
90
91 mc->flags |= MC_GUARD;
92
93 if (!(mc->flags & MC_INHABIT))
94 join(mc->name, chansvs.nick);
95
96 command_success_nodata(si, _("The \2%s\2 flag has been set for channel \2%s\2."), "GUARD", mc->name);
97 return;
98 }
99 else if (!strcasecmp("OFF", parv[1]))
100 {
101 if (!(MC_GUARD & mc->flags))
102 {
103 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for channel \2%s\2."), "GUARD", mc->name);
104 return;
105 }
106
107 logcommand(si, CMDLOG_SET, "SET:GUARD:OFF: \2%s\2", mc->name);
108 verbose(mc, _("\2%s\2 disabled the GUARD flag"), get_source_name(si));
109
110 mc->flags &= ~MC_GUARD;
111
112 if (mc->chan != NULL && !(mc->flags & MC_INHABIT) && !(mc->chan->flags & CHAN_LOG))
113 part(mc->name, chansvs.nick);
114
115 command_success_nodata(si, _("The \2%s\2 flag has been removed for channel \2%s\2."), "GUARD", mc->name);
116 return;
117 }
118 else
119 {
120 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "GUARD");
121 return;
122 }
123 }
124
125 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
126 * vim:ts=8
127 * vim:sw=8
128 * vim:noexpandtab
129 */