| 1 |
pippijn |
1.8 |
/** |
| 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 |
pippijn |
1.3 |
* Copyright © 2007 Jilles Tjoelker, et al |
| 10 |
pippijn |
1.2 |
* Rights to this code are as documented in doc/pod/license.pod. |
| 11 |
pippijn |
1.1 |
* |
| 12 |
pippijn |
1.8 |
* $Id: cs_userinfo.C,v 1.7 2007-09-09 20:05:51 pippijn Exp $ |
| 13 |
pippijn |
1.1 |
*/ |
| 14 |
|
|
|
| 15 |
|
|
#include "atheme.h" |
| 16 |
pippijn |
1.7 |
#include "servers.h" |
| 17 |
pippijn |
1.3 |
#include <ermyth/module.h> |
| 18 |
pippijn |
1.1 |
#include <account/mychan.h> |
| 19 |
|
|
#include <account/myuser.h> |
| 20 |
|
|
#include <account/chanacs.h> |
| 21 |
|
|
|
| 22 |
pippijn |
1.8 |
static char const rcsid[] = "$Id: cs_userinfo.C,v 1.7 2007-09-09 20:05:51 pippijn Exp $"; |
| 23 |
pippijn |
1.1 |
|
| 24 |
pippijn |
1.3 |
REGISTER_MODULE ("chanserv/userinfo", false, "The Ermyth Team <http://ermyth.schmorp.de>"); |
| 25 |
|
|
|
| 26 |
|
|
E cmdvec cs_cmdtree; |
| 27 |
|
|
E helpvec cs_helptree; |
| 28 |
pippijn |
1.1 |
|
| 29 |
|
|
static void cs_cmd_userinfo (sourceinfo_t *si, int parc, char *parv[]); |
| 30 |
|
|
|
| 31 |
pippijn |
1.3 |
command_t const cs_userinfo = { "USERINFO", N_("Sets a userinfo message."), AC_NONE, 3, cs_cmd_userinfo }; |
| 32 |
pippijn |
1.1 |
|
| 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 |
pippijn |
1.6 |
metadata *md; |
| 42 |
pippijn |
1.1 |
unsigned int restrictflags; |
| 43 |
|
|
|
| 44 |
|
|
if (parc < 1) |
| 45 |
|
|
{ |
| 46 |
pippijn |
1.5 |
command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "USERINFO"); |
| 47 |
|
|
command_fail (si, fault::needmoreparams, _("Syntax: USERINFO <channel> [target] [info]")); |
| 48 |
pippijn |
1.1 |
return; |
| 49 |
|
|
} |
| 50 |
|
|
|
| 51 |
pippijn |
1.5 |
mc = mychan_t::find (parv[0]); |
| 52 |
pippijn |
1.1 |
if (!mc) |
| 53 |
|
|
{ |
| 54 |
pippijn |
1.5 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[0]); |
| 55 |
pippijn |
1.1 |
return; |
| 56 |
|
|
} |
| 57 |
|
|
|
| 58 |
|
|
if (mc->find_metadata ("private:close:closer") && !has_priv (si, PRIV_CHAN_AUSPEX)) |
| 59 |
|
|
{ |
| 60 |
pippijn |
1.5 |
command_fail (si, fault::noprivs, _("\2%s\2 is closed."), mc->name); |
| 61 |
pippijn |
1.1 |
return; |
| 62 |
|
|
} |
| 63 |
|
|
|
| 64 |
|
|
restrictflags = chanacs_source_flags (mc, si); |
| 65 |
|
|
|
| 66 |
|
|
if (parc == 1) |
| 67 |
|
|
{ |
| 68 |
|
|
if (!(restrictflags & CA_ACLVIEW)) |
| 69 |
|
|
{ |
| 70 |
pippijn |
1.5 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 71 |
pippijn |
1.1 |
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 |
pippijn |
1.5 |
command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); |
| 96 |
pippijn |
1.1 |
return; |
| 97 |
|
|
} |
| 98 |
pippijn |
1.4 |
mu = myuser_t::find_ext (parv[1]); |
| 99 |
pippijn |
1.1 |
if (mu == NULL) |
| 100 |
|
|
{ |
| 101 |
pippijn |
1.5 |
command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[1]); |
| 102 |
pippijn |
1.1 |
return; |
| 103 |
|
|
} |
| 104 |
|
|
ca = chanacs_find (mc, mu, 0); |
| 105 |
|
|
if (ca == NULL || ca->level & CA_AKICK) |
| 106 |
|
|
{ |
| 107 |
pippijn |
1.5 |
command_fail (si, fault::nosuch_target, _("\2%s\2 has no access to \2%s\2."), mu->name, mc->name); |
| 108 |
pippijn |
1.1 |
return; |
| 109 |
|
|
} |
| 110 |
|
|
if (ca->level & ~allow_flags (restrictflags)) |
| 111 |
|
|
{ |
| 112 |
pippijn |
1.5 |
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 |
pippijn |
1.1 |
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 |
pippijn |
1.3 |
static bool |
| 131 |
|
|
userinfo_check_join (chanuser_t *cu) |
| 132 |
pippijn |
1.1 |
{ |
| 133 |
|
|
myuser_t *mu; |
| 134 |
|
|
mychan_t *mc; |
| 135 |
|
|
chanacs_t *ca; |
| 136 |
pippijn |
1.6 |
metadata *md; |
| 137 |
pippijn |
1.1 |
|
| 138 |
|
|
if (cu == NULL) |
| 139 |
pippijn |
1.3 |
return true; |
| 140 |
pippijn |
1.1 |
if (!(cu->user->server->flags & SF_EOB)) |
| 141 |
pippijn |
1.3 |
return true; |
| 142 |
pippijn |
1.1 |
mu = cu->user->myuser; |
| 143 |
pippijn |
1.5 |
mc = mychan_t::find (cu->chan->name); |
| 144 |
pippijn |
1.1 |
if (mu == NULL || mc == NULL) |
| 145 |
pippijn |
1.3 |
return true; |
| 146 |
pippijn |
1.1 |
ca = chanacs_find (mc, mu, 0); |
| 147 |
|
|
if (ca == NULL || ca->level & CA_AKICK) |
| 148 |
pippijn |
1.3 |
return true; |
| 149 |
pippijn |
1.1 |
if (!(md = ca->find_metadata ("userinfo"))) |
| 150 |
pippijn |
1.3 |
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 |
pippijn |
1.1 |
} |