diff options
Diffstat (limited to 'src/modules.cpp')
-rw-r--r-- | src/modules.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
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<Module*>()); @@ -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; |