2026-02-24 22:39:26 -05:00
|
|
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
|
|
|
|
|
|
#include "Game/ShooterGameMode.h"
|
2026-03-11 07:40:45 -04:00
|
|
|
|
#include "GenericPlatform/GenericPlatformMisc.h"
|
|
|
|
|
|
#include "Containers/UnrealString.h"
|
2026-03-10 22:38:12 -04:00
|
|
|
|
#include "GameLiftClpTypes.h"
|
|
|
|
|
|
#include "GameLift/GameLiftClp.h"
|
2026-03-11 07:40:45 -04:00
|
|
|
|
#include "openssl/sha.h"
|
|
|
|
|
|
|
2026-02-24 22:39:26 -05:00
|
|
|
|
|
|
|
|
|
|
|
2026-03-10 22:38:12 -04:00
|
|
|
|
DEFINE_LOG_CATEGORY(LogShooterGameMode);
|
|
|
|
|
|
|
|
|
|
|
|
// Function implementations.
|
2026-03-05 10:00:22 -05:00
|
|
|
|
|
2026-02-24 22:39:26 -05:00
|
|
|
|
AShooterGameMode::AShooterGameMode()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AShooterGameMode::BeginPlay()
|
|
|
|
|
|
{
|
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
|
#if WITH_GAMELIFT
|
2026-03-04 09:54:18 -05:00
|
|
|
|
InitGameLift();
|
2026-02-24 22:39:26 -05:00
|
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-04 06:40:59 -05:00
|
|
|
|
void AShooterGameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
|
2026-02-24 22:39:26 -05:00
|
|
|
|
{
|
2026-03-04 06:40:59 -05:00
|
|
|
|
Super::InitGame(MapName, Options, ErrorMessage);
|
|
|
|
|
|
CachedCommandLine = FCommandLine::Get();
|
2026-03-12 07:13:47 -04:00
|
|
|
|
GameLiftConfig.ServerPort = cmdlineparser::details::GetConfiguredOrDefaultPort(CachedCommandLine, TEXT("port"));
|
|
|
|
|
|
if (FParse::Param(*CachedCommandLine, TEXT("glAnywhereFleet")))
|
2026-03-05 10:00:22 -05:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "Fleet type: Anywhere");
|
|
|
|
|
|
GameLiftConfig.bAllOptionsFound = GetAnywhereFleetParameters(CachedCommandLine);
|
|
|
|
|
|
LogAnywhereFleetParameters();
|
2026-03-05 10:00:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "Fleet type: EC2");
|
|
|
|
|
|
// TODO: EC2 configuration
|
2026-02-24 22:39:26 -05:00
|
|
|
|
}
|
2026-03-10 22:38:12 -04:00
|
|
|
|
}
|
2026-03-04 09:54:18 -05:00
|
|
|
|
|
2026-03-10 22:38:12 -04:00
|
|
|
|
FString AShooterGameMode::GetSHA256Hash(const FString& InString)
|
|
|
|
|
|
{
|
2026-03-11 07:40:45 -04:00
|
|
|
|
|
|
|
|
|
|
if (InString.IsEmpty())
|
|
|
|
|
|
return TEXT("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
|
|
|
|
|
|
|
|
|
|
|
FSHA256Signature Hash;
|
|
|
|
|
|
|
|
|
|
|
|
// Use OpenSSL to compute the SHA-256 hash
|
|
|
|
|
|
|
|
|
|
|
|
FTCHARToUTF8 Utf8(InString);
|
|
|
|
|
|
const uint8* Bytes = reinterpret_cast<const uint8*>(Utf8.Get());
|
|
|
|
|
|
uint32 Length = Utf8.Length() * sizeof(UTF8CHAR);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SHA256_CTX Sha256Context;
|
|
|
|
|
|
SHA256_Init(&Sha256Context);
|
|
|
|
|
|
SHA256_Update(&Sha256Context, Bytes,Length);
|
|
|
|
|
|
SHA256_Final(Hash.Signature, &Sha256Context);
|
|
|
|
|
|
|
|
|
|
|
|
return Hash.ToString();
|
2026-03-10 22:38:12 -04:00
|
|
|
|
}
|
2026-03-04 09:54:18 -05:00
|
|
|
|
|
2026-03-10 22:38:12 -04:00
|
|
|
|
void AShooterGameMode::InitGameLift()
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 07:13:47 -04:00
|
|
|
|
bool AShooterGameMode::GetAnywhereFleetParameters(const FString& CommandLineString)
|
2026-03-10 22:38:12 -04:00
|
|
|
|
{
|
|
|
|
|
|
bool bAllAnywhereFleetParametersValid = true;
|
2026-03-12 07:13:47 -04:00
|
|
|
|
GameLiftConfig.AuthTokenResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::AuthToken);
|
|
|
|
|
|
if (!GameLiftConfig.AuthTokenResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
GameLiftConfig.FleetIdResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::FleetId);
|
|
|
|
|
|
if (!GameLiftConfig.FleetIdResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
GameLiftConfig.HostIdResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::HostId);
|
|
|
|
|
|
if (!GameLiftConfig.HostIdResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
GameLiftConfig.WebSocketUrlResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::WebsocketUrl);
|
|
|
|
|
|
if (!GameLiftConfig.WebSocketUrlResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
|
|
|
|
|
|
|
|
|
|
|
return bAllAnywhereFleetParametersValid;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void AShooterGameMode::LogAnywhereFleetParameters()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Lambda for getting the token name from token
|
|
|
|
|
|
auto GetTokenName = [](const cmdlineparser::details::FParseResult& Result) -> FString
|
2026-03-10 22:38:12 -04:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
return cmdlineparser::details::CLI_TOKENS[static_cast<int32>(Result.Token)];
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if UE_BUILD_DEBUG
|
|
|
|
|
|
const FString AuthDisplay = GameLiftConfig.AuthTokenResult.Value;
|
2026-03-10 22:38:12 -04:00
|
|
|
|
#else
|
2026-03-12 07:13:47 -04:00
|
|
|
|
const FString AuthDisplay = TEXT("HASH:") + GetSHA256Hash(GameLiftConfig.AuthTokenResult.Value);
|
2026-03-10 22:38:12 -04:00
|
|
|
|
#endif
|
2026-03-12 07:13:47 -04:00
|
|
|
|
|
|
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "Anywhere Fleet Parameters:");
|
|
|
|
|
|
if (GameLiftConfig.AuthTokenResult.bIsValid)
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "AuthToken: {0}", AuthDisplay);
|
2026-02-24 22:39:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(
|
|
|
|
|
|
LogShooterGameMode,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
"AuthToken: {0}",
|
|
|
|
|
|
FString::Format(
|
|
|
|
|
|
*GameLiftConfig.AuthTokenResult.ErrorMessage,
|
|
|
|
|
|
{
|
|
|
|
|
|
FStringFormatArg(GetTokenName(GameLiftConfig.AuthTokenResult)),
|
|
|
|
|
|
FStringFormatArg(AuthDisplay)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2026-02-24 22:39:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 07:13:47 -04:00
|
|
|
|
if (GameLiftConfig.FleetIdResult.bIsValid)
|
2026-03-01 09:29:41 -05:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "FleetId: {0}", GameLiftConfig.FleetIdResult.Value);
|
2026-03-01 09:29:41 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(
|
|
|
|
|
|
LogShooterGameMode,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
"FleetId: {0}",
|
|
|
|
|
|
FString::Format(
|
|
|
|
|
|
*GameLiftConfig.FleetIdResult.ErrorMessage,
|
|
|
|
|
|
{
|
|
|
|
|
|
FStringFormatArg(GetTokenName(GameLiftConfig.FleetIdResult)),
|
|
|
|
|
|
FStringFormatArg(GameLiftConfig.FleetIdResult.Value)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2026-03-01 09:29:41 -05:00
|
|
|
|
}
|
2026-02-24 22:39:26 -05:00
|
|
|
|
|
2026-03-12 07:13:47 -04:00
|
|
|
|
if (GameLiftConfig.HostIdResult.bIsValid)
|
2026-03-01 09:29:41 -05:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "HostId: {0}", GameLiftConfig.HostIdResult.Value);
|
2026-03-01 09:29:41 -05:00
|
|
|
|
}
|
2026-03-10 22:38:12 -04:00
|
|
|
|
else
|
2026-03-04 09:54:18 -05:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(
|
|
|
|
|
|
LogShooterGameMode,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
"HostId: {0}",
|
|
|
|
|
|
FString::Format(
|
|
|
|
|
|
*GameLiftConfig.HostIdResult.ErrorMessage,
|
|
|
|
|
|
{
|
|
|
|
|
|
FStringFormatArg(GetTokenName(GameLiftConfig.HostIdResult)),
|
|
|
|
|
|
FStringFormatArg(GameLiftConfig.HostIdResult.Value)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2026-03-04 09:54:18 -05:00
|
|
|
|
}
|
2026-03-05 10:00:22 -05:00
|
|
|
|
|
2026-03-12 07:13:47 -04:00
|
|
|
|
if (GameLiftConfig.WebSocketUrlResult.bIsValid)
|
2026-03-05 10:00:22 -05:00
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "WebSocketUrl: {0}", GameLiftConfig.WebSocketUrlResult.Value);
|
2026-03-05 10:00:22 -05:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2026-03-12 07:13:47 -04:00
|
|
|
|
UE_LOGFMT(
|
|
|
|
|
|
LogShooterGameMode,
|
|
|
|
|
|
Error,
|
|
|
|
|
|
"WebSocketUrl: {0}",
|
|
|
|
|
|
FString::Format(
|
|
|
|
|
|
*GameLiftConfig.WebSocketUrlResult.ErrorMessage,
|
|
|
|
|
|
{
|
|
|
|
|
|
FStringFormatArg(GetTokenName(GameLiftConfig.WebSocketUrlResult)),
|
|
|
|
|
|
FStringFormatArg(GameLiftConfig.WebSocketUrlResult.Value)
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
);
|
2026-03-05 10:00:22 -05:00
|
|
|
|
}
|
2026-03-12 07:13:47 -04:00
|
|
|
|
|
2026-03-10 22:38:12 -04:00
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "Server Port: {0}", GameLiftConfig.ServerPort);
|
2026-03-12 07:13:47 -04:00
|
|
|
|
|
|
|
|
|
|
if (GameLiftConfig.bAllOptionsFound)
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Log, "Anywhere Fleet Parameters Loaded Successfully....");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
UE_LOGFMT(LogShooterGameMode, Error, "Anywhere Fleet Parameters Load FAILED....");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|