mirror of
https://github.com/mangosfour/server.git
synced 2025-12-16 22:37:02 +00:00
[10081] Use ACE config library instead dotconfpp
NOTE: all config versions update because in old state
it's not compatible with new way loading.
Look for *.conf.dist.in chnages in commit for update configs.
Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
parent
e63dc32f4d
commit
41d178ca7b
7 changed files with 54 additions and 52 deletions
|
|
@ -1,7 +1,9 @@
|
|||
#####################################
|
||||
# MaNGOS Configuration file #
|
||||
#####################################
|
||||
ConfVersion=2010051901
|
||||
|
||||
[MangosdConf]
|
||||
ConfVersion=2010062001
|
||||
|
||||
###################################################################################################################
|
||||
# CONNECTIONS AND DIRECTORIES
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
############################################
|
||||
# MaNGOS realmd configuration file #
|
||||
############################################
|
||||
ConfVersion=2007062001
|
||||
|
||||
[RealmdConf]
|
||||
ConfVersion=2010062001
|
||||
|
||||
###################################################################################################################
|
||||
# REALMD SETTINGS
|
||||
|
|
|
|||
|
|
@ -17,12 +17,35 @@
|
|||
*/
|
||||
|
||||
#include "ConfigEnv.h"
|
||||
#include "ace/Configuration_Import_Export.h"
|
||||
|
||||
#include "Policies/SingletonImp.h"
|
||||
|
||||
INSTANTIATE_SINGLETON_1(Config);
|
||||
|
||||
static bool GetValueHelper(ACE_Configuration_Heap *mConf, const char *name, ACE_TString &result)
|
||||
{
|
||||
if (!mConf)
|
||||
return false;
|
||||
|
||||
ACE_TString section_name;
|
||||
ACE_Configuration_Section_Key section_key;
|
||||
ACE_Configuration_Section_Key root_key = mConf->root_section();
|
||||
|
||||
int i = 0;
|
||||
while (mConf->enumerate_sections(root_key, i, section_name) == 0)
|
||||
{
|
||||
mConf->open_section(root_key, section_name.c_str(), 0, section_key);
|
||||
if (mConf->get_string_value(section_key, name, result) == 0)
|
||||
return true;
|
||||
++i;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Config::Config()
|
||||
: mIgnoreCase(true), mConf(NULL)
|
||||
: mConf(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -31,9 +54,8 @@ Config::~Config()
|
|||
delete mConf;
|
||||
}
|
||||
|
||||
bool Config::SetSource(const char *file, bool ignorecase)
|
||||
bool Config::SetSource(const char *file)
|
||||
{
|
||||
mIgnoreCase = ignorecase;
|
||||
mFilename = file;
|
||||
|
||||
return Reload();
|
||||
|
|
@ -42,43 +64,33 @@ bool Config::SetSource(const char *file, bool ignorecase)
|
|||
bool Config::Reload()
|
||||
{
|
||||
delete mConf;
|
||||
mConf = new ACE_Configuration_Heap;
|
||||
|
||||
mConf = new DOTCONFDocument(mIgnoreCase ?
|
||||
DOTCONFDocument::CASEINSENSETIVE :
|
||||
DOTCONFDocument::CASESENSITIVE);
|
||||
|
||||
if (mConf->setContent(mFilename.c_str()) == -1)
|
||||
if (mConf->open() == 0)
|
||||
{
|
||||
delete mConf;
|
||||
mConf = NULL;
|
||||
return false;
|
||||
ACE_Ini_ImpExp config_importer(*mConf);
|
||||
if (config_importer.import_config(mFilename.c_str()) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
delete mConf;
|
||||
mConf = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Config::GetStringDefault(const char* name, const char* def)
|
||||
{
|
||||
if (!mConf)
|
||||
return std::string(def);
|
||||
|
||||
DOTCONFDocumentNode const *node = mConf->findNode(name);
|
||||
if (!node || !node->getValue())
|
||||
return std::string(def);
|
||||
|
||||
return std::string(node->getValue());
|
||||
ACE_TString val;
|
||||
return GetValueHelper(mConf, name, val) ? val.c_str() : def;
|
||||
}
|
||||
|
||||
bool Config::GetBoolDefault(const char* name, bool def)
|
||||
{
|
||||
if (!mConf)
|
||||
ACE_TString val;
|
||||
if (!GetValueHelper(mConf, name, val))
|
||||
return def;
|
||||
|
||||
DOTCONFDocumentNode const *node = mConf->findNode(name);
|
||||
if (!node || !node->getValue())
|
||||
return def;
|
||||
|
||||
const char* str = node->getValue();
|
||||
const char* str = val.c_str();
|
||||
if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
|
||||
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
|
||||
strcmp(str, "1") == 0)
|
||||
|
|
@ -90,25 +102,13 @@ bool Config::GetBoolDefault(const char* name, bool def)
|
|||
|
||||
int32 Config::GetIntDefault(const char* name, int32 def)
|
||||
{
|
||||
if (!mConf)
|
||||
return def;
|
||||
|
||||
DOTCONFDocumentNode const *node = mConf->findNode(name);
|
||||
if (!node || !node->getValue())
|
||||
return def;
|
||||
|
||||
return atoi(node->getValue());
|
||||
ACE_TString val;
|
||||
return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def;
|
||||
}
|
||||
|
||||
|
||||
float Config::GetFloatDefault(const char* name, float def)
|
||||
{
|
||||
if (!mConf)
|
||||
return def;
|
||||
|
||||
DOTCONFDocumentNode const *node = mConf->findNode(name);
|
||||
if (!node || !node->getValue())
|
||||
return def;
|
||||
|
||||
return (float)atof(node->getValue());
|
||||
ACE_TString val;
|
||||
return GetValueHelper(mConf, name, val) ? (float)atof(val.c_str()) : def;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include <Policies/Singleton.h>
|
||||
#include "Platform/Define.h"
|
||||
|
||||
class DOTCONFDocument;
|
||||
class ACE_Configuration_Heap;
|
||||
|
||||
class MANGOS_DLL_SPEC Config
|
||||
{
|
||||
|
|
@ -31,7 +31,7 @@ class MANGOS_DLL_SPEC Config
|
|||
Config();
|
||||
~Config();
|
||||
|
||||
bool SetSource(const char *file, bool ignorecase = true);
|
||||
bool SetSource(const char *file);
|
||||
bool Reload();
|
||||
|
||||
std::string GetStringDefault(const char* name, const char* def);
|
||||
|
|
@ -44,8 +44,7 @@ class MANGOS_DLL_SPEC Config
|
|||
private:
|
||||
|
||||
std::string mFilename;
|
||||
bool mIgnoreCase;
|
||||
DOTCONFDocument *mConf;
|
||||
ACE_Configuration_Heap *mConf;
|
||||
};
|
||||
|
||||
#define sConfig MaNGOS::Singleton<Config>::Instance()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
#define CONFIGENVIRONMENT_H
|
||||
|
||||
#include "Common.h"
|
||||
#include "dotconfpp/dotconfpp.h"
|
||||
#include "Config.h"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@
|
|||
// Format is YYYYMMDDRR where RR is the change in the conf file
|
||||
// for that day.
|
||||
#ifndef _MANGOSDCONFVERSION
|
||||
# define _MANGOSDCONFVERSION 2010051901
|
||||
# define _MANGOSDCONFVERSION 2010062001
|
||||
#endif
|
||||
#ifndef _REALMDCONFVERSION
|
||||
# define _REALMDCONFVERSION 2007062001
|
||||
# define _REALMDCONFVERSION 2010062001
|
||||
#endif
|
||||
|
||||
#if MANGOS_ENDIAN == MANGOS_BIGENDIAN
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "10080"
|
||||
#define REVISION_NR "10081"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue