]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_sakick.cpp
Convert WriteNumeric() calls to pass the parameters of the numeric as method parameters
[user/henk/code/inspircd.git] / src / modules / m_sakick.cpp
index d3c27b142d1a66278a51624583ec374542db6242..8fc6e741be1fab8d66fdd9e25063978111ff6b23 100644 (file)
@@ -1,53 +1,54 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
- * See: http://www.inspircd.org/wiki/index.php/Credits
+ *   Copyright (C) 2009 John Brooks <john.brooks@dereferenced.net>
+ *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "inspircd.h"
 
-/* $ModDesc: Provides a SAKICK command */
+#include "inspircd.h"
 
 /** Handle /SAKICK
  */
 class CommandSakick : public Command
 {
  public:
-       CommandSakick (InspIRCd* Instance) : Command(Instance,"SAKICK", "o", 2, 3, false, 0)
+       CommandSakick(Module* Creator) : Command(Creator,"SAKICK", 2, 3)
        {
-               this->source = "m_sakick.so";
-               syntax = "<channel> <nick> [reason]";
-               TRANSLATE4(TR_NICK, TR_TEXT, TR_TEXT, TR_END);
+               flags_needed = 'o'; Penalty = 0; syntax = "<channel> <nick> [reason]";
+               TRANSLATE3(TR_TEXT, TR_NICK, TR_TEXT);
        }
 
        CmdResult Handle (const std::vector<std::string>& parameters, User *user)
        {
                User* dest = ServerInstance->FindNick(parameters[1]);
                Channel* channel = ServerInstance->FindChan(parameters[0]);
-               const char* reason = "";
-               const char* servername = NULL;
 
-               if (dest && channel)
+               if ((dest) && (dest->registered == REG_ALL) && (channel))
                {
-                       if (parameters.size() > 2)
-                       {
-                               reason = parameters[2].c_str();
-                       }
-                       else
+                       const std::string& reason = (parameters.size() > 2) ? parameters[2] : dest->nick;
+
+                       if (dest->server->IsULine())
                        {
-                               reason = dest->nick.c_str();
+                               user->WriteNumeric(ERR_NOPRIVILEGES, "Cannot use an SA command on a u-lined client");
+                               return CMD_FAILURE;
                        }
 
-                       if (ServerInstance->ULine(dest->server))
+                       if (!channel->HasUser(dest))
                        {
-                               user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Cannot use an SA command on a u-lined client",user->nick.c_str());
+                               user->WriteNotice("*** " + dest->nick + " is not on " + channel->name);
                                return CMD_FAILURE;
                        }
 
@@ -57,68 +58,43 @@ class CommandSakick : public Command
                         */
                        if (IS_LOCAL(dest))
                        {
-                               if (!channel->ServerKickUser(dest, reason, true, servername))
-                                       delete channel;
-
-                               Channel* n = ServerInstance->FindChan(parameters[1]);
-                               if (!n)
-                               {
-                                       ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" SAKICKed "+dest->nick+" on "+parameters[0]);
-                                       return CMD_SUCCESS;
-                               }
-                               else
-                               {
-                                       if (!n->HasUser(dest))
-                                       {
-                                               ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" SAKICKed "+dest->nick+" on "+parameters[0]);
-                                               return CMD_SUCCESS;
-                                       }
-                                       else
-                                       {
-                                               user->WriteServ("NOTICE %s :*** Unable to kick %s from %s",user->nick.c_str(), dest->nick.c_str(), parameters[0].c_str());
-                                               return CMD_FAILURE;
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               ServerInstance->SNO->WriteToSnoMask('A', std::string(user->nick)+" sent remote SAKICK to kick "+dest->nick+" from "+parameters[0]);
+                               // Target is on this server, kick them and send the snotice
+                               channel->KickUser(ServerInstance->FakeClient, dest, reason);
+                               ServerInstance->SNO->WriteGlobalSno('a', user->nick + " SAKICKed " + dest->nick + " on " + channel->name);
                        }
 
                        return CMD_SUCCESS;
                }
                else
                {
-                       user->WriteServ("NOTICE %s :*** Invalid nickname or channel", user->nick.c_str());
+                       user->WriteNotice("*** Invalid nickname or channel");
                }
 
                return CMD_FAILURE;
        }
+
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters)
+       {
+               User* dest = ServerInstance->FindNick(parameters[1]);
+               if (dest)
+                       return ROUTE_OPT_UCAST(dest->server);
+               return ROUTE_LOCALONLY;
+       }
 };
 
 class ModuleSakick : public Module
 {
-       CommandSakick*  mycommand;
+       CommandSakick cmd;
  public:
-       ModuleSakick(InspIRCd* Me)
-               : Module(Me)
-       {
-
-               mycommand = new CommandSakick(ServerInstance);
-               ServerInstance->AddCommand(mycommand);
-
-       }
-
-       virtual ~ModuleSakick()
+       ModuleSakick()
+               : cmd(this)
        {
        }
 
-       virtual Version GetVersion()
+       Version GetVersion() CXX11_OVERRIDE
        {
-               return Version("$Id$", VF_VENDOR, API_VERSION);
+               return Version("Provides a SAKICK command", VF_OPTCOMMON|VF_VENDOR);
        }
-
 };
 
 MODULE_INIT(ModuleSakick)
-