]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
m_spanningtree Netburst: Remove unused parameters and variables
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 63b73186a1a80320d61868ce11de52713b01b3c0..a06ff3a67248464aeb3646527fbfb1e9948fe451 100644 (file)
@@ -1,16 +1,27 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ *   Copyright (C) 2007-2008, 2012 Robin Burchell <robin+git@viroteck.net>
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2007-2008 Craig Edwards <craigedwards@brainbox.cc>
+ *   Copyright (C) 2008 Pippijn van Steenhoven <pip88nl@gmail.com>
+ *   Copyright (C) 2008 Thomas Stagner <aquanight@inspircd.org>
+ *   Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
  *
- * This program is free but copyrighted software; see
- *            the file COPYING for details.
+ * This file is part of InspIRCd.  InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
  *
- * ---------------------------------------------------
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+
 #include "inspircd.h"
 #include "socket.h"
 #include "xline.h"
@@ -73,7 +84,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);
 
@@ -154,12 +165,19 @@ void TreeSocket::ProcessLine(std::string &line)
                                        }
                                }
                                this->LinkState = CONNECTED;
-
                                Utils->timeoutlist.erase(this);
-                               parameterlist sparams;
-                               Utils->DoOneToAllButSender(prefix, "BURST", params, MyRoot->GetName());
+
                                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());
                        }
                        else if (command == "ERROR")
                        {
@@ -210,11 +228,7 @@ 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())
@@ -223,7 +237,6 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
                if (ServerSource)
                {
                        who = ServerSource->ServerUser;
-                       direction = prefix;
                }
                else
                {
@@ -238,6 +251,7 @@ void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command,
        }
 
        // Make sure prefix is still good
+       direction = who->server;
        prefix = who->uuid;
 
        /*
@@ -342,7 +356,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);
                }
        }
@@ -418,15 +433,35 @@ 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");
+                       return;
+               }
+
+               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 + "'");
+                       return;
                }
 
+               CmdResult res = cmd->Handle(params, who);
+
                if (res == CMD_INVALID)
-                       SendError("Unrecognised or malformed command '" + command + "' -- possibly loaded mismatched modules");
-               if (res == CMD_SUCCESS)
+               {
+                       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");
+               }
+               else if (res == CMD_SUCCESS)
                        Utils->RouteCommand(route_back_again, command, params, who);
        }
 }
@@ -449,13 +484,16 @@ void TreeSocket::Close()
        if (MyRoot)
                Squit(MyRoot,getError());
 
-       if (!linkID.empty())
+       if (!ConnectionFailureShown)
        {
+               ConnectionFailureShown = true;
                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", linkID.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
-               linkID.clear();
+               {
+                       std::string timestr = Utils->Creator->TimeToStr(server_uptime);
+                       ServerInstance->SNO->WriteGlobalSno('l', "Connection to '\2%s\2' was established for %s", linkID.c_str(), timestr.c_str());
+               }
        }
 }