Initial Commit

This commit is contained in:
Norman Lansing
2026-01-28 19:08:51 -05:00
commit ecb33115bf
54042 changed files with 9695586 additions and 0 deletions

View File

@@ -0,0 +1,125 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
#include "GameLiftMetricsTypes.h"
#include <aws/gamelift/metrics/GameLiftMetrics.h>
// Forward declarations
struct FMetricsParameters;
class FSocket;
class FUnrealStatCollector;
class FTickableCollector;
class UGameLiftMetricsConfig;
namespace Aws {
namespace GameLift {
namespace Server {
namespace Model {
class GameSession;
} // Model
} // Server
} // GameLift
} // Aws
class GAMELIFTMETRICS_API FGameLiftMetricsModule : public IModuleInterface
{
public:
// IModuleInterface
virtual void StartupModule() override;
virtual void ShutdownModule() override;
virtual bool SupportsDynamicReloading() override { return false; }
virtual bool SupportsAutomaticShutdown() override { return true; }
// ~IModuleInterface
static FGameLiftMetricsModule& Load();
static FGameLiftMetricsModule& Get();
static FGameLiftMetricsModule* GetPtr();
/**
* Initialize GameLift Metrics using default configuration. These
* may be overriden by environment variables.
*/
void Initialize();
/**
* Initialize GameLift Metrics with metrics parameters.
*
* @param metricsParameters Metrics parameters to use.
*/
void Initialize(const FMetricsParameters& metricsParameters);
/**
* Terminate the GameLift Metrics SDK.
*/
void Terminate();
/**
* Enable or disable metrics at runtime.
* If metrics were previously disabled, this will initialize the metrics system.
* If metrics were previously enabled, this will terminate the metrics system.
*
* @param bEnable Whether to enable or disable metrics
* @return True if the operation was successful
*/
bool SetMetricsEnabled(bool bEnable);
/**
* Check if metrics are currently enabled and running
*
* @return True if metrics are currently enabled and running
*/
bool IsMetricsEnabled() const;
/**
* Records a new game session.
* Call when starting a new session from the FProcessSettings::OnStartGameSession callback.
*/
void OnStartGameSession(const Aws::GameLift::Server::Model::GameSession&);
/**
* Records a new player session.
*
* Call when accepting a player session.
*/
void OnAcceptPlayerSession();
/**
* Records a removed player session.
*
* Call when removing a player session.
*/
void OnRemovePlayerSession();
private:
void StartMetricsCollector();
TSharedPtr<FSocket> Socket;
TUniquePtr<FTickableCollector> Collector;
TSharedPtr<FUnrealStatCollector> UnrealStatCollector;
static FString CurrentGameSessionId;
static FThreadSafeCounter CurrentPlayerCount;
bool bMetricsRunning = false; // Tracks if metrics are currently running
static void CrashHandler(const FGenericCrashContext& Context);
void ReEmitMetrics();
friend class FTickableCollector;
};

View File

@@ -0,0 +1,80 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "CoreMinimal.h"
#include "GameLiftMetricsConfig.generated.h"
/**
* GameLift Metrics module configuration.
*
* Can be configured in `DefaultGame.ini`:
* ```
* [/Script/GameLiftMetricsUnreal.GameLiftMetricsConfig]
* CollectorHost = "127.0.0.1"
* CollectorPort = 8125
* MaxPacketSize = 2048
* CaptureIntervalSeconds = 10
* bEnableMetrics = true
* ```
*/
UCLASS(config=Game, defaultconfig)
class GAMELIFTMETRICS_API UGameLiftMetricsConfig : public UObject
{
GENERATED_BODY()
public:
UGameLiftMetricsConfig() = default;
/**
* Returns the current configuration.
*/
static const UGameLiftMetricsConfig& Get();
/**
* Whether metrics collection is enabled.
* When disabled, no metrics will be collected or sent.
*/
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="GameLift Metrics")
bool bEnableMetrics = true;
/**
* Host to send metrics to.
*/
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="GameLift Metrics")
FString CollectorHost = TEXT("127.0.0.1");
/**
* UDP port number to send metrics to.
*/
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="GameLift Metrics")
int32 CollectorPort = 8125;
/**
* Metrics capture interval before sending data to the collector.
*/
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="GameLift Metrics")
float CaptureIntervalSeconds = 10.0f;
/**
* Maximum UDP packet size.
*
* Typical MTU for Internet packets is 1500 bytes.
* We set the default to 1472, leaving room for headers.
*
* For use with collector on same machine or with AWS jumbo packets this value can be bumped up past 1500 bytes.
*/
UPROPERTY(Config, EditAnywhere, BlueprintReadOnly, Category="GameLift Metrics")
int32 MaxPacketSize = 1472;
};

View File

@@ -0,0 +1,42 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "CoreMinimal.h"
#include <aws/gamelift/metrics/GameLiftMetrics.h>
DECLARE_LOG_CATEGORY_EXTERN(LogGameLiftMetrics, Log, All);
#define WITH_GAMELIFT_METRICS (WITH_GAMELIFT && UE_SERVER)
namespace Aws {
namespace GameLift {
namespace Metrics {
/**
* Logs in all server builds.
*/
GAMELIFT_METRICS_DEFINE_PLATFORM_API(GAMELIFTMETRICS_API, Server, WITH_GAMELIFT_METRICS && UE_SERVER);
/**
* Logs in all development or debug server builds.
*/
GAMELIFT_METRICS_DEFINE_PLATFORM_API(GAMELIFTMETRICS_API, ServerDevelopment, WITH_GAMELIFT_METRICS && UE_SERVER && (UE_BUILD_DEVELOPMENT || UE_BUILD_DEBUG));
/**
* Logs only in debug builds.
*/
GAMELIFT_METRICS_DEFINE_PLATFORM_API(GAMELIFTMETRICS_API, ServerDebug, WITH_GAMELIFT_METRICS && UE_SERVER && UE_BUILD_DEBUG);
} // Metrics
} // GameLift
} // Aws