]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/server.cpp
Fix SpanningTreeProtocolInterface::SendChannelPrivmsg() and SendChannelNotice() sendi...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / server.cpp
index 393d6d8fca8e80cee44fa58fb61327f7c0b0bdfd..d3033799e1a21d8d91990b51377bcf32cbd64871 100644 (file)
@@ -1,16 +1,23 @@
-/*       +------------------------------------+
- *       | Inspire Internet Relay Chat Daemon |
- *       +------------------------------------+
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ *   Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org>
+ *   Copyright (C) 2008 Robin Burchell <robin+git@viroteck.net>
  *
- *  InspIRCd: (C) 2002-2010 InspIRCd Development Team
- * See: http://wiki.inspircd.org/Credits
+ * 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 free but copyrighted software; see
- *            the file COPYING for details.
+ * 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"
@@ -45,7 +52,7 @@ bool TreeSocket::RemoteServer(const std::string &prefix, parameterlist &params)
 
        if (!ParentOfThis)
        {
-               this->SendError("Protocol error - Introduced remote server from unknown server "+ParentOfThis->GetName());
+               this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
                return false;
        }
        if (!ServerInstance->IsSID(sid))
@@ -100,10 +107,6 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
        std::string description = params[4];
        int hops = atoi(params[2].c_str());
 
-       this->InboundServerName = sname;
-       this->InboundDescription = description;
-       this->InboundSID = sid;
-
        this->SendCapabilities(2);
 
        if (hops)
@@ -134,8 +137,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);
@@ -157,26 +161,53 @@ bool TreeSocket::Outbound_Reply_Server(parameterlist &params)
                this->LinkState = CONNECTED;
 
                Utils->timeoutlist.erase(this);
+               linkID = sname;
 
-               TreeServer *Node = new TreeServer(Utils, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
+               MyRoot = new TreeServer(Utils, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
+               Utils->TreeRoot->AddChild(MyRoot);
+               this->DoBurst(MyRoot);
 
-               Utils->TreeRoot->AddChild(Node);
                params[4] = ":" + params[4];
 
-
                /* IMPORTANT: Take password/hmac hash OUT of here before we broadcast the introduction! */
                params[1] = "*";
                Utils->DoOneToAllButSender(ServerInstance->Config->GetSID(),"SERVER",params,sname);
 
-               this->DoBurst(Node);
                return true;
        }
 
-       this->SendError("Invalid credentials (check the other server's linking snomask for more information)");
+       this->SendError("Mismatched server name or password (check the other server's snomask output for details - e.g. umode +s +Ll)");
        ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
        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",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
@@ -196,10 +227,6 @@ bool TreeSocket::Inbound_Server(parameterlist &params)
        std::string description = params[4];
        int hops = atoi(params[2].c_str());
 
-       this->InboundServerName = sname;
-       this->InboundDescription = description;
-       this->InboundSID = sid;
-
        this->SendCapabilities(2);
 
        if (hops)
@@ -227,40 +254,29 @@ 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)
-               {
-                       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());
+               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);
-
-               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;
-               }
+               ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection " + linkID + " ("+description+")");
 
+               this->SendCapabilities(2);
 
-               ServerInstance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->IP)+"] ("+description+")");
+               // 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(std::string("SERVER ")+ServerInstance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+ServerInstance->Config->GetSID()+" :"+ServerInstance->Config->ServerDesc);
+               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.
                this->LinkState = WAIT_AUTH_2;
                return true;
        }
 
-       this->SendError("Invalid credentials");
+       this->SendError("Mismatched server name or password (check the other server's snomask output for details - e.g. umode +s +Ll)");
        ServerInstance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, invalid link credentials");
        return false;
 }