]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Added the send_push event to m_spanningtree (send raw text to a remote user)
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index e4424a1b0f0e4658849a000fa34285bcadbe6903..7d034c17ce263f7986cb93d57f17af56223949c7 100644 (file)
@@ -100,6 +100,7 @@ class Link : public classbase
        std::string EncryptionKey;
        bool HiddenFromStats;
        std::string FailOver;
+       int Timeout;
 };
 
 /** Contains helper functions and variables for this module,
@@ -148,22 +149,22 @@ class SpanningTreeUtilities
        ~SpanningTreeUtilities();
        /** Send a message from this server to one other local or remote
         */
-       bool DoOneToOne(std::string prefix, std::string command, std::deque<std::string> &params, std::string target);
+       bool DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target);
        /** Send a message from this server to all but one other, local or remote
         */
-       bool DoOneToAllButSender(std::string prefix, std::string command, std::deque<std::string> &params, std::string omit);
+       bool DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit);
        /** Send a message from this server to all but one other, local or remote
         */
        bool DoOneToAllButSender(const char* prefix, const char* command, std::deque<std::string> &params, std::string omit);
        /** Send a message from this server to all others
         */
-       bool DoOneToMany(std::string prefix, std::string command, std::deque<std::string> &params);
+       bool DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params);
        /** Send a message from this server to all others
         */
        bool DoOneToMany(const char* prefix, const char* command, std::deque<std::string> &params);
        /** Send a message from this server to all others, without doing any processing on the command (e.g. send it as-is with colons and all)
         */
-       bool DoOneToAllButSenderRaw(std::string data, std::string omit, std::string prefix, irc::string command, std::deque<std::string> &params);
+       bool DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params);
        /** Read the spanningtree module's tags from the config file
         */
        void ReadConfiguration(bool rebind);
@@ -175,16 +176,16 @@ class SpanningTreeUtilities
        void GetListOfServersForChannel(chanrec* c, std::deque<TreeServer*> &list);
        /** Find a server by name
         */
-       TreeServer* FindServer(std::string ServerName);
+       TreeServer* FindServer(const std::string &ServerName);
        /** Find a route to a server by name
         */
-       TreeServer* BestRouteTo(std::string ServerName);
+       TreeServer* BestRouteTo(const std::string &ServerName);
        /** Find a server by glob mask
         */
-       TreeServer* FindServerMask(std::string ServerName);
+       TreeServer* FindServerMask(const std::string &ServerName);
        /** Returns true if this is a server name we recognise
         */
-       bool IsServer(std::string ServerName);
+       bool IsServer(const std::string &ServerName);
        /** Attempt to connect to the failover link of link x
         */
        void DoFailOver(Link* x);
@@ -247,7 +248,8 @@ class TreeServer : public classbase
        {
                Parent = NULL;
                VersionString = "";
-               UserCount = OperCount = 0;
+               UserCount = ServerInstance->UserCount();
+               OperCount = ServerInstance->OperCount();
                VersionString = ServerInstance->GetVersionString();
                Route = NULL;
                Socket = NULL; /* Fix by brain */
@@ -438,7 +440,7 @@ class TreeServer : public classbase
                return Parent;
        }
 
-       void SetVersion(std::string Version)
+       void SetVersion(const std::string &Version)
        {
                VersionString = Version;
        }
@@ -519,7 +521,7 @@ class TreeServer : public classbase
  * there are more than a few servers to deal with.
  * (read as: lots).
  */
