/** * kick.C: This file contains code for the ChanServ KICK 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: kick.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $ */ #include "atheme.h" #include #include #include static char const rcsid[] = "$Id: kick.C,v 1.8 2007/09/22 14:27:27 pippijn Exp $"; REGISTER_MODULE ("chanserv/kick", false, "The Ermyth Team "); static void cs_cmd_kick (sourceinfo_t *si, int parc, char *parv[]); static void cs_cmd_kickban (sourceinfo_t *si, int parc, char *parv[]); command_t const cs_kick = { "KICK", N_("Removes a user from a channel."), AC_NONE, 3, cs_cmd_kick }; command_t const cs_kickban = { "KICKBAN", N_("Removes and bans a user from a channel."), AC_NONE, 3, cs_cmd_kickban }; E cmdvec cs_cmdtree; E helpvec cs_helptree; bool _modinit (module *m) { cs_cmdtree << cs_kick; cs_cmdtree << cs_kickban; help_addentry (cs_helptree, "KICK", "help/chanserv/kick", NULL); help_addentry (cs_helptree, "KICKBAN", "help/chanserv/kickban", NULL); return true; } void _moddeinit () { cs_cmdtree >> cs_kick; cs_cmdtree >> cs_kickban; help_delentry (cs_helptree, "KICK"); help_delentry (cs_helptree, "KICKBAN"); } static void cs_cmd_kick (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *nick = parv[1]; char *reason = parv[2]; mychan_t *mc; user_t *tu; chanuser_t *cu; char reasonbuf[BUFSIZE]; if (!chan || !nick) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICK"); command_fail (si, fault::needmoreparams, _("Syntax: KICK <#channel> [reason]")); 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_REMOVE)) { 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 kick */ if (!(tu = user_find_named (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); return; } /* if target is a service, bail. --nenolod */ 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; } snprintf (reasonbuf, BUFSIZE, "%s (%s)", reason ? reason : "No reason given", get_source_name (si)); phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf); logcommand (si, CMDLOG_SET, "%s KICK %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); if (si->su != tu && !chanuser_find (mc->chan, si->su)) command_success_nodata (si, _("\2%s\2 has been kicked from \2%s\2."), tu->nick, mc->name); } static void cs_cmd_kickban (sourceinfo_t *si, int parc, char *parv[]) { char *chan = parv[0]; char *nick = parv[1]; char *reason = parv[2]; mychan_t *mc; user_t *tu; chanuser_t *cu; char reasonbuf[BUFSIZE]; int n; if (!chan || !nick) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "KICKBAN"); command_fail (si, fault::needmoreparams, _("Syntax: KICKBAN <#channel> [reason]")); 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_REMOVE)) { command_fail (si, fault::noprivs, _("You are not authorized to perform this operation.")); return; } /* figure out who we're going to kick */ if (!(tu = user_find_named (nick))) { command_fail (si, fault::nosuch_target, _("\2%s\2 is not online."), nick); return; } /* if target is a service, bail. --nenolod */ 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; } snprintf (reasonbuf, BUFSIZE, "%s (%s)", reason ? reason : "No reason given", get_source_name (si)); ban (si->service->me, mc->chan, tu); n = remove_ban_exceptions (si->service->me, mc->chan, tu); if (n > 0) command_success_nodata (si, _("To avoid rejoin, %d ban exception(s) matching \2%s\2 have been removed from \2%s\2."), n, tu->nick, mc->name); phandler->kick (chansvs.nick, chan, tu->nick, reasonbuf); logcommand (si, CMDLOG_SET, "%s KICKBAN %s!%s@%s", mc->name, tu->nick, tu->user, tu->vhost); if (si->su != tu && !chanuser_find (mc->chan, si->su)) command_success_nodata (si, _("\2%s\2 has been kickbanned from \2%s\2."), tu->nick, mc->name); }