Lesson 35 - Get Compute Auth Token Working

This commit is contained in:
Norman Lansing
2026-02-28 12:32:28 -05:00
parent 1d477ee42a
commit 4fde462bce
7743 changed files with 1397833 additions and 18 deletions

View File

@@ -0,0 +1,27 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Modules/ModuleManager.h"
#include "GameLiftClientSDKModels.h"
class FGameLiftClientSDKModule : public IModuleInterface
{
public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
virtual bool ConfigureClient(const FString& CredentialsName);
virtual FGL_GameSession CreateGameSession(size_t MaximumPlayerCount, const FString& FleetId, FString& ErrorMsg, const FString& CustomLocation = TEXT(""), const FString& EndPoint = TEXT(""));
virtual TArray<FGL_GameSession> DescribeGameSessions(const FString& FleetId, const FString& StatusFilter, FString& ErrorMsg, const FString& EndPoint = TEXT(""));
virtual FGL_PlayerSession CreatePlayerSession(const FString& GameSessionId, const FString& PlayerData, const FString& PlayerId, FString& ErrorMsg, const FString& EndPoint = TEXT(""));
private:
void* GameLiftClientHandle;
};

View File

@@ -0,0 +1,120 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "CoreMinimal.h"
#if WITH_GAMELIFT_CLIENT
#include <aws/gamelift/core/exports.h>
#endif
#include "GameLiftClientSDKModels.generated.h"
UENUM(BlueprintType)
enum class EGL_GameSessionStatus : uint8 {
NOT_SET UMETA(DisplayName = "Not Set"),
ACTIVE UMETA(DisplayName = "Active"),
ACTIVATING UMETA(DisplayName = "Activating"),
TERMINATED UMETA(DisplayName = "Terminated"),
TERMINATING UMETA(DisplayName = "Terminating"),
ERROR_ UMETA(DisplayName = "Error"),
};
UENUM(BlueprintType)
enum class EGL_PlayerSessionStatus : uint8
{
NOT_SET UMETA(DisplayName = "Not Set"),
RESERVED UMETA(DisplayName = "Reserved"),
ACTIVE UMETA(DisplayName = "Active"),
COMPLETED UMETA(DisplayName = "Completed"),
TIMEDOUT UMETA(DisplayName = "Timedout")
};
USTRUCT(BlueprintType)
struct FGL_GameSession
{
GENERATED_BODY()
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString GameSessionId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString FleetId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
int CurrentPlayerSessionCount = 0;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
int MaximumPlayerSessionCount = 0;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
EGL_GameSessionStatus Status = EGL_GameSessionStatus::NOT_SET;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString IpAddress;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString DnsName;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
int Port = 0;
FString ToString() const
{
return FString::Printf(TEXT("GameSessionId: %s,\nFleetId: %s,\nMaximumPlayerSesssionCount: %s,\nStatus: %s,\nIpAddress: %s,\nDnsName: %s,\nPort: %s\n"),
*GameSessionId, *FleetId, *FString::FromInt(MaximumPlayerSessionCount), *StaticEnum<EGL_GameSessionStatus>()->GetValueAsString(Status), *IpAddress, *DnsName, *FString::FromInt(Port));
}
};
USTRUCT(BlueprintType)
struct FGL_PlayerSession
{
GENERATED_BODY()
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString DnsName;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString FleetArn;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString FleetId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString GameSessionId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString IpAddress;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString PlayerData;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString PlayerId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
FString PlayerSessionId;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
int Port = 0;
UPROPERTY(Category = "GameLiftClient", BlueprintReadOnly)
EGL_PlayerSessionStatus Status = EGL_PlayerSessionStatus::NOT_SET;
FString ToString() const
{
return FString::Printf(TEXT("DnsName: %s,\nFleetArn: %s,\nFleetId: %s,\nGameSessionId: %s,\nIpAddress: %s,\nPlayerData: %s,\nPlayerId: %s,\nPlayerSesssionId: %s,\nPort: %s,\nPlayerStatus: %s,\n"),
*DnsName, *FleetArn, *FleetId, *GameSessionId, *IpAddress, *PlayerData, *PlayerId, *PlayerSessionId, *FString::FromInt(Port), *StaticEnum<EGL_PlayerSessionStatus>()->GetValueAsString(Status));
}
};
namespace GL_Utils
{
#if WITH_GAMELIFT_CLIENT
FGL_GameSession AwsGameSessionToUe(GAMELIFT_GAMESESSION_INSTANCE_HANDLE GameSession);
FGL_GameSession AwsGameSessionToUe(const GAMELIFT_GAMESESSION_INFO& GameSessionInfo);
FGL_PlayerSession AwsPlayerSessionToUe(GAMELIFT_PLAYERSESSION_INSTANCE_HANDLE PlayerSession);
#endif
} // namespace GL_Utils

View File

@@ -0,0 +1,17 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#if WITH_GAMELIFT_CLIENT
#include <string>
#include <Containers/StringConv.h>
namespace AWSSerializer
{
std::string FSToStdS(const FString& String);
FString ASToFS(const char* String);
}
#endif

