]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Cache channel max bans value to save an O(n) loop of match() on every ban (etc) add
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index 497c577f78375b58d678d5c55ec122b07de15a21..871675ed6afc65d03c0ed822de801aa82ca9cf92 100644 (file)
@@ -1653,9 +1653,13 @@ class TreeSocket : public InspSocket
                        ourTS = TS;
 
                        /* Zap all the privilage modes on our side, if the channel exists here */
-                       param_list.push_back(channel);
-                       this->RemoveStatus(Instance->Config->ServerName, param_list);
-                       chan->age = TS;
+                       if (!created)
+                       {
+                               param_list.push_back(channel);
+                               /* Do this first! */
+                               chan->age = TS;
+                               this->RemoveStatus(Instance->Config->ServerName, param_list);
+                       }
                }
 
                /* Put the final parameter of the FJOIN into a tokenstream ready to split it */
@@ -1862,13 +1866,6 @@ class TreeSocket : public InspSocket
                //       0    1   2     3     4      5   6     7
                time_t age = atoi(params[0].c_str());
                
-               /* This used to have a pretty craq'y loop doing the same thing,
-                * now we just let the STL do the hard work (more efficiently)
-                */
-               std::string::size_type pos_after_plus = params[5].find_first_not_of('+');
-               if (pos_after_plus != std::string::npos)
-                       params[5] = params[5].substr(pos_after_plus);
-               
                const char* tempnick = params[1].c_str();
                Instance->Log(DEBUG,"Introduce client %s!%s@%s",tempnick,params[4].c_str(),params[2].c_str());
                
@@ -1895,8 +1892,25 @@ class TreeSocket : public InspSocket
                _new->registered = REG_ALL;
                _new->signon = age;
                
+               /*
+                * we need to remove the + from the modestring, so we can do our stuff
+                */
+               std::string::size_type pos_after_plus = params[5].find_first_not_of('+');
+               if (pos_after_plus != std::string::npos)
+                       params[5] = params[5].substr(pos_after_plus);
+               
+
                for (std::string::iterator v = params[5].begin(); v != params[5].end(); v++)
+               {
                        _new->modes[(*v)-65] = 1;
+                       /* For each mode thats set, increase counter */
+                       ModeHandler* mh = Instance->Modes->FindMode(*v, MODETYPE_USER);
+                       if (mh)
+                               mh->ChangeCount(1);
+               }
+
+               /* now we've done with modes processing, put the + back for remote servers */
+               params[5] = "+" + params[5];
 
 #ifdef SUPPORT_IP6LINKS
                if (params[6].find_first_of(":") != std::string::npos)
@@ -1910,7 +1924,7 @@ class TreeSocket : public InspSocket
                this->Instance->SNO->WriteToSnoMask('C',"Client connecting at %s: %s!%s@%s [%s]",_new->server,_new->nick,_new->ident,_new->host, _new->GetIPString());
 
                params[7] = ":" + params[7];
-               Utils->DoOneToAllButSender(source,"NICK",params,source);
+               Utils->DoOneToAllButSender(source,"NICK", params, source);
 
                // Increment the Source Servers User Count..
                TreeServer* SourceServer = Utils->FindServer(source);
