/** * halfop.C: This file contains code for the ChanServ HALFOP functions. * * 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 © 2005 William Pitcock, et al. * Rights to this code are as documented in doc/pod/license.pod. * * $Id: halfop.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: halfop.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/halfop", false, "The Ermyth Team "); static void cs_cmd_halfop (sourceinfo_t *si, int parc, char *parv[]); static void cs_cmd_dehalfop (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_halfop = { "HALFOP", N_("Gives channel halfops to a user."), AC_NONE, 2, cs_cmd_halfop }; command_t const cs_dehalfop = { "DEHALFOP", N_("Removes channel halfops from a user."), AC_NONE, 2, cs_cmd_dehalfop }; E cmdvec cs_cmdtree; E helpvec cs_helptree; bool _modinit (module *m) { if (ircd && !ircd->uses_halfops) { slog (LG_INFO, "Module %s requires halfop support, refusing to load.", m->name); return false; } cs_cmdtree << cs_halfop; cs_cmdtree << cs_dehalfop; help_addentry (cs_helptree, "HALFOP", "help/chanserv/halfop", NULL); help_addentry (cs_helptree, "DEHALFOP", "help/chanserv/dehalfop", NULL); return true; } void _moddeinit () { cs_cmdtree >> cs_halfop; cs_cmdtree >> cs_dehalfop; help_delentry (cs_helptree, "HALFOP"); help_delentry (cs_helptree, "DEHALFOP"); } static void cs_cmd_halfop (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *nick = parv[1]; mychan_t *mc; user_t *tu; chanuser_t *cu; if (!ircd->uses_halfops) { command_fail (si, fault::noprivs, _("Your IRC server does not support halfops.")); return; } if (!chan) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "HALFOP"); command_fail (si, fault::needmoreparams, _("Syntax: HALFOP <#channel> [nickname]")); return; } mc = mychan_t::find (chan); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); return; } if (!chanacs_source_has_flag (mc, si, CA_HALFOP)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } if (mc->find_metadata ("private:close:closer")) { command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); return; } /* figure out who we're going to halfop */ if (!nick) tu = si->su; else { if (!(tu = user_find_named (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); return; } } if (is_internal_client (tu)) return; /* SECURE check; we can skip this if sender == target, because we already verified */ if ((si->su != tu) && (mc->flags & MC_SECURE) && !chanacs_user_has_flag (mc, tu, CA_HALFOP) && !chanacs_user_has_flag (mc, tu, CA_AUTOHALFOP)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation."), mc->name); command_fail (si, fault::noprivs, _("\2%s\2 has the SECURE option enabled, and \2%s\2 does not have appropriate access."), mc->name, tu->nick); return; } cu = chanuser_find (mc->chan, tu); if (!cu) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); return; } modestack_mode_param (chansvs.nick, mc->chan, MTYPE_ADD, 'h', CLIENT_NAME (tu)); cu->modes |= ircd->halfops_mode; if (si->c == NULL && tu != si->su) notice (chansvs.nick, tu->nick, "You have been halfopped on %s by %s", mc->name, get_source_name (si)); logcommand (si, CMDLOG_SET, "%s HALFOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); if (!chanuser_find (mc->chan, si->su)) command_success_nodata (si, _("\2%s\2 has been halfopped on \2%s\2."), tu->nick, mc->name); } static void cs_cmd_dehalfop (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *nick = parv[1]; mychan_t *mc; user_t *tu; chanuser_t *cu; if (!ircd->uses_halfops) { command_fail (si, fault::noprivs, _("Your IRC server does not support halfops.")); return; } if (!chan) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "DEHALFOP"); command_fail (si, fault::needmoreparams, _("Syntax: DEHALFOP <#channel> [nickname]")); return; } mc = mychan_t::find (chan); if (!mc) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not registered."), chan); return; } if (!chanacs_source_has_flag (mc, si, CA_HALFOP)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } if (mc->find_metadata ("private:close:closer")) { command_fail (si, fault::noprivs, _("\2%s\2 is closed."), chan); return; } /* figure out who we're going to dehalfop */ if (!nick) tu = si->su; else { if (!(tu = user_find_named (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); return; } } if (is_internal_client (tu)) return; cu = chanuser_find (mc->chan, tu); if (!cu) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not on \2%s\2."), tu->nick, mc->name); return; } modestack_mode_param (chansvs.nick, mc->chan, MTYPE_DEL, 'h', CLIENT_NAME (tu)); cu->modes &= ~ircd->halfops_mode; if (si->c == NULL && tu != si->su) notice (chansvs.nick, tu->nick, "You have been dehalfopped on %s by %s", mc->name, get_source_name (si)); logcommand (si, CMDLOG_SET, "%s DEHALFOP %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); if (!chanuser_find (mc->chan, si->su)) command_success_nodata (si, _("\2%s\2 has been dehalfopped on \2%s\2."), tu->nick, mc->name); } /* vim:cinoptions=>s,e0,n0,f0,{0,}0,^0,=s,ps,t0,c3,+s,(2s,us,)20,*30,gs,hs * vim:ts=8 * vim:sw=8 * vim:noexpandtab */