emit receivedMove first before gameOver

This commit is contained in:
Nathaniel Tampus
2023-04-02 15:01:52 +08:00
parent fc2f61446d
commit 651cfb9d2a

View File

@@ -178,6 +178,7 @@ export async function sendMove(this: Socket, m: { from: string; to: string; prom
if (newMove) { if (newMove) {
game.pgn = chess.pgn(); game.pgn = chess.pgn();
this.to(game.code as string).emit("receivedMove", m);
if (chess.isGameOver()) { if (chess.isGameOver()) {
let reason: Game["endReason"]; let reason: Game["endReason"];
if (chess.isCheckmate()) reason = "checkmate"; if (chess.isCheckmate()) reason = "checkmate";
@@ -205,7 +206,6 @@ export async function sendMove(this: Socket, m: { from: string; to: string; prom
game.id = id; game.id = id;
io.to(game.code as string).emit("gameOver", { reason, winnerName, winnerSide, id }); io.to(game.code as string).emit("gameOver", { reason, winnerName, winnerSide, id });
} }
this.to(game.code as string).emit("receivedMove", m);
} else { } else {
throw new Error("invalid move"); throw new Error("invalid move");
} }