Track inactive games and add a command to lock the server for updates

A game that has had no activity for 5 minutes is considered inactive. There can be a limited number of inactive games before they are deleted. A console command is added that will wait for all games to become inactive before stopping the server, and prevent starting new games.
This commit is contained in:
Andrio Celos
2022-12-28 00:03:10 +11:00
parent 7a7d03d165
commit 673eb18aa9
4 changed files with 65 additions and 7 deletions

View File

@@ -5,8 +5,10 @@ using WebSocketSharp.Server;
namespace TableturfBattleServer;
internal class TableturfWebSocketBehaviour : WebSocketBehavior {
public Guid GameID { get; set; }
public Guid ClientToken { get; set; }
public Guid GameID { get; private set; }
public Guid ClientToken { get; private set; }
public Game? Game { get; private set; }
public Player? Player { get; private set; }
protected override void OnOpen() {
var args = this.Context.RequestUri.Query[1..].Split('&').Select(s => s.Split('=', 2)).Where(a => a.Length == 2)
@@ -17,11 +19,13 @@ internal class TableturfWebSocketBehaviour : WebSocketBehavior {
this.ClientToken = clientToken;
// Send an initial state payload.
if (Program.games.TryGetValue(this.GameID, out var game)) {
if (Program.TryGetGame(this.GameID, out var game)) {
this.Game = game;
DTO.PlayerData? playerData = null;
for (int i = 0; i < game.Players.Count; i++) {
var player = game.Players[i];
if (player.Token == this.ClientToken) {
this.Player = player;
playerData = new(i, player);
break;
}