]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/modules.cpp
Add new cross-module event system
[user/henk/code/inspircd.git] / src / modules.cpp
index 05a1552f48d03e405ef18d4ca6880da4c8962466..55d41674bc82a726c8c2ca82a26b4ea64e81b3e7 100644 (file)
@@ -121,7 +121,6 @@ ModResult   Module::OnChangeLocalUserGECOS(LocalUser*, const std::string&) { Detac
 ModResult      Module::OnPreTopicChange(User*, Channel*, const std::string&) { DetachEvent(I_OnPreTopicChange); return MOD_RES_PASSTHRU; }
 void           Module::OnEvent(Event&) { DetachEvent(I_OnEvent); }
 ModResult      Module::OnPassCompare(Extensible* ex, const std::string &password, const std::string &input, const std::string& hashtype) { DetachEvent(I_OnPassCompare); return MOD_RES_PASSTHRU; }
-void           Module::OnGlobalOper(User*) { DetachEvent(I_OnGlobalOper); }
 void           Module::OnPostConnect(User*) { DetachEvent(I_OnPostConnect); }
 void           Module::OnUserMessage(User*, void*, int, const std::string&, char, const CUList&, MessageType) { DetachEvent(I_OnUserMessage); }
 void           Module::OnUserInvite(User*, User*, Channel*, time_t) { DetachEvent(I_OnUserInvite); }
@@ -656,7 +655,7 @@ ServiceProvider* ModuleManager::FindService(ServiceType type, const std::string&
 }
 
 dynamic_reference_base::dynamic_reference_base(Module* Creator, const std::string& Name)
-       : name(Name), value(NULL), creator(Creator)
+       : name(Name), hook(NULL), value(NULL), creator(Creator)
 {
        if (!dynrefs)
                dynrefs = new insp::intrusive_list<dynamic_reference_base>;
@@ -685,9 +684,19 @@ void dynamic_reference_base::SetProvider(const std::string& newname)
 
 void dynamic_reference_base::resolve()
 {
-       std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules->DataProviders.find(name);
-       if (i != ServerInstance->Modules->DataProviders.end())
-               value = static_cast<DataProvider*>(i->second);
+       // Because find() may return any element with a matching key in case count(key) > 1 use lower_bound()
+       // to ensure a dynref with the same name as another one resolves to the same object
+       std::multimap<std::string, ServiceProvider*>::iterator i = ServerInstance->Modules.DataProviders.lower_bound(name);
+       if ((i != ServerInstance->Modules.DataProviders.end()) && (i->first == this->name))
+       {
+               ServiceProvider* newvalue = i->second;
+               if (value != newvalue)
+               {
+                       value = newvalue;
+                       if (hook)
+                               hook->OnCapture();
+               }
+       }
        else
                value = NULL;
 }