]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree.cpp
Added <oper:swhois> to m_swhois, which will override <type:swhois> if specified
[user/henk/code/inspircd.git] / src / modules / m_spanningtree.cpp
index 87b803600c5ece1eec2a55ec4cff537c05c1f2e2..ae68115c5074a61c6c9c0b97663707fb696f3bc7 100644 (file)
 
 /** If you make a change which breaks the protocol, increment this.
  * If you  completely change the protocol, completely change the number.
+ *
+ * IMPORTANT: If you make changes, document your changes here, without fail:
+ * http://www.inspircd.org/wiki/List_of_protocol_changes_between_versions
+ *
+ * Failure to document your protocol changes will result in a painfully
+ * painful death by pain. You have been warned.
  */
-const long ProtocolVersion = 1101;
+const long ProtocolVersion = 1102;
 
 /*
  * The server list in InspIRCd is maintained as two structures
@@ -1921,6 +1927,25 @@ class TreeSocket : public InspSocket
                if (numusers)
                        buffer.append(list).append("\r\n");
 
+               /* Sorry for the hax. Because newly created channels assume +nt,
+                * if this channel doesnt have +nt, explicitly send -n and -t for the missing modes.
+                */
+               bool inverted = false;
+               if (!c->IsModeSet('n'))
+               {
+                       modes.append("-n");
+                       inverted = true;
+               }
+               if (!c->IsModeSet('t'))
+               {
+                       modes.append("-t");
+                       inverted = true;
+               }
+               if (inverted)
+               {
+                       modes.append("+");
+               }
+
                for (BanList::iterator b = c->bans.begin(); b != c->bans.end(); b++)
                {
                        modes.append("b");
@@ -3402,6 +3427,42 @@ class TreeSocket : public InspSocket
                                        }
                                        return true;
                                }
+                               else if (command == "OPERNOTICE")
+                               {
+                                       std::string sourceserv = this->myhost;
+
+                                       if (this->InboundServerName != "")
+                                               sourceserv = this->InboundServerName;
+
+                                       if (params.size() >= 1)
+                                               Instance->WriteOpers("*** From " + sourceserv + ": " + params[0]);
+
+                                       return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
+                               }
+                               else if (command == "MODENOTICE")
+                               {
+                                       std::string sourceserv = this->myhost;
+                                       if (this->InboundServerName != "")
+                                               sourceserv = this->InboundServerName;
+                                       if (params.size() >= 2)
+                                       {
+                                               Instance->WriteMode(params[0].c_str(), WM_AND, "*** From %s: %s", sourceserv.c_str(), params[1].c_str());
+                                       }
+
+                                       return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
+                               }
+                               else if (command == "SNONOTICE")
+                               {
+                                       std::string sourceserv = this->myhost;
+                                       if (this->InboundServerName != "")
+                                               sourceserv = this->InboundServerName;
+                                       if (params.size() >= 2)
+                                       {
+                                               Instance->SNO->WriteToSnoMask(*(params[0].c_str()), "From " + sourceserv + ": "+ params[1]);
+                                       }
+
+                                       return Utils->DoOneToAllButSenderRaw(line, sourceserv, prefix, command, params);
+                               }
                                else if (command == "ENDBURST")
                                {
                                        this->bursting = false;
@@ -3429,6 +3490,25 @@ class TreeSocket : public InspSocket
                                        {
                                                sourceserv = this->InboundServerName;
                                        }
+                                       if ((!who) && (command == "MODE"))
+                                       {
+                                               if (Utils->IsServer(prefix))
+                                               {
+                                                       const char* modelist[127];
+                                                       for (size_t i = 0; i < params.size(); i++)
+                                                               modelist[i] = params[i].c_str();
+
+                                                       userrec* fake = new userrec(Instance);
+                                                       fake->SetFd(FD_MAGIC_NUMBER);
+
+                                                       this->Instance->SendMode(modelist, params.size(), fake);
+       
+                                                       delete fake;
+
+                                                       /* Hot potato! pass it on! */
+                                                       return Utils->DoOneToAllButSenderRaw(line,sourceserv,prefix,command,params);
+                                               }
+                                       }
                                        if (who)
                                        {
                                                if ((command == "NICK") && (params.size() > 0))
@@ -3585,7 +3665,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 +3710,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 +3951,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, false);
+                               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 +4016,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)
@@ -4073,14 +4157,33 @@ class ModuleSpanningTree : public Module
                if (n_users > max_global)
                        max_global = n_users;
 
