]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/server.cpp
Add method for writing server notices.
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / server.cpp
index 33c7f47b39593a7b4e0fcdef86594858752433e6..85204ccaac035b652e723ed56bd0e9ecbb147208 100644 (file)
 
 
 #include "inspircd.h"
-#include "socket.h"
-#include "xline.h"
-#include "socketengine.h"
 
-#include "main.h"
 #include "utils.h"
 #include "link.h"
 #include "treeserver.h"
@@ -55,7 +51,7 @@ bool TreeSocket::RemoteServer(const std::string &prefix, parameterlist &params)
                this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
                return false;
        }
-       if (!ServerInstance->IsSID(sid))
+       if (!InspIRCd::IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
                return false;
@@ -105,17 +101,9 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
        std::string password = params[1];
        std::string sid = params[3];
        std::string description = params[4];
-       int hops = atoi(params[2].c_str());
 
        this->SendCapabilities(2);
 
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
        if (!ServerInstance->IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
@@ -137,8 +125,9 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
                TreeServer* CheckDupe = Utils->FindServer(sname);
                if (CheckDupe)
                {
-                       this->SendError("Server "+sname+" already exists on server "+CheckDupe->GetParent()->GetName()+"!");
-                       ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+CheckDupe->GetParent()->GetName());
+                       std::string pname = CheckDupe->GetParent() ? CheckDupe->GetParent()->GetName() : "<ourself>";
+                       SendError("Server "+sname+" already exists on server "+pname+"!");
+                       ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+pname);
                        return false;
                }
                CheckDupe = Utils->FindServer(sid);
@@ -180,6 +169,33 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
        return false;
 }
 
+bool TreeSocket::CheckDuplicate(const std::string& sname, const std::string& sid)
+{
+       /* Check for fully initialized instances of the server by name */
+       TreeServer* CheckDupe = Utils->FindServer(sname);
+       if (CheckDupe)
+       {
+               std::string pname = CheckDupe->GetParent() ? CheckDupe->GetParent()->GetName() : "<ourself>";
+               SendError("Server "+sname+" already exists on server "+pname+"!");
+               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+pname);
+               return false;
+       }
+
+       /* Check for fully initialized instances of the server by id */
+       ServerInstance->Logs->Log("m_spanningtree", LOG_DEBUG, "Looking for dupe SID %s", sid.c_str());
+       CheckDupe = Utils->FindServerID(sid);
+
+       if (CheckDupe)
+       {
+               this->SendError("Server ID "+CheckDupe->GetID()+" already exists on server "+CheckDupe->GetName()+"! You may want to specify the server ID for the server manually with <server:id> so they do not conflict.");
+               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+
+                               "' already exists on server "+CheckDupe->GetName());
+               return false;
+       }
+
+       return true;
+}
+
 /*
  * Someone else is attempting to connect to us if this is called. Validate their credentials etc.
  *             -- w
@@ -197,17 +213,9 @@ bool TreeSocket::Inbound_Server(parameterlist &params)
        std::string password = params[1];
        std::string sid = params[3];
        std::string description = params[4];
-       int hops = atoi(params[2].c_str());
 
        this->SendCapabilities(2);
 
-       if (hops)
-       {
-               this->SendError("Server too far away for authentication");
-               ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server is too far away for authentication");
-               return false;
-       }
-
        if (!ServerInstance->IsSID(sid))
        {
                this->SendError("Invalid format server ID: "+sid+"!");
@@ -226,39 +234,24 @@ bool TreeSocket::Inbound_Server(parameterlist &params)
                        continue;
                }
 
-               /* Now check for fully initialized ServerInstances of the server by name */
-               TreeServer* CheckDupe = Utils->FindServer(sname);
-               if (CheckDupe)
-               {
-                       std::string pname = CheckDupe->GetParent() ? CheckDupe->GetParent()->GetName() : "<ourself>";
-                       SendError("Server "+sname+" already exists on server "+pname+"!");
-                       ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, already exists on server "+pname);
+               if (!CheckDuplicate(sname, sid))
                        return false;
-               }
 
-               /* Check for fully initialized instances of the server by id */
-               ServerInstance->Logs->Log("m_spanningtree",DEBUG,"Looking for dupe SID %s", sid.c_str());
-               CheckDupe = Utils->FindServerID(sid);
+               ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection " + linkID + " ("+description+")");
 
-               if (CheckDupe)
-               {
-                       this->SendError("Server ID "+CheckDupe->GetID()+" already exists on server "+CheckDupe->GetName()+"! You may want to specify the server ID for the server manually with <server:id> so they do not conflict.");
-                       ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupe->GetID()+
-                                       "' already exists on server "+CheckDupe->GetName());
-                       return false;
-               }
+               this->SendCapabilities(2);
 
-               ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection " + linkID + " ("+description+")");
-               linkID = sname;
+               // Save these for later, so when they accept our credentials (indicated by BURST) we remember them
+               this->capab->hidden = x->Hidden;
+               this->capab->sid = sid;
+               this->capab->description = description;
+               this->capab->name = sname;
 
-               // this is good. Send our details: Our server name and description and hopcount of 0,
+               // Send our details: Our server name and description and hopcount of 0,
                // along with the sendpass from this block.
-               this->SendCapabilities(2);
                this->WriteLine("SERVER "+ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
-               // move to the next state, we are now waiting for THEM.
-               MyRoot = new TreeServer(Utils, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
-               Utils->TreeRoot->AddChild(MyRoot);
 
+               // move to the next state, we are now waiting for THEM.
                this->LinkState = WAIT_AUTH_2;
                return true;
        }