-TreeServer* SpanningTreeUtilities::FindServer(std::string ServerName)
+TreeServer* SpanningTreeUtilities::FindServer(const std::string &ServerName)
 {
        server_hash::iterator iter;
        iter = serverlist.find(ServerName.c_str());
@@ -539,7 +541,7 @@ TreeServer* SpanningTreeUtilities::FindServer(std::string ServerName)
  * See the comments for the constructor of TreeServer
  * for more details.
  */
-TreeServer* SpanningTreeUtilities::BestRouteTo(std::string ServerName)
+TreeServer* SpanningTreeUtilities::BestRouteTo(const std::string &ServerName)
 {
        if (ServerName.c_str() == TreeRoot->GetName())
                return NULL;
@@ -560,7 +562,7 @@ TreeServer* SpanningTreeUtilities::BestRouteTo(std::string ServerName)
  * and match each one until we get a hit. Yes its slow,
  * deal with it.
  */
-TreeServer* SpanningTreeUtilities::FindServerMask(std::string ServerName)
+TreeServer* SpanningTreeUtilities::FindServerMask(const std::string &ServerName)
 {
        for (server_hash::iterator i = serverlist.begin(); i != serverlist.end(); i++)
        {
@@ -571,7 +573,7 @@ TreeServer* SpanningTreeUtilities::FindServerMask(std::string ServerName)
 }
 
 /* A convenient wrapper that returns true if a server exists */
-bool SpanningTreeUtilities::IsServer(std::string ServerName)
+bool SpanningTreeUtilities::IsServer(const std::string &ServerName)
 {
        return (FindServer(ServerName) != NULL);
 }
@@ -899,7 +901,7 @@ class TreeSocket : public InspSocket
                return result;
        }
 
-       bool Capab(std::deque<std::string> params)
+       bool Capab(const std::deque<std::string> &params)
        {
                if (params.size() < 1)
                {
@@ -1052,10 +1054,13 @@ class TreeSocket : public InspSocket
         * does some validation first and passes on the SQUIT to all
         * other remaining servers.
         */
-       void Squit(TreeServer* Current,std::string reason)
+       void Squit(TreeServer* Current, const std::string &reason)
        {
                if ((Current) && (Current != Utils->TreeRoot))
                {
+                       Event rmode((char*)Current->GetName().c_str(), (Module*)Utils->Creator, "lost_server");
+                       rmode.Send(Instance);
+
                        std::deque<std::string> params;
                        params.push_back(Current->GetName());
                        params.push_back(":"+reason);
@@ -1084,7 +1089,7 @@ class TreeSocket : public InspSocket
        }
 
        /** FMODE command - server mode with timestamp checks */
-       bool ForceMode(std::string source, std::deque<std::string> &params)
+       bool ForceMode(const std::string &source, std::deque<std::string> &params)
        {
                /* Chances are this is a 1.0 FMODE without TS */
                if (params.size() < 3)
@@ -1472,7 +1477,7 @@ class TreeSocket : public InspSocket
        }
 
        /** FTOPIC command */
-       bool ForceTopic(std::string source, std::deque<std::string> &params)
+       bool ForceTopic(const std::string &source, std::deque<std::string> &params)
        {
                if (params.size() != 4)
                        return true;
@@ -1516,7 +1521,7 @@ class TreeSocket : public InspSocket
        }
 
        /** FJOIN, similar to TS6 SJOIN, but not quite. */
-       bool ForceJoin(std::string source, std::deque<std::string> &params)
+       bool ForceJoin(const std::string &source, std::deque<std::string> &params)
        {
                /* 1.1 FJOIN works as follows:
                 *
@@ -1609,7 +1614,7 @@ class TreeSocket : public InspSocket
                        /* Lower the TS here */
                        if (Utils->AnnounceTSChange && chan)
                                chan->WriteChannelWithServ(Instance->Config->ServerName,
-                               "TS for %s changed from %lu to %lu", chan->name, ourTS, TS);
+                               "NOTICE %s :TS for %s changed from %lu to %lu", chan->name, chan->name, ourTS, TS);
                        ourTS = TS;
 
                        param_list.push_back(channel);
@@ -1794,7 +1799,7 @@ class TreeSocket : public InspSocket
        }
 
        /** NICK command */
-       bool IntroduceClient(std::string source, std::deque<std::string> &params)
+       bool IntroduceClient(const std::string &source, std::deque<std::string> &params)
        {
                if (params.size() < 8)
                        return true;
@@ -1874,6 +1879,8 @@ class TreeSocket : public InspSocket
         */
        void SendFJoins(TreeServer* Current, chanrec* c)
        {
+               std::string buffer;
+
                Instance->Log(DEBUG,"Sending FJOINs to other server for %s",c->name);
                char list[MAXBUF];
                std::string individual_halfops = std::string(":")+this->Instance->Config->ServerName+" FMODE "+c->name+" "+ConvToStr(c->age);
@@ -1899,7 +1906,8 @@ class TreeSocket : public InspSocket
 
                        if (curlen > (480-NICKMAX))
                        {
-                               this->WriteLine(list);
+                               buffer.append(list).append("\r\n");
+
                                dlen = curlen = snprintf(list,MAXBUF,":%s FJOIN %s %lu",this->Instance->Config->ServerName,c->name,(unsigned long)c->age);
                                ptr = list + dlen;
                                ptrlen = 0;
@@ -1908,64 +1916,83 @@ class TreeSocket : public InspSocket
                }
 
                if (numusers)
-                       this->WriteLine(list);
+                       buffer.append(list).append("\r\n");
 
-                for (BanList::iterator b = c->bans.begin(); b != c->bans.end(); b++)
-                {
+               for (BanList::iterator b = c->bans.begin(); b != c->bans.end(); b++)
+               {
                        modes.append("b");
-                       params.append(b->data).append(" ");
-                }
-               this->WriteLine(std::string(":")+this->Instance->Config->ServerName+" FMODE "+c->name+" "+ConvToStr(c->age)+" +"+c->ChanModes(true)+modes+" "+params);
+                       params.append(" ").append(b->data);
+
+                       if (params.length() >= MAXMODES)
+                       {
+                               /* Wrap at MAXMODES */
+                               buffer.append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params).append("\r\n");
+                               modes = "";
+                               params = "";
+                       }
+               }
+
+               buffer.append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(c->ChanModes(true));
+
+               /* Only send these if there are any */
+               if (!modes.empty())
+                       buffer.append("\r\n").append(":").append(this->Instance->Config->ServerName).append(" FMODE ").append(c->name).append(" ").append(ConvToStr(c->age)).append(" +").append(modes).append(params);
+
+               this->WriteLine(buffer);
        }
 
        /** Send G, Q, Z and E lines */
        void SendXLines(TreeServer* Current)
        {
                char data[MAXBUF];
+               std::string buffer;
                std::string n = this->Instance->Config->ServerName;
                const char* sn = n.c_str();
                int iterations = 0;
                /* Yes, these arent too nice looking, but they get the job done */
                for (std::vector<ZLine*>::iterator i = Instance->XLines->zlines.begin(); i != Instance->XLines->zlines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s\r\n",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<QLine*>::iterator i = Instance->XLines->qlines.begin(); i != Instance->XLines->qlines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s\r\n",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<GLine*>::iterator i = Instance->XLines->glines.begin(); i != Instance->XLines->glines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE G %s %s %lu %lu :%s",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE G %s %s %lu %lu :%s\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<ELine*>::iterator i = Instance->XLines->elines.begin(); i != Instance->XLines->elines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE E %s %s %lu %lu :%s",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE E %s %s %lu %lu :%s\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<ZLine*>::iterator i = Instance->XLines->pzlines.begin(); i != Instance->XLines->pzlines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE Z %s %s %lu %lu :%s\r\n",sn,(*i)->ipaddr,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<QLine*>::iterator i = Instance->XLines->pqlines.begin(); i != Instance->XLines->pqlines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE Q %s %s %lu %lu :%s\r\n",sn,(*i)->nick,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<GLine*>::iterator i = Instance->XLines->pglines.begin(); i != Instance->XLines->pglines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE G %s %s %lu %lu :%s",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE G %s %s %lu %lu :%s\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
                for (std::vector<ELine*>::iterator i = Instance->XLines->pelines.begin(); i != Instance->XLines->pelines.end(); i++, iterations++)
                {
-                       snprintf(data,MAXBUF,":%s ADDLINE E %s %s %lu %lu :%s",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
-                       this->WriteLine(data);
+                       snprintf(data,MAXBUF,":%s ADDLINE E %s %s %lu %lu :%s\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       buffer.append(data);
                }
+
+               if (!buffer.empty())
+                       this->WriteLine(buffer);
        }
 
        /** Send channel modes and topics */
@@ -1999,6 +2026,7 @@ class TreeSocket : public InspSocket
        {
                char data[MAXBUF];
                std::deque<std::string> list;
+               std::string dataline;
                int iterations = 0;
                for (user_hash::iterator u = this->Instance->clientlist.begin(); u != this->Instance->clientlist.end(); u++, iterations++)
                {
@@ -2008,11 +2036,13 @@ class TreeSocket : public InspSocket
                                this->WriteLine(data);
                                if (*u->second->oper)
                                {
-                                       this->WriteLine(":"+std::string(u->second->nick)+" OPERTYPE "+std::string(u->second->oper));
+                                       snprintf(data,MAXBUF,":%s OPERTYPE %s", u->second->nick, u->second->oper);
+                                       this->WriteLine(data);
                                }
                                if (*u->second->awaymsg)
                                {
-                                       this->WriteLine(":"+std::string(u->second->nick)+" AWAY :"+std::string(u->second->awaymsg));
+                                       snprintf(data,MAXBUF,":%s AWAY :%s", u->second->nick, u->second->awaymsg);
+                                       this->WriteLine(data);
                                }
                                FOREACH_MOD_I(this->Instance,I_OnSyncUser,OnSyncUser(u->second,(Module*)Utils->Creator,(void*)this));
                                list.clear();
@@ -2078,8 +2108,8 @@ class TreeSocket : public InspSocket
                                 * chance of the \r being near the end of the
                                 * string, not the start.
                                 */
-                               if (ret.rfind("\r") != std::string::npos)
-                                       ret = in_buffer.substr(0,in_buffer.rfind("\r")-1);
+                               if (ret.find("\r") != std::string::npos)
+                                       ret = in_buffer.substr(0,in_buffer.find("\r")-1);
                                /* Process this one, abort if it
                                 * didnt return true.
                                 */
@@ -2097,14 +2127,22 @@ class TreeSocket : public InspSocket
                                                {
                                                        ctx_in->Decrypt(out, result, nbytes, 0);
                                                        for (int t = 0; t < nbytes; t++)
-                                                               if (result[t] == '\7') result[t] = 0;
+                                                       {
+                                                               if (result[t] == '\7')
+                                                               {
+                                                                       /* We only need to stick a \0 on the
+                                                                        * first \7, the rest will be lost
+                                                                        */
+                                                                       result[t] = 0;
+                                                                       break;
+                                                               }
+                                                       }
                                                        ret = result;
                                                }
                                        }
                                }
                                if (!this->ProcessLine(ret))
                                {
-                                       Instance->Log(DEBUG,"ProcessLine says no!");
                                        return false;
                                }
                        }
@@ -2135,7 +2173,8 @@ class TreeSocket : public InspSocket
                        to64frombits((unsigned char*)result64,(unsigned char*)result,ll);
                        line = result64;
                }
-               return this->Write(line + "\r\n");
+               line.append("\r\n");
+               return this->Write(line);
        }
 
        /* Handle ERROR command */
@@ -2149,7 +2188,7 @@ class TreeSocket : public InspSocket
        }
 
        /** remote MOTD. leet, huh? */
-       bool Motd(std::string prefix, std::deque<std::string> &params)
+       bool Motd(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() > 0)
                {
@@ -2197,7 +2236,7 @@ class TreeSocket : public InspSocket
        }
 
        /** remote ADMIN. leet, huh? */
-       bool Admin(std::string prefix, std::deque<std::string> &params)
+       bool Admin(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() > 0)
                {
@@ -2237,7 +2276,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool Stats(std::string prefix, std::deque<std::string> &params)
+       bool Stats(const std::string &prefix, std::deque<std::string> &params)
        {
                /* Get the reply to a STATS query if it matches this servername,
                 * and send it back as a load of PUSH queries
@@ -2277,7 +2316,7 @@ class TreeSocket : public InspSocket
        /** Because the core won't let users or even SERVERS set +o,
         * we use the OPERTYPE command to do this.
         */
-       bool OperType(std::string prefix, std::deque<std::string> &params)
+       bool OperType(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() != 1)
                {
@@ -2298,7 +2337,7 @@ class TreeSocket : public InspSocket
        /** Because Andy insists that services-compatible servers must
         * implement SVSNICK and SVSJOIN, that's exactly what we do :p
         */
-       bool ForceNick(std::string prefix, std::deque<std::string> &params)
+       bool ForceNick(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 3)
                        return true;
@@ -2326,7 +2365,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool ServiceJoin(std::string prefix, std::deque<std::string> &params)
+       bool ServiceJoin(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 2)
                        return true;
@@ -2341,7 +2380,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool RemoteRehash(std::string prefix, std::deque<std::string> &params)
+       bool RemoteRehash(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return false;
@@ -2359,7 +2398,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool RemoteKill(std::string prefix, std::deque<std::string> &params)
+       bool RemoteKill(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() != 2)
                        return true;
@@ -2389,7 +2428,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool LocalPong(std::string prefix, std::deque<std::string> &params)
+       bool LocalPong(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2430,7 +2469,7 @@ class TreeSocket : public InspSocket
                return true;
        }
        
-       bool MetaData(std::string prefix, std::deque<std::string> &params)
+       bool MetaData(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 3)
                        return true;
@@ -2466,7 +2505,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool ServerVersion(std::string prefix, std::deque<std::string> &params)
+       bool ServerVersion(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2482,7 +2521,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool ChangeHost(std::string prefix, std::deque<std::string> &params)
+       bool ChangeHost(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2497,7 +2536,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool AddLine(std::string prefix, std::deque<std::string> &params)
+       bool AddLine(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 6)
                        return true;
@@ -2554,7 +2593,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool ChangeName(std::string prefix, std::deque<std::string> &params)
+       bool ChangeName(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2570,7 +2609,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool Whois(std::string prefix, std::deque<std::string> &params)
+       bool Whois(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2629,7 +2668,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool Push(std::string prefix, std::deque<std::string> &params)
+       bool Push(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 2)
                        return true;
@@ -2652,7 +2691,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool Time(std::string prefix, std::deque<std::string> &params)
+       bool Time(const std::string &prefix, std::deque<std::string> &params)
        {
                // :source.server TIME remote.server sendernick
                // :remote.server TIME source.server sendernick TS
@@ -2702,7 +2741,7 @@ class TreeSocket : public InspSocket
                return true;
        }
        
-       bool LocalPing(std::string prefix, std::deque<std::string> &params)
+       bool LocalPing(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2732,7 +2771,7 @@ class TreeSocket : public InspSocket
                }
        }
 
-       bool RemoveStatus(std::string prefix, std::deque<std::string> &params)
+       bool RemoveStatus(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 1)
                        return true;
@@ -2790,7 +2829,7 @@ class TreeSocket : public InspSocket
                return true;
        }
 
-       bool RemoteServer(std::string prefix, std::deque<std::string> &params)
+       bool RemoteServer(const std::string &prefix, std::deque<std::string> &params)
        {
                if (params.size() < 4)
                        return false;
@@ -2925,7 +2964,7 @@ class TreeSocket : public InspSocket
                return false;
        }
 
-       void Split(std::string line, std::deque<std::string> &n)
+       void Split(const std::string &line, std::deque<std::string> &n)
        {
                n.clear();
                irc::tokenstream tokens(line);
@@ -2935,7 +2974,7 @@ class TreeSocket : public InspSocket
                return;
        }
 
-       bool ProcessLine(std::string line)
+       bool ProcessLine(std::string &line)
        {
                std::deque<std::string> params;
                irc::string command;
@@ -3309,6 +3348,10 @@ class TreeSocket : public InspSocket
                                                sourceserv = this->InboundServerName;
                                        }
                                        this->Instance->SNO->WriteToSnoMask('l',"Received end of netburst from \2%s\2",sourceserv.c_str());
+
+                                       Event rmode((char*)sourceserv.c_str(), (Module*)Utils->Creator, "new_server");
+                                       rmode.Send(Instance);
+
                                        return true;
                                }
                                else
@@ -3429,7 +3472,9 @@ class TreeSocket : public InspSocket
                {
                        Squit(s,"Remote host closed the connection");
                }
-               this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
+
+               if (quitserver != "")
+                       this->Instance->SNO->WriteToSnoMask('l',"Connection to '\2%s\2' failed.",quitserver.c_str());
        }
 
        virtual int OnIncomingConnection(int newsock, char* ip)
@@ -3490,7 +3535,7 @@ class ServernameResolver : public Resolver
                TreeServer* CheckDupe = Utils->FindServer(MyLink.Name.c_str());
                if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
                {
-                       TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,10,MyLink.Name.c_str());
+                       TreeSocket* newsocket = new TreeSocket(this->Utils, ServerInstance, result,MyLink.Port,false,MyLink.Timeout ? MyLink.Timeout : 10,MyLink.Name.c_str());
                        if (newsocket->GetFd() > -1)
                        {
                                /* We're all OK */
@@ -3597,7 +3642,7 @@ void SpanningTreeUtilities::GetListOfServersForChannel(chanrec* c, std::deque<Tr
        return;
 }
 
-bool SpanningTreeUtilities::DoOneToAllButSenderRaw(std::string data, std::string omit, std::string prefix, irc::string command, std::deque<std::string> &params)
+bool SpanningTreeUtilities::DoOneToAllButSenderRaw(const std::string &data, const std::string &omit, const std::string &prefix, const irc::string &command, std::deque<std::string> &params)
 {
        TreeServer* omitroute = this->BestRouteTo(omit);
        if ((command == "NOTICE") || (command == "PRIVMSG"))
@@ -3665,7 +3710,7 @@ bool SpanningTreeUtilities::DoOneToAllButSenderRaw(std::string data, std::string
        return true;
 }
 
-bool SpanningTreeUtilities::DoOneToAllButSender(std::string prefix, std::string command, std::deque<std::string> &params, std::string omit)
+bool SpanningTreeUtilities::DoOneToAllButSender(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string omit)
 {
        TreeServer* omitroute = this->BestRouteTo(omit);
        std::string FullLine = ":" + prefix + " " + command;
@@ -3692,7 +3737,7 @@ bool SpanningTreeUtilities::DoOneToAllButSender(std::string prefix, std::string
        return true;
 }
 
-bool SpanningTreeUtilities::DoOneToMany(std::string prefix, std::string command, std::deque<std::string> &params)
+bool SpanningTreeUtilities::DoOneToMany(const std::string &prefix, const std::string &command, std::deque<std::string> &params)
 {
        std::string FullLine = ":" + prefix + " " + command;
        unsigned int words = params.size();
@@ -3728,7 +3773,7 @@ bool SpanningTreeUtilities::DoOneToAllButSender(const char* prefix, const char*
        return this->DoOneToAllButSender(spfx, scmd, params, omit);
 }
        
-bool SpanningTreeUtilities::DoOneToOne(std::string prefix, std::string command, std::deque<std::string> &params, std::string target)
+bool SpanningTreeUtilities::DoOneToOne(const std::string &prefix, const std::string &command, std::deque<std::string> &params, std::string target)
 {
        TreeServer* Route = this->BestRouteTo(target);
        if (Route)
@@ -3804,6 +3849,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
                L.AutoConnect = Conf->ReadInteger("link","autoconnect",j,true);
                L.EncryptionKey =  Conf->ReadValue("link","encryptionkey",j);
                L.HiddenFromStats = Conf->ReadFlag("link","hidden",j);
+               L.Timeout = Conf->ReadInteger("link","timeout",j,true);
                L.NextConnectTime = time(NULL) + L.AutoConnect;
                /* Bugfix by brain, do not allow people to enter bad configurations */
                if (L.Name != ServerInstance->Config->ServerName)
@@ -4260,7 +4306,7 @@ class ModuleSpanningTree : public Module
                /* Do we already have an IP? If so, no need to resolve it. */
                if (insp_aton(x->IPAddr.c_str(), &binip) > 0)
                {
-                       TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,10,x->Name.c_str());
+                       TreeSocket* newsocket = new TreeSocket(Utils, ServerInstance, x->IPAddr,x->Port,false,x->Timeout ? x->Timeout : 10,x->Name.c_str());
                        if (newsocket->GetFd() > -1)
                        {
                                /* Handled automatically on success */
@@ -4982,6 +5028,19 @@ class ModuleSpanningTree : public Module
                        params->insert(params->begin() + 1,ConvToStr(ourTS));
                        Utils->DoOneToMany(ServerInstance->Config->ServerName,"FMODE",*params);
                }
+               else if (event->GetEventID() == "send_push")
+               {
+                       if (params->size() < 2)
+                               return;
+                       
+                       userrec *a = ServerInstance->FindNick((*params)[0]);
+                       
+                       if (!a)
+                               return;
+                       
+                       (*params)[1] = ":" + (*params)[1];
+                       Utils->DoOneToOne(ServerInstance->Config->ServerName, "PUSH", *params, a->server);
+               }
        }
 
        virtual ~ModuleSpanningTree()