Debian Codegraph @

modules/chanserv/set_private.c

raw
1 /*
2 * Copyright (c) 2003-2004 E. Will et al.
3 * Copyright (c) 2006-2007 Atheme Development Group
4 * Rights to this code are documented in doc/LICENSE.
5 *
6 * This file contains routines to handle the CService SET PRIVATE command.
7 *
8 */
9
10 #include "atheme.h"
11
12 DECLARE_MODULE_V1
13 (
14 "chanserv/set_private", false, _modinit, _moddeinit,
15 PACKAGE_STRING,
16 VENDOR_STRING
17 );
18
19 static void cs_cmd_set_private(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_set_private = { "PRIVATE", N_("Hides information about a channel."), AC_NONE, 2, cs_cmd_set_private, { .path = "cservice/set_private" } };
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_private, *cs_set_cmdtree);
30
31 use_channel_private++;
32 }
33
34 void _moddeinit(module_unload_intent_t intent)
35 {
36 command_delete(&cs_set_private, *cs_set_cmdtree);
37
38 use_channel_private--;
39 }
40
41 static void cs_cmd_set_private(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 PRIVATE");
54 return;
55 }
56
57 if (!chanacs_source_has_flag(mc, si, CA_SET))
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_PRIVATE & mc->flags)
66 {
67 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for \2%s\2."), "PRIVATE", mc->name);
68 return;
69 }
70
71 logcommand(si, CMDLOG_SET, "SET:PRIVATE:ON: \2%s\2", mc->name);
72 verbose(mc, _("\2%s\2 enabled the PRIVATE flag"), get_source_name(si));
73
74 mc->flags |= MC_PRIVATE;
75
76 command_success_nodata(si, _("The \2%s\2 flag has been set for \2%s\2."), "PRIVATE", mc->name);
77
78 return;
79 }
80
81 else if (!strcasecmp("OFF", parv[1]))
82 {
83 if (!(MC_PRIVATE & mc->flags))
84 {
85 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for \2%s\2."), "PRIVATE", mc->name);
86 return;
87 }
88
89 logcommand(si, CMDLOG_SET, "SET:PRIVATE:OFF: \2%s\2", mc->name);
90 verbose(mc, _("\2%s\2 disabled the PRIVATE flag"), get_source_name(si));
91
92 mc->flags &= ~MC_PRIVATE;
93
94 command_success_nodata(si, _("The \2%s\2 flag has been removed for \2%s\2."), "PRIVATE", mc->name);
95
96 return;
97 }
98
99 else
100 {
101 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "PRIVATE");
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 */