Add client count to DreamDaemon responses

Closes #1909
This commit is contained in:
Jordan Dominion
2024-08-31 21:58:17 -04:00
parent c5341b4471
commit 442ad80017
12 changed files with 40 additions and 6 deletions
+2 -2
View File
@@ -9,8 +9,8 @@
<TgsCommonLibraryVersion>7.0.0</TgsCommonLibraryVersion>
<TgsApiLibraryVersion>13.7.0</TgsApiLibraryVersion>
<TgsClientVersion>16.0.0</TgsClientVersion>
<TgsDmapiVersion>7.2.1</TgsDmapiVersion>
<TgsInteropVersion>5.9.0</TgsInteropVersion>
<TgsDmapiVersion>7.3.0</TgsDmapiVersion>
<TgsInteropVersion>5.10.0</TgsInteropVersion>
<TgsHostWatchdogVersion>1.5.0</TgsHostWatchdogVersion>
<TgsContainerScriptVersion>1.2.1</TgsContainerScriptVersion>
<TgsMigratorVersion>2.0.0</TgsMigratorVersion>
+1 -1
View File
@@ -1,7 +1,7 @@
// tgstation-server DMAPI
// The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in IETF RFC 2119.
#define TGS_DMAPI_VERSION "7.2.1"
#define TGS_DMAPI_VERSION "7.3.0"
// All functions and datums outside this document are subject to change with any version and should not be relied on.
+1 -1
View File
@@ -1 +1 @@
"5.9.0"
"5.10.0"
+1
View File
@@ -95,6 +95,7 @@
#define DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION "newServerVersion"
#define DMAPI5_TOPIC_PARAMETER_BROADCAST_MESSAGE "broadcastMessage"
#define DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT "clientCount"
#define DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE "commandResponse"
#define DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE "commandResponseMessage"
#define DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES "chatResponses"
+3 -1
View File
@@ -149,7 +149,9 @@
if(DMAPI5_TOPIC_COMMAND_HEALTHCHECK)
if(event_handler && event_handler.receive_health_checks)
event_handler.HandleEvent(TGS_EVENT_HEALTH_CHECK)
return TopicResponse()
var/list/health_check_response = TopicResponse()
health_check_response[DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT] = TGS_CLIENT_COUNT
return health_check_response;
if(DMAPI5_TOPIC_COMMAND_WATCHDOG_REATTACH)
detached = FALSE
+2 -1
View File
@@ -17,8 +17,8 @@
#undef DMAPI5_BRIDGE_COMMAND_EVENT
#undef DMAPI5_PARAMETER_ACCESS_IDENTIFIER
#undef DMAPI5_PARAMETER_CLIENT_COUNT
#undef DMAPI5_PARAMETER_CUSTOM_COMMANDS
#undef DMAPI5_PARAMETER_TOPIC_PORT
#undef DMAPI5_CHUNK
#undef DMAPI5_CHUNK_PAYLOAD
@@ -95,6 +95,7 @@
#undef DMAPI5_TOPIC_PARAMETER_NEW_SERVER_VERSION
#undef DMAPI5_TOPIC_PARAMETER_BROADCAST_MESSAGE
#undef DMAPI5_TOPIC_RESPONSE_CLIENT_COUNT
#undef DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE
#undef DMAPI5_TOPIC_RESPONSE_COMMAND_RESPONSE_MESSAGE
#undef DMAPI5_TOPIC_RESPONSE_CHAT_RESPONSES
@@ -19,6 +19,12 @@ namespace Tgstation.Server.Api.Models.Internal
[ResponseOptions]
public DateTimeOffset? LaunchTime { get; set; }
/// <summary>
/// The last known count of connected players. Requires <see cref="DreamDaemonLaunchParameters.HealthCheckSeconds"/> to not be 0 and a game server interop version >= 5.10.0 to populate.
/// </summary>
[ResponseOptions]
public int? ClientCount { get; set; }
/// <summary>
/// If the server is undergoing a soft reset. This may be automatically set by changes to other fields.
/// </summary>
@@ -36,5 +36,10 @@ namespace Tgstation.Server.Host.Components.Interop.Topic
/// <inheritdoc />
public IReadOnlyCollection<uint>? MissingChunks { get; set; }
/// <summary>
/// The number of connected clients to the game. Added in Interop 5.10.0.
/// </summary>
public int? ClientCount { get; }
}
}
@@ -24,6 +24,11 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// </summary>
DateTimeOffset? LaunchTime { get; }
/// <summary>
/// Last known client count queried from the DMAPI. Requires health checks to be enabled to populate.
/// </summary>
int? ClientCount { get; }
/// <summary>
/// The current <see cref="WatchdogStatus"/>.
/// </summary>
@@ -38,6 +38,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <inheritdoc />
public long? SessionId => GetActiveController()?.ReattachInformation.Id;
/// <inheritdoc />
public int? ClientCount { get; private set; }
/// <inheritdoc />
public DateTimeOffset? LaunchTime => GetActiveController()?.LaunchTime;
@@ -570,6 +573,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
// since neither server is running, this is safe to do
LastLaunchParameters = ActiveLaunchParameters;
healthChecksMissed = 0;
ClientCount = null;
try
{
@@ -667,6 +671,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
// we lost the server, just restart entirely
// DCT: Operation must always run
await DisposeAndNullControllers(CancellationToken.None);
ClientCount = null;
const string FailReattachMessage = "Unable to properly reattach to server! Restarting watchdog...";
Logger.LogWarning(FailReattachMessage);
@@ -1183,7 +1188,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
}
}
else
{
healthChecksMissed = 0;
ClientCount = response.ClientCount;
}
return MonitorAction.Continue;
}
@@ -367,6 +367,7 @@ namespace Tgstation.Server.Host.Controllers
result.Status = dd.Status;
result.SessionId = dd.SessionId;
result.LaunchTime = dd.LaunchTime;
result.ClientCount = dd.ClientCount;
}
while (result.Status == WatchdogStatus.Online && !result.SessionId.HasValue); // this is the one invalid combo, it's not that racy
@@ -753,6 +753,9 @@ namespace Tgstation.Server.Tests.Live.Instance
Assert.IsTrue(daemonStatus.LaunchTime.HasValue);
Assert.IsTrue(daemonStatus.LaunchTime.Value >= DateTimeOffset.UtcNow.AddHours(-1));
if (daemonStatus.ClientCount.HasValue)
Assert.AreEqual(0, daemonStatus.ClientCount.Value);
if (sessionIdTracker.HasValue)
if (knownIncrease.HasValue)
if (knownIncrease.Value)
@@ -861,6 +864,8 @@ namespace Tgstation.Server.Tests.Live.Instance
// Ensure it's responding to health checks
await Task.WhenAny(Task.Delay(7000, cancellationToken), ourProcessHandler.Lifetime);
Assert.IsFalse(ddProc.HasExited);
var daemonStatus = await instanceClient.DreamDaemon.Read(cancellationToken);
Assert.AreEqual(0, daemonStatus.ClientCount);
// check DD agrees
var topicRequestResult = await SendTestTopic(