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:
parent
ceb0eeb36b
commit
ecaecd21bb
9 changed files with 242 additions and 3 deletions
17
LANCommander.Server/Hubs/PlaySession.cs
Normal file
17
LANCommander.Server/Hubs/PlaySession.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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}";
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue