Fix double-move sending in corr games
[vchess.git] / client / src / views / Game.vue
index 5145e58..398a0a2 100644 (file)
@@ -490,7 +490,7 @@ export default {
       }
     },
     getGameType: function(game) {
-      if (!!game.id.match(/^i/)) return "import";
+      if (!!game.id.toString().match(/^i/)) return "import";
       return game.cadence.indexOf("d") >= 0 ? "corr" : "live";
     },
     // Notify something after a new move (to opponent and me on MyGames page)
@@ -1189,11 +1189,6 @@ export default {
     //  - from server (one correspondance game I play[ed] or not)
     //  - from remote peer (one live game I don't play, finished or not)
     fetchGame: function(callback) {
-      
-console.log("fecth");
-      console.log(this.gameRef);
-      console.log(this.gameRef.match(/^i/));
-
       if (Number.isInteger(this.gameRef) || !isNaN(parseInt(this.gameRef))) {
         // corr games identifiers are integers
         ajax(
@@ -1456,9 +1451,12 @@ console.log("fecth");
           }
         );
         // PlayOnBoard is enough, and more appropriate for Synchrone Chess
-        V.PlayOnBoard(this.vr.board, move);
+        const arMove = (Array.isArray(move) ? move : [move]);
+        for (let i = 0; i < arMove.length; i++)
+          V.PlayOnBoard(this.vr.board, arMove[i]);
         const position = this.vr.getBaseFen();
-        V.UndoOnBoard(this.vr.board, move);
+        for (let i = arMove.length - 1; i >= 0; i--)
+          V.UndoOnBoard(this.vr.board, arMove[i]);
         if (["all","byrow"].includes(V.ShowMoves)) {
           this.curDiag = getDiagram({
             position: position,