Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic configuration of the sidecar http port to the unreal sdk. #1131

Merged
merged 1 commit into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I've removed this as a setting in the unreal editor. The code no longer uses the setting (and the setting no longer exists) so it should not be documented.

I've previously changed it to reference the environment variable (even though I hadn't updated the code) but as I looked at the code I realized it didn't make sense as a setting.

{{% /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