diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bindings/scripts/ScriptMgr.cpp | 9 | ||||
| -rw-r--r-- | src/mangosd/Master.cpp | 16 | ||||
| -rw-r--r-- | src/realmd/Main.cpp | 11 | ||||
| -rw-r--r-- | src/shared/Config/Config.cpp | 114 | ||||
| -rw-r--r-- | src/shared/Config/Config.h | 18 |
5 files changed, 46 insertions, 122 deletions
diff --git a/src/bindings/scripts/ScriptMgr.cpp b/src/bindings/scripts/ScriptMgr.cpp index fba8143f2f3..0265f2ad690 100644 --- a/src/bindings/scripts/ScriptMgr.cpp +++ b/src/bindings/scripts/ScriptMgr.cpp @@ -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."); diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp index 96e7c28b8fb..eb82d776255 100644 --- a/src/mangosd/Master.cpp +++ b/src/mangosd/Master.cpp @@ -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()); diff --git a/src/realmd/Main.cpp b/src/realmd/Main.cpp index f36558e6fba..898a87af2d7 100644 --- a/src/realmd/Main.cpp +++ b/src/realmd/Main.cpp @@ -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"); diff --git a/src/shared/Config/Config.cpp b/src/shared/Config/Config.cpp index 52fca953f64..b56b804b50a 100644 --- a/src/shared/Config/Config.cpp +++ b/src/shared/Config/Config.cpp @@ -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 true; -} - - -bool Config::GetBoolDefault(const char* name, const bool def) -{ - bool val; - return GetBool(name, &val) ? val : def; -} - + return false; +}; -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; - - *value = atoi(node->getValue()); - - return true; -} - + return def; + return atoi(node->getValue()); +}; -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()); +}; diff --git a/src/shared/Config/Config.h b/src/shared/Config/Config.h index 2c709f02ae5..cb7a45027df 100644 --- a/src/shared/Config/Config.h +++ b/src/shared/Config/Config.h @@ -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: |
