138 lines
3.6 KiB
C++
138 lines
3.6 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"
|
|
|
|
|
|
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("There was an error connecting to the server. Please retry.", true);
|
|
break;
|
|
case EHttpRequestStatus::Failed:
|
|
this->CreateError("Connection to the server completed but then failed.", true);
|
|
break;
|
|
case EHttpRequestStatus::NotStarted:
|
|
this->CreateError("Connection was not started.");
|
|
break;
|
|
case EHttpRequestStatus::Processing:
|
|
this->CreateError("Connection is still being processed.");
|
|
break;
|
|
}
|
|
}
|
|
|
|
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, const bool bCancelForm)
|
|
{
|
|
FUnrealzillaErrorData Error;
|
|
Error.ErrorVerb = EErrorVerb::None;
|
|
Error.ErrorMessage = ErrorMessage;
|
|
Error.bCancelForm = bCancelForm;
|
|
this->ErrorResponse.Execute(Error);
|
|
}
|
|
|
|
|
|
const FString UServerAPI::GetGameVersion()
|
|
{
|
|
FString GameVersion;
|
|
GConfig->GetString(TEXT("/Script/EngineSettings.GeneralProjectSettings"), TEXT("ProjectVersion"), GameVersion, GGameIni);
|
|
if (GameVersion.IsEmpty())
|
|
{
|
|
GameVersion = "1.0.0.0";
|
|
}
|
|
return GameVersion;
|
|
}
|
|
|
|
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("&"));
|
|
}
|
|
|
|
const FString UServerAPI::URLBuilder(const FString &Server, const FString &Path)
|
|
{
|
|
FString ServerValidated = Server;
|
|
FString PathValidated = Path;
|
|
|
|
if (!Server.EndsWith("/"))
|
|
{
|
|
ServerValidated += "/";
|
|
}
|
|
|
|
if (!Path.EndsWith("/"))
|
|
{
|
|
PathValidated += "/";
|
|
}
|
|
while (PathValidated.StartsWith("/"))
|
|
{
|
|
PathValidated = PathValidated.RightChop(1);
|
|
}
|
|
|
|
return (ServerValidated + PathValidated);
|
|
}
|