forked from atheme/atheme-contrib-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs_userinfo.c
157 lines (140 loc) · 4.21 KB
/
cs_userinfo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* Copyright (c) 2007 Jilles Tjoelker, et al
* Rights to this code are as documented in doc/LICENSE.
*
* Per-channel userinfo thingie
*
*/
#include "atheme-compat.h"
DECLARE_MODULE_V1
(
"contrib/cs_userinfo", false, _modinit, _moddeinit,
PACKAGE_STRING,
"Atheme Development Group <http://www.atheme.org>"
);
static void userinfo_check_join(hook_channel_joinpart_t *hdata);
static void cs_cmd_userinfo(sourceinfo_t *si, int parc, char *parv[]);
command_t cs_userinfo = { "USERINFO", N_("Sets a userinfo message."),
AC_NONE, 3, cs_cmd_userinfo, { .path = "contrib/userinfo" } };
void _modinit(module_t *m)
{
hook_add_event("channel_join");
hook_add_channel_join(userinfo_check_join);
service_named_bind_command("chanserv", &cs_userinfo);
}
void _moddeinit(module_unload_intent_t intent)
{
hook_del_channel_join(userinfo_check_join);
service_named_unbind_command("chanserv", &cs_userinfo);
}
/* USERINFO <channel> [user] [message] */
static void cs_cmd_userinfo(sourceinfo_t *si, int parc, char *parv[])
{
mowgli_node_t *n;
myuser_t *mu;
mychan_t *mc;
chanacs_t *ca;
metadata_t *md;
unsigned int restrictflags;
if (parc < 1)
{
command_fail(si, fault_needmoreparams, STR_INSUFFICIENT_PARAMS, "USERINFO");
command_fail(si, fault_needmoreparams, _("Syntax: USERINFO <channel> [target] [info]"));
return;
}
mc = mychan_find(parv[0]);
if (!mc)
{
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), parv[0]);
return;
}
if (metadata_find(mc, "private:close:closer") && !has_priv(si, PRIV_CHAN_AUSPEX))
{
command_fail(si, fault_noprivs, _("\2%s\2 is closed."), mc->name);
return;
}
restrictflags = chanacs_source_flags(mc, si);
if (parc == 1)
{
if (!(restrictflags & CA_ACLVIEW))
{
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
return;
}
command_success_nodata(si, _("Nickname Info"));
command_success_nodata(si, "------------------- ---------------");
MOWGLI_ITER_FOREACH(n, mc->chanacs.head)
{
ca = n->data;
if (ca->entity == NULL)
continue;
md = metadata_find(ca, "userinfo");
if (md == NULL)
continue;
command_success_nodata(si, "%-19s %s", ca->entity->name, md->value);
}
command_success_nodata(si, "------------------- ---------------");
command_success_nodata(si, _("End of \2%s\2 USERINFO listing."), mc->name);
logcommand(si, CMDLOG_GET, "USERINFO:LIST: \2%s\2", mc->name);
}
else
{
if (!(restrictflags & CA_FLAGS))
{
command_fail(si, fault_noprivs, _("You are not authorized to perform this operation."));
return;
}
mu = myuser_find_ext(parv[1]);
if (mu == NULL)
{
command_fail(si, fault_nosuch_target, _("\2%s\2 is not registered."), parv[1]);
return;
}
ca = chanacs_find_literal(mc, entity(mu), 0);
if (ca == NULL || ca->level & CA_AKICK)
{
command_fail(si, fault_nosuch_target, _("\2%s\2 has no access to \2%s\2."), entity(mu)->name, mc->name);
return;
}
if (ca->level & ~allow_flags(mc, restrictflags))
{
command_fail(si, fault_noprivs, _("You are not authorized to modify the access entry for \2%s\2 on \2%s\2."), entity(mu)->name, mc->name);
return;
}
if (parc == 2)
{
metadata_delete(ca, "userinfo");
command_success_nodata(si, _("Deleted userinfo for \2%s\2 on \2%s\2."),
entity(mu)->name, mc->name);
logcommand(si, CMDLOG_SET, "USERINFO:DEL: \2%s\2 on \2%s\2", entity(mu)->name, mc->name);
return;
}
metadata_add(ca, "userinfo", parv[2]);
command_success_nodata(si, _("Added userinfo for \2%s\2 on \2%s\2."),
entity(mu)->name, mc->name);
logcommand(si, CMDLOG_SET, "USERINFO:ADD: \2%s\2 on \2%s\2 (\2%s\2)", entity(mu)->name, mc->name, parv[2]);
}
return;
}
static void userinfo_check_join(hook_channel_joinpart_t *hdata)
{
chanuser_t *cu = hdata->cu;
myuser_t *mu;
mychan_t *mc;
chanacs_t *ca;
metadata_t *md;
if (cu == NULL)
return;
if (!(cu->user->server->flags & SF_EOB))
return;
mu = cu->user->myuser;
mc = mychan_from(cu->chan);
if (mu == NULL || mc == NULL)
return;
ca = chanacs_find_literal(mc, entity(mu), 0);
if (ca == NULL || ca->level & CA_AKICK)
return;
if (!(md = metadata_find(ca, "userinfo")))
return;
msg(chansvs.nick, cu->chan->name, "[%s] %s", cu->user->nick, md->value);
}