]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Moved some stuff to debug
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index c4867200e2cd61dee9a20d45c76e3852d6c5f213..edfef803981dfb5a625611fe20bd2acd2aa248da 100644 (file)
@@ -162,6 +162,26 @@ class TreeServer
                }
                return false;
        }
+
+       // removes child nodes of this node, and of that node, etc etc
+       bool Tidy()
+       {
+               bool stillchildren = true;
+               while (stillchildren)
+               {
+                       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;
+                       }
+               }
+               return true;
+       }
 };
 
 class Link
@@ -351,6 +371,60 @@ class TreeSocket : public InspSocket
                }
        }
 
+       void SquitServer(TreeServer* Current)
+       {
+               // recursively squit the servers attached to 'Current'
+               for (unsigned int q = 0; q < Current->ChildCount(); q++)
+               {
+                       TreeServer* recursive_server = Current->GetChild(q);
+                       this->SquitServer(recursive_server);
+               }
+               // Now we've whacked the kids, whack self
+               log(DEBUG,"Deleted %s",Current->GetName().c_str());
+               bool quittingpeople = true;
+               while (quittingpeople)
+               {
+                       quittingpeople = false;
+                       for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
+                       {
+                               if (!strcasecmp(u->second->server,Current->GetName().c_str()))
+                               {
+                                       log(DEBUG,"Quitting user %s of server %s",u->second->nick,u->second->server);
+                                       Srv->QuitUser(u->second,Current->GetName()+" "+std::string(Srv->GetServerName()));
+                                       quittingpeople = true;
+                                       break;
+                               }
+                       }
+               }
+       }
+
+       void Squit(TreeServer* Current,std::string reason)
+       {
+               if (Current)
+               {
+                       std::deque<std::string> params;
+                       params.push_back(Current->GetName());
+                       params.push_back(":"+reason);
+                       DoOneToAllButSender(Current->GetParent()->GetName(),"SQUIT",params,Current->GetName());
+                       if (Current->GetParent() == TreeRoot)
+                       {
+                               Srv->SendOpers("Server \002"+Current->GetName()+"\002 SQUIT: "+reason);
+                       }
+                       else
+                       {
+                               Srv->SendOpers("Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason);
+                       }
+                       SquitServer(Current);
+                       Current->Tidy();
+                       Current->GetParent()->DelChild(Current);
+                       delete Current;
+               }
+               else
+               {
+                       log(DEBUG,"Squit from unknown server");
+               }
+       }
+
        bool ForceJoin(std::string source, std::deque<std::string> params)
        {
                if (params.size() < 1)
@@ -548,7 +622,7 @@ class TreeSocket : public InspSocket
                TreeServer* Node = new TreeServer(servername,description,ParentOfThis,NULL);
                ParentOfThis->AddChild(Node);
                DoOneToAllButSender(prefix,"SERVER",params,prefix);
-               Srv->SendOpers("*** Server "+prefix+" introduced server "+servername+" ("+description+")");
+               Srv->SendOpers("*** Server \002"+prefix+"\002 introduced server \002"+servername+"\002 ("+description+")");
                return true;
        }
 
@@ -579,7 +653,7 @@ class TreeSocket : public InspSocket
                                // node.
                                TreeServer* Node = new TreeServer(servername,description,TreeRoot,this);
                                TreeRoot->AddChild(Node);
-                               DoOneToAllButSender(servername,"SERVER",params,servername);
+                               DoOneToAllButSender(TreeRoot->GetName(),"SERVER",params,servername);
                                this->DoBurst(Node);
                                return true;
                        }
@@ -605,7 +679,7 @@ class TreeSocket : public InspSocket
                {
                        if ((x->Name == servername) && (x->RecvPass == password))
                        {
-                               Srv->SendOpers("*** Verified incoming server connection from "+servername+"["+this->GetIP()+"] ("+description+")");
+                               Srv->SendOpers("*** Verified incoming server connection from \002"+servername+"\002["+this->GetIP()+"] ("+description+")");
                                this->InboundServerName = servername;
                                this->InboundDescription = description;
                                // this is good. Send our details: Our server name and description and hopcount of 0,
@@ -654,7 +728,7 @@ class TreeSocket : public InspSocket
 
        bool ProcessLine(std::string line)
        {
-               Srv->SendToModeMask("o",WM_AND,"inbound-line: '"+line+"'");
+               Srv->Log(DEBUG,"inbound-line: '"+line+"'");
 
                std::deque<std::string> params = this->Split(line);
                std::string command = "";
@@ -708,7 +782,12 @@ class TreeSocket : public InspSocket
                                        this->LinkState = CONNECTED;
                                        Node = new TreeServer(InboundServerName,InboundDescription,TreeRoot,this);
                                        TreeRoot->AddChild(Node);
-                                       DoOneToAllButSender(InboundServerName,"SERVER",params,InboundServerName);
+                                       params.clear();
+                                       params.push_back(InboundServerName);
+                                       params.push_back("*");
+                                       params.push_back("1");
+                                       params.push_back(InboundDescription);
+                                       DoOneToAllButSender(TreeRoot->GetName(),"SERVER",params,InboundServerName);
                                        this->DoBurst(Node);
                                }
                                else if (command == "ERROR")
@@ -749,6 +828,14 @@ class TreeSocket : public InspSocket
                                {
                                        return this->RemoteServer(prefix,params);
                                }
+                               else if (command == "SQUIT")
+                               {
+                                       if (params.size() == 2)
+                                       {
+                                               this->Squit(FindServer(params[0]),params[1]);
+                                       }
+                                       return true;
+                               }
                                else
                                {
                                        // not a special inter-server command.
@@ -798,12 +885,29 @@ class TreeSocket : public InspSocket
        {
                if (this->LinkState == CONNECTING)
                {
-                       Srv->SendOpers("*** CONNECT: Connection to "+myhost+" timed out.");
+                       Srv->SendOpers("*** CONNECT: Connection to \002"+myhost+"\002 timed out.");
                }
        }
 
        virtual void OnClose()
        {
+               // 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 != "")
+               {
+                       quitserver = this->InboundServerName;
+               }
+               TreeServer* s = FindServer(quitserver);
+               if (s)
+               {
+                       std::deque<std::string> params;
+                       params.push_back(quitserver);
+                       params.push_back(":Remote host closed the connection");
+                       DoOneToAllButSender(Srv->GetServerName(),"SQUIT",params,quitserver);
+                       Squit(s,"Remote host closed the connection");
+               }
        }
 
        virtual int OnIncomingConnection(int newsock, char* ip)
@@ -1009,7 +1113,7 @@ class ModuleSpanningTree : public Module
                char matrix[128][80];
                for (unsigned int t = 0; t < 128; t++)
                {
-                       matrix[line][0] = '\0';
+                       matrix[t][0] = '\0';
                }
                line = 0;
                // The only recursive bit is called here.