Compare commits
2 Commits
30c1e42379
...
e95360489b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e95360489b | ||
|
|
6f3e1d1f86 |
@@ -5,26 +5,21 @@
|
|||||||
#include "HttpModule.h"
|
#include "HttpModule.h"
|
||||||
#include "JsonObjectConverter.h"
|
#include "JsonObjectConverter.h"
|
||||||
#include "Data/API/APIData.h"
|
#include "Data/API/APIData.h"
|
||||||
|
#include "DedicatedServers/DedicatedServers.h"
|
||||||
#include "GameplayTags/DedicatedServersTags.h"
|
#include "GameplayTags/DedicatedServersTags.h"
|
||||||
#include "Interfaces/IHttpResponse.h"
|
#include "Interfaces/IHttpResponse.h"
|
||||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||||
|
|
||||||
void UAPITestManager::ListFleetsButtonClicked()
|
void UAPITestManager::ListFleets()
|
||||||
{
|
{
|
||||||
check(APIData);
|
check(APIData);
|
||||||
|
|
||||||
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
|
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
|
||||||
|
|
||||||
Request->OnProcessRequestComplete().BindUObject(this, &UAPITestManager::ListFleets_Response);
|
Request->OnProcessRequestComplete().BindUObject(this, &UAPITestManager::ListFleets_Response);
|
||||||
|
|
||||||
const FString APIUrl = APIData->GetAPIEndpoint(DedicatedServersTags::GameSessionsAPI::ListFleets);
|
const FString APIUrl = APIData->GetAPIEndpoint(DedicatedServersTags::GameSessionsAPI::ListFleets);
|
||||||
|
|
||||||
Request->SetURL(APIUrl);
|
Request->SetURL(APIUrl);
|
||||||
Request->SetVerb(TEXT("GET"));
|
Request->SetVerb(TEXT("GET"));
|
||||||
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
|
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
|
||||||
Request->ProcessRequest();
|
Request->ProcessRequest();
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "List Fleets Request Made");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||||
@@ -33,18 +28,21 @@ void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponse
|
|||||||
|
|
||||||
TSharedPtr<FJsonObject> JsonObject;
|
TSharedPtr<FJsonObject> JsonObject;
|
||||||
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("$metadata")))
|
const TSharedPtr<FJsonObject>* ErrorObjPtr = nullptr;;
|
||||||
|
|
||||||
|
if (ContainsErrors(JsonObject, false))
|
||||||
{
|
{
|
||||||
TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
|
OnListFleetsResponseReceived.Broadcast(FDS_ListFleetsResponse(), false);
|
||||||
FDS_MetaData DSMetaData;
|
return;
|
||||||
FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
|
|
||||||
DSMetaData.Dump();
|
|
||||||
}
|
}
|
||||||
|
DumpMetaData(JsonObject);
|
||||||
|
|
||||||
FDS_ListFleetsResponse ListFleetsResponse;
|
FDS_ListFleetsResponse ListFleetsResponse;
|
||||||
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
|
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
|
||||||
ListFleetsResponse.Dump();
|
ListFleetsResponse.Dump();
|
||||||
|
OnListFleetsResponseReceived.Broadcast(ListFleetsResponse, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,5 +17,27 @@ void UAPITestOverlay::NativeConstruct()
|
|||||||
|
|
||||||
check (ListFleetsBox)
|
check (ListFleetsBox)
|
||||||
check (ListFleetsBox->Button_ListFleets)
|
check (ListFleetsBox->Button_ListFleets)
|
||||||
ListFleetsBox->Button_ListFleets->OnClicked.AddDynamic(APITestManager, &UAPITestManager::ListFleetsButtonClicked);
|
ListFleetsBox->Button_ListFleets->OnClicked.AddDynamic(this, &UAPITestOverlay::ListFleetsButtonClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAPITestOverlay::ListFleetsButtonClicked()
|
||||||
|
{
|
||||||
|
check(APITestManager);
|
||||||
|
APITestManager->OnListFleetsResponseReceived.AddDynamic(this, &UAPITestOverlay::OnListFleetsResponseReceived);
|
||||||
|
APITestManager->ListFleets();
|
||||||
|
|
||||||
|
ListFleetsBox->Button_ListFleets->SetIsEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAPITestOverlay::OnListFleetsResponseReceived(const FDS_ListFleetsResponse& ListFleetResponse, bool bWasSuccessful)
|
||||||
|
{
|
||||||
|
if (bWasSuccessful)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
ListFleetsBox->Button_ListFleets->SetIsEnabled(true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,3 +2,44 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "UI/HTTP/HTTPRequestManager.h"
|
#include "UI/HTTP/HTTPRequestManager.h"
|
||||||
|
|
||||||
|
#include "HTTPRequestTypes.h"
|
||||||
|
#include "JsonObjectConverter.h"
|
||||||
|
#include "DedicatedServers/DedicatedServers.h"
|
||||||
|
|
||||||
|
bool UHTTPRequestManager::ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bSuppressLog)
|
||||||
|
{
|
||||||
|
if (JsonObject->HasField(TEXT("errorType")) || JsonObject->HasField(TEXT("errorMessage")))
|
||||||
|
{
|
||||||
|
if (!bSuppressLog)
|
||||||
|
{
|
||||||
|
FString ErrorType = JsonObject->HasField(TEXT("errorType")) ? JsonObject->GetStringField(TEXT("errorType")) : TEXT("Unknown Error");
|
||||||
|
FString ErrorMessage = JsonObject->HasField(TEXT("errorMessage")) ? JsonObject->GetStringField(TEXT("errorMessage")) : TEXT("Unknown Error Message");
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Type: {ErrorType}", ErrorType);
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Message: {ErrorMessage}", ErrorMessage);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (JsonObject->HasField(TEXT("$fault")))
|
||||||
|
{
|
||||||
|
if (!bSuppressLog)
|
||||||
|
{
|
||||||
|
FString ErrorType = JsonObject->HasField(TEXT("name")) ? JsonObject->GetStringField(TEXT("name")) : TEXT("Unknown Error");
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Type: {ErrorType}", ErrorType);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UHTTPRequestManager::DumpMetaData(TSharedPtr<FJsonObject> JsonObject)
|
||||||
|
{
|
||||||
|
if (JsonObject->HasField(TEXT("$metadata")))
|
||||||
|
{
|
||||||
|
TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
|
||||||
|
FDS_MetaData DSMetaData;
|
||||||
|
FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
|
||||||
|
DSMetaData.Dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
#include "UI/HTTP/HTTPRequestManager.h"
|
#include "UI/HTTP/HTTPRequestManager.h"
|
||||||
#include "APITestManager.generated.h"
|
#include "APITestManager.generated.h"
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnListFleetsResponseReceived, const FDS_ListFleetsResponse&, ListFleetResponse, bool, bWasSuccessful);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -18,7 +20,10 @@ class DEDICATEDSERVERS_API UAPITestManager : public UHTTPRequestManager
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void ListFleetsButtonClicked();
|
void ListFleets();
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
FOnListFleetsResponseReceived OnListFleetsResponseReceived;
|
||||||
|
|
||||||
void ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
void ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
class UAPITestManager;
|
class UAPITestManager;
|
||||||
class UListFleetsBox;
|
class UListFleetsBox;
|
||||||
|
class FDS_ListFleetsResponse;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -32,6 +33,11 @@ private:
|
|||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<UAPITestManager> APITestManager;
|
TObjectPtr<UAPITestManager> APITestManager;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ListFleetsButtonClicked();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnListFleetsResponseReceived(const FDS_ListFleetsResponse& ListFleetResponse, bool bWasSuccessful);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "HTTPRequestManager.generated.h"
|
#include "HTTPRequestManager.generated.h"
|
||||||
|
|
||||||
class UAPIData;
|
class UAPIData;
|
||||||
|
class FJsonObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -21,5 +22,7 @@ protected:
|
|||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
TObjectPtr<UAPIData> APIData;
|
TObjectPtr<UAPIData> APIData;
|
||||||
|
|
||||||
|
bool ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bSuppressLog = true);
|
||||||
|
void DumpMetaData(TSharedPtr<FJsonObject> JsonObject);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user