]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treesocket2.cpp
Remove the last uses of localised fake clients. This removes a lot of allocations...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treesocket2.cpp
index 067a972ae28346a1aada5fba69e28ac9f1ffebf7..1c6761ea1e986bfd4a23438605005dbda64eda7a 100644 (file)
@@ -799,10 +799,19 @@ 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);
-       Node->SetID(sid);
        params[4] = ":" + params[4];
        Utils->SetRemoteBursting(Node, true);
        Utils->DoOneToAllButSender(prefix,"SERVER",params,prefix);
@@ -873,10 +882,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[4] = ":" + params[4];
-                       Node->SetID(params[3]);
                        Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,sname);
                        this->bursting = true;
                        this->DoBurst(Node);
@@ -934,7 +951,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)
                        {
@@ -1076,7 +1103,15 @@ 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();
@@ -1085,7 +1120,6 @@ bool TreeSocket::ProcessLine(std::string &line)
                                params.push_back("1");
                                params.push_back(InboundSID);
                                params.push_back(":"+InboundDescription);
-                               Node->SetID(InboundSID);
                                Utils->DoOneToAllButSender(Utils->TreeRoot->GetName(),"SERVER",params,InboundServerName);
                                this->bursting = true;
                                this->DoBurst(Node);
@@ -1446,11 +1480,7 @@ 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);
                                        }
@@ -1466,6 +1496,11 @@ bool TreeSocket::ProcessLine(std::string &line)
                                                userrec* x = this->Instance->FindNick(params[0]);
                                                if ((x) && (x != who))
                                                {
+                                                       /* x is local, who is remote */
+                                                       this->DoCollision(x, who->age, who->ident, who->GetIPString(), who->uuid);
+                                                       return true;
+/*
+Old nickname collision logic..
                                                        std::deque<std::string> p;
                                                        p.push_back(params[0]);
                                                        p.push_back(":Nickname collision ("+prefix+" -> "+params[0]+")");
@@ -1481,6 +1516,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