better websocket handling

This commit is contained in:
evanpelle
2025-07-23 09:57:27 -07:00
parent b593034755
commit 814a00c504
2 changed files with 6 additions and 2 deletions
+2 -1
View File
@@ -111,6 +111,7 @@ export class GameServer {
this.log.warn(`cannot add client, already kicked`, {
clientID: client.clientID,
});
client.ws.close(1002, "Kicked from game");
return;
}
this.log.info("client (re)joining game", {
@@ -174,6 +175,7 @@ export class GameServer {
client.lastPing = existing.lastPing;
existing.ws.removeAllListeners();
existing.ws.close(1000);
this.activeClients = this.activeClients.filter((c) => c !== existing);
}
@@ -183,7 +185,6 @@ export class GameServer {
this.allClients.set(client.clientID, client);
client.ws.removeAllListeners();
client.ws.on(
"message",
gatekeeper.wsHandler(client.ip, async (message: string) => {
+4 -1
View File
@@ -442,6 +442,8 @@ export function startWorker() {
clientMsg.pattern,
);
// Remove all listeners because we are passing ws ownership to the GameServer.
ws.removeAllListeners();
const wasFound = gm.addClient(
client,
clientMsg.gameID,
@@ -452,7 +454,8 @@ export function startWorker() {
log.info(
`game ${clientMsg.gameID} not found on worker ${workerId}`,
);
// Handle game not found case
ws.close(1002, "Game not found");
return;
}
// Handle other message types