fixes lol
All checks were successful
Build and Push / build-all (push) Successful in 1m11s

This commit is contained in:
doomtube 2026-01-08 23:07:31 -05:00
parent 7bcbc6b73b
commit d6630ece24

View file

@ -560,25 +560,34 @@ func (m *ChessMatch) MatchLoop(ctx context.Context, logger runtime.Logger, db *s
s.Turn = result.Turn
s.MoveHistory = append(s.MoveHistory, fmt.Sprintf("%s-%s", moveData.From, moveData.To))
// ALWAYS broadcast the move to all players/spectators first
moveMsg, _ := json.Marshal(map[string]interface{}{
"move": moveData,
"fen": s.FEN,
"turn": s.Turn,
})
dispatcher.BroadcastMessage(OpCodeMove, moveMsg, nil, nil, true)
// Then handle game-over if applicable
if result.GameOver {
s.GameOver = true
s.Result = result.Result
// Update ELO
// Update ELO only for valid results
if s.Result == "1-0" {
updateElo(ctx, nk, logger, s.WhiteID, s.WhiteName, s.BlackID, s.BlackName, false)
} else if s.Result == "0-1" {
updateElo(ctx, nk, logger, s.BlackID, s.BlackName, s.WhiteID, s.WhiteName, false)
} else {
} else if s.Result == "1/2-1/2" {
updateElo(ctx, nk, logger, s.WhiteID, s.WhiteName, s.BlackID, s.BlackName, true)
}
msg, _ := json.Marshal(map[string]interface{}{
gameOverMsg, _ := json.Marshal(map[string]interface{}{
"fen": s.FEN,
"result": s.Result,
"reason": result.Reason,
})
dispatcher.BroadcastMessage(OpCodeGameOver, msg, nil, nil, true)
dispatcher.BroadcastMessage(OpCodeGameOver, gameOverMsg, nil, nil, true)
label := MatchLabel{
Game: "chess960",
@ -594,13 +603,6 @@ func (m *ChessMatch) MatchLoop(ctx context.Context, logger runtime.Logger, db *s
dispatcher.MatchLabelUpdate(string(labelJSON))
logger.Info("Game over: %s (%s)", s.Result, result.Reason)
} else {
msg, _ := json.Marshal(map[string]interface{}{
"move": moveData,
"fen": s.FEN,
"turn": s.Turn,
})
dispatcher.BroadcastMessage(OpCodeMove, msg, nil, nil, true)
}
case OpCodeResign: