New Parser Completed. Verification next.
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "ShooterGameModeBase.h"
|
||||
|
||||
#include "ShooterGameMode.generated.h"
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogShooterGameMode, Log, All);
|
||||
@@ -12,47 +11,27 @@ DECLARE_LOG_CATEGORY_EXTERN(LogShooterGameMode, Log, All);
|
||||
struct FProcessParameters;
|
||||
struct FServerParameters;
|
||||
|
||||
struct FGameLiftCliConfig
|
||||
struct FGameLiftConfig
|
||||
{
|
||||
bool bDebugMode = false;
|
||||
bool bIsAnywhereFleet = false;
|
||||
bool bIsCriticalError = false;
|
||||
|
||||
int32 ServerPort = 0;
|
||||
|
||||
int32 ServerPort;
|
||||
|
||||
FString AuthToken;
|
||||
FString FleetId;
|
||||
FString HostId;
|
||||
FString WebSocketUrl;
|
||||
FString ServerRegion;
|
||||
|
||||
};
|
||||
|
||||
namespace GameLiftValidators
|
||||
enum ETokenStatus : uint8
|
||||
{
|
||||
extern const FRegexPattern FleetIdPattern;
|
||||
extern const int32 FleetIdLengthMin;
|
||||
extern const int32 FleetIdLengthMax;
|
||||
extern const FString ServerRegionPattern;
|
||||
extern const int32 ServerRegionLengthMin;
|
||||
extern const int32 ServerRegionLengthMax;
|
||||
extern const FString WebSocketUrlPattern;
|
||||
extern const int32 WebSocketUrlLengthMin;
|
||||
extern const int32 WebSocketUrlLengthMax;
|
||||
extern const FString AuthTokenPattern;
|
||||
extern const int32 AuthTokenLengthMin;
|
||||
extern const int32 AuthTokenLengthMax;
|
||||
extern const FString HostIdPattern;
|
||||
extern const int32 HostIdLengthMin;
|
||||
extern const int32 HostIdLengthMax;
|
||||
extern const int32 ServerPortMin;
|
||||
extern const int32 ServerPortMax;
|
||||
extern const int32 WebSocketPortMin;
|
||||
extern const int32 WebSocketPortMax;
|
||||
|
||||
bool IsStringValid(const FString& Value, const FRegexPattern& OptionalPattern, int32 Min, int32 Max);
|
||||
bool IsNumberValid(int32 Value, int32 Min, int32 Max);
|
||||
}
|
||||
Found,
|
||||
NotFoundRequired,
|
||||
NotFoundNotRequired
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -61,55 +40,21 @@ UCLASS()
|
||||
class FPSTEMPLATE_API AShooterGameMode : public AShooterGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
AShooterGameMode();
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
bool bIsAnywhereFleet = false;
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
FString FleetId;
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
FString AuthToken;
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
FString HostId;
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
FString WebSocketUrl;
|
||||
|
||||
UPROPERTY(Config)
|
||||
FString ServerRegion;
|
||||
|
||||
UPROPERTY(Config, BlueprintReadOnly)
|
||||
int32 ServerPort;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
bool bDebugMode = false;
|
||||
|
||||
virtual void BeginPlay() override;
|
||||
virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
|
||||
void InitGame_original(const FString& MapName, const FString& Options, FString& ErrorMessage);
|
||||
|
||||
private:
|
||||
|
||||
FGameLiftCliConfig GameLiftConfig;
|
||||
|
||||
FString CachedCommandLine;
|
||||
TSharedPtr<FProcessParameters> ProcessParameters;
|
||||
TSharedPtr<FServerParameters> ServerParameters;
|
||||
|
||||
int32 GetConfiguredOrDefaultPort() const;
|
||||
static FString GetSHA256Hash(const FString& Input);
|
||||
|
||||
bool ParseAndOutputResult(const FString& InString, FString& OutValue, bool bRequired = false);
|
||||
bool ParseAndValidate(const FString& InArguments, FGameLiftCliConfig& Config);
|
||||
static bool ValidateFleetId(const FString& InFleetId);
|
||||
|
||||
void InitGameLift();
|
||||
};
|
||||
|
||||
private:
|
||||
FGameLiftConfig GameLiftConfig;
|
||||
FString CachedCommandLine;
|
||||
|
||||
static FString GetSHA256Hash(const FString& CommandLineString);
|
||||
void InitGameLift();
|
||||
|
||||
bool GetAnywhereFleetParameters(FString CommandLineString);
|
||||
void LogAnywhereFleetParameters();
|
||||
};
|
||||
|
||||
23
Source/FPSTemplate/Public/GameLift/GameLiftClp.h
Normal file
23
Source/FPSTemplate/Public/GameLift/GameLiftClp.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
#include "GameLiftClpTypes.h"
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
namespace cmdlineparser
|
||||
{
|
||||
// int32 GetConfiguredOrDefaultPort();
|
||||
int32 GetConfiguredOrDefaultPort(const FString& Token = TEXT("port="));
|
||||
int32 GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token = TEXT("port="));
|
||||
|
||||
details::FParseResult GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token);
|
||||
}
|
||||
|
||||
namespace cmdlineparser::details
|
||||
{
|
||||
inline static constexpr int32 MIN_PORT = 1024;
|
||||
inline static constexpr int32 MAX_PORT = 65535;
|
||||
inline static constexpr const TCHAR* DEFAULT_PORT_TOKEN = TEXT("port=");
|
||||
|
||||
FString EnsureEndsWith(const FString& Token, const TCHAR* Suffix);
|
||||
int32 GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token);
|
||||
}
|
||||
|
||||
93
Source/FPSTemplate/Public/GameLift/GameLiftValidators.h
Normal file
93
Source/FPSTemplate/Public/GameLift/GameLiftValidators.h
Normal file
@@ -0,0 +1,93 @@
|
||||
// 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);
|
||||
|
||||
};
|
||||
24
Source/FPSTemplate/Public/GameLift/GameLiftValidators_old.h
Normal file
24
Source/FPSTemplate/Public/GameLift/GameLiftValidators_old.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
struct FParamResult
|
||||
{
|
||||
FString Value;
|
||||
bool bValid;
|
||||
FString ErrorMessage;
|
||||
};
|
||||
|
||||
namespace GameLiftValidators2
|
||||
{
|
||||
enum class ECliParam
|
||||
{
|
||||
AuthToken, FleetId, HostId, Region, WebSocketUrl, Max
|
||||
};
|
||||
|
||||
|
||||
int32 GetMaxLength(ECliParam ParamType);
|
||||
int32 GetMinLength(ECliParam ParamType);
|
||||
|
||||
bool IsStringValid(const FString& Value, ECliParam ParamType);
|
||||
bool IsNumberValid(int32 Value, int32 Min, int32 Max);
|
||||
}
|
||||
35
Source/FPSTemplate/Public/GameLiftClpTypes.h
Normal file
35
Source/FPSTemplate/Public/GameLiftClpTypes.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
namespace cmdlineparser::details
|
||||
{
|
||||
enum EAvailableTokens
|
||||
{
|
||||
AuthToken,
|
||||
HostId,
|
||||
FleetId,
|
||||
WebsocketUrl,
|
||||
MaxToken
|
||||
};
|
||||
|
||||
enum EErrorCodes
|
||||
{
|
||||
NoError,
|
||||
TokenNotFound,
|
||||
ValueEmpty,
|
||||
FailedValidation,
|
||||
MaxCode
|
||||
};
|
||||
|
||||
extern const TArray<FString>& ERROR_MESSAGES;
|
||||
extern const TArray<FString>& CLI_TOKENS;
|
||||
|
||||
struct FParseResult
|
||||
{
|
||||
EAvailableTokens Token;
|
||||
FString Value;
|
||||
bool bIsValid;
|
||||
EErrorCodes ErrorCode;
|
||||
FString ErrorMessage;
|
||||
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user