| 1 |
pippijn |
1.7 |
/** |
| 2 |
|
|
* count.C: This file contains code for the ChanServ COUNT functions. |
| 3 |
|
|
* |
| 4 |
|
|
* Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team |
| 5 |
|
|
* Rights to this code are as documented in COPYING. |
| 6 |
|
|
* |
| 7 |
|
|
* |
| 8 |
|
|
* Portions of this file were derived from sources bearing the following license: |
| 9 |
pippijn |
1.5 |
* Copyright © 2005-2006 Patrick Fish, et al. |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.7 |
* $Id: count.C,v 1.6 2007-08-30 19:56:20 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.5 |
#include <ermyth/module.h> |
| 17 |
pippijn |
1.1 |
#include <account/mychan.h> |
| 18 |
|
|
#include <account/chanacs.h> |
| 19 |
|
|
#include "template.h" |
| 20 |
|
|
|
| 21 |
pippijn |
1.7 |
static char const rcsid[] = "$Id: count.C,v 1.6 2007-08-30 19:56:20 pippijn Exp $"; |
| 22 |
pippijn |
1.1 |
|
| 23 |
pippijn |
1.5 |
REGISTER_MODULE ("chanserv/count", false, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 24 |
pippijn |
1.1 |
|
| 25 |
|
|
static void cs_cmd_count (sourceinfo_t *si, int parc, char *parv[]); |
| 26 |
|
|
|
| 27 |
pippijn |
1.5 |
command_t const cs_count = { "COUNT", N_("Shows number of entries in access lists."), AC_NONE, 1, cs_cmd_count }; |
| 28 |
pippijn |
1.1 |
|
| 29 |
pippijn |
1.5 |
E cmdvec cs_cmdtree; |
| 30 |
|
|
E helpvec cs_helptree; |
| 31 |
pippijn |
1.1 |
|
| 32 |
pippijn |
1.5 |
bool |
| 33 |
|
|
_modinit (module *m) |
| 34 |
pippijn |
1.1 |
{ |
| 35 |
pippijn |
1.4 |
help_addentry (cs_helptree, "COUNT", "help/chanserv/count", NULL); |
| 36 |
pippijn |
1.1 |
cs_cmdtree << cs_count; |
| 37 |
pippijn |
1.5 |
|
| 38 |
|
|
return true; |
| 39 |
pippijn |
1.1 |
} |
| 40 |
|
|
|
| 41 |
|
|
void |
| 42 |
|
|
_moddeinit () |
| 43 |
|
|
{ |
| 44 |
|
|
help_delentry (cs_helptree, "COUNT"); |
| 45 |
|
|
cs_cmdtree >> cs_count; |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
static void |
| 49 |
|
|
cs_cmd_count (sourceinfo_t *si, int parc, char *parv[]) |
| 50 |
|
|
{ |
| 51 |
|
|
char *chan = parv[0]; |
| 52 |
|
|
chanacs_t *ca; |
| 53 |
pippijn |
1.6 |
mychan_t *mc = mychan_t::find (chan); |
| 54 |
pippijn |
1.1 |
unsigned int ca_sop, ca_aop, ca_hop, ca_vop; |
| 55 |
|
|
int vopcnt = 0, aopcnt = 0, hopcnt = 0, sopcnt = 0, akickcnt = 0; |
| 56 |
|
|
int othercnt = 0; |
| 57 |
|
|
int i; |
| 58 |
|
|
node_t *n; |
| 59 |
|
|
char str[512]; |
| 60 |
|
|
int operoverride = 0; |
| 61 |
|
|
|
| 62 |
|
|
if (!chan) |
| 63 |
|
|
{ |
| 64 |
pippijn |
1.6 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "COUNT"); |
| 65 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: COUNT <#channel>")); |
| 66 |
pippijn |
1.1 |
return; |
| 67 |
|
|
} |
| 68 |
|
|
|
| 69 |
|
|
if (!mc) |
| 70 |
|
|
{ |
| 71 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
| 72 |
pippijn |
1.1 |
return; |
| 73 |
|
|
} |
| 74 |
|
|
|
| 75 |
|
|
if (!chanacs_source_has_flag (mc, si, CA_ACLVIEW)) |
| 76 |
|
|
{ |
| 77 |
|
|
if (has_priv (si, PRIV_CHAN_AUSPEX)) |
| 78 |
|
|
operoverride = 1; |
| 79 |
|
|
else |
| 80 |
|
|
{ |
| 81 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 82 |
pippijn |
1.1 |
return; |
| 83 |
|
|
} |
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
|
|
if (mc->find_metadata ("private:close:closer")) |
| 87 |
|
|
{ |
| 88 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
| 89 |
pippijn |
1.1 |
return; |
| 90 |
|
|
} |
| 91 |
|
|
|
| 92 |
|
|
ca_sop = get_template_flags (mc, "SOP"); |
| 93 |
|
|
ca_aop = get_template_flags (mc, "AOP"); |
| 94 |
|
|
ca_hop = get_template_flags (mc, "HOP"); |
| 95 |
|
|
ca_vop = get_template_flags (mc, "VOP"); |
| 96 |
|
|
|
| 97 |
|
|
LIST_FOREACH (n, mc->chanacs.head) |
| 98 |
|
|
{ |
| 99 |
|
|
ca = (chanacs_t *) n->data; |
| 100 |
|
|
|
| 101 |
|
|
if (ca->level == ca_vop) |
| 102 |
|
|
vopcnt++; |
| 103 |
|
|
else if (ca->level == ca_hop) |
| 104 |
|
|
hopcnt++; |
| 105 |
|
|
else if (ca->level == ca_aop) |
| 106 |
|
|
aopcnt++; |
| 107 |
|
|
else if (ca->level == ca_sop) |
| 108 |
|
|
sopcnt++; |
| 109 |
|
|
else if (ca->level == CA_AKICK) |
| 110 |
|
|
akickcnt++; |
| 111 |
pippijn |
1.5 |
else |
| 112 |
pippijn |
1.1 |
othercnt++; |
| 113 |
|
|
} |
| 114 |
|
|
if (ca_hop == ca_vop) |
| 115 |
|
|
command_success_nodata (si, _("%s: VOp: %d, AOp: %d, SOp: %d, AKick: %d, other: %d"), chan, vopcnt, aopcnt, sopcnt, akickcnt, othercnt); |
| 116 |
|
|
else |
| 117 |
|
|
command_success_nodata (si, _("%s: VOp: %d, HOp: %d, AOp: %d, SOp: %d, AKick: %d, other: %d"), chan, vopcnt, hopcnt, aopcnt, sopcnt, akickcnt, othercnt); |
| 118 |
|
|
snprintf (str, sizeof str, "%s: ", chan); |
| 119 |
|
|
for (i = 0; chanacs_flags[i].flag; i++) |
| 120 |
|
|
{ |
| 121 |
|
|
othercnt = 0; |
| 122 |
|
|
LIST_FOREACH (n, mc->chanacs.head) |
| 123 |
|
|
{ |
| 124 |
|
|
ca = (chanacs_t *) n->data; |
| 125 |
|
|
|
| 126 |
|
|
if (ca->level & chanacs_flags[i].value) |
| 127 |
|
|
othercnt++; |
| 128 |
|
|
} |
| 129 |
|
|
snprintf (str + strlen (str), sizeof str - strlen (str), "%c:%d ", chanacs_flags[i].flag, othercnt); |
| 130 |
|
|
} |
| 131 |
|
|
command_success_nodata (si, "%s", str); |
| 132 |
|
|
if (operoverride) |
| 133 |
|
|
logcommand (si, CMDLOG_ADMIN, "%s COUNT (oper override)", mc->name); |
| 134 |
|
|
else |
| 135 |
|
|
logcommand (si, CMDLOG_GET, "%s COUNT", mc->name); |
| 136 |
|
|
} |
| 137 |
|
|
|
| 138 |
|
|
/* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs |
| 139 |
|
|
* vim:ts=8 |
| 140 |
|
|
* vim:sw=8 |
| 141 |
|
|
* vim:noexpandtab |
| 142 |
|
|
*/ |