mirror of
https://github.com/HikikoMarmy/Champions-Reborn-Server.git
synced 2026-04-05 08:59:54 -03:00
Remove Gateway Server as it's redundant.
This commit is contained in:
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "../../Network/GenericNetRequest.hpp"
|
||||
#include "GetServerAddressEvent.h"
|
||||
|
||||
const std::map< int16_t, std::function< std::unique_ptr< GenericRequest >() > > LOBBY_EVENT_LOOKUP =
|
||||
{
|
||||
{ 0x43, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetServerAddress >();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
#include "../../Network/GenericNetRequest.hpp"
|
||||
#include "GetServerAddressEvent.h"
|
||||
|
||||
const std::map< int16_t, std::function< std::unique_ptr< GenericRequest >() > > LOBBY_EVENT_LOOKUP =
|
||||
{
|
||||
{ 0x43, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetServerAddress >();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "GetServerAddressEvent.h"
|
||||
|
||||
void RequestGetServerAddress::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetServerAddress::ProcessRequest( sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream);
|
||||
|
||||
return std::make_shared< ResultGetServerAddress >( this, Config::service_ip, Config::lobby_port );
|
||||
}
|
||||
|
||||
ResultGetServerAddress::ResultGetServerAddress( GenericRequest *request, std::string ip, int32_t port ) : GenericResponse( *request )
|
||||
{
|
||||
m_ip = ip;
|
||||
m_port = port;
|
||||
}
|
||||
|
||||
ByteStream& ResultGetServerAddress::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_sz_utf8( m_ip );
|
||||
m_stream.write( m_port );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestGetServerAddress : public GenericRequest {
|
||||
public:
|
||||
static std::unique_ptr< RequestGetServerAddress > Create()
|
||||
{
|
||||
return std::make_unique< RequestGetServerAddress >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultGetServerAddress : public GenericResponse {
|
||||
public:
|
||||
std::string m_ip;
|
||||
int32_t m_port;
|
||||
|
||||
ResultGetServerAddress( GenericRequest *request, std::string ip, int32_t port );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,272 +0,0 @@
|
||||
// ╔╗╔╔═╗╦═╗╦═╗╔═╗╔╦╗╦ ╦
|
||||
// ║║║║ ║╠╦╝╠╦╝╠═╣ ║ ╠═╣
|
||||
// ╝╚╝╚═╝╩╚═╩╚═╩ ╩ ╩ ╩ ╩
|
||||
// ╔═╗╔═╗╔╦╗╔═╗╦ ╦╔═╗╦ ╦ ╔═╗╔═╗╦═╗╦ ╦╔═╗╦═╗
|
||||
// ║ ╦╠═╣ ║ ║╣ ║║║╠═╣╚╦╝ ╚═╗║╣ ╠╦╝╚╗╔╝║╣ ╠╦╝
|
||||
// ╚═╝╩ ╩ ╩ ╚═╝╚╩╝╩ ╩ ╩ ╚═╝╚═╝╩╚═ ╚╝ ╚═╝╩╚═
|
||||
|
||||
#include <map>
|
||||
#include "../global_define.h"
|
||||
|
||||
#include "GatewayServer.h"
|
||||
#include "Event/GatewayEvents.h"
|
||||
|
||||
typedef std::map< int16_t, std::function< std::unique_ptr< GenericRequest >() > > CommandMap;
|
||||
|
||||
const CommandMap GATEWAY_REQUEST_LOOKUP =
|
||||
{
|
||||
{ 0x43, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetServerAddress >();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GatewayServer::GatewayServer()
|
||||
{
|
||||
m_running = false;
|
||||
m_listenSocket = INVALID_SOCKET;
|
||||
|
||||
m_clientSockets.clear();
|
||||
m_recvBuffer.resize( 1024 );
|
||||
}
|
||||
|
||||
GatewayServer::~GatewayServer()
|
||||
{
|
||||
Log::Info( "Gateway Server stopped." );
|
||||
}
|
||||
|
||||
void GatewayServer::Start( std::string ip, int32_t port )
|
||||
{
|
||||
m_listenSocket = ::WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED );
|
||||
if( m_listenSocket == INVALID_SOCKET )
|
||||
{
|
||||
Log::Error( "WSASocket() failed" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Bind the socket
|
||||
sockaddr_in service;
|
||||
service.sin_family = AF_INET;
|
||||
service.sin_port = htons( port );
|
||||
|
||||
if( ip == "0.0.0.0" )
|
||||
{
|
||||
service.sin_addr.s_addr = ADDR_ANY;
|
||||
}
|
||||
else
|
||||
{
|
||||
service.sin_addr.s_addr = inet_addr( ip.c_str() );
|
||||
}
|
||||
|
||||
if( bind( m_listenSocket, ( SOCKADDR * )&service, sizeof( service ) ) == SOCKET_ERROR )
|
||||
{
|
||||
Log::Error( "bind() failed" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Listen on the socket
|
||||
if( listen( m_listenSocket, SOMAXCONN ) == SOCKET_ERROR )
|
||||
{
|
||||
Log::Error( "listen() failed" );
|
||||
return;
|
||||
}
|
||||
|
||||
// Start the server
|
||||
m_running = true;
|
||||
m_thread = std::thread( &GatewayServer::Run, this );
|
||||
|
||||
Log::Info( "Gateway Server started on %s:%d", ip.c_str(), port );
|
||||
}
|
||||
|
||||
void GatewayServer::Stop()
|
||||
{
|
||||
m_running = false;
|
||||
if( m_thread.joinable() )
|
||||
{
|
||||
m_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
void GatewayServer::Run()
|
||||
{
|
||||
FD_SET readSet;
|
||||
FD_SET writeSet;
|
||||
|
||||
timeval timeout = { 0, 1000 };
|
||||
|
||||
while( m_running )
|
||||
{
|
||||
FD_ZERO( &readSet );
|
||||
FD_ZERO( &writeSet );
|
||||
|
||||
FD_SET( m_listenSocket, &readSet );
|
||||
|
||||
// Process clients
|
||||
for( auto &client : m_clientSockets )
|
||||
{
|
||||
FD_SET( client->fd, &readSet );
|
||||
FD_SET( client->fd, &writeSet );
|
||||
}
|
||||
|
||||
auto result = select( 0, &readSet, &writeSet, NULL, &timeout );
|
||||
|
||||
if( result == SOCKET_ERROR )
|
||||
{
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 1 ) );
|
||||
break;
|
||||
}
|
||||
|
||||
if( FD_ISSET( m_listenSocket, &readSet ) )
|
||||
{
|
||||
AcceptNewClient();
|
||||
}
|
||||
|
||||
for( auto &client : m_clientSockets )
|
||||
{
|
||||
if( FD_ISSET( client->fd, &readSet ) )
|
||||
{
|
||||
ReadSocket( client );
|
||||
}
|
||||
|
||||
if( FD_ISSET( client->fd, &writeSet ) )
|
||||
{
|
||||
WriteSocket( client );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GatewayServer::AcceptNewClient()
|
||||
{
|
||||
sockaddr_in clientInfo;
|
||||
int32_t addrSize = sizeof( clientInfo );
|
||||
|
||||
SOCKET clientSocket = accept( m_listenSocket, ( SOCKADDR * )&clientInfo, &addrSize );
|
||||
if( clientSocket == INVALID_SOCKET )
|
||||
{
|
||||
Log::Error( "accept() failed" );
|
||||
return;
|
||||
}
|
||||
|
||||
auto new_socket = std::make_shared< RealmSocket >();
|
||||
new_socket->fd = clientSocket;
|
||||
new_socket->remote_addr = clientInfo;
|
||||
new_socket->remote_ip = inet_ntoa( clientInfo.sin_addr );
|
||||
new_socket->remote_port = ntohs( clientInfo.sin_port );
|
||||
|
||||
m_clientSockets.push_back( new_socket );
|
||||
|
||||
//Log::Info( "[GATEWAY] New client connected : (%s)", new_client->remote_ip.c_str() );
|
||||
}
|
||||
|
||||
void GatewayServer::ReadSocket( sptr_socket socket )
|
||||
{
|
||||
if( socket->flag.disconnected )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
auto bytesReceived = recv( socket->fd, ( char * )m_recvBuffer.data(), ( int )m_recvBuffer.size(), 0 );
|
||||
|
||||
if( bytesReceived == SOCKET_ERROR )
|
||||
{
|
||||
auto error = WSAGetLastError();
|
||||
Log::Info( "Socket Error [%d].", error );
|
||||
socket->flag.disconnected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if( bytesReceived == 0 )
|
||||
{
|
||||
Log::Info( "Socket Disconnected." );
|
||||
socket->flag.disconnected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Append the received data to the sockets processing buffer.
|
||||
// There's definitely a more elegant way of handling data here,
|
||||
// but this is just easier for now.
|
||||
socket->m_pendingReadBuffer.insert( socket->m_pendingReadBuffer.end(), m_recvBuffer.begin(), m_recvBuffer.begin() + bytesReceived );
|
||||
|
||||
// Handle valid packets in the buffer.
|
||||
while( socket->m_pendingReadBuffer.size() > 0 )
|
||||
{
|
||||
auto packetSize = htonl( *( int32_t * )&socket->m_pendingReadBuffer[ 0 ] );
|
||||
|
||||
if( packetSize > socket->m_pendingReadBuffer.size() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
auto stream = std::make_shared< ByteStream >( socket->m_pendingReadBuffer.data() + 4, packetSize - 4 );
|
||||
|
||||
// Erase the packet from the buffer
|
||||
socket->m_pendingReadBuffer.erase( socket->m_pendingReadBuffer.begin(), socket->m_pendingReadBuffer.begin() + packetSize );
|
||||
|
||||
// Process the packet
|
||||
HandleRequest( socket, stream );
|
||||
}
|
||||
}
|
||||
|
||||
void GatewayServer::WriteSocket( sptr_socket socket )
|
||||
{
|
||||
if( socket->flag.disconnected )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if( socket->m_pendingWriteBuffer.empty() )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
size_t totalBytesSent = 0;
|
||||
|
||||
while( true )
|
||||
{
|
||||
auto chunkSize = std::min< size_t >( socket->m_pendingWriteBuffer.size(), 1024 );
|
||||
auto bytesSent = send( socket->fd, ( char * )socket->m_pendingWriteBuffer.data(), ( int )chunkSize, 0 );
|
||||
|
||||
if( bytesSent == SOCKET_ERROR )
|
||||
{
|
||||
socket->flag.disconnected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
totalBytesSent += bytesSent;
|
||||
|
||||
if( bytesSent < chunkSize )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if( totalBytesSent == socket->m_pendingWriteBuffer.size() )
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
socket->m_pendingWriteBuffer.erase( socket->m_pendingWriteBuffer.begin(), socket->m_pendingWriteBuffer.begin() + totalBytesSent );
|
||||
}
|
||||
|
||||
void GatewayServer::HandleRequest( sptr_socket socket, sptr_byte_stream stream )
|
||||
{
|
||||
auto packetId = stream->read< uint16_t >();
|
||||
stream->set_position( 0 );
|
||||
|
||||
auto it = GATEWAY_REQUEST_LOOKUP.find( packetId );
|
||||
if( it == GATEWAY_REQUEST_LOOKUP.end() )
|
||||
{
|
||||
//Log::Error( "[GATEWAY] Unknown packet id : 0x%04X", packetId );
|
||||
return;
|
||||
}
|
||||
|
||||
//Log::Debug( "[GATEWAY] Request processed : 0x%04X", packetId );
|
||||
|
||||
auto request = it->second();
|
||||
if( auto res = request->ProcessRequest( stream ) )
|
||||
{
|
||||
socket->send( res );
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
|
||||
class GatewayServer
|
||||
{
|
||||
static inline std::unique_ptr< GatewayServer > m_instance;
|
||||
|
||||
public:
|
||||
static GatewayServer& Get()
|
||||
{
|
||||
if( m_instance == nullptr )
|
||||
{
|
||||
m_instance.reset( new GatewayServer() );
|
||||
}
|
||||
|
||||
return *m_instance;
|
||||
}
|
||||
|
||||
GatewayServer();
|
||||
~GatewayServer();
|
||||
|
||||
void Start( std::string ip, int32_t port );
|
||||
void Stop();
|
||||
bool isRunning() const
|
||||
{
|
||||
return m_running;
|
||||
}
|
||||
|
||||
private:
|
||||
std::atomic< bool > m_running;
|
||||
std::thread m_thread;
|
||||
|
||||
SOCKET m_listenSocket;
|
||||
std::vector< sptr_socket > m_clientSockets;
|
||||
std::vector< uint8_t > m_recvBuffer;
|
||||
|
||||
void Run();
|
||||
void AcceptNewClient();
|
||||
|
||||
void ReadSocket( sptr_socket socket );
|
||||
void WriteSocket( sptr_socket socket );
|
||||
void HandleRequest( sptr_socket socket, sptr_byte_stream stream );
|
||||
};
|
||||
@@ -193,10 +193,8 @@
|
||||
<ClInclude Include="Game\RealmUserManager.h" />
|
||||
<ClInclude Include="Game\GameSession.h" />
|
||||
<ClInclude Include="Game\GameSessionManager.h" />
|
||||
<ClInclude Include="Gateway Server\Event\GatewayEvents.h" />
|
||||
<ClInclude Include="Gateway Server\Event\GetServerAddressEvent.h" />
|
||||
<ClInclude Include="Gateway Server\GatewayServer.h" />
|
||||
<ClInclude Include="global_define.h" />
|
||||
<ClInclude Include="Lobby Server\Event\RequestGetServerAddress.h" />
|
||||
<ClInclude Include="Lobby Server\LobbyEvents.h" />
|
||||
<ClInclude Include="Lobby Server\Event\NotifyClientDiscovered.h" />
|
||||
<ClInclude Include="Lobby Server\Event\NotifyClientReqConnect.h" />
|
||||
@@ -236,8 +234,6 @@
|
||||
<ClCompile Include="Game\RealmUserManager.cpp" />
|
||||
<ClCompile Include="Game\GameSession.cpp" />
|
||||
<ClCompile Include="Game\GameSessionManager.cpp" />
|
||||
<ClCompile Include="Gateway Server\Event\GetServerAddressEvent.cpp" />
|
||||
<ClCompile Include="Gateway Server\GatewayServer.cpp" />
|
||||
<ClCompile Include="global_define.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\NotifyClientDiscovered.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\NotifyClientReqConnect.cpp" />
|
||||
@@ -251,6 +247,7 @@
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetGame.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetRealmStats.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetRules.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetServerAddress.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestLogin.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestLogout.cpp" />
|
||||
<ClCompile Include="Lobby Server\Event\RequestMatchGame.cpp" />
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Gateway Server">
|
||||
<UniqueIdentifier>{9eabece2-9fe0-499d-a5b0-f001d155f4d3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Common">
|
||||
<UniqueIdentifier>{0ecae2be-b6b6-4ee2-bcb2-9252f189acca}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -24,9 +21,6 @@
|
||||
<Filter Include="Header Files\Network">
|
||||
<UniqueIdentifier>{d03ff7f7-63d1-43a7-b2cc-4b585130f545}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Gateway Server">
|
||||
<UniqueIdentifier>{b87d23fc-9dc6-4e3a-949a-6d1b3ac2efb0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Lobby Server">
|
||||
<UniqueIdentifier>{92e2e64a-8125-49a7-8eb0-5e96f8d7d7d0}</UniqueIdentifier>
|
||||
</Filter>
|
||||
@@ -57,12 +51,6 @@
|
||||
<Filter Include="Source Files\Lobby Server\Event">
|
||||
<UniqueIdentifier>{6432e486-7341-4eb8-a6c0-c21ecd2e92f8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files\Gateway Server\Event">
|
||||
<UniqueIdentifier>{01a6a552-7c0d-4ca4-b4d1-5c05d6048fda}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Source Files\Gateway Server\Event">
|
||||
<UniqueIdentifier>{f90649a3-247a-4a65-9ec2-3fca02c7af52}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="stdafx.h">
|
||||
@@ -89,9 +77,6 @@
|
||||
<ClInclude Include="logging.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Gateway Server\GatewayServer.h">
|
||||
<Filter>Header Files\Gateway Server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Network\GenericNetRequest.hpp">
|
||||
<Filter>Header Files\Network</Filter>
|
||||
</ClInclude>
|
||||
@@ -179,15 +164,12 @@
|
||||
<ClInclude Include="Lobby Server\Event\RequestGetGame.h">
|
||||
<Filter>Header Files\Lobby Server\Event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Gateway Server\Event\GatewayEvents.h">
|
||||
<Filter>Header Files\Gateway Server\Event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Gateway Server\Event\GetServerAddressEvent.h">
|
||||
<Filter>Header Files\Gateway Server\Event</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Crypto\RealmCrypt.h">
|
||||
<Filter>Header Files\Crypto</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Lobby Server\Event\RequestGetServerAddress.h">
|
||||
<Filter>Header Files\Lobby Server\Event</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
@@ -205,9 +187,6 @@
|
||||
<ClCompile Include="misc\ByteStream.cpp">
|
||||
<Filter>Source Files\Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Gateway Server\GatewayServer.cpp">
|
||||
<Filter>Source Files\Gateway Server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="logging.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
@@ -289,12 +268,12 @@
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetGame.cpp">
|
||||
<Filter>Source Files\Lobby Server\Event</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Gateway Server\Event\GetServerAddressEvent.cpp">
|
||||
<Filter>Source Files\Gateway Server\Event</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Crypto\RealmCrypt.cpp">
|
||||
<Filter>Source Files\Crypto</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Lobby Server\Event\RequestGetServerAddress.cpp">
|
||||
<Filter>Source Files\Lobby Server\Event</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Norrath Server.rc" />
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
bool Config::Load( std::string filename )
|
||||
{
|
||||
service_ip = "0.0.0.0";
|
||||
gateway_port = 40801;
|
||||
lobby_port = 40802;
|
||||
discovery_port = 40101;
|
||||
lobby_port = 40801;
|
||||
discovery_port = 10101;
|
||||
|
||||
// Read configuration from ini file
|
||||
std::ifstream file( filename );
|
||||
@@ -38,10 +37,6 @@ bool Config::Load( std::string filename )
|
||||
{
|
||||
service_ip = value;
|
||||
}
|
||||
else if( key == "gateway_port" )
|
||||
{
|
||||
gateway_port = std::stoi( value );
|
||||
}
|
||||
else if( key == "lobby_port" )
|
||||
{
|
||||
lobby_port = std::stoi( value );
|
||||
|
||||
@@ -9,7 +9,6 @@ public:
|
||||
static bool Load( std::string filename );
|
||||
|
||||
static inline std::string service_ip;
|
||||
static inline uint16_t gateway_port;
|
||||
static inline uint16_t lobby_port;
|
||||
static inline uint16_t discovery_port;
|
||||
};
|
||||
@@ -21,7 +21,6 @@
|
||||
#include "Network/GenericNetResponse.hpp"
|
||||
#include "Network/GenericNetMessage.hpp"
|
||||
|
||||
#include "Gateway Server/GatewayServer.h"
|
||||
#include "Lobby Server/LobbyServer.h"
|
||||
#include "Discovery Server/DiscoveryServer.h"
|
||||
|
||||
|
||||
30
main.cpp
30
main.cpp
@@ -14,12 +14,12 @@ static void ShowStartup()
|
||||
|
||||
static bool NetworkStartup()
|
||||
{
|
||||
WORD wVersionRequest = MAKEWORD(2, 2);
|
||||
WORD wVersionRequest = MAKEWORD( 2, 2 );
|
||||
WSADATA wsaData;
|
||||
|
||||
if (WSAStartup(wVersionRequest, &wsaData) != 0)
|
||||
if( WSAStartup( wVersionRequest, &wsaData ) != 0 )
|
||||
{
|
||||
Log::Error("WSAStartup() failed");
|
||||
Log::Error( "WSAStartup() failed" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,12 +30,12 @@ int main()
|
||||
{
|
||||
ShowStartup();
|
||||
|
||||
if (false == NetworkStartup())
|
||||
if( !NetworkStartup() )
|
||||
{
|
||||
Log::Error("Could not initialize network.");
|
||||
Log::Error( "Could not initialize network." );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Log::Info( "Server Start..." );
|
||||
|
||||
if( !Config::Load( "config.ini" ) )
|
||||
@@ -44,29 +44,20 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto &gateway_server = GatewayServer::Get();
|
||||
gateway_server.Start( Config::service_ip, Config::gateway_port );
|
||||
|
||||
auto &lobby_server = LobbyServer::Get();
|
||||
lobby_server.Start(Config::service_ip, Config::lobby_port);
|
||||
lobby_server.Start( Config::service_ip, Config::lobby_port );
|
||||
|
||||
auto &discovery_server = DiscoveryServer::Get();
|
||||
discovery_server.Start(Config::service_ip, Config::discovery_port);
|
||||
discovery_server.Start( Config::service_ip, Config::discovery_port );
|
||||
|
||||
while( true )
|
||||
{
|
||||
if( !gateway_server.isRunning() )
|
||||
{
|
||||
Log::Error( "Gateway Server is not running. Exiting." );
|
||||
break;
|
||||
}
|
||||
|
||||
if( !lobby_server.isRunning() )
|
||||
{
|
||||
Log::Error( "Lobby Server is not running. Exiting." );
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if( !discovery_server.isRunning() )
|
||||
{
|
||||
Log::Error( "Discovery Server is not running. Exiting." );
|
||||
@@ -76,9 +67,8 @@ int main()
|
||||
std::this_thread::sleep_for( std::chrono::milliseconds( 250 ) );
|
||||
}
|
||||
|
||||
gateway_server.Stop();
|
||||
lobby_server.Stop();
|
||||
discovery_server.Stop();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user