| 1 |
pippijn |
1.8 |
/** |
| 2 |
|
|
* why.C: This file contains code for the ChanServ WHY function. |
| 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 William Pitcock, 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.8 |
* $Id: why.C,v 1.7 2007-09-05 11:23:13 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/myuser.h> |
| 18 |
|
|
#include <account/mychan.h> |
| 19 |
|
|
#include <account/chanacs.h> |
| 20 |
|
|
|
| 21 |
pippijn |
1.8 |
static char const rcsid[] = "$Id: why.C,v 1.7 2007-09-05 11:23:13 pippijn Exp $"; |
| 22 |
pippijn |
1.1 |
|
| 23 |
pippijn |
1.5 |
REGISTER_MODULE ("chanserv/why", false, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 24 |
pippijn |
1.1 |
|
| 25 |
|
|
static void cs_cmd_why (sourceinfo_t *si, int parc, char *parv[]); |
| 26 |
|
|
|
| 27 |
pippijn |
1.5 |
command_t const cs_why = { "WHY", N_("Explains channel access logic."), AC_NONE, 2, cs_cmd_why }; |
| 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 |
|
|
cs_cmdtree << cs_why; |
| 36 |
pippijn |
1.4 |
help_addentry (cs_helptree, "WHY", "help/chanserv/why", NULL); |
| 37 |
pippijn |
1.5 |
|
| 38 |
|
|
return true; |
| 39 |
pippijn |
1.1 |
} |
| 40 |
|
|
|
| 41 |
|
|
void |
| 42 |
|
|
_moddeinit () |
| 43 |
|
|
{ |
| 44 |
|
|
cs_cmdtree >> cs_why; |
| 45 |
|
|
help_delentry (cs_helptree, "WHY"); |
| 46 |
|
|
} |
| 47 |
|
|
|
| 48 |
|
|
static void |
| 49 |
|
|
cs_cmd_why (sourceinfo_t *si, int parc, char *parv[]) |
| 50 |
|
|
{ |
| 51 |
|
|
char *chan = parv[0]; |
| 52 |
|
|
char *targ = parv[1]; |
| 53 |
|
|
char host[BUFSIZE]; |
| 54 |
|
|
mychan_t *mc; |
| 55 |
|
|
user_t *u; |
| 56 |
|
|
myuser_t *mu; |
| 57 |
|
|
node_t *n; |
| 58 |
|
|
chanacs_t *ca; |
| 59 |
pippijn |
1.7 |
metadata *md; |
| 60 |
pippijn |
1.1 |
int operoverride = 0; |
| 61 |
|
|
int fl = 0; |
| 62 |
|
|
|
| 63 |
|
|
if (!chan || !targ) |
| 64 |
|
|
{ |
| 65 |
pippijn |
1.6 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "WHY"); |
| 66 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: WHY <channel> <user>")); |
| 67 |
pippijn |
1.1 |
return; |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
pippijn |
1.6 |
mc = mychan_t::find (chan); |
| 71 |
pippijn |
1.1 |
u = user_find_named (targ); |
| 72 |
|
|
|
| 73 |
|
|
if (u == NULL) |
| 74 |
|
|
{ |
| 75 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), targ); |
| 76 |
pippijn |
1.1 |
return; |
| 77 |
|
|
} |
| 78 |
|
|
|
| 79 |
|
|
mu = u->myuser; |
| 80 |
|
|
|
| 81 |
|
|
if (mc == NULL) |
| 82 |
|
|
{ |
| 83 |
pippijn |
1.6 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
| 84 |
pippijn |
1.1 |
return; |
| 85 |
|
|
} |
| 86 |
|
|
|
| 87 |
|
|
if (!chanacs_source_has_flag (mc, si, CA_ACLVIEW)) |
| 88 |
|
|
{ |
| 89 |
|
|
if (has_priv (si, PRIV_CHAN_AUSPEX)) |
| 90 |
|
|
operoverride = 1; |
| 91 |
|
|
else |
| 92 |
|
|
{ |
| 93 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 94 |
pippijn |
1.1 |
return; |
| 95 |
|
|
} |
| 96 |
|
|
} |
| 97 |
|
|
|
| 98 |
|
|
if (mc->find_metadata ("private:close:closer")) |
| 99 |
|
|
{ |
| 100 |
pippijn |
1.6 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
| 101 |
pippijn |
1.1 |
return; |
| 102 |
|
|
} |
| 103 |
|
|
|
| 104 |
|
|
if (operoverride) |
| 105 |
|
|
logcommand (si, CMDLOG_ADMIN, "%s WHY %s!%s@%s (oper override)", mc->name, u->nick, u->user, u->vhost); |
| 106 |
|
|
else |
| 107 |
|
|
logcommand (si, CMDLOG_GET, "%s WHY %s!%s@%s", mc->name, u->nick, u->user, u->vhost); |
| 108 |
|
|
|
| 109 |
|
|
snprintf (host, BUFSIZE, "%s!%s@%s", u->nick, u->user, u->vhost); |
| 110 |
|
|
|
| 111 |
|
|
LIST_FOREACH (n, mc->chanacs.head) |
| 112 |
|
|
{ |
| 113 |
|
|
ca = (chanacs_t *) n->data; |
| 114 |
|
|
|
| 115 |
|
|
if (ca->myuser != NULL && ca->myuser == mu) |
| 116 |
|
|
{ |
| 117 |
|
|
fl |= ca->level; |
| 118 |
|
|
command_success_nodata (si, "\2%s\2 has flags \2%s\2 in \2%s\2 because they are logged in as \2%s\2.", u->nick, bitmask_to_flags2 (ca->level, 0, chanacs_flags), mc->name, mu->name); |
| 119 |
|
|
if (ca->level & CA_AKICK) |
| 120 |
|
|
{ |
| 121 |
|
|
md = ca->find_metadata ("reason"); |
| 122 |
|
|
if (md != NULL) |
| 123 |
|
|
command_success_nodata (si, "Ban reason: %s", md->value); |
| 124 |
|
|
} |
| 125 |
|
|
} |
| 126 |
|
|
} |
| 127 |
pippijn |
1.5 |
for (n = phandler->next_matching_host_chanacs (mc, u, mc->chanacs.head); n != NULL; n = phandler->next_matching_host_chanacs (mc, u, n->next)) |
| 128 |
pippijn |
1.1 |
{ |
| 129 |
|
|
ca = static_cast<chanacs_t *> (n->data); |
| 130 |
|
|
fl |= ca->level; |
| 131 |
|
|
command_success_nodata (si, "\2%s\2 has flags \2%s\2 in \2%s\2 because they match the mask \2%s\2.", u->nick, bitmask_to_flags2 (ca->level, 0, chanacs_flags), mc->name, ca->host); |
| 132 |
|
|
if (ca->level & CA_AKICK) |
| 133 |
|
|
{ |
| 134 |
|
|
md = ca->find_metadata ("reason"); |
| 135 |
|
|
if (md != NULL) |
| 136 |
|
|
command_success_nodata (si, "Ban reason: %s", md->value); |
| 137 |
|
|
} |
| 138 |
|
|
} |
| 139 |
|
|
|
| 140 |
|
|
if ((fl & (CA_AKICK | CA_REMOVE)) == (CA_AKICK | CA_REMOVE)) |
| 141 |
|
|
command_success_nodata (si, _("+r exempts from +b.")); |
| 142 |
|
|
else if (fl == 0) |
| 143 |
|
|
command_success_nodata (si, _("\2%s\2 has no special access to \2%s\2."), u->nick, mc->name); |
| 144 |
|
|
} |