-               user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,n_users-ServerInstance->InvisibleUserCount(),ServerInstance->InvisibleUserCount(),this->CountServs());
+               unsigned int ulined_count = 0;
+               unsigned int ulined_local_count = 0;
+
+               /* If ulined are hidden and we're not an oper, count the number of ulined servers hidden,
+                * locally and globally (locally means directly connected to us)
+                */
+               if ((Utils->HideULines) && (!*user->oper))
+               {
+                       for (server_hash::iterator q = Utils->serverlist.begin(); q != Utils->serverlist.end(); q++)
+                       {
+                               if (ServerInstance->ULine(q->second->GetName().c_str()))
+                               {
+                                       ulined_count++;
+                                       if (q->second->GetParent() == Utils->TreeRoot)
+                                               ulined_local_count++;
+                               }
+                       }
+               }
+
+               user->WriteServ("251 %s :There are %d users and %d invisible on %d servers",user->nick,n_users-ServerInstance->InvisibleUserCount(),ServerInstance->InvisibleUserCount(),ulined_count ? this->CountServs() - ulined_count : this->CountServs());
                if (ServerInstance->OperCount())
                        user->WriteServ("252 %s %d :operator(s) online",user->nick,ServerInstance->OperCount());
                if (ServerInstance->UnregisteredUserCount())
                        user->WriteServ("253 %s %d :unknown connections",user->nick,ServerInstance->UnregisteredUserCount());
                if (ServerInstance->ChannelCount())
                        user->WriteServ("254 %s %d :channels formed",user->nick,ServerInstance->ChannelCount());
-               user->WriteServ("254 %s :I have %d clients and %d servers",user->nick,ServerInstance->LocalUserCount(),this->CountLocalServs());
+               user->WriteServ("254 %s :I have %d clients and %d servers",user->nick,ServerInstance->LocalUserCount(),ulined_local_count ? this->CountLocalServs() - ulined_local_count : this->CountLocalServs());
                user->WriteServ("265 %s :Current Local Users: %d  Max: %d",user->nick,ServerInstance->LocalUserCount(),max_local);
                user->WriteServ("266 %s :Current Global Users: %d  Max: %d",user->nick,n_users,max_global);
                return;
@@ -4408,7 +4511,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)
@@ -4783,6 +4886,14 @@ class ModuleSpanningTree : public Module
                        params.push_back(ConvToStr(channel->age));
                        params.push_back(std::string(channel->GetAllPrefixChars(user))+","+std::string(user->nick));
                        Utils->DoOneToMany(ServerInstance->Config->ServerName,"FJOIN",params);
+                       if (channel->GetUserCounter() == 1)
+                       {
+                               /* First user in, sync the modes for the channel */
+                               params.pop_back();
+                               /* This is safe, all inspircd servers default to +nt */
+                               params.push_back("+nt");
+                               Utils->DoOneToMany(ServerInstance->Config->ServerName,"FMODE",params);
+                       }
                }
        }
 
@@ -4932,26 +5043,39 @@ 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, (unsigned long)ServerInstance->Time(false),
+                                       (unsigned long)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);
+                               }
                        }
                }
        }
@@ -5121,6 +5245,33 @@ class ModuleSpanningTree : public Module
                        params->insert(params->begin() + 1,ConvToStr(ourTS));
                        Utils->DoOneToMany(ServerInstance->Config->ServerName,"FMODE",*params);
                }
+               else if (event->GetEventID() == "send_mode_explicit")
+               {
+                       if (params->size() < 2)
+                               return;
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName,"MODE",*params);
+               }
+               else if (event->GetEventID() == "send_opers")
+               {
+                       if (params->size() < 1)
+                               return;
+                       (*params)[0] = ":" + (*params)[0];
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName,"OPERNOTICE",*params);
+               }
+               else if (event->GetEventID() == "send_modeset")
+               {
+                       if (params->size() < 2)
+                               return;
+                       (*params)[1] = ":" + (*params)[1];
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName,"MODENOTICE",*params);
+               }
+               else if (event->GetEventID() == "send_snoset")
+               {
+                       if (params->size() < 2)
+                               return;
+                       (*params)[1] = ":" + (*params)[1];
+                       Utils->DoOneToMany(ServerInstance->Config->ServerName,"SNONOTICE",*params);
+               }
                else if (event->GetEventID() == "send_push")
                {
                        if (params->size() < 2)