Debian Codegraph @

modules/nickserv/set_nogreet.c

raw
1 /*
2 * Copyright (c) 2005 William Pitcock <nenolod -at- nenolod.net>
3 * Copyright (c) 2007 Jilles Tjoelker
4 * Rights to this code are as documented in doc/LICENSE.
5 *
6 * Allows you to opt-out of channel entry messages.
7 *
8 */
9
10 #include "atheme.h"
11 #include "uplink.h"
12 #include "list_common.h"
13 #include "list.h"
14
15 DECLARE_MODULE_V1
16 (
17 "nickserv/set_nogreet", false, _modinit, _moddeinit,
18 PACKAGE_STRING,
19 VENDOR_STRING
20 );
21
22 mowgli_patricia_t **ns_set_cmdtree;
23
24 static void ns_cmd_set_nogreet(sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t ns_set_nogreet = { "NOGREET", N_("Allows you to opt-out of channel entry messages."), AC_NONE, 1, ns_cmd_set_nogreet, { .path = "nickserv/set_nogreet" } };
27
28 static bool has_nogreet(const mynick_t *mn, const void *arg)
29 {
30 myuser_t *mu = mn->owner;
31
32 return ( mu->flags & MU_NOGREET ) == MU_NOGREET;
33 }
34
35 void _modinit(module_t *m)
36 {
37 MODULE_TRY_REQUEST_SYMBOL(m, ns_set_cmdtree, "nickserv/set_core", "ns_set_cmdtree");
38
39 command_add(&ns_set_nogreet, *ns_set_cmdtree);
40
41 use_nslist_main_symbols(m);
42
43 static list_param_t nogreet;
44 nogreet.opttype = OPT_BOOL;
45 nogreet.is_match = has_nogreet;
46
47 list_register("nogreet", &nogreet);
48 }
49
50 void _moddeinit(module_unload_intent_t intent)
51 {
52 list_unregister("nogreet");
53 command_delete(&ns_set_nogreet, *ns_set_cmdtree);
54 }
55
56 /* SET NOGREET [ON|OFF] */
57 static void ns_cmd_set_nogreet(sourceinfo_t *si, int parc, char *parv[])
58 {
59 char *params = parv[0];
60
61 if (!params)
62 {
63 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "NOGREET");
64 return;
65 }
66
67 if (!strcasecmp("ON", params))
68 {
69 if (MU_NOGREET & si->smu->flags)
70 {
71 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for account \2%s\2."), "NOGREET", entity(si->smu)->name);
72 return;
73 }
74
75 logcommand(si, CMDLOG_SET, "SET:NOGREET:ON");
76
77 si->smu->flags |= MU_NOGREET;
78
79 command_success_nodata(si, _("The \2%s\2 flag has been set for account \2%s\2."), "NOGREET" ,entity(si->smu)->name);
80
81 return;
82 }
83 else if (!strcasecmp("OFF", params))
84 {
85 if (!(MU_NOGREET & si->smu->flags))
86 {
87 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for account \2%s\2."), "NOGREET", entity(si->smu)->name);
88 return;
89 }
90
91 logcommand(si, CMDLOG_SET, "SET:NOGREET:OFF");
92
93 si->smu->flags &= ~MU_NOGREET;
94
95 command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "NOGREET", entity(si->smu)->name);
96
97 return;
98 }
99 else
100 {
101 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "NOGREET");
102 return;
103 }
104 }
105
106 /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs
107 * vim:ts=8
108 * vim:sw=8
109 * vim:noexpandtab
110 */