Lesson 79 - Handle Game Session Status
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "HttpModule.h"
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "Data/API/APIData.h"
|
||||
#include "GameFramework/PlayerState.h"
|
||||
#include "GameplayTags/DedicatedServerTags.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
@@ -30,8 +31,6 @@ void UPortalManager::JoinGameSession()
|
||||
void UPortalManager::FindOrCreateGameSession_Response(FHttpRequestPtr Request, FHttpResponsePtr Response,
|
||||
bool bWasSuccessful)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Find or Create Game Session Response Received"));
|
||||
|
||||
if (!bWasSuccessful)
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(HTTPStatusMessages::SomethingWentWrong, true);
|
||||
@@ -45,8 +44,7 @@ void UPortalManager::FindOrCreateGameSession_Response(FHttpRequestPtr Request, F
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(HTTPStatusMessages::SomethingWentWrong, true);
|
||||
}
|
||||
DumpMetadata(JsonObject);
|
||||
|
||||
|
||||
if (JsonObject->HasField(TEXT("GameProperties")))
|
||||
{
|
||||
auto PropertiesArray = JsonObject->GetArrayField(TEXT("GameProperties"));
|
||||
@@ -66,7 +64,59 @@ void UPortalManager::FindOrCreateGameSession_Response(FHttpRequestPtr Request, F
|
||||
|
||||
FDSGameSession GameSession;
|
||||
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &GameSession);
|
||||
GameSession.Dump();
|
||||
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Found Game Session."), false);
|
||||
|
||||
const FString GameSessionId = GameSession.GameSessionId;
|
||||
const FString GameSessionStatus = GameSession.Status;
|
||||
const FString UniquePlayerId = GetUniquePlayerId();
|
||||
|
||||
HandleGameSessionStatus(GameSessionId, GameSessionStatus);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
FString UPortalManager::GetUniquePlayerId() const
|
||||
{
|
||||
APlayerController* LocalPlayerController = GEngine->GetFirstLocalPlayerController(GetWorld());
|
||||
if (IsValid(LocalPlayerController))
|
||||
{
|
||||
APlayerState* LocalPlayerState = LocalPlayerController->GetPlayerState<APlayerState>();
|
||||
if (IsValid(LocalPlayerState) && LocalPlayerState->GetUniqueId().IsValid())
|
||||
{
|
||||
return TEXT("Player_") + FString::FromInt(LocalPlayerState->GetUniqueID());
|
||||
}
|
||||
}
|
||||
return FString();
|
||||
}
|
||||
|
||||
void UPortalManager::HandleGameSessionStatus(const FString& Status, const FString& SessionId)
|
||||
{
|
||||
|
||||
if (Status.Equals(TEXT("ACTIVE")))
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Found Active Game Session. Creating Player Session..."), false);
|
||||
TryCreatePlayerSession(GetUniquePlayerId(), SessionId);
|
||||
}
|
||||
else if (Status.Equals(TEXT("ACTIVATING")))
|
||||
{
|
||||
FTimerDelegate CreateSessionDelegate;
|
||||
CreateSessionDelegate.BindLambda([this]()
|
||||
{
|
||||
JoinGameSession();
|
||||
});
|
||||
APlayerController* LocalPlayerController = GEngine->GetFirstLocalPlayerController(GetWorld());
|
||||
if (IsValid(LocalPlayerController))
|
||||
{
|
||||
LocalPlayerController->GetWorldTimerManager().SetTimer(CreateSessionTimer, CreateSessionDelegate, 0.5f, false);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(HTTPStatusMessages::SomethingWentWrong, true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void UPortalManager::TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId)
|
||||
{
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user