Debian Codegraph @

modules/contrib/src/ns_fenforce.c

raw
1 /*
2 * Copyright (c) 2005-2007 William Pitcock, et al.
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * This file contains code for the NickServ FENFORCE function.
6 */
7
8 #include "atheme-compat.h"
9
10 static void
11 ns_cmd_fenforce(sourceinfo_t *si, int parc, char *parv[])
12 {
13 char *setting;
14 myuser_t *mu;
15
16 if (parc < 2)
17 {
18 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "FENFORCE");
19 command_fail(si, fault_needmoreparams, _("Syntax: FENFORCE <account> ON|OFF"));
20 return;
21 }
22
23 mu = myuser_find_ext(parv[0]);
24 if (!mu)
25 {
26 command_fail(si, fault_nosuch_target, STR_IS_NOT_REGISTERED, parv[0]);
27 return;
28 }
29 setting = parv[1];
30
31 if (strcasecmp(setting, "ON") == 0)
32 {
33 if (metadata_find(mu, "private:doenforce"))
34 {
35 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for account \2%s\2."), "ENFORCE", entity(mu)->name);
36 }
37 else
38 {
39 wallops("%s enabled ENFORCE on the account \2%s\2.", get_oper_name(si), entity(mu)->name);
40 logcommand(si, CMDLOG_ADMIN, "FENFORCE:ON: \2%s\2", entity(mu)->name);
41 metadata_add(mu, "private:doenforce", "1");
42 command_success_nodata(si, _("The \2%s\2 flag has been set for account \2%s\2."), "ENFORCE", entity(mu)->name);
43 }
44 }
45 else if (strcasecmp(setting, "OFF") == 0)
46 {
47 if (metadata_find(mu, "private:doenforce"))
48 {
49 wallops("%s disabled ENFORCE on the account \2%s\2.", get_oper_name(si), entity(mu)->name);
50 logcommand(si, CMDLOG_ADMIN, "FENFORCE:OFF: \2%s\2", entity(mu)->name);
51 metadata_delete(mu, "private:doenforce");
52 command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "ENFORCE", entity(mu)->name);
53 }
54 else
55 {
56 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for account \2%s\2."), "ENFORCE", entity(mu)->name);
57 }
58 }
59 else
60 {
61 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "FENFORCE");
62 }
63 }
64
65 static command_t ns_fenforce = {
66 .name = "FENFORCE",
67 .desc = N_("Enables or disables protection of another user's nicknames."),
68 .access = PRIV_USER_ADMIN,
69 .maxparc = 2,
70 .cmd = &ns_cmd_fenforce,
71 .help = { .path = "contrib/fenforce" },
72 };
73
74 static void
75 mod_init(module_t *const restrict m)
76 {
77 MODULE_TRY_REQUEST_DEPENDENCY(m, "nickserv/enforce");
78
79 service_named_bind_command("nickserv", &ns_fenforce);
80 }
81
82 static void
83 mod_deinit(const module_unload_intent_t intent)
84 {
85 service_named_unbind_command("nickserv", &ns_fenforce);
86 }
87
88 SIMPLE_DECLARE_MODULE_V1("contrib/ns_fenforce", MODULE_UNLOAD_CAPABILITY_OK)