Files
DedicatedServerCourse/Source/DedicatedServers/Private/UI/APITest/APITestManager.cpp
2026-03-30 05:10:02 -04:00

48 lines
1.5 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/APITest/APITestManager.h"
#include "HttpModule.h"
#include "Data/API/APIData.h"
#include "GameplayTags/DedicatedServerTags.h"
#include "Interfaces/IHttpResponse.h"
void UAPITestManager::ListFleetsButtonClicked()
{
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();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "List Fleets Request Made");
}
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, "List Fleets Response Received");
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
{
if (JsonObject->HasField(TEXT("FleetIds")))
{
for (TSharedPtr<FJsonValue> Fleet : JsonObject->GetArrayField(TEXT("FleetIds")))
{
FString FleetString = Fleet->AsString();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FleetString);
}
}
}
}