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

49 lines
1.5 KiB
C++
Raw Normal View History

2026-03-29 07:54:19 -04:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/APITest/APITestManager.h"
2026-03-29 20:20:59 -04:00
#include "HttpModule.h"
2026-03-30 06:57:00 -04:00
#include "JsonObjectConverter.h"
2026-03-29 20:20:59 -04:00
#include "Data/API/APIData.h"
#include "GameplayTags/DedicatedServerTags.h"
2026-03-30 05:10:02 -04:00
#include "Interfaces/IHttpResponse.h"
2026-03-30 06:57:00 -04:00
#include "UI/HTTP/HTTPRequestTypes.h"
2026-03-30 05:10:02 -04:00
2026-03-29 07:54:19 -04:00
2026-03-30 17:30:24 -04:00
void UAPITestManager::ListFleets()
2026-03-29 07:54:19 -04:00
{
2026-03-29 20:20:59 -04:00
check(APIData);
TSharedPtr<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("GET");
Request->SetHeader("Content-Type", "application/json");
Request->ProcessRequest();
}
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
2026-03-30 05:10:02 -04:00
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
{
2026-03-30 17:30:24 -04:00
if (ContainsErrors(JsonObject))
2026-03-30 08:02:56 -04:00
{
2026-03-30 17:30:24 -04:00
OnListFleetsResponseReceived.Broadcast(FDSListFleetsResponse(), false);
2026-03-30 08:02:56 -04:00
return;
}
2026-03-30 17:30:24 -04:00
DumpMetadata(JsonObject);
2026-03-30 07:18:27 -04:00
FDSListFleetsResponse ListFleetsResponse;
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
2026-03-30 17:30:24 -04:00
OnListFleetsResponseReceived.Broadcast(ListFleetsResponse, true);
2026-03-30 07:18:27 -04:00
ListFleetsResponse.Dump();
}
2026-03-29 07:54:19 -04:00
}