]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
Use XLineFactory in ADDLINE, so that it can deal with anything the rest of the ircd...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index a321ee36b6d8f83084724c9a3c0289674d72ca65..b214e01add5b5510a02e7c73c220d174d60b0c0f 100644 (file)
  */
 
 #include "inspircd.h"
-#include "configreader.h"
-#include "users.h"
-#include "channels.h"
-#include "modules.h"
 #include "commands/cmd_whois.h"
 #include "commands/cmd_stats.h"
 #include "socket.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[%d] -> %s", this->GetFd(), line.c_str());
+       Instance->Log(DEBUG, "S[%d] O %s", this->GetFd(), line.c_str());
        line.append("\r\n");
        return this->Write(line);
 }
@@ -71,13 +67,13 @@ bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> &par
        par.push_back(prefix);
        par.push_back("");
 
-       userrec* source = this->Instance->FindNick(prefix);
+       User* source = this->Instance->FindNick(prefix);
        if (!source)
                return true;
 
        for (unsigned int i = 0; i < Instance->Config->module_names.size(); i++)
        {
-               Version V = Instance->modules[i]->GetVersion();
+               Version V = Instance->Modules->modules[i]->GetVersion();
                char modulename[MAXBUF];
                char flagstate[MAXBUF];
                *flagstate = 0;
@@ -94,18 +90,18 @@ bool TreeSocket::Modules(const std::string &prefix, std::deque<std::string> &par
                strlcpy(modulename,Instance->Config->module_names[i].c_str(),256);
                if (*source->oper)
                {
-                       snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(long unsigned int)Instance->modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2);
+                       snprintf(strbuf, MAXBUF, "::%s 900 %s :0x%08lx %d.%d.%d.%d %s (%s)",Instance->Config->ServerName,source->nick,(long unsigned int)Instance->Modules->modules[i],V.Major,V.Minor,V.Revision,V.Build,ServerConfig::CleanFilename(modulename),flagstate+2);
                }
                else
                {
                        snprintf(strbuf, MAXBUF, "::%s 900 %s :%s",Instance->Config->ServerName,source->nick,ServerConfig::CleanFilename(modulename));
                }
                par[1] = strbuf;
-               Utils->DoOneToOne(Instance->Config->ServerName, "PUSH", par, source->server);
+               Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
        }
        snprintf(strbuf, MAXBUF, "::%s 901 %s :End of MODULES list", Instance->Config->ServerName, source->nick);
        par[1] = strbuf;
-       Utils->DoOneToOne(Instance->Config->ServerName, "PUSH", par, source->server);
+       Utils->DoOneToOne(Instance->Config->GetSID(), "PUSH", par, source->server);
        return true;
 }
 
@@ -118,7 +114,7 @@ bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> &params
                {
                        /* It's for our server */
                        string_list results;
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
 
                        if (source)
                        {
@@ -129,27 +125,27 @@ bool TreeSocket::Motd(const std::string &prefix, std::deque<std::string> &params
                                if (!Instance->Config->MOTD.size())
                                {
                                        par[1] = std::string("::")+Instance->Config->ServerName+" 422 "+source->nick+" :Message of the day file is missing.";
-                                       Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                        return true;
                                }
 
                                par[1] = std::string("::")+Instance->Config->ServerName+" 375 "+source->nick+" :"+Instance->Config->ServerName+" message of the day";
-                               Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
 
                                for (unsigned int i = 0; i < Instance->Config->MOTD.size(); i++)
                                {
                                        par[1] = std::string("::")+Instance->Config->ServerName+" 372 "+source->nick+" :- "+Instance->Config->MOTD[i];
-                                       Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                }
 
-                               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);
+                               par[1] = std::string("::")+Instance->Config->ServerName+" 376 "+source->nick+" :End of message of the day.";
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                        }
                }
                else
                {
                        /* Pass it on */
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
                        if (source)
                                Utils->DoOneToOne(prefix, "MOTD", params, params[0]);
                }
