]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Remove cmd_map from the core
authorattilamolnar <attilamolnar@hush.com>
Mon, 1 Jul 2013 17:14:14 +0000 (19:14 +0200)
committerattilamolnar <attilamolnar@hush.com>
Mon, 19 Aug 2013 18:08:41 +0000 (20:08 +0200)
src/commands/cmd_map.cpp [deleted file]
src/modules/m_spanningtree/commands.h
src/modules/m_spanningtree/main.cpp
src/modules/m_spanningtree/main.h
src/modules/m_spanningtree/override_map.cpp
src/modules/m_spanningtree/precommand.cpp
src/server.cpp

diff --git a/src/commands/cmd_map.cpp b/src/commands/cmd_map.cpp
deleted file mode 100644 (file)
index 0698134..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * InspIRCd -- Internet Relay Chat Daemon
- *
- *   Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
- *   Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
- *
- * 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"
-
-class CommandMap : public Command
-{
- public:
-       /** Constructor for map.
-        */
-       CommandMap ( Module* parent) : Command(parent,"MAP",0,0) { Penalty=2; }
-       /** Handle command.
-        * @param parameters The parameters to the comamnd
-        * @param pcnt The number of parameters passed to teh command
-        * @param user The user issuing the command
-        * @return A value from CmdResult to indicate command success or failure.
-        */
-       CmdResult Handle(const std::vector<std::string>& parameters, User *user);
-};
-
-/** Handle /MAP
- */
-CmdResult CommandMap::Handle (const std::vector<std::string>&, User *user)
-{
-       // as with /LUSERS this does nothing without a linking
-       // module to override its behaviour and display something
-       // better.
-
-       if (user->IsOper())
-       {
-               user->WriteNumeric(006, "%s :%s [%s]", user->nick.c_str(), ServerInstance->Config->ServerName.c_str(), ServerInstance->Config->GetSID().c_str());
-               user->WriteNumeric(007, "%s :End of /MAP", user->nick.c_str());
-               return CMD_SUCCESS;
-       }
-       user->WriteNumeric(006, "%s :%s",user->nick.c_str(),ServerInstance->Config->ServerName.c_str());
-       user->WriteNumeric(007, "%s :End of /MAP",user->nick.c_str());
-
-       return CMD_SUCCESS;
-}
-
-COMMAND_INIT(CommandMap)
index a895c569b2510aa6933631de0d98f76f968bdd86..e467cdc8b62e17328b68a10da95e7f7fd4316fa1 100644 (file)
@@ -39,6 +39,22 @@ class CommandRSQuit : public Command
                RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
 };
 
+class CommandMap : public Command
+{
+       /** Show MAP output to a user (recursive)
+        */
+       void ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats);
+
+       /** Returns oper-specific MAP information
+        */
+       std::string MapOperInfo(TreeServer* Current);
+
+ public:
+       CommandMap(Module* Creator);
+       CmdResult Handle(const std::vector<std::string>& parameters, User* user);
+       RouteDescriptor GetRouting(User* user, const std::vector<std::string>& parameters);
+};
+
 class CommandSVSJoin : public ServerCommand
 {
  public:
@@ -269,6 +285,7 @@ class SpanningTreeCommands
  public:
        CommandRConnect rconnect;
        CommandRSQuit rsquit;
+       CommandMap map;
        CommandSVSJoin svsjoin;
        CommandSVSPart svspart;
        CommandSVSNick svsnick;
index 060dc01df9398bfe78a48f13f7ccc6854f2988db..d9a3afbd4d5d0345f1015f84b1b9e7d3914aea67 100644 (file)
@@ -41,7 +41,7 @@ ModuleSpanningTree::ModuleSpanningTree()
 }
 
 SpanningTreeCommands::SpanningTreeCommands(ModuleSpanningTree* module)
-       : rconnect(module), rsquit(module),
+       : rconnect(module), rsquit(module), map(module),
        svsjoin(module), svspart(module), svsnick(module), metadata(module),
        uid(module), opertype(module), fjoin(module), ijoin(module), resync(module),
        fmode(module), ftopic(module), fhost(module), fident(module), fname(module),
@@ -61,6 +61,7 @@ void ModuleSpanningTree::init()
        commands = new SpanningTreeCommands(this);
        ServerInstance->Modules->AddService(commands->rconnect);
        ServerInstance->Modules->AddService(commands->rsquit);
+       ServerInstance->Modules->AddService(commands->map);
 
        delete ServerInstance->PI;
        ServerInstance->PI = new SpanningTreeProtocolInterface(Utils);
@@ -393,6 +394,11 @@ ModResult ModuleSpanningTree::HandleConnect(const std::vector<std::string>& para
        return MOD_RES_DENY;
 }
 
+void ModuleSpanningTree::On005Numeric(std::map<std::string, std::string>& tokens)
+{
+       tokens["MAP"];
+}
+
 void ModuleSpanningTree::OnGetServerDescription(const std::string &servername,std::string &description)
 {
        TreeServer* s = Utils->FindServer(servername);
index e9be4416701bb88a24420d51cd41d6b8ceeaeb8c..f03a36db2ed98052d17bb3d50ef7f3a91aa77abd 100644 (file)
@@ -77,14 +77,6 @@ class ModuleSpanningTree : public Module
         */
        void HandleLinks(const std::vector<std::string>& parameters, User* user);
 
-       /** Show MAP output to a user (recursive)
-        */
-       void ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats);
-
-       /** Handle MAP command
-        */
-       bool HandleMap(const std::vector<std::string>& parameters, User* user);
-
        /** Handle SQUIT
         */
        ModResult HandleSquit(const std::vector<std::string>& parameters, User* user);
