1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-26 22:37:45 +00:00

Merge pull request #322 from goaaats/ini_network_fixes

zone, lobby, api: Streamline network configuration for new INI config
This commit is contained in:
Mordred 2018-06-24 18:32:59 +02:00 committed by GitHub
commit 2de00dc70a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 22 deletions

5
.gitignore vendored
View file

@ -117,4 +117,7 @@ src/servers/Scripts/*/ScriptLoader.cpp
# cotire generated files/folders # cotire generated files/folders
cotire/ cotire/
*_cotire.cmake *_cotire.cmake
*objects.txt
*exports.def

View file

@ -2,7 +2,7 @@
Host = 127.0.0.1 Host = 127.0.0.1
Port = 3306 Port = 3306
Database = sapphire Database = sapphire
Username = sapphire Username = root
Password = Password =
SyncThreads = 2 SyncThreads = 2
AsyncThreads = 2 AsyncThreads = 2
@ -12,6 +12,7 @@ ServerSecret = default
DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack DataPath = C:\\SquareEnix\\FINAL FANTASY XIV - A Realm Reborn\\game\\sqpack
[GlobalNetwork] [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 ZoneHost = 127.0.0.1
ZonePort = 54992 ZonePort = 54992

View file

@ -1,4 +1,8 @@
[Lobby] [Lobby]
WorldID = 67 WorldID = 67
AllowNoSessionConnect = false AllowNoSessionConnect = false
WorldName = Sapphire WorldName = Sapphire
[LobbyNetwork]
ListenIp = 0.0.0.0
ListenPort = 54994

View file

@ -1,2 +1,6 @@
[CharacterCreation] [CharacterCreation]
DefaultGMRank = 255 DefaultGMRank = 255
[RestNetwork]
ListenIp = 0.0.0.0
ListenPort = 80

View file

@ -9,6 +9,10 @@ HotSwap = true
[Network] [Network]
DisconnectTimeout = 20 DisconnectTimeout = 20
[ZoneNetwork]
ListenIp = 0.0.0.0
ListenPort = 54992
[General] [General]
; Sent on login - each line must be shorter than 307 characters, split lines with ';' ; 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/zone.ini MotD = Welcome to Sapphire!;This is a very good server;You can change these messages by editing General.MotD in config/zone.ini

View file

@ -95,12 +95,11 @@ bool loadSettings( int32_t argc, char* argv[] )
if( arg == "ip" ) if( arg == "ip" )
{ {
// todo: ip addr in config m_pConfig->setValue< std::string >( "RestNetwork.ListenIp", val );
m_pConfig->setValue< std::string >( "GlobalNetwork.RestHost", val );
} }
else if( arg == "p" || arg == "port" ) else if( arg == "p" || arg == "port" )
{ {
m_pConfig->setValue< std::string >( "GlobalNetwork.RestPort", val ); m_pConfig->setValue< std::string >( "RestNetwork.ListenPort", val );
} }
else if( arg == "exdpath" || arg == "datapath" ) else if( arg == "exdpath" || arg == "datapath" )
{ {
@ -164,7 +163,8 @@ bool loadSettings( int32_t argc, char* argv[] )
if( !loader.initDbs() ) if( !loader.initDbs() )
return false; return false;
server.config.port = static_cast< uint16_t >( std::stoul( m_pConfig->getValue< std::string >( "GlobalNetwork.RestPort", "80" ) ) ); 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" );
g_log.info( "Database: Connected to " + info.host + ":" + std::to_string( info.port ) ); g_log.info( "Database: Connected to " + info.host + ":" + std::to_string( info.port ) );
@ -756,9 +756,6 @@ int main( int argc, char* argv[] )
if( !loadSettings( argc, argv ) ) if( !loadSettings( argc, argv ) )
throw std::exception(); throw std::exception();
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["^/ZoneName/([0-9]+)$"]["GET"] = &getZoneName;
server.resource["^/sapphire-api/lobby/createAccount"]["POST"] = &createAccount; server.resource["^/sapphire-api/lobby/createAccount"]["POST"] = &createAccount;
server.resource["^/sapphire-api/lobby/login"]["POST"] = &login; server.resource["^/sapphire-api/lobby/login"]["POST"] = &login;
@ -781,6 +778,8 @@ int main( int argc, char* argv[] )
server.start(); server.start();
} ); } );
g_log.info( "API server running on " + m_pConfig->getValue< std::string >( "RestNetwork.ListenIp", "0.0.0.0" ) + ":" + m_pConfig->getValue< std::string >( "RestNetwork.ListenPort", "80" ) );
//Wait for server to start so that the client can connect //Wait for server to start so that the client can connect
this_thread::sleep_for( chrono::seconds( 1 ) ); this_thread::sleep_for( chrono::seconds( 1 ) );

View file

@ -75,7 +75,7 @@ namespace Core {
Network::HivePtr hive( new Network::Hive() ); Network::HivePtr hive( new Network::Hive() );
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive ); Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive );
g_log.info( "Lobbyserver ready for connections." ); g_log.info( "Lobby server running on " + m_pConfig->getValue< std::string >( "LobbyNetwork.ListenIp", "0.0.0.0" ) + ":" + m_pConfig->getValue< std::string >( "LobbyNetwork.ListenPort", "80" ) );
boost::thread_group worker_threads; boost::thread_group worker_threads;
worker_threads.create_thread( boost::bind( &Network::Hive::Run, hive.get() ) ); worker_threads.create_thread( boost::bind( &Network::Hive::Run, hive.get() ) );
@ -109,11 +109,11 @@ namespace Core {
if( arg == "ip" ) if( arg == "ip" )
{ {
// todo: ip addr in config // todo: ip addr in config
m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyHost", val ); m_pConfig->setValue< std::string >( "LobbyNetwork.ListenIp", val );
} }
else if( arg == "p" || arg == "port" ) else if( arg == "p" || arg == "port" )
{ {
m_pConfig->setValue< std::string >( "GlobalNetwork.LobbyPort", val ); m_pConfig->setValue< std::string >( "LobbyNetwork.LobbyPort", val );
} }
else if( arg == "worldip" || arg == "worldip" ) else if( arg == "worldip" || arg == "worldip" )
{ {
@ -131,8 +131,8 @@ namespace Core {
} }
} }
m_port = m_pConfig->getValue< uint16_t >( "GlobalNetwork.LobbyPort", 54994 ); m_port = m_pConfig->getValue< uint16_t >( "LobbyNetwork.ListenPort", 54994 );
m_ip = m_pConfig->getValue< std::string >( "GlobalNetwork.LobbyHost", "0.0.0.0" ); m_ip = m_pConfig->getValue< std::string >( "LobbyNetwork.ListenIp", "0.0.0.0" );
g_restConnector.restHost = m_pConfig->getValue< std::string >( "GlobalNetwork.RestHost" ) + ":" + m_pConfig->getValue< std::string >( "GlobalNetwork.RestPort" ); 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.serverSecret = m_pConfig->getValue< std::string >( "GlobalParameters.ServerSecret" );

View file

@ -85,11 +85,11 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
if( arg == "ip" ) if( arg == "ip" )
{ {
// todo: ip addr in config // todo: ip addr in config
pConfig->setValue< std::string >( "GlobalNetwork.ZoneIP", val ); pConfig->setValue< std::string >( "ZoneNetwork.ListenIp", val );
} }
else if( arg == "p" || arg == "port" ) else if( arg == "p" || arg == "port" )
{ {
pConfig->setValue< std::string >( "GlobalNetwork.ZonePort", val ); pConfig->setValue< std::string >( "ZoneNetwork.ListenPort", val );
} }
else if( arg == "exdpath" || arg == "datapath" ) else if( arg == "exdpath" || arg == "datapath" )
{ {
@ -145,8 +145,8 @@ bool Core::ServerZone::loadSettings( int32_t argc, char* argv[] )
if( !loader.initDbs() ) if( !loader.initDbs() )
return false; return false;
m_port = pConfig->getValue< uint16_t >( "GlobalNetwork.ZonePort", 54992 ); m_port = pConfig->getValue< uint16_t >( "ZoneNetwork.ListenPort", 54992 );
m_ip = pConfig->getValue< std::string >( "GlobalNetwork.ZoneIP", "0.0.0.0" ); m_ip = pConfig->getValue< std::string >( "ZoneNetwork.ListenIp", "0.0.0.0" );
return true; return true;
} }
@ -184,8 +184,7 @@ void Core::ServerZone::run( int32_t argc, char* argv[] )
std::vector< std::thread > thread_list; std::vector< std::thread > thread_list;
thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) ); thread_list.emplace_back( std::thread( std::bind( &Network::Hive::Run, hive.get() ) ) );
pLog->info( "Server listening on port: " + std::to_string( m_port ) ); pLog->info( "Zone server running on " + m_ip + ":" + std::to_string( m_port ) );
pLog->info( "Ready for connections..." );
mainLoop(); mainLoop();