diff options
-rw-r--r-- | src/common/Configuration/Config.cpp | 80 | ||||
-rw-r--r-- | src/common/Configuration/Config.h | 5 | ||||
-rw-r--r-- | src/server/game/World/World.cpp | 8 |
3 files changed, 64 insertions, 29 deletions
diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp index 408e64ffdd7..12d5e6a1118 100644 --- a/src/common/Configuration/Config.cpp +++ b/src/common/Configuration/Config.cpp @@ -29,41 +29,65 @@ namespace bpt = boost::property_tree; namespace { std::string _filename; + std::vector<std::string> _additonalFiles; std::vector<std::string> _args; bpt::ptree _config; std::mutex _configLock; + + bool LoadFile(std::string const& file, bpt::ptree& fullTree, std::string& error) + { + try + { + bpt::ini_parser::read_ini(file, fullTree); + + if (fullTree.empty()) + { + error = "empty file (" + file + ")"; + return false; + } + } + catch (bpt::ini_parser::ini_parser_error const& e) + { + if (e.line() == 0) + error = e.message() + " (" + e.filename() + ")"; + else + error = e.message() + " (" + e.filename() + ":" + std::to_string(e.line()) + ")"; + return false; + } + + return true; + } } -bool ConfigMgr::LoadInitial(std::string const& file, std::vector<std::string> args, +bool ConfigMgr::LoadInitial(std::string file, std::vector<std::string> args, std::string& error) { std::lock_guard<std::mutex> lock(_configLock); - _filename = file; - _args = args; + _filename = std::move(file); + _args = std::move(args); - try - { - bpt::ptree fullTree; - bpt::ini_parser::read_ini(file, fullTree); + bpt::ptree fullTree; + if (!LoadFile(_filename, fullTree, error)) + return false; - if (fullTree.empty()) - { - error = "empty file (" + file + ")"; - return false; - } + // Since we're using only one section per config file, we skip the section and have direct property access + _config = fullTree.begin()->second; - // Since we're using only one section per config file, we skip the section and have direct property access - _config = fullTree.begin()->second; - } - catch (bpt::ini_parser::ini_parser_error const& e) - { - if (e.line() == 0) - error = e.message() + " (" + e.filename() + ")"; - else - error = e.message() + " (" + e.filename() + ":" + std::to_string(e.line()) + ")"; + return true; +} + +bool ConfigMgr::LoadAdditionalFile(std::string file, bool keepOnReload, std::string& error) +{ + bpt::ptree fullTree; + if (!LoadFile(file, fullTree, error)) return false; - } + + for (bpt::ptree::value_type const& child : fullTree.begin()->second) + _config.put_child(bpt::ptree::path_type(child.first, '/'), child.second); + + if (keepOnReload) + _additonalFiles.emplace_back(std::move(file)); return true; } @@ -74,9 +98,17 @@ ConfigMgr* ConfigMgr::instance() return &instance; } -bool ConfigMgr::Reload(std::string& error) +bool ConfigMgr::Reload(std::vector<std::string>& errors) { - return LoadInitial(_filename, std::move(_args), error); + std::string error; + if (!LoadInitial(_filename, std::move(_args), error)) + errors.push_back(std::move(error)); + + for (std::string const& additionalFile : _additonalFiles) + if (!LoadAdditionalFile(additionalFile, false, error)) + errors.push_back(std::move(error)); + + return errors.empty(); } template<class T> diff --git a/src/common/Configuration/Config.h b/src/common/Configuration/Config.h index 4c42b2e7b34..6a37be56bd6 100644 --- a/src/common/Configuration/Config.h +++ b/src/common/Configuration/Config.h @@ -31,11 +31,12 @@ class TC_COMMON_API ConfigMgr public: /// Method used only for loading main configuration files (bnetserver.conf and worldserver.conf) - bool LoadInitial(std::string const& file, std::vector<std::string> args, std::string& error); + bool LoadInitial(std::string file, std::vector<std::string> args, std::string& error); + bool LoadAdditionalFile(std::string file, bool keepOnReload, std::string& error); static ConfigMgr* instance(); - bool Reload(std::string& error); + bool Reload(std::vector<std::string>& errors); std::string GetStringDefault(std::string const& name, const std::string& def, bool quiet = false) const; bool GetBoolDefault(std::string const& name, bool def, bool quiet = false) const; diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 9e03fa5ad10..2383642b917 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -534,10 +534,12 @@ void World::LoadConfigSettings(bool reload) { if (reload) { - std::string configError; - if (!sConfigMgr->Reload(configError)) + std::vector<std::string> configErrors; + if (!sConfigMgr->Reload(configErrors)) { - TC_LOG_ERROR("misc", "World settings reload fail: %s.", configError.c_str()); + for (std::string const& configError : configErrors) + TC_LOG_ERROR("misc", "World settings reload fail: %s.", configError.c_str()); + return; } sLog->LoadFromConfig(); |