]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
m_operjoin Remove duplicated code
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 66826ff3b9e3fa0392e6b766a64b63a9d3fdf5e7..4639a237ede4f329a5f4a2ed9f6a475c27330928 100644 (file)
@@ -29,6 +29,7 @@
 #include "treeserver.h"
 #include "treesocket.h"
 #include "resolvers.h"
+#include "commands.h"
 
 /* Handle ERROR command */
 void TreeSocket::Error(parameterlist &params)
@@ -178,14 +179,8 @@ void TreeSocket::ProcessLine(std::string &line)
                                MyRoot->bursting = true;
                                this->DoBurst(MyRoot);
 
-                               parameterlist sparams;
-                               sparams.push_back(MyRoot->GetName());
-                               sparams.push_back("*");
-                               sparams.push_back("0");
-                               sparams.push_back(MyRoot->GetID());
-                               sparams.push_back(":" + MyRoot->GetDesc());
-                               Utils->DoOneToAllButSender(ServerInstance->Config->GetSID(), "SERVER", sparams, MyRoot->GetName());
-                               Utils->DoOneToAllButSender(MyRoot->GetID(), "BURST", params, MyRoot->GetName());
+                               CommandServer::Builder(MyRoot).Forward(MyRoot);
+                               CmdBuilder(MyRoot->GetID(), "BURST").insert(params).Forward(MyRoot);
                        }
                        else if (command == "ERROR")
                        {
@@ -234,7 +229,6 @@ void TreeSocket::ProcessLine(std::string &line)
 void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
 {
        User* who = ServerInstance->FindUUID(prefix);
-       std::string direction;
 
        if (!who)
        {
@@ -274,10 +268,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                }
        }
 
-       // Make sure prefix is still good
-       direction = who->server;
-       prefix = who->uuid;
-
        /*
         * Check for fake direction here, and drop any instances that are found.
         * What is fake direction? Imagine the following server setup:
@@ -294,12 +284,10 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
         * a valid SID or a valid UUID, so that invalid UUID or SID never makes it
         * to the higher level functions. -- B
         */
-       TreeServer* route_back_again = Utils->BestRouteTo(direction);
-       if ((!route_back_again) || (route_back_again->GetSocket() != this))
+       TreeServer* route_back_again = TreeServer::Get(who)->GetRoute();
+       if (route_back_again->GetSocket() != this)
        {
-               if (route_back_again)
-                       ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'",
-                               prefix.c_str(),linkID.c_str());
+               ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'", prefix.c_str(), linkID.c_str());
                return;
        }
 
@@ -312,16 +300,21 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
 
        ServerCommand* scmd = Utils->Creator->CmdManager.GetHandler(command);
        CommandBase* cmdbase = scmd;
-       Command* cmd;
+       Command* cmd = NULL;
        if (!scmd)
        {
                // Not a special server-to-server command
                cmd = ServerInstance->Parser->GetHandler(command);
                if (!cmd)
                {
-                       irc::stringjoiner pmlist(params);
+                       if (command == "ERROR")
+                       {
+                               this->Error(params);
+                               return;
+                       }
+
                        ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Unrecognised S2S command :%s %s %s",
-                               who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                               who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                        SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
                        return;
                }
@@ -330,9 +323,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
 
        if (params.size() < cmdbase->min_params)
        {
-               irc::stringjoiner pmlist(params);
                ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Insufficient parameters for S2S command :%s %s %s",
-                       who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                       who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                SendError("Insufficient parameters for command '" + command + "'");
                return;
        }
@@ -353,9 +345,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
 
        if (res == CMD_INVALID)
        {
-               irc::stringjoiner pmlist(params);
                ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Error handling S2S command :%s %s %s",
-                       who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
+                       who->uuid.c_str(), command.c_str(), irc::stringjoiner(params).c_str());
                SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
        }
        else if (res == CMD_SUCCESS)
@@ -388,7 +379,7 @@ void TreeSocket::Close()
                time_t server_uptime = ServerInstance->Time() - this->age;
                if (server_uptime)
                {
-                       std::string timestr = Utils->Creator->TimeToStr(server_uptime);
+                       std::string timestr = ModuleSpanningTree::TimeToStr(server_uptime);
                        ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), timestr.c_str());
                }
        }