diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-08 12:17:13 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2005-04-08 12:17:13 +0000 |
commit | 034c2c65df4fad4efe08f2a3f332b5772d59c607 (patch) | |
tree | fa13512af9e03835695dd95b92dabea77c36e74d /src/inspircd.cpp | |
parent | 755d67224f033aaa9b4ef3d2dd00f46bb8c19dc2 (diff) |
rehashing now adds and removes modules
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1009 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspircd.cpp')
-rw-r--r-- | src/inspircd.cpp | 76 |
1 files changed, 76 insertions, 0 deletions
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<std::string> old_module_names, new_module_names, added_modules, removed_modules; + + // store the old module names + for (std::vector<std::string>::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<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++) + { + bool added = true; + for (std::vector<std::string>::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<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++) + { + bool removed = true; + for (std::vector<std::string>::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<std::string>::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<std::string>::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 */ |