From 1f531a1acc8a0b3784cb8ad8ca29816128fa83b5 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Tue, 26 Jan 2021 14:55:25 +0000 Subject: [PATCH] Multiplayer optimisations --- server/MultiplayerMatch.js | 36 +++++++----------------------------- server/User.js | 6 ++++-- 2 files changed, 11 insertions(+), 31 deletions(-) diff --git a/server/MultiplayerMatch.js b/server/MultiplayerMatch.js index 3f93bdd..f0a779a 100644 --- a/server/MultiplayerMatch.js +++ b/server/MultiplayerMatch.js @@ -277,16 +277,8 @@ module.exports = class { missingBeatmap(MatchUser) { const osuPacketWriter = new osu.Bancho.Writer; - // Loop through all slots in the match - for (let i = 0; i < this.slots.length; i++) { - const slot = this.slots[i]; - // Make sure the user in the slot is the user we want to update - if (slot.playerId != MatchUser.id) continue; - - // User is missing the beatmap set the status to reflect it - slot.status = 16; - break; - } + // User is missing the beatmap set the status to reflect it + this.slots[MatchUser.matchSlotId].status = 16; osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); @@ -297,16 +289,8 @@ module.exports = class { notMissingBeatmap(MatchUser) { const osuPacketWriter = new osu.Bancho.Writer; - // Loop through all slots in the match - for (let i = 0; i < this.slots.length; i++) { - const slot = this.slots[i]; - // Make sure the user in the slot is the user we want to update - if (slot.playerId != MatchUser.id) continue; - - // The user is not missing the beatmap, set the status to normal - else slot.status = 4; - break; - } + // The user is not missing the beatmap, set the status to normal + this.slots[MatchUser.matchSlotId].status = 4; osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); @@ -363,11 +347,11 @@ module.exports = class { } } - transferHost(MatchUserToTransferHostTo) { + transferHost(SlotIDToTransferTo) { const osuPacketWriter = new osu.Bancho.Writer; // Set the lobby's host to the new user - this.host = this.slots[MatchUserToTransferHostTo].playerId; + this.host = this.slots[SlotIDToTransferTo].playerId; osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); @@ -380,13 +364,7 @@ module.exports = class { // Check if freemod is enabled if (this.specialModes === 1) { const osuPacketWriter = new osu.Bancho.Writer; - for (let i = 0; i < this.slots.length; i++) { - const slot = this.slots[i]; - if (slot.playerId === MatchUser.id) { - slot.mods = MatchMods; - break; - } - } + this.slots[MatchUser.matchSlotId].mods = MatchMods; osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); diff --git a/server/User.js b/server/User.js index 8be5c0f..34bb0cb 100644 --- a/server/User.js +++ b/server/User.js @@ -14,8 +14,6 @@ module.exports = class { this.spectating = 0; this.location = [0,0]; this.joinedChannels = []; - this.currentMatch = null; - this.matchSlotId = -1; // Presence data this.actionID = 0; @@ -32,6 +30,10 @@ module.exports = class { this.totalScore = 0; this.rank = 0; this.pp = 0; + + // Multiplayer data + this.currentMatch = null; + this.matchSlotId = -1; } // Adds new actions to the user's queue