mirror of
https://github.com/AndrioCelos/TableturfBattleApp.git
synced 2026-10-03 07:39:34 -05:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user