Debian Codegraph @

modules/nickserv/regnolimit.c

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