@@ -166,26 +162,26 @@ bool TreeSocket::Admin(const std::string &prefix, std::deque<std::string> &param
                {
                        /* It's for our server */
                        string_list results;
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
                        if (source)
                        {
                                std::deque<std::string> par;
                                par.push_back(prefix);
                                par.push_back("");
                                par[1] = std::string("::")+Instance->Config->ServerName+" 256 "+source->nick+" :Administrative info for "+Instance->Config->ServerName;
-                               Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                par[1] = std::string("::")+Instance->Config->ServerName+" 257 "+source->nick+" :Name     - "+Instance->Config->AdminName;
-                               Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :Nickname - "+Instance->Config->AdminNick;
-                               Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                par[1] = std::string("::")+Instance->Config->ServerName+" 258 "+source->nick+" :E-Mail   - "+Instance->Config->AdminEmail;
-                               Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                        }
                }
                else
                {
                        /* Pass it on */
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
                        if (source)
                                Utils->DoOneToOne(prefix, "ADMIN", params, params[0]);
                }
@@ -204,7 +200,7 @@ bool TreeSocket::Stats(const std::string &prefix, std::deque<std::string> &param
                {
                        /* It's for our server */
                        string_list results;
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
                        if (source)
                        {
                                std::deque<std::string> par;
@@ -214,16 +210,16 @@ bool TreeSocket::Stats(const std::string &prefix, std::deque<std::string> &param
                                for (size_t i = 0; i < results.size(); i++)
                                {
                                        par[1] = "::" + results[i];
-                                       Utils->DoOneToOne(this->Instance->Config->ServerName, "PUSH",par, source->server);
+                                       Utils->DoOneToOne(this->Instance->Config->GetSID(), "PUSH",par, source->server);
                                }
                        }
                }
                else
                {
                        /* Pass it on */
-                       userrec* source = this->Instance->FindNick(prefix);
+                       User* source = this->Instance->FindNick(prefix);
                        if (source)
-                               Utils->DoOneToOne(prefix, "STATS", params, params[1]);
+                               Utils->DoOneToOne(source->uuid, "STATS", params, params[1]);
                }
        }
        return true;
@@ -238,14 +234,36 @@ bool TreeSocket::OperType(const std::string &prefix, std::deque<std::string> &pa
        if (params.size() != 1)
                return true;
        std::string opertype = params[0];
-       userrec* u = this->Instance->FindNick(prefix);
+       User* u = this->Instance->FindNick(prefix);
        if (u)
        {
+               if (!u->IsModeSet('o'))
+                       this->Instance->all_opers.push_back(u);
                u->modes[UM_OPERATOR] = 1;
-               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;
 }
@@ -258,23 +276,31 @@ bool TreeSocket::ForceNick(const std::string &prefix, std::deque<std::string> &p
        if (params.size() < 3)
                return true;
 
-       userrec* u = this->Instance->FindNick(params[0]);
+       User* u = this->Instance->FindNick(params[0]);
 
        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))
+                               {
+                                       User::QuitUser(this->Instance, u, "Nickname collision");
+                                       return true;
+                               }
                        }
+
                        u->age = atoi(params[2].c_str());
                }
        }
+
        return true;
 }
 