View File

@@ -0,0 +1,64 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Styling/SlateColor.h"
#include "TestAnywhereMenuWidget.generated.h"
class FGameLiftClientSDKModule;
// This is a sample game mode that you can use the test the GameLift Anywhere workflow in the plugin.
// It simulates the process of talking to Amazon GameLift and retrieve info needed to connect to a running game server.
UCLASS()
class UTestAnywhereMenuWidget : public UUserWidget
{
GENERATED_BODY()
public:
UTestAnywhereMenuWidget(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable)
bool ConnectToServer();
public:
UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
FText LogOutputText;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
FSlateColor LogOutputColor;
private:
// This function will fetch command line arguments which are provided when launching the client build in the plugin's Anywhere page.
void TryFetchCommandLineArguments();
// Communicate with Amazon GameLift for game session (e.g. IP address) and player session information.
// Return true if the client can create a player session and ready to connect to the running game server.
bool ConnectToAmazonGameLift();
// These functions simulate the process of finding, creating game session, and creating player session.
bool FindGameSession();
bool CreateGameSession(size_t InMaxPlayerCount);
bool CreatePlayerSession();
void SetOutputMessage(const FString& InMessage, bool bIsError = false);
private:
FGameLiftClientSDKModule* GameLiftSdkModule = nullptr;
// Test inputs
FString InputFleetId;
FString InputCredentialsName;
FString InputCustomLocation;
// Test outputs
FString ServerIpAddress;
FString ServerPort;
FString ServerGameSessionId;
FString ServerPlayerId;
FString ServerPlayerSessionId;
const size_t kMaximumPlayerSessionCount = 10;
};

View File

@@ -0,0 +1,128 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "Http.h"
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Engine/EngineTypes.h"
#include "TestCloudDeploymentMenuWidget.generated.h"
DECLARE_LOG_CATEGORY_EXTERN(TestCloudDeployment, Log, All);
enum class ServerHttpStatusCode : int32
{
// start_game API codes
// 202 (Accepted) if the matchmaking request is accepted and is now being processed
StartGame_Accepted = 202,
// 409 (Conflict) if the another matchmaking request is in progress
StartGame_Conflict = 409,
// 500 (Internal Error) if error occurred when processing the matchmaking request
StartGame_InternalError = 500,
// get_game_connection API codes
// 200 (OK) if the game connection is ready, along with server info: "IpAddress", "Port", "DnsName", "PlayerSessionId", "PlayerId"
GetGameConnection_Ready = 200,
// 204 (No Content) if the requested game is still in progress of matchmaking
GetGameConnection_MatchmakingInProgress = 204,
// 404 (Not Found) if no game has been started by the player, or if all started game were expired
GetGameConnection_NotFound = 404,
// 500 (Internal Error) if errors occurred during matchmaking or placement
GetGameConnection_InternalError = 500,
// 501 (No Server Deployed) if no server has been delpoyed
GetGameConnection_NoServerError = 501,
};
class UWebBrowser;
/**
*
*/
UCLASS()
class UTestCloudDeploymentMenuWidget : public UUserWidget
{
GENERATED_BODY()
public:
UTestCloudDeploymentMenuWidget(const FObjectInitializer& ObjectInitializer);
UFUNCTION(BlueprintCallable)
bool OnLoginClicked();
UFUNCTION(BlueprintCallable)
int OnSignupClicked();
UFUNCTION(BlueprintCallable)
int OnConfirmSignupClicked();
UFUNCTION(BlueprintCallable)
FString GetLatestError();
UPROPERTY(EditAnywhere)
FString ApiGatewayEndpoint;
UPROPERTY(EditAnywhere)
FString GetGameConnectionURI;
UPROPERTY(EditAnywhere)
int GetGameConnectionRetryDelayMs;
UPROPERTY(EditAnywhere)
uint32 MatchmakingTimeoutInSecondsParameter;
UPROPERTY(EditAnywhere)
FString StartSessionURI;
UPROPERTY(EditAnywhere)
FString SignupUrl;
UPROPERTY(EditAnywhere)
FString CallbackUrl;
UPROPERTY(BlueprintReadWrite)
FString Username;
UPROPERTY(BlueprintReadWrite)
FString Password;
UPROPERTY(BlueprintReadWrite)
FString VerificationCode;
UPROPERTY(EditAnywhere)
FString ConfigFilePath;
UPROPERTY()
UWebBrowser* WebBrowser;
UPROPERTY()
FTimerHandle PollGameConnectionHandle;
UPROPERTY()
FTimerHandle PollGameConnectionEndHandle;
protected:
virtual void NativeConstruct() override;
private:
void PollGameConnection();
void PollGameConnectionEnd();
FHttpModule* Http;
int AuthAndGetToken();
void EstablishGameConnection();
void OnGetGameConnectionResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
void StartGame(FString idt);
void OnStartGameResponse(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
bool OpenLevel(const FString& IpAddress, const FString& Port, const FString& Options);
FString IdToken;
bool MatchmakingInProgress;
TAtomic<bool> MatchmakingIsTimedOut;
FString LatestError;
};