Fix moves sending. TODO: fix double opp move + clocks update
authorBenjamin Auder <benjamin.auder@somewhere>
Wed, 12 Jun 2019 14:35:49 +0000 (16:35 +0200)
committerBenjamin Auder <benjamin.auder@somewhere>
Wed, 12 Jun 2019 14:35:49 +0000 (16:35 +0200)
client/src/utils/storage.js
client/src/views/Game.vue
client/src/views/Hall.vue

index ecafe20..a30bb82 100644 (file)
@@ -99,7 +99,7 @@ export const GameStorage =
       fen: o.fenStart,
       moves: [],
       clocks: [...Array(o.players.length)].fill(tc.mainTime),
-      initime: undefined,
+      initime: (o.initime ? Date.now() : undefined),
       score: "*",
     };
 
index 7aa7aa5..8389bde 100644 (file)
@@ -250,8 +250,9 @@ export default {
         // Post-processing: decorate each move with current FEN:
         // (to be able to jump to any position quickly)
         game.moves.forEach(move => {
+          // TODO: this is doing manually what BaseGame.play() achieve...
           move.color = this.vr.turn;
-          vr.play(move);
+          this.vr.play(move);
           move.fen = this.vr.getFen();
         });
         this.vr.re_init(game.fen);
@@ -281,7 +282,7 @@ export default {
       const filtered_move = Object.keys(move)
         .filter(key => allowed_fields.includes(key))
         .reduce((obj, key) => {
-          obj[key] = raw[key];
+          obj[key] = move[key];
           return obj;
         }, {});
       // Send move ("newmove" event) to opponent(s) (if ours)
@@ -291,11 +292,11 @@ export default {
         const elapsed = Date.now() - GameStorage.getInitime();
         this.game.players.forEach(p => {
           if (p.sid != this.st.user.sid)
-            this.st.conn.send("newmove",
-            {
+            this.st.conn.send(JSON.stringify({
+              code: "newmove",
               target: p.sid,
               move: Object.assign({}, filtered_move, {elapsed: elapsed}),
-            });
+            }));
         });
         move.elapsed = elapsed;
       }
index 563ecd3..dd4621b 100644 (file)
@@ -592,6 +592,7 @@ export default {
         fenStart: gameInfo.fen,
         players: gameInfo.players,
         timeControl: gameInfo.timeControl,
+        initime: (gameInfo.players[0].sid == this.st.user.sid),
       });
       if (this.st.settings.sound >= 1)
         new Audio("/sounds/newgame.mp3").play().catch(err => {});