@@ -283,7 +309,7 @@ bool TreeSocket::OperQuit(const std::string &prefix, std::deque<std::string> &pa
        if (params.size() < 1)
                return true;
 
-       userrec* u = this->Instance->FindNick(prefix);
+       User* u = this->Instance->FindNick(prefix);
 
        if (u)
        {
@@ -299,18 +325,44 @@ bool TreeSocket::ServiceJoin(const std::string &prefix, std::deque<std::string>
        if (params.size() < 2)
                return true;
 
-       userrec* u = this->Instance->FindNick(params[0]);
+       if (!this->Instance->IsChannel(params[1].c_str()))
+               return true;
+
+       User* u = this->Instance->FindNick(params[0]);
 
        if (u)
        {
                /* only join if it's local, otherwise just pass it on! */
                if (IS_LOCAL(u))
-                       chanrec::JoinUser(this->Instance, u, params[1].c_str(), false, "", Instance->Time());
+                       Channel::JoinUser(this->Instance, u, params[1].c_str(), false, "", Instance->Time());
                Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
        }
        return true;
 }
 
+bool TreeSocket::ServicePart(const std::string &prefix, std::deque<std::string> &params)
+{
+       if (params.size() < 2)
+               return true;
+
+       if (!this->Instance->IsChannel(params[1].c_str()))
+               return true;
+
+       User* u = this->Instance->FindNick(params[0]);
+       Channel* c = this->Instance->FindChan(params[1]);
+
+       if (u)
+       {
+               /* only part if it's local, otherwise just pass it on! */
+               if (IS_LOCAL(u))
+                       if (!c->PartUser(u, "Services forced part"))
+                               delete c;
+               Utils->DoOneToAllButSender(prefix,"SVSPART",params,prefix);
+       }
+
+       return true;
+}
+
 bool TreeSocket::RemoteRehash(const std::string &prefix, std::deque<std::string> &params)
 {
        if (params.size() < 1)
@@ -334,7 +386,7 @@ bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> &
        if (params.size() != 2)
                return true;
 
-       userrec* who = this->Instance->FindNick(params[0]);
+       User* who = this->Instance->FindNick(params[0]);
 
        if (who)
        {
@@ -349,7 +401,7 @@ bool TreeSocket::RemoteKill(const std::string &prefix, std::deque<std::string> &
                // 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);
+               User::QuitUser(this->Instance,who,reason);
        }
        return true;
 }
@@ -365,13 +417,16 @@ 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
        {
                std::string forwardto = params[1];
-               if (forwardto == this->Instance->Config->ServerName)
+               if (forwardto == Instance->Config->GetSID() || forwardto == Instance->Config->ServerName)
                {
                        /*
                         * this is a PONG for us
@@ -379,7 +434,7 @@ bool TreeSocket::LocalPong(const std::string &prefix, std::deque<std::string> &p
                         * dump the PONG reply back to their fd. If its a server, do nowt.
                         * Services might want to send these s->s, but we dont need to yet.
                         */
-                       userrec* u = this->Instance->FindNick(prefix);
+                       User* u = this->Instance->FindNick(prefix);
                        if (u)
                        {
                                u->WriteServ("PONG %s %s",params[0].c_str(),params[1].c_str());
@@ -412,7 +467,7 @@ bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> &pa
                }
                else if (*(params[0].c_str()) == '#')
                {
-                       chanrec* c = this->Instance->FindChan(params[0]);
+                       Channel* c = this->Instance->FindChan(params[0]);
                        if (c)
                        {
                                FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_CHANNEL,c,params[1],params[2]));
@@ -420,7 +475,7 @@ bool TreeSocket::MetaData(const std::string &prefix, std::deque<std::string> &pa
                }
                else if (*(params[0].c_str()) != '#')
                {
-                       userrec* u = this->Instance->FindNick(params[0]);
+                       User* u = this->Instance->FindNick(params[0]);
                        if (u)
                        {
                                FOREACH_MOD_I(this->Instance,I_OnDecodeMetaData,OnDecodeMetaData(TYPE_USER,u,params[1],params[2]));
@@ -453,7 +508,7 @@ bool TreeSocket::ChangeHost(const std::string &prefix, std::deque<std::string> &
 {
        if (params.size() < 1)
                return true;
-       userrec* u = this->Instance->FindNick(prefix);
+       User* u = this->Instance->FindNick(prefix);
 
        if (u)
        {
@@ -467,51 +522,19 @@ bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> &par
 {
        if (params.size() < 6)
                return true;
-       bool propogate = false;
-       if (!this->bursting)
-               Utils->lines_to_apply = 0;
-       switch (*(params[0].c_str()))
-       {
-               case 'Z':
-                       propogate = Instance->XLines->add_zline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-                       Instance->XLines->zline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
-                       if (propogate)
-                               Utils->lines_to_apply |= APPLY_ZLINES;
-               break;
-               case 'Q':
-                       propogate = Instance->XLines->add_qline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-                       Instance->XLines->qline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
-                       if (propogate)
-                               Utils->lines_to_apply |= APPLY_QLINES;
-               break;
-               case 'E':
-                       propogate = Instance->XLines->add_eline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-                       Instance->XLines->eline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
-               break;
-               case 'G':
-                       propogate = Instance->XLines->add_gline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-                       Instance->XLines->gline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));
-                       if (propogate)
-                               Utils->lines_to_apply |= APPLY_GLINES;
-               break;
-               case 'K':
-                       propogate = Instance->XLines->add_kline(atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
-                       if (propogate)
-                               Utils->lines_to_apply |= APPLY_KLINES;
-               break;
-               default:
-                       /* Just in case... */
-                       this->Instance->SNO->WriteToSnoMask('x',"\2WARNING\2: Invalid xline type '"+params[0]+"' sent by server "+prefix+", ignored!");
-                       propogate = false;
-               break;
-       }
-       /* Send it on its way */
-       if (propogate)
+
+       XLineFactory* xlf = Instance->XLines->GetFactory(params[0][0]);
+
+       if (!xlf)
+               return false;
+
+       XLine* xl = xlf->Generate(Instance->Time(), atoi(params[4].c_str()), params[2].c_str(), params[5].c_str(), params[1].c_str());
+       if (Instance->XLines->AddLine(xl,NULL))
        {
-               if (atoi(params[4].c_str()))
+               /*Instance->XLines->zline_set_creation_time(params[1].c_str(), atoi(params[3].c_str()));*/
+               if (xl->expiry)
                {
-                       time_t c_requires_crap = ConvToInt(params[4]) + Instance->Time();
-                       this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(c_requires_crap).c_str(),params[5].c_str());
+                       this->Instance->SNO->WriteToSnoMask('x',"%s Added %cLINE on %s to expire on %s (%s).",prefix.c_str(),*(params[0].c_str()),params[1].c_str(),Instance->TimeString(xl->expiry).c_str(),params[5].c_str());
                }
                else
                {
@@ -520,11 +543,14 @@ bool TreeSocket::AddLine(const std::string &prefix, std::deque<std::string> &par
                params[5] = ":" + params[5];
                Utils->DoOneToAllButSender(prefix,"ADDLINE",params,prefix);
        }
+       else
+               delete xl;
+
        if (!this->bursting)
        {
-               Instance->XLines->apply_lines(Utils->lines_to_apply);
-               Utils->lines_to_apply = 0;
+               Instance->XLines->ApplyLines();
        }
+
        return true;
 }
 
@@ -532,7 +558,7 @@ bool TreeSocket::ChangeName(const std::string &prefix, std::deque<std::string> &
 {
        if (params.size() < 1)
                return true;
-       userrec* u = this->Instance->FindNick(prefix);
+       User* u = this->Instance->FindNick(prefix);
        if (u)
        {
                u->ChangeName(params[0].c_str());
@@ -546,16 +572,16 @@ bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &param
 {
        if (params.size() < 1)
                return true;
-       userrec* u = this->Instance->FindNick(prefix);
+       User* u = this->Instance->FindNick(prefix);
        if (u)
        {
                // an incoming request
                if (params.size() == 1)
                {
-                       userrec* x = this->Instance->FindNick(params[0]);
+                       User* x = this->Instance->FindNick(params[0]);
                        if ((x) && (IS_LOCAL(x)))
                        {
-                               userrec* x = this->Instance->FindNick(params[0]);
+                               User* x = this->Instance->FindNick(params[0]);
                                char signon[MAXBUF];
                                char idle[MAXBUF];
                                snprintf(signon, MAXBUF, "%lu", (unsigned long)x->signon);
@@ -577,7 +603,7 @@ bool TreeSocket::Whois(const std::string &prefix, std::deque<std::string> &param
                else if (params.size() == 3)
                {
                        std::string who_did_the_whois = params[0];
-                       userrec* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
+                       User* who_to_send_to = this->Instance->FindNick(who_did_the_whois);
                        if ((who_to_send_to) && (IS_LOCAL(who_to_send_to)))
                        {
                                // an incoming reply to a whois we sent out
@@ -604,7 +630,7 @@ bool TreeSocket::Push(const std::string &prefix, std::deque<std::string> &params
 {
        if (params.size() < 2)
                return true;
-       userrec* u = this->Instance->FindNick(params[0]);
+       User* u = this->Instance->FindNick(params[0]);
        if (!u)
                return true;
        if (IS_LOCAL(u))
@@ -653,20 +679,20 @@ bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params
        if (params.size() == 2)
        {
                // someone querying our time?
-               if (this->Instance->Config->ServerName == params[0])
+               if (this->Instance->Config->ServerName == params[0] || this->Instance->Config->GetSID() == params[0])
                {
-                       userrec* u = this->Instance->FindNick(params[1]);
+                       User* u = this->Instance->FindNick(params[1]);
                        if (u)
                        {
                                params.push_back(ConvToStr(Instance->Time(false)));
                                params[0] = prefix;
-                               Utils->DoOneToOne(this->Instance->Config->ServerName,"TIME",params,params[0]);
+                               Utils->DoOneToOne(this->Instance->Config->GetSID(),"TIME",params,params[0]);
                        }
                }
                else
                {
                        // not us, pass it on
-                       userrec* u = this->Instance->FindNick(params[1]);
+                       User* u = this->Instance->FindNick(params[1]);
                        if (u)
                                Utils->DoOneToOne(prefix,"TIME",params,params[0]);
                }
@@ -674,7 +700,7 @@ bool TreeSocket::Time(const std::string &prefix, std::deque<std::string> &params
        else if (params.size() == 3)
        {
                // a response to a previous TIME
-               userrec* u = this->Instance->FindNick(params[1]);
+               User* u = this->Instance->FindNick(params[1]);
                if ((u) && (IS_LOCAL(u)))
                {
                        time_t rawtime = atol(params[2].c_str());
@@ -701,13 +727,13 @@ bool TreeSocket::LocalPing(const std::string &prefix, std::deque<std::string> &p
        if (params.size() == 1)
        {
                std::string stufftobounce = params[0];
-               this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" PONG "+stufftobounce);
+               this->WriteLine(std::string(":")+this->Instance->Config->GetSID()+" PONG "+stufftobounce);
                return true;
        }
        else
        {
                std::string forwardto = params[1];
-               if (forwardto == this->Instance->Config->ServerName)
+               if (forwardto == this->Instance->Config->ServerName || forwardto == this->Instance->Config->GetSID())
                {
                        // this is a ping for us, send back PONG to the requesting server
                        params[1] = params[0];
@@ -729,7 +755,7 @@ bool TreeSocket::RemoveStatus(const std::string &prefix, std::deque<std::string>
 {
        if (params.size() < 1)
                return true;
-       chanrec* c = Instance->FindChan(params[0]);
+       Channel* c = Instance->FindChan(params[0]);
        if (c)
        {
                for (char modeletter = 'A'; modeletter <= 'z'; modeletter++)
@@ -744,18 +770,28 @@ 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)
+       {
+               SendError("Protocol error - Missing SID");
                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)
        {
                this->SendError("Protocol error - Introduced remote server from unknown server "+prefix);
                return false;
        }
+       if (!Utils->IsSID(sid))
+       {
+               this->SendError("Invalid format server ID: "+sid+"!");
+               return false;
+       }
        TreeServer* CheckDupe = Utils->FindServer(servername);
        if (CheckDupe)
        {
@@ -763,10 +799,20 @@ 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+")");
@@ -780,7 +826,7 @@ bool TreeSocket::ComparePass(const std::string &ours, const std::string &theirs)
                /* One or both of us specified hmac sha256, but we don't have sha256 module loaded!
                 * We can't allow this password as valid.
                 */
-               if (!Instance->FindModule("m_sha256.so") || !Utils->ChallengeResponse)
+               if (!Instance->Modules->Find("m_sha256.so") || !Utils->ChallengeResponse)
                                return false;
                else
                        /* Straight string compare of hashes */
@@ -793,17 +839,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)
+       {
+               SendError("Protocol error - Missing SID");
                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();
@@ -815,6 +866,12 @@ bool TreeSocket::Outbound_Reply_Server(std::deque<std::string> &params)
                return false;
        }
 
+       if (!Utils->IsSID(sid))
+       {
+               this->SendError("Invalid format server ID: "+sid+"!");
+               return false;
+       }
+
        for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
        {
                if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password)) || (x->RecvPass == password && (this->GetTheirChallenge().empty()))))
@@ -834,10 +891,19 @@ 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];
-                       Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,sname);
+                       params[4] = ":" + params[4];
+                       Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,sname);
                        this->bursting = true;
                        this->DoBurst(Node);
                        return true;
@@ -850,16 +916,22 @@ 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)
+       {
+               SendError("Protocol error - Missing SID");
                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();
@@ -871,6 +943,12 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
                return false;
        }
 
+       if (!Utils->IsSID(sid))
+       {
+               this->SendError("Invalid format server ID: "+sid+"!");
+               return false;
+       }
+
        for (std::vector<Link>::iterator x = Utils->LinkBlocks.begin(); x < Utils->LinkBlocks.end(); x++)
        {
                if ((x->Name == servername) && ((ComparePass(this->MakePass(x->RecvPass,this->GetOurChallenge()),password) || x->RecvPass == password && (this->GetTheirChallenge().empty()))))
@@ -887,7 +965,17 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
                                CheckDupeSocket->Close();
                                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)
                        {
@@ -898,7 +986,7 @@ bool TreeSocket::Inbound_Server(std::deque<std::string> &params)
                        this->Instance->SNO->WriteToSnoMask('l',"Verified incoming server connection from \002"+sname+"\002["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] ("+description+")");
                        if (this->Hook)
                        {
-                               std::string name = InspSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
+                               std::string name = BufferedSocketNameRequest((Module*)Utils->Creator, this->Hook).Send();
                                this->Instance->SNO->WriteToSnoMask('l',"Connection from \2"+sname+"\2["+(x->HiddenFromStats ? "<hidden>" : this->GetIP())+"] using transport \2"+name+"\2");
                        }
 
@@ -906,7 +994,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;
@@ -924,8 +1012,7 @@ void TreeSocket::Split(const std::string &line, std::deque<std::string> &n)
        std::string param;
        while (tokens.GetToken(param))
        {
-               if (!param.empty())
-                       n.push_back(param);
+               n.push_back(param);
        }
        return;
 }
@@ -941,7 +1028,7 @@ bool TreeSocket::ProcessLine(std::string &line)
        if (line.empty())
                return true;
 
-       Instance->Log(DEBUG, "S[%d] <- %s", this->GetFd(), line.c_str());
+       Instance->Log(DEBUG, "S[%d] I %s", this->GetFd(), line.c_str());
 
        this->Split(line.c_str(),params);
        
@@ -986,11 +1073,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;
@@ -1007,11 +1089,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)
@@ -1019,7 +1096,7 @@ 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 five minutes). Link aborted, PLEASE SYNC YOUR CLOCKS!");
@@ -1034,20 +1111,29 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        {
                                                this->Instance->SetTimeDelta(delta);
                                                // Send this new timestamp to any other servers
-                                               Utils->DoOneToMany(Utils->TreeRoot->GetName(), "TIMESET", params);
+                                               Utils->DoOneToMany(Instance->Config->GetSID(), "TIMESET", params);
                                        }
                                }
                                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);
+                               Utils->DoOneToAllButSender(Instance->Config->GetSID(),"SERVER",params,InboundServerName);
                                this->bursting = true;
                                this->DoBurst(Node);
                        }
@@ -1092,11 +1178,13 @@ bool TreeSocket::ProcessLine(std::string &line)
                        if (!prefix.empty())
                        {
                                std::string direction = prefix;
-                               userrec* t = this->Instance->FindNick(prefix);
+
+                               User *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))
                                {
@@ -1108,20 +1196,24 @@ 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();
+                               TreeServer* n = Utils->FindServer(GetName());
+                               if (n)
+                                       prefix = n->GetID();
+                               else
+                                       prefix = GetName();
                        }
 
                        if ((command == "MODE") && (params.size() >= 2))
                        {
-                               chanrec* channel = Instance->FindChan(params[0]);
+                               Channel* channel = Instance->FindChan(params[0]);
                                if (channel)
                                {
-                                       userrec* x = Instance->FindNick(prefix);
+                                       User* x = Instance->FindNick(prefix);
                                        if (x)
                                        {
                                                if (warned.find(x->server) == warned.end())
@@ -1146,9 +1238,9 @@ bool TreeSocket::ProcessLine(std::string &line)
                        /* 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")
                        {
@@ -1214,8 +1306,6 @@ 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
@@ -1228,16 +1318,13 @@ bool TreeSocket::ProcessLine(std::string &line)
                                if (this->bursting)
                                {
                                        this->bursting = false;
-                                       Instance->XLines->apply_lines(Utils->lines_to_apply);
-                                       Utils->lines_to_apply = 0;
+                                       Instance->XLines->ApplyLines();
                                }
 
                                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
@@ -1250,8 +1337,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                if (this->bursting)
                                {
                                        this->bursting = false;
-                                       Instance->XLines->apply_lines(Utils->lines_to_apply);
-                                       Utils->lines_to_apply = 0;
+                                       Instance->XLines->ApplyLines();
                                }
 
                                return this->LocalPong(prefix,params);
@@ -1277,10 +1363,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "SVSNICK")
                        {
-                               if (prefix.empty())
-                               {
-                                       prefix = this->GetName();
-                               }
                                return this->ForceNick(prefix,params);
                        }
                        else if (command == "OPERQUIT")
@@ -1308,8 +1390,8 @@ bool TreeSocket::ProcessLine(std::string &line)
                                std::string sourceserv = this->myhost;
                                if (params.size() == 3)
                                {
-                                       userrec* user = this->Instance->FindNick(params[1]);
-                                       chanrec* chan = this->Instance->FindChan(params[0]);
+                                       User* user = this->Instance->FindNick(params[1]);
+                                       Channel* chan = this->Instance->FindChan(params[0]);
                                        if (user && chan)
                                        {
                                                if (!chan->ServerKickUser(user, params[2].c_str(), false))
@@ -1325,12 +1407,12 @@ bool TreeSocket::ProcessLine(std::string &line)
                        }
                        else if (command == "SVSJOIN")
                        {
-                               if (prefix.empty())
-                               {
-                                       prefix = this->GetName();
-                               }
                                return this->ServiceJoin(prefix,params);
                        }
+                       else if (command == "SVSPART")
+                       {
+                               return this->ServicePart(prefix,params);
+                       }
                        else if (command == "SQUIT")
                        {
                                if (params.size() == 2)
@@ -1345,7 +1427,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 1)
-                                       Instance->WriteOpers("*** From " + sourceserv + ": " + params[0]);
+                                       Instance->WriteOpers("*** From " + prefix + ": " + params[0]);
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
                        else if (command == "MODENOTICE")
@@ -1355,7 +1437,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 2)
                                {
-                                       Instance->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", sourceserv.c_str(), params[1].c_str());
+                                       Instance->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", prefix.c_str(), params[1].c_str());
                                }
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
@@ -1366,15 +1448,14 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        sourceserv = this->InboundServerName;
                                if (params.size() >= 2)
                                {
-                                       Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + sourceserv + ": "+ params[1]);
+                                       Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + prefix + ": "+ params[1]);
                                }
                                return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
                        }
                        else if (command == "ENDBURST")
                        {
                                this->bursting = false;
-                               Instance->XLines->apply_lines(Utils->lines_to_apply);
-                               Utils->lines_to_apply = 0;
+                               Instance->XLines->ApplyLines();
                                std::string sourceserv = this->myhost;
                                if (!this->InboundServerName.empty())
                                        sourceserv = this->InboundServerName;
@@ -1387,10 +1468,12 @@ 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.
+                                */
+                               User *who = this->Instance->FindUUID(prefix);
+
                                std::string sourceserv = this->myhost;
                                if (!this->InboundServerName.empty())
                                {
@@ -1403,41 +1486,63 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                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);
                                        }
                                }
                                if (who)
                                {
-                                       if ((command == "NICK") && (params.size() > 0))
+                                       if (command == "NICK")
                                        {
+                                               if (params.size() != 2)
+                                               {
+                                                       SendError("Protocol violation: NICK message without TS - :"+std::string(who->uuid)+" NICK "+params[0]);
+                                                       return false;
+                                               }
+                                               /* Update timestamp on user when they change nicks */
+                                               who->age = atoi(params[1].c_str());
+
                                                /* On nick messages, check that the nick doesnt
                                                 * already exist here. If it does, kill their copy,
                                                 * and our copy.
                                                 */
-                                               userrec* x = this->Instance->FindNick(params[0]);
+                                               User* 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);
+                                                       User::QuitUser(this->Instance,x,"Nickname collision ("+prefix+" -> "+params[0]+")");
+                                                       User* y = this->Instance->FindNick(prefix);
                                                        if (y)
                                                        {
-                                                               userrec::QuitUser(this->Instance,y,"Nickname collision");
+                                                               User::QuitUser(this->Instance,y,"Nickname collision");
                                                        }
                                                        return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
+*/
                                                }
                                        }
                                        // its a user
@@ -1450,7 +1555,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                        switch (this->Instance->CallCommandHandler(command.c_str(), strparams, params.size(), who))
                                        {
                                                case CMD_INVALID:
-                                                       this->SendError("Unrecognised command '"+std::string(command.c_str())+"' -- possibly loaded mismatched modules");
+                                                       this->SendError("Unrecognised or malformed command '"+std::string(command.c_str())+"' -- possibly loaded mismatched modules");
                                                        return false;
                                                break;
                                                case CMD_FAILURE:
@@ -1465,7 +1570,7 @@ bool TreeSocket::ProcessLine(std::string &line)
                                {
                                        // its not a user. Its either a server, or somethings screwed up.
                                        if (Utils->IsServer(prefix))
-                                               target = this->Instance->Config->ServerName;
+                                               target = this->Instance->Config->GetSID();
                                        else
                                                return true;
                                }
@@ -1492,7 +1597,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);
@@ -1520,10 +1625,10 @@ void TreeSocket::OnClose()
 
        if (!quitserver.empty())
        {
-               this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
+               Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' failed.",quitserver.c_str());
                time_t server_uptime = Instance->Time() - this->age;    
                if (server_uptime)
-                       Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
+                       Utils->Creator->RemoteMessage(NULL,"Connection to '\2%s\2' was established for %s", quitserver.c_str(), Utils->Creator->TimeToStr(server_uptime).c_str());
        }
 }
 
@@ -1544,8 +1649,8 @@ 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);
-                       close(newsock);
+                       Utils->Creator->RemoteMessage(NULL,"Server connection from %s denied (no link blocks with that IP address)", ip);
+                       Instance->SE->Close(newsock);
                        return false;
                }
        }