X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=include%2Fevent.h;h=baa24d7d08798b9f5c9a370dac3bae2af1f64510;hb=2ba32afa9a9aca7c82966b66bda16c3c3dbfbba5;hp=39273413fa448eb534c47332d0cd71ac26fd8000;hpb=5ae65245221dfad24510ee9a1fbead8db740251f;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/include/event.h b/include/event.h index 39273413f..baa24d7d0 100644 --- a/include/event.h +++ b/include/event.h @@ -1,7 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * - * Copyright (C) 2018-2019 Sadie Powell + * Copyright (C) 2018-2020 Sadie Powell * Copyright (C) 2015, 2018 Attila Molnar * * This file is part of InspIRCd. InspIRCd is free software: you can @@ -20,6 +20,8 @@ #pragma once +#include "base.h" + namespace Events { class ModuleEventListener; @@ -58,6 +60,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 +186,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 +208,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);