/** * cs_userinfo.C: Per-channel userinfo thingie * * Copyright © 2007 Pippijn van Steenhoven / The Ermyth Team * Rights to this code are as documented in COPYING. * * * Portions of this file were derived from sources bearing the following license: * Copyright © 2007 Jilles Tjoelker, et al * Rights to this code are as documented in doc/pod/license.pod. * * $Id: cs_userinfo.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include "servers.h" #include #include #include #include static char const rcsid[] = "$Id: cs_userinfo.C,v 1.9 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/userinfo", false, "The Ermyth Team "); E cmdvec cs_cmdtree; E helpvec cs_helptree; static void cs_cmd_userinfo (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_userinfo = { "USERINFO", N_("Sets a userinfo message."), AC_NONE, 3, cs_cmd_userinfo }; /* USERINFO [user] [message] */ static void cs_cmd_userinfo (sourceinfo_t *si, int parc, char *parv[]) { node_t *n; myuser_t *mu; mychan_t *mc; chanacs_t *ca; metadata *md; unsigned int restrictflags; if (parc < 1) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "USERINFO"); command_fail (si, fault::needmoreparams, _("Syntax: USERINFO [target] [info]")); return; } mc = mychan_t::find (parv[0]); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), parv[0]); return; } if (mc->find_metadata ("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, "------------------- ---------------"); LIST_FOREACH (n, mc->chanacs.head) { ca = static_cast (n->data); if (ca->myuser == NULL) continue; md = ca->find_metadata ("userinfo"); if (md == NULL) continue; command_success_nodata (si, "%-19s %s", ca->myuser->name, md->value); } command_success_nodata (si, "------------------- ---------------"); command_success_nodata (si, _("End of \2%s\2 USERINFO listing."), mc->name); logcommand (si, CMDLOG_GET, "%s USERINFO", mc->name); } else { if (!(restrictflags & CA_FLAGS)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } mu = myuser_t::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 (mc, 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."), mu->name, mc->name); return; } if (ca->level & ~allow_flags (restrictflags)) { 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); return; } if (parc == 2) { ca->del_metadata ("userinfo"); command_success_nodata (si, _("Deleted userinfo for \2%s\2 on \2%s\2."), mu->name, mc->name); logcommand (si, CMDLOG_SET, "%s USERINFO %s", mc->name, mu->name); return; } ca->add_metadata ("userinfo", parv[2]); command_success_nodata (si, _("Added userinfo for \2%s\2 on \2%s\2."), mu->name, mc->name); logcommand (si, CMDLOG_SET, "%s USERINFO %s %s", mc->name, mu->name, parv[2]); } return; } static bool userinfo_check_join (chanuser_t *cu) { myuser_t *mu; mychan_t *mc; chanacs_t *ca; metadata *md; if (cu == NULL) return true; if (!(cu->user->server->flags & SF_EOB)) return true; mu = cu->user->myuser; mc = mychan_t::find (cu->chan->name); if (mu == NULL || mc == NULL) return true; ca = chanacs_find (mc, mu, 0); if (ca == NULL || ca->level & CA_AKICK) return true; if (!(md = ca->find_metadata ("userinfo"))) return true; phandler->privmsg (chansvs.nick, cu->chan->name, "[%s] %s", cu->user->nick, md->value); return true; } bool _modinit (module *m) { chanuser_t::callback.join.attach (userinfo_check_join); cs_cmdtree << cs_userinfo; help_addentry (cs_helptree, "USERINFO", "help/chanserv/userinfo", NULL); return true; } void _moddeinit (void) { chanuser_t::callback.join.detach (userinfo_check_join); cs_cmdtree >> cs_userinfo; help_delentry (cs_helptree, "USERINFO"); }