[CORE] implemented multiple configuration files loading

currently it's used to load the default [auth|world]server.conf.dist

but you can use sConfigMgr->LoadMore to load your custom config

in your modules to add/overwrite properties
This commit is contained in:
Yehonal
2016-07-30 18:14:38 +02:00
committed by Yehonal
parent 648163a2e0
commit 2ca258e179
5 changed files with 38 additions and 14 deletions

View File

@@ -104,7 +104,15 @@ extern int main(int argc, char** argv)
++count;
}
if (!sConfigMgr->LoadInitial(configFile))
std::string cfg_def_file=_TRINITY_REALM_CONFIG;
cfg_def_file += ".dist";
if (!sConfigMgr->LoadInitial(cfg_def_file.c_str())) {
printf("Invalid or missing default configuration file : %s\n", cfg_def_file.c_str());
return 1;
}
if (!sConfigMgr->LoadMore(configFile))
{
printf("Invalid or missing configuration file : %s\n", configFile);
printf("Verify that the file exists and has \'[authserver]\' written in the top of the file!\n");

View File

@@ -429,7 +429,7 @@ void World::LoadConfigSettings(bool reload)
{
if (!sConfigMgr->Reload())
{
sLog->outError("World settings reload fail: can't read settings from %s.", sConfigMgr->GetFilename().c_str());
sLog->outError("World settings reload fail: can't read settings.");
return;
}

View File

@@ -49,10 +49,9 @@ bool ConfigMgr::LoadInitial(char const* file)
GuardType guard(_configLock);
_filename = file;
_config.reset(new ACE_Configuration_Heap());
if (_config->open() == 0)
if (LoadData(_filename.c_str()))
if (LoadData(file))
return true;
_config.reset();
@@ -71,11 +70,25 @@ bool ConfigMgr::LoadMore(char const* file)
bool ConfigMgr::Reload()
{
return LoadInitial(_filename.c_str());
for(std::vector<std::string>::iterator it = _confFiles.begin(); it != _confFiles.end(); ++it) {
if (it==_confFiles.begin()) {
if (!LoadInitial((*it).c_str()))
return false;
} else {
if (!LoadMore((*it).c_str()))
return false;
}
}
return true;
}
bool ConfigMgr::LoadData(char const* file)
{
if(std::find(_confFiles.begin(), _confFiles.end(), file) == _confFiles.end()) {
_confFiles.push_back(file);
}
ACE_Ini_ImpExp config_importer(*_config.get());
if (config_importer.import_config(file) == 0)
return true;
@@ -112,12 +125,6 @@ float ConfigMgr::GetFloatDefault(const char* name, float def)
return GetValueHelper(name, val) ? (float)atof(val.c_str()) : def;
}
std::string const& ConfigMgr::GetFilename()
{
GuardType guard(_configLock);
return _filename;
}
std::list<std::string> ConfigMgr::GetKeysByString(std::string const& name)
{
GuardType guard(_configLock);

View File

@@ -21,6 +21,7 @@
#include <string>
#include <list>
#include <vector>
#include <ace/Singleton.h>
#include <ace/Configuration_Import_Export.h>
#include <ace/Thread_Mutex.h>
@@ -55,7 +56,6 @@ public:
int GetIntDefault(const char* name, int def);
float GetFloatDefault(const char* name, float def);
std::string const& GetFilename();
std::list<std::string> GetKeysByString(std::string const& name);
private:
@@ -65,7 +65,7 @@ private:
typedef ACE_Thread_Mutex LockType;
typedef ACE_Guard<LockType> GuardType;
std::string _filename;
std::vector<std::string> _confFiles;
Config _config;
LockType _configLock;

View File

@@ -125,12 +125,21 @@ extern int main(int argc, char** argv)
++c;
}
if (!sConfigMgr->LoadInitial(cfg_file))
std::string cfg_def_file=_TRINITY_CORE_CONFIG;
cfg_def_file += ".dist";
if (!sConfigMgr->LoadInitial(cfg_def_file.c_str())) {
printf("Invalid or missing default configuration file : %s\n", cfg_def_file.c_str());
return 1;
}
if (!sConfigMgr->LoadMore(cfg_file))
{
printf("Invalid or missing configuration file : %s\n", cfg_file);
printf("Verify that the file exists and has \'[worldserver]' written in the top of the file!\n");
return 1;
}
sLog->outString("Using configuration file %s.", cfg_file);
sLog->outString("Using SSL version: %s (library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION));