From b933b3d01485151b3ccb61060d3aa864d426165d Mon Sep 17 00:00:00 2001 From: aqw42 Date: Fri, 30 May 2025 23:11:20 +0200 Subject: [PATCH] Changed from lastping to ws.close --- src/server/GameServer.ts | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/server/GameServer.ts b/src/server/GameServer.ts index 3bcf80ba7..ad8f60759 100644 --- a/src/server/GameServer.ts +++ b/src/server/GameServer.ts @@ -235,10 +235,12 @@ export class GameServer { this.activeClients = this.activeClients.filter( (c) => c.clientID !== client.clientID, ); + this.markClientDisconnected(client, true); }); client.ws.on("error", (error: Error) => { if ((error as any).code === "WS_ERR_UNEXPECTED_RSV_1") { client.ws.close(1002); + this.markClientDisconnected(client, true); } }); @@ -359,7 +361,6 @@ export class GameServer { this.intents = []; this.handleSynchronization(); - this.checkDisconnectedStatus(); let msg = ""; try { @@ -444,6 +445,7 @@ export class GameServer { }); if (client.ws.readyState === WebSocket.OPEN) { client.ws.close(1000, "no heartbeats received, closing connection"); + this.markClientDisconnected(client, true); } } else { alive.push(client); @@ -529,6 +531,7 @@ export class GameServer { persistentID: client.persistentID, }); client.ws.close(1000, "Kicked from game"); + this.markClientDisconnected(client, true); this.activeClients = this.activeClients.filter( (c) => c.clientID !== clientID, ); @@ -540,27 +543,6 @@ export class GameServer { } } - private checkDisconnectedStatus() { - if (this.turns.length % 5 !== 0) { - return; - } - - const now = Date.now(); - for (const [clientID, client] of this.allClients) { - if ( - client.isDisconnected === false && - now - client.lastPing > this.disconnectedTimeout - ) { - this.markClientDisconnected(client, true); - } else if ( - client.isDisconnected && - now - client.lastPing < this.disconnectedTimeout - ) { - this.markClientDisconnected(client, false); - } - } - } - private markClientDisconnected(client: Client, isDisconnected: boolean) { client.isDisconnected = isDisconnected; this.addIntent({