]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
First round of servername->sid stuffs
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index ca51ed464a3b48c31cd71b1f54226e3f180895f6..7f274ba13dae8b78b57f4ac2660806931aba550d 100644 (file)
  * ---------------------------------------------------
  */
 
-#include "configreader.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
+#include "inspircd.h"
 #include "commands/cmd_whois.h"
 #include "commands/cmd_stats.h"
 #include "socket.h"
-#include "inspircd.h"
 #include "wildcard.h"
 #include "xline.h"
 #include "transport.h"
@@ -38,7 +34,7 @@ static std::map<std::string, std::string> warned;       /* Server names that hav
 
 int TreeSocket::WriteLine(std::string line)
 {
-       Instance->Log(DEBUG, "-> %s", line.c_str());
+       Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
        line.append("\r\n");
        return this->Write(line);
 }
@@ -49,7 +45,7 @@ bool TreeSocket::Error(std::deque<std::string> &params)
 {
        if (params.size() < 1)
                return false;
-       this->Instance->SNO->WriteToSnoMask('l',"ERROR from %s: %s",(InboundServerName != "" ? InboundServerName.c_str() : myhost.c_str()),params[0].c_str());
+       this->Instance->SNO->WriteToSnoMask('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;
 }
@@ -142,7 +138,7 @@ bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> &params
                                        Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
                                }
 
-                               par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" End of message of the day.";
+                               par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" :End of message of the day.";
                                Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
                        }
                }
@@ -245,7 +241,28 @@ bool TreeSocket::OperType(const std::string &prefix, std::deque<std::string> &pa
                this->Instance->all_opers.push_back(u);
                strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
                Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
-               this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
+
+               TreeServer* remoteserver=Utils->FindServer(u->server);
+               bool dosend = true;
+
+               if (this->Utils->quiet_bursts)
+               {
+                       /*
+                        * If quiet bursts are enabled, and server is bursting or silent uline (i.e. services),
+                        * then do nothing. -- w00t
+                        */
+                       if (
+                               this->bursting ||
+                               Utils->FindRemoteBurstServer(remoteserver) ||
+                               this->Instance->SilentULine(this->Instance->FindServerNamePtr(u->server))
+                          )
+                       {
+                               dosend = false;
+                       }
+               }
+
+               if (dosend)
+                       this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
        }
        return true;
 }
@@ -263,18 +280,26 @@ bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> &p
        if (u)
        {
                Utils->DoOneToAllButSender(prefix,"SVSNICK",params,prefix);
+
                if (IS_LOCAL(u))
                {
                        std::deque<std::string> par;
                        par.push_back(params[1]);
+
                        if (!u->ForceNickChange(params[1].c_str()))
                        {
-                               userrec::QuitUser(this->Instance, u, "Nickname collision");
-                               return true;
+                               /* buh. UID them */
+                               if (!u->ForceNickChange(u->uuid))
+                               {
+                                       userrec::QuitUser(this->Instance, u, "Nickname collision");
+                                       return true;
+                               }
                        }
+
                        u->age = atoi(params[2].c_str());
                }
        }
+
        return true;
 }
 
@@ -287,62 +312,19 @@ bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> &pa
 
        if (u)
        {
-               Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
                u->SetOperQuit(params[0]);
+               params[0] = ":" + params[0];
+               Utils->DoOneToAllButSender(prefix,"OPERQUIT",params,prefix);
        }
        return true;
 }
 
