From b618b194f3166a55ca7e7889c7346b65c174d397 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Fri, 18 Dec 2020 00:55:22 +0000 Subject: Don't call events provided by dying or dead modules. --- include/event.h | 37 ++++++++++++++++++----------- src/modules/m_spanningtree/misccommands.cpp | 6 +++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/include/event.h b/include/event.h index 9fd43ccd2..7e8e64c7d 100644 --- a/include/event.h +++ b/include/event.h @@ -58,6 +58,9 @@ class Events::ModuleEventProvider : public ServiceProvider, private dynamic_refe prov.SetCaptureHook(this); } + /** Retrieves the module which created this listener. */ + const Module* GetModule() const { return prov.creator; } + /** Get list of objects subscribed to this event * @return List of subscribed objects */ @@ -181,13 +184,16 @@ inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleE * FOREACH_MOD_CUSTOM(accountevprov, AccountEventListener, OnAccountChange, MOD_RESULT, (user, newaccount)) */ #define FOREACH_MOD_CUSTOM(prov, listenerclass, func, params) do { \ - const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ - for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + if (!(prov).GetModule() || (prov).GetModule()->dying) \ { \ - listenerclass* _t = static_cast(*_i); \ - const Module* _m = _t->GetModule(); \ - if (_m && !_m->dying) \ + const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ + for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + { \ + listenerclass* _t = static_cast(*_i); \ + const Module* _m = _t->GetModule(); \ + if (_m && !_m->dying) \ _t->func params ; \ + } \ } \ } while (0); @@ -200,15 +206,18 @@ inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleE */ #define FIRST_MOD_RESULT_CUSTOM(prov, listenerclass, func, result, params) do { \ result = MOD_RES_PASSTHRU; \ - const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ - for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + if (!(prov).GetModule() || (prov).GetModule()->dying) \ { \ - listenerclass* _t = static_cast(*_i); \ - const Module* _m = _t->GetModule(); \ - if (!_m || _m->dying) \ - continue; \ - result = _t->func params ; \ - if (result != MOD_RES_PASSTHRU) \ - break; \ + const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ + for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ + { \ + listenerclass* _t = static_cast(*_i); \ + const Module* _m = _t->GetModule(); \ + if (!_m || _m->dying) \ + continue; \ + result = _t->func params ; \ + if (result != MOD_RES_PASSTHRU) \ + break; \ + } \ } \ } while (0); diff --git a/src/modules/m_spanningtree/misccommands.cpp b/src/modules/m_spanningtree/misccommands.cpp index c9f86d696..bba05b1fc 100644 --- a/src/modules/m_spanningtree/misccommands.cpp +++ b/src/modules/m_spanningtree/misccommands.cpp @@ -26,12 +26,18 @@ void CmdBuilder::FireEvent(Server* target, const char* cmd, ClientProtocol::TagMap& taglist) { + if (!Utils->Creator || Utils->Creator->dying) + return; + FOREACH_MOD_CUSTOM(Utils->Creator->GetMessageEventProvider(), ServerProtocol::MessageEventListener, OnBuildMessage, (target, cmd, taglist)); UpdateTags(); } void CmdBuilder::FireEvent(User* target, const char* cmd, ClientProtocol::TagMap& taglist) { + if (!Utils->Creator || Utils->Creator->dying) + return; + FOREACH_MOD_CUSTOM(Utils->Creator->GetMessageEventProvider(), ServerProtocol::MessageEventListener, OnBuildMessage, (target, cmd, taglist)); UpdateTags(); } -- cgit v1.2.3