@@ -125,10 +117,6 @@ class ModuleSpanningTree : public Module
         */
        void RemoteMessage(User* user, const char* format, ...) CUSTOM_PRINTF(3, 4);
 
-       /** Returns oper-specific MAP information
-        */
-       const std::string MapOperInfo(TreeServer* Current);
-
        /** Display a time as a human readable string
         */
        static std::string TimeToStr(time_t secs);
@@ -166,6 +154,7 @@ class ModuleSpanningTree : public Module
        void OnLoadModule(Module* mod) CXX11_OVERRIDE;
        void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
        ModResult OnAcceptConnection(int newsock, ListenSocket* from, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server) CXX11_OVERRIDE;
+       void On005Numeric(std::map<std::string, std::string>& tokens) CXX11_OVERRIDE;
        CullResult cull();
        ~ModuleSpanningTree();
        Version GetVersion() CXX11_OVERRIDE;
index ae30ae706ce36532a536da48432a67cde6668c63..2b655097d5fe497c6c6d55f0919b0cceeb36bd2b 100644 (file)
 #include "main.h"
 #include "utils.h"
 #include "treeserver.h"
+#include "commands.h"
 
-const std::string ModuleSpanningTree::MapOperInfo(TreeServer* Current)
+CommandMap::CommandMap(Module* Creator)
+       : Command(Creator, "MAP", 0, 1)
+{
+       Penalty = 2;
+}
+
+std::string CommandMap::MapOperInfo(TreeServer* Current)
 {
        time_t secs_up = ServerInstance->Time() - Current->age;
-       return " [Up: " + TimeToStr(secs_up) + (Current->rtt == 0 ? "]" : " Lag: " + ConvToStr(Current->rtt) + "ms]");
+       return " [Up: " + ModuleSpanningTree::TimeToStr(secs_up) + (Current->rtt == 0 ? "]" : " Lag: " + ConvToStr(Current->rtt) + "ms]");
 }
 
-void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats)
+void CommandMap::ShowMap(TreeServer* Current, User* user, int depth, int &line, char* names, int &maxnamew, char* stats)
 {
        ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "ShowMap depth %d on line %d", depth, line);
        float percent;
@@ -92,31 +99,20 @@ void ModuleSpanningTree::ShowMap(TreeServer* Current, User* user, int depth, int
 // and divisons, we instead render the map onto a backplane of characters
 // (a character matrix), then draw the branches as a series of "L" shapes
 // from the nodes. This is not only friendlier on CPU it uses less stack.
-bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, User* user)
+CmdResult CommandMap::Handle(const std::vector<std::string>& parameters, User* user)
 {
        if (parameters.size() > 0)
        {
                /* Remote MAP, the server is within the 1st parameter */
                TreeServer* s = Utils->FindServerMask(parameters[0]);
-               bool ret = false;
                if (!s)
                {
                        user->WriteNumeric(ERR_NOSUCHSERVER, "%s %s :No such server", user->nick.c_str(), parameters[0].c_str());
-                       ret = true;
-               }
-               else if (s && s != Utils->TreeRoot)
-               {
-                       parameterlist params;
-                       params.push_back(parameters[0]);
-
-                       params[0] = s->GetName();
-                       Utils->DoOneToOne(user->uuid, "MAP", params, s->GetName());
-                       ret = true;
+                       return CMD_FAILURE;
                }
 
-               // Don't return if s == Utils->TreeRoot (us)
-               if (ret)
-                       return true;
+               if (s != Utils->TreeRoot)
+                       return CMD_SUCCESS;
        }
 
        // These arrays represent a virtual screen which we will
@@ -184,6 +180,12 @@ bool ModuleSpanningTree::HandleMap(const std::vector<std::string>& parameters, U
        delete[] names;
        delete[] stats;
 
-       return true;
+       return CMD_SUCCESS;
 }
 
+RouteDescriptor CommandMap::GetRouting(User* user, const std::vector<std::string>& parameters)
+{
+       if (!parameters.empty())
+               return ROUTE_UNICAST(parameters[0]);
+       return ROUTE_LOCALONLY;
+}
index bc78e96abb09fae7cddf226771014e0793b6ab42..29b6ae64296380fc06177cc7d2cfff91acab0c2e 100644 (file)
@@ -36,10 +36,6 @@ ModResult ModuleSpanningTree::OnPreCommand(std::string &command, std::vector<std
        {
                return this->HandleSquit(parameters,user);
        }
-       else if (command == "MAP")
-       {
-               return this->HandleMap(parameters,user) ? MOD_RES_DENY : MOD_RES_PASSTHRU;
-       }
        else if (command == "LINKS")
        {
                this->HandleLinks(parameters,user);
index efefa0d37a4b713951057708e8ffc7844db63124..97b4058c0e321d00e2bb021d39a01c85d64ceacc 100644 (file)
@@ -186,7 +186,7 @@ void ISupportManager::Build()
        tokens["STATUSMSG"] = ServerInstance->Modes->BuildPrefixes(false);
        tokens["TOPICLEN"] = ConvToStr(ServerInstance->Config->Limits.MaxTopic);
 
-       tokens["FNC"] = tokens["MAP"] = tokens["VBANLIST"] =
+       tokens["FNC"] = tokens["VBANLIST"] =
                tokens["WALLCHOPS"] = tokens["WALLVOICES"];
 
        // Modules can add new tokens and also edit or remove existing tokens