Make a few packets awaited so that the client gets data on time

This commit is contained in:
Holly Stubbs 2022-09-30 11:34:52 +01:00
parent b6b5e3804c
commit ad6ad5ed2c
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
3 changed files with 28 additions and 18 deletions

28
server/MultiplayerMatch.js Normal file → Executable file
View file

@ -148,10 +148,9 @@ class MultiplayerMatch {
this.activeMods = MatchData.activeMods; this.activeMods = MatchData.activeMods;
if (this.gameName !== MatchData.gameName) { const gameNameChanged = this.gameName !== MatchData.gameName;
this.gameName = MatchData.gameName; this.gameName = MatchData.gameName;
await global.DatabaseHelper.query("UPDATE mp_matches SET name = ? WHERE id = ?", [this.gameName, this.matchId]);
}
if (MatchData.gamePassword == '') MatchData.gamePassword == null; if (MatchData.gamePassword == '') MatchData.gamePassword == null;
this.gamePassword = MatchData.gamePassword; this.gamePassword = MatchData.gamePassword;
@ -167,9 +166,20 @@ class MultiplayerMatch {
this.matchTeamType = MatchData.matchTeamType; this.matchTeamType = MatchData.matchTeamType;
this.specialModes = MatchData.specialModes; this.specialModes = MatchData.specialModes;
if (this.seed !== MatchData.seed) { const gameSeedChanged = this.seed !== MatchData.seed;
this.seed = MatchData.seed; this.seed = MatchData.seed;
await global.DatabaseHelper.query("UPDATE mp_matches SET seed = ? WHERE id = ?", [this.seed, this.matchId]);
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(); this.sendMatchUpdate();
@ -430,7 +440,7 @@ class MultiplayerMatch {
} }
} }
onPlayerFinishMatch(MatchUser = new User) { async onPlayerFinishMatch(MatchUser = new User) {
if (this.matchLoadSlots == null) { if (this.matchLoadSlots == null) {
// Repopulate user loading slots again // Repopulate user loading slots again
this.matchLoadSlots = []; this.matchLoadSlots = [];
@ -461,7 +471,7 @@ class MultiplayerMatch {
} }
// All players have finished playing, finish the match // All players have finished playing, finish the match
if (allLoaded) this.finishMatch(); if (allLoaded) await this.finishMatch();
} }
async finishMatch() { async finishMatch() {

4
server/Packets/Logout.js Normal file → Executable file
View file

@ -1,7 +1,7 @@
const consoleHelper = require("../../consoleHelper.js"), const consoleHelper = require("../../consoleHelper.js"),
Streams = require("../Streams.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???"; if (CurrentUser.uuid === "bot") throw "Tried to log bot out, WTF???";
const logoutStartTime = Date.now(); const logoutStartTime = Date.now();
@ -17,7 +17,7 @@ module.exports = function(CurrentUser) {
// Remove user from user list // Remove user from user list
global.users.remove(CurrentUser.uuid); 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}]`); consoleHelper.printBancho(`User logged out, took ${Date.now() - logoutStartTime}ms. [User: ${CurrentUser.username}]`);
} }

14
server/serverHandler.js Normal file → Executable file
View file

@ -159,7 +159,7 @@ module.exports = async function(req, res) {
const PacketData = osuPacketReader.Parse(); const PacketData = osuPacketReader.Parse();
// Go through each packet sent by the client // Go through each packet sent by the client
PacketData.forEach(CurrentPacket => { for (CurrentPacket of PacketData) {
switch (CurrentPacket.id) { switch (CurrentPacket.id) {
case packetIDs.client_changeAction: case packetIDs.client_changeAction:
ChangeAction(PacketUser, CurrentPacket.data); ChangeAction(PacketUser, CurrentPacket.data);
@ -170,7 +170,7 @@ module.exports = async function(req, res) {
break; break;
case packetIDs.client_logout: case packetIDs.client_logout:
Logout(PacketUser); await Logout(PacketUser);
break; break;
case packetIDs.client_requestStatusUpdate: case packetIDs.client_requestStatusUpdate:
@ -206,7 +206,7 @@ module.exports = async function(req, res) {
break; break;
case packetIDs.client_createMatch: case packetIDs.client_createMatch:
global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data); await global.MultiplayerManager.createMultiplayerMatch(PacketUser, CurrentPacket.data);
break; break;
case packetIDs.client_joinMatch: case packetIDs.client_joinMatch:
@ -222,7 +222,7 @@ module.exports = async function(req, res) {
break; break;
case packetIDs.client_matchChangeSettings: case packetIDs.client_matchChangeSettings:
PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data); await PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data);
break; break;
case packetIDs.client_matchNotReady: case packetIDs.client_matchNotReady:
@ -230,7 +230,7 @@ module.exports = async function(req, res) {
break; break;
case packetIDs.client_partMatch: case packetIDs.client_partMatch:
global.MultiplayerManager.leaveMultiplayerMatch(PacketUser); await global.MultiplayerManager.leaveMultiplayerMatch(PacketUser);
break; break;
// Also handles user kick if the slot has a user // Also handles user kick if the slot has a user
@ -267,7 +267,7 @@ module.exports = async function(req, res) {
break; break;
case packetIDs.client_matchComplete: case packetIDs.client_matchComplete:
PacketUser.currentMatch.onPlayerFinishMatch(PacketUser); await PacketUser.currentMatch.onPlayerFinishMatch(PacketUser);
break; break;
case packetIDs.client_matchScoreUpdate: case packetIDs.client_matchScoreUpdate:
@ -333,7 +333,7 @@ module.exports = async function(req, res) {
console.dir(CurrentPacket); console.dir(CurrentPacket);
break; break;
} }
}); }
responseData = PacketUser.queue; responseData = PacketUser.queue;
PacketUser.clearQueue(); PacketUser.clearQueue();