Session and User management
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
#include "../global_define.h"
|
||||
#include "GameSessionManager.h"
|
||||
|
||||
#include "../Lobby Server/Event/NotifyClientDiscovered.h"
|
||||
#include "../Lobby Server/Event/NotifyClientReqConnect.h"
|
||||
#include "../Lobby Server/Event/NotifyGameDiscovered.h"
|
||||
|
||||
GameSessionManager::GameSessionManager()
|
||||
{
|
||||
m_gameIndex = 0;
|
||||
@@ -12,6 +16,85 @@ GameSessionManager::~GameSessionManager()
|
||||
{
|
||||
}
|
||||
|
||||
void GameSessionManager::Process()
|
||||
{
|
||||
for( auto &gameSession : m_publicGameSessionList )
|
||||
{
|
||||
ProcessGameSession( gameSession );
|
||||
}
|
||||
|
||||
for( auto &gameSession : m_privateGameSessionList )
|
||||
{
|
||||
ProcessGameSession( gameSession );
|
||||
}
|
||||
}
|
||||
|
||||
void GameSessionManager::ProcessGameSession( sptr_game_session gameSession )
|
||||
{
|
||||
static int test = 0;
|
||||
|
||||
//if( 0 == onePass ) return;
|
||||
|
||||
for( auto &member : gameSession->m_userList )
|
||||
{
|
||||
if( member == nullptr )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( member->m_state == RealmUser::UserState::DiscoveryPending )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//if( member->m_state == RealmUser::UserState::JoinPending )
|
||||
if( test == 1 )
|
||||
{
|
||||
//HandleJoinDiscovery( gameSession, member );
|
||||
|
||||
|
||||
//auto gameOwner = gameSession->GetOwner();
|
||||
|
||||
//NotifyClientRequestConnect notify( discoveryInfo->m_ip.c_str(), discoveryInfo->m_port );
|
||||
//gameOwner->m_realmSocket->send( notify );
|
||||
//
|
||||
//member->m_state = RealmUser::UserState::InGameLobby;
|
||||
//
|
||||
//NotifyGameDiscovered notifyGameDiscover( discoveryInfo->m_ip.c_str(), discoveryInfo->m_port );
|
||||
//member->m_realmSocket->send( notifyGameDiscover );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Notify the host that a user has joined the game
|
||||
//NotifyClientRequestConnect notify( "192.168.1.248", 47115 );
|
||||
|
||||
//NotifyClientRequestConnect notify( "192.168.1.248", 40820 );
|
||||
//gameOwner->m_realmSocket->send( notify );
|
||||
|
||||
// Notify the user that the host has accepted the connection
|
||||
//NotifyGameDiscovered notify2( gameOwner->discovery.ip, gameOwner->discovery.port );
|
||||
//member->m_realmSocket->send( notify2 );
|
||||
}
|
||||
|
||||
|
||||
if( test == 2 )
|
||||
{
|
||||
//NotifyGameDiscovered msg2( "192.168.1.248", 3001 );
|
||||
//member->m_realmSocket->send( msg2 );
|
||||
|
||||
//NotifyClientDiscovered msg1( "192.168.1.248", 3001 );
|
||||
//member->m_realmSocket->send( msg1 );
|
||||
|
||||
NotifyClientRequestConnect notify( "127.0.0.1", 3001 );
|
||||
member->m_realmSocket->send( notify );
|
||||
}
|
||||
}
|
||||
|
||||
test = 0;
|
||||
}
|
||||
|
||||
bool GameSessionManager::CreatePublicGameSession( sptr_user owner, std::wstring gameName, int32_t minimumLevel, int32_t maximumLevel )
|
||||
{
|
||||
auto &hostSessionId = owner->m_sessionId;
|
||||
@@ -74,34 +157,29 @@ bool GameSessionManager::CreatePrivateGameSession( sptr_user owner, std::wstring
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GameSessionManager::UpdateGameSessionDiscovery( sptr_user owner, std::string hostIp, int32_t hostPort )
|
||||
bool GameSessionManager::CancelGameSession( std::wstring sessionId )
|
||||
{
|
||||
auto &hostSessionId = owner->m_sessionId;
|
||||
|
||||
for( auto &gameSession : m_publicGameSessionList )
|
||||
for( auto it = m_publicGameSessionList.begin(); it != m_publicGameSessionList.end(); ++it )
|
||||
{
|
||||
if( gameSession->m_hostSessionId == hostSessionId )
|
||||
if( ( *it )->m_hostSessionId == sessionId )
|
||||
{
|
||||
//gameSession->m_hostIp = hostIp;
|
||||
//gameSession->m_hostPort = hostPort;
|
||||
|
||||
Log::Debug( "Public Game session canceled! [%S]", sessionId.c_str() );
|
||||
m_publicGameSessionList.erase( it );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for( auto &gameSession : m_privateGameSessionList )
|
||||
for( auto it = m_privateGameSessionList.begin(); it != m_privateGameSessionList.end(); ++it )
|
||||
{
|
||||
if( gameSession->m_hostSessionId == hostSessionId )
|
||||
if( ( *it )->m_hostSessionId == sessionId )
|
||||
{
|
||||
//gameSession->m_hostIp = hostIp;
|
||||
//gameSession->m_hostPort = hostPort;
|
||||
|
||||
Log::Debug( "Private Game session canceled! [%S]", sessionId.c_str() );
|
||||
m_privateGameSessionList.erase( it );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Log::Error( "Failed to update game session discovery information! [%S]", hostSessionId.c_str() );
|
||||
|
||||
Log::Error( "Failed to cancel game session! [%S]", sessionId.c_str() );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -163,3 +241,21 @@ bool GameSessionManager::UserJoinGame( const int32_t gameId, sptr_user joiningUs
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void GameSessionManager::HandleJoinDiscovery( sptr_game_session gameSession, sptr_user joiningUser )
|
||||
{
|
||||
auto discoveryInfo = DiscoveryServer::Get().GetDiscoveryInfo( joiningUser->m_sessionId );
|
||||
|
||||
if( !discoveryInfo.has_value() )
|
||||
{
|
||||
Log::Error( "Discovery info not found! [%S]", joiningUser->m_sessionId.c_str() );
|
||||
return;
|
||||
}
|
||||
|
||||
Log::Debug( "Member Discovery: %s:%d", discoveryInfo->m_ip.c_str(), discoveryInfo->m_port );
|
||||
|
||||
auto hostUser = gameSession->GetOwner();
|
||||
|
||||
NotifyClientRequestConnect notify( "192.168.1.248", 3001 );
|
||||
hostUser->m_realmSocket->send( notify );
|
||||
}
|
||||
|
||||
@@ -28,14 +28,18 @@ public:
|
||||
return *m_instance;
|
||||
}
|
||||
|
||||
public:
|
||||
void Process();
|
||||
void ProcessGameSession( sptr_game_session gameSession );
|
||||
|
||||
bool CreatePublicGameSession( sptr_user owner, std::wstring gameName, int32_t minimumLevel, int32_t maximumLevel );
|
||||
bool CreatePrivateGameSession( sptr_user owner, std::wstring gameName, int32_t minimumLevel, int32_t maximumLevel );
|
||||
bool UpdateGameSessionDiscovery( sptr_user owner, std::string hostIp, int32_t hostPort );
|
||||
bool CancelGameSession( std::wstring sessionId );
|
||||
|
||||
sptr_game_session FindGame( const std::wstring sessionId );
|
||||
sptr_game_session FindGame( const int32_t gameId );
|
||||
|
||||
bool UserJoinGame( const int32_t gameId, sptr_user joiningUser );
|
||||
|
||||
private:
|
||||
void HandleJoinDiscovery( sptr_game_session gameSession, sptr_user joiningUser );
|
||||
};
|
||||
@@ -4,7 +4,6 @@ RealmUser::RealmUser()
|
||||
{
|
||||
m_state = UserState::MainMenu;
|
||||
m_realmSocket = nullptr;
|
||||
m_discoverySocket = nullptr;
|
||||
m_sessionId = L"";
|
||||
}
|
||||
|
||||
@@ -18,11 +17,5 @@ RealmUser::~RealmUser()
|
||||
m_realmSocket.reset();
|
||||
}
|
||||
|
||||
if( m_discoverySocket )
|
||||
{
|
||||
m_discoverySocket->flag.disconnected = true;
|
||||
m_discoverySocket.reset();
|
||||
}
|
||||
|
||||
m_sessionId = L"";
|
||||
}
|
||||
@@ -7,13 +7,14 @@ public:
|
||||
|
||||
enum class UserState {
|
||||
MainMenu,
|
||||
DiscoveryPending,
|
||||
JoinPending,
|
||||
InGameLobby,
|
||||
InGameSession,
|
||||
} m_state;
|
||||
|
||||
sptr_tcp_socket m_realmSocket;
|
||||
sptr_udp_socket m_discoverySocket;
|
||||
|
||||
std::wstring m_sessionId;
|
||||
};
|
||||
|
||||
|
||||
@@ -89,17 +89,4 @@ sptr_user RealmUserManager::GetUser( sptr_tcp_socket socket )
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
sptr_user RealmUserManager::GetUser( sptr_udp_socket socket )
|
||||
{
|
||||
for( auto &user : m_users )
|
||||
{
|
||||
if( user->m_discoverySocket == socket )
|
||||
{
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,6 @@ public:
|
||||
|
||||
sptr_user GetUser( const std::wstring &sessionId );
|
||||
sptr_user GetUser( sptr_tcp_socket socket );
|
||||
sptr_user GetUser( sptr_udp_socket socket );
|
||||
|
||||
private:
|
||||
};
|
||||
Reference in New Issue
Block a user