aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/Configuration/Config.cpp72
-rw-r--r--src/common/Configuration/Config.h10
-rw-r--r--src/server/worldserver/Main.cpp2
3 files changed, 46 insertions, 38 deletions
diff --git a/src/common/Configuration/Config.cpp b/src/common/Configuration/Config.cpp
index aafd902c558..abf64c5c200 100644
--- a/src/common/Configuration/Config.cpp
+++ b/src/common/Configuration/Config.cpp
@@ -68,64 +68,70 @@ bool ConfigMgr::Reload(std::string& error)
return LoadInitial(_filename, error);
}
-std::string ConfigMgr::GetStringDefault(std::string const& name, const std::string& def) const
+template<class T>
+T ConfigMgr::GetValueDefault(std::string const& name, T def) const
{
try
{
- std::string value = _config.get<std::string>(ptree::path_type(name, '/'));
- value.erase(std::remove(value.begin(), value.end(), '"'), value.end());
- return value;
+ return _config.get<T>(ptree::path_type(name, '/'));
}
catch (boost::property_tree::ptree_bad_path)
{
TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %s\" to this file",
- name.c_str(), _filename.c_str(), name.c_str(), def.c_str());
- return def;
+ name.c_str(), _filename.c_str(), name.c_str(), std::to_string(def).c_str());
+ }
+ catch (boost::property_tree::ptree_bad_data)
+ {
+ TC_LOG_ERROR("server.loading", "Bad value defined for name %s in config file %s, going to use %s instead",
+ name.c_str(), _filename.c_str(), std::to_string(def).c_str());
}
+
+ return def;
}
-bool ConfigMgr::GetBoolDefault(std::string const& name, bool def) const
+template<>
+std::string ConfigMgr::GetValueDefault<std::string>(std::string const& name, std::string def) const
{
try
{
- std::string val = _config.get<std::string>(ptree::path_type(name, '/'));
- val.erase(std::remove(val.begin(), val.end(), '"'), val.end());
- return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || val == "1");
+ return _config.get<std::string>(ptree::path_type(name, '/'));
}
catch (boost::property_tree::ptree_bad_path)
{
- TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %d\" to this file",
- name.c_str(), _filename.c_str(), name.c_str(), def ? 1 : 0);
- return def;
+ TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %s\" to this file",
+ name.c_str(), _filename.c_str(), name.c_str(), def.c_str());
+ }
+ catch (boost::property_tree::ptree_bad_data)
+ {
+ TC_LOG_ERROR("server.loading", "Bad value defined for name %s in config file %s, going to use %s instead",
+ name.c_str(), _filename.c_str(), def.c_str());
}
+
+ return def;
+}
+
+std::string ConfigMgr::GetStringDefault(std::string const& name, const std::string& def) const
+{
+ std::string val = GetValueDefault(name, def);
+ val.erase(std::remove(val.begin(), val.end(), '"'), val.end());
+ return val;
+}
+
+bool ConfigMgr::GetBoolDefault(std::string const& name, bool def) const
+{
+ std::string val = GetValueDefault(name, std::string(def ? "1" : "0"));
+ val.erase(std::remove(val.begin(), val.end(), '"'), val.end());
+ return (val == "true" || val == "TRUE" || val == "yes" || val == "YES" || val == "1");
}
int ConfigMgr::GetIntDefault(std::string const& name, int def) const
{
- try
- {
- return _config.get<int>(ptree::path_type(name, '/'));
- }
- catch (boost::property_tree::ptree_bad_path)
- {
- TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %d\" to this file",
- name.c_str(), _filename.c_str(), name.c_str(), def);
- return def;
- }
+ return GetValueDefault(name, def);
}
float ConfigMgr::GetFloatDefault(std::string const& name, float def) const
{
- try
- {
- return _config.get<float>(ptree::path_type(name, '/'));
- }
- catch (boost::property_tree::ptree_bad_path)
- {
- TC_LOG_WARN("server.loading", "Missing name %s in config file %s, add \"%s = %f\" to this file",
- name.c_str(), _filename.c_str(), name.c_str(), def);
- return def;
- }
+ return GetValueDefault(name, def);
}
std::string const& ConfigMgr::GetFilename()
diff --git a/src/common/Configuration/Config.h b/src/common/Configuration/Config.h
index ff6d279f9ce..10113cd88d3 100644
--- a/src/common/Configuration/Config.h
+++ b/src/common/Configuration/Config.h
@@ -28,8 +28,10 @@
class TC_COMMON_API ConfigMgr
{
- ConfigMgr() { }
- ~ConfigMgr() { }
+ ConfigMgr() = default;
+ ConfigMgr(ConfigMgr const&) = delete;
+ ConfigMgr& operator=(ConfigMgr const&) = delete;
+ ~ConfigMgr() = default;
public:
/// Method used only for loading main configuration files (authserver.conf and worldserver.conf)
@@ -52,8 +54,8 @@ private:
boost::property_tree::ptree _config;
std::mutex _configLock;
- ConfigMgr(ConfigMgr const&);
- ConfigMgr& operator=(ConfigMgr const&);
+ template<class T>
+ T GetValueDefault(std::string const& name, T def) const;
};
#define sConfigMgr ConfigMgr::instance()
diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp
index a81401bf7b8..c047c1fafc3 100644
--- a/src/server/worldserver/Main.cpp
+++ b/src/server/worldserver/Main.cpp
@@ -226,7 +226,7 @@ extern int main(int argc, char** argv)
if (networkThreads <= 0)
{
- TC_LOG_ERROR("server.worldserver", "Network.Threads cannot be less than 0");
+ TC_LOG_ERROR("server.worldserver", "Network.Threads must be greater than 0");
return false;
}