This commit is contained in:
parent
d6630ece24
commit
b43c6210be
2 changed files with 56 additions and 0 deletions
|
|
@ -181,6 +181,11 @@
|
|||
game = new Chess(convertChess960Fen(payload.fen));
|
||||
}
|
||||
|
||||
// Restore move history if rejoining an in-progress game
|
||||
if (payload.moveHistory && payload.moveHistory.length > 0) {
|
||||
moveHistory = payload.moveHistory;
|
||||
}
|
||||
|
||||
gamesOverlay.setMode('playing');
|
||||
gamesOverlay.updateState({
|
||||
positionId: payload.positionId,
|
||||
|
|
@ -202,6 +207,11 @@
|
|||
game = new Chess(convertChess960Fen(payload.fen));
|
||||
}
|
||||
|
||||
// Restore move history for spectators
|
||||
if (payload.moveHistory && payload.moveHistory.length > 0) {
|
||||
moveHistory = payload.moveHistory;
|
||||
}
|
||||
|
||||
gamesOverlay.setMode('spectating');
|
||||
gamesOverlay.updateState({
|
||||
positionId: payload.positionId,
|
||||
|
|
@ -213,6 +223,32 @@
|
|||
blackName: payload.blackName
|
||||
});
|
||||
|
||||
updateBoardDisplay();
|
||||
} else if (payload.status === 'finished') {
|
||||
// Rejoining a finished game
|
||||
const session = nakama.getSession();
|
||||
myColor = payload.whiteId === session?.user_id ? 'w' : 'b';
|
||||
|
||||
if (Chess && payload.fen) {
|
||||
game = new Chess(convertChess960Fen(payload.fen));
|
||||
}
|
||||
|
||||
if (payload.moveHistory && payload.moveHistory.length > 0) {
|
||||
moveHistory = payload.moveHistory;
|
||||
}
|
||||
|
||||
gamesOverlay.setMode('finished');
|
||||
gamesOverlay.updateState({
|
||||
positionId: payload.positionId,
|
||||
fen: payload.fen,
|
||||
whiteId: payload.whiteId,
|
||||
blackId: payload.blackId,
|
||||
whiteName: payload.whiteName,
|
||||
blackName: payload.blackName,
|
||||
result: payload.result,
|
||||
gameOver: payload.gameOver
|
||||
});
|
||||
|
||||
updateBoardDisplay();
|
||||
}
|
||||
}
|
||||
|
|
@ -499,6 +535,8 @@
|
|||
return myColor === 'b' ? 'You win!' : 'You lose';
|
||||
} else if (result === 'timeout') {
|
||||
return reason || 'Match timed out';
|
||||
} else if (result === 'cancelled') {
|
||||
return reason || 'Match cancelled';
|
||||
}
|
||||
return `Draw${reason ? ` (${reason})` : ''}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -720,6 +720,24 @@ func (m *ChessMatch) MatchSignal(ctx context.Context, logger runtime.Logger, db
|
|||
if data == "cancel" {
|
||||
logger.Info("Match cancelled via signal")
|
||||
s.PendingCancel = true
|
||||
|
||||
// Broadcast cancellation to any connected clients
|
||||
msg, _ := json.Marshal(map[string]interface{}{
|
||||
"result": "cancelled",
|
||||
"reason": "Challenge cancelled by creator",
|
||||
})
|
||||
dispatcher.BroadcastMessage(OpCodeGameOver, msg, nil, nil, true)
|
||||
|
||||
// Update match label to cancelled status so it's not detected as active
|
||||
label := MatchLabel{
|
||||
Game: "chess960",
|
||||
Status: "cancelled",
|
||||
White: s.WhiteName,
|
||||
WhiteID: s.WhiteID,
|
||||
PositionID: s.PositionID,
|
||||
}
|
||||
labelJSON, _ := json.Marshal(label)
|
||||
dispatcher.MatchLabelUpdate(string(labelJSON))
|
||||
}
|
||||
|
||||
return s, ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue