mirror of
https://github.com/HikikoMarmy/Champions-Reborn-Server.git
synced 2026-04-05 08:59:54 -03:00
Parse Game Name and Location.
This commit is contained in:
@@ -15,6 +15,24 @@ GameSessionManager::~GameSessionManager()
|
||||
{
|
||||
}
|
||||
|
||||
std::tuple<std::wstring, std::wstring> GameSessionManager::ParseInfoData( const std::wstring &str )
|
||||
{
|
||||
size_t openBracket = str.find( '[' );
|
||||
size_t closeBracket = str.find( ']', openBracket );
|
||||
|
||||
if( openBracket != std::string::npos && closeBracket != std::string::npos )
|
||||
{
|
||||
std::wstring roomName = str.substr( 0, openBracket );
|
||||
std::wstring areaName = str.substr( openBracket + 1, closeBracket - openBracket - 1 );
|
||||
|
||||
roomName.erase( roomName.find_last_not_of( L" \t\r\n" ) + 1 );
|
||||
|
||||
return { roomName, areaName };
|
||||
}
|
||||
|
||||
return { str, L"" };
|
||||
}
|
||||
|
||||
void GameSessionManager::OnDisconnectUser( sptr_user user )
|
||||
{
|
||||
if( !user || user->m_gameId < 0 )
|
||||
@@ -41,13 +59,15 @@ void GameSessionManager::OnDisconnectUser( sptr_user user )
|
||||
}
|
||||
}
|
||||
|
||||
bool GameSessionManager::CreatePublicGameSession( sptr_user owner, std::wstring gameName )
|
||||
bool GameSessionManager::CreatePublicGameSession( sptr_user owner, std::wstring gameInfo )
|
||||
{
|
||||
auto new_session = std::make_shared< GameSession >();
|
||||
|
||||
auto [gameName, gameLocation] = ParseInfoData( gameInfo );
|
||||
|
||||
new_session->m_type = GameSession::GameType::Public;
|
||||
new_session->m_gameIndex = m_gameIndex;
|
||||
new_session->m_gameLocation = L"Kelethin";
|
||||
new_session->m_gameLocation = gameLocation;
|
||||
new_session->m_gameName = gameName;
|
||||
new_session->m_minimumLevel = 1;
|
||||
new_session->m_maximumLevel = 9999;
|
||||
@@ -68,8 +88,10 @@ bool GameSessionManager::CreatePublicGameSession( sptr_user owner, std::wstring
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GameSessionManager::CreatePrivateGameSession( sptr_user owner, std::wstring gameName )
|
||||
bool GameSessionManager::CreatePrivateGameSession( sptr_user owner, std::wstring gameInfo )
|
||||
{
|
||||
auto [gameName, gameLocation] = ParseInfoData( gameInfo );
|
||||
|
||||
// Check if the game name or host session id is already in use
|
||||
for( auto &gameSession : m_gameSessionList )
|
||||
{
|
||||
@@ -87,7 +109,7 @@ bool GameSessionManager::CreatePrivateGameSession( sptr_user owner, std::wstring
|
||||
|
||||
new_session->m_type = GameSession::GameType::Private;
|
||||
new_session->m_gameIndex = m_gameIndex;
|
||||
new_session->m_gameLocation = L"Kelethin";
|
||||
new_session->m_gameLocation = gameLocation;
|
||||
new_session->m_gameName = gameName;
|
||||
new_session->m_minimumLevel = 1;
|
||||
new_session->m_maximumLevel = 9999;
|
||||
|
||||
@@ -11,6 +11,8 @@ private:
|
||||
int32_t m_gameIndex;
|
||||
std::vector< sptr_game_session > m_gameSessionList;
|
||||
|
||||
std::tuple< std::wstring, std::wstring > ParseInfoData( const std::wstring &str );
|
||||
|
||||
public:
|
||||
GameSessionManager();
|
||||
~GameSessionManager();
|
||||
@@ -30,8 +32,8 @@ public:
|
||||
|
||||
void OnDisconnectUser( sptr_user user );
|
||||
|
||||
bool CreatePublicGameSession( sptr_user user, std::wstring gameName );
|
||||
bool CreatePrivateGameSession( sptr_user user, std::wstring gameName );
|
||||
bool CreatePublicGameSession( sptr_user user, std::wstring gameInfo );
|
||||
bool CreatePrivateGameSession( sptr_user user, std::wstring gameInfo );
|
||||
bool ForceTerminateGame( const int32_t gameId );
|
||||
sptr_game_session FindGame( const int32_t gameId );
|
||||
sptr_game_session FindGame( const std::wstring &gameName );
|
||||
|
||||
@@ -7,14 +7,14 @@ void RequestCreatePrivateGame::Deserialize( sptr_byte_stream stream )
|
||||
DeserializeHeader( stream );
|
||||
|
||||
m_sessionId = stream->read_encrypted_utf16();
|
||||
m_gameName = stream->read_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_gameName );
|
||||
auto result = GameSessionManager::Get().CreatePrivateGameSession( user, m_gameInfo );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
@@ -22,7 +22,7 @@ sptr_generic_response RequestCreatePrivateGame::ProcessRequest( sptr_user user,
|
||||
return std::make_shared< ResultCreatePrivateGame >( this, CREATE_REPLY::GENERAL_ERROR, "", 0 );
|
||||
}
|
||||
|
||||
Log::Info( "[%S] Create Private Game: %S", m_sessionId.c_str(), m_gameName.c_str() );
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class RequestCreatePrivateGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_gameName;
|
||||
std::wstring m_gameInfo;
|
||||
|
||||
enum CREATE_REPLY {
|
||||
SUCCESS = 0,
|
||||
|
||||
@@ -17,14 +17,14 @@ void RequestCreatePublicGame::Deserialize( sptr_byte_stream stream )
|
||||
auto unknown_c = stream->read_u32();
|
||||
auto unknown_d = stream->read_u32();
|
||||
|
||||
m_gameName = stream->read_utf16();
|
||||
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_gameName );
|
||||
auto result = GameSessionManager::Get().CreatePublicGameSession( user, m_gameInfo );
|
||||
|
||||
if( !result )
|
||||
{
|
||||
@@ -32,7 +32,7 @@ sptr_generic_response RequestCreatePublicGame::ProcessRequest( sptr_user user, s
|
||||
return std::make_shared< ResultCreatePublicGame >( this, CREATE_REPLY::GENERAL_ERROR, "", 0 );
|
||||
}
|
||||
|
||||
Log::Info( "[%S] Create Public Game: %S", m_sessionId.c_str(), m_gameName.c_str() );
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class RequestCreatePublicGame : public GenericRequest
|
||||
{
|
||||
private:
|
||||
std::wstring m_sessionId;
|
||||
std::wstring m_gameName;
|
||||
std::wstring m_gameInfo;
|
||||
|
||||
int32_t m_minimumLevel;
|
||||
int32_t m_maximumLevel;
|
||||
|
||||
Reference in New Issue
Block a user