From ad6ad5ed2c6a92e334addd900a7a53666420934c Mon Sep 17 00:00:00 2001 From: Holly Date: Fri, 30 Sep 2022 11:34:52 +0100 Subject: [PATCH] Make a few packets awaited so that the client gets data on time --- server/MultiplayerMatch.js | 28 +++++++++++++++++++--------- server/Packets/Logout.js | 4 ++-- server/serverHandler.js | 14 +++++++------- 3 files changed, 28 insertions(+), 18 deletions(-) mode change 100644 => 100755 server/MultiplayerMatch.js mode change 100644 => 100755 server/Packets/Logout.js mode change 100644 => 100755 server/serverHandler.js diff --git a/server/MultiplayerMatch.js b/server/MultiplayerMatch.js old mode 100644 new mode 100755 index 29d54a5..76dd89f --- a/server/MultiplayerMatch.js +++ b/server/MultiplayerMatch.js @@ -148,10 +148,9 @@ class MultiplayerMatch { this.activeMods = MatchData.activeMods; - if (this.gameName !== MatchData.gameName) { - this.gameName = MatchData.gameName; - await global.DatabaseHelper.query("UPDATE mp_matches SET name = ? WHERE id = ?", [this.gameName, this.matchId]); - } + const gameNameChanged = this.gameName !== MatchData.gameName; + this.gameName = MatchData.gameName; + if (MatchData.gamePassword == '') MatchData.gamePassword == null; this.gamePassword = MatchData.gamePassword; @@ -167,9 +166,20 @@ class MultiplayerMatch { this.matchTeamType = MatchData.matchTeamType; this.specialModes = MatchData.specialModes; - if (this.seed !== MatchData.seed) { - this.seed = MatchData.seed; - await global.DatabaseHelper.query("UPDATE mp_matches SET seed = ? WHERE id = ?", [this.seed, this.matchId]); + const gameSeedChanged = this.seed !== MatchData.seed; + this.seed = MatchData.seed; + + if (gameNameChanged || gameSeedChanged) { + const queryData = []; + if (gameNameChanged) { + queryData.push(MatchData.gameName); + } + if (gameSeedChanged) { + queryData.push(MatchData.seed); + } + queryData.push(this.matchId); + + await global.DatabaseHelper.query(`UPDATE mp_matches SET ${gameNameChanged ? `name = ?${gameSeedChanged ? ", " : ""}` : ""}${gameSeedChanged ? `seed = ?` : ""} WHERE id = ?`, queryData); } this.sendMatchUpdate(); @@ -430,7 +440,7 @@ class MultiplayerMatch { } } - onPlayerFinishMatch(MatchUser = new User) { + async onPlayerFinishMatch(MatchUser = new User) { if (this.matchLoadSlots == null) { // Repopulate user loading slots again this.matchLoadSlots = []; @@ -461,7 +471,7 @@ class MultiplayerMatch { } // All players have finished playing, finish the match - if (allLoaded) this.finishMatch(); + if (allLoaded) await this.finishMatch(); } async finishMatch() { diff --git a/server/Packets/Logout.js b/server/Packets/Logout.js old mode 100644 new mode 100755 index 5ee25c4..61a91b0 --- a/server/Packets/Logout.js +++ b/server/Packets/Logout.js @@ -1,7 +1,7 @@ const consoleHelper = require("../../consoleHelper.js"), Streams = require("../Streams.js"); -module.exports = function(CurrentUser) { +module.exports = async function(CurrentUser) { if (CurrentUser.uuid === "bot") throw "Tried to log bot out, WTF???"; const logoutStartTime = Date.now(); @@ -17,7 +17,7 @@ module.exports = function(CurrentUser) { // Remove user from user list global.users.remove(CurrentUser.uuid); - global.DatabaseHelper.query("UPDATE osu_info SET value = ? WHERE name = 'online_now'", [global.users.getLength() - 1]); + await global.DatabaseHelper.query("UPDATE osu_info SET value = ? WHERE name = 'online_now'", [global.users.getLength() - 1]); consoleHelper.printBancho(`User logged out, took ${Date.now() - logoutStartTime}ms. [User: ${CurrentUser.username}]`); } \ No newline at end of file diff --git a/server/serverHandler.js b/server/serverHandler.js old mode 100644 new mode 100755 index f7ad279..24a5bd5 --- a/server/serverHandler.js +++ b/server/serverHandler.js @@ -159,7 +159,7 @@ module.exports = async function(req, res) { const PacketData = osuPacketReader.Parse(); // Go through each packet sent by the client - PacketData.forEach(CurrentPacket => { + for (CurrentPacket of PacketData) { switch (CurrentPacket.id) { case packetIDs.client_changeAction: ChangeAction(PacketUser, CurrentPacket.data); @@ -170,7 +170,7 @@ module.exports = async function(req, res) { break; case packetIDs.client_logout: - Logout(PacketUser); + await Logout(PacketUser); break; case packetIDs.client_requestStatusUpdate: @@ -206,7 +206,7 @@ module.exports = async function(req, res) { break; case packetIDs.client_createMatch: - global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data); + await global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data); break; case packetIDs.client_joinMatch: @@ -222,7 +222,7 @@ module.exports = async function(req, res) { break; case packetIDs.client_matchChangeSettings: - PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data); + await PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data); break; case packetIDs.client_matchNotReady: @@ -230,7 +230,7 @@ module.exports = async function(req, res) { break; case packetIDs.client_partMatch: - global.MultiplayerManager.leaveMultiplayerMatch(PacketUser); + await global.MultiplayerManager.leaveMultiplayerMatch(PacketUser); break; // Also handles user kick if the slot has a user @@ -267,7 +267,7 @@ module.exports = async function(req, res) { break; case packetIDs.client_matchComplete: - PacketUser.currentMatch.onPlayerFinishMatch(PacketUser); + await PacketUser.currentMatch.onPlayerFinishMatch(PacketUser); break; case packetIDs.client_matchScoreUpdate: @@ -333,7 +333,7 @@ module.exports = async function(req, res) { console.dir(CurrentPacket); break; } - }); + } responseData = PacketUser.queue; PacketUser.clearQueue();