]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
Fix typo.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 42921058c995b4194df51579de8ed6370ede5344..15a7898ed992ae24aa34bc900464306495ca4f65 100644 (file)
@@ -73,7 +73,7 @@ void TreeSocket::ProcessLine(std::string &line)
        std::string command;
        parameterlist params;
 
-       ServerInstance->Logs->Log("m_spanningtree",DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
+       ServerInstance->Logs->Log("m_spanningtree", RAWIO, "S[%d] I %s", this->GetFd(), line.c_str());
 
        Split(line, prefix, command, params);
 
@@ -82,8 +82,6 @@ void TreeSocket::ProcessLine(std::string &line)
 
        switch (this->LinkState)
        {
-               TreeServer* Node;
-
                case WAIT_AUTH_1:
                        /*
                         * State WAIT_AUTH_1:
@@ -158,27 +156,10 @@ void TreeSocket::ProcessLine(std::string &line)
                                this->LinkState = CONNECTED;
 
                                Utils->timeoutlist.erase(this);
-                               if (myautoconnect)
-                               {
-                                       myautoconnect->position = -1;
-                                       myautoconnect = NULL;
-                               }
-
-                               Link* lnk = Utils->FindLink(InboundServerName);
-
-                               Node = new TreeServer(this->Utils, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
-
-                               Utils->TreeRoot->AddChild(Node);
                                parameterlist sparams;
-                               sparams.push_back(InboundServerName);
-                               sparams.push_back("*");
-                               sparams.push_back("1");
-                               sparams.push_back(InboundSID);
-                               sparams.push_back(":"+InboundDescription);
-                               Utils->DoOneToAllButSender(ServerInstance->Config->GetSID(),"SERVER",sparams,InboundServerName);
-                               Utils->DoOneToAllButSender(prefix, "BURST", params, InboundServerName);
-                               Node->bursting = true;
-                               this->DoBurst(Node);
+                               Utils->DoOneToAllButSender(MyRoot->GetID(), "BURST", params, MyRoot->GetName());
+                               MyRoot->bursting = true;
+                               this->DoBurst(MyRoot);
                        }
                        else if (command == "ERROR")
                        {
@@ -229,20 +210,15 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        User* who = ServerInstance->FindUUID(prefix);
        std::string direction;
 
-       if (who)
-       {
-               direction = who->server;
-       }
-       else
+       if (!who)
        {
                TreeServer* ServerSource = Utils->FindServer(prefix);
                if (prefix.empty())
-                       ServerSource = Utils->FindServer(GetName());
+                       ServerSource = MyRoot;
 
                if (ServerSource)
                {
                        who = ServerSource->ServerUser;
-                       direction = prefix;
                }
                else
                {
@@ -257,6 +233,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        }
 
        // Make sure prefix is still good
+       direction = who->server;
        prefix = who->uuid;
 
        /*
@@ -280,7 +257,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                if (route_back_again)
                        ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Protocol violation: Fake direction '%s' from connection '%s'",
-                               prefix.c_str(),this->GetName().c_str());
+                               prefix.c_str(),linkID.c_str());
                return;
        }
 
@@ -361,7 +338,8 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                if (params.size() >= 2)
                {
-                       ServerInstance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + who->nick + ": "+ params[1]);
+                       ServerInstance->SNO->WriteToSnoMask(params[0][0], "From " + who->nick + ": "+ params[1]);
+                       params[1] = ":" + params[1];
                        Utils->DoOneToAllButSender(prefix, command, params, prefix);
                }
        }
@@ -437,59 +415,62 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        else
        {
                Command* cmd = ServerInstance->Parser->GetHandler(command);
-               CmdResult res = CMD_INVALID;
-               if (cmd && params.size() >= cmd->min_params)
+               
+               if (!cmd)
+               {
+                       irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
+                       ServerInstance->Logs->Log("m_spanningtree", 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");
+               }
+
+               if (params.size() < cmd->min_params)
                {
-                       res = cmd->Handle(params, who);
+                       irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
+                       ServerInstance->Logs->Log("m_spanningtree", 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 + "'");
                }
 
+               CmdResult res = cmd->Handle(params, who);
+
                if (res == CMD_INVALID)
-                       SendError("Unrecognised or malformed command '" + command + "' -- possibly loaded mismatched modules");
+               {
+                       irc::stringjoiner pmlist(" ", params, 0, params.size() - 1);
+                       ServerInstance->Logs->Log("m_spanningtree", 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");
+               }
                if (res == CMD_SUCCESS)
                        Utils->RouteCommand(route_back_again, command, params, who);
        }
 }
 
-std::string TreeSocket::GetName()
-{
-       std::string sourceserv = this->myhost;
-       if (!this->InboundServerName.empty())
-       {
-               sourceserv = this->InboundServerName;
-       }
-       return sourceserv;
-}
-
 void TreeSocket::OnTimeout()
 {
-       ServerInstance->SNO->WriteGlobalSno('l', "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
+       ServerInstance->SNO->WriteGlobalSno('l', "CONNECT: Connection to \002%s\002 timed out.", linkID.c_str());
 }
 
 void TreeSocket::Close()
 {
+       if (fd != -1)
+               ServerInstance->GlobalCulls.AddItem(this);
        this->BufferedSocket::Close();
        SetError("Remote host closed connection");
 
        // Connection closed.
        // If the connection is fully up (state CONNECTED)
        // then propogate a netsplit to all peers.
-       std::string quitserver = this->myhost;
-       if (!this->InboundServerName.empty())
-       {
-               quitserver = this->InboundServerName;
-       }
-       TreeServer* s = Utils->FindServer(quitserver);
-       if (s && s->GetSocket() == this)
-       {
-               Squit(s,getError());
-       }
+       if (MyRoot)
+               Squit(MyRoot,getError());
 
-       if (!quitserver.empty())
+       if (!linkID.empty())
        {
-               ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' failed.",quitserver.c_str());
+               ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' failed.",linkID.c_str());
 
                time_t server_uptime = ServerInstance->Time() - this->age;
                if (server_uptime)
-                       ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+                       ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+               linkID.clear();
        }
 }