From 3349ccce42f828d24f7a4b3607a464d848436325 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 6 Jan 2019 23:39:30 +1100 Subject: [PATCH 1/9] initial move of all config items to a object --- src/common/Config/ConfigDef.h | 96 +++++++++++++++++++++++++++++++++ src/common/Config/ConfigMgr.cpp | 67 +++++++++++++++++++++++ src/common/Config/ConfigMgr.h | 9 +++- src/world/ServerMgr.cpp | 14 ++--- 4 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 src/common/Config/ConfigDef.h diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h new file mode 100644 index 00000000..16c8cfb6 --- /dev/null +++ b/src/common/Config/ConfigDef.h @@ -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 diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index b1e975f2..4d551425 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -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; +} \ No newline at end of file diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index cf3109e6..7a7b41ba 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -6,6 +6,7 @@ #include #include #include +#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 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"; diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 70f452f4..202c0a83 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -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; From 092b34311485b60b95038a3cfd1bb850b44b700f Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 00:03:48 +1100 Subject: [PATCH 2/9] move all the old config calls to the new config object --- src/api/main.cpp | 55 ++++++++++++++-------------- src/lobby/GameConnection.cpp | 34 +++++++---------- src/lobby/ServerLobby.cpp | 23 ++++++------ src/world/Actor/PlayerEvent.cpp | 2 +- src/world/Script/NativeScriptMgr.cpp | 2 +- src/world/Script/ScriptMgr.cpp | 7 ++-- src/world/ServerMgr.cpp | 6 +-- 7 files changed, 60 insertions(+), 69 deletions(-) diff --git a/src/api/main.cpp b/src/api/main.cpp index 467797a4..ee2d7edd 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -77,6 +77,8 @@ bool loadSettings( int32_t argc, char* argv[] ) return false; } + auto pConfig = m_pConfig->getConfig(); + std::vector< std::string > args( argv + 1, argv + argc ); for( size_t i = 0; i + 1 < args.size(); i += 2 ) { @@ -140,7 +142,7 @@ bool loadSettings( int32_t argc, char* argv[] ) } Logger::info( "Setting up generated EXD data" ); - auto dataPath = m_pConfig->getValue< std::string >( "GlobalParameters", "DataPath", "" ); + auto dataPath = m_pConfig->getConfig()->globalParameters.dataPath; if( !g_exdDataGen.init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); @@ -151,21 +153,20 @@ bool loadSettings( int32_t argc, char* argv[] ) Sapphire::Db::DbLoader loader; Sapphire::Db::ConnectionInfo info; - info.password = m_pConfig->getValue< std::string >( "Database", "Password", "" ); - info.host = m_pConfig->getValue< std::string >( "Database", "Host", "127.0.0.1" ); - info.database = m_pConfig->getValue< std::string >( "Database", "Database", "sapphire" ); - info.port = m_pConfig->getValue< uint16_t >( "Database", "Port", 3306 ); - info.user = m_pConfig->getValue< std::string >( "Database", "Username", "root" ); - info.syncThreads = m_pConfig->getValue< uint8_t >( "Database", "SyncThreads", 2 ); - info.asyncThreads = m_pConfig->getValue< uint8_t >( "Database", "AsyncThreads", 2 ); + info.password = pConfig->database.password; + info.host = pConfig->database.host; + info.database = pConfig->database.database; + info.port = pConfig->database.port; + info.user = pConfig->database.username; + info.syncThreads = pConfig->database.syncThreads; + info.asyncThreads = pConfig->database.asyncThreads; loader.addDb( g_charaDb, info ); if( !loader.initDbs() ) return false; - server.config.port = static_cast< uint16_t >( std::stoul( - m_pConfig->getValue< std::string >( "RestNetwork", "ListenPort", "80" ) ) ); - server.config.address = m_pConfig->getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" ); + server.config.port = pConfig->restNetwork.listenPort; + server.config.address = pConfig->restNetwork.listenIP; Logger::info( "Database: Connected to {0}:{1}", info.host, info.port ); @@ -267,9 +268,9 @@ void createAccount( shared_ptr< HttpServer::Response > response, shared_ptr< Htt // todo: construct proper json object here std::string json_string = "{\"sId\":\"" + sId + "\", \"lobbyHost\":\"" + - m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) + + m_pConfig->getConfig()->globalNetwork.lobbyHost + "\", \"frontierHost\":\"" + - m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + "\"}"; + m_pConfig->getConfig()->globalNetwork.restHost + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -300,9 +301,9 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer: // todo: build proper json object and stringify it std::string json_string = "{\"sId\":\"" + sId + "\", \"lobbyHost\":\"" + - m_pConfig->getValue< std::string >( "GlobalNetwork", "LobbyHost" ) + + m_pConfig->getConfig()->globalNetwork.lobbyHost + "\", \"frontierHost\":\"" + - m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + "\"}"; + m_pConfig->getConfig()->globalNetwork.restHost + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -332,7 +333,7 @@ void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H int32_t accountId = g_sapphireAPI.checkSession( sId ); - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -372,15 +373,15 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H if( result != -1 ) { - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); } else { - int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, m_pConfig->getValue< uint8_t >( - "CharacterCreation", "DefaultGMRank", 255 ) ); + int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, + m_pConfig->getConfig()->characterCreation.defaultGMRank ); std::string json_string = "{\"result\":\"" + std::to_string( charId ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); @@ -413,7 +414,7 @@ void insertSession( shared_ptr< HttpServer::Response > response, shared_ptr< Htt std::string secret = json["secret"]; // reloadConfig(); - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -445,7 +446,7 @@ void checkNameTaken( shared_ptr< HttpServer::Response > response, shared_ptr< Ht // reloadConfig(); - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -482,7 +483,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http if( result != -1 ) { - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -521,7 +522,7 @@ void getNextCharId( shared_ptr< HttpServer::Response > response, shared_ptr< Htt // reloadConfig(); - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -552,7 +553,7 @@ void getNextContentId( shared_ptr< HttpServer::Response > response, shared_ptr< // reloadConfig(); - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -587,7 +588,7 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr< if( result != -1 ) { - if( m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ) != secret ) + if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -767,8 +768,8 @@ int main( int argc, char* argv[] ) server.start(); } ); - Logger::info( "API server running on {0}:{1}", m_pConfig->getValue< std::string >( "RestNetwork", "ListenIp", "0.0.0.0" ), - m_pConfig->getValue< std::string >( "RestNetwork", "ListenPort", "80" ) ); + auto& cfg = m_pConfig->getConfig()->restNetwork; + Logger::info( "API server running on {0}:{1}", cfg.listenIP, cfg.listenPort ); //Wait for server to start so that the client can connect this_thread::sleep_for( chrono::seconds( 1 ) ); diff --git a/src/lobby/GameConnection.cpp b/src/lobby/GameConnection.cpp index 206c06a9..1ad9ebf3 100644 --- a/src/lobby/GameConnection.cpp +++ b/src/lobby/GameConnection.cpp @@ -128,11 +128,10 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet serverListPacket->data().seq = 1; serverListPacket->data().offset = 0; serverListPacket->data().numServers = 1; - serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 ); + serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig()->getConfig()->lobby.worldID; serverListPacket->data().server[ 0 ].index = 0; serverListPacket->data().final = 1; - strcpy( serverListPacket->data().server[ 0 ].name, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); + strcpy( serverListPacket->data().server[ 0 ].name, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); pRP.addPacket( serverListPacket ); auto retainerListPacket = makeLobbyPacket< FFXIVIpcRetainerList >( tmpId ); @@ -162,15 +161,13 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet auto& charEntry = charList[ charIndex ]; details.uniqueId = std::get< 1 >( charEntry ); details.contentId = std::get< 2 >( charEntry ); - details.serverId = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 ); - details.serverId1 = g_serverLobby.getConfig()->getValue< uint16_t >( "Lobby", "WorldID", 1 ); + details.serverId = g_serverLobby.getConfig()->getConfig()->lobby.worldID; + details.serverId1 = g_serverLobby.getConfig()->getConfig()->lobby.worldID; details.index = charIndex; strcpy( details.charDetailJson, std::get< 3 >( charEntry ).c_str() ); strcpy( details.nameChara, std::get< 0 >( charEntry ).c_str() ); - strcpy( details.nameServer, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); - strcpy( details.nameServer1, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); + strcpy( details.nameServer, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( details.nameServer1, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); charListPacket->data().charaDetails[ j ] = details; @@ -236,9 +233,8 @@ void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, auto enterWorldPacket = makeLobbyPacket< FFXIVIpcEnterWorld >( tmpId ); enterWorldPacket->data().contentId = lookupId; enterWorldPacket->data().seq = sequence; - strcpy( enterWorldPacket->data().host, - g_serverLobby.getConfig()->getValue< std::string >( "GlobalNetwork", "ZoneHost" ).c_str() ); - enterWorldPacket->data().port = g_serverLobby.getConfig()->getValue< uint16_t >( "GlobalNetwork", "ZonePort" ); + strcpy( enterWorldPacket->data().host, g_serverLobby.getConfig()->getConfig()->globalNetwork.zoneHost.c_str() ); + enterWorldPacket->data().port = g_serverLobby.getConfig()->getConfig()->globalNetwork.zonePort; enterWorldPacket->data().charId = logInCharId; memcpy( enterWorldPacket->data().sid, m_pSession->getSessionId(), 66 ); pRP.addPacket( enterWorldPacket ); @@ -249,7 +245,7 @@ bool Sapphire::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_ { LobbySessionPtr pSession = g_serverLobby.getSession( ( char* ) &packet.data[ 0 ] + 0x20 ); - if( g_serverLobby.getConfig()->getValue< bool >( "Lobby", "AllowNoSessionConnect" ) && pSession == nullptr ) + if( g_serverLobby.getConfig()->getConfig()->lobby.allowNoSessionConnect && pSession == nullptr ) { auto session = make_LobbySession(); session->setAccountID( 0 ); @@ -316,8 +312,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); charCreatePacket->data().content_id = newContentId; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); charCreatePacket->data().type = 1; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; @@ -340,10 +335,8 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); charCreatePacket->data().content_id = newContentId; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); - strcpy( charCreatePacket->data().world2, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( charCreatePacket->data().world2, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); charCreatePacket->data().type = 2; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; @@ -371,8 +364,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& //charCreatePacket->data().content_id = deletePlayer.getContentId(); charCreatePacket->data().content_id = 0; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, - g_serverLobby.getConfig()->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); charCreatePacket->data().type = 4; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; diff --git a/src/lobby/ServerLobby.cpp b/src/lobby/ServerLobby.cpp index 1efaf3d0..1d83609a 100644 --- a/src/lobby/ServerLobby.cpp +++ b/src/lobby/ServerLobby.cpp @@ -67,9 +67,7 @@ namespace Sapphire Network::HivePtr hive( new Network::Hive() ); Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive, pFw ); - Logger::info( - "Lobby server running on " + m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" ) + ":" + - m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenPort", "80" ) ); + Logger::info( "Lobby server running on {0}:{1}", m_ip, m_port ); std::vector< std::thread > threadGroup; @@ -108,19 +106,19 @@ namespace Sapphire if( arg == "ip" ) { // todo: ip addr in config - m_pConfig->setValue< std::string >( "LobbyNetwork.ListenIp", val ); + m_pConfig->getConfig()->lobbyNetwork.listenIp = val; } else if( arg == "p" || arg == "port" ) { - m_pConfig->setValue< std::string >( "LobbyNetwork.LobbyPort", val ); + m_pConfig->getConfig()->lobbyNetwork.listenPort = std::stoi( val ); } else if( arg == "worldip" || arg == "worldip" ) { - m_pConfig->setValue< std::string >( "GlobalNetwork.ZoneHost", val ); + m_pConfig->getConfig()->globalNetwork.zoneHost = val; } else if( arg == "worldport" ) { - m_pConfig->setValue< std::string >( "GlobalNetwork.ZonePort", val ); + m_pConfig->getConfig()->globalNetwork.zonePort = std::stoi( val ); } } catch( ... ) @@ -130,12 +128,13 @@ namespace Sapphire } } - m_port = m_pConfig->getValue< uint16_t >( "LobbyNetwork", "ListenPort", 54994 ); - m_ip = m_pConfig->getValue< std::string >( "LobbyNetwork", "ListenIp", "0.0.0.0" ); + m_port = m_pConfig->getConfig()->lobbyNetwork.listenPort; + m_ip = m_pConfig->getConfig()->lobbyNetwork.listenIp; - g_restConnector.restHost = m_pConfig->getValue< std::string >( "GlobalNetwork", "RestHost" ) + ":" + - m_pConfig->getValue< std::string >( "GlobalNetwork", "RestPort" ); - g_restConnector.serverSecret = m_pConfig->getValue< std::string >( "GlobalParameters", "ServerSecret" ); + + g_restConnector.restHost = m_pConfig->getConfig()->globalNetwork.restHost + ":" + + std::to_string( m_pConfig->getConfig()->globalNetwork.restPort ); + g_restConnector.serverSecret = m_pConfig->getConfig()->globalParameters.serverSecret; return true; } diff --git a/src/world/Actor/PlayerEvent.cpp b/src/world/Actor/PlayerEvent.cpp index e243d2a2..cd32d132 100644 --- a/src/world/Actor/PlayerEvent.cpp +++ b/src/world/Actor/PlayerEvent.cpp @@ -327,7 +327,7 @@ void Sapphire::Entity::Player::eventItemActionStart( uint32_t eventId, void Sapphire::Entity::Player::onLogin() { auto pConfig = m_pFw->get< ConfigMgr >(); - auto motd = pConfig->getValue< std::string >( "General", "MotD", "" ); + auto motd = pConfig->getConfig()->general.motd; std::istringstream ss( motd ); std::string msg; diff --git a/src/world/Script/NativeScriptMgr.cpp b/src/world/Script/NativeScriptMgr.cpp index 6f2f6169..69126c75 100644 --- a/src/world/Script/NativeScriptMgr.cpp +++ b/src/world/Script/NativeScriptMgr.cpp @@ -125,7 +125,7 @@ namespace Sapphire::Scripting World::Manager::BaseManager( pFw ) { auto pConfig = framework()->get< ConfigMgr >(); - m_loader.setCachePath( pConfig->getValue< std::string >( "Scripts", "CachePath", "./cache/" ) ); + m_loader.setCachePath( pConfig->getConfig()->scripts.cachePath ); } diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index 408c51d9..f92f5cb1 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -50,8 +50,7 @@ bool Sapphire::Scripting::ScriptMgr::init() std::set< std::string > files; auto pConfig = framework()->get< ConfigMgr >(); - auto status = loadDir( pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" ), - files, m_nativeScriptMgr->getModuleExtension() ); + auto status = loadDir( pConfig->getConfig()->scripts.path, files, m_nativeScriptMgr->getModuleExtension() ); if( !status ) { @@ -82,11 +81,11 @@ bool Sapphire::Scripting::ScriptMgr::init() void Sapphire::Scripting::ScriptMgr::watchDirectories() { auto pConfig = framework()->get< ConfigMgr >(); - auto shouldWatch = pConfig->getValue< bool >( "Scripts", "HotSwap", true ); + auto shouldWatch = pConfig->getConfig()->scripts.hotSwap; if( !shouldWatch ) return; - Watchdog::watchMany( pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" ) + "*" + + Watchdog::watchMany( pConfig->getConfig()->scripts.path + "*" + m_nativeScriptMgr->getModuleExtension(), [ this ]( const std::vector< ci::fs::path >& paths ) { diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 202c0a83..4f3047f2 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -74,8 +74,8 @@ bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] ) return false; } - m_port = pConfig->getValue< uint16_t >( "ZoneNetwork", "ListenPort", 54992 ); - m_ip = pConfig->getValue< std::string >( "ZoneNetwork", "ListenIp", "0.0.0.0" ); + m_port = pConfig->getConfig()->zoneNetwork.listenPort; + m_ip = pConfig->getConfig()->zoneNetwork.listenIp; return true; } @@ -99,7 +99,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) Logger::info( "Setting up generated EXD data" ); auto pExdData = std::make_shared< Data::ExdDataGenerated >(); - auto dataPath = pConfig->getValue< std::string >( "GlobalParameters", "DataPath", "" ); + auto dataPath = pConfig->getConfig()->globalParameters.dataPath; if( !pExdData->init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); From 3521ae7c8dde13032e46c8bf3ff87cb65fe758ec Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 22:11:52 +1100 Subject: [PATCH 3/9] 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 {}; From 03df0b242c502d6aa877884c9667b714a93896ea Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:00:09 +1100 Subject: [PATCH 4/9] lobby works again with new config stuff --- config/global.ini.default | 1 + config/lobby.ini.default | 1 - src/api/main.cpp | 118 +++++++++++---------------- src/common/Config/ConfigDef.h | 4 +- src/common/Config/ConfigMgr.cpp | 54 ++++-------- src/common/Config/ConfigMgr.h | 8 +- src/lobby/GameConnection.cpp | 26 +++--- src/lobby/ServerLobby.cpp | 45 +++++++--- src/lobby/ServerLobby.h | 5 +- src/lobby/mainLobbyServer.cpp | 2 +- src/world/Actor/PlayerEvent.cpp | 5 +- src/world/Script/NativeScriptMgr.cpp | 6 +- src/world/Script/ScriptMgr.cpp | 11 ++- src/world/ServerMgr.cpp | 55 ++++++++++--- src/world/ServerMgr.h | 7 ++ src/world/mainGameServer.cpp | 2 +- 16 files changed, 181 insertions(+), 169 deletions(-) diff --git a/config/global.ini.default b/config/global.ini.default index 5d6b36fb..46cd4747 100644 --- a/config/global.ini.default +++ b/config/global.ini.default @@ -11,6 +11,7 @@ AsyncThreads = 2 ServerSecret = default DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack WorldID = 67 +DefaultGMRank = 255 [Network] ; Values definining how Users and other servers will access - these have to be set to your public IP when running a public server diff --git a/config/lobby.ini.default b/config/lobby.ini.default index 9420d8e9..4d88ee63 100644 --- a/config/lobby.ini.default +++ b/config/lobby.ini.default @@ -1,7 +1,6 @@ [Lobby] AllowNoSessionConnect = false WorldName = Sapphire -DefaultGMRank = 255 [Network] ListenIp = 0.0.0.0 diff --git a/src/api/main.cpp b/src/api/main.cpp index ee2d7edd..8c0ae020 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -51,14 +51,36 @@ void default_resource_send( const HttpServer& server, const shared_ptr< HttpServ auto m_pConfig = std::make_shared< Sapphire::ConfigMgr >(); HttpServer server; -std::string configPath( "config.ini" ); +std::string configPath( "api.ini" ); +Sapphire::Common::Config::ApiConfig m_config; void reloadConfig() { m_pConfig = std::make_shared< Sapphire::ConfigMgr >(); + bool failedLoad = false; + + // load global cfg first + if( !m_pConfig->loadGlobalConfig( m_config.global ) ) + { + Logger::fatal( "Error loading config global.ini" ); + failedLoad = true; + } + if( !m_pConfig->loadConfig( configPath ) ) - throw "Error loading config "; + { + Logger::fatal( "Error loading config {0}", configPath ); + failedLoad = true; + } + + if( failedLoad ) + { + throw "Error loading config"; + } + + // setup api config + m_config.network.listenPort = m_pConfig->getValue< uint16_t >( "Network", "ListenPort", 80 ); + m_config.network.listenIP = m_pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" ); } void print_request_info( shared_ptr< HttpServer::Request > request ) @@ -77,8 +99,6 @@ bool loadSettings( int32_t argc, char* argv[] ) return false; } - auto pConfig = m_pConfig->getConfig(); - std::vector< std::string > args( argv + 1, argv + argc ); for( size_t i = 0; i + 1 < args.size(); i += 2 ) { @@ -93,46 +113,7 @@ bool loadSettings( int32_t argc, char* argv[] ) // trim '-' from start of arg arg = arg.erase( 0, arg.find_first_not_of( '-' ) ); - if( arg == "ip" ) - { - m_pConfig->setValue< std::string >( "RestNetwork.ListenIp", val ); - } - else if( arg == "p" || arg == "port" ) - { - m_pConfig->setValue< std::string >( "RestNetwork.ListenPort", val ); - } - else if( arg == "exdpath" || arg == "datapath" ) - { - m_pConfig->setValue< std::string >( "GlobalParameters.DataPath", val ); - } - else if( arg == "h" || arg == "dbhost" ) - { - m_pConfig->setValue< std::string >( "Database.Host", val ); - } - else if( arg == "dbport" ) - { - m_pConfig->setValue< std::string >( "Database.Port", val ); - } - else if( arg == "u" || arg == "user" || arg == "dbuser" ) - { - m_pConfig->setValue< std::string >( "Database.Username", val ); - } - else if( arg == "pass" || arg == "dbpass" ) - { - m_pConfig->setValue< std::string >( "Database.Password", val ); - } - else if( arg == "d" || arg == "db" || arg == "database" ) - { - m_pConfig->setValue< std::string >( "Database.Database", val ); - } - else if( arg == "lobbyip" || arg == "lobbyhost" ) - { - m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyHost", val ); - } - else if( arg == "lobbyport" ) - { - m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyPort", val ); - } + } catch( ... ) { @@ -142,7 +123,7 @@ bool loadSettings( int32_t argc, char* argv[] ) } Logger::info( "Setting up generated EXD data" ); - auto dataPath = m_pConfig->getConfig()->globalParameters.dataPath; + auto dataPath = m_config.global.parameters.dataPath; if( !g_exdDataGen.init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); @@ -153,20 +134,20 @@ bool loadSettings( int32_t argc, char* argv[] ) Sapphire::Db::DbLoader loader; Sapphire::Db::ConnectionInfo info; - info.password = pConfig->database.password; - info.host = pConfig->database.host; - info.database = pConfig->database.database; - info.port = pConfig->database.port; - info.user = pConfig->database.username; - info.syncThreads = pConfig->database.syncThreads; - info.asyncThreads = pConfig->database.asyncThreads; + 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() ) return false; - server.config.port = pConfig->restNetwork.listenPort; - server.config.address = pConfig->restNetwork.listenIP; + server.config.port = m_config.network.listenPort; + server.config.address = m_config.network.listenIP; Logger::info( "Database: Connected to {0}:{1}", info.host, info.port ); @@ -268,9 +249,9 @@ void createAccount( shared_ptr< HttpServer::Response > response, shared_ptr< Htt // todo: construct proper json object here std::string json_string = "{\"sId\":\"" + sId + "\", \"lobbyHost\":\"" + - m_pConfig->getConfig()->globalNetwork.lobbyHost + + m_config.global.network.lobbyHost + "\", \"frontierHost\":\"" + - m_pConfig->getConfig()->globalNetwork.restHost + "\"}"; + m_config.global.network.restHost + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -301,9 +282,9 @@ void login( shared_ptr< HttpServer::Response > response, shared_ptr< HttpServer: // todo: build proper json object and stringify it std::string json_string = "{\"sId\":\"" + sId + "\", \"lobbyHost\":\"" + - m_pConfig->getConfig()->globalNetwork.lobbyHost + + m_config.global.network.lobbyHost + "\", \"frontierHost\":\"" + - m_pConfig->getConfig()->globalNetwork.restHost + "\"}"; + m_config.global.network.restHost + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -333,7 +314,7 @@ void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H int32_t accountId = g_sapphireAPI.checkSession( sId ); - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -373,7 +354,7 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H if( result != -1 ) { - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -381,7 +362,7 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H else { int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, - m_pConfig->getConfig()->characterCreation.defaultGMRank ); + m_config.global.parameters.defaultGMRank ); std::string json_string = "{\"result\":\"" + std::to_string( charId ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); @@ -414,7 +395,7 @@ void insertSession( shared_ptr< HttpServer::Response > response, shared_ptr< Htt std::string secret = json["secret"]; // reloadConfig(); - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -446,7 +427,7 @@ void checkNameTaken( shared_ptr< HttpServer::Response > response, shared_ptr< Ht // reloadConfig(); - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -483,7 +464,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http if( result != -1 ) { - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -522,7 +503,7 @@ void getNextCharId( shared_ptr< HttpServer::Response > response, shared_ptr< Htt // reloadConfig(); - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -553,7 +534,7 @@ void getNextContentId( shared_ptr< HttpServer::Response > response, shared_ptr< // reloadConfig(); - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -588,7 +569,7 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr< if( result != -1 ) { - if( m_pConfig->getConfig()->globalParameters.serverSecret != secret ) + if( m_config.global.parameters.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -768,8 +749,7 @@ int main( int argc, char* argv[] ) server.start(); } ); - auto& cfg = m_pConfig->getConfig()->restNetwork; - Logger::info( "API server running on {0}:{1}", cfg.listenIP, cfg.listenPort ); + Logger::info( "API server running on {0}:{1}", m_config.network.listenIP, m_config.network.listenPort ); //Wait for server to start so that the client can connect this_thread::sleep_for( chrono::seconds( 1 ) ); diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h index ee9f3496..ac4f3952 100644 --- a/src/common/Config/ConfigDef.h +++ b/src/common/Config/ConfigDef.h @@ -21,6 +21,8 @@ namespace Sapphire::Common::Config std::string serverSecret; std::string dataPath; uint16_t worldID; + + uint8_t defaultGMRank; } parameters; struct Network @@ -76,8 +78,6 @@ namespace Sapphire::Common::Config bool allowNoSessionConnect; std::string worldName; - - uint8_t defaultGMRank; }; struct ApiConfig diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index fd820327..222c4a85 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -58,6 +58,7 @@ bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config 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 ); + config.parameters.defaultGMRank = getValue< uint8_t >( "Parameters", "DefaultGMRank", 255 ); // network config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" ); @@ -88,44 +89,19 @@ bool Sapphire::ConfigMgr::copyDefaultConfig( const std::string& configName ) void Sapphire::ConfigMgr::initConfigData() { - m_pConfig = std::make_shared< Common::Configuration >(); - // 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; +// 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 ); } \ No newline at end of file diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index bcae72b7..91dab976 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -16,10 +16,8 @@ namespace Sapphire ConfigMgr() = default; ~ConfigMgr() = default; - using ConfigurationPtr = std::shared_ptr< Common::Configuration >; - bool loadConfig( const std::string& configName ); - bool loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName = "config.ini" ); + bool loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName = "global.ini" ); template struct always_false : std::false_type {}; @@ -59,16 +57,12 @@ 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"; diff --git a/src/lobby/GameConnection.cpp b/src/lobby/GameConnection.cpp index 1ad9ebf3..f5e5180e 100644 --- a/src/lobby/GameConnection.cpp +++ b/src/lobby/GameConnection.cpp @@ -128,10 +128,10 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet serverListPacket->data().seq = 1; serverListPacket->data().offset = 0; serverListPacket->data().numServers = 1; - serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig()->getConfig()->lobby.worldID; + serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig().global.parameters.worldID; serverListPacket->data().server[ 0 ].index = 0; serverListPacket->data().final = 1; - strcpy( serverListPacket->data().server[ 0 ].name, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( serverListPacket->data().server[ 0 ].name, g_serverLobby.getConfig().worldName.c_str() ); pRP.addPacket( serverListPacket ); auto retainerListPacket = makeLobbyPacket< FFXIVIpcRetainerList >( tmpId ); @@ -161,13 +161,13 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet auto& charEntry = charList[ charIndex ]; details.uniqueId = std::get< 1 >( charEntry ); details.contentId = std::get< 2 >( charEntry ); - details.serverId = g_serverLobby.getConfig()->getConfig()->lobby.worldID; - details.serverId1 = g_serverLobby.getConfig()->getConfig()->lobby.worldID; + details.serverId = g_serverLobby.getConfig().global.parameters.worldID; + details.serverId1 = g_serverLobby.getConfig().global.parameters.worldID; details.index = charIndex; strcpy( details.charDetailJson, std::get< 3 >( charEntry ).c_str() ); strcpy( details.nameChara, std::get< 0 >( charEntry ).c_str() ); - strcpy( details.nameServer, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); - strcpy( details.nameServer1, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( details.nameServer, g_serverLobby.getConfig().worldName.c_str() ); + strcpy( details.nameServer1, g_serverLobby.getConfig().worldName.c_str() ); charListPacket->data().charaDetails[ j ] = details; @@ -233,8 +233,8 @@ void Sapphire::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, auto enterWorldPacket = makeLobbyPacket< FFXIVIpcEnterWorld >( tmpId ); enterWorldPacket->data().contentId = lookupId; enterWorldPacket->data().seq = sequence; - strcpy( enterWorldPacket->data().host, g_serverLobby.getConfig()->getConfig()->globalNetwork.zoneHost.c_str() ); - enterWorldPacket->data().port = g_serverLobby.getConfig()->getConfig()->globalNetwork.zonePort; + strcpy( enterWorldPacket->data().host, g_serverLobby.getConfig().global.network.zoneHost.c_str() ); + enterWorldPacket->data().port = g_serverLobby.getConfig().global.network.zonePort; enterWorldPacket->data().charId = logInCharId; memcpy( enterWorldPacket->data().sid, m_pSession->getSessionId(), 66 ); pRP.addPacket( enterWorldPacket ); @@ -245,7 +245,7 @@ bool Sapphire::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_ { LobbySessionPtr pSession = g_serverLobby.getSession( ( char* ) &packet.data[ 0 ] + 0x20 ); - if( g_serverLobby.getConfig()->getConfig()->lobby.allowNoSessionConnect && pSession == nullptr ) + if( g_serverLobby.getConfig().allowNoSessionConnect && pSession == nullptr ) { auto session = make_LobbySession(); session->setAccountID( 0 ); @@ -312,7 +312,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); charCreatePacket->data().content_id = newContentId; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig().worldName.c_str() ); charCreatePacket->data().type = 1; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; @@ -335,8 +335,8 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& auto charCreatePacket = makeLobbyPacket< FFXIVIpcCharCreate >( tmpId ); charCreatePacket->data().content_id = newContentId; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); - strcpy( charCreatePacket->data().world2, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig().worldName.c_str() ); + strcpy( charCreatePacket->data().world2, g_serverLobby.getConfig().worldName.c_str() ); charCreatePacket->data().type = 2; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; @@ -364,7 +364,7 @@ bool Sapphire::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& //charCreatePacket->data().content_id = deletePlayer.getContentId(); charCreatePacket->data().content_id = 0; strcpy( charCreatePacket->data().name, name.c_str() ); - strcpy( charCreatePacket->data().world, g_serverLobby.getConfig()->getConfig()->lobby.worldName.c_str() ); + strcpy( charCreatePacket->data().world, g_serverLobby.getConfig().worldName.c_str() ); charCreatePacket->data().type = 4; charCreatePacket->data().seq = sequence; charCreatePacket->data().unknown = 1; diff --git a/src/lobby/ServerLobby.cpp b/src/lobby/ServerLobby.cpp index 1d83609a..7d09dcbe 100644 --- a/src/lobby/ServerLobby.cpp +++ b/src/lobby/ServerLobby.cpp @@ -41,9 +41,9 @@ namespace Sapphire return g_restConnector.getSession( sessionId ); } - ConfigMgrPtr ServerLobby::getConfig() const + Sapphire::Common::Config::LobbyConfig& ServerLobby::getConfig() { - return m_pConfig; + return m_config; } void ServerLobby::run( int32_t argc, char* argv[] ) @@ -83,12 +83,33 @@ namespace Sapphire { Logger::info( "Loading config {0}", m_configPath ); + bool failedLoad = false; + if( !m_pConfig->loadGlobalConfig( m_config.global, "global.ini" ) ) + { + Logger::fatal( "Error loading config global.ini, copying default..." ); + failedLoad = true; + } + if( !m_pConfig->loadConfig( m_configPath ) ) { Logger::fatal( "Error loading config {0}", m_configPath ); - Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); + failedLoad = true; + } + + if( failedLoad ) + { + Logger::fatal( "If this is the first time starting the server, " + "we've copied the default configs for your editing pleasure." ); return false; } + + // load lobby config + m_config.allowNoSessionConnect = m_pConfig->getValue< bool >( "Lobby", "AllowNoSessionConnect", false ); + m_config.worldName = m_pConfig->getValue< std::string >( "Lobby", "WorldName", "Sapphire" ); + + m_config.network.listenIp = m_pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" ); + m_config.network.listenPort = m_pConfig->getValue< uint16_t >( "Network", "ListenPort", 54994 ); + std::vector< std::string > args( argv + 1, argv + argc ); for( size_t i = 0; i + 1 < args.size(); i += 2 ) { @@ -106,19 +127,19 @@ namespace Sapphire if( arg == "ip" ) { // todo: ip addr in config - m_pConfig->getConfig()->lobbyNetwork.listenIp = val; + m_config.network.listenIp = val; } else if( arg == "p" || arg == "port" ) { - m_pConfig->getConfig()->lobbyNetwork.listenPort = std::stoi( val ); + m_config.network.listenPort = std::stoi( val ); } else if( arg == "worldip" || arg == "worldip" ) { - m_pConfig->getConfig()->globalNetwork.zoneHost = val; + m_config.global.network.zoneHost = val; } else if( arg == "worldport" ) { - m_pConfig->getConfig()->globalNetwork.zonePort = std::stoi( val ); + m_config.global.network.zonePort = std::stoi( val ); } } catch( ... ) @@ -128,13 +149,13 @@ namespace Sapphire } } - m_port = m_pConfig->getConfig()->lobbyNetwork.listenPort; - m_ip = m_pConfig->getConfig()->lobbyNetwork.listenIp; + m_port = m_config.network.listenPort; + m_ip = m_config.network.listenIp; - g_restConnector.restHost = m_pConfig->getConfig()->globalNetwork.restHost + ":" + - std::to_string( m_pConfig->getConfig()->globalNetwork.restPort ); - g_restConnector.serverSecret = m_pConfig->getConfig()->globalParameters.serverSecret; + g_restConnector.restHost = m_config.global.network.restHost + ":" + + std::to_string( m_config.global.network.restPort ); + g_restConnector.serverSecret = m_config.global.parameters.serverSecret; return true; } diff --git a/src/lobby/ServerLobby.h b/src/lobby/ServerLobby.h index e0907682..8e101bfb 100644 --- a/src/lobby/ServerLobby.h +++ b/src/lobby/ServerLobby.h @@ -4,6 +4,7 @@ #include #include +#include #include "Forwards.h" const std::string LOBBY_VERSION = "0.0.5"; @@ -44,12 +45,14 @@ namespace Sapphire m_sessionMap[ std::string( sessionId ) ] = pSession; } - std::shared_ptr< ConfigMgr > getConfig() const; + Sapphire::Common::Config::LobbyConfig& getConfig(); LobbySessionPtr getSession( char* sessionId ); uint32_t m_numConnections; + Sapphire::Common::Config::LobbyConfig m_config; + }; } diff --git a/src/lobby/mainLobbyServer.cpp b/src/lobby/mainLobbyServer.cpp index 2ef742e4..54e1f9ff 100644 --- a/src/lobby/mainLobbyServer.cpp +++ b/src/lobby/mainLobbyServer.cpp @@ -1,6 +1,6 @@ #include "ServerLobby.h" -Sapphire::ServerLobby g_serverLobby( "config.ini" ); +Sapphire::ServerLobby g_serverLobby( "lobby.ini" ); int main( int32_t argc, char* argv[] ) { diff --git a/src/world/Actor/PlayerEvent.cpp b/src/world/Actor/PlayerEvent.cpp index cd32d132..089cc5c0 100644 --- a/src/world/Actor/PlayerEvent.cpp +++ b/src/world/Actor/PlayerEvent.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "Network/GameConnection.h" #include "Network/PacketWrappers/ActorControlPacket142.h" @@ -326,8 +325,8 @@ void Sapphire::Entity::Player::eventItemActionStart( uint32_t eventId, void Sapphire::Entity::Player::onLogin() { - auto pConfig = m_pFw->get< ConfigMgr >(); - auto motd = pConfig->getConfig()->general.motd; + auto pServerMgr = m_pFw->get< Sapphire::World::ServerMgr >(); + auto motd = pServerMgr->getConfig().motd; std::istringstream ss( motd ); std::string msg; diff --git a/src/world/Script/NativeScriptMgr.cpp b/src/world/Script/NativeScriptMgr.cpp index 69126c75..2cf8fa37 100644 --- a/src/world/Script/NativeScriptMgr.cpp +++ b/src/world/Script/NativeScriptMgr.cpp @@ -1,7 +1,7 @@ #include "NativeScriptMgr.h" #include -#include +#include "ServerMgr.h" #include "Framework.h" @@ -124,8 +124,8 @@ namespace Sapphire::Scripting NativeScriptMgr::NativeScriptMgr( FrameworkPtr pFw ) : World::Manager::BaseManager( pFw ) { - auto pConfig = framework()->get< ConfigMgr >(); - m_loader.setCachePath( pConfig->getConfig()->scripts.cachePath ); + auto pServerMgr = framework()->get< Sapphire::World::ServerMgr >(); + m_loader.setCachePath( pServerMgr->getConfig().scripts.cachePath ); } diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index f92f5cb1..13702363 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -1,6 +1,5 @@ #include #include -#include #include @@ -48,9 +47,9 @@ void Sapphire::Scripting::ScriptMgr::update() bool Sapphire::Scripting::ScriptMgr::init() { std::set< std::string > files; - auto pConfig = framework()->get< ConfigMgr >(); + auto pServerMgr = framework()->get< World::ServerMgr >(); - auto status = loadDir( pConfig->getConfig()->scripts.path, files, m_nativeScriptMgr->getModuleExtension() ); + auto status = loadDir( pServerMgr->getConfig().scripts.path, files, m_nativeScriptMgr->getModuleExtension() ); if( !status ) { @@ -80,12 +79,12 @@ bool Sapphire::Scripting::ScriptMgr::init() void Sapphire::Scripting::ScriptMgr::watchDirectories() { - auto pConfig = framework()->get< ConfigMgr >(); - auto shouldWatch = pConfig->getConfig()->scripts.hotSwap; + auto pServerMgr = framework()->get< World::ServerMgr >(); + auto shouldWatch = pServerMgr->getConfig().scripts.hotSwap; if( !shouldWatch ) return; - Watchdog::watchMany( pConfig->getConfig()->scripts.path + "*" + + Watchdog::watchMany( pServerMgr->getConfig().scripts.path + "*" + m_nativeScriptMgr->getModuleExtension(), [ this ]( const std::vector< ci::fs::path >& paths ) { diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 4f3047f2..0ad9295e 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -67,15 +67,43 @@ bool Sapphire::World::ServerMgr::loadSettings( int32_t argc, char* argv[] ) Logger::info( "Loading config {0}", m_configName ); + bool failedLoad = false; + + // load global cfg first + if( !pConfig->loadGlobalConfig( m_config.global ) ) + { + Logger::fatal( "Error loading config global.ini, copying default..." ); + failedLoad = true; + } + if( !pConfig->loadConfig( m_configName ) ) { Logger::fatal( "Error loading config {0}", m_configName ); - Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); + failedLoad = true; + } + + if( failedLoad ) + { + Logger::fatal( "If this is the first time starting the server, " + "we've copied the default configs for your editing pleasure." ); return false; } - m_port = pConfig->getConfig()->zoneNetwork.listenPort; - m_ip = pConfig->getConfig()->zoneNetwork.listenIp; + // load world specific config + m_config.scripts.hotSwap = pConfig->getValue( "Scripts", "HotSwap", true ); + m_config.scripts.path = pConfig->getValue< std::string >( "Scripts", "Path", "./compiledscripts/" ); + m_config.scripts.cachePath = pConfig->getValue< std::string >( "Scripts", "CachePath", "./cache/" ); + + m_config.network.disconnectTimeout = pConfig->getValue< uint16_t >( "Network", "DisconnectTimeout", 20 ); + m_config.network.listenIp = pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" ); + m_config.network.listenPort = pConfig->getValue< uint16_t >( "Network", "ListenPort", 54992 ); + + m_config.motd = pConfig->getValue< std::string >( "General", "MotD", "" ); + + m_config.housing.defaultEstateName = pConfig->getValue< std::string >( "Housing", "DefaultEstateName", "Estate #{}" ); + + m_port = m_config.network.listenPort; + m_ip = m_config.network.listenIp; return true; } @@ -99,7 +127,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) Logger::info( "Setting up generated EXD data" ); auto pExdData = std::make_shared< Data::ExdDataGenerated >(); - auto dataPath = pConfig->getConfig()->globalParameters.dataPath; + auto dataPath = m_config.global.parameters.dataPath; if( !pExdData->init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); @@ -109,13 +137,13 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) framework()->set< Data::ExdDataGenerated >( pExdData ); Sapphire::Db::ConnectionInfo info; - 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; + 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 > >(); Sapphire::Db::DbLoader loader; @@ -461,3 +489,8 @@ Sapphire::Entity::BNpcTemplatePtr Sapphire::World::ServerMgr::getBNpcTemplate( u return nullptr; } + +Sapphire::Common::Config::WorldConfig& Sapphire::World::ServerMgr::getConfig() +{ + return m_config; +} diff --git a/src/world/ServerMgr.h b/src/world/ServerMgr.h index a18e0c45..fa3cf5ea 100644 --- a/src/world/ServerMgr.h +++ b/src/world/ServerMgr.h @@ -7,6 +7,7 @@ #include #include "ForwardsZone.h" #include "Manager/BaseManager.h" +#include namespace Sapphire::World { @@ -18,6 +19,8 @@ namespace Sapphire::World ~ServerMgr() override; + using WorldConfigPtr = std::shared_ptr< Sapphire::Common::Config::WorldConfig >; + void run( int32_t argc, char* argv[] ); bool createSession( uint32_t sessionId ); @@ -48,6 +51,8 @@ namespace Sapphire::World std::string getPlayerNameFromDb( uint32_t playerId, bool forceDbLoad = false ); void updatePlayerName( uint32_t playerId, const std::string& playerNewName ); + Sapphire::Common::Config::WorldConfig& getConfig(); + private: uint16_t m_port; std::string m_ip; @@ -59,6 +64,8 @@ namespace Sapphire::World std::mutex m_sessionMutex; + Sapphire::Common::Config::WorldConfig m_config; + std::map< uint32_t, SessionPtr > m_sessionMapById; std::map< std::string, SessionPtr > m_sessionMapByName; std::map< uint32_t, std::string > m_playerNameMapById; diff --git a/src/world/mainGameServer.cpp b/src/world/mainGameServer.cpp index a39f068b..a0dcddac 100644 --- a/src/world/mainGameServer.cpp +++ b/src/world/mainGameServer.cpp @@ -9,7 +9,7 @@ using namespace Sapphire::World; int main( int32_t argc, char* argv[] ) { auto pFramework = Sapphire::make_Framework(); - auto pServer = std::make_shared< ServerMgr >( "config.ini", pFramework ); + auto pServer = std::make_shared< ServerMgr >( "world.ini", pFramework ); pFramework->set< ServerMgr >( pServer ); pServer->run( argc, argv ); return 0; From bf0324cfea6e8d30f47dc3d6f2a72f2ccee2d014 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:08:43 +1100 Subject: [PATCH 5/9] everything should be working again... --- src/api/main.cpp | 25 ++++++++++--------------- src/common/Config/ConfigMgr.cpp | 2 +- src/common/Config/ConfigMgr.h | 2 +- src/world/ServerMgr.cpp | 2 +- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/src/api/main.cpp b/src/api/main.cpp index 8c0ae020..23580484 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -49,25 +49,26 @@ void default_resource_send( const HttpServer& server, const shared_ptr< HttpServ const shared_ptr< ifstream >& ifs ); -auto m_pConfig = std::make_shared< Sapphire::ConfigMgr >(); HttpServer server; std::string configPath( "api.ini" ); Sapphire::Common::Config::ApiConfig m_config; void reloadConfig() { - m_pConfig = std::make_shared< Sapphire::ConfigMgr >(); + auto pConfig = std::make_shared< Sapphire::ConfigMgr >(); + + Logger::info( "Loading config " + configPath ); bool failedLoad = false; // load global cfg first - if( !m_pConfig->loadGlobalConfig( m_config.global ) ) + if( !pConfig->loadGlobalConfig( m_config.global ) ) { Logger::fatal( "Error loading config global.ini" ); failedLoad = true; } - if( !m_pConfig->loadConfig( configPath ) ) + if( !pConfig->loadConfig( configPath ) ) { Logger::fatal( "Error loading config {0}", configPath ); failedLoad = true; @@ -75,12 +76,13 @@ void reloadConfig() if( failedLoad ) { + Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); throw "Error loading config"; } // setup api config - m_config.network.listenPort = m_pConfig->getValue< uint16_t >( "Network", "ListenPort", 80 ); - m_config.network.listenIP = m_pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" ); + m_config.network.listenPort = pConfig->getValue< uint16_t >( "Network", "ListenPort", 80 ); + m_config.network.listenIP = pConfig->getValue< std::string >( "Network", "ListenIp", "0.0.0.0" ); } void print_request_info( shared_ptr< HttpServer::Request > request ) @@ -90,14 +92,7 @@ void print_request_info( shared_ptr< HttpServer::Request > request ) bool loadSettings( int32_t argc, char* argv[] ) { - Logger::info( "Loading config " + configPath ); - - if( !m_pConfig->loadConfig( configPath ) ) - { - Logger::fatal( "Error loading config {0}", configPath ); - Logger::fatal( "If this is the first time starting the server, we've copied the default one for your editing pleasure." ); - return false; - } + reloadConfig(); std::vector< std::string > args( argv + 1, argv + argc ); for( size_t i = 0; i + 1 < args.size(); i += 2 ) @@ -126,7 +121,7 @@ bool loadSettings( int32_t argc, char* argv[] ) auto dataPath = m_config.global.parameters.dataPath; if( !g_exdDataGen.init( dataPath ) ) { - Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); + Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in global.ini" ); Logger::fatal( "DataPath: {0}", dataPath ); return false; } diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index 222c4a85..aa5ddc9a 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -31,7 +31,7 @@ bool Sapphire::ConfigMgr::loadConfig( const std::string& configName ) return true; } -bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName ) +bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config, const std::string& configName ) { auto configFile = fs::path( fs::path( m_configFolderRoot ) / configName ); diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index 91dab976..edcc3567 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -17,7 +17,7 @@ namespace Sapphire ~ConfigMgr() = default; bool loadConfig( const std::string& configName ); - bool loadGlobalConfig( Common::Config::GlobalConfig& config, const string& configName = "global.ini" ); + bool loadGlobalConfig( Common::Config::GlobalConfig& config, const std::string& configName = "global.ini" ); template struct always_false : std::false_type {}; diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 0ad9295e..a5e74e29 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -130,7 +130,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) auto dataPath = m_config.global.parameters.dataPath; if( !pExdData->init( dataPath ) ) { - Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in config.ini" ); + Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in global.ini" ); Logger::fatal( "DataPath: {0}", dataPath ); return; } From eb56f5fda2ddde78a23042bd6b0bb73eaa6ef59c Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:16:01 +1100 Subject: [PATCH 6/9] cleanup db connection config --- src/api/main.cpp | 15 +++------------ src/common/Config/ConfigDef.h | 13 +++---------- src/common/Config/ConfigMgr.cpp | 2 +- src/common/Database/DbCommon.h | 18 ++++++++++++++++++ src/common/Database/DbConnection.h | 12 +----------- src/world/ServerMgr.cpp | 11 +---------- 6 files changed, 27 insertions(+), 44 deletions(-) create mode 100644 src/common/Database/DbCommon.h diff --git a/src/api/main.cpp b/src/api/main.cpp index 23580484..372cad9f 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -76,7 +76,7 @@ void reloadConfig() 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"; } @@ -128,23 +128,14 @@ bool loadSettings( int32_t argc, char* argv[] ) Sapphire::Db::DbLoader loader; - 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; - - loader.addDb( g_charaDb, info ); + loader.addDb( g_charaDb, m_config.global.database ); if( !loader.initDbs() ) return false; server.config.port = m_config.network.listenPort; 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; } diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h index ac4f3952..2fcc8251 100644 --- a/src/common/Config/ConfigDef.h +++ b/src/common/Config/ConfigDef.h @@ -1,20 +1,13 @@ #ifndef SAPPHIRE_CONFIGDEF_H #define SAPPHIRE_CONFIGDEF_H +#include + namespace Sapphire::Common::Config { struct GlobalConfig { - struct Database - { - std::string host; - uint16_t port; - std::string database; - std::string username; - std::string password; - uint8_t syncThreads; - uint8_t asyncThreads; - } database; + Sapphire::Db::ConnectionInfo database; struct Parameters { diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index aa5ddc9a..e42e04bb 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -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.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.user = 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 ); diff --git a/src/common/Database/DbCommon.h b/src/common/Database/DbCommon.h new file mode 100644 index 00000000..89d537b6 --- /dev/null +++ b/src/common/Database/DbCommon.h @@ -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 diff --git a/src/common/Database/DbConnection.h b/src/common/Database/DbConnection.h index 05bfd793..a31a531d 100644 --- a/src/common/Database/DbConnection.h +++ b/src/common/Database/DbConnection.h @@ -7,6 +7,7 @@ #include #include #include "Util/LockedWaitQueue.h" +#include "DbCommon.h" namespace Mysql { @@ -31,17 +32,6 @@ namespace Sapphire::Db 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 > >; class DbConnection : diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index a5e74e29..5014dc08 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -136,18 +136,9 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) } 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 > >(); Sapphire::Db::DbLoader loader; - loader.addDb( *pDb, info ); + loader.addDb( *pDb, m_config.global.database ); if( !loader.initDbs() ) { Logger::fatal( "Database not initialized properly!" ); From 047d0328e083767cf6ecabd5db147055e5f5473b Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:20:50 +1100 Subject: [PATCH 7/9] remove old shit --- src/common/Config/ConfigMgr.cpp | 19 ------------------- src/common/Config/ConfigMgr.h | 1 - 2 files changed, 20 deletions(-) diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index e42e04bb..d236f9dd 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -85,23 +85,4 @@ bool Sapphire::ConfigMgr::copyDefaultConfig( const std::string& configName ) fs::copy_file( configPath.string() + m_configDefaultSuffix, configPath ); return true; -} - -void Sapphire::ConfigMgr::initConfigData() -{ - // 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 ); } \ No newline at end of file diff --git a/src/common/Config/ConfigMgr.h b/src/common/Config/ConfigMgr.h index edcc3567..265cff46 100644 --- a/src/common/Config/ConfigMgr.h +++ b/src/common/Config/ConfigMgr.h @@ -59,7 +59,6 @@ namespace Sapphire private: bool copyDefaultConfig( const std::string& configName ); - void initConfigData(); std::unique_ptr< INIReader > m_pInih; From 35def4d4f2c86bc2af807000ac13675493689e15 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:26:34 +1100 Subject: [PATCH 8/9] refactor parameters to general, fix build error --- config/global.ini.default | 2 +- src/api/main.cpp | 20 ++++++++++---------- src/common/Config/ConfigDef.h | 4 ++-- src/common/Config/ConfigMgr.cpp | 10 ++++------ src/lobby/GameConnection.cpp | 6 +++--- src/lobby/ServerLobby.cpp | 2 +- src/world/ServerMgr.cpp | 2 +- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/config/global.ini.default b/config/global.ini.default index 46cd4747..87c3b4cc 100644 --- a/config/global.ini.default +++ b/config/global.ini.default @@ -7,7 +7,7 @@ Password = SyncThreads = 2 AsyncThreads = 2 -[Parameters] +[General] ServerSecret = default DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack WorldID = 67 diff --git a/src/api/main.cpp b/src/api/main.cpp index 372cad9f..5fd967a0 100644 --- a/src/api/main.cpp +++ b/src/api/main.cpp @@ -118,7 +118,7 @@ bool loadSettings( int32_t argc, char* argv[] ) } Logger::info( "Setting up generated EXD data" ); - auto dataPath = m_config.global.parameters.dataPath; + auto dataPath = m_config.global.general.dataPath; if( !g_exdDataGen.init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in global.ini" ); @@ -300,7 +300,7 @@ void deleteCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H int32_t accountId = g_sapphireAPI.checkSession( sId ); - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -340,7 +340,7 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H if( result != -1 ) { - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -348,7 +348,7 @@ void createCharacter( shared_ptr< HttpServer::Response > response, shared_ptr< H else { int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, - m_config.global.parameters.defaultGMRank ); + m_config.global.general.defaultGMRank ); std::string json_string = "{\"result\":\"" + std::to_string( charId ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); @@ -381,7 +381,7 @@ void insertSession( shared_ptr< HttpServer::Response > response, shared_ptr< Htt std::string secret = json["secret"]; // reloadConfig(); - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -413,7 +413,7 @@ void checkNameTaken( shared_ptr< HttpServer::Response > response, shared_ptr< Ht // reloadConfig(); - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -450,7 +450,7 @@ void checkSession( shared_ptr< HttpServer::Response > response, shared_ptr< Http if( result != -1 ) { - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -489,7 +489,7 @@ void getNextCharId( shared_ptr< HttpServer::Response > response, shared_ptr< Htt // reloadConfig(); - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -520,7 +520,7 @@ void getNextContentId( shared_ptr< HttpServer::Response > response, shared_ptr< // reloadConfig(); - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -555,7 +555,7 @@ void getCharacterList( shared_ptr< HttpServer::Response > response, shared_ptr< if( result != -1 ) { - if( m_config.global.parameters.serverSecret != secret ) + if( m_config.global.general.serverSecret != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); diff --git a/src/common/Config/ConfigDef.h b/src/common/Config/ConfigDef.h index 2fcc8251..a6a111b8 100644 --- a/src/common/Config/ConfigDef.h +++ b/src/common/Config/ConfigDef.h @@ -9,14 +9,14 @@ namespace Sapphire::Common::Config { Sapphire::Db::ConnectionInfo database; - struct Parameters + struct General { std::string serverSecret; std::string dataPath; uint16_t worldID; uint8_t defaultGMRank; - } parameters; + } general; struct Network { diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index d236f9dd..fe5cee56 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -26,8 +26,6 @@ bool Sapphire::ConfigMgr::loadConfig( const std::string& configName ) if( m_pInih->ParseError() < 0 ) return false; - initConfigData(); - return true; } @@ -55,10 +53,10 @@ bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config 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 ); - config.parameters.defaultGMRank = getValue< uint8_t >( "Parameters", "DefaultGMRank", 255 ); + config.general.dataPath = getValue< std::string >( "Parameters", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); + config.general.serverSecret = getValue< std::string >( "Parameters", "ServerSecret", "default" ); + config.general.worldID = getValue< uint16_t >( "Parameters", "WorldID", 67 ); + config.general.defaultGMRank = getValue< uint8_t >( "Parameters", "DefaultGMRank", 255 ); // network config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" ); diff --git a/src/lobby/GameConnection.cpp b/src/lobby/GameConnection.cpp index f5e5180e..6b17b453 100644 --- a/src/lobby/GameConnection.cpp +++ b/src/lobby/GameConnection.cpp @@ -128,7 +128,7 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet serverListPacket->data().seq = 1; serverListPacket->data().offset = 0; serverListPacket->data().numServers = 1; - serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig().global.parameters.worldID; + serverListPacket->data().server[ 0 ].id = g_serverLobby.getConfig().global.general.worldID; serverListPacket->data().server[ 0 ].index = 0; serverListPacket->data().final = 1; strcpy( serverListPacket->data().server[ 0 ].name, g_serverLobby.getConfig().worldName.c_str() ); @@ -161,8 +161,8 @@ void Sapphire::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet auto& charEntry = charList[ charIndex ]; details.uniqueId = std::get< 1 >( charEntry ); details.contentId = std::get< 2 >( charEntry ); - details.serverId = g_serverLobby.getConfig().global.parameters.worldID; - details.serverId1 = g_serverLobby.getConfig().global.parameters.worldID; + details.serverId = g_serverLobby.getConfig().global.general.worldID; + details.serverId1 = g_serverLobby.getConfig().global.general.worldID; details.index = charIndex; strcpy( details.charDetailJson, std::get< 3 >( charEntry ).c_str() ); strcpy( details.nameChara, std::get< 0 >( charEntry ).c_str() ); diff --git a/src/lobby/ServerLobby.cpp b/src/lobby/ServerLobby.cpp index 7d09dcbe..d1530dcf 100644 --- a/src/lobby/ServerLobby.cpp +++ b/src/lobby/ServerLobby.cpp @@ -155,7 +155,7 @@ namespace Sapphire g_restConnector.restHost = m_config.global.network.restHost + ":" + std::to_string( m_config.global.network.restPort ); - g_restConnector.serverSecret = m_config.global.parameters.serverSecret; + g_restConnector.serverSecret = m_config.global.general.serverSecret; return true; } diff --git a/src/world/ServerMgr.cpp b/src/world/ServerMgr.cpp index 5014dc08..d675859a 100644 --- a/src/world/ServerMgr.cpp +++ b/src/world/ServerMgr.cpp @@ -127,7 +127,7 @@ void Sapphire::World::ServerMgr::run( int32_t argc, char* argv[] ) Logger::info( "Setting up generated EXD data" ); auto pExdData = std::make_shared< Data::ExdDataGenerated >(); - auto dataPath = m_config.global.parameters.dataPath; + auto dataPath = m_config.global.general.dataPath; if( !pExdData->init( dataPath ) ) { Logger::fatal( "Error setting up generated EXD data. Make sure that DataPath is set correctly in global.ini" ); From 2776ecd6d40de9e20b844200af2a4aa2bd961691 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:31:04 +1100 Subject: [PATCH 9/9] update ini reading to use 'general' instead of 'parameters' --- src/common/Config/ConfigMgr.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/Config/ConfigMgr.cpp b/src/common/Config/ConfigMgr.cpp index fe5cee56..a1ad914b 100644 --- a/src/common/Config/ConfigMgr.cpp +++ b/src/common/Config/ConfigMgr.cpp @@ -53,10 +53,10 @@ bool Sapphire::ConfigMgr::loadGlobalConfig( Common::Config::GlobalConfig& config config.database.asyncThreads = getValue< uint8_t >( "Database", "AsyncThreads", 2 ); // params - config.general.dataPath = getValue< std::string >( "Parameters", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); - config.general.serverSecret = getValue< std::string >( "Parameters", "ServerSecret", "default" ); - config.general.worldID = getValue< uint16_t >( "Parameters", "WorldID", 67 ); - config.general.defaultGMRank = getValue< uint8_t >( "Parameters", "DefaultGMRank", 255 ); + config.general.dataPath = getValue< std::string >( "General", "DataPath", "C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack" ); + config.general.serverSecret = getValue< std::string >( "General", "ServerSecret", "default" ); + config.general.worldID = getValue< uint16_t >( "General", "WorldID", 67 ); + config.general.defaultGMRank = getValue< uint8_t >( "General", "DefaultGMRank", 255 ); // network config.network.zoneHost = getValue< std::string >( "Network", "ZoneHost", "127.0.0.1" );