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 change 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_quietchg", 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_quietchg(sourceinfo_t *si, int parc, char *parv[]);
25
26 command_t ns_set_quietchg = { "QUIETCHG", N_("Allows you to opt-out of channel change messages."), AC_NONE, 1, ns_cmd_set_quietchg, { .path = "nickserv/set_quietchg" } };
27
has_quietchg(const mynick_t * mn,const void * arg)28 static bool has_quietchg(const mynick_t *mn, const void *arg)
29 {
30 myuser_t *mu = mn->owner;
31
32 return ( mu->flags & MU_QUIETCHG ) == MU_QUIETCHG;
33 }
34
_modinit(module_t * m)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_quietchg, *ns_set_cmdtree);
40
41 use_nslist_main_symbols(m);
42
43 static list_param_t quietchg;
44 quietchg.opttype = OPT_BOOL;
45 quietchg.is_match = has_quietchg;
46
47 list_register("quietchg", &quietchg);
48 }
49
_moddeinit(module_unload_intent_t intent)50 void _moddeinit(module_unload_intent_t intent)
51 {
52 command_delete(&ns_set_quietchg, *ns_set_cmdtree);
53
54 list_unregister("quietchg");
55 }
56
57 /* SET QUIETCHG [ON|OFF] */
ns_cmd_set_quietchg(sourceinfo_t * si,int parc,char * parv[])58 static void ns_cmd_set_quietchg(sourceinfo_t *si, int parc, char *parv[])
59 {
60 char *setting = parv[0];
61
62 if (!setting)
63 {
64 command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "QUIETCHG");
65 return;
66 }
67
68 if (!strcasecmp("ON", setting))
69 {
70 if (MU_QUIETCHG & si->smu->flags)
71 {
72 command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for account \2%s\2."), "QUIETCHG", entity(si->smu)->name);
73 return;
74 }
75
76 logcommand(si, CMDLOG_SET, "SET:QUIETCHG:ON");
77
78 si->smu->flags |= MU_QUIETCHG;
79
80 command_success_nodata(si, _("The \2%s\2 flag has been set for account \2%s\2."), "QUIETCHG" ,entity(si->smu)->name);
81
82 return;
83 }
84 else if (!strcasecmp("OFF", setting))
85 {
86 if (!(MU_QUIETCHG & si->smu->flags))
87 {
88 command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for account \2%s\2."), "QUIETCHG", entity(si->smu)->name);
89 return;
90 }
91
92 logcommand(si, CMDLOG_SET, "SET:QUIETCHG:OFF");
93
94 si->smu->flags &= ~MU_QUIETCHG;
95
96 command_success_nodata(si, _("The \2%s\2 flag has been removed for account \2%s\2."), "QUIETCHG", entity(si->smu)->name);
97
98 return;
99 }
100 else
101 {
102 command_fail(si, fault_badparams, STR_INVALID_PARAMS, "QUIETCHG");
103 return;
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 */
112