Clean up Network Events
Beginning support for RTA
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "NotifyClientDiscovered.h"
|
||||
|
||||
NotifyClientDiscovered::NotifyClientDiscovered( std::string clientIp, int32_t clientPort ) : GenericMessage( 0x40 )
|
||||
{
|
||||
m_clientIp = clientIp;
|
||||
m_clientPort = clientPort;
|
||||
}
|
||||
|
||||
ByteStream &NotifyClientDiscovered::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_sz_utf8( m_clientIp );
|
||||
m_stream.write_u32( m_clientPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class NotifyClientDiscovered : public GenericMessage {
|
||||
private:
|
||||
std::string m_clientIp;
|
||||
int32_t m_clientPort;
|
||||
|
||||
public:
|
||||
NotifyClientDiscovered( std::string clientIp, int32_t clientPort );
|
||||
ByteStream &Serialize() override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "NotifyClientReqConnect.h"
|
||||
|
||||
NotifyClientRequestConnect::NotifyClientRequestConnect( std::string clientIp, int32_t clientPort ) : GenericMessage( 0x3F )
|
||||
{
|
||||
m_clientIp = clientIp;
|
||||
m_clientPort = clientPort;
|
||||
}
|
||||
|
||||
ByteStream &NotifyClientRequestConnect::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_sz_utf8( m_clientIp );
|
||||
m_stream.write_u32( m_clientPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class NotifyClientRequestConnect : public GenericMessage
|
||||
{
|
||||
private:
|
||||
std::string m_clientIp;
|
||||
int32_t m_clientPort;
|
||||
|
||||
public:
|
||||
NotifyClientRequestConnect( std::string clientIp, int32_t clientPort );
|
||||
ByteStream &Serialize() override;
|
||||
};
|
||||
@@ -1,19 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "NotifyGameDiscovered.h"
|
||||
|
||||
NotifyGameDiscovered::NotifyGameDiscovered( std::string clientIp, int32_t clientPort ) : GenericMessage( 0x3E )
|
||||
{
|
||||
m_clientIp = clientIp;
|
||||
m_clientPort = clientPort;
|
||||
}
|
||||
|
||||
ByteStream &NotifyGameDiscovered::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_sz_utf8( m_clientIp );
|
||||
m_stream.write_u32( m_clientPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class NotifyGameDiscovered : public GenericMessage {
|
||||
private:
|
||||
std::string m_clientIp;
|
||||
int32_t m_clientPort;
|
||||
|
||||
public:
|
||||
NotifyGameDiscovered( std::string clientIp, int32_t clientPort );
|
||||
ByteStream &Serialize() override;
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestCancelGame.h"
|
||||
|
||||
void RequestCancelGame::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestCancelGame::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
if( user == nullptr )
|
||||
{
|
||||
Log::Error( "User not found! [%S]", m_sessionId.c_str() );
|
||||
return std::make_shared< ResultCancelGame >( this );
|
||||
}
|
||||
|
||||
GameSessionManager::Get().RequestCancel( user );
|
||||
|
||||
return std::make_shared< ResultCancelGame >( this );
|
||||
}
|
||||
|
||||
ResultCancelGame::ResultCancelGame( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ByteStream &ResultCancelGame::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestCancelGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestCancelGame > Create()
|
||||
{
|
||||
return std::make_unique< RequestCancelGame >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultCancelGame : public GenericResponse {
|
||||
public:
|
||||
ResultCancelGame( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestCreateAccount.h"
|
||||
|
||||
void RequestCreateAccount::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
auto username = stream->read_encrypted_utf16();
|
||||
auto password = stream->read_encrypted_utf16();
|
||||
auto emailAddress = stream->read_encrypted_utf16();
|
||||
auto dateOfBirth = stream->read_encrypted_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestCreateAccount::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
Log::Debug( "Account creation isn't supported. Random SessionID generated." );
|
||||
|
||||
if( nullptr == user )
|
||||
{
|
||||
Log::Error( "RequestCreateAccount::ProcessRequest() - User not found!" );
|
||||
return std::make_shared< ResultCreateAccount >( this, CREATE_ACCOUNT_REPLY::ERROR_FATAL, L"" );
|
||||
}
|
||||
|
||||
return std::make_shared< ResultCreateAccount >( this, CREATE_ACCOUNT_REPLY::SUCCESS, user->m_sessionId );
|
||||
}
|
||||
|
||||
ResultCreateAccount::ResultCreateAccount( GenericRequest *request, int32_t reply, std::wstring sessionId ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_sessionId = sessionId;
|
||||
}
|
||||
|
||||
ByteStream &ResultCreateAccount::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
m_stream.write_encrypted_utf16( m_sessionId );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Account Creation is used in the Network Beta for CoN
|
||||
// but it isn't used or supported here because retail
|
||||
// uses "foo" and "bar" to login without user data.
|
||||
|
||||
class RequestCreateAccount : public GenericRequest
|
||||
{
|
||||
enum CREATE_ACCOUNT_REPLY {
|
||||
SUCCESS = 0,
|
||||
ERROR_FATAL,
|
||||
ERROR_NOT_EXIST
|
||||
};
|
||||
public:
|
||||
static std::unique_ptr< RequestCreateAccount > Create()
|
||||
{
|
||||
return std::make_unique< RequestCreateAccount >();
|
||||
}
|
||||
|
||||
CREATE_ACCOUNT_REPLY m_reply;
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultCreateAccount : public GenericResponse {
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
int32_t m_reply;
|
||||
|
||||
public:
|
||||
ResultCreateAccount( GenericRequest *request, int32_t reply, std::wstring sessionId );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
|
||||
#include "RequestCreatePrivateGame.h"
|
||||
|
||||
void RequestCreatePrivateGame::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_gameInfo = stream->read_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestCreatePrivateGame::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto result = GameSessionManager::Get().CreatePrivateGameSession( user, m_gameInfo );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
Log::Error( "RequestCreatePrivateGame::ProcessRequest() - Failed to create private game session!" );
|
||||
return std::make_shared< ResultCreatePrivateGame >( this, CREATE_REPLY::GENERAL_ERROR, "", 0 );
|
||||
}
|
||||
|
||||
Log::Info( "[%S] Create Private Game: %S", m_sessionId.c_str(), m_gameInfo.c_str() );
|
||||
|
||||
return std::make_shared< ResultCreatePrivateGame >( this, CREATE_REPLY::SUCCESS, Config::service_ip, Config::discovery_port );
|
||||
}
|
||||
|
||||
ResultCreatePrivateGame::ResultCreatePrivateGame( GenericRequest *request, int32_t reply, std::string discoveryIp, int32_t discoveryPort ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_discoveryIp = discoveryIp;
|
||||
m_discoveryPort = discoveryPort;
|
||||
}
|
||||
|
||||
ByteStream &ResultCreatePrivateGame::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
m_stream.write_sz_utf8( m_discoveryIp );
|
||||
m_stream.write( m_discoveryPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestCreatePrivateGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_gameInfo;
|
||||
|
||||
enum CREATE_REPLY {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR,
|
||||
GENERAL_ERROR,
|
||||
GAME_NAME_IN_USE = 38,
|
||||
GAME_PENDING = 40,
|
||||
};
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestCreatePrivateGame > Create()
|
||||
{
|
||||
return std::make_unique< RequestCreatePrivateGame >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultCreatePrivateGame : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
std::string m_discoveryIp;
|
||||
int32_t m_discoveryPort;
|
||||
|
||||
public:
|
||||
ResultCreatePrivateGame( GenericRequest *request, int32_t reply, std::string discoveryIp = "", int32_t discoveryPort = 0 );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,56 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
|
||||
#include "RequestCreatePublicGame.h"
|
||||
|
||||
// Request
|
||||
void RequestCreatePublicGame::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
|
||||
// Some kind of match attributes
|
||||
auto unknown_a = stream->read_u16();
|
||||
auto unknown_b = stream->read_u32();
|
||||
auto unknown_c = stream->read_u32();
|
||||
auto unknown_d = stream->read_u32();
|
||||
|
||||
m_gameInfo = stream->read_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestCreatePublicGame::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto result = GameSessionManager::Get().CreatePublicGameSession( user, m_gameInfo );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
Log::Error( "RequestCreatePublicGame::ProcessRequest() - Failed to create public game session!" );
|
||||
return std::make_shared< ResultCreatePublicGame >( this, CREATE_REPLY::GENERAL_ERROR, "", 0 );
|
||||
}
|
||||
|
||||
Log::Info( "[%S] Create Public Game: %S", m_sessionId.c_str(), m_gameInfo.c_str() );
|
||||
|
||||
return std::make_shared< ResultCreatePublicGame >(this, CREATE_REPLY::SUCCESS, Config::service_ip, Config::discovery_port);
|
||||
}
|
||||
|
||||
// Result
|
||||
ResultCreatePublicGame::ResultCreatePublicGame( GenericRequest *request, int32_t reply, std::string discoveryIp, int32_t discoveryPort ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_discoveryIp = discoveryIp;
|
||||
m_discoveryPort = discoveryPort;
|
||||
}
|
||||
|
||||
ByteStream &ResultCreatePublicGame::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
m_stream.write_sz_utf8( m_discoveryIp );
|
||||
m_stream.write( m_discoveryPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestCreatePublicGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_gameInfo;
|
||||
|
||||
int32_t m_minimumLevel;
|
||||
int32_t m_maximumLevel;
|
||||
|
||||
enum CREATE_REPLY {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR,
|
||||
GENERAL_ERROR,
|
||||
GAME_NAME_IN_USE = 38,
|
||||
GAME_PENDING = 40,
|
||||
};
|
||||
public:
|
||||
static std::unique_ptr< RequestCreatePublicGame > Create()
|
||||
{
|
||||
return std::make_unique< RequestCreatePublicGame >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultCreatePublicGame : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
std::string m_discoveryIp;
|
||||
int32_t m_discoveryPort;
|
||||
|
||||
public:
|
||||
ResultCreatePublicGame( GenericRequest *request, int32_t reply, std::string discoveryIp = "", int32_t discoveryPort = 0 );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,50 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestDoClientDiscovery.h"
|
||||
|
||||
void RequestDoClientDiscovery::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_gameId = stream->read_u32();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestDoClientDiscovery::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto session = GameSessionManager::Get().FindGame( m_gameId );
|
||||
if( session == nullptr )
|
||||
{
|
||||
return std::make_shared< ResultDoClientDiscovery >( this, DISCOVERY_REPLY::FATAL_ERROR, "", 0 );
|
||||
}
|
||||
|
||||
if( session->m_currentPlayers >= session->m_maximumPlayers )
|
||||
{
|
||||
return std::make_shared< ResultDoClientDiscovery >( this, DISCOVERY_REPLY::GAME_FULL, "", 0 );
|
||||
}
|
||||
|
||||
user->m_gameId = m_gameId;
|
||||
user->m_isHost = false;
|
||||
|
||||
return std::make_shared< ResultDoClientDiscovery >( this, DISCOVERY_REPLY::SUCCESS, Config::service_ip, Config::discovery_port );
|
||||
}
|
||||
|
||||
ResultDoClientDiscovery::ResultDoClientDiscovery( GenericRequest *request, int32_t reply, std::string ip, int32_t port ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_discoveryIP = ip;
|
||||
m_discoveryPort = port;
|
||||
}
|
||||
|
||||
ByteStream &ResultDoClientDiscovery::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
m_stream.write_sz_utf8( m_discoveryIP );
|
||||
m_stream.write( m_discoveryPort );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestDoClientDiscovery : public GenericRequest
|
||||
{
|
||||
private:
|
||||
enum DISCOVERY_REPLY {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR = 1,
|
||||
GAME_FULL = 2,
|
||||
};
|
||||
|
||||
std::wstring m_sessionId;
|
||||
int32_t m_gameId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestDoClientDiscovery > Create()
|
||||
{
|
||||
return std::make_unique< RequestDoClientDiscovery >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultDoClientDiscovery : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
std::string m_discoveryIP;
|
||||
int32_t m_discoveryPort;
|
||||
|
||||
public:
|
||||
ResultDoClientDiscovery( GenericRequest *request, int32_t reply, std::string ip = "", int32_t port = 0);
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestGetEncryptionKey.h"
|
||||
|
||||
void RequestGetEncryptionKey::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetEncryptionKey::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto publicKey = stream->read_utf8();
|
||||
auto unknown = stream->read_u32();
|
||||
|
||||
return std::make_shared< ResultGetEncryptionKey >( this );
|
||||
}
|
||||
|
||||
ResultGetEncryptionKey::ResultGetEncryptionKey( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
m_symKey = RealmCrypt::getSymmetricKey();
|
||||
}
|
||||
|
||||
ByteStream& ResultGetEncryptionKey::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_encrypted_bytes( m_symKey );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestGetEncryptionKey : public GenericRequest
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr< RequestGetEncryptionKey > Create()
|
||||
{
|
||||
return std::make_unique< RequestGetEncryptionKey >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultGetEncryptionKey : public GenericResponse {
|
||||
public:
|
||||
std::vector< uint8_t > m_symKey;
|
||||
|
||||
ResultGetEncryptionKey( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,69 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestGetGame.h"
|
||||
|
||||
void RequestGetGame::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_gameName = stream->read_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetGame::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
if( user == nullptr )
|
||||
{
|
||||
Log::Error( "User not found! [%S]", m_sessionId.c_str() );
|
||||
return std::make_shared< ResultGetGame >( this, TIMEOUT );
|
||||
}
|
||||
|
||||
auto session = GameSessionManager::Get().FindGame( m_gameName );
|
||||
|
||||
if( session == nullptr )
|
||||
{
|
||||
Log::Error( "Game session not found! [%S]", m_gameName.c_str() );
|
||||
return std::make_shared< ResultGetGame >( this, NOT_FOUND );
|
||||
}
|
||||
|
||||
if( session->m_currentPlayers >= session->m_maximumPlayers )
|
||||
{
|
||||
Log::Error( "Game session is full! [%S]", m_gameName.c_str() );
|
||||
return std::make_shared< ResultGetGame >( this, TIMEOUT );
|
||||
}
|
||||
|
||||
auto host_user = session->m_owner.lock();
|
||||
|
||||
if( host_user == nullptr )
|
||||
{
|
||||
Log::Error( "Game session owner not found! [%S]", m_gameName.c_str() );
|
||||
return std::make_shared< ResultGetGame >( this, TIMEOUT );
|
||||
}
|
||||
|
||||
user->m_isHost = false;
|
||||
user->m_gameId = session->m_gameIndex;
|
||||
|
||||
return std::make_shared< ResultGetGame >( this, SUCCESS, session->m_gameIndex );
|
||||
}
|
||||
|
||||
ResultGetGame::ResultGetGame( GenericRequest *request, int32_t reply, int32_t gameId ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_gameId = gameId;
|
||||
}
|
||||
|
||||
ByteStream &ResultGetGame::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
// TODO: These may come in from the UpdateGameData event
|
||||
m_stream.write_utf16( L"Kelethin" );
|
||||
m_stream.write_utf16( L"OwnerName" );
|
||||
|
||||
m_stream.write_u32( m_gameId );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestGetGame : public GenericRequest {
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_gameName;
|
||||
|
||||
enum REPLY {
|
||||
SUCCESS = 0,
|
||||
TIMEOUT,
|
||||
NOT_FOUND
|
||||
};
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestGetGame > Create()
|
||||
{
|
||||
return std::make_unique< RequestGetGame >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultGetGame : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
int32_t m_gameId;
|
||||
|
||||
public:
|
||||
ResultGetGame( GenericRequest *request, int32_t reply, int32_t gameId = 0 );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestGetRealmStats.h"
|
||||
|
||||
void RequestGetRealmStats::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetRealmStats::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
return std::make_shared< ResultGetRealmStats >( this );
|
||||
}
|
||||
|
||||
ResultGetRealmStats::ResultGetRealmStats( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ByteStream &ResultGetRealmStats::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
// Player count on the game page.
|
||||
m_stream.write_u32( RealmUserManager::Get().GetUserCount() ); // Users Logged In Game
|
||||
|
||||
// I'm not sure this appears anywhere in the game.
|
||||
m_stream.write_u32( 0 ); // Users Logged In Realm
|
||||
m_stream.write_u32( 0 ); // Users Running Game
|
||||
m_stream.write_u32( 0 ); // Users Running Realm
|
||||
m_stream.write_u32( 0 ); // Users Playing Game
|
||||
m_stream.write_u32( 0 ); // Users Playing Realm
|
||||
m_stream.write_u32( 0 ); // unmatchedGamesGame
|
||||
m_stream.write_u32( 0 ); // unmatchedGamesRealm
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestGetRealmStats : public GenericRequest
|
||||
{
|
||||
public:
|
||||
static std::unique_ptr< RequestGetRealmStats > Create()
|
||||
{
|
||||
return std::make_unique< RequestGetRealmStats >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultGetRealmStats : public GenericResponse {
|
||||
public:
|
||||
ResultGetRealmStats( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,38 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestGetRules.h"
|
||||
|
||||
void RequestGetRules::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_language = stream->read_sz_utf8();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetRules::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
// TODO: Get rules/eula based on language
|
||||
std::wstring rules =
|
||||
L"Welcome to the Norrath Emulated Server!\n\n"
|
||||
L"This server is currently in development\n"
|
||||
L"and may not be fully functional.\n\n";
|
||||
|
||||
return std::make_shared< ResultGetRules >( this, rules );
|
||||
}
|
||||
|
||||
ResultGetRules::ResultGetRules( GenericRequest *request, std::wstring rules ) : GenericResponse( *request )
|
||||
{
|
||||
m_rules = rules;
|
||||
}
|
||||
|
||||
ByteStream &ResultGetRules::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
m_stream.write_utf16( m_rules );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestGetRules : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::string m_language;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestGetRules > Create()
|
||||
{
|
||||
return std::make_unique< RequestGetRules >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultGetRules : public GenericResponse {
|
||||
private:
|
||||
std::wstring m_rules;
|
||||
|
||||
public:
|
||||
ResultGetRules( GenericRequest *request, std::wstring rules );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,32 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestGetServerAddress.h"
|
||||
|
||||
void RequestGetServerAddress::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
}
|
||||
|
||||
sptr_generic_response RequestGetServerAddress::ProcessRequest( sptr_user user, 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,21 +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_user user, 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,51 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestLogin.h"
|
||||
|
||||
void RequestLogin::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_username = stream->read_encrypted_utf16();
|
||||
m_password = stream->read_encrypted_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestLogin::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
if( m_username.empty() || m_password.empty() )
|
||||
{
|
||||
Log::Error( "RequestLogin::ProcessRequest() - Username or password is empty" );
|
||||
return std::make_shared< ResultLogin >( this, LOGIN_REPLY::NOT_EXIST, L"" );
|
||||
}
|
||||
|
||||
if( m_username == L"foo" && m_password == L"bar" )
|
||||
{
|
||||
// Retail CoN does not use any login information.
|
||||
Log::Debug( "RequestLogin : Champions of Norrath v2.0" );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Network Beta CoN uses login information, but it's invalid because of version 2.0.
|
||||
Log::Debug( "RequestLogin : Champions of Norrath v1.0" );
|
||||
}
|
||||
|
||||
return std::make_shared< ResultLogin >( this, LOGIN_REPLY::SUCCESS, user->m_sessionId );
|
||||
}
|
||||
|
||||
ResultLogin::ResultLogin( GenericRequest *request, int32_t reply, std::wstring sessionId ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
m_sessionId = sessionId;
|
||||
}
|
||||
|
||||
ByteStream &ResultLogin::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
m_stream.write_encrypted_utf16( m_sessionId );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
// Account Login is used in the Network Beta for CoN.
|
||||
// In the retail version, the game simply logs in with
|
||||
// "foo" and "bar" as the username and password.
|
||||
//
|
||||
// A unique Session ID is generated and assigned to the player.
|
||||
|
||||
class RequestLogin : public GenericRequest
|
||||
{
|
||||
private:
|
||||
enum LOGIN_REPLY {
|
||||
SUCCESS = 0,
|
||||
FATAL_ERROR,
|
||||
NOT_EXIST,
|
||||
};
|
||||
|
||||
std::wstring m_username;
|
||||
std::wstring m_password;
|
||||
std::wstring m_sessionId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestLogin > Create()
|
||||
{
|
||||
return std::make_unique< RequestLogin >();
|
||||
}
|
||||
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultLogin : public GenericResponse {
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
int32_t m_reply;
|
||||
|
||||
public:
|
||||
ResultLogin( GenericRequest *request, int32_t reply, std::wstring sessionId );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestLogout.h"
|
||||
|
||||
void RequestLogout::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestLogout::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
Log::Debug( "[%S] Logout", m_sessionId.c_str() );
|
||||
|
||||
return std::make_shared< ResultLogout >( this, 0 );
|
||||
}
|
||||
|
||||
ResultLogout::ResultLogout( GenericRequest *request, int32_t reply ) : GenericResponse( *request )
|
||||
{
|
||||
m_reply = reply;
|
||||
}
|
||||
|
||||
ByteStream &ResultLogout::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( m_reply );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestLogout : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestLogout > Create()
|
||||
{
|
||||
return std::make_unique< RequestLogout >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultLogout : public GenericResponse {
|
||||
private:
|
||||
int32_t m_reply;
|
||||
public:
|
||||
ResultLogout( GenericRequest *request, int32_t reply );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,90 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestMatchGame.h"
|
||||
|
||||
void RequestMatchGame::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
|
||||
auto unknown_a = stream->read_u16();
|
||||
auto unknown_b = stream->read_u32();
|
||||
auto unknown_c = stream->read_u32();
|
||||
auto unknown_d = stream->read_u32();
|
||||
|
||||
auto unknown_e = stream->read_u32();
|
||||
|
||||
// Match Game Node Count
|
||||
for( uint32_t i = 0; i < unknown_e; i++ )
|
||||
{
|
||||
auto node_a = stream->read_u16();
|
||||
auto node_b = stream->read_u32();
|
||||
|
||||
auto node_c = stream->read_utf16();
|
||||
|
||||
auto node_d = stream->read_u32();
|
||||
auto node_e = stream->read_u32();
|
||||
auto node_f = stream->read_u32();
|
||||
auto node_g = stream->read_u16();
|
||||
}
|
||||
|
||||
auto unknown_f = stream->read_u8();
|
||||
auto unknown_g = stream->read_u32();
|
||||
auto unknown_h = stream->read_u32();
|
||||
|
||||
int dbg = 0;
|
||||
}
|
||||
|
||||
sptr_generic_response RequestMatchGame::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
return std::make_shared< ResultMatchGame >( this );
|
||||
}
|
||||
|
||||
ResultMatchGame::ResultMatchGame( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ByteStream &ResultMatchGame::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
auto publicGameList = GameSessionManager::Get().GetAvailableGameSessionList();
|
||||
auto publicGameCount = static_cast< uint32_t >( publicGameList.size() );
|
||||
|
||||
m_stream.write_u32( publicGameCount );
|
||||
{
|
||||
for( auto &game : publicGameList )
|
||||
m_stream.write_utf16( game->m_gameAddress );
|
||||
}
|
||||
|
||||
m_stream.write_u32( publicGameCount );
|
||||
{
|
||||
for( auto &game : publicGameList )
|
||||
m_stream.write_utf16( game->m_gameName );
|
||||
}
|
||||
|
||||
m_stream.write_u32( publicGameCount );
|
||||
{
|
||||
for( auto &game : publicGameList )
|
||||
m_stream.write_utf16( game->m_ownerName );
|
||||
}
|
||||
|
||||
m_stream.write_u32( publicGameCount );
|
||||
{
|
||||
for( auto &game : publicGameList )
|
||||
m_stream.write_u32( game->m_gameIndex );
|
||||
}
|
||||
|
||||
m_stream.write_u32( publicGameCount );
|
||||
{
|
||||
for( auto &game : publicGameList )
|
||||
m_stream.write_utf8( game->m_gameData );
|
||||
}
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestMatchGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestMatchGame > Create()
|
||||
{
|
||||
return std::make_unique< RequestMatchGame >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultMatchGame : public GenericResponse {
|
||||
public:
|
||||
ResultMatchGame( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestTouchSession.h"
|
||||
|
||||
void RequestTouchSession::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestTouchSession::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
return std::make_shared< ResultTouchSession >( this );
|
||||
}
|
||||
|
||||
ResultTouchSession::ResultTouchSession( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ByteStream &ResultTouchSession::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestTouchSession : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestTouchSession > Create()
|
||||
{
|
||||
return std::make_unique< RequestTouchSession >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultTouchSession : public GenericResponse {
|
||||
public:
|
||||
ResultTouchSession( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,68 +0,0 @@
|
||||
#include "../../global_define.h"
|
||||
#include "RequestUpdateGameData.h"
|
||||
|
||||
void RequestUpdateGameData::Deserialize( sptr_byte_stream stream )
|
||||
{
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_gameData = stream->read_utf8();
|
||||
}
|
||||
|
||||
sptr_generic_response RequestUpdateGameData::ProcessRequest( sptr_user user, sptr_byte_stream stream )
|
||||
{
|
||||
Deserialize( stream );
|
||||
|
||||
auto gameSession = GameSessionManager::Get().FindGame( user->m_gameId );
|
||||
|
||||
if( gameSession == nullptr )
|
||||
{
|
||||
Log::Error( "Game not found! [%S]", m_sessionId.c_str() );
|
||||
return std::make_shared< ResultUpdateGameData >( this );
|
||||
}
|
||||
|
||||
if( m_gameData.size() != 256 )
|
||||
{
|
||||
Log::Error( "Game data size is not 256 bytes! [%S]", m_sessionId.c_str() );
|
||||
return std::make_shared< ResultUpdateGameData >( this );
|
||||
}
|
||||
|
||||
gameSession->m_gameData = m_gameData;
|
||||
|
||||
// Parse Game Data. Not the most ideal way to do this, but it works.
|
||||
char currentPlayers = 0;
|
||||
char maxPlayers = 0;
|
||||
char description[ 200 ] = { 0 };
|
||||
|
||||
int result = sscanf( m_gameData.c_str(), " %hhd / %hhd :%199[^\r\n]", ¤tPlayers, &maxPlayers, description );
|
||||
|
||||
if( result >= 2 )
|
||||
{
|
||||
gameSession->m_currentPlayers = currentPlayers;
|
||||
gameSession->m_maximumPlayers = maxPlayers;
|
||||
gameSession->m_description = ( result == 3 ) ? description : ""; // Empty if not parsed
|
||||
}
|
||||
else
|
||||
{
|
||||
Log::Debug( "Failed to parse game info from: %s", m_gameData.c_str() );
|
||||
}
|
||||
|
||||
std::string ip = std::string( m_gameData.c_str() + 220, 24 );
|
||||
user->m_localAddr = ip;
|
||||
|
||||
return std::make_shared< ResultUpdateGameData >( this );
|
||||
}
|
||||
|
||||
ResultUpdateGameData::ResultUpdateGameData( GenericRequest *request ) : GenericResponse( *request )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ByteStream &ResultUpdateGameData::Serialize()
|
||||
{
|
||||
m_stream.write_u16( m_packetId );
|
||||
m_stream.write_u32( m_requestId );
|
||||
m_stream.write_u32( 0 );
|
||||
|
||||
return m_stream;
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
class RequestUpdateGameData : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::string m_gameData;
|
||||
|
||||
public:
|
||||
static std::unique_ptr< RequestUpdateGameData > Create()
|
||||
{
|
||||
return std::make_unique< RequestUpdateGameData >();
|
||||
}
|
||||
sptr_generic_response ProcessRequest( sptr_user user, sptr_byte_stream stream ) override;
|
||||
void Deserialize( sptr_byte_stream stream ) override;
|
||||
};
|
||||
|
||||
class ResultUpdateGameData : public GenericResponse {
|
||||
public:
|
||||
ResultUpdateGameData( GenericRequest *request );
|
||||
ByteStream &Serialize();
|
||||
};
|
||||
@@ -1,101 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
#include "Event/RequestCancelGame.h"
|
||||
#include "Event/RequestCreateAccount.h"
|
||||
#include "Event/RequestCreatePrivateGame.h"
|
||||
#include "Event/RequestCreatePublicGame.h"
|
||||
#include "Event/RequestGetGame.h"
|
||||
#include "Event/RequestGetRealmStats.h"
|
||||
#include "Event/RequestLogin.h"
|
||||
#include "Event/RequestLogout.h"
|
||||
#include "Event/RequestMatchGame.h"
|
||||
#include "Event/RequestTouchSession.h"
|
||||
#include "Event/RequestDoClientDiscovery.h"
|
||||
#include "Event/RequestGetServerAddress.h"
|
||||
#include "Event/RequestGetEncryptionKey.h"
|
||||
#include "Event/RequestGetRules.h"
|
||||
#include "Event/RequestUpdateGameData.h"
|
||||
|
||||
const std::map< int16_t, std::function< std::unique_ptr< GenericRequest >() > > LOBBY_REQUEST_EVENT =
|
||||
{
|
||||
{ 0x0005, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestCancelGame >();
|
||||
}
|
||||
},
|
||||
{ 0x0006, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestCreateAccount >();
|
||||
}
|
||||
},
|
||||
{ 0x0008, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestCreatePrivateGame >();
|
||||
}
|
||||
},
|
||||
{ 0x000A, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestCreatePublicGame >();
|
||||
}
|
||||
},
|
||||
{ 0x000D, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetGame >();
|
||||
}
|
||||
},
|
||||
{ 0x000F, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetRealmStats >();
|
||||
}
|
||||
},
|
||||
{ 0x0016, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestLogin >();
|
||||
}
|
||||
},
|
||||
{ 0x0017, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestLogout >();
|
||||
}
|
||||
},
|
||||
{ 0x0018, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestMatchGame >();
|
||||
}
|
||||
},
|
||||
{ 0x0024, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestTouchSession >();
|
||||
}
|
||||
},
|
||||
{ 0x0025, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestDoClientDiscovery >();
|
||||
}
|
||||
},
|
||||
{ 0x0027, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetEncryptionKey >();
|
||||
}
|
||||
},
|
||||
{ 0x0042, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetRules >();
|
||||
}
|
||||
},
|
||||
{ 0x0043, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestGetServerAddress >();
|
||||
}
|
||||
},
|
||||
{
|
||||
0x0044, []() -> std::unique_ptr< GenericRequest >
|
||||
{
|
||||
return std::make_unique< RequestUpdateGameData >();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
@@ -6,14 +6,15 @@
|
||||
// ╩═╝╚═╝╚═╝╚═╝ ╩ ╚═╝╚═╝╩╚═ ╚╝ ╚═╝╩╚═
|
||||
|
||||
#include "../global_define.h"
|
||||
#include "../Network/Events.h"
|
||||
|
||||
#include "LobbyEvents.h"
|
||||
#include "LobbyServer.h"
|
||||
|
||||
LobbyServer::LobbyServer()
|
||||
{
|
||||
m_running = false;
|
||||
m_listenSocket = INVALID_SOCKET;
|
||||
m_conSocket = INVALID_SOCKET;
|
||||
m_rtaSocket = INVALID_SOCKET;
|
||||
|
||||
m_clientSockets.clear();
|
||||
m_recvBuffer.resize( 1024 );
|
||||
@@ -21,49 +22,33 @@ LobbyServer::LobbyServer()
|
||||
|
||||
LobbyServer::~LobbyServer()
|
||||
{
|
||||
Log::Info( "Lobby Server stopped." );
|
||||
if( m_conSocket != INVALID_SOCKET )
|
||||
{
|
||||
closesocket( m_conSocket );
|
||||
m_conSocket = INVALID_SOCKET;
|
||||
}
|
||||
if( m_rtaSocket != INVALID_SOCKET )
|
||||
{
|
||||
closesocket( m_rtaSocket );
|
||||
m_rtaSocket = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyServer::Start( std::string ip, int32_t port )
|
||||
void LobbyServer::Start( std::string ip )
|
||||
{
|
||||
m_listenSocket = ::WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED );
|
||||
if( m_listenSocket == INVALID_SOCKET )
|
||||
{
|
||||
Log::Error( "WSASocket() failed" );
|
||||
m_conSocket = OpenNetworkSocket( ip, 40801 );
|
||||
if( m_conSocket == INVALID_SOCKET )
|
||||
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" );
|
||||
m_rtaSocket = OpenNetworkSocket( ip, 40810 );
|
||||
if( m_rtaSocket == INVALID_SOCKET )
|
||||
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( &LobbyServer::Run, this );
|
||||
|
||||
Log::Info( "Lobby Server started on %s:%d", ip.c_str(), port );
|
||||
Log::Info( "Lobby Server started" );
|
||||
}
|
||||
|
||||
void LobbyServer::Stop()
|
||||
@@ -75,6 +60,43 @@ void LobbyServer::Stop()
|
||||
}
|
||||
}
|
||||
|
||||
SOCKET LobbyServer::OpenNetworkSocket( std::string ip, int32_t port )
|
||||
{
|
||||
SOCKET sock = ::WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED );
|
||||
if( sock == INVALID_SOCKET )
|
||||
{
|
||||
Log::Error( "WSASocket() failed on port %u", port );
|
||||
return INVALID_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( sock, ( SOCKADDR * )&service, sizeof( service ) ) == SOCKET_ERROR )
|
||||
{
|
||||
Log::Error( "bind() failed on port %u", port );
|
||||
closesocket( sock );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if( listen( sock, SOMAXCONN ) == SOCKET_ERROR )
|
||||
{
|
||||
Log::Error( "listen() failed on port %u", port );
|
||||
closesocket( sock );
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
Log::Info( "Socket Opened on %s:%d", ip.c_str(), port );
|
||||
|
||||
return sock;
|
||||
}
|
||||
|
||||
void LobbyServer::Run()
|
||||
{
|
||||
FD_SET readSet;
|
||||
@@ -87,18 +109,23 @@ void LobbyServer::Run()
|
||||
FD_ZERO( &readSet );
|
||||
FD_ZERO( &writeSet );
|
||||
|
||||
FD_SET( m_listenSocket, &readSet );
|
||||
FD_SET( m_conSocket, &readSet );
|
||||
FD_SET( m_rtaSocket, &readSet );
|
||||
|
||||
CheckSocketProblem();
|
||||
|
||||
// Process clients
|
||||
for( auto &client : m_clientSockets )
|
||||
auto maxfd = std::max< SOCKET >( m_conSocket, m_rtaSocket );
|
||||
|
||||
for( const auto &client : m_clientSockets )
|
||||
{
|
||||
FD_SET( client->fd, &readSet );
|
||||
FD_SET( client->fd, &writeSet );
|
||||
|
||||
if( client->fd > maxfd )
|
||||
maxfd = client->fd;
|
||||
}
|
||||
|
||||
auto result = select( 0, &readSet, &writeSet, NULL, &timeout );
|
||||
auto result = select( static_cast< int >( maxfd + 1 ), &readSet, &writeSet, NULL, &timeout );
|
||||
|
||||
if( result == SOCKET_ERROR )
|
||||
{
|
||||
@@ -106,9 +133,14 @@ void LobbyServer::Run()
|
||||
continue;
|
||||
}
|
||||
|
||||
if( FD_ISSET( m_listenSocket, &readSet ) )
|
||||
if( FD_ISSET( m_conSocket, &readSet ) )
|
||||
{
|
||||
AcceptNewClient();
|
||||
AcceptNewClient( m_conSocket, RealmClientType::CHAMPIONS_OF_NORRATH );
|
||||
}
|
||||
|
||||
if( FD_ISSET( m_rtaSocket, &readSet ) )
|
||||
{
|
||||
AcceptNewClient( m_rtaSocket, RealmClientType::RETURN_TO_ARMS );
|
||||
}
|
||||
|
||||
for( auto &client : m_clientSockets )
|
||||
@@ -152,12 +184,12 @@ void LobbyServer::CheckSocketProblem()
|
||||
}
|
||||
}
|
||||
|
||||
void LobbyServer::AcceptNewClient()
|
||||
void LobbyServer::AcceptNewClient( SOCKET socket, RealmClientType clientType )
|
||||
{
|
||||
sockaddr_in clientInfo{};
|
||||
int32_t addrSize = sizeof( clientInfo );
|
||||
|
||||
SOCKET clientSocket = accept( m_listenSocket, ( SOCKADDR * )&clientInfo, &addrSize );
|
||||
SOCKET clientSocket = accept( socket, ( SOCKADDR * )&clientInfo, &addrSize );
|
||||
if( clientSocket == INVALID_SOCKET )
|
||||
{
|
||||
Log::Error( "accept() failed" );
|
||||
@@ -172,7 +204,7 @@ void LobbyServer::AcceptNewClient()
|
||||
|
||||
m_clientSockets.push_back( new_socket );
|
||||
|
||||
RealmUserManager::Get().CreateUser( new_socket );
|
||||
RealmUserManager::Get().CreateUser( new_socket, clientType );
|
||||
|
||||
Log::Info( "[LOBBY] New Client Connected : (%s)", new_socket->remote_ip.c_str() );
|
||||
}
|
||||
@@ -213,7 +245,7 @@ void LobbyServer::ReadSocket( sptr_socket socket )
|
||||
{
|
||||
int32_t packetSize = ntohl( *reinterpret_cast< const int32_t * >( &socket->m_pendingReadBuffer[ 0 ] ) );
|
||||
|
||||
if( packetSize <= 0 || packetSize > 1024 )
|
||||
if( packetSize <= 0 || packetSize > 2048 )
|
||||
{
|
||||
Log::Error( "Invalid packet size: %d. Disconnecting client.", packetSize );
|
||||
socket->flag.disconnected = true;
|
||||
@@ -298,8 +330,11 @@ void LobbyServer::HandleRequest( sptr_socket socket, sptr_byte_stream stream )
|
||||
auto packetId = stream->read< uint16_t >();
|
||||
stream->set_position( 0 );
|
||||
|
||||
auto it = LOBBY_REQUEST_EVENT.find( packetId );
|
||||
if( it == LOBBY_REQUEST_EVENT.end() )
|
||||
Log::Debug( "Event Request %04X", packetId );
|
||||
Log::Packet( stream->data, stream->data.size(), false );
|
||||
|
||||
auto it = REQUEST_EVENT.find( packetId );
|
||||
if( it == REQUEST_EVENT.end() )
|
||||
{
|
||||
Log::Error( "[LOBBY] Unknown packet id : 0x%04X", packetId );
|
||||
Log::Packet( stream->data, stream->data.size(), false );
|
||||
|
||||
@@ -3,37 +3,6 @@
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
class GameRoom {
|
||||
public:
|
||||
GameRoom()
|
||||
{
|
||||
m_gameType = GameType::PRIVATE;
|
||||
m_roomId = 0;
|
||||
m_ownerSessionId = L"";
|
||||
m_gameName = L"";
|
||||
m_minimumLevel = 0;
|
||||
m_maximumLevel = 0;
|
||||
}
|
||||
|
||||
~GameRoom()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
enum GameType {
|
||||
PRIVATE,
|
||||
PUBLIC
|
||||
} m_gameType;
|
||||
|
||||
int32_t m_roomId;
|
||||
std::wstring m_ownerSessionId;
|
||||
std::wstring m_gameName;
|
||||
int32_t m_minimumLevel;
|
||||
int32_t m_maximumLevel;
|
||||
};
|
||||
|
||||
typedef std::shared_ptr< GameRoom > sptr_game_room;
|
||||
|
||||
class LobbyServer
|
||||
{
|
||||
private:
|
||||
@@ -60,7 +29,7 @@ public:
|
||||
LobbyServer();
|
||||
~LobbyServer();
|
||||
|
||||
void Start( std::string ip, int32_t port );
|
||||
void Start( std::string ip );
|
||||
void Stop();
|
||||
bool isRunning() const
|
||||
{
|
||||
@@ -68,13 +37,16 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
SOCKET m_listenSocket;
|
||||
SOCKET m_conSocket;
|
||||
SOCKET m_rtaSocket;
|
||||
std::vector< sptr_socket > m_clientSockets;
|
||||
std::vector< uint8_t > m_recvBuffer;
|
||||
|
||||
SOCKET OpenNetworkSocket( std::string ip, int32_t port );
|
||||
|
||||
void Run();
|
||||
void CheckSocketProblem();
|
||||
void AcceptNewClient();
|
||||
void AcceptNewClient( SOCKET socket, RealmClientType clientType );
|
||||
void ReadSocket( sptr_socket socket );
|
||||
void WriteSocket( sptr_socket socket );
|
||||
void HandleRequest( sptr_socket socket, sptr_byte_stream stream );
|
||||
|
||||
Reference in New Issue
Block a user