Skip to content

Commit

Permalink
Add dynamic configuration of the sidecar http port to the unreal sdk. (
Browse files Browse the repository at this point in the history
  • Loading branch information
roberthbailey authored and markmandel committed Oct 22, 2019
1 parent 08e1ee8 commit 6c179c3
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions sdks/unreal/Agones/Agones.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"FileVersion": 4,
"Version": 1,
"VersionName": "0.1",
"VersionName": "0.2",
"FriendlyName": "Agones",
"Description": "Unreal Engine Plugin for Agones Game Server Client",
"Category": "Google",
Expand Down
19 changes: 13 additions & 6 deletions sdks/unreal/Agones/Source/Agones/AgonesHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@

#include "AgonesHook.h"
#include "AgonesSettings.h"
#include "GenericPlatform/GenericPlatformMisc.h"
#include "Runtime/Online/HTTP/Public/Http.h"

#define LOCTEXT_NAMESPACE "AgonesHook"
DEFINE_LOG_CATEGORY(LogAgonesHook);

static FString GetSidecarAddress()
{
FString port = FPlatformMisc::GetEnvironmentVariable(TEXT("AGONES_SDK_HTTP_PORT"));
return FString(TEXT("http://localhost:")) + (!port.IsEmpty() ? port : FString(TEXT("59358")));
}

FAgonesHook::FAgonesHook()
: FTickableGameObject()
, CurrentHealthTime(0.0f)
, Settings(nullptr)
, SidecarAddress(GetSidecarAddress())
, ReadySuffix(FString(TEXT("/ready")))
, HealthSuffix(FString(TEXT("/health")))
, ShutdownSuffix(FString(TEXT("/shutdown")))
Expand All @@ -31,7 +39,7 @@ FAgonesHook::FAgonesHook()
check(Settings != nullptr);

UE_LOG(LogAgonesHook, Log, TEXT("Initialized Agones Hook, Sidecar address: %s, Health Enabled: %s, Health Ping: %f, Debug: %s")
, *Settings->AgonesSidecarAddress
, *SidecarAddress
, (Settings->bHealthPingEnabled ? TEXT("True") : TEXT("False"))
, Settings->HealthPingSeconds
, (Settings->bDebugLogEnabled ? TEXT("True") : TEXT("False")));
Expand Down Expand Up @@ -80,20 +88,19 @@ static TSharedRef<IHttpRequest> MakeRequest(const FString& URL)

void FAgonesHook::Ready()
{
SendRequest(Settings->AgonesSidecarAddress + ReadySuffix);
SendRequest(SidecarAddress + ReadySuffix);
}

void FAgonesHook::Health()
{
SendRequest(Settings->AgonesSidecarAddress + HealthSuffix);
SendRequest(SidecarAddress + HealthSuffix);
}

void FAgonesHook::Shutdown()
{
SendRequest(Settings->AgonesSidecarAddress + ShutdownSuffix);
SendRequest(SidecarAddress + ShutdownSuffix);
}


bool FAgonesHook::SendRequest(const FString& URL)
{
TSharedRef<IHttpRequest> req = MakeRequest(URL);
Expand All @@ -112,4 +119,4 @@ bool FAgonesHook::SendRequest(const FString& URL)
return bSuccess;
}

#undef LOCTEXT_NAMESPACE
#undef LOCTEXT_NAMESPACE
3 changes: 2 additions & 1 deletion sdks/unreal/Agones/Source/Agones/AgonesHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class FAgonesHook : public FTickableGameObject
/** Agones settings */
const class UAgonesSettings* Settings;

const FString SidecarAddress;
const FString ReadySuffix;
const FString HealthSuffix;
const FString ShutdownSuffix;
};
};
1 change: 0 additions & 1 deletion sdks/unreal/Agones/Source/Agones/AgonesSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

UAgonesSettings::UAgonesSettings()
: Super()
, AgonesSidecarAddress("http://localhost:59358")
, bHealthPingEnabled(true)
, HealthPingSeconds(5.0f)
, bDebugLogEnabled(false)
Expand Down
3 changes: 0 additions & 3 deletions sdks/unreal/Agones/Source/Agones/Public/AgonesSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ class AGONES_API UAgonesSettings : public UObject
/** Default constructor */
UAgonesSettings();

UPROPERTY(EditAnywhere, config, Category = "Agones", meta = (DisplayName = "Agones Sidecar IP Address"))
FString AgonesSidecarAddress;

UPROPERTY(EditAnywhere, config, Category = "Agones", meta = (DisplayName = "Health Ping Enabled"))
bool bHealthPingEnabled;

Expand Down
3 changes: 0 additions & 3 deletions site/content/en/docs/Guides/Client SDKs/unreal.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ Available settings:
{{% feature expiryVersion="1.1.0" %}}
- Agones Sidecar IP. (default: `http://localhost:59358`)
{{% /feature %}}
{{% feature publishVersion="1.1.0" %}}
- Agones Sidecar IP. (default: `http://localhost:${AGONES_SDK_HTTP_PORT}`)
{{% /feature %}}
- Health Ping Enabled. Whether the server sends a health ping to the Agones sidecar. (default: `true`)
- Health Ping Seconds. Interval of the server sending a health ping to the Agones sidecar. (default: `5`)
- Debug Logging Enabled. Debug logging for development of this Plugin. (default: `false`)
Expand Down

0 comments on commit 6c179c3

Please sign in to comment.