Fix client reconnection after page refresh (#3117)

## Description:

- Removed all code related to generating a client ID on the client. The
server now assigns the client ID and sends it to the client in lobby
messages.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced

## Please put your Discord username so you can be contacted if a bug or
regression is found:

w.o.n
This commit is contained in:
Ryan
2026-02-09 01:10:11 +00:00
committed by GitHub
parent e7676b4260
commit 8dcc7cfb9a
15 changed files with 321 additions and 276 deletions
+14 -16
View File
@@ -8,7 +8,7 @@ import {
GameMode,
GameType,
} from "../core/game/Game";
import { ClientRejoinMessage, GameConfig, GameID } from "../core/Schemas";
import { GameConfig, GameID } from "../core/Schemas";
import { Client } from "./Client";
import { GamePhase, GameServer } from "./GameServer";
@@ -32,32 +32,30 @@ export class GameManager {
);
}
joinClient(client: Client, gameID: GameID): boolean {
joinClient(
client: Client,
gameID: GameID,
): "joined" | "kicked" | "rejected" | "not_found" {
const game = this.games.get(gameID);
if (game) {
game.joinClient(client);
return true;
}
return false;
if (!game) return "not_found";
return game.joinClient(client);
}
rejoinClient(
ws: WebSocket,
persistentID: string,
msg: ClientRejoinMessage,
gameID: GameID,
lastTurn: number = 0,
): boolean {
const game = this.games.get(msg.gameID);
if (game) {
game.rejoinClient(ws, persistentID, msg);
return true;
}
return false;
const game = this.games.get(gameID);
if (!game) return false;
return game.rejoinClient(ws, persistentID, lastTurn);
}
createGame(
id: GameID,
gameConfig: GameConfig | undefined,
creatorClientID?: string,
creatorPersistentID?: string,
startsAt?: number,
) {
const game = new GameServer(
@@ -83,7 +81,7 @@ export class GameManager {
disabledUnits: [],
...gameConfig,
},
creatorClientID,
creatorPersistentID,
startsAt,
);
this.games.set(id, game);