[gnome-chess] Ensure draws are only claimed when valid



commit 92b943ecd23d8bcb9c2cd55c8a9903c2018c821f
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Sun Jan 27 11:24:54 2019 -0600

    Ensure draws are only claimed when valid
    
    For robustness, let's make it a bug to try claiming a draw when it's not
    possible. Guard against this in the one point it can currently happen.

 lib/chess-game.vala  | 1 +
 src/gnome-chess.vala | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
---
diff --git a/lib/chess-game.vala b/lib/chess-game.vala
index 75f55e4..e7fdf05 100644
--- a/lib/chess-game.vala
+++ b/lib/chess-game.vala
@@ -286,6 +286,7 @@ public class ChessGame : Object
     }
 
     private void claim_draw_cb ()
+        requires (can_claim_draw ())
     {
         if (is_fifty_move_rule_fulfilled ())
             stop (ChessResult.DRAW, ChessRule.FIFTY_MOVES);
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 8f04aad..12aeef6 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -797,7 +797,8 @@ Copyright © 2015–2016 Sahil Sareen""";
 
     private void engine_offer_draw_cb (ChessEngine engine)
     {
-        opponent.claim_draw ();
+        if (game.can_claim_draw ())
+            opponent.claim_draw ();
 
         /*
          * If the draw cannot be claimed, do nothing.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]