ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/ermyth/modules/chanserv/why.C
Revision: 1.4
Committed: Sun Jul 22 18:38:43 2007 UTC (19 years, 2 months ago) by pippijn
Content type: text/plain
Branch: MAIN
Changes since 1.3: +3 -3 lines
Log Message:
-fixed help
- temporarily work around corruption in jsonrpc

File Contents

# User Rev Content
1 pippijn 1.1 /*
2     * Copyright © 2005-2006 William Pitcock, 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 WHY function.
6     *
7 pippijn 1.4 * $Id: why.C,v 1.3 2007-07-21 13:23:19 pippijn Exp $
8 pippijn 1.1 */
9    
10     #include "atheme.h"
11     #include <account/myuser.h>
12     #include <account/mychan.h>
13     #include <account/chanacs.h>
14    
15 pippijn 1.4 static char const rcsid[] = "$Id: why.C,v 1.3 2007-07-21 13:23:19 pippijn Exp $";
16 pippijn 1.1
17     struct cs_why_listeners : callback::has_listeners
18     {
19     };
20    
21     cs_why_listeners listeners;
22    
23     DECLARE_MODULE_V1 ("chanserv/why", false, _modinit, _moddeinit, rcsid, "The Ermyth Team <http://ermyth.schmorp.de>");
24    
25     static void cs_cmd_why (sourceinfo_t *si, int parc, char *parv[]);
26    
27     command_t cs_why = { "WHY", N_("Explains channel access logic."),
28     AC_NONE, 2, cs_cmd_why
29     };
30    
31     cmdvec *cs_cmdtree;
32     helpvec *cs_helptree;
33    
34     void
35     _modinit (module_t *m)
36     {
37     MODULE_USE_SYMBOL_T (cs_cmdtree, cmdvec, "chanserv/main", "cs_cmdtree");
38     MODULE_USE_SYMBOL_T (cs_helptree, helpvec, "chanserv/main", "cs_helptree");
39    
40     cs_cmdtree << cs_why;
41 pippijn 1.4 help_addentry (cs_helptree, "WHY", "help/chanserv/why", NULL);
42 pippijn 1.1 }
43    
44     void
45     _moddeinit ()
46     {
47     cs_cmdtree >> cs_why;
48     help_delentry (cs_helptree, "WHY");
49     }
50    
51     static void
52     cs_cmd_why (sourceinfo_t *si, int parc, char *parv[])
53     {
54     char *chan = parv[0];
55     char *targ = parv[1];
56     char host[BUFSIZE];
57     mychan_t *mc;
58     user_t *u;
59     myuser_t *mu;
60     node_t *n;
61     chanacs_t *ca;
62     metadata *md;
63     int operoverride = 0;
64     int fl = 0;
65    
66     if (!chan || !targ)
67     {
68     command_fail (si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "WHY");
69     command_fail (si, fault_needmoreparams, _("Syntax: WHY <channel> <user>"));
70     return;
71     }
72    
73     mc = mychan_find (chan);
74     u = user_find_named (targ);
75    
76     if (u == NULL)
77     {
78     command_fail (si, fault_nosuch_target, _("\2%s\2 is not online."), targ);
79     return;
80     }
81    
82     mu = u->myuser;
83    
84     if (mc == NULL)
85     {
86     command_fail (si, fault_nosuch_target, _("\2%s\2 is not registered."), chan);
87     return;
88     }
89    
90     if (!chanacs_source_has_flag (mc, si, CA_ACLVIEW))
91     {
92     if (has_priv (si, PRIV_CHAN_AUSPEX))
93     operoverride = 1;
94     else
95     {
96     command_fail (si, fault_noprivs, _("You are not authorized to perform this operation."));
97     return;
98     }
99     }
100    
101     if (mc->find_metadata ("private:close:closer"))
102     {
103     command_fail (si, fault_noprivs, _("\2%s\2 is closed."), chan);
104     return;
105     }
106    
107     if (operoverride)
108     logcommand (si, CMDLOG_ADMIN, "%s WHY %s!%s@%s (oper override)", mc->name, u->nick, u->user, u->vhost);
109     else
110     logcommand (si, CMDLOG_GET, "%s WHY %s!%s@%s", mc->name, u->nick, u->user, u->vhost);
111    
112     snprintf (host, BUFSIZE, "%s!%s@%s", u->nick, u->user, u->vhost);
113    
114     if (is_founder (mc, mu))
115     {
116     command_success_nodata (si, "\2%s\2 has founder access to \2%s\2 because they are logged in as \2%s\2.", u->nick, mc->name, mu->name);
117     }
118     LIST_FOREACH (n, mc->chanacs.head)
119     {
120     ca = (chanacs_t *) n->data;
121    
122     if (ca->myuser != NULL && ca->myuser == mu)
123     {
124     fl |= ca->level;
125     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);
126     if (ca->level & CA_AKICK)
127     {
128     md = ca->find_metadata ("reason");
129     if (md != NULL)
130     command_success_nodata (si, "Ban reason: %s", md->value);
131     }
132     }
133     }
134     for (n = next_matching_host_chanacs (mc, u, mc->chanacs.head); n != NULL; n = next_matching_host_chanacs (mc, u, n->next))
135     {
136     ca = static_cast<chanacs_t *> (n->data);
137     fl |= ca->level;
138     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);
139     if (ca->level & CA_AKICK)
140     {
141     md = ca->find_metadata ("reason");
142     if (md != NULL)
143     command_success_nodata (si, "Ban reason: %s", md->value);
144     }
145     }
146    
147     if ((fl & (CA_AKICK | CA_REMOVE)) == (CA_AKICK | CA_REMOVE))
148     command_success_nodata (si, _("+r exempts from +b."));
149     else if (fl == 0)
150     command_success_nodata (si, _("\2%s\2 has no special access to \2%s\2."), u->nick, mc->name);
151     }