From 463d56e76efb6024864bb6bc9f57d99e1f3d4fd7 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 10 Jun 2018 16:34:26 +0000 Subject: [PATCH] remove old XMLConfig completely and implement new ConfigMgr --- bin/config/settings_lobby.xml | 34 --------- bin/config/settings_rest.xml | 32 -------- bin/config/settings_zone.xml | 45 ----------- src/common/Forwards.h | 4 +- src/servers/sapphire_api/main.cpp | 76 +++++++++---------- src/servers/sapphire_lobby/GameConnection.cpp | 21 ++--- src/servers/sapphire_lobby/ServerLobby.cpp | 26 +++---- src/servers/sapphire_lobby/ServerLobby.h | 7 +- .../sapphire_lobby/mainLobbyServer.cpp | 2 +- src/servers/sapphire_zone/Actor/Player.cpp | 1 - .../sapphire_zone/Actor/PlayerEvent.cpp | 12 ++- src/servers/sapphire_zone/Actor/PlayerSql.cpp | 1 - .../sapphire_zone/Script/ScriptLoader.cpp | 6 +- .../sapphire_zone/Script/ScriptMgr.cpp | 12 +-- src/servers/sapphire_zone/ServerZone.cpp | 56 +++++++------- src/servers/sapphire_zone/ServerZone.h | 4 +- src/servers/sapphire_zone/mainGameServer.cpp | 10 +-- 17 files changed, 116 insertions(+), 233 deletions(-) delete mode 100644 bin/config/settings_lobby.xml delete mode 100644 bin/config/settings_rest.xml delete mode 100644 bin/config/settings_zone.xml diff --git a/bin/config/settings_lobby.xml b/bin/config/settings_lobby.xml deleted file mode 100644 index df2052ce..00000000 --- a/bin/config/settings_lobby.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - 54994 - 54998 - - 127.0.0.1 - - 127.0.0.1 - - 54992 - - 127.0.0.1:80 - - default - - - 127.0.0.1 - 3306 - root - - sapphire - - - - - false - - 67 - - - Sapphire - - \ No newline at end of file diff --git a/bin/config/settings_rest.xml b/bin/config/settings_rest.xml deleted file mode 100644 index c0b84b7f..00000000 --- a/bin/config/settings_rest.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - 54994 - 54998 - - 127.0.0.1 - - C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack - - - 127.0.0.1 - - 127.0.0.1 - - default - - 80 - - 127.0.0.1 - 3306 - root - - sapphire - - - - - - 255 - - diff --git a/bin/config/settings_zone.xml b/bin/config/settings_zone.xml deleted file mode 100644 index 5282957a..00000000 --- a/bin/config/settings_zone.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - 54992 - - 127.0.0.1 - - C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack - - - - ./compiledscripts/ - ./cache/ - - - true - ../scripts/native/ - ../cmake-build-debug/ - cmake --build %1% --target %2% - - - - - ./compiledscripts/ - - - 127.0.0.1 - 3306 - root - - sapphire - 2 - 2 - - - - - - - <<<Welcome to Sapphire>>> - This is a very good server - You can change these messages by editing MotDArray in config/settings_zone.xml - - - diff --git a/src/common/Forwards.h b/src/common/Forwards.h index 515bfe0e..5c8061db 100644 --- a/src/common/Forwards.h +++ b/src/common/Forwards.h @@ -6,9 +6,9 @@ namespace Core { - class XMLConfig; + class ConfigMgr; - typedef boost::shared_ptr XMLConfigPtr; + typedef boost::shared_ptr ConfigMgrPtr; namespace Network diff --git a/src/servers/sapphire_api/main.cpp b/src/servers/sapphire_api/main.cpp index d42d53cf..d4fac57b 100644 --- a/src/servers/sapphire_api/main.cpp +++ b/src/servers/sapphire_api/main.cpp @@ -7,7 +7,7 @@ #include #include -#include +#include #include #include @@ -52,13 +52,13 @@ void default_resource_send( const HttpServer &server, const shared_ptr< HttpServ const shared_ptr< ifstream > &ifs ); -auto m_pConfig = boost::make_shared< Core::XMLConfig >(); +auto m_pConfig = boost::make_shared< Core::ConfigMgr >(); HttpServer server; -std::string configPath( "config/settings_rest.xml" ); +std::string configPath( "rest.ini" ); void reloadConfig() { - m_pConfig = boost::make_shared< Core::XMLConfig >(); + m_pConfig = boost::make_shared< Core::ConfigMgr >(); if( !m_pConfig->loadConfig( configPath ) ) throw "Error loading config "; @@ -96,43 +96,43 @@ bool loadSettings( int32_t argc, char* argv[] ) if( arg == "ip" ) { // todo: ip addr in config - m_pConfig->setValue< std::string >( "Settings.General.ListenIP", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.RestHost", val ); } else if( arg == "p" || arg == "port" ) { - m_pConfig->setValue< std::string >( "Settings.General.ListenPort", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.RestPort", val ); } else if( arg == "exdpath" || arg == "datapath" ) { - m_pConfig->setValue< std::string >( "Settings.General.DataPath", val ); + m_pConfig->setValue< std::string >( "GlobalParameters.DataPath", val ); } else if( arg == "h" || arg == "dbhost" ) { - m_pConfig->setValue< std::string >( "Settings.General.Mysql.Host", val ); + m_pConfig->setValue< std::string >( "Database.Host", val ); } else if( arg == "dbport" ) { - m_pConfig->setValue< std::string >( "Settings.General.Mysql.Port", val ); + m_pConfig->setValue< std::string >( "Database.Port", val ); } else if( arg == "u" || arg == "user" || arg == "dbuser" ) { - m_pConfig->setValue< std::string >( "Settings.General.Mysql.Username", val ); + m_pConfig->setValue< std::string >( "Database.Username", val ); } else if( arg == "pass" || arg == "dbpass" ) { - m_pConfig->setValue< std::string >( "Settings.General.Mysql.Pass", val ); + m_pConfig->setValue< std::string >( "Database.Password", val ); } else if( arg == "d" || arg == "db" || arg == "database" ) { - m_pConfig->setValue< std::string >( "Settings.General.Mysql.Database", val ); + m_pConfig->setValue< std::string >( "Database.Database", val ); } else if ( arg == "lobbyip" || arg == "lobbyhost" ) { - m_pConfig->setValue< std::string >( "Settings.General.LobbyHost", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyHost", val ); } else if ( arg == "lobbyport" ) { - m_pConfig->setValue< std::string >( "Settings.General.LobbyPort", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyPort", val ); } } catch( ... ) @@ -143,7 +143,7 @@ bool loadSettings( int32_t argc, char* argv[] ) } g_log.info( "Setting up generated EXD data" ); - if( !g_exdDataGen.init( m_pConfig->getValue< std::string >( "Settings.General.DataPath", "" ) ) ) + if( !g_exdDataGen.init( m_pConfig->getValue< std::string >( "GlobalParameters.DataPath", "" ) ) ) { g_log.fatal( "Error setting up generated EXD data " ); return false; @@ -152,19 +152,19 @@ bool loadSettings( int32_t argc, char* argv[] ) Core::Db::DbLoader loader; Core::Db::ConnectionInfo info; - info.password = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Pass", "" ); - info.host = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Host", "127.0.0.1" ); - info.database = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Database", "sapphire" ); - info.port = m_pConfig->getValue< uint16_t >( "Settings.General.Mysql.Port", 3306 ); - info.user = m_pConfig->getValue< std::string >( "Settings.General.Mysql.Username", "root" ); - info.syncThreads = m_pConfig->getValue< uint8_t >( "Settings.General.Mysql.SyncThreads", 2 ); - info.asyncThreads = m_pConfig->getValue< uint8_t >( "Settings.General.Mysql.AsyncThreads", 2 ); + 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 ); loader.addDb( g_charaDb, info ); if( !loader.initDbs() ) return false; - server.config.port = static_cast< uint16_t >( std::stoul( m_pConfig->getValue< std::string >( "Settings.General.HttpPort", "80" ) ) ); + server.config.port = static_cast< uint16_t >( std::stoul( m_pConfig->getValue< std::string >( "GlobalNetwork.RestPort", "80" ) ) ); g_log.info( "Database: Connected to " + info.host + ":" + std::to_string( info.port ) ); @@ -269,8 +269,8 @@ void createAccount( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.LobbyHost" ) + - "\", \"frontierHost\":\"" + m_pConfig->getValue< std::string >( "Settings.General.FrontierHost" ) + "\"}"; + "\", \"lobbyHost\":\"" + m_pConfig->getValue< std::string >( "GlobalNetwork.LobbyHost" ) + + "\", \"frontierHost\":\"" + m_pConfig->getValue< std::string >( "GlobalNetwork.RestHost" ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -301,8 +301,8 @@ void login( shared_ptr response, shared_ptrgetValue< std::string >("Settings.General.LobbyHost") + - "\", \"frontierHost\":\"" + m_pConfig->getValue< std::string >( "Settings.General.FrontierHost" ) + "\"}"; + "\", \"lobbyHost\":\"" + m_pConfig->getValue< std::string >( "GlobalNetwork.LobbyHost" ) + + "\", \"frontierHost\":\"" + m_pConfig->getValue< std::string >( "GlobalNetwork.RestHost" ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); } else @@ -333,7 +333,7 @@ void deleteCharacter( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -374,14 +374,14 @@ void createCharacter( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "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 >( "Settings.Parameters.DefaultGMRank", 255 ) ); + int32_t charId = g_sapphireAPI.createCharacter( result, name, finalJson, m_pConfig->getValue< uint8_t >( "CharacterCreation.DefaultGMRank", 255 ) ); std::string json_string = "{\"result\":\"" + std::to_string( charId ) + "\"}"; *response << buildHttpResponse( 200, json_string, JSON ); @@ -414,7 +414,7 @@ void insertSession( shared_ptr response, shared_ptr( "accountId" ); std::string secret = pt.get( "secret" ); // reloadConfig(); - if( m_pConfig->getValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -448,7 +448,7 @@ void checkNameTaken( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -486,7 +486,7 @@ void checkSession( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -523,7 +523,7 @@ void getNextCharId( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -555,7 +555,7 @@ void getNextContentId( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -591,7 +591,7 @@ void getCharacterList( shared_ptr response, shared_ptrgetValue< std::string >( "Settings.General.ServerSecret" ) != secret ) + if( m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" ) != secret ) { std::string json_string = "{\"result\":\"invalid_secret\"}"; *response << buildHttpResponse( 403, json_string, JSON ); @@ -756,8 +756,8 @@ int main( int argc, char* argv[] ) if( !loadSettings( argc, argv ) ) throw std::exception(); - server.config.port = stoi( m_pConfig->getValue< std::string >( "Settings.General.HttpPort", "80" ) ); - g_log.info( "Starting API server at port " + m_pConfig->getValue< std::string >( "Settings.General.HttpPort", "80" ) + "..." ); + server.config.port = stoi( m_pConfig->getValue< std::string >( "GlobalNetwork.RestPort", "80" ) ); + g_log.info( "Starting API server at port " + m_pConfig->getValue< std::string >( "GlobalNetwork.RestPort", "80" ) + "..." ); server.resource["^/ZoneName/([0-9]+)$"]["GET"] = &getZoneName; server.resource["^/sapphire-api/lobby/createAccount"]["POST"] = &createAccount; diff --git a/src/servers/sapphire_lobby/GameConnection.cpp b/src/servers/sapphire_lobby/GameConnection.cpp index 12c40d78..2d99df2c 100644 --- a/src/servers/sapphire_lobby/GameConnection.cpp +++ b/src/servers/sapphire_lobby/GameConnection.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -129,10 +130,10 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui serverListPacket.data().seq = 1; serverListPacket.data().offset = 0; serverListPacket.data().numServers = 1; - serverListPacket.data().server[0].id = g_serverLobby.getConfig()->getValue( "Settings.Parameters.WorldID", 1 ); + serverListPacket.data().server[0].id = g_serverLobby.getConfig()->getValue( "Lobby.WorldID", 1 ); serverListPacket.data().server[0].index = 0; serverListPacket.data().final = 1; - strcpy( serverListPacket.data().server[0].name, g_serverLobby.getConfig()->getValue< std::string >( "Settings.Parameters.WorldName", "Sapphire" ).c_str() ); + strcpy( serverListPacket.data().server[0].name, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); pRP.addPacket( serverListPacket ); @@ -166,11 +167,11 @@ void Core::Network::GameConnection::getCharList( FFXIVARR_PACKET_RAW& packet, ui auto& charEntry = charList[charIndex]; details.uniqueId = get< 1 >( charEntry ); details.contentId = get< 2 >( charEntry ); - details.serverId = g_serverLobby.getConfig()->getValue( "Settings.Parameters.WorldID", 1 ); + details.serverId = g_serverLobby.getConfig()->getValue( "Lobby.WorldID", 1 ); details.index = charIndex; strcpy( details.charDetailJson, get< 3 >( charEntry ).c_str() ); strcpy( details.nameChara, get< 0 >( charEntry ).c_str() ); - strcpy( details.nameServer, g_serverLobby.getConfig()->getValue< std::string >( "Settings.Parameters.WorldName", "Sapphire" ).c_str() ); + strcpy( details.nameServer, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); charListPacket.data().charaDetails[j] = details; @@ -238,8 +239,8 @@ void Core::Network::GameConnection::enterWorld( FFXIVARR_PACKET_RAW& packet, uin enterWorldPacket.data().contentId = lookupId; enterWorldPacket.data().seq = sequence; - strcpy( enterWorldPacket.data().host, g_serverLobby.getConfig()->getValue< std::string >( "Settings.General.ZoneIp" ).c_str() ); - enterWorldPacket.data().port = g_serverLobby.getConfig()->getValue< uint16_t >( "Settings.General.ZonePort" ); + 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" ); enterWorldPacket.data().charId = logInCharId; memcpy( enterWorldPacket.data().sid, m_pSession->getSessionId(), 66 ); @@ -251,7 +252,7 @@ bool Core::Network::GameConnection::sendServiceAccountList( FFXIVARR_PACKET_RAW& { LobbySessionPtr pSession = g_serverLobby.getSession( ( char* )&packet.data[0] + 0x20 ); - if( g_serverLobby.getConfig()->getValue< bool >( "Settings.Parameters.AllowNoSessionConnect" ) && pSession == nullptr ) + if( g_serverLobby.getConfig()->getValue< bool >( "Lobby.AllowNoSessionConnect" ) && pSession == nullptr ) { auto session = make_LobbySession(); session->setAccountID( 0 ); @@ -319,7 +320,7 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac charCreatePacket.data().content_id = newContentId; strcpy( charCreatePacket.data().name, name.c_str() ); - strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Settings.Parameters.WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); charCreatePacket.data().type = 1; charCreatePacket.data().seq = sequence; charCreatePacket.data().unknown = 1; @@ -343,7 +344,7 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac charCreatePacket.data().content_id = newContentId; strcpy( charCreatePacket.data().name, name.c_str() ); - strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Settings.Parameters.WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); charCreatePacket.data().type = 2; charCreatePacket.data().seq = sequence; charCreatePacket.data().unknown = 1; @@ -374,7 +375,7 @@ bool Core::Network::GameConnection::createOrModifyChar( FFXIVARR_PACKET_RAW& pac //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 >( "Settings.Parameters.WorldName", "Sapphire" ).c_str() ); + strcpy( charCreatePacket.data().world, g_serverLobby.getConfig()->getValue< std::string >( "Lobby.WorldName", "Sapphire" ).c_str() ); charCreatePacket.data().type = 4; charCreatePacket.data().seq = sequence; charCreatePacket.data().unknown = 1; diff --git a/src/servers/sapphire_lobby/ServerLobby.cpp b/src/servers/sapphire_lobby/ServerLobby.cpp index 82693b12..ff59fd84 100644 --- a/src/servers/sapphire_lobby/ServerLobby.cpp +++ b/src/servers/sapphire_lobby/ServerLobby.cpp @@ -8,7 +8,7 @@ #include #include -#include +#include //#include "LobbySession.h" @@ -37,7 +37,7 @@ namespace Core { m_configPath( configPath ), m_numConnections( 0 ) { - m_pConfig = boost::shared_ptr( new XMLConfig ); + m_pConfig = boost::shared_ptr< ConfigMgr >( new ConfigMgr ); } ServerLobby::~ServerLobby( void ) @@ -49,7 +49,7 @@ namespace Core { return g_restConnector.getSession( sessionId ); } - XMLConfigPtr ServerLobby::getConfig() const + ConfigMgrPtr ServerLobby::getConfig() const { return m_pConfig; } @@ -109,23 +109,19 @@ namespace Core { if( arg == "ip" ) { // todo: ip addr in config - m_pConfig->setValue< std::string >( "Settings.General.ListenIp", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyHost", val ); } else if( arg == "p" || arg == "port" ) { - m_pConfig->setValue< std::string >( "Settings.General.ListenPort", val ); - } - else if( arg == "ap" || arg == "auth" || arg == "authport" ) - { - m_pConfig->setValue< std::string>( "Settings.General.AuthPort", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyPort", val ); } else if( arg == "worldip" || arg == "worldip" ) { - m_pConfig->setValue < std::string >( "Settings.General.WorldIp", val ); + m_pConfig->setValue < std::string >( "GlobalNetwork.ZoneHost", val ); } else if( arg == "worldport" ) { - m_pConfig->setValue< std::string >( "Settings.General.WorldPort", val ); + m_pConfig->setValue< std::string >( "GlobalNetwork.ZonePort", val ); } } catch( ... ) @@ -135,11 +131,11 @@ namespace Core { } } - m_port = m_pConfig->getValue< uint16_t >( "Settings.General.ListenPort", 54994 ); - m_ip = m_pConfig->getValue< std::string >( "Settings.General.ListenIp", "0.0.0.0" ); + m_port = m_pConfig->getValue< uint16_t >( "GlobalNetwork.LobbyPort", 54994 ); + m_ip = m_pConfig->getValue< std::string >( "GlobalNetwork.LobbyHost", "0.0.0.0" ); - g_restConnector.restHost = m_pConfig->getValue< std::string >( "Settings.General.RestHost" ); - g_restConnector.serverSecret = m_pConfig->getValue< std::string >( "Settings.General.ServerSecret" ); + 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" ); return true; } diff --git a/src/servers/sapphire_lobby/ServerLobby.h b/src/servers/sapphire_lobby/ServerLobby.h index 8f28cdc0..b4efd1db 100644 --- a/src/servers/sapphire_lobby/ServerLobby.h +++ b/src/servers/sapphire_lobby/ServerLobby.h @@ -6,7 +6,6 @@ #include #include -#include #include "Forwards.h" @@ -15,7 +14,7 @@ const std::string LOBBY_VERSION = "0.0.5"; namespace Core { class LobbySession; - class XMLConfig; + class ConfigMgr; typedef std::map< std::string, LobbySessionPtr > LobbySessionMap; class ServerLobby @@ -30,7 +29,7 @@ namespace Core uint16_t m_port; std::string m_ip; - boost::shared_ptr m_pConfig; + boost::shared_ptr< ConfigMgr > m_pConfig; public: ServerLobby( const std::string& configPath ); @@ -45,7 +44,7 @@ namespace Core m_sessionMap[std::string( sessionId )] = pSession; } - boost::shared_ptr getConfig() const; + boost::shared_ptr< ConfigMgr > getConfig() const; LobbySessionPtr getSession( char* sessionId ); uint32_t m_numConnections; diff --git a/src/servers/sapphire_lobby/mainLobbyServer.cpp b/src/servers/sapphire_lobby/mainLobbyServer.cpp index e247f3b5..00747ecc 100644 --- a/src/servers/sapphire_lobby/mainLobbyServer.cpp +++ b/src/servers/sapphire_lobby/mainLobbyServer.cpp @@ -1,6 +1,6 @@ #include "ServerLobby.h" -Core::ServerLobby g_serverLobby( "config/settings_lobby.xml" ); +Core::ServerLobby g_serverLobby( "lobby.ini" ); int main( int32_t argc, char* argv[] ) { diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp index dbc28283..1b1ed8a6 100644 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ b/src/servers/sapphire_zone/Actor/Player.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/src/servers/sapphire_zone/Actor/PlayerEvent.cpp b/src/servers/sapphire_zone/Actor/PlayerEvent.cpp index ec05b996..ab79db49 100644 --- a/src/servers/sapphire_zone/Actor/PlayerEvent.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerEvent.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include "Network/GameConnection.h" #include "Network/PacketWrappers/ActorControlPacket142.h" @@ -307,10 +307,14 @@ void Core::Entity::Player::eventItemActionStart( uint32_t eventId, void Core::Entity::Player::onLogin() { - auto pConfig = g_fw.get< XMLConfig >(); - for( auto& child : pConfig->getChild( "Settings.Parameters.MotDArray" ) ) + auto pConfig = g_fw.get< ConfigMgr >(); + auto motd = pConfig->getValue< std::string >( "General.MotD", "" ); + + std::istringstream ss( motd ); + std::string msg; + while( std::getline( ss, msg, ';' ) ) { - sendNotice( child.second.data() ); + sendNotice( msg ); } } diff --git a/src/servers/sapphire_zone/Actor/PlayerSql.cpp b/src/servers/sapphire_zone/Actor/PlayerSql.cpp index 7ced3f9a..929396f1 100644 --- a/src/servers/sapphire_zone/Actor/PlayerSql.cpp +++ b/src/servers/sapphire_zone/Actor/PlayerSql.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include diff --git a/src/servers/sapphire_zone/Script/ScriptLoader.cpp b/src/servers/sapphire_zone/Script/ScriptLoader.cpp index 05530db9..fec4bfe6 100644 --- a/src/servers/sapphire_zone/Script/ScriptLoader.cpp +++ b/src/servers/sapphire_zone/Script/ScriptLoader.cpp @@ -1,7 +1,7 @@ #include "ScriptLoader.h" #include -#include +#include #include "ServerZone.h" @@ -53,7 +53,7 @@ bool Core::Scripting::ScriptLoader::unloadModule( ModuleHandle handle ) Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const std::string& path ) { auto pLog = g_fw.get< Logger >(); - auto pConfig = g_fw.get< XMLConfig >(); + auto pConfig = g_fw.get< ConfigMgr >(); fs::path f( path ); if( isModuleLoaded( f.stem().string() ) ) @@ -63,7 +63,7 @@ Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const st } // copy to temp dir - fs::path cacheDir( f.parent_path() /= pConfig->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) ); + fs::path cacheDir( f.parent_path() /= pConfig->getValue< std::string >( "Scripts.CachePath", "./cache/" ) ); fs::create_directories( cacheDir ); fs::path dest( cacheDir /= f.filename().string() ); diff --git a/src/servers/sapphire_zone/Script/ScriptMgr.cpp b/src/servers/sapphire_zone/Script/ScriptMgr.cpp index 00437d22..8e2efdbe 100644 --- a/src/servers/sapphire_zone/Script/ScriptMgr.cpp +++ b/src/servers/sapphire_zone/Script/ScriptMgr.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include "watchdog/Watchdog.h" @@ -51,10 +51,10 @@ void Core::Scripting::ScriptMgr::update() bool Core::Scripting::ScriptMgr::init() { std::set< std::string > files; - auto pConfig = g_fw.get< XMLConfig >(); + auto pConfig = g_fw.get< ConfigMgr >(); auto pLog = g_fw.get< Logger >(); - auto status = loadDir( pConfig->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ), + auto status = loadDir( pConfig->getValue< std::string >( "Scripts.Path", "./compiledscripts/" ), files, m_nativeScriptMgr->getModuleExtension() ); if( !status ) @@ -85,12 +85,12 @@ bool Core::Scripting::ScriptMgr::init() void Core::Scripting::ScriptMgr::watchDirectories() { - auto pConfig = g_fw.get< XMLConfig >(); - auto shouldWatch = pConfig->getValue< bool >( "Settings.General.Scripts.HotSwap.Enabled", true ); + auto pConfig = g_fw.get< ConfigMgr >(); + auto shouldWatch = pConfig->getValue< bool >( "Scripts.HotSwap", true ); if( !shouldWatch ) return; - Watchdog::watchMany( pConfig->getValue< std::string >( "Settings.General.Scripts.Path", "./compiledscripts/" ) + "*" + m_nativeScriptMgr->getModuleExtension(), + Watchdog::watchMany( pConfig->getValue< std::string >( "Scripts.Path", "./compiledscripts/" ) + "*" + m_nativeScriptMgr->getModuleExtension(), [ this ]( const std::vector< ci::fs::path >& paths ) { if( !m_firstScriptChangeNotificiation ) diff --git a/src/servers/sapphire_zone/ServerZone.cpp b/src/servers/sapphire_zone/ServerZone.cpp index d1880965..87b23a4f 100644 --- a/src/servers/sapphire_zone/ServerZone.cpp +++ b/src/servers/sapphire_zone/ServerZone.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include @@ -37,8 +37,8 @@ extern Core::Framework g_fw; -Core::ServerZone::ServerZone( const std::string& configPath ) : - m_configPath( configPath ), +Core::ServerZone::ServerZone( const std::string& configName ) : + m_configName( configName ), m_bRunning( true ), m_lastDBPingTime( 0 ) { @@ -56,15 +56,15 @@ size_t Core::ServerZone::getSessionCount() const bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) { auto pLog = g_fw.get< Core::Logger >(); - auto pConfig = g_fw.get< Core::XMLConfig >(); + auto pConfig = g_fw.get< Core::ConfigMgr >(); auto pExd = g_fw.get< Data::ExdDataGenerated >(); auto pDb = g_fw.get< Db::DbWorkerPool< Db::CharaDbConnection > >(); - pLog->info( "Loading config " + m_configPath ); + pLog->info( "Loading config " + m_configName ); - if( !pConfig->loadConfig( m_configPath ) ) + if( !pConfig->loadConfig( m_configName ) ) { - pLog->fatal( "Error loading config " + m_configPath ); + pLog->fatal( "Error loading config " + m_configName ); return false; } @@ -85,39 +85,35 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) if( arg == "ip" ) { // todo: ip addr in config - pConfig->setValue< std::string >( "Settings.General.ListenIP", val ); + pConfig->setValue< std::string >( "GlobalNetwork.ZoneIP", val ); } else if( arg == "p" || arg == "port" ) { - pConfig->setValue< std::string >( "Settings.General.ListenPort", val ); + pConfig->setValue< std::string >( "GlobalNetwork.ZonePort", val ); } else if( arg == "exdpath" || arg == "datapath" ) { - pConfig->setValue< std::string >( "Settings.General.DataPath", val ); - } - else if( arg == "s" || arg == "scriptpath" ) - { - pConfig->setValue< std::string >( "Settings.General.ScriptPath", val ); + pConfig->setValue< std::string >( "GlobalParameters.DataPath", val ); } else if( arg == "h" || arg == "dbhost" ) { - pConfig->setValue< std::string >( "Settings.General.Mysql.Host", val ); + pConfig->setValue< std::string >( "Database.Host", val ); } else if( arg == "dbport" ) { - pConfig->setValue< std::string >( "Settings.General.Mysql.Port", val ); + pConfig->setValue< std::string >( "Database.Port", val ); } else if( arg == "u" || arg == "user" || arg == "dbuser" ) { - pConfig->setValue< std::string >( "Settings.General.Mysql.Username", val ); + pConfig->setValue< std::string >( "Database.Username", val ); } else if( arg == "pass" || arg == "dbpass" ) { - pConfig->setValue< std::string >( "Settings.General.Mysql.Pass", val ); + pConfig->setValue< std::string >( "Database.Password", val ); } else if( arg == "d" || arg == "db" || arg == "database" ) { - pConfig->setValue< std::string >( "Settings.General.Mysql.Database", val ); + pConfig->setValue< std::string >( "Database.Database", val ); } } catch( ... ) @@ -128,7 +124,7 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) } pLog->info( "Setting up generated EXD data" ); - if( !pExd->init( pConfig->getValue< std::string >( "Settings.General.DataPath", "" ) ) ) + if( !pExd->init( pConfig->getValue< std::string >( "GlobalParameters.DataPath", "" ) ) ) { pLog->fatal( "Error setting up generated EXD data " ); return false; @@ -137,27 +133,27 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] ) Core::Db::DbLoader loader; Core::Db::ConnectionInfo info; - info.password = pConfig->getValue< std::string >( "Settings.General.Mysql.Pass", "" ); - info.host = pConfig->getValue< std::string >( "Settings.General.Mysql.Host", "127.0.0.1" ); - info.database = pConfig->getValue< std::string >( "Settings.General.Mysql.Database", "sapphire" ); - info.port = pConfig->getValue< uint16_t >( "Settings.General.Mysql.Port", 3306 ); - info.user = pConfig->getValue< std::string >( "Settings.General.Mysql.Username", "root" ); - info.syncThreads = pConfig->getValue< uint8_t >( "Settings.General.Mysql.SyncThreads", 2 ); - info.asyncThreads = pConfig->getValue< uint8_t >( "Settings.General.Mysql.AsyncThreads", 2 ); + 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 ); loader.addDb( *pDb, info ); if( !loader.initDbs() ) return false; - m_port = pConfig->getValue< uint16_t >( "Settings.General.ListenPort", 54992 ); - m_ip = pConfig->getValue< std::string >( "Settings.General.ListenIp", "0.0.0.0" ); + m_port = pConfig->getValue< uint16_t >( "GlobalNetwork.ZonePort", 54992 ); + m_ip = pConfig->getValue< std::string >( "GlobalNetwork.ZoneIP", "0.0.0.0" ); return true; } void Core::ServerZone::run( int32_t argc, char* argv[] ) { - auto pLog = g_fw.get< Core::Logger>(); + auto pLog = g_fw.get< Core::Logger >(); auto pScript = g_fw.get< Scripting::ScriptMgr >(); auto pLsMgr = g_fw.get< LinkshellMgr >(); auto pTeriMgr = g_fw.get< TerritoryMgr >(); diff --git a/src/servers/sapphire_zone/ServerZone.h b/src/servers/sapphire_zone/ServerZone.h index 09230846..c28a94b7 100644 --- a/src/servers/sapphire_zone/ServerZone.h +++ b/src/servers/sapphire_zone/ServerZone.h @@ -14,7 +14,7 @@ namespace Core { class ServerZone { public: - ServerZone( const std::string& configPath ); + ServerZone( const std::string& configName ); ~ServerZone(); void run( int32_t argc, char* argv[] ); @@ -44,7 +44,7 @@ namespace Core { bool m_bRunning; - std::string m_configPath; + std::string m_configName; std::mutex m_sessionMutex; diff --git a/src/servers/sapphire_zone/mainGameServer.cpp b/src/servers/sapphire_zone/mainGameServer.cpp index b083b3b4..5b9572f3 100644 --- a/src/servers/sapphire_zone/mainGameServer.cpp +++ b/src/servers/sapphire_zone/mainGameServer.cpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include "Script/ScriptMgr.h" #include @@ -13,34 +12,36 @@ #include "Zone/TerritoryMgr.h" #include "DebugCommand/DebugCommandHandler.h" +#include + Core::Framework g_fw; using namespace Core; bool setupFramework() { - auto pServer = boost::make_shared< ServerZone >( "config/settings_zone.xml" ); + auto pServer = boost::make_shared< ServerZone >( "zone.ini" ); auto pLogger = boost::make_shared< Logger >(); - auto pConfig = boost::make_shared< XMLConfig >(); auto pExdData = boost::make_shared< Data::ExdDataGenerated >(); auto pScript = boost::make_shared< Scripting::ScriptMgr >(); auto pDb = boost::make_shared< Db::DbWorkerPool< Db::CharaDbConnection > >(); auto pLsMgr = boost::make_shared< LinkshellMgr >(); auto pTeriMgr = boost::make_shared< TerritoryMgr >(); auto pDebugCom = boost::make_shared< DebugCommandHandler >(); + auto pConfig = boost::make_shared< ConfigMgr >(); pLogger->setLogPath( "log/SapphireZone_" ); pLogger->init(); g_fw.set< ServerZone >( pServer ); g_fw.set< Logger >( pLogger ); - g_fw.set< XMLConfig >( pConfig ); g_fw.set< Data::ExdDataGenerated >( pExdData ); g_fw.set< Scripting::ScriptMgr >( pScript ); g_fw.set< Db::DbWorkerPool< Db::CharaDbConnection > >( pDb ); g_fw.set< LinkshellMgr >( pLsMgr ); g_fw.set< TerritoryMgr >( pTeriMgr ); g_fw.set< DebugCommandHandler >( pDebugCom ); + g_fw.set< ConfigMgr >( pConfig ); // actuall catch errors here... return true; @@ -48,7 +49,6 @@ bool setupFramework() int main( int32_t argc, char* argv[] ) { - if( !setupFramework() ) return 0; // too fucking bad...