[Scummvm-git-logs] scummvm-sites multiplayer -> 5060112ea7d821538d26617ce3162291f6cda972

LittleToonCat noreply at scummvm.org
Thu Oct 26 03:33:28 UTC 2023


This automated email contains information about 1 new commit which have been
pushed to the 'scummvm-sites' repo located at https://github.com/scummvm/scummvm-sites .

Summary:
5060112ea7 MULTIPLAYER: Get disconnected users from database.


Commit: 5060112ea7d821538d26617ce3162291f6cda972
    https://github.com/scummvm/scummvm-sites/commit/5060112ea7d821538d26617ce3162291f6cda972
Author: Little Cat (toontownlittlecat at gmail.com)
Date: 2023-10-26T00:33:19-03:00

Commit Message:
MULTIPLAYER: Get disconnected users from database.

Changed paths:
    lobby/database/WebAPI.js
    lobby/global/Stats.js


diff --git a/lobby/database/WebAPI.js b/lobby/database/WebAPI.js
index 02dc30d..d40a737 100644
--- a/lobby/database/WebAPI.js
+++ b/lobby/database/WebAPI.js
@@ -49,6 +49,23 @@ class WebAPI {
         return user;
     }
 
+    async getUserById(userId, game) {
+        // This should not be confused with redis.getUserById
+        // which gets users who are already logged in to the lobby.
+        //
+        // This call should only be used only if you want user infomation
+        // who are not logged in (which should happen rarely).
+
+        const user = await this.post('/get_user_by_id', {token: this.token,
+                                                         userId: userId,
+                                                         game: game});
+        if (user.error) {
+            this.logger.error(`Failed to get user with id ${userId}: ${user}`);
+            return {};
+        }
+        return user;
+    }
+
     async getNews() {
         const news = await this.post('/get_news', {token: this.token});
         return news;
diff --git a/lobby/global/Stats.js b/lobby/global/Stats.js
index d5c874d..dd75cf0 100644
--- a/lobby/global/Stats.js
+++ b/lobby/global/Stats.js
@@ -135,21 +135,19 @@ const ResultsMappers = {
 
 const CalculateStats = {
     "baseball": async (userId, gameResults, opponentId, opponentGameResults) => {
-        const user = await redis.getUserById(userId, "baseball");
+        let user = await redis.getUserById(userId, "baseball");
         if (Object.keys(user).length == 0) {
-            // TODO: User must've disconnected from the lobby, get
-            // stats from the WebAPI and work from there.
-            logger.warn(`TODO: User ${userId} not in redis.`);
-            return
+            // User must've disconnected from the lobby, get
+            // stats from the database and work from there.
+            user = await database.getUserById(userId, "baseball");
         }
         const stats = ProfileMappers["baseball"](user.stats);
 
-        const opponent = await redis.getUserById(opponentId, "baseball");
+        let opponent = await redis.getUserById(opponentId, "baseball");
         if (Object.keys(opponent).length == 0) {
-            // TODO: User must've disconnected from the lobby, get
-            // stats from the WebAPI and work from there.
-            logger.warn(`TODO: User ${opponentId} not in redis.`);
-            return
+            // User must've disconnected from the lobby, get
+            // stats from the database and work from there.
+            opponent = await database.getUserById(opponentId, "baseball");
         }
         const opponentStats = ProfileMappers["baseball"](opponent.stats);
 




More information about the Scummvm-git-logs mailing list