From 3521ae7c8dde13032e46c8bf3ff87cb65fe758ec Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 22:11:52 +1100 Subject: [PATCH] shift a lot of config around --- config/api.ini.default | 3 ++ config/config.ini.default | 62 -------------------------- config/global.ini.default | 24 ++++++++++ config/lobby.ini.default | 8 ++++ config/world.ini.default | 20 +++++++++ src/common/Config/ConfigDef.h | 79 ++++++++++++++++----------------- src/common/Config/ConfigMgr.cpp | 60 ++++++++++++++++--------- src/common/Config/ConfigMgr.h | 1 + 8 files changed, 134 insertions(+), 123 deletions(-) create mode 100644 config/api.ini.default delete mode 100644 config/config.ini.default create mode 100644 config/global.ini.default create mode 100644 config/lobby.ini.default create mode 100644 config/world.ini.default diff --git a/config/api.ini.default b/config/api.ini.default new file mode 100644 index 00000000..25cacbb0 --- /dev/null +++ b/config/api.ini.default @@ -0,0 +1,3 @@ +[Network] +ListenIp = 0.0.0.0 +ListenPort = 80 \ No newline at end of file diff --git a/config/config.ini.default b/config/config.ini.default deleted file mode 100644 index cacd9115..00000000 --- a/config/config.ini.default +++ /dev/null @@ -1,62 +0,0 @@ -[Database] -Host = 127.0.0.1 -Port = 3306 -Database = sapphire -Username = sapphire -Password = -SyncThreads = 2 -AsyncThreads = 2 - -[GlobalParameters] -ServerSecret = default -DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack - -[GlobalNetwork] -; Values definining how Users and other servers will access - these have to be set to your public IP when running a public server -ZoneHost = 127.0.0.1 -ZonePort = 54992 - -LobbyHost = 127.0.0.1 -LobbyPort = 54994 - -RestHost = 127.0.0.1 -RestPort = 80 - -[Lobby] -WorldID = 67 -AllowNoSessionConnect = false -WorldName = Sapphire - -[LobbyNetwork] -ListenIp = 0.0.0.0 -ListenPort = 54994 - -[CharacterCreation] -DefaultGMRank = 255 - -[RestNetwork] -ListenIp = 0.0.0.0 -ListenPort = 80 - -[Scripts] -; where compiled script modules are located -Path = ./compiledscripts/ -; relative to Path, where we copy and load modules from -CachePath = ./cache/ -; whether we should detect changes to script modules and reload them -HotSwap = true - -[Network] -DisconnectTimeout = 20 - -[ZoneNetwork] -ListenIp = 0.0.0.0 -ListenPort = 54992 - -[General] -; Sent on login - each line must be shorter than 307 characters, split lines with ';' -MotD = Welcome to Sapphire!;This is a very good server;You can change these messages by editing General.MotD in config/config.ini - -[Housing] -; Set the default estate name. %i will be replaced with the plot number -DefaultEstateName = Estate #%i \ No newline at end of file diff --git a/config/global.ini.default b/config/global.ini.default new file mode 100644 index 00000000..5d6b36fb --- /dev/null +++ b/config/global.ini.default @@ -0,0 +1,24 @@ +[Database] +Host = 127.0.0.1 +Port = 3306 +Database = sapphire +Username = sapphire +Password = +SyncThreads = 2 +AsyncThreads = 2 + +[Parameters] +ServerSecret = default +DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack +WorldID = 67 + +[Network] +; Values definining how Users and other servers will access - these have to be set to your public IP when running a public server +ZoneHost = 127.0.0.1 +ZonePort = 54992 + +LobbyHost = 127.0.0.1 +LobbyPort = 54994 + +RestHost = 127.0.0.1 +RestPort = 80 \ No newline at end of file diff --git a/config/lobby.ini.default b/config/lobby.ini.default new file mode 100644 index 00000000..9420d8e9 --- /dev/null +++ b/config/lobby.ini.default @@ -0,0 +1,8 @@ +[Lobby] +AllowNoSessionConnect = false +WorldName = Sapphire +DefaultGMRank = 255 + +[Network] +ListenIp = 0.0.0.0 +ListenPort = 54994 \ No newline at end of file diff --git a/config/world.ini.default b/config/world.ini.default new file mode 100644 index 00000000..0fd35e32 --- /dev/null +++ b/config/world.ini.default @@ -0,0 +1,20 @@ +[Scripts] +; where compiled script modules are located +Path = ./compiledscripts/ +; relative to Path, where we copy and load modules from +CachePath = ./cache/ +; whether we should detect changes to script modules and reload them +HotSwap = true + +[Network] +ListenIp = 0.0.0.0 +ListenPort = 54992 +DisconnectTimeout = 20 + +[General] +; Sent on login - each line must be shorter than 307 characters, split lines with ';' +MotD = Welcome to Sapphire!;This is a very good server;You can change these messages by editing General.MotD in config/config.ini + +[Housing] +; Set the default estate name. {0} will be replaced with the plot number +DefaultEstateName = Estate ${0} \ No newline at end of file diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h index 16c8cfb6..ee9f3496 100644 --- a/src/common/Config/ConfigDef.h +++ b/src/common/Config/ConfigDef.h @@ -1,9 +1,9 @@ #ifndef SAPPHIRE_CONFIGDEF_H #define SAPPHIRE_CONFIGDEF_H -namespace Sapphire::Common +namespace Sapphire::Common::Config { - struct Configuration + struct GlobalConfig { struct Database { @@ -14,16 +14,16 @@ namespace Sapphire::Common std::string password; uint8_t syncThreads; uint8_t asyncThreads; - } database; - struct GlobalParameters + struct Parameters { std::string serverSecret; std::string dataPath; - } globalParameters; + uint16_t worldID; + } parameters; - struct GlobalNetwork + struct Network { std::string zoneHost; uint16_t zonePort; @@ -33,31 +33,26 @@ namespace Sapphire::Common std::string restHost; uint16_t restPort; - } globalNetwork; + } network; + }; - struct Lobby - { - uint16_t worldID; - bool allowNoSessionConnect; - std::string worldName; - } lobby; - struct LobbyNetwork + struct WorldConfig + { + GlobalConfig global; + + struct Network { std::string listenIp; uint16_t listenPort; - } lobbyNetwork; - struct CharacterCreation - { - uint8_t defaultGMRank; - } characterCreation; + uint16_t disconnectTimeout; + } network; - struct RestNetwork + struct Housing { - std::string listenIP; - uint16_t listenPort; - } restNetwork; + std::string defaultEstateName; + } housing; struct Scripts { @@ -66,30 +61,34 @@ namespace Sapphire::Common bool hotSwap; } scripts; + std::string motd; + }; + + struct LobbyConfig + { + GlobalConfig global; + struct Network - { - Network() : - disconnectTimeout( 20 ) - {} - - uint16_t disconnectTimeout; - } network; - - struct ZoneNetwork { std::string listenIp; uint16_t listenPort; - } zoneNetwork; + } network; - struct General - { - std::string motd; - } general; + bool allowNoSessionConnect; + std::string worldName; - struct Housing + uint8_t defaultGMRank; + }; + + struct ApiConfig + { + GlobalConfig global; + + struct Network { - std::string defaultEstateName; - } housing; + std::string listenIP; + uint16_t listenPort; + } network; }; } diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index 4d551425..fd820327 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -31,6 +31,45 @@ bool Sapphire::ConfigMgr::loadConfig( const std::string& configName ) return true; } +bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName ) +{ + auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName ); + + if( !fs::exists( configFile ) ) + { + copyDefaultConfig( configName ); + return false; + } + + m_pInih = std::make_unique< INIReader >( configFile.string() ); + if( m_pInih->ParseError() < 0 ) + return false; + + // database + config.database.host = getValue< std::string >( "Database", "Host", "127.0.0.1" ); + config.database.port = getValue< uint16_t >( "Database", "Port", 3306 ); + config.database.database = getValue< std::string >( "Database", "Database", "sapphire" ); + config.database.username = getValue< std::string >( "Database", "Username", "sapphire" ); + config.database.password = getValue< std::string >( "Database", "Password", "" ); + config.database.syncThreads = getValue< uint8_t >( "Database", "SyncThreads", 2 ); + config.database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 ); + + // params + config.parameters.dataPath = getValue< std::string >( "Parameters", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); + config.parameters.serverSecret = getValue< std::string >( "Parameters", "ServerSecret", "default" ); + config.parameters.worldID = getValue< uint16_t >( "Parameters", "WorldID", 67 ); + + // network + config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" ); + config.network.zonePort = getValue< uint16_t >( "Network", "ZonePort", 54992 ); + config.network.lobbyHost = getValue< std::string >( "Network", "LobbyHost", "127.0.0.1" ); + config.network.lobbyPort = getValue< uint16_t >( "Network", "LobbyPort", 54994 ); + config.network.restHost = getValue< std::string >( "Network", "RestHost", "127.0.0.1" ); + config.network.restPort = getValue< uint16_t >( "Network", "RestPort", 80 ); + + return true; +} + bool Sapphire::ConfigMgr::copyDefaultConfig( const std::string& configName ) { fs::path configPath( m_configFolderRoot ); @@ -51,27 +90,6 @@ 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 ); diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index 7a7b41ba..bcae72b7 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -19,6 +19,7 @@ namespace Sapphire using ConfigurationPtr = std::shared_ptr< Common::Configuration >; bool loadConfig( const std::string& configName ); + bool loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName = "config.ini" ); template struct always_false : std::false_type {};