Added in namespace GameLiftValidators and methods

This commit is contained in:
Norman Lansing
2026-03-05 10:00:22 -05:00
parent ade2a38d7c
commit 99b168b6b5
2 changed files with 161 additions and 5 deletions

View File

@@ -3,6 +3,7 @@
#include "Game/ShooterGameMode.h"
#include "Logging/LogMacros.h"
#include "Logging/StructuredLog.h"
#if WITH_GAMELIFT
#include "GameLiftServerSDK.h"
@@ -10,6 +11,49 @@
DEFINE_LOG_CATEGORY(LogShooterGameMode)
namespace GameLiftValidators {
const FRegexPattern FleetIdPattern(TEXT("^[a-z]*fleet-[a-zA-Z0-9\\-]+$"));
const int32 FleetIdLengthMin = 1;
const int32 FleetIdLengthMax = 128;
const FString ServerRegionPattern(TEXT("^[a-z]{2}-[a-z]+-[0-9]$"));
const int32 ServerRegionLengthMin = 3;
const int32 ServerRegionLengthMax = 16;
const FString WebSocketUrlPattern(TEXT("^(ws|wss):\\/\\/([0-9a-zA-Z.-]+)(:([1-9][0-9]{0,4}))?(\\/.*)?$"));
const int32 WebSocketUrlLengthMin = 1;
const int32 WebSocketUrlLengthMax = 128;
const FString AuthTokenPattern(TEXT("^[A-Za-z0-9+/=]+$"));
const int32 AuthTokenLengthMin = 20;
const int32 AuthTokenLengthMax = 2048;
const FString HostIdPattern(TEXT("^[a-z]*host-[a-zA-Z0-9\\-]+$"));
const int32 HostIdLengthMin = 1;
const int32 HostIdLengthMax = 128;
const int32 ServerPortMin = 1026;
const int32 ServerPortMax = 60000;
const int32 WebSocketPortMin = 1;
const int32 WebSocketPortMax = 60000;
bool ValidateString(const FString& Value, const FRegexPattern* OptionalPattern, const int32 Min, const int32 Max)
{
if (Value.IsEmpty()) return false;
if (OptionalPattern)
{
return FRegexMatcher(*OptionalPattern, Value).FindNext() &&
Value.Len() >= Min &&
Value.Len() <= Max;
}
else
{
return Value.Len() >= Min && Value.Len() <= Max;
}
}
bool ValidateNumber(const int32 Value, const int32 Min, const int32 Max)
{
return Value >= Min && Value <= Max;
}
}
AShooterGameMode::AShooterGameMode()
{
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing ShooterGameMode..."));
@@ -27,12 +71,46 @@ void AShooterGameMode::BeginPlay()
void AShooterGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
Super::InitGame(MapName, Options, ErrorMessage);
UE_LOG(LogShooterGameMode, Log, TEXT("[%s] Parsing CLI"), *FDateTime::UtcNow().ToString(TEXT("%Y%m%d-%H%M%S")));
CachedCommandLine = FCommandLine::Get();
bool bIsCriticalError = false;
// Parsing of Command Line
bDebugMode = FParse::Param(*CachedCommandLine, TEXT("Debug"));
GameLiftConfig.bDebugMode = FParse::Param(*CachedCommandLine, TEXT("Debug"));
if (GameLiftConfig.bDebugMode)
{
UE_LOG(LogShooterGameMode, Log, TEXT("Debug mode: ENABLED"));
#if UE_BUILD_DEBUG
UE_LOG(LogShooterGameMode, Log, TEXT("Command Line Arguments: %s"), *CachedCommandLine);
#endif
}
GameLiftConfig.ServerPort = GetConfiguredOrDefaultPort();
GameLiftConfig.bIsAnywhereFleet = FParse::Param(*CachedCommandLine, TEXT("glAnywhere"));
if (GameLiftConfig.bIsAnywhereFleet)
{
UE_LOGFMT(LogShooterGameMode, Log, "GameLift Anywhere Fleet Command Line Parsing");
UE_LOGFMT(LogShooterGameMode, Log, "======Command Line Parameters======");
UE_LOGFMT(LogShooterGameMode, Log, "===================================");
}
else
{
}
}
void AShooterGameMode::InitGame_original(const FString& MapName, const FString& Options, FString& ErrorMessage)
{
Super::InitGame(MapName, Options, ErrorMessage);
UE_LOG(LogShooterGameMode, Log, TEXT("[%s] Parsing CLI"), *FDateTime::UtcNow().ToString(TEXT("%Y%m%d-%H%M%S")));
CachedCommandLine = FCommandLine::Get();
bool bIsCriticalError = false;
if (bDebugMode)
{
@@ -207,8 +285,37 @@ FString AShooterGameMode::GetSHA256Hash(const FString& Input)
return FString::Printf(TEXT("Fail_%dbytes"), Input.Len());
}
void AShooterGameMode::InitGameLift()
bool AShooterGameMode::ParseAndOutputResult(const FString& InString, FString& OutValue, bool bRequired)
{
//TODO: Need to write later, working on parser first.
// Returns True if it is a critical error, returns false
if (!FParse::Value(*InString, TEXT("hostId="), HostId))
{
UE_LOG(LogShooterGameMode, Error, TEXT("HostId Missing in Command Line"));
return bRequired;
}
else
{
UE_LOG(LogShooterGameMode, Log, TEXT("Host ID: %s"), *HostId);
return false;
}
}
bool AShooterGameMode::ValidateFleetId(const FString& InFleetId)
{
// FRegexMatcher Matcher(FleetIdPattern, InFleetId);
// return Matcher.IsMatch() &&
// InFleetId.Len() >= 10 &&
// InFleetId.Len() < 128;
return false;
}
void AShooterGameMode::InitGameLift()
{
#if WITH_GAMELIFT
//TODO: Need to write later, working on parser first.
#else
UE_LOGFMT(LogShooterGameMode, Warning, "GameLift disabled");
#endif
}