Debian Codegraph @

modules/chanserv/set_gameserv.c

raw
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 GAMESERV command.
7 *
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/set_gameserv", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void cs_cmd_set_gameserv(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_set_gameserv = { "GAMESERV", N_("Allows or disallows gaming services."), AC_NONE, 2, cs_cmd_set_gameserv, { .path = "cservice/set_gameserv" } };
22
23 mowgli_patricia_t **cs_set_cmdtree;
24
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_gameserv, *cs_set_cmdtree);
30 }
31
32 void _moddeinit(module_unload_intent_t intent)
33 {
34 command_delete(&cs_set_gameserv, *cs_set_cmdtree);
35 }
36
37 static void cs_cmd_set_gameserv(sourceinfo_t *si, int parc, char *parv[])
38 {
39 mychan_t *mc;
40 const char *val;
41 metadata_t *md;
42
43 if (!(mc = mychan_find(parv[0])))
44 {
45 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]);
46 return;
47 }
48
49 if (!parv[1])
50 {
51 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "SET GAMESERV");
52 return;
53 }
54
55 if (!chanacs_source_has_flag(mc, si, CA_SET))
56 {
57 command_fail(si, fault_noprivs, _("You are not authorized to perform this command."));
58 return;
59 }
60
61 if (!strcasecmp("ALL", parv[1]))
62 val = "ALL";
63 else if (!strcasecmp("VOICE", parv[1]) || !strcasecmp("VOICES", parv[1]))
64 val = "VOICE";
65 else if (!strcasecmp("OP", parv[1]) || !strcasecmp("OPS", parv[1]))
66 val = "OP";
67 else if (!strcasecmp("OFF", parv[1]))
68 val = NULL;
69 else
70 {
71 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "GAMESERV");
72 return;
73 }
74
75 md = metadata_find(mc, "gameserv");
76
77 if (val != NULL)
78 {
79 if (md != NULL && !strcasecmp(md->value, val))
80 {
81 command_fail(si, fault_nochange, _("\2%s\2 is already set to %s for \2%s\2."), "GAMESERV", val, mc->name);
82 return;
83 }
84 logcommand(si, CMDLOG_SET, "SET:GAMESERV: \2%s\2 to \2%s\2", mc->name, val);
85 verbose(mc, _("\2%s\2 set the GAMESERV flag to \2%s\2"), get_source_name(si), val);
86
87 metadata_add(mc, "gameserv", val);
88
89 command_success_nodata(si, _("\2%s\2 has been set to \2%s\2 for \2%s\2."), "GAMESERV", val, mc->name);
90
91 return;
92 }
93 else
94 {
95 if (md == NULL)
96 {
97 command_fail(si, fault_nochange, _("\2%s\2 was not set for \2%s\2."), "GAMESERV", mc->name);
98 return;
99 }
100
101 logcommand(si, CMDLOG_SET, "SET:GAMESERV:OFF: \2%s\2", mc->name);
102 verbose(mc, _("\2%s\2 disabled the GAMESERV flag"), get_source_name(si));
103
104 metadata_delete(mc, "gameserv");
105
106 command_success_nodata(si, _("\2%s\2 has been disabled for \2%s\2."), "GAMESERV", mc->name);
107 }
108 }
109
110 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
111 * vim:ts=8
112 * vim:sw=8
113 * vim:noexpandtab
114 */