]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
m_spanningtree Assign an id to new Memberships
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 66826ff3b9e3fa0392e6b766a64b63a9d3fdf5e7..8d939d22a20eefb040b4a3d37d79a065d72fde8f 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,30 +300,26 @@ 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);
-                       ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Unrecognised S2S command :%s %s %s",
-                               who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
-                       SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
-                       return;
+                       if (command == "ERROR")
+                       {
+                               this->Error(params);
+                               return;
+                       }
+
+                       throw ProtocolException("Unknown command");
                }
                cmdbase = cmd;
        }
 
        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());
-               SendError("Insufficient parameters for command '" + command + "'");
-               return;
-       }
+               throw ProtocolException("Insufficient parameters");
 
        if ((!params.empty()) && (params.back().empty()) && (!cmdbase->allow_empty_last_param))
        {
@@ -349,16 +333,13 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        if (scmd)
                res = scmd->Handle(who, params);
        else
-               res = cmd->Handle(params, who);
-
-       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());
-               SendError("Error handling '" + command + "' -- possibly loaded mismatched modules");
+               res = cmd->Handle(params, who);
+               if (res == CMD_INVALID)
+                       throw ProtocolException("Error in command handler");
        }
-       else if (res == CMD_SUCCESS)
+
+       if (res == CMD_SUCCESS)
                Utils->RouteCommand(route_back_again, cmdbase, params, who);
 }
 
@@ -388,7 +369,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());
                }
        }