Files
DedicatedServerCourse/Source/DedicatedServers/Private/UI/API_Test/APITestManager.cpp

49 lines
1.7 KiB
C++
Raw Normal View History

2026-03-15 17:02:22 -04:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/API_Test/APITestManager.h"
2026-03-15 21:46:18 -04:00
#include "HttpModule.h"
2026-03-16 06:30:18 -04:00
#include "JsonObjectConverter.h"
2026-03-15 21:46:18 -04:00
#include "Data/API/APIData.h"
2026-03-16 18:12:29 -04:00
#include "DedicatedServers/DedicatedServers.h"
2026-03-15 21:46:18 -04:00
#include "GameplayTags/DedicatedServersTags.h"
2026-03-15 22:09:50 -04:00
#include "Interfaces/IHttpResponse.h"
2026-03-16 06:30:18 -04:00
#include "UI/HTTP/HTTPRequestTypes.h"
2026-03-15 17:02:22 -04:00
2026-03-16 22:30:26 -04:00
void UAPITestManager::ListFleets()
2026-03-15 17:02:22 -04:00
{
2026-03-15 21:46:18 -04:00
check(APIData);
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &UAPITestManager::ListFleets_Response);
const FString APIUrl = APIData->GetAPIEndpoint(DedicatedServersTags::GameSessionsAPI::ListFleets);
Request->SetURL(APIUrl);
Request->SetVerb(TEXT("GET"));
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
Request->ProcessRequest();
}
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "List Fleets Response Received");
2026-03-15 22:09:50 -04:00
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
2026-03-16 18:12:29 -04:00
2026-03-15 22:09:50 -04:00
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
{
2026-03-16 18:12:29 -04:00
const TSharedPtr<FJsonObject>* ErrorObjPtr = nullptr;;
2026-03-16 22:30:26 -04:00
if (ContainsErrors(JsonObject, false))
2026-03-16 18:12:29 -04:00
{
2026-03-16 22:30:26 -04:00
OnListFleetsResponseReceived.Broadcast(FDS_ListFleetsResponse(), false);
2026-03-16 18:12:29 -04:00
return;
}
2026-03-16 22:30:26 -04:00
DumpMetaData(JsonObject);
2026-03-16 06:46:34 -04:00
FDS_ListFleetsResponse ListFleetsResponse;
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
ListFleetsResponse.Dump();
2026-03-16 22:30:26 -04:00
OnListFleetsResponseReceived.Broadcast(ListFleetsResponse, true);
2026-03-15 22:09:50 -04:00
}
2026-03-15 17:02:22 -04:00
}