Lesson 79 - Handle Game Session Status

This commit is contained in:
Norman Lansing
2026-04-05 16:43:32 -04:00
parent a5bfad07cc
commit bc219f373d
4 changed files with 64 additions and 8 deletions

View File

@@ -1 +1 @@
<EFBFBD><1C><>5<EFBFBD>L9OHn<48>q<EFBFBD>
T<>丠鏣<E4B8A0><E98FA3>

View File

@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "2025.3.0.1708",
"VersionName": "2025.3.3",
"FriendlyName": "RiderLink",
"Description": "Plugin for establishing IPC connection with JetBrains Rider IDE",
"Category": "Programming",

View File

@@ -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)
{
}

View File

@@ -27,4 +27,10 @@ public:
private:
void FindOrCreateGameSession_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
FString GetUniquePlayerId() const;
void HandleGameSessionStatus(const FString& Status, const FString& SessionId);
void TryCreatePlayerSession(const FString& PlayerId, const FString& GameSessionId);
FTimerHandle CreateSessionTimer;
};