From cd1d8f81262d5bcc5191a52152c5a34ee8a2adb0 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Mon, 7 Jan 2019 23:00:09 +1100 Subject: [PATCH] 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;