-/*
- * Remote SQUIT (RSQUIT). Routing works similar to SVSNICK: Route it to the server that the target is connected to locally,
- * then let that server do the dirty work (squit it!). Example:
- * A -> B -> C -> D: oper on A squits D, A routes to B, B routes to C, C notices D connected locally, kills it. -- w00t
- */
-bool TreeSocket::RemoteSquit(const std::string &prefix, std::deque<std::string> &params)
+bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> &params)
 {
-       /* ok.. :w00t RSQUIT jupe.barafranca.com :reason here */
        if (params.size() < 2)
                return true;
 
-       TreeServer* s = Utils->FindServerMask(params[0]);
-
-       if (s)
-       {
-               if (s == Utils->TreeRoot)
-               {
-                       this->Instance->SNO->WriteToSnoMask('l',"What the fuck, I recieved a remote SQUIT for myself? :< (from %s", prefix.c_str());
-                       return true;
-               }
-
-               TreeSocket* sock = s->GetSocket();
-
-               if (sock)
-               {
-                       /* it's locally connected, KILL IT! */
-                       Instance->SNO->WriteToSnoMask('l',"RSQUIT: Server \002%s\002 removed from network by %s: %s", params[0].c_str(), prefix.c_str(), params[1].c_str());
-                       sock->Squit(s,"Server quit by " + prefix + ": " + params[1]);
-                       Instance->SE->DelFd(sock);
-                       sock->Close();
-                       delete sock;
-               }
-               else
-               {
-                       /* route the rsquit */
-                       params[1] = ":" + params[1];
-                       Utils->DoOneToOne(prefix, "RSQUIT", params, params[0]);
-               }
-       }
-       else
-       {
-               /* mother fucker! it doesn't exist */
-       }
-
-       return true;
-}
-
-bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string> &params)
-{
-       if (params.size() < 2)
+       if (!this->Instance->IsChannel(params[1].c_str()))
                return true;
 
        userrec* u = this->Instance->FindNick(params[0]);
@@ -376,30 +358,25 @@ bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque<std::string>
 }
 
 bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> &params)
