]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Add irc::portparser, a class to parse port ranges in the form "6660,6661,6662-6669...
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index 2a77e39dd26b7590cd8884bf2953fc4793a1eefe..20c81bd95af8d3086f682bc479394b82d2e3d638 100644 (file)
@@ -1965,12 +1965,12 @@ class TreeSocket : public InspSocket
                }
                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\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       snprintf(data,MAXBUF,":%s ADDLINE G %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*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\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       snprintf(data,MAXBUF,":%s ADDLINE E %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*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++)
@@ -1985,12 +1985,12 @@ class TreeSocket : public InspSocket
                }
                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\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       snprintf(data,MAXBUF,":%s ADDLINE G %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*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\r\n",sn,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
+                       snprintf(data,MAXBUF,":%s ADDLINE E %s@%s %s %lu %lu :%s\r\n",sn,(*i)->identmask,(*i)->hostmask,(*i)->source,(unsigned long)(*i)->set_time,(unsigned long)(*i)->duration,(*i)->reason);
                        buffer.append(data);
                }
 
@@ -2701,7 +2701,7 @@ class TreeSocket : public InspSocket
                
                bool force = false;
                
-               if ((params.size() == 2) && (params[1] == "force"))
+               if ((params.size() == 2) && (params[1] == "FORCE"))
                        force = true;
                
                time_t rts = atoi(params[0].c_str());
@@ -2745,7 +2745,7 @@ class TreeSocket : public InspSocket
                                userrec* u = this->Instance->FindNick(params[1]);
                                if (u)
                                {
-                                       params.push_back(ConvToStr(Instance->Time(true)));
+                                       params.push_back(ConvToStr(Instance->Time(false)));
                                        params[0] = prefix;
                                        Utils->DoOneToOne(this->Instance->Config->ServerName,"TIME",params,params[0]);
                                }
@@ -3124,7 +3124,7 @@ class TreeSocket : public InspSocket
                                                time_t us = Instance->Time(true);
                                                int delta = them - us;
 
-                                               if ((params.size() == 2) && (params[1] == "force"))
+                                               if ((params.size() == 2) && (params[1] == "FORCE"))
                                                        force = true;
 
                                                if ((delta < -600) || (delta > 600))
@@ -3585,7 +3585,7 @@ class ServernameResolver : public Resolver
        Link MyLink;
        SpanningTreeUtilities* Utils;
  public: 
-       ServernameResolver(SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD), MyLink(x), Utils(Util)
+       ServernameResolver(Module* me, SpanningTreeUtilities* Util, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(Util)
        {
                /* Nothing in here, folks */
        }
@@ -3630,7 +3630,7 @@ class SecurityIPResolver : public Resolver
        Link MyLink;
        SpanningTreeUtilities* Utils;
  public:
-       SecurityIPResolver(SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD), MyLink(x), Utils(U)
+       SecurityIPResolver(Module* me, SpanningTreeUtilities* U, InspIRCd* Instance, const std::string &hostname, Link x) : Resolver(Instance, hostname, DNS_QUERY_FORWARD, me), MyLink(x), Utils(U)
        {
        }
 
@@ -3871,27 +3871,31 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
                {
                        std::string Type = Conf->ReadValue("bind","type",j);
                        std::string IP = Conf->ReadValue("bind","address",j);
-                       int Port = Conf->ReadInteger("bind","port",j,true);
+                       std::string Port = Conf->ReadValue("bind","port",j);
                        if (Type == "servers")
                        {
-                               ServerInstance->Log(DEBUG,"m_spanningtree: Binding server port %s:%d", IP.c_str(), Port);
-                               if (IP == "*")
+                               irc::portparser portrange(Port);
+                               int portno = -1;
+                               while ((portno = portrange.GetToken()))
                                {
-                                       IP = "";
-                               }
-                               TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(),Port,true,10);
-                               if (listener->GetState() == I_LISTENING)
-                               {
-                                       ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), Port);
-                                       Bindings.push_back(listener);
-                               }
-                               else
-                               {
-                                       ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port %d",Port);
-                                       listener->Close();
-                                       DELETE(listener);
+                                       ServerInstance->Log(DEBUG,"m_spanningtree: Binding server port %s:%d", IP.c_str(), portno);
+                                       if (IP == "*")
+                                               IP = "";
+
+                                       TreeSocket* listener = new TreeSocket(this, ServerInstance, IP.c_str(), portno, true, 10);
+                                       if (listener->GetState() == I_LISTENING)
+                                       {
+                                               ServerInstance->Log(DEFAULT,"m_spanningtree: Binding server port %s:%d successful!", IP.c_str(), portno);
+                                               Bindings.push_back(listener);
+                                       }
+                                       else
+                                       {
+                                               ServerInstance->Log(DEFAULT,"m_spanningtree: Warning: Failed to bind server port %s:%d",IP.c_str(), portno);
+                                               listener->Close();
+                                               DELETE(listener);
+                                       }
+                                       ServerInstance->Log(DEBUG,"Done with this binding");
                                }
