* Fixed/improved the config library: Removed useless methods and fixed the existing.

* Few related changes to make the rest of the core reflect the changes.

--HG--
branch : trunk
This commit is contained in:
XTZGZoReX
2009-03-18 20:46:39 +01:00
parent 5f2e9f1ed1
commit 5184783bd1
5 changed files with 46 additions and 122 deletions

View File

@@ -625,17 +625,18 @@ extern void AddSC_zulaman();
void LoadDatabase()
{
//Get db string from file
char const* dbstring = NULL;
std::string dbstring;
TScriptConfig.GetStringDefault("WorldDatabaseInfo", "");
if (!TScriptConfig.GetString("WorldDatabaseInfo", &dbstring) )
if (dbstring.empty() )
{
error_log("TSCR: Missing world database info from configuration file. Load database aborted.");
return;
}
//Initialize connection to DB
if (dbstring && TScriptDB.Initialize(dbstring) )
outstring_log("TSCR: TrinityScript database: %s",dbstring);
if (!dbstring.empty() && TScriptDB.Initialize(dbstring.c_str()) )
outstring_log("TSCR: TrinityScript database: %s",dbstring.c_str());
else
{
error_log("TSCR: Unable to connect to Database. Load database aborted.");

View File

@@ -403,14 +403,15 @@ int Master::Run()
/// Initialize connection to the databases
bool Master::_StartDB()
{
///- Get world database info from configuration file
std::string dbstring;
if(!sConfig.GetString("WorldDatabaseInfo", &dbstring))
///- Get world database info from configuration file
dbstring = sConfig.GetStringDefault("WorldDatabaseInfo", "");
if(dbstring.empty())
{
sLog.outError("Database not specified in configuration file");
return false;
}
sLog.outString("World Database: %s", dbstring.c_str());
///- Initialise the world database
if(!WorldDatabase.Initialize(dbstring.c_str()))
@@ -419,12 +420,13 @@ bool Master::_StartDB()
return false;
}
if(!sConfig.GetString("CharacterDatabaseInfo", &dbstring))
///- Get character database info from configuration file
dbstring = sConfig.GetStringDefault("CharacterDatabaseInfo", "");
if(dbstring.empty())
{
sLog.outError("Character Database not specified in configuration file");
return false;
}
sLog.outString("Character Database: %s", dbstring.c_str());
///- Initialise the Character database
if(!CharacterDatabase.Initialize(dbstring.c_str()))
@@ -434,14 +436,14 @@ bool Master::_StartDB()
}
///- Get login database info from configuration file
if(!sConfig.GetString("LoginDatabaseInfo", &dbstring))
dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
if(dbstring.empty())
{
sLog.outError("Login database not specified in configuration file");
return false;
}
///- Initialise the login database
sLog.outString("Login Database: %s", dbstring.c_str() );
if(!LoginDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Cannot connect to login database %s",dbstring.c_str());

View File

@@ -57,7 +57,7 @@ char serviceDescription[] = "Massive Network Game Object Server";
int m_ServiceStatus = -1;
#endif
bool StartDB(std::string &dbstring);
bool StartDB();
void UnhookSignals();
void HookSignals();
@@ -179,8 +179,7 @@ extern int main(int argc, char **argv)
}
///- Initialize the database connection
std::string dbstring;
if(!StartDB(dbstring))
if(!StartDB())
return 1;
///- Get the list of realms for the server
@@ -304,15 +303,15 @@ void OnSignal(int s)
}
/// Initialize connection to the database
bool StartDB(std::string &dbstring)
bool StartDB()
{
if(!sConfig.GetString("LoginDatabaseInfo", &dbstring))
std::string dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", "");
if(dbstring.empty())
{
sLog.outError("Database not specified");
return false;
}
sLog.outString("Database: %s", dbstring.c_str() );
if(!LoginDatabase.Initialize(dbstring.c_str()))
{
sLog.outError("Cannot connect to database");

View File

@@ -60,118 +60,48 @@ bool Config::Reload()
return true;
}
bool Config::GetString(const char* name, std::string *value)
{
if(!mConf)
return false;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if(!node || !node->getValue())
return false;
*value = node->getValue();
return true;
}
bool Config::GetString(const char* name, char const **value)
{
if(!mConf)
return false;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if(!node || !node->getValue())
return false;
*value = node->getValue();
return true;
}
std::string Config::GetStringDefault(const char* name, const char* def)
std::string Config::GetStringDefault(const char * name, std::string def)
{
if(!mConf)
return std::string(def);
DOTCONFDocumentNode const *node = mConf->findNode(name);
const DOTCONFDocumentNode * node = mConf->findNode(name);
if(!node || !node->getValue())
return std::string(def);
return std::string(node->getValue());
}
};
bool Config::GetBool(const char* name, bool *value)
bool Config::GetBoolDefault(const char * name, const bool def)
{
if(!mConf)
return false;
DOTCONFDocumentNode const *node = mConf->findNode(name);
const DOTCONFDocumentNode * node = mConf->findNode(name);
if(!node || !node->getValue())
return false;
const char* str = node->getValue();
return def;
const char * str = node->getValue();
if(strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
strcmp(str, "1") == 0)
{
*value = true;
}
return true;
else
*value = false;
return false;
};
return true;
}
bool Config::GetBoolDefault(const char* name, const bool def)
{
bool val;
return GetBool(name, &val) ? val : def;
}
bool Config::GetInt(const char* name, int *value)
int32 Config::GetIntDefault(const char * name, const int32 def)
{
if(!mConf)
return false;
DOTCONFDocumentNode const *node = mConf->findNode(name);
return def;
const DOTCONFDocumentNode * node = mConf->findNode(name);
if(!node || !node->getValue())
return false;
return def;
return atoi(node->getValue());
};
*value = atoi(node->getValue());
return true;
}
bool Config::GetFloat(const char* name, float *value)
float Config::GetFloatDefault(const char * name, const float def)
{
if(!mConf)
return false;
DOTCONFDocumentNode const *node = mConf->findNode(name);
return def;
const DOTCONFDocumentNode * node = mConf->findNode(name);
if(!node || !node->getValue())
return false;
*value = atof(node->getValue());
return true;
}
int Config::GetIntDefault(const char* name, const int def)
{
int val;
return GetInt(name, &val) ? val : def;
}
float Config::GetFloatDefault(const char* name, const float def)
{
float val;
return (GetFloat(name, &val) ? val : def);
}
return def;
return atof(node->getValue());
};

View File

@@ -34,19 +34,11 @@ class TRINITY_DLL_SPEC Config
bool SetSource(const char *file, bool ignorecase = true);
bool Reload();
bool GetString(const char* name, std::string *value);
bool GetString(const char* name, char const **value);
std::string GetStringDefault(const char* name, const char* def);
bool GetBool(const char* name, bool *value);
bool GetBoolDefault(const char* name, const bool def = false);
bool GetInt(const char* name, int *value);
int GetIntDefault(const char* name, const int def);
bool GetFloat(const char* name, float *value);
float GetFloatDefault(const char* name, const float def);
std::string GetStringDefault(const char * name, std::string def);
bool GetBoolDefault(const char * name, const bool def);
int32 GetIntDefault(const char * name, const int32 def);
float GetFloatDefault(const char * name, const float def);
std::string GetFilename() const { return mFilename; }
private: