]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules/m_spanningtree/main.cpp
Same here
[user/henk/code/inspircd.git] / src / modules / m_spanningtree / main.cpp
index b37edf583c776c483494c725bb22120828037b7f..8ddbe5e309b61614574ed23e3f52d5a36a035387 100644 (file)
@@ -30,8 +30,9 @@
 #include "m_spanningtree/treesocket.h"
 #include "m_spanningtree/rconnect.h"
 #include "m_spanningtree/rsquit.h"
+#include "m_spanningtree/protocolinterface.h"
 
-/* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_spanningtree/rconnect.h m_spanningtree/rsquit.h */
+/* $ModDep: m_spanningtree/timesynctimer.h m_spanningtree/resolvers.h m_spanningtree/main.h m_spanningtree/utils.h m_spanningtree/treeserver.h m_spanningtree/link.h m_spanningtree/treesocket.h m_spanningtree/rconnect.h m_spanningtree/rsquit.h m_spanningtree/protocolinterface.h */
 
 ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
        : Module(Me), max_local(0), max_global(0)
@@ -52,9 +53,12 @@ ModuleSpanningTree::ModuleSpanningTree(InspIRCd* Me)
                I_OnUserJoin, I_OnChangeHost, I_OnChangeName, I_OnUserPart, I_OnPostConnect,
                I_OnUserQuit, I_OnUserPostNick, I_OnUserKick, I_OnRemoteKill, I_OnRehash,
                I_OnOper, I_OnAddLine, I_OnDelLine, I_ProtoSendMode, I_OnMode,
-               I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnCancelAway, I_OnPostCommand
+               I_OnStats, I_ProtoSendMetaData, I_OnEvent, I_OnSetAway, I_OnPostCommand
        };
-       ServerInstance->Modules->Attach(eventlist, this, 29);
+       ServerInstance->Modules->Attach(eventlist, this, 28);
+
+       delete ServerInstance->PI;
+       ServerInstance->PI = new SpanningTreeProtocolInterface(this, Utils, ServerInstance);
 
        for (std::vector<User*>::const_iterator i = ServerInstance->Users->local_users.begin(); i != ServerInstance->Users->local_users.end(); i++)
        {
@@ -214,17 +218,25 @@ void ModuleSpanningTree::DoPingChecks(time_t curtime)
                }
        }
 
+
        /*
         * Cancel remote burst mode on any servers which still have it enabled due to latency/lack of data.
         * This prevents lost REMOTECONNECT notices
-        * XXX this should probably not do this until server has been bursting for, say, 60 seconds or something
         */
+       timeval t;
+       gettimeofday(&t, NULL);
+       long ts = (t.tv_sec * 1000) + (t.tv_usec / 1000);
+
        for (server_hash::iterator i = Utils->serverlist.begin(); i != Utils->serverlist.end(); i++)
        {
                if (i->second->bursting)
                {
-                       ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not finished burst, forcing end of burst.", i->second->GetName().c_str());
-                       i->second->FinishBurst();
+                       unsigned long bursttime = ts - i->second->StartBurst;
+                       if (bursttime > 60000) // A minute
+                       {
+                               ServerInstance->SNO->WriteToSnoMask('l',"Server \002%s\002 has not finished burst, forcing end of burst.", i->second->GetName().c_str());
+                               i->second->FinishBurst();
+                       }
                }
        }
 }
@@ -449,6 +461,10 @@ void ModuleSpanningTree::OnWallops(User* user, const std::string &text)
 
 void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
 {
+       /* Server origin */
+       if (user == NULL)
+               return;
+
        if (target_type == TYPE_USER)
        {
                User* d = (User*)dest;
@@ -497,6 +513,10 @@ void ModuleSpanningTree::OnUserNotice(User* user, void* dest, int target_type, c
 
 void ModuleSpanningTree::OnUserMessage(User* user, void* dest, int target_type, const std::string &text, char status, const CUList &exempt_list)
 {
+       /* Server origin */
+       if (user == NULL)
+               return;
+
        if (target_type == TYPE_USER)
        {
                // route private messages which are targetted at clients only to the server
@@ -564,12 +584,9 @@ void ModuleSpanningTree::OnUserJoin(User* user, Channel* channel, bool sync, boo
                        // new joining permissions for the user.
                        params.push_back(channel->name);
                        params.push_back(ConvToStr(channel->age));
-                       params.push_back(std::string(channel->GetAllPrefixChars(user))+","+std::string(user->uuid));
-                       Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
-                       /* First user in, sync the modes for the channel */
-                       params.pop_back();
                        params.push_back(std::string("+") + channel->ChanModes(true));
-                       Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",params);
+                       params.push_back(ServerInstance->Modes->ModeString(user, channel, false)+","+std::string(user->uuid));
+                       Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FJOIN",params);
                }
                else
                {
@@ -817,24 +834,25 @@ void ModuleSpanningTree::OnMode(User* user, void* dest, int target_type, const s
        }
 }
 
-void ModuleSpanningTree::OnSetAway(User* user)
+int ModuleSpanningTree::OnSetAway(User* user, const std::string &awaymsg)
 {
        if (IS_LOCAL(user))
        {
-               std::deque<std::string> params;
-               params.push_back(":"+std::string(user->awaymsg));
-               Utils->DoOneToMany(user->uuid,"AWAY",params);
+               if (awaymsg.empty())
+               {
+                       std::deque<std::string> params;
+                       params.clear();
+                       Utils->DoOneToMany(user->uuid,"AWAY",params);
+               }
+               else
+               {
+                       std::deque<std::string> params;
+                       params.push_back(":" + awaymsg);
+                       Utils->DoOneToMany(user->uuid,"AWAY",params);
+               }
        }
-}
 
-void ModuleSpanningTree::OnCancelAway(User* user)
-{
-       if (IS_LOCAL(user))
-       {
-               std::deque<std::string> params;
-               params.clear();
-               Utils->DoOneToMany(user->uuid,"AWAY",params);
-       }
+       return 0;
 }
 
 void ModuleSpanningTree::ProtoSendMode(void* opaque, int target_type, void* target, const std::string &modeline)
@@ -883,112 +901,19 @@ void ModuleSpanningTree::ProtoSendMetaData(void* opaque, int target_type, void*
 
 void ModuleSpanningTree::OnEvent(Event* event)
 {
-       std::deque<std::string>* params = (std::deque<std::string>*)event->GetData();
-       if (event->GetEventID() == "send_encap")
+       if ((event->GetEventID() == "send_encap") || (event->GetEventID() == "send_metadata") || (event->GetEventID() == "send_topic") || (event->GetEventID() == "send_mode") || (event->GetEventID() == "send_mode_explicit") || (event->GetEventID() == "send_opers")
+               || (event->GetEventID() == "send_modeset") || (event->GetEventID() == "send_snoset") || (event->GetEventID() == "send_push"))
        {
-               if (params->size() < 2)
-                       return;
-
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(), "ENCAP", *params);
-       }
-       else if (event->GetEventID() == "send_metadata")
-       {
-               if (params->size() < 3)
-                       return;
-               (*params)[2] = ":" + (*params)[2];
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"METADATA",*params);
-       }
-       else if (event->GetEventID() == "send_topic")
-       {
-               if (params->size() < 2)
-                       return;
-               (*params)[1] = ":" + (*params)[1];
-               params->insert(params->begin() + 1,ServerInstance->Config->ServerName);
-               params->insert(params->begin() + 1,ConvToStr(ServerInstance->Time()));
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FTOPIC",*params);
-       }
-       else if (event->GetEventID() == "send_mode")
-       {
-               if (params->size() < 2)
-                       return;
-               // Insert the TS value of the object, either User or Channel
-               time_t ourTS = 0;
-               std::string output_text;
-
-               /* Warning: in-place translation is only safe for type TR_NICK */
-               for (size_t n = 0; n < params->size(); n++)
-                       ServerInstance->Parser->TranslateUIDs(TR_NICK, (*params)[n], (*params)[n]);
-
-               User* a = ServerInstance->FindNick((*params)[0]);
-               if (a)
-               {
-                       ourTS = a->age;
-                       Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",*params);
-                       return;
-               }
-               else
-               {
-                       Channel* c = ServerInstance->FindChan((*params)[0]);
-                       if (c)
-                       {
-                               ourTS = c->age;
-                               params->insert(params->begin() + 1,ConvToStr(ourTS));
-                               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"FMODE",*params);
-                       }
-               }
-       }
-       else if (event->GetEventID() == "send_mode_explicit")
-       {
-               if (params->size() < 2)
-                       return;
-               std::string output_text;
-
-               /* Warning: in-place translation is only safe for type TR_NICK */
-               for (size_t n = 0; n < params->size(); n++)
-                       ServerInstance->Parser->TranslateUIDs(TR_NICK, (*params)[n], (*params)[n]);
-
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODE",*params);
-       }
-       else if (event->GetEventID() == "send_opers")
-       {
-               if (params->size() < 1)
-                       return;
-               (*params)[0] = ":" + (*params)[0];
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"OPERNOTICE",*params);
-       }
-       else if (event->GetEventID() == "send_modeset")
-       {
-               if (params->size() < 2)
-                       return;
-               (*params)[1] = ":" + (*params)[1];
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"MODENOTICE",*params);
-       }
-       else if (event->GetEventID() == "send_snoset")
-       {
-               if (params->size() < 2)
-                       return;
-               (*params)[1] = ":" + (*params)[1];
-               Utils->DoOneToMany(ServerInstance->Config->GetSID(),"SNONOTICE",*params);
-       }
-       else if (event->GetEventID() == "send_push")
-       {
-               if (params->size() < 2)
-                       return;
-                       
-               User *a = ServerInstance->FindNick((*params)[0]);
-                       
-               if (!a)
-                       return;
-
-               (*params)[0] = a->uuid;
-               (*params)[1] = ":" + (*params)[1];
-               Utils->DoOneToOne(ServerInstance->Config->GetSID(), "PUSH", *params, a->server);
+               ServerInstance->Logs->Log("m_spanningtree", DEBUG, "WARNING: Deprecated use of old 1.1 style m_spanningtree event ignored, type '"+event->GetEventID()+"'!");
        }
 }
 
 ModuleSpanningTree::~ModuleSpanningTree()
 {
        /* This will also free the listeners */
+       delete ServerInstance->PI;
+       ServerInstance->PI = new ProtocolInterface(ServerInstance);
+
        delete Utils;
 
        ServerInstance->Timers->DelTimer(RefreshTimer);