Lesson 35 - Get Compute Auth Token Working
This commit is contained in:
@@ -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;
|
||||
};
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user