diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-25 16:31:05 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-01-25 16:31:05 +0000 |
commit | cdaf7ac3781a0ea1bfbfac85c4a428ddea7725f9 (patch) | |
tree | 84758aa082957cf9c19fa59df9b55d06e33fb9dd | |
parent | 51fff2f99dc4692cfbb14eda789d615280d79365 (diff) |
Added PRIORITY_BEFORE and PRIORITY_AFTER (see src/modules/m_hostchange.cpp for how it works, function Prioritize())
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2889 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd.h | 2 | ||||
-rw-r--r-- | include/modules.h | 21 | ||||
-rw-r--r-- | src/inspircd.cpp | 56 | ||||
-rw-r--r-- | src/modules.cpp | 24 | ||||
-rw-r--r-- | src/modules/m_hostchange.cpp | 5 |
5 files changed, 107 insertions, 1 deletions
diff --git a/include/inspircd.h b/include/inspircd.h index fd2255046..68289d5ee 100644 --- a/include/inspircd.h +++ b/include/inspircd.h @@ -121,6 +121,8 @@ class InspIRCd bool UnloadModule(const char* filename); void MoveToLast(std::string modulename); void MoveToFirst(std::string modulename); + void MoveAfter(std::string modulename, std::string after); + void MoveBefore(std::string modulename, std::string before); InspIRCd(int argc, char** argv); int Run(); diff --git a/include/modules.h b/include/modules.h index 6afb0e181..5939ba0bb 100644 --- a/include/modules.h +++ b/include/modules.h @@ -272,7 +272,7 @@ class ExtMode : public classbase }; -enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST }; +enum Priority { PRIORITY_FIRST, PRIORITY_DONTCARE, PRIORITY_LAST, PRIORITY_BEFORE, PRIORITY_AFTER }; enum Implementation { I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUserJoin, I_OnUserPart, I_OnRehash, I_OnServerRaw, I_OnExtendedMode, I_OnUserPreJoin, I_OnUserPreKick, I_OnUserKick, I_OnOper, I_OnInfo, I_OnWhois, I_OnUserPreInvite, @@ -1163,6 +1163,25 @@ class Server : public classbase * of the IRC server, as read from the config file by the core. */ ServerConfig* GetConfig(); + + /** 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'. + * @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(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'. + * @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(std::string modulename); + /** Sends text to all opers. * This method sends a server notice to all opers with the usermode +s. */ diff --git a/src/inspircd.cpp b/src/inspircd.cpp index ac94b6f90..6b43ab921 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -329,6 +329,40 @@ void InspIRCd::MoveTo(std::string modulename,int slot) } } +void InspIRCd::MoveAfter(std::string modulename, std::string after) +{ + log(DEBUG,"Move %s after %s...",modulename.c_str(),after.c_str()); + for (unsigned int v = 0; v < Config->module_names.size(); v++) + { + log(DEBUG,"Curr=%s after=%s v=%d",Config->module_names[v].c_str(),after.c_str(),v); + if (Config->module_names[v] == after) + { + MoveTo(modulename, v); + return; + } + } +} + +void InspIRCd::MoveBefore(std::string modulename, std::string before) +{ + log(DEBUG,"Move %s before %s...",modulename.c_str(),before.c_str()); + for (unsigned int v = 0; v < Config->module_names.size(); v++) + { + if (Config->module_names[v] == before) + { + if (v > 0) + { + MoveTo(modulename, v-1); + } + else + { + MoveTo(modulename, v); + } + return; + } + } +} + void InspIRCd::MoveToFirst(std::string modulename) { MoveTo(modulename,0); @@ -492,6 +526,8 @@ bool InspIRCd::LoadModule(const char* filename) // 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 < Config->module_names.size(); j++) { if (modules[j]->Prioritize() == PRIORITY_LAST) @@ -502,6 +538,18 @@ bool InspIRCd::LoadModule(const char* filename) { put_to_front.push_back(Config->module_names[j]); } + else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_BEFORE) + { + log(DEBUG,"Module %d wants PRIORITY_BEFORE",j); + put_before[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8]; + log(DEBUG,"Before: %s",Config->module_names[modules[j]->Prioritize() >> 8].c_str()); + } + else if ((modules[j]->Prioritize() & 0xFF) == PRIORITY_AFTER) + { + log(DEBUG,"Module %d wants PRIORITY_AFTER",j); + put_after[Config->module_names[j]] = Config->module_names[modules[j]->Prioritize() >> 8]; + log(DEBUG,"After: %s",Config->module_names[modules[j]->Prioritize() >> 8].c_str()); + } } for (unsigned int j = 0; j < put_to_back.size(); j++) { @@ -511,6 +559,14 @@ bool InspIRCd::LoadModule(const char* filename) { 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); + } BuildISupport(); return true; } diff --git a/src/modules.cpp b/src/modules.cpp index 2cfb586ca..0a2115916 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -335,6 +335,30 @@ void Server::RemoveSocket(InspSocket* sock) } } +long Server::PriorityAfter(std::string modulename) +{ + for (unsigned int j = 0; j < Config->module_names.size(); j++) + { + if (Config->module_names[j] == modulename) + { + return ((j << 8) | PRIORITY_AFTER); + } + } + return PRIORITY_DONTCARE; +} + +long Server::PriorityBefore(std::string modulename) +{ + for (unsigned int j = 0; j < Config->module_names.size(); j++) + { + if (Config->module_names[j] == modulename) + { + return ((j << 8) | PRIORITY_BEFORE); + } + } + return PRIORITY_DONTCARE; +} + void Server::RehashServer() { WriteOpers("*** Rehashing config file"); diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 0d7060f8b..bd4a0ba6e 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -45,6 +45,11 @@ class ModuleHostChange : public Module delete Conf; } + Priority Prioritize() + { + return (Priority)Srv->PriorityAfter("m_cloaking.so"); + } + void Implements(char* List) { List[I_OnRehash] = List[I_OnUserConnect] = 1; |