Debian Codegraph @

modules/chanserv/getkey.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the CService GETKEY functions.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/getkey", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_cmd_getkey(sourceinfo_t *si, int parc, char *parv[]);
19
20 command_t cs_getkey = { "GETKEY", N_("Returns the key (+k) of a channel."),
21 AC_NONE, 1, cs_cmd_getkey, { .path = "cservice/getkey" } };
22
23 void _modinit(module_t *m)
24 {
25 service_named_bind_command("chanserv", &cs_getkey);
26 }
27
28 void _moddeinit(module_unload_intent_t intent)
29 {
30 service_named_unbind_command("chanserv", &cs_getkey);
31 }
32
33 static void cs_cmd_getkey(sourceinfo_t *si, int parc, char *parv[])
34 {
35 char *chan = parv[0];
36 mychan_t *mc;
37
38 if (!chan)
39 {
40 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "GETKEY");
41 command_fail(si, fault_needmoreparams, _("Syntax: GETKEY <#channel>"));
42 return;
43 }
44
45 mc = mychan_find(chan);
46 if (!mc)
47 {
48 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), chan);
49 return;
50 }
51
52 if (metadata_find(mc, "private:close:closer"))
53 {
54 command_fail(si, fault_noprivs, _("\2%s\2 is closed."), chan);
55 return;
56 }
57
58 if (!chanacs_source_has_flag(mc, si, CA_INVITE))
59 {
60 command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
61 return;
62 }
63
64 if (!mc->chan)
65 {
66 command_fail(si, fault_nosuch_target, _("\2%s\2 is currently empty."), mc->name);
67 return;
68 }
69
70 if (!mc->chan->key)
71 {
72 command_fail(si, fault_nosuch_key, _("\2%s\2 is not keyed."), mc->name);
73 return;
74 }
75 logcommand(si, CMDLOG_GET, "GETKEY: \2%s\2", mc->name);
76 command_success_string(si, mc->chan->key, _("Channel \2%s\2 key is: %s"),
77 mc->name, mc->chan->key);
78 }
79
80 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
81 * vim:ts=8
82 * vim:sw=8
83 * vim:noexpandtab
84 */