From 034c2c65df4fad4efe08f2a3f332b5772d59c607 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 8 Apr 2005 12:17:13 +0000 Subject: [PATCH] rehashing now adds and removes modules git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1009 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 45f1ba474..c0cebd522 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -447,6 +447,82 @@ void ReadConfig(bool bail, userrec* user) log(DEFAULT,"Applying K lines, Q lines and Z lines..."); apply_lines(); log(DEFAULT,"Done reading configuration file, InspIRCd is now running."); + if (!bail) + { + log(DEFAULT,"Adding and removing modules due to rehash..."); + + std::vector old_module_names, new_module_names, added_modules, removed_modules; + + // store the old module names + for (std::vector::iterator t = module_names.begin(); t != module_names.end(); t++) + { + old_module_names.push_back(*t); + } + + // get the new module names + for (int count2 = 0; count2 < ConfValueEnum("module",&config_f); count2++) + { + ConfValue("module","name",count2,Value,&config_f); + new_module_names.push_back(Value); + } + + // now create a list of new modules that are due to be loaded + // and a seperate list of modules which are due to be unloaded + for (std::vector::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++) + { + bool added = true; + for (std::vector::iterator old = old_module_names.begin(); old != old_module_names.end(); old++) + { + if (*old == *_new) + added = false; + } + if (added) + added_modules.push_back(*_new); + } + for (std::vector::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++) + { + bool removed = true; + for (std::vector::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++) + { + if (*newm == *oldm) + removed = false; + } + if (removed) + removed_modules.push_back(*oldm); + } + // now we have added_modules, a vector of modules to be loaded, and removed_modules, a vector of modules + // to be removed. + int rem = 0, add = 0; + if (!removed_modules.empty()) + for (std::vector::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++) + { + if (UnloadModule(removing->c_str())) + { + WriteOpers("*** REHASH UNLOADED MODULE: %s",removing->c_str()); + WriteServ(user->fd,"973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str()); + rem++; + } + else + { + WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ModuleError()); + } + } + if (!added_modules.empty()) + for (std::vector::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++) + { + if (LoadModule(adding->c_str())) + { + WriteOpers("*** REHASH LOADED MODULE: %s",adding->c_str()); + WriteServ(user->fd,"975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str()); + add++; + } + else + { + WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ModuleError()); + } + } + log(DEFAULT,"Successfully unloaded %d of %d modules and loaded %d of %d modules.",rem,removed_modules.size(),add,added_modules.size()); + } } /* write formatted text to a socket, in same format as printf */ -- 2.39.5