Lesson 44 - Deleting the Fleet (EC2), all working at this point.
This commit is contained in:
@@ -53,6 +53,10 @@
|
|||||||
{
|
{
|
||||||
"Name": "PerforceSourceControl",
|
"Name": "PerforceSourceControl",
|
||||||
"Enabled": false
|
"Enabled": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "GameLiftPlugin",
|
||||||
|
"Enabled": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Game/ShooterGameMode.h"
|
#include "Game/ShooterGameMode.h"
|
||||||
|
#include "Logging/LogMacros.h"
|
||||||
#include "DSP/BufferDiagnostics.h"
|
#include "DSP/BufferDiagnostics.h"
|
||||||
#include "UObject/ConstructorHelpers.h"
|
#include "UObject/ConstructorHelpers.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
#include "GameLiftServerSDKModels.h"
|
#include "GameLiftServerSDKModels.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "Chaos/ImplicitQRSVD.h"
|
||||||
#include "GenericPlatform/GenericPlatformOutputDevices.h"
|
#include "GenericPlatform/GenericPlatformOutputDevices.h"
|
||||||
#include "Misc/TypeContainer.h"
|
#include "Misc/TypeContainer.h"
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ bool AShooterGameMode::SetParametersFromCommandLine(FServerParameters& OutServer
|
|||||||
OutProcessParameters.port = FURL::UrlConfig.DefaultPort;
|
OutProcessParameters.port = FURL::UrlConfig.DefaultPort;
|
||||||
FParse::Value(*CommandLine, TEXT("port="), OutProcessParameters.port);
|
FParse::Value(*CommandLine, TEXT("port="), OutProcessParameters.port);
|
||||||
|
|
||||||
LogServerSummary(OutServerParameters,OutProcessParameters);
|
// LogServerSummary(OutServerParameters,OutProcessParameters);
|
||||||
|
|
||||||
return bCriticalFault;
|
return bCriticalFault;
|
||||||
}
|
}
|
||||||
@@ -104,7 +105,7 @@ void AShooterGameMode::LogServerSummary(const FServerParameters& InServerParamet
|
|||||||
const FProcessParameters& InProcessParameters)
|
const FProcessParameters& InProcessParameters)
|
||||||
{
|
{
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_YELLOW);
|
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_YELLOW);
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("=== SERVER STARTUP SUMMARY ==="));
|
UE_LOG(LogShooterGameMode, Log, TEXT("=== GAMELIFT SERVER STARTUP SUMMARY ==="));
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), InProcessParameters.port);
|
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), InProcessParameters.port);
|
||||||
|
|
||||||
// Inline validation of ServerParams
|
// Inline validation of ServerParams
|
||||||
@@ -118,6 +119,54 @@ void AShooterGameMode::LogServerSummary(const FServerParameters& InServerParamet
|
|||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AShooterGameMode::LogGameLiftServerSummary(bool bIsAnywhere, const FServerParameters& InServerParameters,
|
||||||
|
const FProcessParameters& InProcessParameters)
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_YELLOW);
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("=== GAMELIFT SERVER STARTUP SUMMARY ==="));
|
||||||
|
|
||||||
|
if (bIsAnywhere)
|
||||||
|
{
|
||||||
|
// Anywhere only Logging
|
||||||
|
if (!InServerParameters.m_fleetId.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("FleetId: %s"), *InServerParameters.m_fleetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InServerParameters.m_webSocketUrl.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("WebSocketUrl: %s"), *InServerParameters.m_webSocketUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InServerParameters.m_hostId.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("HostId: %s"), *InServerParameters.m_hostId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef UE_BUILD_DEBUG
|
||||||
|
const FString TokenStatus = FString::Printf(TEXT("FULL: %s"), *InServerParameters.m_authToken);
|
||||||
|
#else
|
||||||
|
const FString TokenStatus = InServerParameters.m_authToken.IsEmpty() ? TEXT("MISSING ❌") : FString::Printf(TEXT("LEN: %d"),InServerParameters.m_authToken.Len());
|
||||||
|
#endif
|
||||||
|
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("AuthToken: %s"), *TokenStatus);
|
||||||
|
|
||||||
|
|
||||||
|
// Inline validation of ServerParams
|
||||||
|
const bool bAllValid = !InServerParameters.m_authToken.IsEmpty() &&
|
||||||
|
!InServerParameters.m_hostId.IsEmpty() &&
|
||||||
|
!InServerParameters.m_fleetId.IsEmpty() &&
|
||||||
|
!InServerParameters.m_webSocketUrl.IsEmpty();
|
||||||
|
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("All Anywhere params: %s"), bAllValid ? TEXT("VALID ✓") : TEXT("MISSING ❌"));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), InProcessParameters.port);
|
||||||
|
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
void AShooterGameMode::BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule)
|
void AShooterGameMode::BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule)
|
||||||
{
|
{
|
||||||
// Implement callback function onStartGameSession
|
// Implement callback function onStartGameSession
|
||||||
@@ -248,6 +297,16 @@ void AShooterGameMode::InitGameLift()
|
|||||||
// Getting the module first.
|
// Getting the module first.
|
||||||
FGameLiftServerSDKModule& GameLiftSdkModule = FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK"));
|
FGameLiftServerSDKModule& GameLiftSdkModule = FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK"));
|
||||||
|
|
||||||
|
// The port being used, uses UE system default if not entered as a switch
|
||||||
|
ProcessParameters.port = FURL::UrlConfig.DefaultPort;
|
||||||
|
FParse::Value(FCommandLine::Get(), TEXT("port="), ProcessParameters.port);
|
||||||
|
|
||||||
|
if (ProcessParameters.port <= 0 || ProcessParameters.port > 65535)
|
||||||
|
{
|
||||||
|
UE_LOG(LogShooterGameMode, Error, TEXT("Port Value Fault: %d (Value must be between 1 and 65535"), ProcessParameters.port);
|
||||||
|
FPlatformMisc::RequestExit(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Define the server parameters for a GameLift Anywhere fleet. These are not needed for a GameLift managed EC2 fleet.
|
// Define the server parameters for a GameLift Anywhere fleet. These are not needed for a GameLift managed EC2 fleet.
|
||||||
bool bIsAnywhereActive = false;
|
bool bIsAnywhereActive = false;
|
||||||
if (FParse::Param(FCommandLine::Get(), TEXT("-glAnywhere")))
|
if (FParse::Param(FCommandLine::Get(), TEXT("-glAnywhere")))
|
||||||
@@ -272,7 +331,7 @@ void AShooterGameMode::InitGameLift()
|
|||||||
FPlatformMisc::RequestExit(true);
|
FPlatformMisc::RequestExit(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LogServerParameters(ServerParameters);
|
// LogServerParameters(ServerParameters);
|
||||||
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing the GameLift Server..."));
|
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing the GameLift Server..."));
|
||||||
|
|
||||||
@@ -289,7 +348,11 @@ void AShooterGameMode::InitGameLift()
|
|||||||
// EC2: Empty ServerParameters = GameLift agent provies all config
|
// EC2: Empty ServerParameters = GameLift agent provies all config
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing EC2 GameLift Server..."));
|
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing EC2 GameLift Server..."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InitiateConnectionWithGameLiftAgent(ServerParameters, GameLiftSdkModule)) return;
|
if (InitiateConnectionWithGameLiftAgent(ServerParameters, GameLiftSdkModule)) return;
|
||||||
|
|
||||||
|
LogGameLiftServerSummary(bIsAnywhereActive, ServerParameters, ProcessParameters);
|
||||||
InitiateProcessReady(ProcessParameters, GameLiftSdkModule);
|
InitiateProcessReady(ProcessParameters, GameLiftSdkModule);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,206 +11,6 @@
|
|||||||
|
|
||||||
#include "ShooterGameMode.generated.h"
|
#include "ShooterGameMode.generated.h"
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
struct FCommandLineArgs
|
|
||||||
{
|
|
||||||
TMap<FString,FString> Options;
|
|
||||||
TArray<FString> CmdArguments;
|
|
||||||
|
|
||||||
void ParseCommandLine()
|
|
||||||
{
|
|
||||||
const TCHAR* CommandLine = FCommandLine::Get();
|
|
||||||
|
|
||||||
// Reserves estimated space to avoid reallocations
|
|
||||||
Options.Reserve(10);
|
|
||||||
CmdArguments.Reserve(10);
|
|
||||||
|
|
||||||
FString Key, Value, Token;
|
|
||||||
FString FlagName = FString(TEXT(""));
|
|
||||||
while (FParse::Token(CommandLine, Token, true))
|
|
||||||
{
|
|
||||||
// Check if token starts with '-'
|
|
||||||
if (Token.StartsWith(TEXT("-")))
|
|
||||||
{
|
|
||||||
// Remove the leading '-' and store the flag name
|
|
||||||
FlagName = Token.Mid(1);
|
|
||||||
|
|
||||||
// If it's in the form Key=Value, split it
|
|
||||||
if (FlagName.Split(TEXT("="), &Key, &Value))
|
|
||||||
{
|
|
||||||
Key=Key.ToLower();
|
|
||||||
Value=Value.ToLower();
|
|
||||||
// Normalize boolean values
|
|
||||||
if (Value.Equals(TEXT("true"), ESearchCase::IgnoreCase) || Value.Equals(TEXT("1")))
|
|
||||||
{
|
|
||||||
Options.Add(Key, TEXT("true"));
|
|
||||||
}
|
|
||||||
else if (Value.Equals(TEXT("false"), ESearchCase::IgnoreCase) || Value.Equals(TEXT("0")))
|
|
||||||
{
|
|
||||||
Options.Add(Key, TEXT("false"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Options.Add(Key, Value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Bare flag (for
|
|
||||||
// example -Debug or -NoSound)
|
|
||||||
|
|
||||||
// The convention is flags starting with "No" are false
|
|
||||||
if (FlagName.StartsWith(TEXT("No")) && FlagName.Len() > 2)
|
|
||||||
{
|
|
||||||
Key = FlagName.Mid(2).ToLower();
|
|
||||||
|
|
||||||
Options.Add(Key, TEXT("false"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Key = FlagName.ToLower();
|
|
||||||
Options.Add(Key, TEXT("true"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Also add to Arguments array for backward compatibility
|
|
||||||
CmdArguments.Add(FlagName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CmdArguments.Add(Token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FString GetValueFromKey(const FString& Key, const FString& DefaultValue = TEXT("")) const
|
|
||||||
{
|
|
||||||
FString NormalizedKey = Key.ToLower();
|
|
||||||
const FString* ValuePtr = Options.Find(NormalizedKey);
|
|
||||||
return ValuePtr ? *ValuePtr : DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryGetValue(const FString& Key, FString& OutValue) const
|
|
||||||
{
|
|
||||||
FString NormalizedKey = Key.ToLower();
|
|
||||||
if (const FString* ValuePtr = Options.Find(NormalizedKey))
|
|
||||||
{
|
|
||||||
OutValue = *ValuePtr;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
FString ToString() const
|
|
||||||
{
|
|
||||||
FString Result;
|
|
||||||
for (const auto& Pair : Options)
|
|
||||||
{
|
|
||||||
Result += FString::Printf(TEXT("-%s=%s "), *Pair.Key, *Pair.Value);
|
|
||||||
}
|
|
||||||
for (const FString& Arg : CmdArguments)
|
|
||||||
{
|
|
||||||
Result += Arg + TEXT(" ");
|
|
||||||
}
|
|
||||||
return Result.TrimEnd();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a boolean value, returns Default if not found or invalid
|
|
||||||
bool GetBool(const FString& Key, bool DefaultValue = false) const
|
|
||||||
{
|
|
||||||
FString Value;
|
|
||||||
if (TryGetValue(Key, Value))
|
|
||||||
{
|
|
||||||
if (Value.Equals(TEXT("true"), ESearchCase::IgnoreCase) ||
|
|
||||||
Value.Equals(TEXT("1")) ||
|
|
||||||
Value.Equals(TEXT("yes"), ESearchCase::IgnoreCase))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (Value.Equals(TEXT("false"), ESearchCase::IgnoreCase) ||
|
|
||||||
Value.Equals(TEXT("0")) ||
|
|
||||||
Value.Equals(TEXT("no"), ESearchCase::IgnoreCase))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get an integer value, returns Default if not found or not numeric
|
|
||||||
int32 GetInt(const FString& Key, int32 DefaultValue = 0) const
|
|
||||||
{
|
|
||||||
FString Value;
|
|
||||||
if (TryGetValue(Key, Value))
|
|
||||||
{
|
|
||||||
return FCString::Atoi(*Value);
|
|
||||||
}
|
|
||||||
return DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get a float value
|
|
||||||
float GetFloat(const FString& Key, float DefaultValue = 0.0f) const
|
|
||||||
{
|
|
||||||
FString Value;
|
|
||||||
if (TryGetValue(Key, Value))
|
|
||||||
{
|
|
||||||
return FCString::Atof(*Value);
|
|
||||||
}
|
|
||||||
return DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get as FName (useful for modes, map names, etc.)
|
|
||||||
FName GetName(const FString& Key, const FName& DefaultValue = NAME_None) const
|
|
||||||
{
|
|
||||||
FString Value;
|
|
||||||
if (TryGetValue(Key, Value))
|
|
||||||
{
|
|
||||||
return FName(*Value);
|
|
||||||
}
|
|
||||||
return DefaultValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a string value (core setter used by others)
|
|
||||||
void SetValue(const FString& Key, const FString& Value)
|
|
||||||
{
|
|
||||||
Options.Add(Key.ToLower(), Value.ToLower());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a boolean option
|
|
||||||
void SetBool(const FString& Key, bool bValue)
|
|
||||||
{
|
|
||||||
Options.Add(Key.ToLower(), bValue ? TEXT("true") : TEXT("false"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set an integer option
|
|
||||||
void SetInt(const FString& Key, int32 Value)
|
|
||||||
{
|
|
||||||
Options.Add(Key.ToLower(), FString::FromInt(Value));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a float option (with minimal formatting)
|
|
||||||
void SetFloat(const FString& Key, float Value, int32 Precision = 2)
|
|
||||||
{
|
|
||||||
FString FloatStr = FString::SanitizeFloat(Value, Precision);
|
|
||||||
Options.Add(Key.ToLower(), FloatStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set an FName option
|
|
||||||
void SetName(const FString& Key, const FName& NameValue)
|
|
||||||
{
|
|
||||||
Options.Add(Key.ToLower(), NameValue.ToString().ToLower());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a bare flag (true/false toggle stored for ToString output)
|
|
||||||
void SetFlag(const FString& Flag, bool bEnabled = true)
|
|
||||||
{
|
|
||||||
FString Key = Flag.ToLower();
|
|
||||||
Options.Add(Key, bEnabled ? TEXT("true") : TEXT("false"));
|
|
||||||
CmdArguments.Add(Flag); // maintain compatibility with older flag parsing
|
|
||||||
}
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
DECLARE_LOG_CATEGORY_EXTERN(LogShooterGameMode, Log, All);
|
DECLARE_LOG_CATEGORY_EXTERN(LogShooterGameMode, Log, All);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -236,6 +36,7 @@ private:
|
|||||||
void SetProcessIdOnServerParameters(FServerParameters& OutServerParameters);
|
void SetProcessIdOnServerParameters(FServerParameters& OutServerParameters);
|
||||||
bool ValidateServerParameters(const FString& CommandLine, const FString& ParameterName, FString& OutValue, const bool bCritical = true);
|
bool ValidateServerParameters(const FString& CommandLine, const FString& ParameterName, FString& OutValue, const bool bCritical = true);
|
||||||
void LogServerSummary(const FServerParameters& InServerParameters, const FProcessParameters& InProcessParameters);
|
void LogServerSummary(const FServerParameters& InServerParameters, const FProcessParameters& InProcessParameters);
|
||||||
|
void LogGameLiftServerSummary(bool bIsAnywhere, const FServerParameters& InServerParameters, const FProcessParameters& InProcessParameters);
|
||||||
void BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters,
|
void BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters,
|
||||||
FGameLiftServerSDKModule& GameLiftSdkModule);
|
FGameLiftServerSDKModule& GameLiftSdkModule);
|
||||||
void InitiateProcessReady(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule);
|
void InitiateProcessReady(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule);
|
||||||
|
|||||||
Reference in New Issue
Block a user