/** * clearchan.C: This file contains functionality implementing OperServ CLEARCHAN. * * 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 © 2006 Robin Burchell * Rights to this code are documented in doc/LICENCE. * * $Id: clearchan.C,v 1.6 2007/09/16 18:54:43 pippijn Exp $ */ #include "atheme.h" #include static char const rcsid[] = "$Id: clearchan.C,v 1.6 2007/09/16 18:54:43 pippijn Exp $"; REGISTER_MODULE ("operserv/clearchan", false, "Robin Burchell "); #define CLEAR_KICK 1 #define CLEAR_KILL 2 #define CLEAR_GLINE 3 static void os_cmd_clearchan (sourceinfo_t *si, int parc, char *parv[]); command_t const os_clearchan = { "CLEARCHAN", N_("Clears a channel via KICK, KILL or GLINE"), PRIV_CHAN_ADMIN, 3, os_cmd_clearchan }; E cmdvec os_cmdtree; E helpvec os_helptree; static void os_cmd_clearchan (sourceinfo_t *si, int parc, char *parv[]) { chanuser_t *cu = NULL; node_t *n = NULL; channel_t *c = NULL; int action; char *actionstr = parv[0]; char *targchan = parv[1]; char *treason = parv[2]; char reason[512]; int matches = 0; int ignores = 0; if (!actionstr || !targchan || !treason) { command_fail (si, fault::needmoreparams, STR_INSUFFICIENT_PARAMS, "CLEARCHAN"); command_fail (si, fault::needmoreparams, _("Syntax: CLEARCHAN KICK|KILL|GLINE <#channel> ")); return; } c = channel_find (targchan); if (!c) { command_fail (si, fault::nosuch_target, _("Channel \2%s\2 does not exist."), targchan); return; } /* check what they are doing is valid */ if (!strcasecmp (actionstr, "KICK")) action = CLEAR_KICK; else if (!strcasecmp (actionstr, "KILL")) action = CLEAR_KILL; else if (!strcasecmp (actionstr, "GLINE") || !strcasecmp (actionstr, "KLINE")) action = CLEAR_GLINE; else { /* not valid! */ command_fail (si, fault::badparams, _("\2%s\2 is not a valid action"), actionstr); return; } if (action != CLEAR_KICK && !has_priv (si, PRIV_MASS_AKILL)) { command_fail (si, fault::noprivs, _("You do not have %s privilege."), PRIV_MASS_AKILL); return; } if (action == CLEAR_KICK) snprintf (reason, sizeof reason, "(Clearing) %s", treason); else snprintf (reason, sizeof reason, "(Clearing %s) %s", targchan, treason); wallops ("\2%s\2 is clearing channel %s with %s", get_oper_name (si), targchan, actionstr); snoop ("CLEARCHAN: %s on \2%s\2 by \2%s\2", actionstr, targchan, get_oper_name (si)); command_success_nodata (si, _("Clearing \2%s\2 with \2%s\2"), targchan, actionstr); /* iterate over the users in channel */ LIST_FOREACH (n, c->members.head) { cu = static_cast < chanuser_t *>(n->data); if (is_internal_client (cu->user)) ; else if (is_ircop (cu->user)) { command_success_nodata (si, _("\2CLEARCHAN\2: Ignoring IRC Operator \2%s\2!%s@%s {%s}"), cu->user->nick, cu->user->user, cu->user->host, cu->user->gecos); ignores++; } else { command_success_nodata (si, _("\2CLEARCHAN\2: \2%s\2 hit \2%s\2!%s@%s {%s}"), actionstr, cu->user->nick, cu->user->user, cu->user->host, cu->user->gecos); matches++; switch (action) { case CLEAR_KICK: phandler->kick (opersvs.nick, targchan, cu->user->nick, reason); break; case CLEAR_KILL: phandler->skill (opersvs.nick, cu->user->nick, reason); user_delete (cu->user); break; case CLEAR_GLINE: phandler->kline_sts ("*", "*", cu->user->host, 604800, reason); } } } command_success_nodata (si, _("\2%d\2 matches, \2%d\2 ignores for \2%s\2 on \2%s\2"), matches, ignores, actionstr, targchan); logcommand (si, CMDLOG_ADMIN, "CLEARCHAN %s %s %s (%d matches, %d ignores)", actionstr, targchan, treason, matches, ignores); } bool _modinit (module *m) { os_cmdtree << os_clearchan; help_addentry (os_helptree, "CLEARCHAN", "help/operserv/clearchan", NULL); return true; } void _moddeinit (void) { os_cmdtree >> os_clearchan; help_delentry (os_helptree, "CLEARCHAN"); }