Debian Codegraph @

modules/botserv/set_fantasy.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Copyright (c) 2007 Jilles Tjoelker
4 * Rights to this code are as documented in doc/LICENSE.
5 *
6 * Enable fantasy commands.
7 *
8 */
9
10 #include "atheme.h"
11 #include "uplink.h"
12
13 DECLARE_MODULE_V1
14 (
15 "botserv/set_fantasy", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 mowgli_patricia_t **bs_set_cmdtree;
21
22 static void bs_set_fantasy_config_ready(void *unused);
23
24 static void bs_cmd_set_fantasy(sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t bs_set_fantasy = { "FANTASY", N_("Enable fantasy commands."), AC_AUTHENTICATED, 2, bs_cmd_set_fantasy, { .path = "botserv/set_fantasy" } };
27
28 void _modinit(module_t *m)
29 {
30 MODULE_TRY_REQUEST_SYMBOL(m, bs_set_cmdtree, "botserv/set_core", "bs_set_cmdtree");
31
32 command_add(&bs_set_fantasy, *bs_set_cmdtree);
33
34 hook_add_event("config_ready");
35 hook_add_config_ready(bs_set_fantasy_config_ready);
36 }
37
38 void _moddeinit(module_unload_intent_t intent)
39 {
40 command_delete(&bs_set_fantasy, *bs_set_cmdtree);
41
42 hook_del_config_ready(bs_set_fantasy_config_ready);
43 }
44
45 static void bs_set_fantasy_config_ready(void *unused)
46 {
47 if (chansvs.fantasy)
48 bs_set_fantasy.access = NULL;
49 else
50 bs_set_fantasy.access = AC_DISABLED;
51 }
52
53 static void bs_cmd_set_fantasy(sourceinfo_t *si, int parc, char *parv[])
54 {
55 char *channel = parv[0];
56 char *option = parv[1];
57 mychan_t *mc;
58 metadata_t *md;
59
60 if (parc < 2 || !channel || !option)
61 {
62 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET FANTASY");
63 command_fail(si, fault_needmoreparams, _("Syntax: SET <#channel> FANTASY {ON|OFF}"));
64 return;
65 }
66
67 mc = mychan_find(channel);
68 if (!mc)
69 {
70 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), channel);
71 return;
72 }
73
74 if (!chanacs_source_has_flag(mc, si, CA_SET))
75 {
76 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
77 return;
78 }
79
80 if (!irccasecmp(option, "ON"))
81 {
82 if ((md = metadata_find(mc, "private:botserv:bot-assigned")) != NULL)
83 metadata_add(mc, "private:botserv:bot-handle-fantasy", md->value);
84
85 logcommand(si, CMDLOG_SET, "SET:FANTASY:ON: \2%s\2", mc->name);
86
87 command_success_nodata(si, _("Fantasy mode is now \2ON\2 on channel %s."), mc->name);
88 }
89 else if(!irccasecmp(option, "OFF"))
90 {
91 metadata_delete(mc, "private:botserv:bot-handle-fantasy");
92 logcommand(si, CMDLOG_SET, "SET:FANTASY:OFF: \2%s\2", mc->name);
93 command_success_nodata(si, _("Fantasy mode is now \2OFF\2 on channel %s."), mc->name);
94 }
95 else
96 {
97 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "SET FANTASY");
98 command_fail(si, fault_badparams, _("Syntax: SET <#channel> FANTASY {ON|OFF}"));
99 }
100 }
101
102 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
103 * vim:ts=8
104 * vim:sw=8
105 * vim:noexpandtab
106 */