2023-04-01 00:04:24 -04:00

119 lines
3.3 KiB
C++

// ©2022 Batty Bovine Productions, LLC. All Rights Reserved.
#include "ServerAPI.h"
#include "HttpModule.h"
#include "JsonObjectConverter.h"
#include "UnrealzillaGlobalSettings.h"
#include "Kismet/GameplayStatics.h"
const FString GetGameVersion()
{
FString GameVersion;
GConfig->GetString(TEXT("/Script/EngineSettings.GeneralProjectSettings"), TEXT("ProjectVersion"), GameVersion, GGameIni);
if (GameVersion.IsEmpty())
{
GameVersion = "1.0.0.0";
}
return GameVersion;
}
void UServerAPI::ReturnListOfBugs()
{
this->BugDataResponse.Execute(TArray<FUnrealzillaBugData>());
}
void UServerAPI::PrepareForm()
{
this->FormDataResponse.Execute(FUnrealzillaFormPrepData());
}
void UServerAPI::SendFormData(const FUnrealzillaPostData &PostData)
{
this->BugDataResponse.Execute(TArray<FUnrealzillaBugData>());
}
void UServerAPI::ServerConnectionError(const EHttpRequestStatus::Type Status)
{
switch (Status) {
case EHttpRequestStatus::Failed_ConnectionError:
this->CreateError("Unable to connect to the server");
//this->ShowProcessingOverlayMessage("Unable to connect to the server", true);
break;
case EHttpRequestStatus::NotStarted:
this->CreateError("Connection could not start");
//this->ShowProcessingOverlayMessage("Connection could not start", true);
break;
case EHttpRequestStatus::Failed:
this->CreateError("Connection failed");
//this->ShowProcessingOverlayMessage("Connection failed", true);
break;
default:
this->CreateError("Request failed for unknown reasons");
//this->ShowProcessingOverlayMessage("Request failed for unknown reasons", true);
}
}
void UServerAPI::CreateError(const EErrorVerb &Verb, const FBugzillaJSONPostResponse &Data)
{
FUnrealzillaErrorData Error;
Error.ErrorVerb = Verb;
Error.ErrorCode = Data.code;
Error.ErrorMessage = Data.message;
Error.DocumentationLink = Data.documentation;
this->ErrorResponse.Execute(Error);
}
void UServerAPI::CreateError(const EErrorVerb &Verb, const FBugzillaJSONProductResponse &Data)
{
FUnrealzillaErrorData Error;
Error.ErrorVerb = Verb;
Error.ErrorCode = Data.code;
Error.ErrorMessage = Data.message;
Error.DocumentationLink = Data.documentation;
this->ErrorResponse.Execute(Error);
}
void UServerAPI::CreateError(const EErrorVerb &Verb, const FBugzillaJSONFieldResponse &Data)
{
FUnrealzillaErrorData Error;
Error.ErrorVerb = Verb;
Error.ErrorCode = Data.code;
Error.ErrorMessage = Data.message;
Error.DocumentationLink = Data.documentation;
this->ErrorResponse.Execute(Error);
}
void UServerAPI::CreateError(const EErrorVerb &Verb, const FBugzillaJSONBugResponse &Data)
{
FUnrealzillaErrorData Error;
Error.ErrorVerb = Verb;
Error.ErrorCode = Data.code;
Error.ErrorMessage = Data.message;
Error.DocumentationLink = Data.documentation;
this->ErrorResponse.Execute(Error);
}
void UServerAPI::CreateError(const FString &ErrorMessage)
{
FUnrealzillaErrorData Error;
Error.ErrorVerb = EErrorVerb::None;
Error.ErrorMessage = ErrorMessage;
this->ErrorResponse.Execute(Error);
}
const FString UServerAPI::FormatQueryString(const TMap<FString, FString> &QueryData)
{
TArray<FString> AssembledKeyValuePairs;
TArray<FString> QueryKeys;
QueryData.GenerateKeyArray(QueryKeys);
for (const FString &QueryKey : QueryKeys)
{
AssembledKeyValuePairs.Add(QueryKey + "=" + QueryData[QueryKey]);
}
return FString::Join(AssembledKeyValuePairs, TEXT("&"));
}