-{
+{       
        if (params.size() != 2)
                return true;
 
-       std::string nick = params[0];
-       userrec* u = this->Instance->FindNick(prefix);
-       userrec* who = this->Instance->FindNick(nick);
+       userrec* who = this->Instance->FindNick(params[0]);
 
        if (who)
        {
-               /* Prepend kill source, if we don't have one */
-               std::string sourceserv = prefix;
-               if (u)
-               {
-                       sourceserv = u->server;
-               }
+               /* Prepend kill source, if we don't have one */          
                if (*(params[1].c_str()) != '[')
                {
-                       params[1] = "[" + sourceserv + "] Killed (" + params[1] +")";
+                       params[1] = "[" + prefix + "] Killed (" + params[1] +")";
                }
                std::string reason = params[1];
                params[1] = ":" + params[1];
-               Utils->DoOneToAllButSender(prefix,"KILL",params,sourceserv);
-               who->Write(":%s KILL %s :%s (%s)", sourceserv.c_str(), who->nick, sourceserv.c_str(), reason.c_str());
+               Utils->DoOneToAllButSender(prefix,"KILL",params,prefix);
+               // NOTE: This is safe with kill hiding on, as RemoteKill is only reached if we have a server prefix.
+               // in short this is not executed for USERS.
+               who->Write(":%s KILL %s :%s (%s)", prefix.c_str(), who->nick, prefix.c_str(), reason.c_str());
                userrec::QuitUser(this->Instance,who,reason);
        }
        return true;
@@ -416,7 +393,10 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> &p
                if (ServerSource)
                {
                        ServerSource->SetPingFlag();
-                       ServerSource->rtt = Instance->Time() - ServerSource->LastPing;
+                       timeval t;
+                       gettimeofday(&t, NULL);
+                       long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
+                       ServerSource->rtt = ts - ServerSource->LastPingMsec;
                }
        }
        else
@@ -455,6 +435,8 @@ bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> &pa
        TreeServer* ServerSource = Utils->FindServer(prefix);
        if (ServerSource)
        {
+               Utils->SetRemoteBursting(ServerSource, false);
+
                if (params[0] == "*")
                {
                        FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_OTHER,NULL,params[1],params[2]));
@@ -793,12 +775,13 @@ bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string>
 
 bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string> &params)
 {
-       if (params.size() < 4)
+       if (params.size() < 5)
                return false;
        std::string servername = params[0];
        std::string password = params[1];
        // hopcount is not used for a remote server, we calculate this ourselves
-       std::string description = params[3];
+       std::string sid = params[3];
+       std::string description = params[4];
        TreeServer* ParentOfThis = Utils->FindServer(prefix);
        if (!ParentOfThis)
        {
@@ -812,10 +795,21 @@ bool TreeSocket::RemoteServer(const std::string &prefix, std::deque<std::string>
                this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, already exists. Closing link with " + prefix);
                return false;
        }
+
        Link* lnk = Utils->FindLink(servername);
-       TreeServer* Node = new TreeServer(this->Utils,this->Instance,servername,description,ParentOfThis,NULL, lnk ? lnk->Hidden : false);
+
+       TreeServer *Node = new TreeServer(this->Utils, this->Instance, servername, description, sid, ParentOfThis,NULL, lnk ? lnk->Hidden : false);
+
+       if (Node->DuplicateID())
+       {
+               this->SendError("Server ID "+sid+" already exists on the network!");
+               this->Instance->SNO->WriteToSnoMask('l',"Server \2"+servername+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link with " + prefix);
+               return false;
+       }
+
        ParentOfThis->AddChild(Node);
-       params[3] = ":" + params[3];
+       params[4] = ":" + params[4];
+       Utils->SetRemoteBursting(Node, true);
        Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
        this->Instance->SNO->WriteToSnoMask('l',"Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
        return true;
@@ -841,17 +835,22 @@ bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
 
 bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
 {
-       if (params.size() < 4)
+       if (params.size() < 5)
                return false;
 
        irc::string servername = params[0].c_str();
        std::string sname = params[0];
        std::string password = params[1];
-       std::string description = params[3];
+       std::string sid = params[3];
+       std::string description = params[4];
        int hops = atoi(params[2].c_str());
 
        this->InboundServerName = sname;
        this->InboundDescription = description;
+       this->InboundSID = sid;
+
+       if (!sentcapab)
+               this->SendCapabilities();
 
        if (hops)
        {
@@ -879,9 +878,18 @@ bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
                        // we should add the details of this server now
                        // to the servers tree, as a child of the root
                        // node.
-                       TreeServer* Node = new TreeServer(this->Utils,this->Instance,sname,description,Utils->TreeRoot,this,x->Hidden);
+
+                       TreeServer *Node = new TreeServer(this->Utils, this->Instance, sname, description, sid, Utils->TreeRoot, this, x->Hidden);
+
+                       if (Node->DuplicateID())
+                       {
+                               this->SendError("Server ID "+sid+" already exists on the network!");
+                               this->Instance->SNO->WriteToSnoMask('l',"Server \2"+assign(servername)+"\2 being introduced denied, server ID already exists on the network. Closing link.");
+                               return false;
+                       }
+
                        Utils->TreeRoot->AddChild(Node);
-                       params[3] = ":" + params[3];
+                       params[4] = ":" + params[4];
                        Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,sname);
                        this->bursting = true;
                        this->DoBurst(Node);
@@ -895,16 +903,21 @@ bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
 
 bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
 {
-       if (params.size() < 4)
+       if (params.size() < 5)
                return false;
        irc::string servername = params[0].c_str();
        std::string sname = params[0];
        std::string password = params[1];
-       std::string description = params[3];
+       std::string sid = params[3];
+       std::string description = params[4];
        int hops = atoi(params[2].c_str());
 
        this->InboundServerName = sname;
        this->InboundDescription = description;
+       this->InboundSID = sid;
+
+       if (!sentcapab)
+               this->SendCapabilities();
 
        if (hops)
        {
@@ -927,10 +940,19 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
                                CheckDupeSocket->SendError("Negotiation collision");
                                Instance->SE->DelFd(CheckDupeSocket);
                                CheckDupeSocket->Close();
-                               delete CheckDupeSocket;
                                return false;
                        }
-                       /* Now check for fully initialized instances of the server */
+                       /* Check for fully initialized instances of the server by id */
+                       Instance->Log(DEBUG,"Looking for dupe SID %s", sid.c_str());
+                       TreeServer* CheckDupeSID = Utils->FindServerID(sid);
+                       if (CheckDupeSID)
+                       {
+                               this->SendError("Server ID "+CheckDupeSID->GetID()+" already exists on server "+CheckDupeSID->GetName()+"!");
+                               this->Instance->SNO->WriteToSnoMask('l',"Server connection from \2"+sname+"\2 denied, server ID '"+CheckDupeSID->GetID()+
+                                               "' already exists on server "+CheckDupeSID->GetName());
+                               return false;
+                       }
+                       /* Now check for fully initialized instances of the server by name */
                        TreeServer* CheckDupe = Utils->FindServer(sname);
                        if (CheckDupe)
                        {
@@ -949,7 +971,7 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
 
                        // this is good. Send our details: Our server name and description and hopcount of 0,
                        // along with the sendpass from this block.
-                       this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 :"+this->Instance->Config->ServerDesc);
+                       this->WriteLine(std::string("SERVER ")+this->Instance->Config->ServerName+" "+this->MakePass(x->SendPass, this->GetTheirChallenge())+" 0 "+Instance->Config->GetSID()+" :"+this->Instance->Config->ServerDesc);
                        // move to the next state, we are now waiting for THEM.
                        this->LinkState = WAIT_AUTH_2;
                        return true;
@@ -966,7 +988,10 @@ void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
        irc::tokenstream tokens(line);
        std::string param;
        while (tokens.GetToken(param))
-               n.push_back(param);
+       {
+               if (!param.empty())
+                       n.push_back(param);
+       }
        return;
 }
 
@@ -981,10 +1006,13 @@ bool TreeSocket::ProcessLine(std::string &line)
        if (line.empty())
                return true;
 
-       Instance->Log(DEBUG, "<- %s", line.c_str());
+       Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
 
        this->Split(line.c_str(),params);
-
+       
+       if (params.empty())
+               return true;
+       
        if ((params[0][0] == ':') && (params.size() > 1))
        {
                prefix = params[0].substr(1);
@@ -1023,11 +1051,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->Capab(params);
                        }
-                       else if ((command == "U") || (command == "S"))
-                       {
-                               this->SendError("Cannot use the old-style mesh linking protocol with m_spanningtree.so!");
-                               return false;
-                       }
                        else
                        {
                                irc::string error = "Invalid command in negotiation phase: " + command;
@@ -1044,11 +1067,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                                // silently ignore.
                                return true;
                        }
-                       else if ((command == "U") || (command == "S"))
-                       {
-                               this->SendError("Cannot use the old-style mesh linking protocol with m_spanningtree.so!");
-                               return false;
-                       }
                        else if (command == "BURST")
                        {
                                if (params.size() && Utils->EnableTimeSync)
@@ -1056,10 +1074,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        bool we_have_delta = (Instance->Time(false) != Instance->Time(true));
                                        time_t them = atoi(params[0].c_str());
                                        time_t delta = them - Instance->Time(false);
-                                       if ((delta < -300) || (delta > 300))
+                                       if ((delta < -600) || (delta > 600))
                                        {
                                                Instance->SNO->WriteToSnoMask('l',"\2ERROR\2: Your clocks are out by %d seconds (this is more than five minutes). Link aborted, \2PLEASE SYNC YOUR CLOCKS!\2",abs(delta));
-                                               SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than ten minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
+                                               SendError("Your clocks are out by "+ConvToStr(abs(delta))+" seconds (this is more than five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
                                                return false;
                                        }
                                        else if ((delta < -30) || (delta > 30))
@@ -1076,13 +1094,22 @@ bool TreeSocket::ProcessLine(std::string &line)
                                }
                                this->LinkState = CONNECTED;
                                Link* lnk = Utils->FindLink(InboundServerName);
-                               Node = new TreeServer(this->Utils,this->Instance, InboundServerName, InboundDescription, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
+
+                               Node = new TreeServer(this->Utils,this->Instance, InboundServerName, InboundDescription, InboundSID, Utils->TreeRoot, this, lnk ? lnk->Hidden : false);
+
+                               if (Node->DuplicateID())
+                               {
+                                       this->SendError("Server ID "+InboundSID+" already exists on the network!");
+                                       this->Instance->SNO->WriteToSnoMask('l',"Server \2"+InboundServerName+"\2 being introduced from \2" + prefix + "\2 denied, server ID already exists on the network. Closing link.");
+                                       return false;
+                               }
                                Utils->DelBurstingServer(this);
                                Utils->TreeRoot->AddChild(Node);
                                params.clear();
                                params.push_back(InboundServerName);
                                params.push_back("*");
                                params.push_back("1");
+                               params.push_back(InboundSID);
                                params.push_back(":"+InboundDescription);
                                Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,InboundServerName);
                                this->bursting = true;
@@ -1126,14 +1153,16 @@ bool TreeSocket::ProcessLine(std::string &line)
                        // have been exchanged and anything past this point is taken
                        // as gospel.
 
-                       if (prefix != "")
+                       if (!prefix.empty())
                        {
                                std::string direction = prefix;
-                               userrec* t = this->Instance->FindNick(prefix);
+
+                               userrec *t = this->Instance->FindUUID(prefix);
                                if (t)
                                {
                                        direction = t->server;
                                }
+
                                TreeServer* route_back_again = Utils->BestRouteTo(direction);
                                if ((!route_back_again) || (route_back_again->GetSocket() != this))
                                {
@@ -1145,9 +1174,13 @@ bool TreeSocket::ProcessLine(std::string &line)
                                 * When there is activity on the socket, reset the ping counter so
                                 * that we're not wasting bandwidth pinging an active server.
                                 */
-                               route_back_again->SetNextPingTime(time(NULL) + 60);
+                               route_back_again->SetNextPingTime(time(NULL) + Utils->PingFreq);
                                route_back_again->SetPingFlag();
                        }
+                       else
+                       {
+                               prefix = this->GetName();
+                       }
 
                        if ((command == "MODE") && (params.size() >= 2))
                        {
@@ -1175,16 +1208,19 @@ bool TreeSocket::ProcessLine(std::string &line)
                                 */
                                command = "MODE";
                        }
-                       std::string target = "";
+                       std::string target;
                        /* Yes, know, this is a mess. Its reasonably fast though as we're
                         * working with std::string here.
                         */
-                       if ((command == "NICK") && (params.size() >= 8))
+                       if (command == "UID")
                        {
-                               return this->IntroduceClient(prefix,params);
+                               return this->ParseUID(prefix, params);
                        }
                        else if (command == "FJOIN")
                        {
+                               TreeServer* ServerSource = Utils->FindServer(prefix);
+                               if (ServerSource)
+                                       Utils->SetRemoteBursting(ServerSource, false);
                                return this->ForceJoin(prefix,params);
                        }
                        else if (command == "STATS")
@@ -1195,6 +1231,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->Motd(prefix, params);
                        }
+                       else if (command == "KILL" && Utils->IsServer(prefix))
+                       {
+                               return this->RemoteKill(prefix,params);
+                       }
                        else if (command == "MODULES")
                        {
                                return this->Modules(prefix, params);
@@ -1217,12 +1257,11 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "FMODE")
                        {
+                               TreeServer* ServerSource = Utils->FindServer(prefix);
+                               if (ServerSource)
+                                       Utils->SetRemoteBursting(ServerSource, false);
                                return this->ForceMode(prefix,params);
                        }
-                       else if (command == "KILL")
-                       {
-                               return this->RemoteKill(prefix,params);
-                       }
                        else if (command == "FTOPIC")
                        {
                                return this->ForceTopic(prefix,params);
@@ -1241,40 +1280,46 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "PING")
                        {
+                               if (prefix.empty())
+                                       prefix = this->GetName();
                                /*
                                 * We just got a ping from a server that's bursting.
                                 * This can't be right, so set them to not bursting, and
                                 * apply their lines.
                                 */
+                               TreeServer* ServerSource = Utils->FindServer(prefix);
+                               if (ServerSource)
+                                       Utils->SetRemoteBursting(ServerSource, false);
+
                                if (this->bursting)
                                {
                                        this->bursting = false;
                                        Instance->XLines->apply_lines(Utils->lines_to_apply);
                                        Utils->lines_to_apply = 0;
                                }
-                               if (prefix == "")
-                               {
-                                       prefix = this->GetName();
-                               }
+
                                return this->LocalPing(prefix,params);
                        }
                        else if (command == "PONG")
                        {
+                               if (prefix.empty())
+                                       prefix = this->GetName();
                                /*
                                 * We just got a pong from a server that's bursting.
                                 * This can't be right, so set them to not bursting, and
                                 * apply their lines.
                                 */
+                               TreeServer* ServerSource = Utils->FindServer(prefix);
+                               if (ServerSource)
+                                       Utils->SetRemoteBursting(ServerSource, false);
+
                                if (this->bursting)
                                {
                                        this->bursting = false;
                                        Instance->XLines->apply_lines(Utils->lines_to_apply);
                                        Utils->lines_to_apply = 0;
                                }
-                               if (prefix == "")
-                               {
-                                       prefix = this->GetName();
-                               }
+
                                return this->LocalPong(prefix,params);
                        }
                        else if (command == "VERSION")
@@ -1291,11 +1336,14 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "ADDLINE")
                        {
+                               TreeServer* ServerSource = Utils->FindServer(prefix);
+                               if (ServerSource)
+                                       Utils->SetRemoteBursting(ServerSource, false);
                                return this->AddLine(prefix,params);
                        }
                        else if (command == "SVSNICK")
                        {
-                               if (prefix == "")
+                               if (prefix.empty())
                                {
                                        prefix = this->GetName();
                                }
@@ -1305,10 +1353,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                        {
                                return this->OperQuit(prefix,params);
                        }
-                       else if (command == "RSQUIT")
-                       {
-                               return this->RemoteSquit(prefix, params);
-                       }
                        else if (command == "IDLE")
                        {
                                return this->Whois(prefix,params);
@@ -1339,7 +1383,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                        delete chan;
                                        }
                                }
-                               if (this->InboundServerName != "")
+                               if (!this->InboundServerName.empty())
                                {
                                        sourceserv = this->InboundServerName;
                                }
@@ -1347,7 +1391,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "SVSJOIN")
                        {
-                               if (prefix == "")
+                               if (prefix.empty())
                                {
                                        prefix = this->GetName();
                                }
@@ -1364,7 +1408,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                        else if (command == "OPERNOTICE")
                        {
                                std::string sourceserv = this->myhost;
-                               if (this->InboundServerName != "")
+                               if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 1)
                                        Instance->WriteOpers("*** From " + sourceserv + ": " + params[0]);
@@ -1373,7 +1417,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                        else if (command == "MODENOTICE")
                        {
                                std::string sourceserv = this->myhost;
-                               if (this->InboundServerName != "")
+                               if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 2)
                                {
@@ -1384,7 +1428,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                        else if (command == "SNONOTICE")
                        {
                                std::string sourceserv = this->myhost;
-                               if (this->InboundServerName != "")
+                               if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 2)
                                {
@@ -1398,10 +1442,8 @@ bool TreeSocket::ProcessLine(std::string &line)
                                Instance->XLines->apply_lines(Utils->lines_to_apply);
                                Utils->lines_to_apply = 0;
                                std::string sourceserv = this->myhost;
-                               if (this->InboundServerName != "")
-                               {
+                               if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
-                               }
                                this->Instance->SNO->WriteToSnoMask('l',"Received end of netburst from \2%s\2",sourceserv.c_str());
 
                                Event rmode((char*)sourceserv.c_str(), (Module*)Utils->Creator, "new_server");
@@ -1411,12 +1453,14 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else
                        {
-                               // not a special inter-server command.
-                               // Emulate the actual user doing the command,
-                               // this saves us having a huge ugly parser.
-                               userrec* who = this->Instance->FindNick(prefix);
+                               /*
+                                * Not a special s2s command. Emulate the user doing it.
+                                * This saves us having a huge ugly command parser again.
+                                */
+                               userrec *who = this->Instance->FindUUID(prefix);
+
                                std::string sourceserv = this->myhost;
-                               if (this->InboundServerName != "")
+                               if (!this->InboundServerName.empty())
                                {
                                        sourceserv = this->InboundServerName;
                                }
@@ -1424,14 +1468,10 @@ bool TreeSocket::ProcessLine(std::string &line)
                                {
                                        if (Utils->IsServer(prefix))
                                        {
-                                               const char* modelist[127];
+                                               const char* modelist[MAXPARAMETERS];
                                                for (size_t i = 0; i < params.size(); i++)
                                                        modelist[i] = params[i].c_str();
-                                               userrec* fake = new userrec(Instance);
-                                               fake->SetFd(FD_MAGIC_NUMBER);
-                                               this->Instance->SendMode(modelist, params.size(), fake);
-
-                                               delete fake;
+                                               this->Instance->SendMode(modelist, params.size(), this->Instance->FakeClient);
                                                /* Hot potato! pass it on! */
                                                return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
                                        }
@@ -1444,16 +1484,33 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                 * already exist here. If it does, kill their copy,
                                                 * and our copy.
                                                 */
-                                               userrec* x = this->Instance->FindNick(params[0]);
+                                               userrec* x = this->Instance->FindNickOnly(params[0]);
                                                if ((x) && (x != who))
                                                {
+                                                       int collideret = 0;
+                                                       /* x is local, who is remote */
+                                                       collideret = this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
+                                                       if (collideret != 1)
+                                                       {
+                                                               /*
+                                                                * Remote client lost, or both lost,
+                                                                * parsing this nickchange would be
+                                                                * pointless, as the incoming client's
+                                                                * server will soon recieve SVSNICK to
+                                                                * change its nick to its UID. :)
+                                                                *   -- w00t
+                                                                */
+                                                               return true;
+                                                       }
+/*
+Old nickname collision logic..
                                                        std::deque<std::string> p;
                                                        p.push_back(params[0]);
-                                                       p.push_back("Nickname collision ("+prefix+" -> "+params[0]+")");
+                                                       p.push_back(":Nickname collision ("+prefix+" -> "+params[0]+")");
                                                        Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
                                                        p.clear();
                                                        p.push_back(prefix);
-                                                       p.push_back("Nickname collision");
+                                                       p.push_back(":Nickname collision");
                                                        Utils->DoOneToMany(this->Instance->Config->ServerName,"KILL",p);
                                                        userrec::QuitUser(this->Instance,x,"Nickname collision ("+prefix+" -> "+params[0]+")");
                                                        userrec* y = this->Instance->FindNick(prefix);
@@ -1462,6 +1519,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                                userrec::QuitUser(this->Instance,y,"Nickname collision");
                                                        }
                                                        return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
+*/
                                                }
                                        }
                                        // its a user
@@ -1505,7 +1563,7 @@ bool TreeSocket::ProcessLine(std::string &line)
 std::string TreeSocket::GetName()
 {
        std::string sourceserv = this->myhost;
-       if (this->InboundServerName != "")
+       if (!this->InboundServerName.empty())
        {
                sourceserv = this->InboundServerName;
        }
@@ -1516,7 +1574,7 @@ void TreeSocket::OnTimeout()
 {
        if (this->LinkState == CONNECTING)
        {
-               this->Instance->SNO->WriteToSnoMask('l',"CONNECT: Connection to \002"+myhost+"\002 timed out.");
+               Utils->Creator->RemoteMessage(NULL, "CONNECT: Connection to \002%s\002 timed out.", myhost.c_str());
                Link* MyLink = Utils->FindLink(myhost);
                if (MyLink)
                        Utils->DoFailOver(MyLink);
@@ -1525,11 +1583,14 @@ void TreeSocket::OnTimeout()
 
 void TreeSocket::OnClose()
 {
+       if (this->LinkState == LISTENER)
+               return;
+
        // 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 != "")
+       if (!this->InboundServerName.empty())
        {
                quitserver = this->InboundServerName;
        }
@@ -1539,8 +1600,13 @@ void TreeSocket::OnClose()
                Squit(s,"Remote host closed the connection");
        }
 
-       if (quitserver != "")
-               this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
+       if (!quitserver.empty())
+       {
+               Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
+               time_t server_uptime = Instance->Time() - this->age;    
+               if (server_uptime)
+                       Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+       }
 }
 
 int TreeSocket::OnIncomingConnection(int newsock, char* ip)
@@ -1560,7 +1626,7 @@ int TreeSocket::OnIncomingConnection(int newsock, char* ip)
 
                if (!found)
                {
-                       this->Instance->SNO->WriteToSnoMask('l',"Server connection from %s denied (no link blocks with that IP address)", ip);
+                       Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
                        close(newsock);
                        return false;
                }