From 5ea6956f401f4375e31a9dfc20a0e69f410fc271 Mon Sep 17 00:00:00 2001
From: Gautam Anand
{text("yourGlobalRank")}: #{eloData.rank} -
*/} +24 * 60 * 60 * 1000)) { bulkOps.push({ updateOne: { filter: { _id: user._id }, update: { - $set: { rank: currentRank }, - ...(Date.now() - user.lastEloHistoryUpdate > 24 * 60 * 60 * 1000 && { $push: { elo_history: { elo: user.elo, time: Date.now() } }, $set: { lastEloHistoryUpdate: Date.now() }, $set: { elo_today: 0 }, - }) }, }, }); } + } // Execute bulk operations if (bulkOps.length > 0) { @@ -80,13 +68,14 @@ async function calculateRanks() { } console.timeEnd('Updated ranks'); + console.log('bulkOps', bulkOps.length); } -// Calculate ranks every 3 hours +// Calculate ranks every 12 hours // setInterval(calculateRanks, 60 * 60 * 1000 * 3); function recursiveCalculateRanks() { calculateRanks().then(() => { - setTimeout(recursiveCalculateRanks, 3 * 60 * 60 * 1000); + setTimeout(recursiveCalculateRanks, 12 * 60 * 60 * 1000); }); } recursiveCalculateRanks(); diff --git a/models/User.js b/models/User.js index 29d577d..91d3f0f 100644 --- a/models/User.js +++ b/models/User.js @@ -114,10 +114,7 @@ const userSchema = new mongoose.Schema({ duels_tied: { type: Number, default: 0 - }, - rank: { - type: Number, - }, + } }); const User = mongoose.models.User || mongoose.model('User', userSchema); diff --git a/public/locales/en/common.json b/public/locales/en/common.json index ddda062..54a0b6f 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -228,5 +228,6 @@ "elo": "ELO", "xp": "XP", "leagueModalDesc": "Play duels to gain ELO and climb the leaderboard.", - "leagueModalDesc2": "Stats may be delayed up to 1 hour" + "leagueModalDesc2": "Stats may be delayed up to 1 hour", + "unableToJoinDuel": "Unable to find duel at this time. Please email support@worldguessr.com" } diff --git a/ws/classes/Player.js b/ws/classes/Player.js index 35da5fa..cf6922a 100644 --- a/ws/classes/Player.js +++ b/ws/classes/Player.js @@ -81,6 +81,7 @@ export default class Player { this.username = valid.username; this.accountId = valid._id.toString(); this.elo = valid.elo; + this.banned = valid.banned; this.league = getLeague(this.elo).name; this.send({ type: 'verify' diff --git a/ws/ws.js b/ws/ws.js index 37828a5..fb99c3e 100644 --- a/ws/ws.js +++ b/ws/ws.js @@ -373,6 +373,15 @@ app.ws('/wg', { if ((json.type === 'publicDuel') && !player.gameId) { console.log('public duel requested by', player.username, player.ip); + if(player.banned) { + player.send({ + type: 'toast', + key: 'unableToJoinDuel', + toastType: 'error' + }); + return; + + } // get range of league player.inQueue = true;