Send keepalive while game is running

Sends a keepalive/heartbeat signal across RPC while a game is running. Server-side this enables the ability to manage play session state with realtime information instead of hoping that the client will stop the play session. Keepalives are tracked in server cache allowing for future potential horizontally-scaled server instances.
This commit is contained in:
Pat Hartl 2026-06-14 00:53:19 -05:00
parent ceb0eeb36b
commit ecaecd21bb
9 changed files with 242 additions and 3 deletions

View file

@ -0,0 +1,17 @@
namespace LANCommander.Server.Hubs;
public partial class RpcHub
{
public async Task GameKeepAliveAsync(Guid gameId)
{
try
{
if (Guid.TryParse(Context.UserIdentifier, out var userId))
await keepAliveTracker.TouchAsync(gameId, userId);
}
catch (Exception ex)
{
logger.LogError(ex, "Failed to record keepalive for game {GameId}", gameId);
}
}
}

View file

@ -16,7 +16,8 @@ public partial class RpcHub(
ServerService serverService,
GameService gameService,
ScriptDebugger scriptDebugger,
ScriptClient scriptClient) : Hub<IRpcSubscriber>, IRpcHub
ScriptClient scriptClient,
PlaySessionKeepAliveTracker keepAliveTracker) : Hub<IRpcSubscriber>, IRpcHub
{
private string GetConnectionsCacheKey(string userIdentifier) => $"RPC/Connections/{userIdentifier}";