Lesson 76 - Parsing the Game Session Response
This commit is contained in:
2
FPSTemplate.uproject.DotSettings.user
Normal file
2
FPSTemplate.uproject.DotSettings.user
Normal file
@@ -0,0 +1,2 @@
|
||||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003APoqebak_002Easm_002Fl_003AC_0021_003FUsers_003Fnlans_003FAppData_003FLocal_003FTemp_003FSandboxFiles_003FTyjudof_003FPoqebak_002Easm/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>
|
||||
@@ -1,6 +1,11 @@
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
#include "DedicatedServers/DedicatedServers.h"
|
||||
|
||||
namespace HTTPStatusMessages
|
||||
{
|
||||
const FString SomethingWentWrong{TEXT("Something went wrong...")};
|
||||
}
|
||||
|
||||
void FDSMetaData::Dump() const
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "MetaData:");
|
||||
@@ -21,6 +26,39 @@ void FDSListFleetsResponse::Dump() const
|
||||
|
||||
if (!NextToken.IsEmpty())
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "NextToken: {NextToken}", NextToken);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "NextToken: {NextToken}", *NextToken);
|
||||
}
|
||||
}
|
||||
|
||||
void FDSGameSession::Dump() const
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "GameSession:");
|
||||
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "GameSessionId: {GameSessionId}", *GameSessionId);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " Name: {Name}", *Name);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " FleetArn: {FleetArn}", *FleetArn);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " CreationTime: {CreationTime}", CreationTime); // need to write a conversion function
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " TerminationTime: {TerminationTime}", TerminationTime); // need to write a conversion function
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " CurrentPlayerSessionCount: {CurrentPlayerSessionCount}", CurrentPlayerSessionCount);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " MaximumPlayerSessionCount: {MaximumPlayerSessionCount}", MaximumPlayerSessionCount);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " Status: {Status}", *Status);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " StatusReason: {StatusReason}", *StatusReason);
|
||||
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " GameProperties:");
|
||||
for (const TTuple<FString, FString> GameProperty : GameProperties)
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " {Key} : {Value}", *GameProperty.Key, *GameProperty.Value);
|
||||
}
|
||||
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " IpAddress: {IpAddress}", *IpAddress);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " DnsName: {DnsName}", *DnsName);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " Port: {Port}", Port);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " PlayerSessionCreationPolicy: {PlayerSessionCreationPolicy}", *PlayerSessionCreationPolicy);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " CreatorId: {CreatorId}", *CreatorId);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " GameSessionData: {GameSessionData}", *GameSessionData);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " MatchmakerData: {MatchmakerData}", *MatchmakerData);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " Location: {Location}", *Location);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " ComputeName: {ComputeName}", *ComputeName);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, " PlayerGatewayStatus: {PlayerGatewayStatus}", *PlayerGatewayStatus);
|
||||
|
||||
}
|
||||
|
||||
@@ -4,12 +4,15 @@
|
||||
#include "UI/Portal/PortalManager.h"
|
||||
|
||||
#include "HttpModule.h"
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "Data/API/APIData.h"
|
||||
#include "GameplayTags/DedicatedServerTags.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
|
||||
void UPortalManager::JoinGameSession()
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Searching for Game Session..."));
|
||||
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Searching for Game Session..."), false);
|
||||
|
||||
check(APIData);
|
||||
|
||||
@@ -28,4 +31,42 @@ void UPortalManager::FindOrCreateGameSession_Response(FHttpRequestPtr Request, F
|
||||
bool bWasSuccessful)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Find or Create Game Session Response Received"));
|
||||
|
||||
if (!bWasSuccessful)
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(HTTPStatusMessages::SomethingWentWrong, true);
|
||||
}
|
||||
|
||||
TSharedPtr<FJsonObject> JsonObject;
|
||||
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
|
||||
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
if (ContainsErrors(JsonObject))
|
||||
{
|
||||
BroadcastJoinGameSessionMessage.Broadcast(HTTPStatusMessages::SomethingWentWrong, true);
|
||||
}
|
||||
DumpMetadata(JsonObject);
|
||||
|
||||
if (JsonObject->HasField(TEXT("GameProperties")))
|
||||
{
|
||||
auto PropertiesArray = JsonObject->GetArrayField(TEXT("GameProperties"));
|
||||
TSharedPtr<FJsonObject> FlatMapJson = MakeShareable(new FJsonObject);
|
||||
|
||||
for (auto& PropJson : PropertiesArray)
|
||||
{
|
||||
auto PropObj = PropJson->AsObject();
|
||||
FString Key = PropObj->GetStringField(TEXT("Key"));
|
||||
FString Value = PropObj->GetStringField(TEXT("Value"));
|
||||
FlatMapJson->SetStringField(Key, Value);
|
||||
}
|
||||
// Replace the array with a flat map field
|
||||
JsonObject->SetObjectField(TEXT("GameProperties"), FlatMapJson);
|
||||
}
|
||||
|
||||
|
||||
FDSGameSession GameSession;
|
||||
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &GameSession);
|
||||
GameSession.Dump();
|
||||
BroadcastJoinGameSessionMessage.Broadcast(TEXT("Found Game Session."), false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,14 @@ void USignInOverlay::OnJoinGameButtonClicked()
|
||||
JoinGameWidget->Button_JoinGame->SetIsEnabled(false);
|
||||
}
|
||||
|
||||
void USignInOverlay::UpdateJoinGameStatusMessage(const FString& StatusMessage)
|
||||
void USignInOverlay::UpdateJoinGameStatusMessage(const FString& StatusMessage, const bool bShouldResetJoinGameButton)
|
||||
{
|
||||
check(IsValid(JoinGameWidget));
|
||||
check(IsValid(JoinGameWidget->Button_JoinGame));
|
||||
JoinGameWidget->SetStatusMessage(StatusMessage);
|
||||
|
||||
if (bShouldResetJoinGameButton)
|
||||
{
|
||||
JoinGameWidget->Button_JoinGame->SetIsEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "UI/HTTP/HTTPRequestManager.h"
|
||||
#include "APITestManager.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnListFleetsResponseReceived, const FDSListFleetsResponse&, ListFleetsResponse, bool, bWasSuccessful);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnListFleetsResponseReceived, const FDSListFleetsResponse&, ListFleetsResponse, const bool, bWasSuccessful);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,11 @@
|
||||
|
||||
#include "HTTPRequestTypes.generated.h"
|
||||
|
||||
namespace HTTPStatusMessages
|
||||
{
|
||||
extern DEDICATEDSERVERS_API const FString SomethingWentWrong;
|
||||
}
|
||||
|
||||
USTRUCT()
|
||||
struct FDSMetaData
|
||||
{
|
||||
@@ -33,5 +38,73 @@ struct FDSListFleetsResponse
|
||||
UPROPERTY()
|
||||
FString NextToken;
|
||||
|
||||
void Dump() const;
|
||||
};
|
||||
|
||||
USTRUCT()
|
||||
struct FDSGameSession
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
UPROPERTY()
|
||||
FString GameSessionId{};
|
||||
|
||||
UPROPERTY()
|
||||
FString Name{};
|
||||
|
||||
UPROPERTY()
|
||||
FString FleetArn{};
|
||||
|
||||
UPROPERTY()
|
||||
double CreationTime{};
|
||||
|
||||
UPROPERTY()
|
||||
double TerminationTime{};
|
||||
|
||||
UPROPERTY()
|
||||
int32 CurrentPlayerSessionCount{};
|
||||
|
||||
UPROPERTY()
|
||||
int32 MaximumPlayerSessionCount{};
|
||||
|
||||
UPROPERTY()
|
||||
FString Status{};
|
||||
|
||||
UPROPERTY()
|
||||
FString StatusReason{};
|
||||
|
||||
UPROPERTY()
|
||||
TMap<FString, FString> GameProperties{};
|
||||
|
||||
UPROPERTY()
|
||||
FString IpAddress{};
|
||||
|
||||
UPROPERTY()
|
||||
FString DnsName{};
|
||||
|
||||
UPROPERTY()
|
||||
int32 Port{};
|
||||
|
||||
UPROPERTY()
|
||||
FString PlayerSessionCreationPolicy{};
|
||||
|
||||
UPROPERTY()
|
||||
FString CreatorId{};
|
||||
|
||||
UPROPERTY()
|
||||
FString GameSessionData{};
|
||||
|
||||
UPROPERTY()
|
||||
FString MatchmakerData{};
|
||||
|
||||
UPROPERTY()
|
||||
FString Location{};
|
||||
|
||||
UPROPERTY()
|
||||
FString ComputeName{};
|
||||
|
||||
UPROPERTY()
|
||||
FString PlayerGatewayStatus{};
|
||||
|
||||
void Dump() const;
|
||||
};
|
||||
@@ -7,7 +7,7 @@
|
||||
#include "UI/HTTP/HTTPRequestManager.h"
|
||||
#include "PortalManager.generated.h"
|
||||
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FBroadcastJoinGameSessionMessage, const FString&, StatusMessage);
|
||||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FBroadcastJoinGameSessionMessage, const FString&, StatusMessage, bool, bShouldResetJoinGameButton);
|
||||
|
||||
/**
|
||||
*
|
||||
|
||||
@@ -39,5 +39,5 @@ private:
|
||||
void OnJoinGameButtonClicked();
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateJoinGameStatusMessage(const FString& StatusMessage);
|
||||
void UpdateJoinGameStatusMessage(const FString& StatusMessage, const bool bShouldResetJoinGameButton);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user