Debian Codegraph @

modules/chanserv/set_prefix.c

raw
1 /*
2 * Copyright (c) 2006-2010 Atheme Development Group
3 * Rights to this code are documented in doc/LICENSE.
4 *
5 * This file contains routines to handle the CService SET PREFIX command.
6 *
7 */
8
9 #include "atheme.h"
10
11 DECLARE_MODULE_V1
12 (
13 "chanserv/set_prefix", false, _modinit, _moddeinit,
14 PACKAGE_STRING,
15 VENDOR_STRING
16 );
17
18 static void cs_set_prefix_config_ready(void *unused);
19 static void cs_cmd_set_prefix(sourceinfo_t *si, int parc, char *parv[]);
20
21 command_t cs_set_prefix = { "PREFIX", N_("Sets the channel PREFIX."), AC_NONE, 2, cs_cmd_set_prefix, { .path = "cservice/set_prefix" } };
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_prefix, *cs_set_cmdtree);
30
31 hook_add_event("config_ready");
32 hook_add_config_ready(cs_set_prefix_config_ready);
33 }
34
35 void _moddeinit(module_unload_intent_t intent)
36 {
37 command_delete(&cs_set_prefix, *cs_set_cmdtree);
38
39 hook_del_config_ready(cs_set_prefix_config_ready);
40 }
41
42 static void cs_set_prefix_config_ready(void *unused)
43 {
44 if (chansvs.fantasy)
45 cs_set_prefix.access = NULL;
46 else
47 cs_set_prefix.access = AC_DISABLED;
48 }
49
50 static int goodprefix(const char *p)
51 {
52 int i;
53 int haschar = 0;
54 int hasnonprint = 0;
55
56 for (i = 0; p[i]; i++) {
57 if (!isspace((unsigned char)p[i])) { haschar = 1; }
58 if (!isprint((unsigned char)p[i])) { hasnonprint = 1; }
59 }
60
61 return haschar && !hasnonprint;
62 }
63
64
65 static void cs_cmd_set_prefix(sourceinfo_t *si, int parc, char *parv[])
66 {
67 mychan_t *mc;
68 char *prefix = parv[1];
69
70 if (!(mc = mychan_find(parv[0])))
71 {
72 command_fail(si, fault_nosuch_target, _("Channel \2%s\2 is not registered."), parv[0]);
73 return;
74 }
75
76 if (!chanacs_source_has_flag(mc, si, CA_SET))
77 {
78 command_fail(si, fault_noprivs, _("You are not authorized to execute this command."));
79 return;
80 }
81
82 if (!prefix || !strcasecmp(prefix, "DEFAULT"))
83 {
84 metadata_delete(mc, "private:prefix");
85 logcommand(si, CMDLOG_SET, "SET:PREFIX: \2%s\2 reset", mc->name);
86 verbose(mc, _("The fantasy prefix for the channel has been reset by \2%s\2"), get_source_name(si));
87 command_success_nodata(si, _("The fantasy prefix for channel \2%s\2 has been reset."), parv[0]);
88 return;
89 }
90
91 if (!goodprefix(prefix))
92 {
93 command_fail(si, fault_badparams, _("Prefix '%s' is invalid. The prefix may "
94 "contain only printable characters, and must contain at least "
95 "one non-space character."), prefix);
96 return;
97 }
98
99 metadata_add(mc, "private:prefix", prefix);
100 logcommand(si, CMDLOG_SET, "SET:PREFIX: \2%s\2 \2%s\2", mc->name, prefix);
101 verbose(mc, _("\2%s\2 set the fantasy prefix to \2%s\2"), get_source_name(si), prefix);
102 command_success_nodata(si, _("The fantasy prefix for channel \2%s\2 has been set to \2%s\2."),
103 parv[0], prefix);
104
105 }
106
107 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
108 * vim:ts=8
109 * vim:sw=8
110 * vim:noexpandtab
111 */