/** * listchans.C: This file contains code for the nickserv LISTCHANS function. * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2005 Atheme Development Group * Rights to this code are as documented in doc/pod/license.pod. * * $Id: listchans.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $ */ #include "atheme.h" #include #include #include #include static char const rcsid[] = "$Id: listchans.C,v 1.9 2007/09/22 14:27:28 pippijn Exp $"; REGISTER_MODULE ("nickserv/listchans", false, "The Ermyth Team "); static void ns_cmd_listchans (sourceinfo_t *si, int parc, char *parv[]); command_t const ns_listchans = { "LISTCHANS", N_("Lists channels that you have access to."), AC_NONE, 1, ns_cmd_listchans }; command_t const ns_myaccess = { "MYACCESS", N_("Alias for LISTCHANS"), AC_NONE, 1, ns_cmd_listchans }; E cmdvec ns_cmdtree; E helpvec ns_helptree; bool _modinit (module *m) { ns_cmdtree << ns_myaccess; help_addentry (ns_helptree, "MYACCESS", "help/nickserv/listchans", NULL); ns_cmdtree << ns_listchans; help_addentry (ns_helptree, "LISTCHANS", "help/nickserv/listchans", NULL); return true; } void _moddeinit () { ns_cmdtree >> ns_myaccess; help_delentry (ns_helptree, "MYACCESS"); ns_cmdtree >> ns_listchans; help_delentry (ns_helptree, "LISTCHANS"); } static void ns_cmd_listchans (sourceinfo_t *si, int parc, char *parv[]) { myuser_t *mu; node_t *n; chanacs_t *ca; unsigned int akicks = 0, i; /* Optional target */ char *target = parv[0]; if (target) { if (!has_priv (si, PRIV_CHAN_AUSPEX)) { command_fail (si, fault::noprivs, _("You are not authorized to use the target argument.")); return; } mu = myuser_t::find_ext (target); if (mu == NULL) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target); return; } } else { mu = si->smu; if (mu == NULL) { command_fail (si, fault::noprivs, _("You are not logged in.")); return; } } if (mu != si->smu) { /* must have been an oper */ snoop ("LISTCHANS: \2%s\2 on \2%s\2", get_oper_name (si), mu->name); logcommand (si, CMDLOG_ADMIN, "LISTCHANS %s", mu->name); } else { /* just a user, or oper is listing himself */ logcommand (si, CMDLOG_GET, "LISTCHANS"); } if (mu->chanacs.count == 0) { command_success_nodata (si, _("No channel access was found for the nickname \2%s\2."), mu->name); return; } LIST_FOREACH (n, mu->chanacs.head) { ca = (chanacs_t *) n->data; /* don't tell users they're akicked (flag +b) */ if (!(ca->level & CA_AKICK)) command_success_nodata (si, _("Access flag(s) %s in %s"), bitmask_to_flags (ca->level, chanacs_flags), ca->mychan->name); else akicks++; } i = mu->chanacs.count - akicks; if (i == 0) command_success_nodata (si, _("No channel access was found for the nickname \2%s\2."), mu->name); else command_success_nodata (si, ngettext (N_("\2%d\2 channel access match for the nickname \2%s\2"), N_("\2%d\2 channel access matches for the nickname \2%s\2"), i), i, mu->name); }