From bf44023d115745d4a6a1ce06ff291ffb73480efb Mon Sep 17 00:00:00 2001 From: brain Date: Sun, 4 Nov 2007 15:29:49 +0000 Subject: Development/Hooking in full swing now: WARNING, this will break ALL modules for the time being until complete! git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8497 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modules.cpp | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/modules.cpp b/src/modules.cpp index d9fca88cd..601aeabef 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -191,8 +191,7 @@ void Module::OnBufferFlushed(User*) { } void Module::OnText(User*, void*, int, const std::string&, char, CUList&) { } -ModuleManager::ModuleManager(InspIRCd* Ins) -: ModCount(0), Instance(Ins) +ModuleManager::ModuleManager(InspIRCd* Ins) : ModCount(0), Instance(Ins) { for (int n = I_BEGIN + 1; n != I_END; ++n) EventHandlers.push_back(std::list()); @@ -202,6 +201,38 @@ ModuleManager::~ModuleManager() { } +bool ModuleManager::Attach(Implementation i, Module* mod) +{ + if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end()) + return false; + + EventHandlers[i].push_back(mod); + return true; +} + +bool ModuleManager::Detach(Implementation i, Module* mod) +{ + EventHandlerIter x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod); + + if (x == EventHandlers[i].end()) + return false; + + EventHandlers[i].erase(x); + return true; +} + +void ModuleManager::Attach(Implementation* i, Module* mod, size_t sz) +{ + for (size_t n = 0; n < sz; ++n) + Attach(i[n], mod); +} + +void ModuleManager::DetachAll(Module* mod) +{ + for (size_t n = I_BEGIN + 1; n != I_END; ++n) + Detach((Implementation)n, mod); +} + const char* ModuleManager::LastError() { return MODERR; -- cgit v1.2.3