Lesson 62 - Parsing the MetaData
This commit is contained in:
@@ -4,3 +4,5 @@
|
|||||||
#include "Modules/ModuleManager.h"
|
#include "Modules/ModuleManager.h"
|
||||||
|
|
||||||
IMPLEMENT_MODULE( FDefaultModuleImpl, DedicateServers );
|
IMPLEMENT_MODULE( FDefaultModuleImpl, DedicateServers );
|
||||||
|
|
||||||
|
DEFINE_LOG_CATEGORY(LogDedicatedServers);
|
||||||
|
|||||||
@@ -3,3 +3,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
|
DECLARE_LOG_CATEGORY_EXTERN(LogDedicatedServers, Log, All)
|
||||||
@@ -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();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal 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);
|
||||||
|
}
|
||||||
27
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal file
27
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal 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;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user