2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <map>
|
|
|
|
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Network/Hive.h>
|
|
|
|
#include <Network/Acceptor.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
2018-03-06 22:22:19 +01:00
|
|
|
#include <Version.h>
|
|
|
|
#include <Logging/Logger.h>
|
|
|
|
#include <Config/XMLConfig.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
//#include "LobbySession.h"
|
|
|
|
|
|
|
|
#include "ServerLobby.h"
|
|
|
|
|
|
|
|
#include "GameConnection.h"
|
|
|
|
#include "RestConnector.h"
|
2018-03-06 23:20:07 +01:00
|
|
|
#include "Forwards.h"
|
|
|
|
#include <Forwards.h>
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
#include <thread>
|
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
|
|
|
#include <boost/property_tree/ptree.hpp>
|
|
|
|
#include <boost/property_tree/json_parser.hpp>
|
2017-08-11 23:13:00 +01:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2017-08-08 13:53:47 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
Core::Logger g_log;
|
|
|
|
Core::Network::RestConnector g_restConnector;
|
|
|
|
|
|
|
|
namespace Core {
|
|
|
|
|
|
|
|
|
|
|
|
ServerLobby::ServerLobby( const std::string& configPath ) :
|
|
|
|
m_configPath( configPath ),
|
|
|
|
m_numConnections( 0 )
|
|
|
|
{
|
|
|
|
m_pConfig = boost::shared_ptr<XMLConfig>( new XMLConfig );
|
|
|
|
}
|
|
|
|
|
|
|
|
ServerLobby::~ServerLobby( void )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
LobbySessionPtr ServerLobby::getSession( char* sessionId )
|
|
|
|
{
|
|
|
|
return g_restConnector.getSession( sessionId );
|
|
|
|
}
|
|
|
|
|
2017-09-10 02:24:29 +02:00
|
|
|
XMLConfigPtr ServerLobby::getConfig() const
|
|
|
|
{
|
|
|
|
return m_pConfig;
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:56:30 +01:00
|
|
|
void ServerLobby::run( int32_t argc, char* argv[] )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
2018-02-09 20:11:30 +11:00
|
|
|
g_log.setLogPath( "log/SapphireLobby" );
|
2017-08-08 13:53:47 +02:00
|
|
|
g_log.init();
|
|
|
|
|
|
|
|
g_log.info( "===========================================================" );
|
|
|
|
g_log.info( "Sapphire Server Project " );
|
2017-10-20 02:23:45 +11:00
|
|
|
g_log.info( "Version: " + Version::VERSION );
|
|
|
|
g_log.info( "Git Hash: " + Version::GIT_HASH );
|
2017-08-08 13:53:47 +02:00
|
|
|
g_log.info( "Compiled: " __DATE__ " " __TIME__ );
|
|
|
|
g_log.info( "===========================================================" );
|
|
|
|
|
|
|
|
if( !loadSettings( argc, argv ) )
|
|
|
|
{
|
|
|
|
g_log.fatal( "Error loading settings! " );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Network::HivePtr hive( new Network::Hive() );
|
|
|
|
Network::addServerToHive< Network::GameConnection >( m_ip, m_port, hive );
|
|
|
|
|
|
|
|
g_log.info( "Lobbyserver ready for connections." );
|
|
|
|
|
|
|
|
boost::thread_group worker_threads;
|
|
|
|
worker_threads.create_thread( boost::bind( &Network::Hive::Run, hive.get() ) );
|
|
|
|
worker_threads.join_all();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-11 22:56:30 +01:00
|
|
|
bool ServerLobby::loadSettings( int32_t argc, char* argv[] )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
g_log.info( "Loading config " + m_configPath );
|
|
|
|
|
|
|
|
if( !m_pConfig->loadConfig( m_configPath ) )
|
|
|
|
{
|
|
|
|
g_log.fatal( "Error loading config " + m_configPath );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
std::vector<std::string> args( argv + 1, argv + argc );
|
2017-10-19 07:12:09 -07:00
|
|
|
for( size_t i = 0; i + 1 < args.size(); i += 2 )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
std::string arg( "" );
|
|
|
|
std::string val( "" );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2017-08-11 23:13:00 +01:00
|
|
|
arg = boost::to_lower_copy( std::string( args[i] ) );
|
2017-08-08 13:53:47 +02:00
|
|
|
val = std::string( args[i + 1] );
|
|
|
|
|
|
|
|
// trim '-' from start of arg
|
|
|
|
arg = arg.erase( 0, arg.find_first_not_of( '-' ) );
|
|
|
|
|
|
|
|
if( arg == "ip" )
|
|
|
|
{
|
|
|
|
// todo: ip addr in config
|
2017-08-11 23:13:00 +01:00
|
|
|
m_pConfig->setValue< std::string >( "Settings.General.ListenIp", val );
|
2017-08-08 13:53:47 +02:00
|
|
|
}
|
|
|
|
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 );
|
|
|
|
}
|
2017-08-11 23:13:00 +01:00
|
|
|
else if( arg == "worldip" || arg == "worldip" )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
m_pConfig->setValue < std::string >( "Settings.General.WorldIp", val );
|
|
|
|
}
|
2017-08-11 23:13:00 +01:00
|
|
|
else if( arg == "worldport" )
|
2017-08-08 13:53:47 +02:00
|
|
|
{
|
|
|
|
m_pConfig->setValue< std::string >( "Settings.General.WorldPort", val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
g_log.error( "Error parsing argument: " + arg + " " + "value: " + val + "\n" );
|
|
|
|
g_log.error( "Usage: <arg> <val> \n" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 23:13:00 +01:00
|
|
|
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" );
|
2017-08-08 13:53:47 +02:00
|
|
|
|
|
|
|
g_restConnector.restHost = m_pConfig->getValue< std::string >( "Settings.General.RestHost" );
|
|
|
|
g_restConnector.serverSecret = m_pConfig->getValue< std::string >( "Settings.General.ServerSecret" );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|