| 1 |
pippijn |
1.1 |
/* |
| 2 |
|
|
* Copyright © 2005 Robin Burchell, et al. |
| 3 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 4 |
pippijn |
1.1 |
* |
| 5 |
|
|
* This file contains code for the ChanServ LIST function. |
| 6 |
|
|
* |
| 7 |
pippijn |
1.4 |
* $Id: list.C,v 1.3 2007-07-21 13:23:18 pippijn Exp $ |
| 8 |
pippijn |
1.1 |
*/ |
| 9 |
|
|
|
| 10 |
|
|
#include "atheme.h" |
| 11 |
|
|
#include <account/myuser.h> |
| 12 |
|
|
#include <account/mychan.h> |
| 13 |
|
|
|
| 14 |
pippijn |
1.4 |
static char const rcsid[] = "$Id: list.C,v 1.3 2007-07-21 13:23:18 pippijn Exp $"; |
| 15 |
pippijn |
1.1 |
|
| 16 |
|
|
struct cs_list_listeners : callback::has_listeners |
| 17 |
|
|
{ |
| 18 |
|
|
}; |
| 19 |
|
|
|
| 20 |
|
|
cs_list_listeners listeners; |
| 21 |
|
|
|
| 22 |
|
|
DECLARE_MODULE_V1 ("chanserv/list", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 23 |
|
|
|
| 24 |
|
|
static void cs_cmd_list (sourceinfo_t *si, int parc, char *parv[]); |
| 25 |
|
|
|
| 26 |
|
|
command_t cs_list = { "LIST", N_("Lists channels registered matching a given pattern."), PRIV_CHAN_AUSPEX, 1, cs_cmd_list }; |
| 27 |
|
|
|
| 28 |
|
|
cmdvec *cs_cmdtree; |
| 29 |
|
|
helpvec *cs_helptree; |
| 30 |
|
|
|
| 31 |
|
|
void |
| 32 |
|
|
_modinit (module_t *m) |
| 33 |
|
|
{ |
| 34 |
|
|
MODULE_USE_SYMBOL_T (cs_cmdtree, cmdvec, "chanserv/main", "cs_cmdtree"); |
| 35 |
|
|
MODULE_USE_SYMBOL_T (cs_helptree, helpvec, "chanserv/main", "cs_helptree"); |
| 36 |
|
|
|
| 37 |
|
|
cs_cmdtree << cs_list; |
| 38 |
pippijn |
1.4 |
help_addentry (cs_helptree, "LIST", "help/chanserv/list", NULL); |
| 39 |
pippijn |
1.1 |
} |
| 40 |
|
|
|
| 41 |
|
|
void |
| 42 |
|
|
_moddeinit () |
| 43 |
|
|
{ |
| 44 |
|
|
cs_cmdtree >> cs_list; |
| 45 |
|
|
help_delentry (cs_helptree, "LIST"); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
static void |
| 49 |
|
|
cs_cmd_list (sourceinfo_t *si, int parc, char *parv[]) |
| 50 |
|
|
{ |
| 51 |
|
|
mychan_t *mc; |
| 52 |
|
|
char *chanpattern = parv[0]; |
| 53 |
|
|
char buf[BUFSIZE]; |
| 54 |
|
|
unsigned int matches = 0; |
| 55 |
|
|
dictionary_iteration_state_t state; |
| 56 |
|
|
|
| 57 |
|
|
if (!chanpattern) |
| 58 |
|
|
{ |
| 59 |
|
|
command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "LIST"); |
| 60 |
|
|
command_fail (si, fault_needmoreparams, _("Syntax: LIST <channel pattern>")); |
| 61 |
|
|
return; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
snoop ("LIST:CHANNELS: \2%s\2 by \2%s\2", chanpattern, get_oper_name (si)); |
| 65 |
|
|
command_success_nodata (si, _("Channels matching pattern \2%s\2:"), chanpattern); |
| 66 |
|
|
|
| 67 |
|
|
DICTIONARY_FOREACH (mc, mychan_t, &state, mclist) |
| 68 |
|
|
{ |
| 69 |
|
|
if (!match (chanpattern, mc->name)) |
| 70 |
|
|
{ |
| 71 |
|
|
/* in the future we could add a LIMIT parameter */ |
| 72 |
|
|
*buf = '\0'; |
| 73 |
|
|
|
| 74 |
|
|
if (mc->find_metadata ("private:mark:setter")) |
| 75 |
|
|
{ |
| 76 |
|
|
strlcat (buf, "\2[marked]\2", BUFSIZE); |
| 77 |
|
|
} |
| 78 |
|
|
if (mc->find_metadata ("private:close:closer")) |
| 79 |
|
|
{ |
| 80 |
|
|
if (*buf) |
| 81 |
|
|
strlcat (buf, " ", BUFSIZE); |
| 82 |
|
|
|
| 83 |
|
|
strlcat (buf, "\2[closed]\2", BUFSIZE); |
| 84 |
|
|
} |
| 85 |
|
|
if (mc->flags & MC_HOLD) |
| 86 |
|
|
{ |
| 87 |
|
|
if (*buf) |
| 88 |
|
|
strlcat (buf, " ", BUFSIZE); |
| 89 |
|
|
|
| 90 |
|
|
strlcat (buf, "\2[held]\2", BUFSIZE); |
| 91 |
|
|
} |
| 92 |
|
|
|
| 93 |
|
|
command_success_nodata (si, "- %s (%s) %s", mc->name, mc->founder->name, buf); |
| 94 |
|
|
matches++; |
| 95 |
|
|
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
logcommand (si, CMDLOG_ADMIN, "LIST %s (%d matches)", chanpattern, matches); |
| 99 |
|
|
if (matches == 0) |
| 100 |
|
|
command_success_nodata (si, _("No channel matched pattern \2%s\2"), chanpattern); |
| 101 |
|
|
else |
| 102 |
|
|
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); |
| 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 |
|
|
*/ |