94 lines
2.2 KiB
C
94 lines
2.2 KiB
C
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|||
|
|
|
|||
|
|
#pragma once
|
|||
|
|
|
|||
|
|
#include "CoreMinimal.h"
|
|||
|
|
#include "Kismet/BlueprintFunctionLibrary.h"
|
|||
|
|
#include "GameLiftValidators.generated.h"
|
|||
|
|
|
|||
|
|
UENUM(BlueprintType)
|
|||
|
|
enum class EGameLiftParams : uint8
|
|||
|
|
{
|
|||
|
|
AuthToken,
|
|||
|
|
FleetId,
|
|||
|
|
HostId,
|
|||
|
|
ServerRegion,
|
|||
|
|
WebSocketUrl,
|
|||
|
|
Max // Sentry to determine length of EGameLiftParams
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
UENUM(BlueprintType)
|
|||
|
|
enum class EValidationError : uint8
|
|||
|
|
{
|
|||
|
|
None, // Valid
|
|||
|
|
Empty, // Missing Parameter
|
|||
|
|
TooShort, // Too Short
|
|||
|
|
TooLong, // Too long
|
|||
|
|
InvalidFormat, // Invalid format
|
|||
|
|
NotFound // Sentinel value, any new error codes get put above this.
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
USTRUCT(BlueprintType)
|
|||
|
|
struct FParamResult
|
|||
|
|
{
|
|||
|
|
GENERATED_BODY()
|
|||
|
|
|
|||
|
|
EGameLiftParams ParamType;
|
|||
|
|
FString Value;
|
|||
|
|
bool bValid;
|
|||
|
|
FString ErrorMessage;
|
|||
|
|
EValidationError ErrorCode;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
|
|||
|
|
UCLASS()
|
|||
|
|
class FPSTEMPLATE_API UGameLiftValidators : public UBlueprintFunctionLibrary
|
|||
|
|
{
|
|||
|
|
GENERATED_BODY()
|
|||
|
|
|
|||
|
|
private:
|
|||
|
|
static TArray<FString>& GetPatterns();
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
static constexpr int32 MaxLengths[static_cast<int32>(EGameLiftParams::Max)] =
|
|||
|
|
{
|
|||
|
|
64, //authToken
|
|||
|
|
512, //FleetId
|
|||
|
|
128, //HostId
|
|||
|
|
128, //WebSocketUrl
|
|||
|
|
16, //Region (ca-central-1)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
static constexpr int32 MinLengths[static_cast<int32>(EGameLiftParams::Max)] =
|
|||
|
|
{
|
|||
|
|
1, //authToken
|
|||
|
|
1, //FleetId
|
|||
|
|
1, //HostId
|
|||
|
|
1, //WebSocketUrl
|
|||
|
|
3, //Region (ca-central-1)
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
static bool IsStringValid(const FString& Value, EGameLiftParams ParamType);
|
|||
|
|
static bool IsStringShort(const FString& Value, EGameLiftParams ParamType);
|
|||
|
|
static bool IsStringLong(const FString& Value, EGameLiftParams ParamType);
|
|||
|
|
static bool IsMatchesRegex(const FString& Value, EGameLiftParams ParamType);
|
|||
|
|
|
|||
|
|
public:
|
|||
|
|
|
|||
|
|
|
|||
|
|
UFUNCTION(BlueprintCallable, Category = "GameLift")
|
|||
|
|
static FParamResult ValidateParam(const FString& Value, EGameLiftParams ParamType);
|
|||
|
|
|
|||
|
|
|
|||
|
|
UFUNCTION(BlueprintCallable, Category = "GameLift")
|
|||
|
|
static FString GetParameterFromEnum(EGameLiftParams InParam);
|
|||
|
|
|
|||
|
|
UFUNCTION(BlueprintCallable, Category = "GameLift")
|
|||
|
|
static FString GetErrorFromEnum(EValidationError InParam);
|
|||
|
|
|
|||
|
|
UFUNCTION(BlueprintCallable, Category = "GameLift")
|
|||
|
|
static void LogValidationErrorMessage(FParamResult ValidationResult);
|
|||
|
|
|
|||
|
|
};
|