Lesson 55 working properly now

This commit is contained in:
Norman Lansing
2026-03-26 21:07:11 -04:00
parent 241b78fa4a
commit f093212884
28 changed files with 65618 additions and 529 deletions

View File

@@ -0,0 +1,55 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
struct FServerParameters;
struct FProcessParameters;
#include "CoreMinimal.h"
#include "GameFramework/GameMode.h"
#include "Game/GameLift/GameLiftClpTypes.h"
#include "DS_GameMode.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(LogDS_GameMode, Log, All);
struct FGameLiftConfig
{
bool bIsAnywhereFleet = false;
bool bAllOptionsFound = false;
int32 ServerPort = 7777;
cmdlineparser::details::FParseResult AuthTokenResult;
cmdlineparser::details::FParseResult FleetIdResult;
cmdlineparser::details::FParseResult HostIdResult;
cmdlineparser::details::FParseResult WebSocketUrlResult;
};
UCLASS()
class DEDICATEDSERVERS_API ADS_GameMode : public AGameMode
{
GENERATED_BODY()
public:
protected:
virtual void BeginPlay() override;
virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
private:
FGameLiftConfig GameLiftConfig;
FString CachedCommandLine;
static FString GetSHA256Hash(const FString& InString);
void InitGameLift();
bool GetAnywhereFleetParameters(const FString& CommandLineString);
void LogAnywhereFleetParameters();
TSharedPtr<FProcessParameters> ProcessParameters;
static void LogServerParameters(const FServerParameters& InServerParameters);
static FString GetValueOrHash(const FString& Value);
};

View File

@@ -0,0 +1,79 @@
#pragma once
namespace cmdlineparser::details
{
enum EAvailableTokens
{
Unknown = 0,
AuthToken,
HostId,
FleetId,
WebsocketUrl,
MaxToken
};
enum EErrorCodes
{
NoError,
TokenNotFound,
ValueEmpty,
FailedValidation,
MaxCode
};
inline static const TMap<EErrorCodes, FString>& ERROR_MESSAGES = []() ->
const TMap<EErrorCodes, FString>&
{
static TMap<EErrorCodes, FString> Error_Messages =
{
{NoError,TEXT("VALID: {0}: {1}") },
{FailedValidation,TEXT("VALIDATION FAILED: [-{0}=] found.... Value: [{1}]") },
{TokenNotFound,TEXT("INVALID TOKEN: [-{0}=] not found in command line arguments") },
{ValueEmpty,TEXT("EMPTY VALUE: [-{0}=] found. No value assigned") },
};
return Error_Messages;
}();
inline static const TMap<EAvailableTokens, FString>& CLI_TOKENS = []() ->
const TMap<EAvailableTokens, FString>&
{
static TMap<EAvailableTokens, FString> Cli_Tokens =
{
{AuthToken, TEXT("authtoken") },
{FleetId, TEXT("fleetid") },
{HostId, TEXT("hostid") },
{Unknown, TEXT("unknown") },
{WebsocketUrl, TEXT("websocketurl") }
};
return Cli_Tokens;
}();
inline static const TMap<EAvailableTokens, FString>& REGEX_PATTERNS = []() ->
const TMap<EAvailableTokens, FString>&
{
static TMap<EAvailableTokens, FString> Regex_Patterns =
{
{Unknown,TEXT(".*") },
{AuthToken,TEXT("^[a-zA-Z0-9\\-]+$") },
{HostId,TEXT("^[a-zA-Z0-9][a-zA-Z0-9\\-]{0,62}[a-zA-Z0-9]?$") },
{FleetId,TEXT("^[a-z]*fleet-[a-zA-Z0-9\\-]+$|^arn:.*:[a-z]*fleet\\/[a-z]*fleet-[a-zA-Z0-9\\-]+$") },
{WebsocketUrl,TEXT("^wss://[a-z0-9-]+(\\.[a-z0-9-]+)*\\.api\\.amazongamelift\\.com(:[0-9]+)?/?$") },
};
return Regex_Patterns;
}();
// extern const TMap<EErrorCodes, FString>& ERROR_MESSAGES;
// extern const TMap<EAvailableTokens, FString>& CLI_TOKENS;
// extern const TMap<EAvailableTokens, FString>& REGEX_PATTERNS;
struct FParseResult
{
EAvailableTokens Token = EAvailableTokens::Unknown;
FString Value = FString();
bool bIsValid = false;
EErrorCodes ErrorCode = EErrorCodes::TokenNotFound;
FString ErrorMessage = FString();
};
}