mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 05:57:45 +00:00
initial move of all config items to a object
This commit is contained in:
parent
fc93308939
commit
3349ccce42
4 changed files with 178 additions and 8 deletions
96
src/common/Config/ConfigDef.h
Normal file
96
src/common/Config/ConfigDef.h
Normal file
|
@ -0,0 +1,96 @@
|
|||
#ifndef SAPPHIRE_CONFIGDEF_H
|
||||
#define SAPPHIRE_CONFIGDEF_H
|
||||
|
||||
namespace Sapphire::Common
|
||||
{
|
||||
struct Configuration
|
||||
{
|
||||
struct Database
|
||||
{
|
||||
std::string host;
|
||||
uint16_t port;
|
||||
std::string database;
|
||||
std::string username;
|
||||
std::string password;
|
||||
uint8_t syncThreads;
|
||||
uint8_t asyncThreads;
|
||||
|
||||
} database;
|
||||
|
||||
struct GlobalParameters
|
||||
{
|
||||
std::string serverSecret;
|
||||
std::string dataPath;
|
||||
} globalParameters;
|
||||
|
||||
struct GlobalNetwork
|
||||
{
|
||||
std::string zoneHost;
|
||||
uint16_t zonePort;
|
||||
|
||||
std::string lobbyHost;
|
||||
uint16_t lobbyPort;
|
||||
|
||||
std::string restHost;
|
||||
uint16_t restPort;
|
||||
} globalNetwork;
|
||||
|
||||
struct Lobby
|
||||
{
|
||||
uint16_t worldID;
|
||||
bool allowNoSessionConnect;
|
||||
std::string worldName;
|
||||
} lobby;
|
||||
|
||||
struct LobbyNetwork
|
||||
{
|
||||
std::string listenIp;
|
||||
uint16_t listenPort;
|
||||
} lobbyNetwork;
|
||||
|
||||
struct CharacterCreation
|
||||
{
|
||||
uint8_t defaultGMRank;
|
||||
} characterCreation;
|
||||
|
||||
struct RestNetwork
|
||||
{
|
||||
std::string listenIP;
|
||||
uint16_t listenPort;
|
||||
} restNetwork;
|
||||
|
||||
struct Scripts
|
||||
{
|
||||
std::string path;
|
||||
std::string cachePath;
|
||||
bool hotSwap;
|
||||
} scripts;
|
||||
|
||||
struct Network
|
||||
{
|
||||
Network() :
|
||||
disconnectTimeout( 20 )
|
||||
{}
|
||||
|
||||
uint16_t disconnectTimeout;
|
||||
} network;
|
||||
|
||||
struct ZoneNetwork
|
||||
{
|
||||
std::string listenIp;
|
||||
uint16_t listenPort;
|
||||
} zoneNetwork;
|
||||
|
||||
struct General
|
||||
{
|
||||
std::string motd;
|
||||
} general;
|
||||
|
||||
struct Housing
|
||||
{
|
||||
std::string defaultEstateName;
|
||||
} housing;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //SAPPHIRE_CONFIGDEF_H
|
|
@ -26,6 +26,8 @@ bool Sapphire::ConfigMgr::loadConfig( const std::string& configName )
|
|||
if( m_pInih->ParseError() < 0 )
|
||||
return false;
|
||||
|
||||
initConfigData();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -44,3 +46,68 @@ bool Sapphire::ConfigMgr::copyDefaultConfig( const std::string& configName )
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Sapphire::ConfigMgr::initConfigData()
|
||||
{
|
||||
m_pConfig = std::make_shared< Common::Configuration >();
|
||||
|
||||
// database
|
||||
m_pConfig->database.host = getValue< std::string >( "Database", "Host", "127.0.0.1" );
|
||||
m_pConfig->database.port = getValue< uint16_t >( "Database", "Port", 3306 );
|
||||
m_pConfig->database.database = getValue< std::string >( "Database", "Database", "sapphire" );
|
||||
m_pConfig->database.username = getValue< std::string >( "Database", "Username", "sapphire" );
|
||||
m_pConfig->database.password = getValue< std::string >( "Database", "Password", "" );
|
||||
m_pConfig->database.syncThreads = getValue< uint8_t >( "Database", "SyncThreads", 2 );
|
||||
m_pConfig->database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 );
|
||||
|
||||
// global parameters
|
||||
m_pConfig->globalParameters.dataPath = getValue< std::string >( "GlobalParameters", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" );
|
||||
m_pConfig->globalParameters.serverSecret = getValue< std::string >( "GlobalParameters", "ServerSecret", "default" );
|
||||
|
||||
// global network
|
||||
m_pConfig->globalNetwork.zoneHost = getValue< std::string >( "GlobalNetwork", "ZoneHost", "127.0.0.1" );
|
||||
m_pConfig->globalNetwork.zonePort = getValue< uint16_t >( "GlobalNetwork", "ZonePort", 54992 );
|
||||
m_pConfig->globalNetwork.lobbyHost = getValue< std::string >( "GlobalNetwork", "LobbyHost", "127.0.0.1" );
|
||||
m_pConfig->globalNetwork.lobbyPort = getValue< uint16_t >( "GlobalNetwork", "LobbyPort", 54994 );
|
||||
m_pConfig->globalNetwork.restHost = getValue< std::string >( "GlobalNetwork", "RestHost", "127.0.0.1" );
|
||||
m_pConfig->globalNetwork.restPort = getValue< uint16_t >( "GlobalNetwork", "RestPort", 80 );
|
||||
|
||||
// lobby
|
||||
m_pConfig->lobby.worldID = getValue< uint16_t >( "Lobby", "WorldID", 67 );
|
||||
m_pConfig->lobby.allowNoSessionConnect = getValue< bool >( "Lobby", "AllowNoSessionConnect", false );
|
||||
m_pConfig->lobby.worldName = getValue< std::string >( "Lobby", "WorldName", "Sapphire" );
|
||||
|
||||
// lobby network
|
||||
m_pConfig->lobbyNetwork.listenIp = getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" );
|
||||
m_pConfig->lobbyNetwork.listenPort = getValue< uint16_t >( "LobbyNetwork", "ListenPort", 54994 );
|
||||
|
||||
// character creation
|
||||
m_pConfig->characterCreation.defaultGMRank = getValue< uint8_t >( "CharacterCreation", "DefaultGMRank", 255 );
|
||||
|
||||
// rest network
|
||||
m_pConfig->restNetwork.listenIP = getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" );
|
||||
m_pConfig->restNetwork.listenPort = getValue< uint16_t >( "RestNetwork", "ListenPort", 80 );
|
||||
|
||||
// scripts
|
||||
m_pConfig->scripts.hotSwap = getValue( "Scripts", "HotSwap", true );
|
||||
m_pConfig->scripts.path = getValue< std::string >( "Scripts", "Path", "./compiledscripts/" );
|
||||
m_pConfig->scripts.cachePath = getValue< std::string >( "Scripts", "CachePath", "./cache/" );
|
||||
|
||||
// network
|
||||
m_pConfig->network.disconnectTimeout = getValue< uint16_t >( "Network", "DisconnectTimeout", 20 );
|
||||
|
||||
// zone network
|
||||
m_pConfig->zoneNetwork.listenIp = getValue< std::string >( "ZoneNetwork", "ListenIp", "0.0.0.0" );
|
||||
m_pConfig->zoneNetwork.listenPort = getValue< uint16_t >( "ZoneNetwork", "ListenPort", 54992 );
|
||||
|
||||
// general
|
||||
m_pConfig->general.motd = getValue< std::string >( "General", "MotD", "" );
|
||||
|
||||
// housing
|
||||
m_pConfig->housing.defaultEstateName = getValue< std::string >( "Housing", "DefaultEstateName", "Estate #{}" );
|
||||
}
|
||||
|
||||
Sapphire::ConfigMgr::ConfigurationPtr Sapphire::ConfigMgr::getConfig()
|
||||
{
|
||||
return m_pConfig;
|
||||
}
|
|
@ -6,6 +6,7 @@
|
|||
#include <inih/INIReader.h>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
#include "ConfigDef.h"
|
||||
|
||||
namespace Sapphire
|
||||
{
|
||||
|
@ -13,9 +14,10 @@ namespace Sapphire
|
|||
{
|
||||
public:
|
||||
ConfigMgr() = default;
|
||||
|
||||
~ConfigMgr() = default;
|
||||
|
||||
using ConfigurationPtr = std::shared_ptr< Common::Configuration >;
|
||||
|
||||
bool loadConfig( const std::string& configName );
|
||||
|
||||
template<class T> struct always_false : std::false_type {};
|
||||
|
@ -56,11 +58,16 @@ namespace Sapphire
|
|||
//m_propTree.put( name, defaultValue );
|
||||
}
|
||||
|
||||
ConfigurationPtr getConfig();
|
||||
|
||||
private:
|
||||
bool copyDefaultConfig( const std::string& configName );
|
||||
void initConfigData();
|
||||
|
||||
std::unique_ptr< INIReader > m_pInih;
|
||||
|
||||
ConfigurationPtr m_pConfig;
|
||||
|
||||
const std::string m_globalConfigFile = "global.ini";
|
||||
const std::string m_configFolderRoot = "./config/";
|
||||
const std::string m_configDefaultSuffix = ".default";
|
||||
|
|
|
@ -109,13 +109,13 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] )
|
|||
framework()->set< Data::ExdDataGenerated >( pExdData );
|
||||
|
||||
Sapphire::Db::ConnectionInfo info;
|
||||
info.password = pConfig->getValue< std::string >( "Database", "Password", "" );
|
||||
info.host = pConfig->getValue< std::string >( "Database", "Host", "127.0.0.1" );
|
||||
info.database = pConfig->getValue< std::string >( "Database", "Database", "sapphire" );
|
||||
info.port = pConfig->getValue< uint16_t >( "Database", "Port", 3306 );
|
||||
info.user = pConfig->getValue< std::string >( "Database", "Username", "root" );
|
||||
info.syncThreads = pConfig->getValue< uint8_t >( "Database", "SyncThreads", 2 );
|
||||
info.asyncThreads = pConfig->getValue< uint8_t >( "Database", "AsyncThreads", 2 );
|
||||
info.password = pConfig->getConfig()->database.password;
|
||||
info.host = pConfig->getConfig()->database.host;
|
||||
info.database = pConfig->getConfig()->database.database;
|
||||
info.port = pConfig->getConfig()->database.port;
|
||||
info.user = pConfig->getConfig()->database.username;
|
||||
info.syncThreads = pConfig->getConfig()->database.syncThreads;
|
||||
info.asyncThreads = pConfig->getConfig()->database.asyncThreads;
|
||||
|
||||
auto pDb = std::make_shared< Db::DbWorkerPool< Db::ZoneDbConnection > >();
|
||||
Sapphire::Db::DbLoader loader;
|
||||
|
|
Loading…
Add table
Reference in a new issue