Compare commits
28 Commits
0beaf68d7d
...
new/API_Ga
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9fb60888ba | ||
|
|
acc105c84d | ||
|
|
d9eb52c047 | ||
|
|
e95360489b | ||
|
|
6f3e1d1f86 | ||
|
|
30c1e42379 | ||
|
|
7f154aa6f9 | ||
|
|
8d6f3f68f1 | ||
|
|
3912fe52c6 | ||
|
|
d989960b41 | ||
|
|
3407b94731 | ||
|
|
b26e9eb576 | ||
|
|
898fba8153 | ||
|
|
f52a4225c3 | ||
|
|
2ec989d34a | ||
|
|
3e61d4cec0 | ||
|
|
7f14cad36f | ||
|
|
6afd336bbf | ||
|
|
554c94a778 | ||
|
|
23bcff131a | ||
|
|
51e89e8613 | ||
|
|
bf2ead5f97 | ||
|
|
04f5cb37dc | ||
|
|
5bfc79cbda | ||
|
|
99b168b6b5 | ||
|
|
ade2a38d7c | ||
|
|
ebf932882b | ||
|
|
13daff916c |
@@ -2,9 +2,9 @@
|
|||||||
CommonUI.Debug.CheckGameViewportClientValid=0
|
CommonUI.Debug.CheckGameViewportClientValid=0
|
||||||
|
|
||||||
[/Script/EngineSettings.GameMapsSettings]
|
[/Script/EngineSettings.GameMapsSettings]
|
||||||
GameDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap
|
GameDefaultMap=/Game/Maps/StartupMap.StartupMap
|
||||||
EditorStartupMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap
|
EditorStartupMap=/Game/Maps/StartupMap.StartupMap
|
||||||
GlobalDefaultGameMode=/Game/Blueprints/Game/BP_ShooterGameMode.BP_ShooterGameMode_C
|
GlobalDefaultGameMode=/Game/Blueprints/Game/BP_ShooterGameModeBase.BP_ShooterGameModeBase_C
|
||||||
ServerDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap
|
ServerDefaultMap=/Game/ThirdPerson/Maps/ThirdPersonMap.ThirdPersonMap
|
||||||
|
|
||||||
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
|
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
|
||||||
@@ -179,6 +179,11 @@ DefaultBroadphaseSettings=(bUseMBPOnClient=False,bUseMBPOnServer=False,bUseMBPOu
|
|||||||
MinDeltaVelocityForHitEvents=0.000000
|
MinDeltaVelocityForHitEvents=0.000000
|
||||||
ChaosSettings=(DefaultThreadingModel=TaskGraph,DedicatedThreadTickMode=VariableCappedWithTarget,DedicatedThreadBufferMode=Double)
|
ChaosSettings=(DefaultThreadingModel=TaskGraph,DedicatedThreadTickMode=VariableCappedWithTarget,DedicatedThreadBufferMode=Double)
|
||||||
|
|
||||||
|
[URL]
|
||||||
|
DefaultPort=7777
|
||||||
|
|
||||||
[CoreRedirects]
|
[CoreRedirects]
|
||||||
+PropertyRedirects=(OldName="/Script/FPSTemplate.CommandLineArgs.Arguments",NewName="/Script/FPSTemplate.CommandLineArgs.CmdArguments")
|
+EnumRedirects=(OldName="/Script/FPSTemplate.EvalidationError",NewName="/Script/FPSTemplate.EValidationError")
|
||||||
|
+FunctionRedirects=(OldName="/Script/FPSTemplate.GameLiftValidators.LogValidataErrorMessage",NewName="/Script/FPSTemplate.GameLiftValidators.LogValidationErrorMessage")
|
||||||
|
;+PropertyRedirects=(OldName="/Script/FPSTemplate.CommandLineArgs.Arguments",NewName="/Script/FPSTemplate.CommandLineArgs.CmdArguments")
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
BIN
Content/Blueprints/Game/BP_ShooterGameModeBase.uasset
Normal file
BIN
Content/Blueprints/Game/BP_ShooterGameModeBase.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/API/ListFleets/WBP_FleetId.uasset
Normal file
BIN
Content/DedicatedServers/API/ListFleets/WBP_FleetId.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/API/ListFleets/WBP_ListFleetsBox.uasset
Normal file
BIN
Content/DedicatedServers/API/ListFleets/WBP_ListFleetsBox.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/APITest/BP_APITestManager.uasset
Normal file
BIN
Content/DedicatedServers/APITest/BP_APITestManager.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/APITest/UI/BP_APITestHUD.uasset
Normal file
BIN
Content/DedicatedServers/APITest/UI/BP_APITestHUD.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/APITest/UI/WBP_APITestOverlay.uasset
Normal file
BIN
Content/DedicatedServers/APITest/UI/WBP_APITestOverlay.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/Data/DA_GameSessionsAPIData.uasset
Normal file
BIN
Content/DedicatedServers/Data/DA_GameSessionsAPIData.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/Portal/BP_PortalHUD.uasset
Normal file
BIN
Content/DedicatedServers/Portal/BP_PortalHUD.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/Portal/BP_PortalManager.uasset
Normal file
BIN
Content/DedicatedServers/Portal/BP_PortalManager.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/Portal/WBP_JoinGame.uasset
Normal file
BIN
Content/DedicatedServers/Portal/WBP_JoinGame.uasset
Normal file
Binary file not shown.
BIN
Content/DedicatedServers/Portal/WBP_SignInOverlay.uasset
Normal file
BIN
Content/DedicatedServers/Portal/WBP_SignInOverlay.uasset
Normal file
Binary file not shown.
Binary file not shown.
@@ -12,6 +12,11 @@
|
|||||||
"Engine",
|
"Engine",
|
||||||
"UMG"
|
"UMG"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "DedicatedServers",
|
||||||
|
"Type": "Runtime",
|
||||||
|
"LoadingPhase": "Default"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"Plugins": [
|
"Plugins": [
|
||||||
|
|||||||
44
Source/DedicatedServers/DedicatedServers.Build.cs
Normal file
44
Source/DedicatedServers/DedicatedServers.Build.cs
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
|
using UnrealBuildTool;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public class DedicatedServers : ModuleRules
|
||||||
|
{
|
||||||
|
public DedicatedServers(ReadOnlyTargetRules Target) : base(Target)
|
||||||
|
{
|
||||||
|
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
|
PublicDependencyModuleNames.AddRange(new string[]
|
||||||
|
{
|
||||||
|
"Core",
|
||||||
|
"CoreUObject",
|
||||||
|
"Engine",
|
||||||
|
"GameplayTags",
|
||||||
|
"HTTP"
|
||||||
|
});
|
||||||
|
|
||||||
|
PrivateDependencyModuleNames.AddRange(new string[]
|
||||||
|
{
|
||||||
|
"Slate",
|
||||||
|
"SlateCore",
|
||||||
|
"OpenSSL",
|
||||||
|
"UMG",
|
||||||
|
"Json",
|
||||||
|
"JsonUtilities"
|
||||||
|
});
|
||||||
|
|
||||||
|
// Adds in the plugin for GameLiftServerSDK if it is the server build.
|
||||||
|
|
||||||
|
if (Target.Type == TargetType.Server)
|
||||||
|
{
|
||||||
|
PublicDependencyModuleNames.Add("GameLiftServerSDK");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PublicDefinitions.Add("WITH_GAMELIFT=0");
|
||||||
|
}
|
||||||
|
bEnableExceptions = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
Source/DedicatedServers/DedicatedServers.cpp
Normal file
8
Source/DedicatedServers/DedicatedServers.cpp
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
#include "DedicatedServers.h"
|
||||||
|
#include "Modules/ModuleManager.h"
|
||||||
|
|
||||||
|
IMPLEMENT_MODULE( FDefaultModuleImpl, DedicateServers );
|
||||||
|
|
||||||
|
DEFINE_LOG_CATEGORY(LogDedicatedServers);
|
||||||
7
Source/DedicatedServers/DedicatedServers.h
Normal file
7
Source/DedicatedServers/DedicatedServers.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
|
DECLARE_LOG_CATEGORY_EXTERN(LogDedicatedServers, Log, All)
|
||||||
11
Source/DedicatedServers/Private/Data/API/APIData.cpp
Normal file
11
Source/DedicatedServers/Private/Data/API/APIData.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Data/API/APIData.h"
|
||||||
|
|
||||||
|
FString UAPIData::GetAPIEndpoint(const FGameplayTag& APIEndpoint)
|
||||||
|
{
|
||||||
|
const FString ResourceName = Resources.FindChecked(APIEndpoint);
|
||||||
|
|
||||||
|
return InvokeUrl + "/" + Stage + "/" + ResourceName;
|
||||||
|
}
|
||||||
364
Source/DedicatedServers/Private/Game/DS_GameMode.cpp
Normal file
364
Source/DedicatedServers/Private/Game/DS_GameMode.cpp
Normal file
@@ -0,0 +1,364 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "DedicatedServers/Public/Game/DS_GameMode.h"
|
||||||
|
#include "openssl/sha.h"
|
||||||
|
#include "GameLift/GameLiftClp.h"
|
||||||
|
#if WITH_GAMELIFT
|
||||||
|
#include "GameLiftServerSDK.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
DEFINE_LOG_CATEGORY(LogDS_GameMode);
|
||||||
|
|
||||||
|
void ADS_GameMode::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADS_GameMode::InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage)
|
||||||
|
{
|
||||||
|
Super::InitGame(MapName, Options, ErrorMessage);
|
||||||
|
|
||||||
|
#if WITH_GAMELIFT
|
||||||
|
|
||||||
|
CachedCommandLine = FCommandLine::Get();
|
||||||
|
|
||||||
|
const FPortResult PortResult = cmdlineparser::details::GetConfiguredOrDefaultPort(CachedCommandLine, TEXT("port"));;
|
||||||
|
if (PortResult.bUsedDefaultPort)
|
||||||
|
{
|
||||||
|
UE_LOGFMT (LogDS_GameMode, Warning, "{0}", PortResult.WarningMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLiftConfig.ServerPort = PortResult.Port;
|
||||||
|
if (FParse::Param(*CachedCommandLine, TEXT("glAnywhereFleet")))
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Fleet type: Anywhere");
|
||||||
|
GameLiftConfig.bIsAnywhereFleet = true;
|
||||||
|
GameLiftConfig.bAllOptionsFound = GetAnywhereFleetParameters(CachedCommandLine);
|
||||||
|
LogAnywhereFleetParameters();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Fleet type: EC2");
|
||||||
|
// TODO: EC2 configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
FString ADS_GameMode::GetSHA256Hash(const FString& InString)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (InString.IsEmpty())
|
||||||
|
return TEXT("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
|
||||||
|
|
||||||
|
FSHA256Signature Hash;
|
||||||
|
|
||||||
|
// Use OpenSSL to compute the SHA-256 hash
|
||||||
|
|
||||||
|
FTCHARToUTF8 Utf8(InString);
|
||||||
|
const uint8* Bytes = reinterpret_cast<const uint8*>(Utf8.Get());
|
||||||
|
uint32 Length = Utf8.Length();
|
||||||
|
|
||||||
|
|
||||||
|
SHA256_CTX Sha256Context;
|
||||||
|
SHA256_Init(&Sha256Context);
|
||||||
|
SHA256_Update(&Sha256Context, Bytes,Length);
|
||||||
|
SHA256_Final(Hash.Signature, &Sha256Context);
|
||||||
|
|
||||||
|
return Hash.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADS_GameMode::InitGameLift()
|
||||||
|
{
|
||||||
|
#if WITH_GAMELIFT
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Calling InitGameLift...");
|
||||||
|
|
||||||
|
// Get the module first
|
||||||
|
FGameLiftServerSDKModule* GameLiftSdkModule = &FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>("GameLiftServerSDK");
|
||||||
|
FGameLiftGenericOutcome InitSdkOutcome;
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Initializing the GameLift Server...");
|
||||||
|
if (GameLiftConfig.bIsAnywhereFleet)
|
||||||
|
{
|
||||||
|
// Define the server parameters for an Anywhere fleet. These are not needed for a GameLift managed EC2 fleet.
|
||||||
|
FServerParameters ServerParametersForAnywhere;
|
||||||
|
|
||||||
|
uint32 PID = FPlatformProcess::GetCurrentProcessId();
|
||||||
|
FString PIDString = FString::FromInt(static_cast<int32>(PID));
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Configuring server parameters for Anywhere...");
|
||||||
|
// If AnywhereFleets are being used load the command line arguments parsed earlier.
|
||||||
|
ServerParametersForAnywhere.m_webSocketUrl = TCHAR_TO_UTF8(*GameLiftConfig.WebSocketUrlResult.Value);
|
||||||
|
ServerParametersForAnywhere.m_fleetId = TCHAR_TO_UTF8((*GameLiftConfig.FleetIdResult.Value));
|
||||||
|
ServerParametersForAnywhere.m_hostId = TCHAR_TO_UTF8(*GameLiftConfig.HostIdResult.Value);
|
||||||
|
ServerParametersForAnywhere.m_processId = PIDString;
|
||||||
|
ServerParametersForAnywhere.m_authToken = TCHAR_TO_UTF8(*GameLiftConfig.AuthTokenResult.Value);
|
||||||
|
LogServerParameters(ServerParametersForAnywhere);
|
||||||
|
|
||||||
|
// InitSDK will establish a local connection with GameLift's agent to enable further communication.
|
||||||
|
InitSdkOutcome = GameLiftSdkModule->InitSDK(ServerParametersForAnywhere);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
InitSdkOutcome = GameLiftSdkModule->InitSDK();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (InitSdkOutcome.IsSuccess())
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_GREEN);
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("GameLift InitSDK succeeded!"));
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_RED);
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("ERROR: InitSDK failed : ("));
|
||||||
|
FGameLiftError GameLiftError = InitSdkOutcome.GetError();
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("ERROR: %s"), *GameLiftError.m_errorMessage);
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessParameters = MakeShared<FProcessParameters>();
|
||||||
|
//When a game session is created, Amazon GameLift Servers sends an activation request to the game server and passes along the game session object containing game properties and other settings.
|
||||||
|
//Here is where a game server should take action based on the game session object.
|
||||||
|
//Once the game server is ready to receive incoming player connections, it should invoke GameLiftServerAPI.ActivateGameSession()
|
||||||
|
// ReSharper disable once CppPassValueParameterByConstReference - not safe to do with async lambdas
|
||||||
|
ProcessParameters->OnStartGameSession.BindLambda([=](Aws::GameLift::Server::Model::GameSession InGameSession)
|
||||||
|
{
|
||||||
|
const FString GameSessionId = FString(InGameSession.GetGameSessionId());
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("GameSession Initializing: %s"), *GameSessionId);
|
||||||
|
GameLiftSdkModule->ActivateGameSession();
|
||||||
|
});
|
||||||
|
|
||||||
|
//OnProcessTerminate callback. Amazon GameLift Servers will invoke this callback before shutting down an instance hosting this game server.
|
||||||
|
//It gives this game server a chance to save its state, communicate with services, etc., before being shut down.
|
||||||
|
//In this case, we simply tell Amazon GameLift Servers we are indeed going to shut down.
|
||||||
|
ProcessParameters->OnTerminate.BindLambda([=]()
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("Game Server Process is terminating"));
|
||||||
|
// First call ProcessEnding()
|
||||||
|
FGameLiftGenericOutcome processEndingOutcome = GameLiftSdkModule->ProcessEnding();
|
||||||
|
// Then call Destroy() to free the SDK from memory
|
||||||
|
FGameLiftGenericOutcome destroyOutcome = GameLiftSdkModule->Destroy();
|
||||||
|
// Exit the process with success or failure
|
||||||
|
if (processEndingOutcome.IsSuccess() && destroyOutcome.IsSuccess()) {
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("Server process ending successfully"));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!processEndingOutcome.IsSuccess()) {
|
||||||
|
const FGameLiftError& error = processEndingOutcome.GetError();
|
||||||
|
UE_LOG(LogDS_GameMode, Error, TEXT("ProcessEnding() failed. Error: %s"),
|
||||||
|
error.m_errorMessage.IsEmpty() ? TEXT("Unknown error") : *error.m_errorMessage);
|
||||||
|
}
|
||||||
|
if (!destroyOutcome.IsSuccess()) {
|
||||||
|
const FGameLiftError& error = destroyOutcome.GetError();
|
||||||
|
UE_LOG(LogDS_GameMode, Error, TEXT("Destroy() failed. Error: %s"),
|
||||||
|
error.m_errorMessage.IsEmpty() ? TEXT("Unknown error") : *error.m_errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GLog->Flush();
|
||||||
|
FGenericPlatformMisc::RequestExit(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
//This is the Health Check callback.
|
||||||
|
//Amazon GameLift Servers will invoke this callback every 60 seconds or so.
|
||||||
|
//Here, a game server might want to check the health of dependencies and such.
|
||||||
|
//Simply return true if healthy, false otherwise.
|
||||||
|
//The game server has 60 seconds to respond with its health status. Amazon GameLift Servers will default to 'false' if the game server doesn't respond in time.
|
||||||
|
//In this case, we're always healthy!
|
||||||
|
ProcessParameters->OnHealthCheck.BindLambda([]()
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("Performing Health Check"));
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
|
ProcessParameters->port = GameLiftConfig.ServerPort;
|
||||||
|
|
||||||
|
TArray<FString> Logfiles;
|
||||||
|
Logfiles.Add(TEXT("FPSTemplate/Saved/Log/server.log"));
|
||||||
|
ProcessParameters->logParameters = Logfiles;
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Calling Process Ready...");
|
||||||
|
FGameLiftGenericOutcome ProcessReadyOutcome = GameLiftSdkModule->ProcessReady(*ProcessParameters);
|
||||||
|
|
||||||
|
if (ProcessReadyOutcome.IsSuccess())
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_GREEN);
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("Process Ready!"));
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_RED);
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("ERROR: Process Ready Failed!"));
|
||||||
|
FGameLiftError ProcessReadyError = ProcessReadyOutcome.GetError();
|
||||||
|
UE_LOG(LogDS_GameMode, Log, TEXT("ERROR: %s"), *ProcessReadyError.m_errorMessage);
|
||||||
|
UE_LOG(LogDS_GameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "InitGameLift completed!");
|
||||||
|
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ADS_GameMode::GetAnywhereFleetParameters(const FString& CommandLineString)
|
||||||
|
{
|
||||||
|
bool bAllAnywhereFleetParametersValid = true;
|
||||||
|
GameLiftConfig.AuthTokenResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::AuthToken);
|
||||||
|
if (!GameLiftConfig.AuthTokenResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
||||||
|
|
||||||
|
GameLiftConfig.FleetIdResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::FleetId);
|
||||||
|
if (!GameLiftConfig.FleetIdResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
||||||
|
|
||||||
|
GameLiftConfig.HostIdResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::HostId);
|
||||||
|
if (!GameLiftConfig.HostIdResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
||||||
|
|
||||||
|
GameLiftConfig.WebSocketUrlResult = cmdlineparser::GetValueOfToken(CommandLineString, cmdlineparser::details::EAvailableTokens::WebsocketUrl);
|
||||||
|
if (!GameLiftConfig.WebSocketUrlResult.bIsValid) bAllAnywhereFleetParametersValid = false;
|
||||||
|
|
||||||
|
return bAllAnywhereFleetParametersValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADS_GameMode::LogAnywhereFleetParameters()
|
||||||
|
{
|
||||||
|
// Lambda for getting the token name from token
|
||||||
|
auto GetTokenName = [](const cmdlineparser::details::FParseResult& Result) -> FString
|
||||||
|
{
|
||||||
|
return cmdlineparser::details::CLI_TOKENS[static_cast<int32>(Result.Token)];
|
||||||
|
};
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Anywhere Fleet Parameters:");
|
||||||
|
if (GameLiftConfig.AuthTokenResult.bIsValid)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "AuthToken: {0}", GetValueOrHash(GameLiftConfig.AuthTokenResult.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(
|
||||||
|
LogDS_GameMode,
|
||||||
|
Error,
|
||||||
|
"AuthToken: {0}",
|
||||||
|
FString::Format(
|
||||||
|
*GameLiftConfig.AuthTokenResult.ErrorMessage,
|
||||||
|
{
|
||||||
|
FStringFormatArg(GetTokenName(GameLiftConfig.AuthTokenResult)),
|
||||||
|
FStringFormatArg(GetValueOrHash(GameLiftConfig.AuthTokenResult.Value)),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLiftConfig.FleetIdResult.bIsValid)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "FleetId: {0}", GameLiftConfig.FleetIdResult.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(
|
||||||
|
LogDS_GameMode,
|
||||||
|
Error,
|
||||||
|
"FleetId: {0}",
|
||||||
|
FString::Format(
|
||||||
|
*GameLiftConfig.FleetIdResult.ErrorMessage,
|
||||||
|
{
|
||||||
|
FStringFormatArg(GetTokenName(GameLiftConfig.FleetIdResult)),
|
||||||
|
FStringFormatArg(GameLiftConfig.FleetIdResult.Value)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLiftConfig.HostIdResult.bIsValid)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "HostId: {0}", GameLiftConfig.HostIdResult.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(
|
||||||
|
LogDS_GameMode,
|
||||||
|
Error,
|
||||||
|
"HostId: {0}",
|
||||||
|
FString::Format(
|
||||||
|
*GameLiftConfig.HostIdResult.ErrorMessage,
|
||||||
|
{
|
||||||
|
FStringFormatArg(GetTokenName(GameLiftConfig.HostIdResult)),
|
||||||
|
FStringFormatArg(GameLiftConfig.HostIdResult.Value)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GameLiftConfig.WebSocketUrlResult.bIsValid)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "WebSocketUrl: {0}", GameLiftConfig.WebSocketUrlResult.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(
|
||||||
|
LogDS_GameMode,
|
||||||
|
Error,
|
||||||
|
"WebSocketUrl: {0}",
|
||||||
|
FString::Format(
|
||||||
|
*GameLiftConfig.WebSocketUrlResult.ErrorMessage,
|
||||||
|
{
|
||||||
|
FStringFormatArg(GetTokenName(GameLiftConfig.WebSocketUrlResult)),
|
||||||
|
FStringFormatArg(GameLiftConfig.WebSocketUrlResult.Value)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Server Port: {0}", GameLiftConfig.ServerPort);
|
||||||
|
|
||||||
|
if (GameLiftConfig.bAllOptionsFound)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, "Anywhere Fleet Parameters Loaded Successfully....");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Error, "Anywhere Fleet Parameters Load FAILED....");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ADS_GameMode::LogServerParameters(const FServerParameters& InServerParameters)
|
||||||
|
{
|
||||||
|
#if WITH_GAMELIFT
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> WebSocket URL: {WebSocketUrl}", InServerParameters.m_webSocketUrl);
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Fleet ID: {FleetId}", InServerParameters.m_fleetId);
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Process ID: {ProcessId}", InServerParameters.m_processId);
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Host ID (Compute Name): {HostId}", InServerParameters.m_hostId);
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Auth Token: {AuthToken}", GetValueOrHash(InServerParameters.m_authToken));
|
||||||
|
|
||||||
|
if (!InServerParameters.m_awsRegion.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Aws Region: {AwsRegion}", InServerParameters.m_awsRegion);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InServerParameters.m_accessKey.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Access Key: {AccessKey}", GetValueOrHash(InServerParameters.m_accessKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InServerParameters.m_secretKey.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Secret Key: {SecretKey}", GetValueOrHash(InServerParameters.m_secretKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!InServerParameters.m_sessionToken.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDS_GameMode, Log, ">>>> Session Token: {SessionToken}", GetValueOrHash(InServerParameters.m_sessionToken));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
FString ADS_GameMode::GetValueOrHash(const FString& Value)
|
||||||
|
{
|
||||||
|
#if UE_BUILD_DEBUG || UE_BUILD_DEVELOPMENT
|
||||||
|
return Value;
|
||||||
|
#else
|
||||||
|
return TEXT("HASH:") + GetSHA256Hash(Value);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
100
Source/DedicatedServers/Private/GameLift/GameLiftClp.cpp
Normal file
100
Source/DedicatedServers/Private/GameLift/GameLiftClp.cpp
Normal file
@@ -0,0 +1,100 @@
|
|||||||
|
#include "GameLift/GameLiftClp.h"
|
||||||
|
|
||||||
|
FPortResult cmdlineparser::GetConfiguredOrDefaultPort(const FString& Token)
|
||||||
|
{
|
||||||
|
return details::GetConfiguredOrDefaultPort(FCommandLine::Get(), Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
FPortResult cmdlineparser::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||||
|
{
|
||||||
|
return details::GetConfiguredOrDefaultPort(CommandLine, Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
cmdlineparser::details::FParseResult cmdlineparser::GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token)
|
||||||
|
{
|
||||||
|
details::FParseResult Result;
|
||||||
|
FString ValueOfToken;
|
||||||
|
Result.Token = Token;
|
||||||
|
|
||||||
|
ensure(Token != details::EAvailableTokens::Unknown);
|
||||||
|
ensure(Token < details::EAvailableTokens::MaxToken);
|
||||||
|
const bool bTokenFound = FParse::Value(
|
||||||
|
*CommandLine,
|
||||||
|
*details::EnsureEndsWith(details::CLI_TOKENS[static_cast<int32>(Token)],
|
||||||
|
TEXT("=")),
|
||||||
|
ValueOfToken
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!bTokenFound)
|
||||||
|
{
|
||||||
|
Result.Value = FString();
|
||||||
|
Result.ErrorCode = details::EErrorCodes::TokenNotFound;
|
||||||
|
Result.bIsValid = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ValueOfToken.IsEmpty())
|
||||||
|
{
|
||||||
|
Result.Value = FString();
|
||||||
|
Result.ErrorCode = details::EErrorCodes::ValueEmpty;
|
||||||
|
Result.bIsValid = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (details::DoesRegExMatch(ValueOfToken, details::REGEX_PATTERNS[static_cast<int32>(Token)]))
|
||||||
|
{
|
||||||
|
Result.ErrorCode = details::EErrorCodes::NoError;
|
||||||
|
Result.bIsValid = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Result.ErrorCode = details::EErrorCodes::FailedValidation;
|
||||||
|
Result.bIsValid = false;
|
||||||
|
}
|
||||||
|
Result.Value = ValueOfToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure(Result.ErrorCode < details::EErrorCodes::MaxCode);
|
||||||
|
FString ErrorMessage = details::ERROR_MESSAGES[static_cast<int32>(Result.ErrorCode)];
|
||||||
|
FString TokenName = details::CLI_TOKENS[static_cast<int32>(Result.Token)];
|
||||||
|
FString Value = Result.Value;
|
||||||
|
Result.ErrorMessage = ErrorMessage;
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// cmdlineparser::Details namespace
|
||||||
|
|
||||||
|
FString cmdlineparser::details::EnsureEndsWith(const FString& Token, const TCHAR* Suffix)
|
||||||
|
{
|
||||||
|
return Token.EndsWith(Suffix) ? Token : Token + Suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
FPortResult cmdlineparser::details::GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token)
|
||||||
|
{
|
||||||
|
FPortResult PortResult;
|
||||||
|
PortResult.Port = FURL::UrlConfig.DefaultPort;
|
||||||
|
|
||||||
|
if (int32 CliPort; FParse::Value(*CommandLine, *EnsureEndsWith(Token, TEXT("=")), CliPort))
|
||||||
|
{
|
||||||
|
if (CliPort >= details::MIN_PORT && CliPort <= details::MAX_PORT)
|
||||||
|
{
|
||||||
|
PortResult.Port = CliPort;
|
||||||
|
PortResult.bUsedDefaultPort = false;
|
||||||
|
PortResult.WarningMessage = FString();
|
||||||
|
return PortResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PortResult.bUsedDefaultPort = true;
|
||||||
|
PortResult.WarningMessage = FString("Command Line Option for Port is out of ranged... Using Default Port %s", PortResult.Port);
|
||||||
|
return PortResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cmdlineparser::details::DoesRegExMatch(const FString& Text, const FString& Pattern)
|
||||||
|
{
|
||||||
|
const FRegexPattern RegexPattern(Pattern);
|
||||||
|
FRegexMatcher Matcher(RegexPattern, Text);
|
||||||
|
return Matcher.FindNext();
|
||||||
|
}
|
||||||
34
Source/DedicatedServers/Private/GameLiftClpTypes.cpp
Normal file
34
Source/DedicatedServers/Private/GameLiftClpTypes.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "GameLiftClpTypes.h"
|
||||||
|
|
||||||
|
const TArray<FString>& cmdlineparser::details::ERROR_MESSAGES = []() -> const TArray<FString>&
|
||||||
|
{
|
||||||
|
static TArray<FString> Error_Messages;
|
||||||
|
Error_Messages.Add(TEXT("VALID: {0}: {1}"));
|
||||||
|
Error_Messages.Add(TEXT("INVALID TOKEN: [-{0}=] not found in command line arguments"));
|
||||||
|
Error_Messages.Add(TEXT("EMPTY VALUE: [-{0}=] found. No value assigned"));
|
||||||
|
Error_Messages.Add(TEXT("VALIDATION FAILED: [-{0}=] found.... Value: [{1}]"));
|
||||||
|
return Error_Messages;
|
||||||
|
}();
|
||||||
|
|
||||||
|
|
||||||
|
const TArray<FString>& cmdlineparser::details::CLI_TOKENS = []() -> const TArray<FString>&
|
||||||
|
{
|
||||||
|
static TArray<FString> Cli_Tokens;
|
||||||
|
Cli_Tokens.Add(TEXT("unknown")); // Unknown = 0;
|
||||||
|
Cli_Tokens.Add(TEXT("authtoken"));
|
||||||
|
Cli_Tokens.Add(TEXT("hostid"));
|
||||||
|
Cli_Tokens.Add(TEXT("fleetid"));
|
||||||
|
Cli_Tokens.Add(TEXT("websocketurl"));
|
||||||
|
return Cli_Tokens;
|
||||||
|
}();
|
||||||
|
|
||||||
|
const TArray<FString>& cmdlineparser::details::REGEX_PATTERNS = []() -> const TArray<FString>&
|
||||||
|
{
|
||||||
|
static TArray<FString> Cli_Tokens;
|
||||||
|
Cli_Tokens.Add(TEXT(".*")); // unknown = 0
|
||||||
|
Cli_Tokens.Add(TEXT("^[a-zA-Z0-9\\-]+$"));
|
||||||
|
Cli_Tokens.Add(TEXT("^[a-zA-Z0-9][a-zA-Z0-9\\-]{0,62}[a-zA-Z0-9]?$"));
|
||||||
|
Cli_Tokens.Add(TEXT("^[a-z]*fleet-[a-zA-Z0-9\\-]+$|^arn:.*:[a-z]*fleet\\/[a-z]*fleet-[a-zA-Z0-9\\-]+$"));
|
||||||
|
Cli_Tokens.Add(TEXT("^wss://[a-z0-9-]+(\\.[a-z0-9-]+)*\\.api\\.amazongamelift\\.com(:[0-9]+)?/?$"));
|
||||||
|
return Cli_Tokens;
|
||||||
|
}();
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#include "GameplayTags/DedicatedServersTags.h"
|
||||||
|
|
||||||
|
namespace DedicatedServersTags
|
||||||
|
{
|
||||||
|
namespace GameSessionsAPI
|
||||||
|
{
|
||||||
|
UE_DEFINE_GAMEPLAY_TAG_COMMENT(ListFleets, "DedicatedServersTags.GameSessionsAPI.ListFleets", "List Fleets resource on the Game Session Resource")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/API/GameSessions/JoinGame.h"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/API/ListFleets/FleetId.h"
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/API/ListFleets/ListFleetsBox.h"
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/API_Test/APITestManager.h"
|
||||||
|
#include "HttpModule.h"
|
||||||
|
#include "JsonObjectConverter.h"
|
||||||
|
#include "Data/API/APIData.h"
|
||||||
|
#include "DedicatedServers/DedicatedServers.h"
|
||||||
|
#include "GameplayTags/DedicatedServersTags.h"
|
||||||
|
#include "Interfaces/IHttpResponse.h"
|
||||||
|
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||||
|
|
||||||
|
void UAPITestManager::ListFleets()
|
||||||
|
{
|
||||||
|
check(APIData);
|
||||||
|
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
|
||||||
|
Request->OnProcessRequestComplete().BindUObject(this, &UAPITestManager::ListFleets_Response);
|
||||||
|
const FString APIUrl = APIData->GetAPIEndpoint(DedicatedServersTags::GameSessionsAPI::ListFleets);
|
||||||
|
Request->SetURL(APIUrl);
|
||||||
|
Request->SetVerb(TEXT("GET"));
|
||||||
|
Request->SetHeader(TEXT("Content-Type"), TEXT("application/json"));
|
||||||
|
Request->ProcessRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "List Fleets Response Received");
|
||||||
|
|
||||||
|
TSharedPtr<FJsonObject> JsonObject;
|
||||||
|
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
|
||||||
|
|
||||||
|
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||||
|
{
|
||||||
|
const TSharedPtr<FJsonObject>* ErrorObjPtr = nullptr;;
|
||||||
|
|
||||||
|
if (ContainsErrors(JsonObject, false))
|
||||||
|
{
|
||||||
|
OnListFleetsResponseReceived.Broadcast(FDS_ListFleetsResponse(), false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DumpMetaData(JsonObject);
|
||||||
|
|
||||||
|
FDS_ListFleetsResponse ListFleetsResponse;
|
||||||
|
FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), &ListFleetsResponse);
|
||||||
|
ListFleetsResponse.Dump();
|
||||||
|
OnListFleetsResponseReceived.Broadcast(ListFleetsResponse, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#include "UI/API_Test/APITestOverlay.h"
|
||||||
|
#include "UI/API_Test/APITestManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include "Components/Button.h"
|
||||||
|
#include "Components/ScrollBox.h"
|
||||||
|
#include "Components/TextBlock.h"
|
||||||
|
#include "UI/API/ListFleets/FleetId.h"
|
||||||
|
#include "UI/API/ListFleets/ListFleetsBox.h"
|
||||||
|
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||||
|
|
||||||
|
|
||||||
|
void UAPITestOverlay::NativeConstruct()
|
||||||
|
{
|
||||||
|
Super::NativeConstruct();
|
||||||
|
|
||||||
|
check(APITestManagerClass);
|
||||||
|
APITestManager = NewObject<UAPITestManager>(this, APITestManagerClass);
|
||||||
|
|
||||||
|
check (ListFleetsBox)
|
||||||
|
check (ListFleetsBox->Button_ListFleets)
|
||||||
|
ListFleetsBox->Button_ListFleets->OnClicked.AddDynamic(this, &UAPITestOverlay::ListFleetsButtonClicked);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAPITestOverlay::ListFleetsButtonClicked()
|
||||||
|
{
|
||||||
|
check(APITestManager);
|
||||||
|
APITestManager->OnListFleetsResponseReceived.AddDynamic(this, &UAPITestOverlay::OnListFleetsResponseReceived);
|
||||||
|
APITestManager->ListFleets();
|
||||||
|
|
||||||
|
ListFleetsBox->Button_ListFleets->SetIsEnabled(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UAPITestOverlay::OnListFleetsResponseReceived(const FDS_ListFleetsResponse& ListFleetResponse, bool bWasSuccessful)
|
||||||
|
{
|
||||||
|
if (APITestManager->OnListFleetsResponseReceived.IsAlreadyBound(this, &UAPITestOverlay::OnListFleetsResponseReceived))
|
||||||
|
{
|
||||||
|
APITestManager->OnListFleetsResponseReceived.RemoveDynamic(this, &UAPITestOverlay::OnListFleetsResponseReceived);
|
||||||
|
}
|
||||||
|
check(FleetIdWidgetClass);
|
||||||
|
ListFleetsBox->ScrollBox_ListFleets->ClearChildren();
|
||||||
|
if (bWasSuccessful)
|
||||||
|
{
|
||||||
|
for (const FString& FleetId : ListFleetResponse.FleetIds)
|
||||||
|
{
|
||||||
|
UFleetId* FleetIdWidget = CreateWidget<UFleetId>(this, FleetIdWidgetClass);
|
||||||
|
FleetIdWidget->TextBlock_FleetId->SetText(FText::FromString(FleetId));
|
||||||
|
ListFleetsBox->ScrollBox_ListFleets->AddChild(FleetIdWidget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UFleetId* FleetIdWidget = CreateWidget<UFleetId>(this, FleetIdWidgetClass);
|
||||||
|
FleetIdWidget->TextBlock_FleetId->SetText(FText::FromString("Something went wrong!"));
|
||||||
|
ListFleetsBox->ScrollBox_ListFleets->AddChild(FleetIdWidget);
|
||||||
|
}
|
||||||
|
ListFleetsBox->Button_ListFleets->SetIsEnabled(true);
|
||||||
|
}
|
||||||
17
Source/DedicatedServers/Private/UI/API_Test/API_TestHUD.cpp
Normal file
17
Source/DedicatedServers/Private/UI/API_Test/API_TestHUD.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/API_Test/API_TestHUD.h"
|
||||||
|
#include "UI/API_Test/APITestOverlay.h"
|
||||||
|
|
||||||
|
void AAPI_TestHUD::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
APlayerController* PlayerController = GetOwningPlayerController();
|
||||||
|
if (IsValid(PlayerController) && APITestOverlayClass)
|
||||||
|
{
|
||||||
|
APITestOverlay = CreateWidget<UAPITestOverlay>(PlayerController, APITestOverlayClass);
|
||||||
|
APITestOverlay->AddToViewport();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/HTTP/HTTPRequestManager.h"
|
||||||
|
|
||||||
|
#include "HTTPRequestTypes.h"
|
||||||
|
#include "JsonObjectConverter.h"
|
||||||
|
#include "DedicatedServers/DedicatedServers.h"
|
||||||
|
|
||||||
|
bool UHTTPRequestManager::ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bSuppressLog)
|
||||||
|
{
|
||||||
|
if (JsonObject->HasField(TEXT("errorType")) || JsonObject->HasField(TEXT("errorMessage")))
|
||||||
|
{
|
||||||
|
if (!bSuppressLog)
|
||||||
|
{
|
||||||
|
FString ErrorType = JsonObject->HasField(TEXT("errorType")) ? JsonObject->GetStringField(TEXT("errorType")) : TEXT("Unknown Error");
|
||||||
|
FString ErrorMessage = JsonObject->HasField(TEXT("errorMessage")) ? JsonObject->GetStringField(TEXT("errorMessage")) : TEXT("Unknown Error Message");
|
||||||
|
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Type: {ErrorType}", ErrorType);
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Message: {ErrorMessage}", ErrorMessage);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (JsonObject->HasField(TEXT("$fault")))
|
||||||
|
{
|
||||||
|
if (!bSuppressLog)
|
||||||
|
{
|
||||||
|
FString ErrorType = JsonObject->HasField(TEXT("name")) ? JsonObject->GetStringField(TEXT("name")) : TEXT("Unknown Error");
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Error, "Error Type: {ErrorType}", ErrorType);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UHTTPRequestManager::DumpMetaData(TSharedPtr<FJsonObject> JsonObject)
|
||||||
|
{
|
||||||
|
if (JsonObject->HasField(TEXT("$metadata")))
|
||||||
|
{
|
||||||
|
TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
|
||||||
|
FDS_MetaData DSMetaData;
|
||||||
|
FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
|
||||||
|
DSMetaData.Dump();
|
||||||
|
}
|
||||||
|
}
|
||||||
24
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
24
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||||
|
#include "DedicatedServers/DedicatedServers.h"
|
||||||
|
|
||||||
|
void FDS_MetaData::Dump() const
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "MetaData:");
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "httpStatusCode: {httpStatusCode}", httpStatusCode);
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "requestId: {requestId}", requestId);
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "attemps: {attempts}", attempts);
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "totalRetryDelay: {totalRetryDelay}", totalRetryDelay);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FDS_ListFleetsResponse::Dump() const
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "ListFleetsResponse:");
|
||||||
|
for (const FString& FleetId : FleetIds)
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "FleetId: {FleetId}", FleetId);
|
||||||
|
}
|
||||||
|
if (!NextToken.IsEmpty())
|
||||||
|
{
|
||||||
|
UE_LOGFMT(LogDedicatedServers, Log, "NextToken: {NextToken}", NextToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
43
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal file
43
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
// Because this is in the private section is is still usable by the DedicatedServer Module, but not outside of the module.
|
||||||
|
|
||||||
|
#include "HTTPRequestTypes.generated.h"
|
||||||
|
|
||||||
|
USTRUCT()
|
||||||
|
struct FDS_MetaData
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
int32 httpStatusCode{};
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
FString requestId{};
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
int32 attempts{};
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
double totalRetryDelay{};
|
||||||
|
|
||||||
|
void Dump() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
USTRUCT()
|
||||||
|
struct FDS_ListFleetsResponse
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TArray<FString> FleetIds{};
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
FString NextToken{};
|
||||||
|
|
||||||
|
void Dump() const;
|
||||||
|
};
|
||||||
23
Source/DedicatedServers/Private/UI/Portal/PortalHUD.cpp
Normal file
23
Source/DedicatedServers/Private/UI/Portal/PortalHUD.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/Portal/PortalHUD.h"
|
||||||
|
#include "UI/Portal/SignIn/SignInOverlay.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
|
||||||
|
void APortalHUD::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
|
||||||
|
APlayerController* OwningPlayerController = GetOwningPlayerController();
|
||||||
|
SignInOverlay = CreateWidget<USignInOverlay>(OwningPlayerController, SignInOverlayClass);
|
||||||
|
if (IsValid(SignInOverlay))
|
||||||
|
{
|
||||||
|
SignInOverlay->AddToViewport();
|
||||||
|
}
|
||||||
|
|
||||||
|
const FInputModeGameAndUI InputModeData;
|
||||||
|
OwningPlayerController->SetInputMode(InputModeData);
|
||||||
|
OwningPlayerController->SetShowMouseCursor(true);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/Portal/PortalManager.h"
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "UI/Portal/SignIn/SignInOverlay.h"
|
||||||
|
|
||||||
|
#include "UI/Portal/PortalManager.h"
|
||||||
|
|
||||||
|
void USignInOverlay::NativeConstruct()
|
||||||
|
{
|
||||||
|
Super::NativeConstruct();
|
||||||
|
check(PortalManagerClass);
|
||||||
|
|
||||||
|
PortalManager = NewObject<UPortalManager>(PortalManagerClass);
|
||||||
|
}
|
||||||
38
Source/DedicatedServers/Public/Data/API/APIData.h
Normal file
38
Source/DedicatedServers/Public/Data/API/APIData.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Engine/DataAsset.h"
|
||||||
|
#include "GameplayTags/DedicatedServersTags.h"
|
||||||
|
#include "APIData.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UAPIData : public UDataAsset
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
FString GetAPIEndpoint(const FGameplayTag& APIEndpoint);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Name of the API - for labeling in the Data Asset; this is not used by any code.
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere)
|
||||||
|
FString Name;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
FString InvokeUrl;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
FString Stage;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TMap<FGameplayTag, FString> Resources;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
50
Source/DedicatedServers/Public/Game/DS_GameMode.h
Normal file
50
Source/DedicatedServers/Public/Game/DS_GameMode.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "DedicatedServers/Public/GameLiftClpTypes.h"
|
||||||
|
#include "GameFramework/GameMode.h"
|
||||||
|
#include "DS_GameMode.generated.h"
|
||||||
|
|
||||||
|
DECLARE_LOG_CATEGORY_EXTERN(LogDS_GameMode, Log, All);
|
||||||
|
|
||||||
|
struct FProcessParameters;
|
||||||
|
struct FServerParameters;
|
||||||
|
|
||||||
|
struct FGameLiftConfig
|
||||||
|
{
|
||||||
|
bool bIsAnywhereFleet = false;
|
||||||
|
bool bAllOptionsFound = false;
|
||||||
|
|
||||||
|
int32 ServerPort = 7777;
|
||||||
|
|
||||||
|
cmdlineparser::details::FParseResult AuthTokenResult;
|
||||||
|
cmdlineparser::details::FParseResult FleetIdResult;
|
||||||
|
cmdlineparser::details::FParseResult HostIdResult;
|
||||||
|
cmdlineparser::details::FParseResult WebSocketUrlResult;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API ADS_GameMode : public AGameMode
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
virtual void InitGame(const FString& MapName, const FString& Options, FString& ErrorMessage) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
FGameLiftConfig GameLiftConfig;
|
||||||
|
FString CachedCommandLine;
|
||||||
|
TSharedPtr<FProcessParameters> ProcessParameters;
|
||||||
|
|
||||||
|
static FString GetSHA256Hash(const FString& InString);
|
||||||
|
void InitGameLift();
|
||||||
|
|
||||||
|
bool GetAnywhereFleetParameters(const FString& CommandLineString);
|
||||||
|
void LogAnywhereFleetParameters();
|
||||||
|
static void LogServerParameters(const FServerParameters& InServerParameters);
|
||||||
|
static FString GetValueOrHash(const FString& Value);
|
||||||
|
};
|
||||||
30
Source/DedicatedServers/Public/GameLift/GameLiftClp.h
Normal file
30
Source/DedicatedServers/Public/GameLift/GameLiftClp.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "GameLiftClpTypes.h"
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
|
||||||
|
struct FPortResult
|
||||||
|
{
|
||||||
|
int32 Port;
|
||||||
|
bool bUsedDefaultPort;
|
||||||
|
FString WarningMessage;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace cmdlineparser
|
||||||
|
{
|
||||||
|
FPortResult GetConfiguredOrDefaultPort(const FString& Token = TEXT("port="));
|
||||||
|
FPortResult GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token = TEXT("port="));
|
||||||
|
|
||||||
|
details::FParseResult GetValueOfToken(const FString& CommandLine, const details::EAvailableTokens Token);
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace cmdlineparser::details
|
||||||
|
{
|
||||||
|
inline static constexpr int32 MIN_PORT = 1024;
|
||||||
|
inline static constexpr int32 MAX_PORT = 65535;
|
||||||
|
inline static constexpr const TCHAR* DEFAULT_PORT_TOKEN = TEXT("port=");
|
||||||
|
|
||||||
|
FString EnsureEndsWith(const FString& Token, const TCHAR* Suffix);
|
||||||
|
FPortResult GetConfiguredOrDefaultPort(const FString& CommandLine, const FString& Token);
|
||||||
|
bool DoesRegExMatch(const FString& Text, const FString& Pattern);
|
||||||
|
}
|
||||||
|
|
||||||
37
Source/DedicatedServers/Public/GameLiftClpTypes.h
Normal file
37
Source/DedicatedServers/Public/GameLiftClpTypes.h
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace cmdlineparser::details
|
||||||
|
{
|
||||||
|
enum EAvailableTokens
|
||||||
|
{
|
||||||
|
Unknown = 0,
|
||||||
|
AuthToken,
|
||||||
|
HostId,
|
||||||
|
FleetId,
|
||||||
|
WebsocketUrl,
|
||||||
|
MaxToken
|
||||||
|
};
|
||||||
|
|
||||||
|
enum EErrorCodes
|
||||||
|
{
|
||||||
|
NoError,
|
||||||
|
TokenNotFound,
|
||||||
|
ValueEmpty,
|
||||||
|
FailedValidation,
|
||||||
|
MaxCode
|
||||||
|
};
|
||||||
|
|
||||||
|
extern const TArray<FString>& ERROR_MESSAGES;
|
||||||
|
extern const TArray<FString>& CLI_TOKENS;
|
||||||
|
extern const TArray<FString>& REGEX_PATTERNS;
|
||||||
|
|
||||||
|
struct FParseResult
|
||||||
|
{
|
||||||
|
EAvailableTokens Token = EAvailableTokens::Unknown;
|
||||||
|
FString Value = FString();
|
||||||
|
bool bIsValid = false;
|
||||||
|
EErrorCodes ErrorCode = EErrorCodes::TokenNotFound;
|
||||||
|
FString ErrorMessage = FString();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "NativeGameplayTags.h"
|
||||||
|
|
||||||
|
namespace DedicatedServersTags
|
||||||
|
{
|
||||||
|
namespace GameSessionsAPI
|
||||||
|
{
|
||||||
|
UE_DECLARE_GAMEPLAY_TAG_EXTERN(ListFleets)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "JoinGame.generated.h"
|
||||||
|
|
||||||
|
class UButton;
|
||||||
|
class UTextBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UJoinGame : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UButton> Button_JoinGame;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UTextBlock> TextBlock_StatusMessage;
|
||||||
|
};
|
||||||
23
Source/DedicatedServers/Public/UI/API/ListFleets/FleetId.h
Normal file
23
Source/DedicatedServers/Public/UI/API/ListFleets/FleetId.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "FleetId.generated.h"
|
||||||
|
|
||||||
|
class UTextBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UFleetId : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget), BlueprintReadWrite)
|
||||||
|
TObjectPtr<UTextBlock> TextBlock_FleetId;
|
||||||
|
};
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "ListFleetsBox.generated.h"
|
||||||
|
|
||||||
|
class UButton;
|
||||||
|
class UScrollBox;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UListFleetsBox : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UScrollBox> ScrollBox_ListFleets;
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UButton> Button_ListFleets;
|
||||||
|
};
|
||||||
29
Source/DedicatedServers/Public/UI/API_Test/APITestManager.h
Normal file
29
Source/DedicatedServers/Public/UI/API_Test/APITestManager.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Interfaces/IHttpRequest.h"
|
||||||
|
#include "UI/HTTP/HTTPRequestManager.h"
|
||||||
|
#include "APITestManager.generated.h"
|
||||||
|
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnListFleetsResponseReceived, const FDS_ListFleetsResponse&, ListFleetResponse, bool, bWasSuccessful);
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UAPITestManager : public UHTTPRequestManager
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ListFleets();
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
FOnListFleetsResponseReceived OnListFleetsResponseReceived;
|
||||||
|
|
||||||
|
void ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
|
||||||
|
};
|
||||||
50
Source/DedicatedServers/Public/UI/API_Test/APITestOverlay.h
Normal file
50
Source/DedicatedServers/Public/UI/API_Test/APITestOverlay.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "APITestOverlay.generated.h"
|
||||||
|
|
||||||
|
class UAPITestManager;
|
||||||
|
class UListFleetsBox;
|
||||||
|
struct FDS_ListFleetsResponse;
|
||||||
|
class UFleetId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UAPITestOverlay : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<UAPITestManager> APITestManagerClass;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<UFleetId> FleetIdWidgetClass;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UListFleetsBox> ListFleetsBox;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<UAPITestManager> APITestManager;
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void ListFleetsButtonClicked();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnListFleetsResponseReceived(const FDS_ListFleetsResponse& ListFleetResponse, bool bWasSuccessful);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
29
Source/DedicatedServers/Public/UI/API_Test/API_TestHUD.h
Normal file
29
Source/DedicatedServers/Public/UI/API_Test/API_TestHUD.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/HUD.h"
|
||||||
|
#include "API_TestHUD.generated.h"
|
||||||
|
|
||||||
|
class UAPITestOverlay;
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API AAPI_TestHUD : public AHUD
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<UAPITestOverlay> APITestOverlayClass;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<UAPITestOverlay> APITestOverlay;
|
||||||
|
|
||||||
|
};
|
||||||
28
Source/DedicatedServers/Public/UI/HTTP/HTTPRequestManager.h
Normal file
28
Source/DedicatedServers/Public/UI/HTTP/HTTPRequestManager.h
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UObject/Object.h"
|
||||||
|
#include "HTTPRequestManager.generated.h"
|
||||||
|
|
||||||
|
class UAPIData;
|
||||||
|
class FJsonObject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS(Blueprintable)
|
||||||
|
class DEDICATEDSERVERS_API UHTTPRequestManager : public UObject
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TObjectPtr<UAPIData> APIData;
|
||||||
|
|
||||||
|
bool ContainsErrors(TSharedPtr<FJsonObject> JsonObject, bool bSuppressLog = true);
|
||||||
|
void DumpMetaData(TSharedPtr<FJsonObject> JsonObject);
|
||||||
|
|
||||||
|
};
|
||||||
32
Source/DedicatedServers/Public/UI/Portal/PortalHUD.h
Normal file
32
Source/DedicatedServers/Public/UI/Portal/PortalHUD.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "GameFramework/HUD.h"
|
||||||
|
#include "PortalHUD.generated.h"
|
||||||
|
|
||||||
|
class USignInOverlay;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API APortalHUD : public AHUD
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<USignInOverlay> SignInOverlayClass;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<USignInOverlay> SignInOverlay;
|
||||||
|
};
|
||||||
16
Source/DedicatedServers/Public/UI/Portal/PortalManager.h
Normal file
16
Source/DedicatedServers/Public/UI/Portal/PortalManager.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "UI/HTTP/HTTPRequestManager.h"
|
||||||
|
#include "PortalManager.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API UPortalManager : public UHTTPRequestManager
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
};
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "SignInOverlay.generated.h"
|
||||||
|
|
||||||
|
class UJoinGame;
|
||||||
|
class UPortalManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class DEDICATEDSERVERS_API USignInOverlay : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
UPROPERTY(meta = (BindWidget))
|
||||||
|
TObjectPtr<UJoinGame> JoinGameWidget;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly)
|
||||||
|
TSubclassOf<UPortalManager> PortalManagerClass;
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void NativeConstruct() override;
|
||||||
|
private:
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<UPortalManager> PortalManager;
|
||||||
|
};
|
||||||
@@ -11,5 +11,6 @@ public class FPSTemplateTarget : TargetRules
|
|||||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||||
ExtraModuleNames.Add("FPSTemplate");
|
ExtraModuleNames.Add("FPSTemplate");
|
||||||
|
ExtraModuleNames.Add("DedicatedServers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// Copyright Epic Games, Inc. All Rights Reserved.
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
||||||
|
|
||||||
|
using System.IO;
|
||||||
using UnrealBuildTool;
|
using UnrealBuildTool;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
public class FPSTemplate : ModuleRules
|
public class FPSTemplate : ModuleRules
|
||||||
{
|
{
|
||||||
@@ -8,21 +10,25 @@ public class FPSTemplate : ModuleRules
|
|||||||
{
|
{
|
||||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||||
|
|
||||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "PhysicsCore" });
|
PublicDependencyModuleNames.AddRange(new string[]
|
||||||
|
|
||||||
PrivateDependencyModuleNames.AddRange(new string[] { "GameplayTags", "Slate", "SlateCore" });
|
|
||||||
|
|
||||||
// Adds in the plugin for GameLiftServerSDK if it is the server build.
|
|
||||||
|
|
||||||
if (Target.Type == TargetType.Server)
|
|
||||||
{
|
{
|
||||||
PublicDependencyModuleNames.Add("GameLiftServerSDK");
|
"Core",
|
||||||
}
|
"CoreUObject",
|
||||||
else
|
"Engine",
|
||||||
|
"InputCore",
|
||||||
|
"EnhancedInput",
|
||||||
|
"PhysicsCore",
|
||||||
|
"OpenSSL",
|
||||||
|
"DedicatedServers"
|
||||||
|
});
|
||||||
|
|
||||||
|
PrivateDependencyModuleNames.AddRange(new string[]
|
||||||
{
|
{
|
||||||
PublicDefinitions.Add("WITH_GAMELIFT=0");
|
"GameplayTags",
|
||||||
}
|
"Slate",
|
||||||
bEnableExceptions = true;
|
"SlateCore",
|
||||||
|
"OpenSSL",
|
||||||
|
});
|
||||||
|
|
||||||
// Uncomment if you are using Slate UI
|
// Uncomment if you are using Slate UI
|
||||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||||
|
|||||||
@@ -1,295 +0,0 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
|
||||||
|
|
||||||
|
|
||||||
#include "Game/ShooterGameMode.h"
|
|
||||||
|
|
||||||
#include "DSP/BufferDiagnostics.h"
|
|
||||||
#include "UObject/ConstructorHelpers.h"
|
|
||||||
#include "Kismet/GameplayStatics.h"
|
|
||||||
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
#include "GameLiftServerSDKModels.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "GenericPlatform/GenericPlatformOutputDevices.h"
|
|
||||||
#include "Misc/TypeContainer.h"
|
|
||||||
|
|
||||||
DEFINE_LOG_CATEGORY(LogShooterGameMode)
|
|
||||||
|
|
||||||
AShooterGameMode::AShooterGameMode()
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing ShooterGameMode..."));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::BeginPlay()
|
|
||||||
{
|
|
||||||
Super::BeginPlay();
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
InitGameLift();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
|
|
||||||
// ReSharper disable once CppMemberFunctionMayBeConst - cannot be const due to FCommandLine::Get() and UE_LOG with non-const log category
|
|
||||||
bool AShooterGameMode::SetParametersFromCommandLine(FServerParameters& OutServerParameters,
|
|
||||||
FProcessParameters& OutProcessParameters)
|
|
||||||
{
|
|
||||||
bool bCriticalFault = false;
|
|
||||||
|
|
||||||
FString CommandLine = FCommandLine::Get();
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>> Command Line: %s"), *CommandLine);
|
|
||||||
|
|
||||||
// Checks if param exists (returns bool)
|
|
||||||
|
|
||||||
// AuthToken returned from the "aws gamelift get-compute-auth-token" API. Note this will expire and require a new call to the API after 15 minutes.
|
|
||||||
bCriticalFault |= ValidateServerParameters(CommandLine, TEXT("authtoken"),OutServerParameters.m_authToken);
|
|
||||||
|
|
||||||
// The Host/compute-name of the GameLift Anywhere instance
|
|
||||||
bCriticalFault |= ValidateServerParameters(CommandLine, TEXT("hostid"),OutServerParameters.m_hostId);
|
|
||||||
|
|
||||||
// The AnywhereFleet ID.
|
|
||||||
bCriticalFault |= ValidateServerParameters(CommandLine, TEXT("fleetid"),OutServerParameters.m_fleetId);
|
|
||||||
|
|
||||||
// The WebSocket URL (GameLiftServiceSdkEndpoint)
|
|
||||||
bCriticalFault |= ValidateServerParameters(CommandLine, TEXT("websocketurl"),OutServerParameters.m_webSocketUrl);
|
|
||||||
|
|
||||||
// The port being used, uses UE system default if not entered as a switch
|
|
||||||
OutProcessParameters.port = FURL::UrlConfig.DefaultPort;
|
|
||||||
FParse::Value(*CommandLine, TEXT("port="), OutProcessParameters.port);
|
|
||||||
|
|
||||||
LogServerSummary(OutServerParameters,OutProcessParameters);
|
|
||||||
|
|
||||||
return bCriticalFault;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::LogServerParameters(const FServerParameters& InServerParameters)
|
|
||||||
{
|
|
||||||
// Log Server Parameters
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_YELLOW);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>> WebSocket URL: %s"), *InServerParameters.m_webSocketUrl);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Fleet ID: %s"), *InServerParameters.m_fleetId);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Process ID: %s"), *InServerParameters.m_processId);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Host ID (Compute Name): %s"), *InServerParameters.m_hostId);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Auth Token: %s"), *InServerParameters.m_authToken);
|
|
||||||
// UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Aws Region: %s"), *ServerParameters.m_awsRegion);
|
|
||||||
// UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Access Key: %s"), *ServerParameters.m_accessKey);
|
|
||||||
// UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Secret Key: %s"), *ServerParameters.m_secretKey);
|
|
||||||
// UE_LOG(LogShooterGameMode, Log, TEXT(">>>> Session Token: %s"), *ServerParameters.m_sessionToken);
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::SetProcessIdOnServerParameters(FServerParameters& OutServerParameters)
|
|
||||||
{
|
|
||||||
// The PID of the running process
|
|
||||||
#if PLATFORM_WINDOWS
|
|
||||||
OutServerParameters.m_processId = FString::Printf(TEXT("%d"), GetCurrentProcessId());
|
|
||||||
#else
|
|
||||||
OutServerParameters.m_processId = FString::Printf(TEXT("%d"), FGenericPlatformProcess::GetCurrentProcessId());
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AShooterGameMode::ValidateServerParameters(const FString& CommandLine, const FString& ParameterName,
|
|
||||||
FString& OutValue, const bool bCritical)
|
|
||||||
{
|
|
||||||
if (!FParse::Value(*CommandLine, *FString::Printf(TEXT("%s="), *ParameterName), OutValue))
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Warning, TEXT("-%s not found"), *ParameterName);
|
|
||||||
return bCritical;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::LogServerSummary(const FServerParameters& InServerParameters,
|
|
||||||
const FProcessParameters& InProcessParameters)
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_YELLOW);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("=== SERVER STARTUP SUMMARY ==="));
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Port: %d"), InProcessParameters.port);
|
|
||||||
|
|
||||||
// Inline validation of ServerParams
|
|
||||||
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, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule)
|
|
||||||
{
|
|
||||||
// Implement callback function onStartGameSession
|
|
||||||
// GameLift sends a game session activation request to the game server
|
|
||||||
// and passes a game session object with game properties and other settings.
|
|
||||||
// Here is where a game server takes action based on the game session object.
|
|
||||||
// When the game server is ready to receive incoming player connections,
|
|
||||||
// it invokes the server SDK call ActivateGameSession().
|
|
||||||
|
|
||||||
|
|
||||||
ProcessParameters.OnStartGameSession.BindLambda([this, &GameLiftSdkModule](Aws::GameLift::Server::Model::GameSession InGameSession)
|
|
||||||
{
|
|
||||||
FString GameSessionId = FString(InGameSession.GetGameSessionId());
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("GameSession Initializing: %s"), *GameSessionId);
|
|
||||||
FGameLiftGenericOutcome ActivateGameSessionOutcome = GameLiftSdkModule.ActivateGameSession();
|
|
||||||
if (ActivateGameSessionOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Activate GameSession successful"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const FGameLiftError& Error = ActivateGameSessionOutcome.GetError();
|
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT("ActivateGameSession() failed. Error: %s"), Error.m_errorMessage.IsEmpty() ? TEXT("Unknown Error") : *Error.m_errorMessage);
|
|
||||||
FPlatformMisc::RequestExit(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ProcessParameters.OnTerminate.BindLambda([this, &GameLiftSdkModule]()
|
|
||||||
{
|
|
||||||
FGameLiftGenericOutcome ProcessEndingOutcome = GameLiftSdkModule.ProcessEnding();
|
|
||||||
FGameLiftGenericOutcome DestroyOutcome = GameLiftSdkModule.Destroy();
|
|
||||||
if (ProcessEndingOutcome.IsSuccess() && DestroyOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Server process ending successfully"));
|
|
||||||
FPlatformMisc::RequestExit(false);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!ProcessEndingOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
const FGameLiftError& Error = ProcessEndingOutcome.GetError();
|
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT("ProcessEnding() failed. Error: %s"), Error.m_errorMessage.IsEmpty() ? TEXT("Unknown Error") : *Error.m_errorMessage);
|
|
||||||
}
|
|
||||||
if (!DestroyOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
const FGameLiftError& Error = DestroyOutcome.GetError();
|
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT("Destroy() failed. Error: %s"), Error.m_errorMessage.IsEmpty() ? TEXT("Unknown error") : *Error.m_errorMessage);
|
|
||||||
}
|
|
||||||
FPlatformMisc::RequestExit(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ProcessParameters.OnHealthCheck.BindLambda([=]()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Here, the game server tells GameLift where to find game session Log files.
|
|
||||||
// At the end of a game session, GameLift uploads everything in the specified
|
|
||||||
// location and stores it in the cloud for access later.
|
|
||||||
|
|
||||||
TArray<FString> LogFiles;
|
|
||||||
FString LogDirectory =FPaths::ProjectSavedDir() / TEXT("Logs");
|
|
||||||
FString LogFile = LogDirectory / TEXT("GameLiftServer.log");
|
|
||||||
LogFiles.Add(LogFile);
|
|
||||||
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Before Adding Log Files"));
|
|
||||||
ProcessParameters.logParameters = LogFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AShooterGameMode::InitiateProcessReady(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule)
|
|
||||||
{
|
|
||||||
// The game server calls ProcessReady() to tell Amazon GameLift Servers it's ready to host game sessions.
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Calling Process Ready..."));
|
|
||||||
FGameLiftGenericOutcome ProcessReadyOutcome = GameLiftSdkModule.ProcessReady(ProcessParameters);
|
|
||||||
|
|
||||||
if (ProcessReadyOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_GREEN);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Process Ready!"));
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_RED);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("ERROR: Process Ready Failed!"));
|
|
||||||
FGameLiftError ProcessReadyError = ProcessReadyOutcome.GetError();
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("ERROR: %s"), *ProcessReadyError.m_errorMessage);
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("InitGameLift completed!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AShooterGameMode::InitiateConnectionWithGameLiftAgent(FServerParameters& ServerParameters, FGameLiftServerSDKModule& GameLiftSdkModule)
|
|
||||||
{
|
|
||||||
// InitSDK will establish a local connection with GameLift's agent to enable further communication
|
|
||||||
|
|
||||||
FGameLiftGenericOutcome InitSdkOutcome = GameLiftSdkModule.InitSDK(ServerParameters);
|
|
||||||
if (InitSdkOutcome.IsSuccess())
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_GREEN);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("GameLift Init SDK Succeeded"));
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_RED);
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("ERROR: InitSDK failed : ("));
|
|
||||||
FGameLiftError GameLiftError = InitSdkOutcome.GetError();
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("ERROR: %s"), *GameLiftError.m_errorMessage);
|
|
||||||
UE_LOG(LogShooterGameMode, SetColor, TEXT("%s"), COLOR_NONE);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void AShooterGameMode::InitGameLift()
|
|
||||||
{
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Calling InitGameLift"));
|
|
||||||
|
|
||||||
FServerParameters ServerParameters;
|
|
||||||
FProcessParameters ProcessParameters;
|
|
||||||
|
|
||||||
// Getting the module first.
|
|
||||||
FGameLiftServerSDKModule& GameLiftSdkModule = FModuleManager::LoadModuleChecked<FGameLiftServerSDKModule>(FName("GameLiftServerSDK"));
|
|
||||||
|
|
||||||
// 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")))
|
|
||||||
{
|
|
||||||
bIsAnywhereActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bIsAnywhereActive)
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Configuring server parameters for Anywhere..."));
|
|
||||||
if (SetParametersFromCommandLine(ServerParameters, ProcessParameters))
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Error, TEXT("Critical Error, shutting server down..."));
|
|
||||||
FPlatformMisc::RequestExit(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetProcessIdOnServerParameters(ServerParameters);
|
|
||||||
if (ServerParameters.m_processId.IsEmpty())
|
|
||||||
{
|
|
||||||
UE_LOG(LogShooterGameMode, Warning, TEXT("ProcessId is empty"));
|
|
||||||
FPlatformMisc::RequestExit(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
LogServerParameters(ServerParameters);
|
|
||||||
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing the GameLift Server..."));
|
|
||||||
|
|
||||||
BindGameLiftCallbackFunctions(ProcessParameters, GameLiftSdkModule);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Using EC2
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Using Gamelift EC2 Managed Fleet"));
|
|
||||||
|
|
||||||
// EC2: Bind Callbacks (populates logParameters automatically)
|
|
||||||
BindGameLiftCallbackFunctions(ProcessParameters, GameLiftSdkModule);
|
|
||||||
|
|
||||||
// EC2: Empty ServerParameters = GameLift agent provies all config
|
|
||||||
UE_LOG(LogShooterGameMode, Log, TEXT("Initializing EC2 GameLift Server..."));
|
|
||||||
}
|
|
||||||
if (InitiateConnectionWithGameLiftAgent(ServerParameters, GameLiftSdkModule)) return;
|
|
||||||
InitiateProcessReady(ProcessParameters, GameLiftSdkModule);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
@@ -1,246 +0,0 @@
|
|||||||
// Fill out your copyright notice in the Description page of Project Settings.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
|
||||||
#include "ShooterGameModeBase.h"
|
|
||||||
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
#include "GameLiftServerSDK.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#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);
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
UCLASS()
|
|
||||||
class FPSTEMPLATE_API AShooterGameMode : public AShooterGameModeBase
|
|
||||||
{
|
|
||||||
GENERATED_BODY()
|
|
||||||
|
|
||||||
public:
|
|
||||||
AShooterGameMode();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual void BeginPlay() override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void InitGameLift();
|
|
||||||
#if WITH_GAMELIFT
|
|
||||||
bool SetParametersFromCommandLine(FServerParameters& OutServerParameters, FProcessParameters& OutProcessParameters);
|
|
||||||
static void LogServerParameters(const FServerParameters& InServerParameters);
|
|
||||||
void SetProcessIdOnServerParameters(FServerParameters& OutServerParameters);
|
|
||||||
bool ValidateServerParameters(const FString& CommandLine, const FString& ParameterName, FString& OutValue, const bool bCritical = true);
|
|
||||||
void LogServerSummary(const FServerParameters& InServerParameters, const FProcessParameters& InProcessParameters);
|
|
||||||
void BindGameLiftCallbackFunctions(FProcessParameters& ProcessParameters,
|
|
||||||
FGameLiftServerSDKModule& GameLiftSdkModule);
|
|
||||||
void InitiateProcessReady(FProcessParameters& ProcessParameters, FGameLiftServerSDKModule& GameLiftSdkModule);
|
|
||||||
bool InitiateConnectionWithGameLiftAgent(FServerParameters& ServerParameters,
|
|
||||||
FGameLiftServerSDKModule& GameLiftSdkModule);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -3,14 +3,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "GameFramework/GameMode.h"
|
#include "Game/DS_GameMode.h"
|
||||||
#include "ShooterGameModeBase.generated.h"
|
#include "ShooterGameModeBase.generated.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class FPSTEMPLATE_API AShooterGameModeBase : public AGameMode
|
class FPSTEMPLATE_API AShooterGameModeBase : public ADS_GameMode
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ public class FPSTemplateClientTarget : TargetRules
|
|||||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||||
ExtraModuleNames.Add("FPSTemplate");
|
ExtraModuleNames.Add("FPSTemplate");
|
||||||
|
ExtraModuleNames.Add("DedicatedServers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ public class FPSTemplateEditorTarget : TargetRules
|
|||||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||||
ExtraModuleNames.Add("FPSTemplate");
|
ExtraModuleNames.Add("FPSTemplate");
|
||||||
|
ExtraModuleNames.Add("DedicatedServers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,5 +11,6 @@ public class FPSTemplateServerTarget : TargetRules
|
|||||||
DefaultBuildSettings = BuildSettingsVersion.V6;
|
DefaultBuildSettings = BuildSettingsVersion.V6;
|
||||||
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
IncludeOrderVersion = EngineIncludeOrderVersion.Unreal5_7;
|
||||||
ExtraModuleNames.Add("FPSTemplate");
|
ExtraModuleNames.Add("FPSTemplate");
|
||||||
|
ExtraModuleNames.Add("DedicatedServers");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user