| 1 |
/* |
| 2 |
* Copyright (c) 2005 Atheme Development Group |
| 3 |
* Rights to this code are as documented in doc/LICENSE. |
| 4 |
* |
| 5 |
* This file contains code for the nickserv LISTCHANS function. |
| 6 |
* -- Contains an alias "MYACCESS" for legacy users |
| 7 |
* |
| 8 |
*/ |
| 9 |
|
| 10 |
#include "atheme.h" |
| 11 |
|
| 12 |
DECLARE_MODULE_V1 |
| 13 |
( |
| 14 |
"nickserv/listchans", false, _modinit, _moddeinit, |
| 15 |
PACKAGE_STRING, |
| 16 |
VENDOR_STRING |
| 17 |
); |
| 18 |
|
| 19 |
static void ns_cmd_listchans(sourceinfo_t *si, int parc, char *parv[]); |
| 20 |
|
| 21 |
command_t ns_listchans = { "LISTCHANS", N_("Lists channels that you have access to."), AC_NONE, 1, ns_cmd_listchans, { .path = "nickserv/listchans" } }; |
| 22 |
|
| 23 |
void _modinit(module_t *m) |
| 24 |
{ |
| 25 |
service_named_bind_command("nickserv", &ns_listchans); |
| 26 |
} |
| 27 |
|
| 28 |
void _moddeinit(module_unload_intent_t intent) |
| 29 |
{ |
| 30 |
service_named_unbind_command("nickserv", &ns_listchans); |
| 31 |
} |
| 32 |
|
| 33 |
static void ns_cmd_listchans(sourceinfo_t *si, int parc, char *parv[]) |
| 34 |
{ |
| 35 |
myuser_t *mu; |
| 36 |
mowgli_node_t *n; |
| 37 |
chanacs_t *ca; |
| 38 |
unsigned int akicks = 0, i; |
| 39 |
|
| 40 |
/* Optional target */ |
| 41 |
char *target = parv[0]; |
| 42 |
|
| 43 |
if (target) |
| 44 |
{ |
| 45 |
if (!has_priv(si, PRIV_CHAN_AUSPEX)) |
| 46 |
{ |
| 47 |
command_fail(si, fault_noprivs, _("You are not authorized to use the target argument.")); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
mu = myuser_find_ext(target); |
| 52 |
|
| 53 |
if (mu == NULL) |
| 54 |
{ |
| 55 |
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), target); |
| 56 |
return; |
| 57 |
} |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
mu = si->smu; |
| 62 |
if (mu == NULL) |
| 63 |
{ |
| 64 |
command_fail(si, fault_noprivs, _("You are not logged in.")); |
| 65 |
return; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
if (mu != si->smu) |
| 70 |
{ /* must have been an oper */ |
| 71 |
logcommand(si, CMDLOG_ADMIN, "LISTCHANS: \2%s\2", entity(mu)->name); |
| 72 |
} |
| 73 |
else |
| 74 |
{ /* just a user, or oper is listing himself */ |
| 75 |
logcommand(si, CMDLOG_GET, "LISTCHANS"); |
| 76 |
} |
| 77 |
|
| 78 |
if (MOWGLI_LIST_LENGTH(&entity(mu)->chanacs) == 0) |
| 79 |
{ |
| 80 |
command_success_nodata(si, _("No channel access was found for the nickname \2%s\2."), entity(mu)->name); |
| 81 |
return; |
| 82 |
} |
| 83 |
|
| 84 |
MOWGLI_ITER_FOREACH(n, entity(mu)->chanacs.head) |
| 85 |
{ |
| 86 |
ca = (chanacs_t *)n->data; |
| 87 |
|
| 88 |
/* don't tell users they're akicked (flag +b) */ |
| 89 |
if (ca->level != CA_AKICK) |
| 90 |
command_success_nodata(si, _("Access flag(s) %s in %s"), bitmask_to_flags(ca->level), ca->mychan->name); |
| 91 |
else |
| 92 |
akicks++; |
| 93 |
} |
| 94 |
|
| 95 |
i = MOWGLI_LIST_LENGTH(&entity(mu)->chanacs) - akicks; |
| 96 |
|
| 97 |
if (i == 0) |
| 98 |
command_success_nodata(si, _("No channel access was found for the nickname \2%s\2."), entity(mu)->name); |
| 99 |
else |
| 100 |
command_success_nodata(si, ngettext(N_("\2%d\2 channel access match for the nickname \2%s\2"), |
| 101 |
N_("\2%d\2 channel access matches for the nickname \2%s\2"), i), |
| 102 |
i, entity(mu)->name); |
| 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 |
*/ |