X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_spanningtree%2Ftreesocket2.cpp;h=8d939d22a20eefb040b4a3d37d79a065d72fde8f;hb=c8f92d97c2cd92a07bbb76b96a67cd089c7e3407;hp=66826ff3b9e3fa0392e6b766a64b63a9d3fdf5e7;hpb=b14ebbccf08ec34a73e1ba271e67da80d9fe805c;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_spanningtree/treesocket2.cpp b/src/modules/m_spanningtree/treesocket2.cpp index 66826ff3b..8d939d22a 100644 --- a/src/modules/m_spanningtree/treesocket2.cpp +++ b/src/modules/m_spanningtree/treesocket2.cpp @@ -29,6 +29,7 @@ #include "treeserver.h" #include "treesocket.h" #include "resolvers.h" +#include "commands.h" /* Handle ERROR command */ void TreeSocket::Error(parameterlist ¶ms) @@ -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()); } }