ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/modules/contrib/cs_userinfo.C
Revision: 1.9
Committed: Sat Sep 22 14:27:27 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 * cs_userinfo.C: Per-channel userinfo thingie
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 © 2007 Jilles Tjoelker, et al
10 * Rights to this code are as documented in doc/pod/license.pod.
11 *
12 * $Id: cs_userinfo.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $
13 */
14
15 #include "atheme.h"
16 #include "servers.h"
17 #include <ermyth/module.h>
18 #include <account/mychan.h>
19 #include <account/myuser.h>
20 #include <account/chanacs.h>
21
22 static char const rcsid[] = "$Id: cs_userinfo.C,v 1.8 2007-09-16 18:54:43 pippijn Exp $";
23
24 REGISTER_MODULE ("chanserv/userinfo", false, "The Ermyth Team <http://ermyth.xinutec.org>");
25
26 E cmdvec cs_cmdtree;
27 E helpvec cs_helptree;
28
29 static void cs_cmd_userinfo (sourceinfo_t *si, int parc, char *parv[]);
30
31 command_t const cs_userinfo = { "USERINFO", N_("Sets a userinfo message."), AC_NONE, 3, cs_cmd_userinfo };
32
33 /* USERINFO <channel> [user] [message] */
34 static void
35 cs_cmd_userinfo (sourceinfo_t *si, int parc, char *parv[])
36 {
37 node_t *n;
38 myuser_t *mu;
39 mychan_t *mc;
40 chanacs_t *ca;
41 metadata *md;
42 unsigned int restrictflags;
43
44 if (parc < 1)
45 {
46 command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "USERINFO");
47 command_fail (si, fault::needmoreparams, _("Syntax: USERINFO <channel> [target] [info]"));
48 return;
49 }
50
51 mc = mychan_t::find (parv[0]);
52 if (!mc)
53 {
54 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[0]);
55 return;
56 }
57
58 if (mc->find_metadata ("private:close:closer") && !has_priv (si, PRIV_CHAN_AUSPEX))
59 {
60 command_fail (si, fault::noprivs, _("\2%s\2 is closed."), mc->name);
61 return;
62 }
63
64 restrictflags = chanacs_source_flags (mc, si);
65
66 if (parc == 1)
67 {
68 if (!(restrictflags & CA_ACLVIEW))
69 {
70 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
71 return;
72 }
73 command_success_nodata (si, _("Nickname Info"));
74 command_success_nodata (si, "------------------- ---------------");
75
76 LIST_FOREACH (n, mc->chanacs.head)
77 {
78 ca = static_cast<chanacs_t *> (n->data);
79 if (ca->myuser == NULL)
80 continue;
81 md = ca->find_metadata ("userinfo");
82 if (md == NULL)
83 continue;
84 command_success_nodata (si, "%-19s %s", ca->myuser->name, md->value);
85 }
86
87 command_success_nodata (si, "------------------- ---------------");
88 command_success_nodata (si, _("End of \2%s\2 USERINFO listing."), mc->name);
89 logcommand (si, CMDLOG_GET, "%s USERINFO", mc->name);
90 }
91 else
92 {
93 if (!(restrictflags & CA_FLAGS))
94 {
95 command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."));
96 return;
97 }
98 mu = myuser_t::find_ext (parv[1]);
99 if (mu == NULL)
100 {
101 command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[1]);
102 return;
103 }
104 ca = chanacs_find (mc, mu, 0);
105 if (ca == NULL || ca->level & CA_AKICK)
106 {
107 command_fail (si, fault::nosuch_target, _("\2%s\2 has no access to \2%s\2."), mu->name, mc->name);
108 return;
109 }
110 if (ca->level & ~allow_flags (restrictflags))
111 {
112 command_fail (si, fault::noprivs, _("You are not authorized to modify the access entry for \2%s\2 on \2%s\2."), mu->name, mc->name);
113 return;
114 }
115 if (parc == 2)
116 {
117 ca->del_metadata ("userinfo");
118 command_success_nodata (si, _("Deleted userinfo for \2%s\2 on \2%s\2."), mu->name, mc->name);
119 logcommand (si, CMDLOG_SET, "%s USERINFO %s", mc->name, mu->name);
120 return;
121 }
122
123 ca->add_metadata ("userinfo", parv[2]);
124 command_success_nodata (si, _("Added userinfo for \2%s\2 on \2%s\2."), mu->name, mc->name);
125 logcommand (si, CMDLOG_SET, "%s USERINFO %s %s", mc->name, mu->name, parv[2]);
126 }
127 return;
128 }
129
130 static bool
131 userinfo_check_join (chanuser_t *cu)
132 {
133 myuser_t *mu;
134 mychan_t *mc;
135 chanacs_t *ca;
136 metadata *md;
137
138 if (cu == NULL)
139 return true;
140 if (!(cu->user->server->flags & SF_EOB))
141 return true;
142 mu = cu->user->myuser;
143 mc = mychan_t::find (cu->chan->name);
144 if (mu == NULL || mc == NULL)
145 return true;
146 ca = chanacs_find (mc, mu, 0);
147 if (ca == NULL || ca->level & CA_AKICK)
148 return true;
149 if (!(md = ca->find_metadata ("userinfo")))
150 return true;
151 phandler->privmsg (chansvs.nick, cu->chan->name, "[%s] %s", cu->user->nick, md->value);
152
153 return true;
154 }
155
156 bool
157 _modinit (module *m)
158 {
159 chanuser_t::callback.join.attach (userinfo_check_join);
160 cs_cmdtree << cs_userinfo;
161 help_addentry (cs_helptree, "USERINFO", "help/chanserv/userinfo", NULL);
162
163 return true;
164 }
165
166 void
167 _moddeinit (void)
168 {
169 chanuser_t::callback.join.detach (userinfo_check_join);
170 cs_cmdtree >> cs_userinfo;
171 help_delentry (cs_helptree, "USERINFO");
172 }