From 335a371fdbfc1fa5b85cc93482f8207da123b3be Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 8 Dec 2025 16:42:29 -0800 Subject: [PATCH] bugfix: singleplayer not starting (#2589) #075c232 introduced a bug that prevented singplayer games from starting. The `updateCallback` was not set for localserver, and local server didn't send a start message when client sent a "rejoin". ## 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: evan --- src/client/LocalServer.ts | 21 +++++++++++++++++++-- src/client/Transport.ts | 11 +++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/client/LocalServer.ts b/src/client/LocalServer.ts index c21114911..d813c52a3 100644 --- a/src/client/LocalServer.ts +++ b/src/client/LocalServer.ts @@ -41,16 +41,25 @@ export class LocalServer { private turnStartTime = 0; private turnCheckInterval: NodeJS.Timeout; + private clientConnect: () => void; + private clientMessage: (message: ServerMessage) => void; constructor( private lobbyConfig: LobbyConfig, - private clientConnect: () => void, - private clientMessage: (message: ServerMessage) => void, private isReplay: boolean, private eventBus: EventBus, ) {} + public updateCallback( + clientConnect: () => void, + clientMessage: (message: ServerMessage) => void, + ) { + this.clientConnect = clientConnect; + this.clientMessage = clientMessage; + } + start() { + console.log("local server starting"); this.turnCheckInterval = setInterval(() => { const turnIntervalMs = this.lobbyConfig.serverConfig.turnIntervalMs() * @@ -97,6 +106,14 @@ export class LocalServer { } onMessage(clientMsg: ClientMessage) { + if (clientMsg.type === "rejoin") { + this.clientMessage({ + type: "start", + gameStartInfo: this.lobbyConfig.gameStartInfo!, + turns: this.turns, + lobbyCreatedAt: this.lobbyConfig.gameStartInfo!.lobbyCreatedAt, + } satisfies ServerStartGameMessage); + } if (clientMsg.type === "intent") { if (this.lobbyConfig.gameRecord) { // If we are replaying a game, we don't want to process intents diff --git a/src/client/Transport.ts b/src/client/Transport.ts index 8c0f9a434..9f4f1f5a7 100644 --- a/src/client/Transport.ts +++ b/src/client/Transport.ts @@ -292,8 +292,12 @@ export class Transport { onconnect: () => void, onmessage: (message: ServerMessage) => void, ) { - this.onconnect = onconnect; - this.onmessage = onmessage; + if (this.isLocal) { + this.localServer.updateCallback(onconnect, onmessage); + } else { + this.onconnect = onconnect; + this.onmessage = onmessage; + } } private connectLocal( @@ -302,11 +306,10 @@ export class Transport { ) { this.localServer = new LocalServer( this.lobbyConfig, - onconnect, - onmessage, this.lobbyConfig.gameRecord !== undefined, this.eventBus, ); + this.localServer.updateCallback(onconnect, onmessage); this.localServer.start(); }