]> 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 918ce21645a88fe151448f26dd607e5ace7e5d83..15a7898ed992ae24aa34bc900464306495ca4f65 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
  * See: http://wiki.inspircd.org/Credits
  *
  * This program is free but copyrighted software; see
 #include "resolvers.h"
 
 /* Handle ERROR command */
-bool TreeSocket::Error(parameterlist &params)
+void TreeSocket::Error(parameterlist &params)
 {
-       if (params.size() < 1)
-               return false;
-       ServerInstance->SNO->WriteGlobalSno('l',"ERROR from %s: %s",(!InboundServerName.empty() ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
-       /* we will return false to cause the socket to close. */
-       return false;
+       std::string msg = params.size() ? params[0] : "";
+       SetError("received ERROR " + msg);
 }
 
 void TreeSocket::Split(const std::string& line, std::string& prefix, std::string& command, parameterlist& params)
@@ -76,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);
 
@@ -85,8 +82,6 @@ void TreeSocket::ProcessLine(std::string &line)
 
        switch (this->LinkState)
        {
-               TreeServer* Node;
-
                case WAIT_AUTH_1:
                        /*
                         * State WAIT_AUTH_1:
@@ -161,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")
                        {
@@ -222,6 +200,8 @@ void TreeSocket::ProcessLine(std::string &line)
                         */
                        this->ProcessConnectedLine(prefix, command, params);
                break;
+               case DYING:
+               break;
        }
 }
 
@@ -230,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
                {
@@ -258,6 +233,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        }
 
        // Make sure prefix is still good
+       direction = who->server;
        prefix = who->uuid;
 
        /*
@@ -281,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;
        }
 
@@ -293,27 +269,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                command = "MODE";
 
        // TODO move all this into Commands
-       if (command == "UID")
-       {
-               this->ParseUID(prefix, params);
-       }
-       else if (command == "FJOIN")
-       {
-               this->ForceJoin(who,params);
-       }
-       else if (command == "STATS")
-       {
-               this->Stats(prefix, params);
-       }
-       else if (command == "MOTD")
-       {
-               this->Motd(prefix, params);
-       }
-       else if (command == "ADMIN")
-       {
-               this->Admin(prefix, params);
-       }
-       else if (command == "MAP")
+       if (command == "MAP")
        {
                Utils->Creator->HandleMap(params, who);
        }
@@ -325,26 +281,10 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                this->Error(params);
        }
-       else if (command == "OPERTYPE")
-       {
-               this->OperType(prefix,params);
-       }
        else if (command == "AWAY")
        {
                this->Away(prefix,params);
        }
-       else if (command == "FMODE")
-       {
-               this->ForceMode(who,params);
-       }
-       else if (command == "FTOPIC")
-       {
-               this->ForceTopic(prefix,params);
-       }
-       else if (command == "METADATA")
-       {
-               this->MetaData(prefix,params);
-       }
        else if (command == "PING")
        {
                this->LocalPing(prefix,params);
@@ -363,18 +303,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                this->ServerVersion(prefix,params);
        }
-       else if (command == "FHOST")
-       {
-               this->ChangeHost(prefix,params);
-       }
-       else if (command == "FNAME")
-       {
-               this->ChangeName(prefix,params);
-       }
-       else if (command == "FIDENT")
-       {
-               this->ChangeIdent(prefix,params);
-       }
        else if (command == "ADDLINE")
        {
                this->AddLine(prefix,params);
@@ -383,10 +311,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                this->DelLine(prefix,params);
        }
-       else if (command == "SVSNICK")
-       {
-               this->SVSNick(prefix,params);
-       }
        else if (command == "SAVE")
        {
                this->ForceNick(prefix,params);
@@ -403,18 +327,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        {
                this->Push(prefix,params);
        }
-       else if (command == "TIME")
-       {
-               this->Time(prefix,params);
-       }
-       else if (command == "SVSJOIN")
-       {
-               this->ServiceJoin(prefix,params);
-       }
-       else if (command == "SVSPART")
-       {
-               this->ServicePart(prefix,params);
-       }
        else if (command == "SQUIT")
        {
                if (params.size() == 2)
@@ -426,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);
                }
        }
@@ -502,65 +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)
                {
-                       res = cmd->Handle(params, who);
+                       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)
+               {
+                       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()
 {
-       if (this->LinkState == CONNECTING)
-       {
-               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();
-
-       // Test fix for big fuckup
-       if (this->LinkState != CONNECTED)
-               return;
+       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)
-       {
-               Squit(s,"Remote host closed the connection");
-       }
+       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();
        }
 }