Debian Codegraph @

modules/nickserv/hold.c

raw
1 /*
2 * Copyright (c) 2005 Atheme Development Group
3 * Rights to this code are as documented in doc/LICENSE.
4 *
5 * Controls noexpire options for nicknames.
6 *
7 */
8
9 #include "atheme.h"
10 #include "list_common.h"
11 #include "list.h"
12
13 DECLARE_MODULE_V1
14 (
15 "nickserv/hold", false, _modinit, _moddeinit,
16 PACKAGE_STRING,
17 VENDOR_STRING
18 );
19
20 static void ns_cmd_hold(sourceinfo_t *si, int parc, char *parv[]);
21
22 command_t ns_hold = { "HOLD", N_("Prevents an account from expiring."),
23 PRIV_HOLD, 2, ns_cmd_hold, { .path = "nickserv/hold" } };
24
25 static bool is_held(const mynick_t *mn, const void *arg) {
26 myuser_t *mu = mn->owner;
27
28 return ( mu->flags & MU_HOLD ) == MU_HOLD;
29 }
30
31 void _modinit(module_t *m)
32 {
33 service_named_bind_command("nickserv", &ns_hold);
34
35 use_nslist_main_symbols(m);
36
37 static list_param_t hold;
38 hold.opttype = OPT_BOOL;
39 hold.is_match = is_held;
40
41 list_register("hold", &hold);
42 list_register("held", &hold);
43 list_register("noexpire", &hold);
44 }
45
46 void _moddeinit(module_unload_intent_t intent)
47 {
48 service_named_unbind_command("nickserv", &ns_hold);
49
50 list_unregister("hold");
51 list_unregister("held");
52 list_unregister("noexpire");
53 }
54
55 static void ns_cmd_hold(sourceinfo_t *si, int parc, char *parv[])
56 {
57 char *target = parv[0];
58 char *action = parv[1];
59 myuser_t *mu;
60
61 if (!target || !action)
62 {
63 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "HOLD");
64 command_fail(si, fault_needmoreparams, _("Usage: HOLD <account> <ON|OFF>"));
65 return;
66 }
67
68 if (!(mu = myuser_find_ext(target)))
69 {
70 command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), target);
71 return;
72 }
73
74 if (!strcasecmp(action, "ON"))
75 {
76 if (mu->flags & MU_HOLD)
77 {
78 command_fail(si, fault_badparams, _("\2%s\2 is already held."), entity(mu)->name);
79 return;
80 }
81
82 mu->flags |= MU_HOLD;
83
84 wallops("%s set the HOLD option for the account \2%s\2.", get_oper_name(si), entity(mu)->name);
85 logcommand(si, CMDLOG_ADMIN, "HOLD:ON: \2%s\2", entity(mu)->name);
86 command_success_nodata(si, _("\2%s\2 is now held."), entity(mu)->name);
87 }
88 else if (!strcasecmp(action, "OFF"))
89 {
90 if (!(mu->flags & MU_HOLD))
91 {
92 command_fail(si, fault_badparams, _("\2%s\2 is not held."), entity(mu)->name);
93 return;
94 }
95
96 mu->flags &= ~MU_HOLD;
97
98 wallops("%s removed the HOLD option on the account \2%s\2.", get_oper_name(si), entity(mu)->name);
99 logcommand(si, CMDLOG_ADMIN, "HOLD:OFF: \2%s\2", entity(mu)->name);
100 command_success_nodata(si, _("\2%s\2 is no longer held."), entity(mu)->name);
101 }
102 else
103 {
104 command_fail(si, fault_needmoreparams, STR_INVALID_PARAMS, "HOLD");
105 command_fail(si, fault_needmoreparams, _("Usage: HOLD <account> <ON|OFF>"));
106 }
107 }
108
109 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
110 * vim:ts=8
111 * vim:sw=8
112 * vim:noexpandtab
113 */