-                               ServerInstance->Log(DEBUG,"Done with this binding");
                        }
                }
        }
@@ -3932,7 +3936,7 @@ void SpanningTreeUtilities::ReadConfiguration(bool rebind)
                                {
                                        try
                                        {
-                                               SecurityIPResolver* sr = new SecurityIPResolver(this, ServerInstance, L.IPAddr, L);
+                                               SecurityIPResolver* sr = new SecurityIPResolver((Module*)this->Creator, this, ServerInstance, L.IPAddr, L);
                                                ServerInstance->AddResolver(sr);
                                        }
                                        catch (ModuleException& e)
@@ -4408,7 +4412,7 @@ class ModuleSpanningTree : public Module
                {
                        try
                        {
-                               ServernameResolver* snr = new ServernameResolver(Utils, ServerInstance,x->IPAddr, *x);
+                               ServernameResolver* snr = new ServernameResolver((Module*)this, Utils, ServerInstance,x->IPAddr, *x);
                                ServerInstance->AddResolver(snr);
                        }
                        catch (ModuleException& e)
@@ -4932,26 +4936,38 @@ class ModuleSpanningTree : public Module
 
        void OnLine(userrec* source, const std::string &host, bool adding, char linetype, long duration, const std::string &reason)
        {
-               if (IS_LOCAL(source))
+               if (!source)
                {
-                       char type[8];
-                       snprintf(type,8,"%cLINE",linetype);
-                       std::string stype = type;
-                       if (adding)
-                       {
-                               char sduration[MAXBUF];
-                               snprintf(sduration,MAXBUF,"%ld",duration);
-                               std::deque<std::string> params;
-                               params.push_back(host);
-                               params.push_back(sduration);
-                               params.push_back(":"+reason);
-                               Utils->DoOneToMany(source->nick,stype,params);
-                       }
-                       else
+                       /* Server-set lines */
+                       char data[MAXBUF];
+                       snprintf(data,MAXBUF,"%c %s %s %lu %lu :%s", linetype, host.c_str(), ServerInstance->Config->ServerName, ServerInstance->Time(false), duration, reason.c_str());
+                       std::deque<std::string> params;
+                       params.push_back(data);
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName, "ADDLINE", params);
+               }
+               else
+               {
+                       if (IS_LOCAL(source))
                        {
-                               std::deque<std::string> params;
-                               params.push_back(host);
-                               Utils->DoOneToMany(source->nick,stype,params);
+                               char type[8];
+                               snprintf(type,8,"%cLINE",linetype);
+                               std::string stype = type;
+                               if (adding)
+                               {
+                                       char sduration[MAXBUF];
+                                       snprintf(sduration,MAXBUF,"%ld",duration);
+                                       std::deque<std::string> params;
+                                       params.push_back(host);
+                                       params.push_back(sduration);
+                                       params.push_back(":"+reason);
+                                       Utils->DoOneToMany(source->nick,stype,params);
+                               }
+                               else
+                               {
+                                       std::deque<std::string> params;
+                                       params.push_back(host);
+                                       Utils->DoOneToMany(source->nick,stype,params);
+                               }
                        }
                }
        }