Browse Source

Merged in feature/MENU-1_TH-8-server-provide-game-id-to-client (pull request #1)

change game query for new status(PLAYING/PAUSED) & provide game id to app
Johan LE BAUT 5 years ago
parent
commit
3330624099

+ 4 - 4
server/db/mariadb-connector.js

@@ -148,17 +148,17 @@ export default class MariadbConnector {
     }
   }
 
-  async getNonFinishedGamesForPlayer(username) {
+  async getJoinableGamesForPlayer(username) {
 
     let conn;
     let games = [];
     try {
       conn = await this.pool.getConnection();
       const res = await conn.query(
-        "SELECT * FROM`games` WHERE status != 'FINISHED' AND(player1 = ? OR player2 = '' OR player2 = ?)",
+        "SELECT * FROM`games` WHERE (status = 'CREATED' OR status = 'PAUSED')  AND(player1 = ? OR player2 = '' OR player2 = ?)",
         [username,username]);
-      for (const { player1,player2,deck,adv_rules } of res) {
-        games.push({player1,player2,deck,adv_rules});
+      for (const { id,player1,player2,deck,adv_rules } of res) {
+        games.push({id,player1,player2,deck,adv_rules});
       }
       console.log(`returning for ${username} : `, games);
     } finally {

+ 4 - 4
server/server.js

@@ -104,7 +104,7 @@ function Server() {
       console.log(' Received games-list message, player name : ' + playerName);
       let response = {};
       try {
-        let games = await getNonFinishedGames(playerName);
+        let games = await getJoinableGames(playerName);
         response = {
           res: "ok",
           message: games
@@ -209,10 +209,10 @@ function Server() {
     }
   };
 
-  let getNonFinishedGames = async function (username) {
+  let getJoinableGames = async function (username) {
 
     try {
-      let games = await mariadbConn.getNonFinishedGamesForPlayer(username);
+      let games = await mariadbConn.getJoinableGamesForPlayer(username);
       return games;
     } catch (err) {
       console.log('KO : not able to get games : ' + err);
@@ -227,7 +227,7 @@ function Server() {
     removePlayerDb,
     addGameDb,
     removeGameDb,
-    getNonFinishedGames
+    getJoinableGames
   };
 
 }

+ 0 - 7
src/menu/control/server-login.js

@@ -1,7 +0,0 @@
-'use strict';
-
-export default class ServerLogin {
-  constructor() {
-
-  }
-}

+ 1 - 0
src/menu/views/menu-pages/online-room-div-page.js

@@ -68,6 +68,7 @@ export default function OnlineRoomDivPage(element, listener) {
           li.appendChild(spanTitle);
           li.appendChild(div);
           li.appendChild(spanDesc);
+          li.setAttribute("id",game.id);
           listOnlineGames.appendChild(li);
         });
         loaderOnlineGames.style.display= 'none';