ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/nickserv/listchans.C
Revision: 1.9
Committed: Sat Sep 22 14:27:28 2007 UTC (16 years, 8 months ago) by pippijn
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +3 -3 lines
Log Message:
split up ermyth into ermyth-modules, libermyth (currently just ermyth-util) and ermyth-core

File Contents

# Content
1 /**
2 * listchans.C: This file contains code for the nickserv LISTCHANS 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 Atheme Development Group
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: listchans.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/chanacs.h>
18 #include <account/mychan.h>
19 #include <account/myuser.h>
20
21 static char const rcsid[] = "$Id: listchans.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
22
23 REGISTER_MODULE ("nickserv/listchans", false, "The Ermyth Team <http://ermyth.xinutec.org>");
24
25 static void ns_cmd_listchans (sourceinfo_t *si, int parc, char *parv[]);
26
27 command_t const ns_listchans = { "LISTCHANS", N_("Lists channels that you have access to."), AC_NONE, 1, ns_cmd_listchans };
28 command_t const ns_myaccess = { "MYACCESS", N_("Alias for LISTCHANS"), AC_NONE, 1, ns_cmd_listchans };
29
30 E cmdvec ns_cmdtree;
31 E helpvec ns_helptree;
32
33 bool
34 _modinit (module *m)
35 {
36 ns_cmdtree << ns_myaccess;
37 help_addentry (ns_helptree, "MYACCESS", "help/nickserv/listchans", NULL);
38
39 ns_cmdtree << ns_listchans;
40 help_addentry (ns_helptree, "LISTCHANS", "help/nickserv/listchans", NULL);
41
42 return true;
43 }
44
45 void
46 _moddeinit ()
47 {
48 ns_cmdtree >> ns_myaccess;
49 help_delentry (ns_helptree, "MYACCESS");
50
51 ns_cmdtree >> ns_listchans;
52 help_delentry (ns_helptree, "LISTCHANS");
53 }
54
55 static void
56 ns_cmd_listchans (sourceinfo_t *si, int parc, char *parv[])
57 {
58 myuser_t *mu;
59 node_t *n;
60 chanacs_t *ca;
61 unsigned int akicks = 0, i;
62
63 /* Optional target */
64 char *target = parv[0];
65
66 if (target)
67 {
68 if (!has_priv (si, PRIV_CHAN_AUSPEX))
69 {
70 command_fail (si, fault::noprivs, _("You are not authorized to use the target argument."));
71 return;
72 }
73
74 mu = myuser_t::find_ext (target);
75
76 if (mu == NULL)
77 {
78 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), target);
79 return;
80 }
81 }
82 else
83 {
84 mu = si->smu;
85 if (mu == NULL)
86 {
87 command_fail (si, fault::noprivs, _("You are not logged in."));
88 return;
89 }
90 }
91
92 if (mu != si->smu)
93 { /* must have been an oper */
94 snoop ("LISTCHANS: \2%s\2 on \2%s\2", get_oper_name (si), mu->name);
95 logcommand (si, CMDLOG_ADMIN, "LISTCHANS %s", mu->name);
96 }
97 else
98 { /* just a user, or oper is listing himself */
99 logcommand (si, CMDLOG_GET, "LISTCHANS");
100 }
101
102 if (mu->chanacs.count == 0)
103 {
104 command_success_nodata (si, _("No channel access was found for the nickname \2%s\2."), mu->name);
105 return;
106 }
107
108 LIST_FOREACH (n, mu->chanacs.head)
109 {
110 ca = (chanacs_t *) n->data;
111
112 /* don't tell users they're akicked (flag +b) */
113 if (!(ca->level & CA_AKICK))
114 command_success_nodata (si, _("Access flag(s) %s in %s"), bitmask_to_flags (ca->level, chanacs_flags), ca->mychan->name);
115 else
116 akicks++;
117 }
118
119 i = mu->chanacs.count - akicks;
120
121 if (i == 0)
122 command_success_nodata (si, _("No channel access was found for the nickname \2%s\2."), mu->name);
123 else
124 command_success_nodata (si, ngettext (N_("\2%d\2 channel access match for the nickname \2%s\2"), N_("\2%d\2 channel access matches for the nickname \2%s\2"), i), i, mu->name);
125 }