Finish Pacosako + add GameStat table to know how many live games are played
[vchess.git] / client / src / views / Hall.vue
index 4e1e54b..ebb4675 100644 (file)
@@ -441,7 +441,8 @@ export default {
                 }
               }
             );
-          } else addChallenges();
+          }
+          else addChallenges();
         }
       }
     );
@@ -562,9 +563,8 @@ export default {
     },
     // o: challenge or game
     classifyObject: function(o) {
-      // Consider imports as live games (TODO)
-      if (!!o.id && !!o.id.toString().match(/^i/)) return "live";
-      return o.cadence.indexOf("d") === -1 ? "live" : "corr";
+      // No imported games here
+      return (o.cadence.indexOf("d") >= 0 ? "corr" : "live");
     },
     setDisplay: function(letter, type, e) {
       this[letter + "display"] = type;
@@ -702,7 +702,8 @@ export default {
             // For self multi-connects tests:
             this.newConnect[data.from[0]] = true;
             this.send("askidentity", { target: data.from[0], page: page });
-          } else {
+          }
+          else {
             this.people[data.from[0]].tmpIds[data.from[1]] =
               { page: page, focus: true };
             this.$forceUpdate(); //TODO: shouldn't be required
@@ -734,7 +735,8 @@ export default {
                 "all"
               );
             }
-          } else {
+          }
+          else {
             // Remove the matching live game if now unreachable
             const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
             // Corr games are always reachable:
@@ -949,7 +951,8 @@ export default {
                 );
               });
               this.games = this.games.concat(moreGames);
-            } else this.hasMore = false;
+            }
+            else this.hasMore = false;
           }
         }
       );
@@ -1017,7 +1020,8 @@ export default {
           position: parsedFen.position
           //,orientation: parsedFen.turn
         });
-      } else this.newchallenge.diag = "";
+      }
+      else this.newchallenge.diag = "";
     },
     newChallFromPreset(pchall) {
       this.partialResetNewchallenge();
@@ -1155,7 +1159,8 @@ export default {
       if (ctype == "live") {
         // Live challenges have a random ID
         finishAddChallenge(null);
-      } else {
+      }
+      else {
         // Correspondence game: send challenge to server
         ajax(
           "/challenges",
@@ -1194,7 +1199,8 @@ export default {
         else
           // Corr challenge: just remove the challenge
           this.send("deletechallenge_s", { data: { cid: c.id } });
-      } else {
+      }
+      else {
         const oppsid = this.getOppsid(c);
         if (!!oppsid)
           this.send("refusechallenge", { data: c.id, target: oppsid });
@@ -1218,24 +1224,26 @@ export default {
           alert(this.st.tr["Please log in to accept corr challenges"]);
           return;
         }
-        c.accepted = true;
-        await import("@/variants/" + c.vname + ".js")
-        .then((vModule) => {
-          window.V = vModule[c.vname + "Rules"];
-          if (!!c.to) {
-            // c.to == this.st.user.name (connected)
-            if (!!c.fen) {
-              const parsedFen = V.ParseFen(c.fen);
-              this.tchallDiag = getDiagram({
-                position: parsedFen.position,
-                orientation: parsedFen.turn
-              });
+        else {
+          c.accepted = true;
+          await import("@/variants/" + c.vname + ".js")
+          .then((vModule) => {
+            window.V = vModule[c.vname + "Rules"];
+            if (!!c.to) {
+              // c.to == this.st.user.name (connected)
+              if (!!c.fen) {
+                const parsedFen = V.ParseFen(c.fen);
+                this.tchallDiag = getDiagram({
+                  position: parsedFen.position,
+                  orientation: parsedFen.turn
+                });
+              }
+              this.curChallToAccept = c;
+              document.getElementById("modalAccept").checked = true;
             }
-            this.curChallToAccept = c;
-            document.getElementById("modalAccept").checked = true;
-          }
-          else this.finishProcessingChallenge(c);
-        });
+            else this.finishProcessingChallenge(c);
+          });
+        }
       }
       else {
         // My challenge
@@ -1299,7 +1307,14 @@ export default {
       if (c.type == "live") {
         notifyNewgame();
         this.startNewGame(gameInfo);
-      } else {
+        // Increment game stats counter in DB
+        ajax(
+          "/gamestat",
+          "POST",
+          { data: { vid: gameInfo.vid } }
+        );
+      }
+      else {
         // corr: game only on server
         ajax(
           "/games",
@@ -1349,7 +1364,7 @@ export default {
                 new Audio("/sounds/newgame.flac").play().catch(() => {});
               notify(
                 "New live game",
-                { body: "vs " + game.players[1-myIdx].name || "@nonymous" }
+                { body: "vs " + (game.players[1-myIdx].name || "@nonymous") }
               );
             }
             this.$router.push("/game/" + gameInfo.id);