1 |
/** |
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 |
* Copyright © 2005-2006 William Pitcock, et al. |
10 |
* Rights to this code are as documented in doc/pod/license.pod. |
11 |
* |
12 |
* $Id: why.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $ |
13 |
*/ |
14 |
|
15 |
#include "atheme.h" |
16 |
#include <ermyth/module.h> |
17 |
#include <account/myuser.h> |
18 |
#include <account/mychan.h> |
19 |
#include <account/chanacs.h> |
20 |
|
21 |
static char const rcsid[] = "$Id: why.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $"; |
22 |
|
23 |
REGISTER_MODULE ("chanserv/why", false, "The Ermyth Team <http://ermyth.xinutec.org>"); |
24 |
|
25 |
static void cs_cmd_why (sourceinfo_t *si, int parc, char *parv[]); |
26 |
|
27 |
command_t const cs_why = { "WHY", N_("Explains channel access logic."), AC_NONE, 2, cs_cmd_why }; |
28 |
|
29 |
E cmdvec cs_cmdtree; |
30 |
E helpvec cs_helptree; |
31 |
|
32 |
bool |
33 |
_modinit (module *m) |
34 |
{ |
35 |
cs_cmdtree << cs_why; |
36 |
help_addentry (cs_helptree, "WHY", "help/chanserv/why", NULL); |
37 |
|
38 |
return true; |
39 |
} |
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 |
metadata *md; |
60 |
int operoverride = 0; |
61 |
int fl = 0; |
62 |
|
63 |
if (!chan || !targ) |
64 |
{ |
65 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "WHY"); |
66 |
command_fail (si, fault::needmoreparams, _("Syntax: WHY <channel> <user>")); |
67 |
return; |
68 |
} |
69 |
|
70 |
mc = mychan_t::find (chan); |
71 |
u = user_find_named (targ); |
72 |
|
73 |
if (u == NULL) |
74 |
{ |
75 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), targ); |
76 |
return; |
77 |
} |
78 |
|
79 |
mu = u->myuser; |
80 |
|
81 |
if (mc == NULL) |
82 |
{ |
83 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); |
84 |
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 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
94 |
return; |
95 |
} |
96 |
} |
97 |
|
98 |
if (mc->find_metadata ("private:close:closer")) |
99 |
{ |
100 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); |
101 |
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 |
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 |
{ |
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 |
} |