]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/treeserver.cpp
Clean up duplicated link snomask messages on errors
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / treeserver.cpp
index 95f6866988be14306ad97ea6aca97bf2d5408e65..060c958d7ee04be40da73432cfb8061599af9f2e 100644 (file)
@@ -14,7 +14,8 @@
 #include "inspircd.h"
 #include "socket.h"
 #include "xline.h"
-#include "../transport.h"
+#include "main.h"
+#include "../spanningtree.h"
 
 #include "utils.h"
 #include "treeserver.h"
@@ -26,7 +27,7 @@
  * no socket associated with it. Its version string is our own local version.
  */
 TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id)
-                                               : ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util)
+       : ServerName(Name.c_str()), ServerDesc(Desc), Utils(Util), ServerUser(ServerInstance->FakeClient)
 {
        age = ServerInstance->Time();
        bursting = false;
@@ -47,7 +48,7 @@ TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::strin
  * its ping counters so that it will be pinged one minute from now.
  */
 TreeServer::TreeServer(SpanningTreeUtilities* Util, std::string Name, std::string Desc, const std::string &id, TreeServer* Above, TreeSocket* Sock, bool Hide)
-       : Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), Hidden(Hide)
+       : Parent(Above), ServerName(Name.c_str()), ServerDesc(Desc), Socket(Sock), Utils(Util), ServerUser(new FakeUser(id, Name)), Hidden(Hide)
 {
        age = ServerInstance->Time();
        bursting = true;
@@ -147,8 +148,7 @@ void TreeServer::FinishBurst()
        unsigned long bursttime = ts - this->StartBurst;
        ServerInstance->SNO->WriteToSnoMask(Parent == Utils->TreeRoot ? 'l' : 'L', "Received end of netburst from \2%s\2 (burst time: %lu %s)",
                ServerName.c_str(), (bursttime > 10000 ? bursttime / 1000 : bursttime), (bursttime > 10000 ? "secs" : "msecs"));
-       Event rmode((char*)ServerName.c_str(),  (Module*)Utils->Creator, "new_server");
-       rmode.Send();
+       AddServerEvent(Utils->Creator, ServerName.c_str());
 }
 
 void TreeServer::SetID(const std::string &id)
@@ -333,27 +333,32 @@ bool TreeServer::DelChild(TreeServer* Child)
  */
 bool TreeServer::Tidy()
 {
-       bool stillchildren = true;
-       while (stillchildren)
+       while (1)
        {
-               stillchildren = false;
-               for (std::vector<TreeServer*>::iterator a = Children.begin(); a != Children.end(); a++)
-               {
-                       TreeServer* s = (TreeServer*)*a;
-                       s->Tidy();
-                       Children.erase(a);
-                       delete s;
-                       stillchildren = true;
-                       break;
-               }
+               std::vector<TreeServer*>::iterator a = Children.begin();
+               if (a == Children.end())
+                       return true;
+               TreeServer* s = *a;
+               s->Tidy();
+               s->cull();
+               Children.erase(a);
+               delete s;
        }
-       return true;
+}
+
+CullResult TreeServer::cull()
+{
+       if (ServerUser != ServerInstance->FakeClient)
+               ServerUser->cull();
+       return classbase::cull();
 }
 
 TreeServer::~TreeServer()
 {
        /* We'd better tidy up after ourselves, eh? */
        this->DelHashEntry();
+       if (ServerUser != ServerInstance->FakeClient)
+               delete ServerUser;
 
        server_hash::iterator iter = Utils->sidlist.find(GetID());
        if (iter != Utils->sidlist.end())