From ab6f48ea4d9c549830f549f077c597f57ea4a57d Mon Sep 17 00:00:00 2001
From: Benjamin Auder <benjamin.auder@somewhere>
Date: Tue, 21 Jan 2020 15:27:34 +0100
Subject: [PATCH] Fixes around game observing. TODO: abort/resign/draw + corr

---
 client/src/views/Game.vue | 8 ++++++--
 server/sockets.js         | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/client/src/views/Game.vue b/client/src/views/Game.vue
index 984a66bf..09d9df8a 100644
--- a/client/src/views/Game.vue
+++ b/client/src/views/Game.vue
@@ -189,7 +189,7 @@ export default {
           {
             // Minimal game informations:
             id: this.game.id,
-            players: this.game.players.map(p => p.name),
+            players: this.game.players.map(p => { return {name:p.name}; }),
             vid: this.game.vid,
             timeControl: this.game.timeControl,
           };
@@ -512,7 +512,11 @@ export default {
     gameOver: function(score) {
       this.game.mode = "analyze";
       this.game.score = score;
-      GameStorage.update(this.gameRef.id, { score: score });
+      const myIdx = this.game.players.findIndex(p => {
+        return p.sid == this.st.user.sid || p.uid == this.st.user.id;
+      });
+      if (myIdx >= 0) //OK, I play in this game
+        GameStorage.update(this.gameRef.id, { score: score });
     },
   },
 };
diff --git a/server/sockets.js b/server/sockets.js
index b51a978a..ed7275ff 100644
--- a/server/sockets.js
+++ b/server/sockets.js
@@ -91,7 +91,7 @@ module.exports = function(wss) {
               : 0;
             const rid = gameSids[gid][idx];
             clients[rid].sock.send(JSON.stringify(
-              {code:"askgame", from: rid}));
+              {code:"askgame", from: sid}));
           });
           break;
         }
-- 
2.44.0