]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Changed to strchr
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index a6db47bf5e9663e351b0680e96bd145b9d6cc2b4..bf50b463b7584832ec584858c9d75617f32354ce 100644 (file)
@@ -47,10 +47,6 @@ enum ServerState { LISTENER, CONNECTING, WAIT_AUTH_1, WAIT_AUTH_2, CONNECTED };
 typedef nspace::hash_map<std::string, userrec*, nspace::hash<string>, irc::StrHashComp> user_hash;
 extern user_hash clientlist;
 
-const char* OneToEither[] = { "PRIVMSG", "NOTICE", NULL };
-const char* OneToMany[] = { "NICK", "QUIT", "JOIN", "PART", "MODE", "INVITE", "KICK", "KILL", NULL };
-const char* OneToOne[] = { "REHASH", "DIE", "TRACE", "WHOIS", NULL };
-
 class TreeServer;
 class TreeSocket;
 
@@ -68,7 +64,6 @@ class TreeServer
        int UserCount;
        int OperCount;
        TreeSocket* Socket;     // for directly connected servers this points at the socket object
-       bool Deleted;
        
  public:
 
@@ -79,7 +74,6 @@ class TreeServer
                ServerDesc = "";
                VersionString = "";
                UserCount = OperCount = 0;
-               Deleted = false;
        }
 
        TreeServer(std::string Name, std::string Desc) : ServerName(Name), ServerDesc(Desc)
@@ -87,14 +81,12 @@ class TreeServer
                Parent = NULL;
                VersionString = "";
                UserCount = OperCount = 0;
-               Deleted = false;
        }
 
        TreeServer(std::string Name, std::string Desc, TreeServer* Above, TreeSocket* Sock) : Parent(Above), ServerName(Name), ServerDesc(Desc), Socket(Sock)
        {
                VersionString = "";
                UserCount = OperCount = 0;
-               Deleted = false;
        }
 
        std::string GetName()
@@ -149,11 +141,6 @@ class TreeServer
                }
        }
 
-       void MarkDeleted()
-       {
-               this->Deleted = true;
-       }
-
        void AddChild(TreeServer* Child)
        {
                Children.push_back(Child);
@@ -181,14 +168,15 @@ class TreeServer
                        stillchildren = false;
                        for (std::vector<TreeServer*>::iterator a = Children.begin(); a < Children.end(); a++)
                        {
-                               TreeServer*a = (TreeServer*)*a;
-                               a->Tidy();
+                               TreeServer* s = (TreeServer*)*a;
+                               s->Tidy();
                                Children.erase(a);
-                               delete a;
+                               delete s;
                                stillchildren = true;
                                break;
                        }
                }
+               return true;
        }
 };
 
@@ -304,6 +292,8 @@ class TreeSocket : public InspSocket
        ServerState LinkState;
        std::string InboundServerName;
        std::string InboundDescription;
+       int num_lost_users;
+       int num_lost_servers;
        
  public:
 
@@ -388,8 +378,8 @@ class TreeSocket : public InspSocket
                        this->SquitServer(recursive_server);
                }
                // Now we've whacked the kids, whack self
-               this->MarkDeleted();
-               log(DEBUG,"Deleted %s",Current->GetName());
+               log(DEBUG,"Deleted %s",Current->GetName().c_str());
+               num_lost_servers++;
                bool quittingpeople = true;
                while (quittingpeople)
                {
@@ -398,7 +388,9 @@ class TreeSocket : public InspSocket
                        {
                                if (!strcasecmp(u->second->server,Current->GetName().c_str()))
                                {
-                                       Srv->QuitUser(u,Current->GetName()+" "+std::string(Srv->GetServerName()));
+                                       log(DEBUG,"Quitting user %s of server %s",u->second->nick,u->second->server);
+                                       Srv->QuitUser(u->second,Current->GetName()+" "+std::string(Srv->GetServerName()));
+                                       num_lost_users++;
                                        quittingpeople = true;
                                        break;
                                }
@@ -406,11 +398,34 @@ class TreeSocket : public InspSocket
                }
        }
 
