1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-25 05:57:45 +00:00

cleanup db connection config

This commit is contained in:
NotAdam 2019-01-07 23:16:01 +11:00
parent bf0324cfea
commit eb56f5fda2
6 changed files with 27 additions and 44 deletions

View file

@ -76,7 +76,7 @@ void reloadConfig()
if( failedLoad ) if( failedLoad )
{ {
Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); Logger::fatal( "If this is the first time starting the server, we've copied the default configs for your editing pleasure." );
throw "Error loading config"; throw "Error loading config";
} }
@ -128,23 +128,14 @@ bool loadSettings( int32_t argc, char* argv[] )
Sapphire::Db::DbLoader loader; Sapphire::Db::DbLoader loader;
Sapphire::Db::ConnectionInfo info; loader.addDb( g_charaDb, m_config.global.database );
info.password = m_config.global.database.password;
info.host = m_config.global.database.host;
info.database = m_config.global.database.database;
info.port = m_config.global.database.port;
info.user = m_config.global.database.username;
info.syncThreads = m_config.global.database.syncThreads;
info.asyncThreads = m_config.global.database.asyncThreads;
loader.addDb( g_charaDb, info );
if( !loader.initDbs() ) if( !loader.initDbs() )
return false; return false;
server.config.port = m_config.network.listenPort; server.config.port = m_config.network.listenPort;
server.config.address = m_config.network.listenIP; server.config.address = m_config.network.listenIP;
Logger::info( "Database: Connected to {0}:{1}", info.host, info.port ); Logger::info( "Database: Connected to {0}:{1}", m_config.global.database.host, m_config.global.database.port );
return true; return true;
} }

View file

@ -1,20 +1,13 @@
#ifndef SAPPHIRE_CONFIGDEF_H #ifndef SAPPHIRE_CONFIGDEF_H
#define SAPPHIRE_CONFIGDEF_H #define SAPPHIRE_CONFIGDEF_H
#include <Database/DbCommon.h>
namespace Sapphire::Common::Config namespace Sapphire::Common::Config
{ {
struct GlobalConfig struct GlobalConfig
{ {
struct Database Sapphire::Db::ConnectionInfo database;
{
std::string host;
uint16_t port;
std::string database;
std::string username;
std::string password;
uint8_t syncThreads;
uint8_t asyncThreads;
} database;
struct Parameters struct Parameters
{ {

View file

@ -49,7 +49,7 @@ bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config
config.database.host = getValue< std::string >( "Database", "Host", "127.0.0.1" ); config.database.host = getValue< std::string >( "Database", "Host", "127.0.0.1" );
config.database.port = getValue< uint16_t >( "Database", "Port", 3306 ); config.database.port = getValue< uint16_t >( "Database", "Port", 3306 );
config.database.database = getValue< std::string >( "Database", "Database", "sapphire" ); config.database.database = getValue< std::string >( "Database", "Database", "sapphire" );
config.database.username = getValue< std::string >( "Database", "Username", "sapphire" ); config.database.user = getValue< std::string >( "Database", "Username", "sapphire" );
config.database.password = getValue< std::string >( "Database", "Password", "" ); config.database.password = getValue< std::string >( "Database", "Password", "" );
config.database.syncThreads = getValue< uint8_t >( "Database", "SyncThreads", 2 ); config.database.syncThreads = getValue< uint8_t >( "Database", "SyncThreads", 2 );
config.database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 ); config.database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 );

View file

@ -0,0 +1,18 @@
#ifndef SAPPHIRE_DBCOMMON_H
#define SAPPHIRE_DBCOMMON_H
namespace Sapphire::Db
{
struct ConnectionInfo
{
std::string user;
std::string password;
std::string database;
std::string host;
uint16_t port;
uint8_t syncThreads;
uint8_t asyncThreads;
};
}
#endif //SAPPHIRE_DBCOMMON_H

View file

@ -7,6 +7,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "Util/LockedWaitQueue.h" #include "Util/LockedWaitQueue.h"
#include "DbCommon.h"
namespace Mysql namespace Mysql
{ {
@ -31,17 +32,6 @@ namespace Sapphire::Db
CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNC CONNECTION_BOTH = CONNECTION_ASYNC | CONNECTION_SYNC
}; };
struct ConnectionInfo
{
std::string user;
std::string password;
std::string database;
std::string host;
uint16_t port;
uint8_t syncThreads;
uint8_t asyncThreads;
};
using PreparedStatementMap = std::map< uint32_t, std::pair< std::string, ConnectionFlags > >; using PreparedStatementMap = std::map< uint32_t, std::pair< std::string, ConnectionFlags > >;
class DbConnection : class DbConnection :

View file

@ -136,18 +136,9 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
} }
framework()->set< Data::ExdDataGenerated >( pExdData ); framework()->set< Data::ExdDataGenerated >( pExdData );
Sapphire::Db::ConnectionInfo info;
info.password = m_config.global.database.password;
info.host = m_config.global.database.host;
info.database = m_config.global.database.database;
info.port = m_config.global.database.port;
info.user = m_config.global.database.username;
info.syncThreads = m_config.global.database.syncThreads;
info.asyncThreads = m_config.global.database.asyncThreads;
auto pDb = std::make_shared< Db::DbWorkerPool< Db::ZoneDbConnection > >(); auto pDb = std::make_shared< Db::DbWorkerPool< Db::ZoneDbConnection > >();
Sapphire::Db::DbLoader loader; Sapphire::Db::DbLoader loader;
loader.addDb( *pDb, info ); loader.addDb( *pDb, m_config.global.database );
if( !loader.initDbs() ) if( !loader.initDbs() )
{ {
Logger::fatal( "Database not initialized properly!" ); Logger::fatal( "Database not initialized properly!" );