Lesson 62 - Parsing the MetaData

This commit is contained in:
Norman Lansing
2026-03-16 06:30:18 -04:00
parent 8d6f3f68f1
commit 7f154aa6f9
5 changed files with 49 additions and 6 deletions

View File

@@ -4,3 +4,5 @@
#include "Modules/ModuleManager.h" #include "Modules/ModuleManager.h"
IMPLEMENT_MODULE( FDefaultModuleImpl, DedicateServers ); IMPLEMENT_MODULE( FDefaultModuleImpl, DedicateServers );
DEFINE_LOG_CATEGORY(LogDedicatedServers);

View File

@@ -3,3 +3,5 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
DECLARE_LOG_CATEGORY_EXTERN(LogDedicatedServers, Log, All)

View File

@@ -3,9 +3,11 @@
#include "UI/API_Test/APITestManager.h" #include "UI/API_Test/APITestManager.h"
#include "HttpModule.h" #include "HttpModule.h"
#include "JsonObjectConverter.h"
#include "Data/API/APIData.h" #include "Data/API/APIData.h"
#include "GameplayTags/DedicatedServersTags.h" #include "GameplayTags/DedicatedServersTags.h"
#include "Interfaces/IHttpResponse.h" #include "Interfaces/IHttpResponse.h"
#include "UI/HTTP/HTTPRequestTypes.h"
void UAPITestManager::ListFleetsButtonClicked() void UAPITestManager::ListFleetsButtonClicked()
{ {
@@ -33,13 +35,12 @@ void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponse
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString()); TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(JsonReader, JsonObject)) if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
{ {
if (JsonObject->HasField(TEXT("FleetIds"))) if (JsonObject->HasField(TEXT("$metadata")))
{ {
for (TSharedPtr<FJsonValue> Fleet :JsonObject->GetArrayField(TEXT("FleetIds"))) TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
{ FDS_MetaData DSMetaData;
FString FleetString = Fleet->AsString(); FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FleetString); DSMetaData.Dump();
}
} }
} }
} }

View File

@@ -0,0 +1,11 @@
#include "UI/HTTP/HTTPRequestTypes.h"
#include "DedicatedServers/DedicatedServers.h"
void FDS_MetaData::Dump() const
{
UE_LOGFMT(LogDedicatedServers, Log, "MetaData:");
UE_LOGFMT(LogDedicatedServers, Log, "httpStatusCode: {httpStatusCode}", httpStatusCode);
UE_LOGFMT(LogDedicatedServers, Log, "requestId: {requestId}", requestId);
UE_LOGFMT(LogDedicatedServers, Log, "attemps: {attempts}", attempts);
UE_LOGFMT(LogDedicatedServers, Log, "totalRetryDelay: {totalRetryDelay}", totalRetryDelay);
}

View File

@@ -0,0 +1,27 @@
#pragma once
// Because this is in the private section is is still usable by the DedicatedServer Module, but not outside of the module.
#include "HTTPRequestTypes.generated.h"
USTRUCT()
struct FDS_MetaData
{
GENERATED_BODY()
public:
UPROPERTY()
int32 httpStatusCode{};
UPROPERTY()
FString requestId{};
UPROPERTY()
int32 attempts{};
UPROPERTY()
double totalRetryDelay{};
void Dump() const;
};