From 06a96d121febdc2d42208cbde4cd3f908649452e Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 11 Aug 2021 00:45:15 +0100 Subject: Add a detach method that takes an Implementation array. --- include/modules.h | 9 +++++++++ src/coremods/core_channel/core_channel.cpp | 5 +---- src/modules/m_clearchan.cpp | 3 ++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/modules.h b/include/modules.h index b8c547990..9095ae60e 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1147,6 +1147,15 @@ class CoreExport ModuleManager */ bool Detach(Implementation i, Module* mod); + /** Detach an array of events from a module + * This is not required when your module unloads, as the core will + * automatically detach your module from all events it is attached to. + * @param i Event types (array) to detach + * @param mod Module to detach events from + * @param sz The size of the implementation array + */ + void Detach(Implementation* i, Module* mod, size_t sz); + /** Detach all events from a module (used on unload) * @param mod Module to detach from */ diff --git a/src/coremods/core_channel/core_channel.cpp b/src/coremods/core_channel/core_channel.cpp index 4338de934..dcfc8f739 100644 --- a/src/coremods/core_channel/core_channel.cpp +++ b/src/coremods/core_channel/core_channel.cpp @@ -198,10 +198,7 @@ class CoreModChannel if (optionstag->getBool("invitebypassmodes", true)) ServerInstance->Modules.Attach(events, this, sizeof(events)/sizeof(Implementation)); else - { - for (unsigned int i = 0; i < sizeof(events)/sizeof(Implementation); i++) - ServerInstance->Modules.Detach(events[i], this); - } + ServerInstance->Modules.Detach(events, this, sizeof(events)/sizeof(Implementation)); auto limitstag = ServerInstance->Config->ConfValue("limits"); keymode.maxkeylen = limitstag->getUInt("maxkey", 32, 1, ModeParser::MODE_PARAM_MAX); diff --git a/src/modules/m_clearchan.cpp b/src/modules/m_clearchan.cpp index 7d726fafd..b8710a56a 100644 --- a/src/modules/m_clearchan.cpp +++ b/src/modules/m_clearchan.cpp @@ -157,7 +157,8 @@ class ModuleClearChan : public Module void init() override { // Only attached while we are working; don't react to events otherwise - ServerInstance->Modules.DetachAll(this); + Implementation events[] = { I_OnBuildNeighborList, I_OnUserKick }; + ServerInstance->Modules.Detach(events, this, sizeof(events)/sizeof(Implementation)); } void OnBuildNeighborList(User* source, IncludeChanList& include, std::map& exception) override -- cgit v1.3.1-10-gc9f91