diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-11-04 15:39:06 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-11-04 15:39:06 +0000 |
commit | 2facf72164bcf6ddef3b865ee729e6918cd06fd0 (patch) | |
tree | 53306c112a54ca2569ffbab755514b03ea28f16a | |
parent | bf44023d115745d4a6a1ce06ff291ffb73480efb (diff) |
Next part of Development/Hooking (see wiki)
Module::Prioritize and Module::Implements are now GONE.
ModuleManager::MoveTo, MoveBefore, MoveAfter, MoveFirst, MoveLast are GONE too.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8498 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/modules.h | 83 | ||||
-rw-r--r-- | src/modules.cpp | 153 | ||||
-rw-r--r-- | src/modules/m_alias.cpp | 6 |
3 files changed, 3 insertions, 239 deletions
diff --git a/include/modules.h b/include/modules.h index 4adab2378..b9dcd0b8d 100644 --- a/include/modules.h +++ b/include/modules.h @@ -422,41 +422,6 @@ class CoreExport Module : public Extensible */ virtual Version GetVersion(); - /** The Implements function specifies which methods a module should receive events for. - * The char* parameter passed to this function contains a set of true or false values - * (1 or 0) which indicate wether each function is implemented. You must use the Iimplementation - * enum (documented elsewhere on this page) to mark functions as active. For example, to - * receive events for OnUserJoin(): - * - * Implements[I_OnUserJoin] = 1; - * - * @param The implement list - */ - virtual void Implements(char* Implements); - - /** Used to set the 'priority' of a module (e.g. when it is called in relation to other modules. - * Some modules prefer to be called before other modules, due to their design. For example, a - * module which is expected to operate on complete information would expect to be placed last, so - * that any other modules which wish to adjust that information would execute before it, to be sure - * its information is correct. You can change your module's priority by returning one of: - * - * PRIORITY_FIRST - To place your module first in the list - * - * PRIORITY_LAST - To place your module last in the list - * - * PRIORITY_DONTCARE - To leave your module as it is (this is the default value, if you do not implement this function) - * - * The result of InspIRCd::PriorityBefore() - To move your module before another named module - * - * The result of InspIRCd::PriorityLast() - To move your module after another named module - * - * For a good working example of this method call, please see src/modules/m_spanningtree.cpp - * and src/modules/m_hostchange.so which make use of it. It is highly recommended that unless - * your module has a real need to reorder its priority, it should not implement this function, - * as many modules changing their priorities can make the system redundant. - */ - virtual Priority Prioritize(); - /** Called when a user connects. * The details of the connecting user are available to you in the parameter User *user * @param user The user who is connecting @@ -1682,54 +1647,6 @@ class CoreExport ModuleManager : public classbase */ bool EraseModule(unsigned int j); - /** Move a given module to a specific slot in the list - * @param modulename The module name to relocate - * @param slot The slot to move the module into - */ - void MoveTo(std::string modulename,int slot); - - /** Moves the given module to the last slot in the list - * @param modulename The module name to relocate - */ - void MoveToLast(std::string modulename); - - /** Moves the given module to the first slot in the list - * @param modulename The module name to relocate - */ - void MoveToFirst(std::string modulename); - - /** Moves one module to be placed after another in the list - * @param modulename The module name to relocate - * @param after The module name to place the module after - */ - void MoveAfter(std::string modulename, std::string after); - - /** Moves one module to be placed before another in the list - * @param modulename The module name to relocate - * @param after The module name to place the module before - */ - void MoveBefore(std::string modulename, std::string before); - - /** For use with Module::Prioritize(). - * When the return value of this function is returned from - * Module::Prioritize(), this specifies that the module wishes - * to be ordered exactly BEFORE 'modulename'. For more information - * please see Module::Prioritize(). - * @param modulename The module your module wants to be before in the call list - * @returns a priority ID which the core uses to relocate the module in the list - */ - long PriorityBefore(const std::string &modulename); - - /** For use with Module::Prioritize(). - * When the return value of this function is returned from - * Module::Prioritize(), this specifies that the module wishes - * to be ordered exactly AFTER 'modulename'. For more information please - * see Module::Prioritize(). - * @param modulename The module your module wants to be after in the call list - * @returns a priority ID which the core uses to relocate the module in the list - */ - long PriorityAfter(const std::string &modulename); - /** Publish a 'feature'. * There are two ways for a module to find another module it depends on. * Either by name, using InspIRCd::FindModule, or by feature, using this diff --git a/src/modules.cpp b/src/modules.cpp index 601aeabef..f0d52d331 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -178,9 +178,7 @@ void Module::OnChangeName(User*, const std::string&) { } void Module::OnAddLine(User*, XLine*) { } void Module::OnDelLine(User*, XLine*) { } void Module::OnCleanup(int, void*) { } -void Module::Implements(char* Implements) { for (int j = 0; j < 255; j++) Implements[j] = 0; } void Module::OnChannelDelete(Channel*) { } -Priority Module::Prioritize() { return PRIORITY_DONTCARE; } void Module::OnSetAway(User*) { } void Module::OnCancelAway(User*) { } int Module::OnUserList(User*, Channel*, CUList*&) { return 0; } @@ -332,15 +330,6 @@ bool ModuleManager::Load(const char* filename) /* save the module and the module's classfactory, if * this isnt done, random crashes can occur :/ */ Instance->Config->module_names.push_back(filename); - - char* x = &Instance->Config->implement_lists[this->ModCount+1][0]; - for(int t = 0; t < 255; t++) - x[t] = 0; - - modules[this->ModCount+1]->Implements(x); - - for(int t = 0; t < 255; t++) - Instance->Config->global_implementation[t] += Instance->Config->implement_lists[this->ModCount+1][t]; } else { @@ -370,31 +359,6 @@ bool ModuleManager::Load(const char* filename) this->ModCount++; FOREACH_MOD_I(Instance,I_OnLoadModule,OnLoadModule(modules[this->ModCount],filename_str)); - // now work out which modules, if any, want to move to the back of the queue, - // and if they do, move them there. - std::vector<std::string> put_to_back; - std::vector<std::string> put_to_front; - std::map<std::string,std::string> put_before; - std::map<std::string,std::string> put_after; - for (unsigned int j = 0; j < Instance->Config->module_names.size(); j++) - { - if (modules[j]->Prioritize() == PRIORITY_LAST) - put_to_back.push_back(Instance->Config->module_names[j]); - else if (modules[j]->Prioritize() == PRIORITY_FIRST) - put_to_front.push_back(Instance->Config->module_names[j]); - else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE) - put_before[Instance->Config->module_names[j]] = Instance->Config->module_names[modules[j]->Prioritize() >> 8]; - else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER) - put_after[Instance->Config->module_names[j]] = Instance->Config->module_names[modules[j]->Prioritize() >> 8]; - } - for (unsigned int j = 0; j < put_to_back.size(); j++) - MoveToLast(put_to_back[j]); - for (unsigned int j = 0; j < put_to_front.size(); j++) - MoveToFirst(put_to_front[j]); - for (std::map<std::string,std::string>::iterator j = put_before.begin(); j != put_before.end(); j++) - MoveBefore(j->first,j->second); - for (std::map<std::string,std::string>::iterator j = put_after.begin(); j != put_after.end(); j++) - MoveAfter(j->first,j->second); Instance->BuildISupport(); return true; } @@ -456,84 +420,6 @@ bool ModuleManager::EraseModule(unsigned int j) return success; } -void ModuleManager::MoveTo(std::string modulename,int slot) -{ - unsigned int v2 = 256; - - for (unsigned int v = 0; v < Instance->Config->module_names.size(); v++) - { - if (Instance->Config->module_names[v] == modulename) - { - // found an instance, swap it with the item at the end - v2 = v; - break; - } - } - if ((v2 != (unsigned int)slot) && (v2 < 256)) - { - // Swap the module names over - Instance->Config->module_names[v2] = Instance->Config->module_names[slot]; - Instance->Config->module_names[slot] = modulename; - // now swap the module factories - ircd_module* temp = handles[v2]; - handles[v2] = handles[slot]; - handles[slot] = temp; - // now swap the module objects - Module* temp_module = modules[v2]; - modules[v2] = modules[slot]; - modules[slot] = temp_module; - // now swap the implement lists (we dont - // need to swap the global or recount it) - for (int n = 0; n < 255; n++) - { - char x = Instance->Config->implement_lists[v2][n]; - Instance->Config->implement_lists[v2][n] = Instance->Config->implement_lists[slot][n]; - Instance->Config->implement_lists[slot][n] = x; - } - } -} - -void ModuleManager::MoveAfter(std::string modulename, std::string after) -{ - for (unsigned int v = 0; v < Instance->Config->module_names.size(); v++) - { - if (Instance->Config->module_names[v] == after) - { - MoveTo(modulename, v); - return; - } - } -} - -void ModuleManager::MoveBefore(std::string modulename, std::string before) -{ - for (unsigned int v = 0; v < Instance->Config->module_names.size(); v++) - { - if (Instance->Config->module_names[v] == before) - { - if (v > 0) - { - MoveTo(modulename, v-1); - } - else - { - MoveTo(modulename, v); - } - return; - } - } -} - -void ModuleManager::MoveToFirst(std::string modulename) -{ - MoveTo(modulename,0); -} - -void ModuleManager::MoveToLast(std::string modulename) -{ - MoveTo(modulename,this->GetCount()); -} - bool ModuleManager::Unload(const char* filename) { std::string filename_str = filename; @@ -573,20 +459,7 @@ bool ModuleManager::Unload(const char* filename) FOREACH_MOD_I(Instance,I_OnUnloadModule,OnUnloadModule(modules[j],Instance->Config->module_names[j])); - for(int t = 0; t < 255; t++) - { - Instance->Config->global_implementation[t] -= Instance->Config->implement_lists[j][t]; - } - - /* We have to renumber implement_lists after unload because the module numbers change! - */ - for(int j2 = j; j2 < 254; j2++) - { - for(int t = 0; t < 255; t++) - { - Instance->Config->implement_lists[j2][t] = Instance->Config->implement_lists[j2+1][t]; - } - } + this->DetachAll(modules[j]); // found the module Instance->Parser->RemoveCommands(filename); @@ -626,30 +499,6 @@ void ModuleManager::LoadAll() Instance->Log(DEFAULT,"Total loaded modules: %d", this->GetCount()+1); } -long ModuleManager::PriorityAfter(const std::string &modulename) -{ - for (unsigned int j = 0; j < Instance->Config->module_names.size(); j++) - { - if (Instance->Config->module_names[j] == modulename) - { - return ((j << 8) | PRIORITY_AFTER); - } - } - return PRIORITY_DONTCARE; -} - -long ModuleManager::PriorityBefore(const std::string &modulename) -{ - for (unsigned int j = 0; j < Instance->Config->module_names.size(); j++) - { - if (Instance->Config->module_names[j] == modulename) - { - return ((j << 8) | PRIORITY_BEFORE); - } - } - return PRIORITY_DONTCARE; -} - bool ModuleManager::PublishFeature(const std::string &FeatureName, Module* Mod) { if (Features.find(FeatureName) == Features.end()) diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index 90517255e..94891af7c 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -75,11 +75,9 @@ class ModuleAlias : public Module { ReadAliases(); pars.resize(MAXPARAMETERS); - } - void Implements(char* List) - { - List[I_OnPreCommand] = List[I_OnRehash] = 1; + Me->Modules->Attach(I_OnPreCommand, this); + Me->Modules->Attach(I_OnRehash, this); } virtual ~ModuleAlias() |