juego pausado al irse un jugador

This commit is contained in:
2025-08-11 18:47:59 -06:00
parent ee0243d456
commit deb63d4e38
2 changed files with 34 additions and 1 deletions

View File

@@ -252,7 +252,24 @@ export class GameRoom extends Room<GameState> {
}
}
this.allowReconnection(client, 30);
// Allow reconnection; when it happens, mark player connected and resume if both are present
const reconnection = this.allowReconnection(client, 30);
reconnection.then((newClient) => {
const p = this.state.players.get(client.sessionId);
if (p) {
p.connected = true;
}
// Provide basic identity back to the reconnecting client
try {
newClient.send("playerInfo", { sessionId: client.sessionId, name: p?.name || "player", roomId: this.roomId });
} catch {}
if (this.state.gameStatus === GameStatus.PAUSED && this.getConnectedPlayersCount() === 2) {
this.state.resumeGame();
this.setMetadata({ gameStatus: 'playing' });
}
}).catch(() => {
// reconnection window expired; nothing to do here
});
}
async onReconnect(client: Client) {