From f78e308daa6af5c8fee3c460b3da81dce904f9f2 Mon Sep 17 00:00:00 2001
From: FluxCapacitor2 <31071265+FluxCapacitor2@users.noreply.github.com>
Date: Sun, 3 Dec 2023 23:21:48 -0500
Subject: [PATCH] Allow customization of Agones healthcheck and reservation
 periods with environment variables

---
 README.md                                             | 11 +++++++++++
 .../server/bootstrap/prod/AgonesIntegration.kt        |  5 +++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index dcb5438a..27533f7a 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,17 @@ This uses the `Dockerfile` in the current directory to build an image with the v
 
 Environment variables:
 * `PUFFIN_VELOCITY_SECRET` - Your Velocity proxy forwarding secret (optional). If not specified, Mojang authentication will be enabled.
+* `BLUEDRAGON_AGONES_HEALTHCHECK_INTERVAL_MS` - The amount of time in between Agones healthcheck pings, in milliseconds.
+* `BLUEDRAGON_AGONES_RESERVATION_TIME_MS` - The amount of time in between Agones server reservations, in milliseconds.
+* `BLUEDRAGON_AGONES_DISABLED` - Disables Agones integration if set to any value.
+* `BLUEDRAGON_ENV_TYPE` - Set to "DEV" to enable development mode.
+* `BLUEDRAGON_QUEUE_TYPE` - Set to "IPC" to use Puffin or "TEST" for the `TestQueue`. If not present, a default value is inferred.
+* `BLUEDRAGON_MONGO_HOSTNAME` - The hostname used to connect to MongoDB.
+* `BLUEDRAGON_PUFFIN_HOSTNAME` - The hostname used to connect to Puffin.
+* `BLUEDRAGON_LUCKPERMS_HOSTNAME` - The hostname used to connect to LuckPerms.
+* `HOSTNAME` - Used to determine the server name. Provided by default in Docker or Kubernetes environments.
+* `SERVER_INSTANCE_MIN_INACTIVE_TIME` - The amount of time that an instance must be inactive before it is cleaned up.
+* `SERVER_INSTANCE_CLEANUP_PERIOD` - The amount of time in between instance cleanup tasks.
 
 ## Implementation
 To learn how to integrate other server software with BlueDragon's systems, see the [Integration Guide](./INTEGRATION.md)
diff --git a/src/main/kotlin/com/bluedragonmc/server/bootstrap/prod/AgonesIntegration.kt b/src/main/kotlin/com/bluedragonmc/server/bootstrap/prod/AgonesIntegration.kt
index 8ae64fe0..e1bbf19a 100644
--- a/src/main/kotlin/com/bluedragonmc/server/bootstrap/prod/AgonesIntegration.kt
+++ b/src/main/kotlin/com/bluedragonmc/server/bootstrap/prod/AgonesIntegration.kt
@@ -24,10 +24,11 @@ object AgonesIntegration : Bootstrap(EnvType.PRODUCTION) {
     lateinit var stub: SDKGrpcKt.SDKCoroutineStub
 
     // The amount of milliseconds in between health check pings
-    private const val HEALTH_CHECK_INTERVAL = 10_000L
+    private val HEALTH_CHECK_INTERVAL = System.getenv("BLUEDRAGON_AGONES_HEALTHCHECK_INTERVAL_MS")?.toLongOrNull() ?: 10_000L
 
     // When players are online, keep the server reserved for twice the healthcheck interval.
-    private const val RESERVATION_TIME = HEALTH_CHECK_INTERVAL * 2L
+    private val RESERVATION_TIME =
+        System.getenv("BLUEDRAGON_AGONES_RESERVATION_TIME_MS")?.toLongOrNull() ?: (HEALTH_CHECK_INTERVAL * 2L)
 
     override fun hook(eventNode: EventNode<Event>) {