-       void Squit(TreeServer* Current)
+       void Squit(TreeServer* Current,std::string reason)
        {
-               SquitServer(Current);
-               Current->Tidy();
-               Current->GetParent()->DelChild(Current);
+               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 split: "+reason);
+                       }
+                       else
+                       {
+                               Srv->SendOpers("Server \002"+Current->GetName()+"\002 split from server \002"+Current->GetParent()->GetName()+"\002 with reason: "+reason);
+                       }
+                       num_lost_servers = 0;
+                       num_lost_users = 0;
+                       SquitServer(Current);
+                       Current->Tidy();
+                       Current->GetParent()->DelChild(Current);
+                       delete Current;
+                       WriteOpers("Netsplit complete, lost \002%d\002 users on \002%d\002 servers.", num_lost_users, num_lost_servers);
+               }
+               else
+               {
+                       log(DEBUG,"Squit from unknown server");
+               }
        }
 
        bool ForceJoin(std::string source, std::deque<std::string> params)
@@ -610,7 +625,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;
        }
 
@@ -667,7 +682,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,
@@ -716,7 +731,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 = "";
@@ -816,6 +831,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.
@@ -865,7 +888,7 @@ 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.");
                }
        }
 
@@ -884,13 +907,9 @@ class TreeSocket : public InspSocket
                {
                        std::deque<std::string> params;
                        params.push_back(quitserver);
-                       params.push_back(":Remote host closed the connection");
+                       params.push_back("Remote host closed the connection");
                        DoOneToAllButSender(Srv->GetServerName(),"SQUIT",params,quitserver);
-                       Squit(s);
-               }
-               else
-               {
-                       log(DEBUG,"SQUIT from unknown server %s",quitserver.c_str());
+                       Squit(s,"Remote host closed the connection");
                }
        }
 
@@ -909,7 +928,14 @@ bool DoOneToAllButSender(std::string prefix, std::string command, std::deque<std
        std::string FullLine = ":" + prefix + " " + command;
        for (unsigned int x = 0; x < params.size(); x++)
        {
-               FullLine = FullLine + " " + params[x];
+               if (!strchr(params[x].c_str(),' '))
+               {
+                       FullLine = FullLine + " " + params[x];
+               }
+               else
+               {
+                       FullLine = FullLine + " :" + params[x];
+               }
        }
        for (unsigned int x = 0; x < TreeRoot->ChildCount(); x++)
        {
@@ -933,7 +959,14 @@ bool DoOneToMany(std::string prefix, std::string command, std::deque<std::string
        std::string FullLine = ":" + prefix + " " + command;
        for (unsigned int x = 0; x < params.size(); x++)
        {
-               FullLine = FullLine + " " + params[x];
+               if (!strchr(params[x].c_str(),' '))
+               {
+                       FullLine = FullLine + " " + params[x];
+               }
+               else
+               {
+                       FullLine = FullLine + " :" + params[x];
+               }
        }
        for (unsigned int x = 0; x < TreeRoot->ChildCount(); x++)
        {
@@ -955,7 +988,14 @@ bool DoOneToOne(std::string prefix, std::string command, std::deque<std::string>
                std::string FullLine = ":" + prefix + " " + command;
                for (unsigned int x = 0; x < params.size(); x++)
                {
-                       FullLine = FullLine + " " + params[x];
+                       if (!strchr(params[x].c_str(),' '))
+                       {
+                               FullLine = FullLine + " " + params[x];
+                       }
+                       else
+                       {
+                               FullLine = FullLine + " :" + params[x];
+                       }
                }
                if (Route->GetSocket())
                {
@@ -1202,10 +1242,21 @@ class ModuleSpanningTree : public Module
                                std::deque<std::string> params;
                                params.clear();
                                params.push_back(d->nick);
-                               params.push_back(":"+text);
+                               params.push_back(text);
                                DoOneToOne(user->nick,"PRIVMSG",params,d->server);
                        }
                }
+               else
+               {
+                       if (std::string(user->server) == Srv->GetServerName())
+                       {
+                               chanrec *c = (chanrec*)dest;
+                               std::deque<std::string> params;
+                               params.push_back(c->name);
+                               params.push_back(text);
+                               DoOneToMany(user->nick,"PRIVMSG",params);
+                       }
+               }
        }
 
        virtual void OnUserJoin(userrec* user, chanrec* channel)