@@ -2353,6 +2367,7 @@ class TreeSocket : public InspSocket
                if (u)
                {
                        u->modes[UM_OPERATOR] = 1;
+                       this->Instance->all_opers.push_back(u);
                        strlcpy(u->oper,opertype.c_str(),NICKMAX-1);
                        Utils->DoOneToAllButSender(u->nick,"OPERTYPE",params,u->server);
                        this->Instance->SNO->WriteToSnoMask('o',"From %s: User %s (%s@%s) is now an IRC operator of type %s",u->server, u->nick,u->ident,u->host,irc::Spacify(opertype.c_str()));
@@ -2449,7 +2464,9 @@ class TreeSocket : public InspSocket
 
                if (u)
                {
-                       chanrec::JoinUser(this->Instance, u, params[1].c_str(), false);
+                       /* only join if it's local, otherwise just pass it on! */
+                       if (IS_LOCAL(u))
+                               chanrec::JoinUser(this->Instance, u, params[1].c_str(), false);
                        Utils->DoOneToAllButSender(prefix,"SVSJOIN",params,prefix);
                }
                return true;
@@ -2464,7 +2481,7 @@ class TreeSocket : public InspSocket
 
                if (this->Instance->MatchText(this->Instance->Config->ServerName,servermask))
                {
-                       this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated from server \002"+prefix+"\002.");
+                       this->Instance->SNO->WriteToSnoMask('l',"Remote rehash initiated by \002"+prefix+"\002.");
                        this->Instance->RehashServer();
                        Utils->ReadConfiguration(false);
                        InitializeDisabledCommands(Instance->Config->DisabledCommands, Instance);
@@ -2924,8 +2941,7 @@ class TreeSocket : public InspSocket
                                Instance->Log(DEBUG,"Stacked line size %d",stackresult.size());
                                stackresult.push_front(ConvToStr(c->age));
                                stackresult.push_front(c->name);
-                               // dont echo this out, at best its just going to be bounced back -- Brain
-                               //Utils->DoOneToMany(Instance->Config->ServerName, "FMODE", stackresult);
+                               Utils->DoOneToMany(Instance->Config->ServerName, "FMODE", stackresult);
                                stackresult.erase(stackresult.begin() + 1);
                                Instance->Log(DEBUG,"Stacked items:");
                                for (size_t z = 0; z < stackresult.size(); z++)
@@ -3698,12 +3714,12 @@ class ServernameResolver : public Resolver
        Link MyLink;
        SpanningTreeUtilities* Utils;
  public: 
-       ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(Util)
+       ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), MyLink(x), Utils(Util)
        {
                /* Nothing in here, folks */
        }
 
-       void OnLookupComplete(const std::string &result)
+       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
        {
                /* Initiate the connection, now that we have an IP to use.
                 * Passing a hostname directly to InspSocket causes it to
@@ -3748,11 +3764,11 @@ class SecurityIPResolver : public Resolver
        Link MyLink;
        SpanningTreeUtilities* Utils;
  public:
-       SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(U)
+       SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x, bool &cached) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, cached, me), MyLink(x), Utils(U)
        {
        }
 
-       void OnLookupComplete(const std::string &result)
+       void OnLookupComplete(const std::string &result, unsigned int ttl, bool cached)
        {
                ServerInstance->Log(DEBUG,"Security IP cache: Adding IP address '%s' for Link '%s'",result.c_str(),MyLink.Name.c_str());
                Utils->ValidIPs.push_back(result);
@@ -4106,8 +4122,9 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
                                {
                                        try
                                        {
-                                               SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L);
-                                               ServerInstance->AddResolver(sr);
+                                               bool cached;
+                                               SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L, cached);
+                                               ServerInstance->AddResolver(sr, cached);
                                        }
                                        catch (ModuleException& e)
                                        {
@@ -4637,8 +4654,9 @@ class ModuleSpanningTree : public Module
                {
                        try
                        {
-                               ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x);
-                               ServerInstance->AddResolver(snr);
+                               bool cached;
+                               ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x, cached);
+                               ServerInstance->AddResolver(snr, cached);
                        }
                        catch (ModuleException& e)
                        {
@@ -5125,21 +5143,22 @@ class ModuleSpanningTree : public Module
                Utils->DoOneToMany(source->nick,"KILL",params);
        }
 
-       virtual void OnRehash(const std::string &parameter)
+       virtual void OnRehash(userrec* user, const std::string &parameter)
        {
                if (parameter != "")
                {
                        std::deque<std::string> params;
                        params.push_back(parameter);
-                       Utils->DoOneToMany(ServerInstance->Config->ServerName,"REHASH",params);
+                       Utils->DoOneToMany(user ? user->nick : ServerInstance->Config->ServerName, "REHASH", params);
                        // check for self
                        if (ServerInstance->MatchText(ServerInstance->Config->ServerName,parameter))
                        {
-                               ServerInstance->WriteOpers("*** Remote rehash initiated from server \002%s\002",ServerInstance->Config->ServerName);
+                               ServerInstance->WriteOpers("*** Remote rehash initiated locally by \002%s\002", user ? user->nick : ServerInstance->Config->ServerName);
                                ServerInstance->RehashServer();
                        }
                }
                Utils->ReadConfiguration(false);
+               InitializeDisabledCommands(ServerInstance->Config->DisabledCommands, ServerInstance);
        }
 
        // note: the protocol does not allow direct umode +o except