/** * list.C: This file contains code for the ChanServ LIST 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 Robin Burchell, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: list.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $ */ #include #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: list.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/list", false, "The Ermyth Team "); static void cs_cmd_list (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_list = { "LIST", N_("Lists channels registered matching a given pattern."), PRIV_CHAN_AUSPEX, 1, cs_cmd_list }; E cmdvec cs_cmdtree; E helpvec cs_helptree; bool _modinit (module *m) { cs_cmdtree << cs_list; help_addentry (cs_helptree, "LIST", "help/chanserv/list", NULL); return true; } void _moddeinit () { cs_cmdtree >> cs_list; help_delentry (cs_helptree, "LIST"); } static void cs_cmd_list (sourceinfo_t *si, int parc, char *parv[]) { mychan_t *mc; char *chanpattern = parv[0]; char buf[BUFSIZE]; unsigned int matches = 0; if (!chanpattern) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "LIST"); command_fail (si, fault::needmoreparams, _("Syntax: LIST ")); return; } snoop ("LIST:CHANNELS: \2%s\2 by \2%s\2", chanpattern, get_oper_name (si)); command_success_nodata (si, _("Channels matching pattern \2%s\2:"), chanpattern); foreach (mychan_t::pair_type &mp, mychan_t::map) { mc = mp.second; if (!match (chanpattern, mc->name)) { /* in the future we could add a LIMIT parameter */ *buf = '\0'; if (mc->find_metadata ("private:mark:setter")) strlcat (buf, "\2[marked]\2", BUFSIZE); if (mc->find_metadata ("private:close:closer")) { if (*buf) strlcat (buf, " ", BUFSIZE); strlcat (buf, "\2[closed]\2", BUFSIZE); } if (mc->flags & MC_HOLD) { if (*buf) strlcat (buf, " ", BUFSIZE); strlcat (buf, "\2[held]\2", BUFSIZE); } command_success_nodata (si, "- %s (%s) %s", mc->name, mc->founder_names (), buf); matches++; } } logcommand (si, CMDLOG_ADMIN, "LIST %s (%d matches)", chanpattern, matches); if (matches == 0) command_success_nodata (si, _("No channel matched pattern \2%s\2"), chanpattern); else command_success_nodata (si, ngettext (N_("\2%d\2 match for pattern \2%s\2"), N_("\2%d\2 matches for pattern \2%s\2"), matches), matches, chanpattern); }