Files
DedicatedServerCourse/Source/FPSTemplate/Public/Game/ShooterGameMode.h
2026-03-05 10:00:22 -05:00

116 lines
2.9 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "ShooterGameModeBase.h"
#include "ShooterGameMode.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogShooterGameMode, Log, All);
struct FProcessParameters;
struct FServerParameters;
struct FGameLiftCliConfig
{
bool bDebugMode = false;
bool bIsAnywhereFleet = false;
bool bIsCriticalError = false;
int32 ServerPort = 0;
FString AuthToken;
FString FleetId;
FString HostId;
FString WebSocketUrl;
FString ServerRegion;
};
namespace GameLiftValidators
{
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 ValidateString(const FString& Value, const FRegexPattern& OptionalPattern, int32 Min, int32 Max);
bool ValidateNumber(int32 Value, int32 Min, int32 Max);
}
/**
*
*/
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();
};