| 1 |
/* |
| 2 |
* Copyright (c) 2006-2007 William Pitcock, et al. |
| 3 |
* Rights to this code are documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains routines to handle the NickServ SET PRIVMSG command. |
| 6 |
*/ |
| 7 |
|
| 8 |
#include "atheme.h" |
| 9 |
#include "list_common.h" |
| 10 |
#include "list.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"nickserv/set_privmsg", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
mowgli_patricia_t **ns_set_cmdtree; |
| 20 |
|
| 21 |
/* SET PRIVMSG ON|OFF */ |
| 22 |
static void ns_cmd_set_privmsg(sourceinfo_t *si, int parc, char *parv[]) |
| 23 |
{ |
| 24 |
char *params = parv[0]; |
| 25 |
|
| 26 |
if (!params) |
| 27 |
{ |
| 28 |
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "PRIVMSG"); |
| 29 |
return; |
| 30 |
} |
| 31 |
|
| 32 |
if (!strcasecmp("ON", params)) |
| 33 |
{ |
| 34 |
if (MU_USE_PRIVMSG & si->smu->flags) |
| 35 |
{ |
| 36 |
command_fail(si, fault_nochange, _("The \2%s\2 flag is already set for \2%s\2."), "PRIVMSG", entity(si->smu)->name); |
| 37 |
return; |
| 38 |
} |
| 39 |
|
| 40 |
logcommand(si, CMDLOG_SET, "SET:PRIVMSG:ON"); |
| 41 |
|
| 42 |
si->smu->flags |= MU_USE_PRIVMSG; |
| 43 |
|
| 44 |
command_success_nodata(si, _("The \2%s\2 flag has been set for \2%s\2."), "PRIVMSG" ,entity(si->smu)->name); |
| 45 |
|
| 46 |
return; |
| 47 |
} |
| 48 |
else if (!strcasecmp("OFF", params)) |
| 49 |
{ |
| 50 |
if (!(MU_USE_PRIVMSG & si->smu->flags)) |
| 51 |
{ |
| 52 |
command_fail(si, fault_nochange, _("The \2%s\2 flag is not set for \2%s\2."), "PRIVMSG", entity(si->smu)->name); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
logcommand(si, CMDLOG_SET, "SET:PRIVMSG:OFF"); |
| 57 |
|
| 58 |
si->smu->flags &= ~MU_USE_PRIVMSG; |
| 59 |
|
| 60 |
command_success_nodata(si, _("The \2%s\2 flag has been removed for \2%s\2."), "PRIVMSG", entity(si->smu)->name); |
| 61 |
|
| 62 |
return; |
| 63 |
} |
| 64 |
else |
| 65 |
{ |
| 66 |
command_fail(si, fault_badparams, STR_INVALID_PARAMS, "PRIVMSG"); |
| 67 |
return; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
command_t ns_set_privmsg = { "PRIVMSG", N_("Uses private messages instead of notices if enabled."), AC_NONE, 1, ns_cmd_set_privmsg, { .path = "nickserv/set_privmsg" } }; |
| 72 |
|
| 73 |
static bool uses_privmsg(const mynick_t *mn, const void *arg) |
| 74 |
{ |
| 75 |
myuser_t *mu = mn->owner; |
| 76 |
|
| 77 |
return ( mu->flags & MU_USE_PRIVMSG ) == MU_USE_PRIVMSG; |
| 78 |
} |
| 79 |
|
| 80 |
void _modinit(module_t *m) |
| 81 |
{ |
| 82 |
MODULE_TRY_REQUEST_SYMBOL(m, ns_set_cmdtree, "nickserv/set_core", "ns_set_cmdtree"); |
| 83 |
command_add(&ns_set_privmsg, *ns_set_cmdtree); |
| 84 |
|
| 85 |
use_privmsg++; |
| 86 |
|
| 87 |
use_nslist_main_symbols(m); |
| 88 |
|
| 89 |
static list_param_t use_privmsg; |
| 90 |
use_privmsg.opttype = OPT_BOOL; |
| 91 |
use_privmsg.is_match = uses_privmsg; |
| 92 |
|
| 93 |
list_register("use-privmsg", &use_privmsg); |
| 94 |
list_register("use_privmsg", &use_privmsg); |
| 95 |
} |
| 96 |
|
| 97 |
void _moddeinit(module_unload_intent_t intent) |
| 98 |
{ |
| 99 |
command_delete(&ns_set_privmsg, *ns_set_cmdtree); |
| 100 |
|
| 101 |
use_privmsg--; |
| 102 |
|
| 103 |
list_unregister("use-privmsg"); |
| 104 |
list_unregister("use_privmsg"); |
| 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 |
*/ |