Lesson 44 - Deleting the Fleet (EC2), all working at this point.

This commit is contained in:
Norman Lansing
2026-03-03 18:27:04 -05:00
parent 0beaf68d7d
commit 13daff916c
3 changed files with 72 additions and 204 deletions

View File

@@ -2,7 +2,7 @@
#include "Game/ShooterGameMode.h"
#include "Logging/LogMacros.h"
#include "DSP/BufferDiagnostics.h"
#include "UObject/ConstructorHelpers.h"
#include "Kismet/GameplayStatics.h"
@@ -11,6 +11,7 @@
#include "GameLiftServerSDKModels.h"
#endif
#include "Chaos/ImplicitQRSVD.h"
#include "GenericPlatform/GenericPlatformOutputDevices.h"
#include "Misc/TypeContainer.h"
@@ -58,7 +59,7 @@ bool AShooterGameMode::SetParametersFromCommandLine(FServerParameters& OutServer
OutProcessParameters.port = FURL::UrlConfig.DefaultPort;
FParse::Value(*CommandLine, TEXT("port="), OutProcessParameters.port);
LogServerSummary(OutServerParameters,OutProcessParameters);
// LogServerSummary(OutServerParameters,OutProcessParameters);
return bCriticalFault;
}
@@ -104,7 +105,7 @@ void AShooterGameMode::LogServerSummary(const FServerParameters& InServerParamet
const FProcessParameters& InProcessParameters)
{
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);
// Inline validation of ServerParams
@@ -118,6 +119,54 @@ void AShooterGameMode::LogServerSummary(const FServerParameters& InServerParamet
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)
{
// Implement callback function onStartGameSession
@@ -248,6 +297,16 @@ void AShooterGameMode::InitGameLift()
// Getting the module first.
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.
bool bIsAnywhereActive = false;
if (FParse::Param(FCommandLine::Get(), TEXT("-glAnywhere")))
@@ -272,7 +331,7 @@ void AShooterGameMode::InitGameLift()
FPlatformMisc::RequestExit(true);
return;
}
LogServerParameters(ServerParameters);
// LogServerParameters(ServerParameters);
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing the GameLift Server..."));
@@ -289,7 +348,11 @@ void AShooterGameMode::InitGameLift()
// EC2: Empty ServerParameters = GameLift agent provies all config
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing EC2 GameLift Server..."));
}
if (InitiateConnectionWithGameLiftAgent(ServerParameters, GameLiftSdkModule)) return;
LogGameLiftServerSummary(bIsAnywhereActive, ServerParameters, ProcessParameters);
InitiateProcessReady(ProcessParameters, GameLiftSdkModule);
#endif
}