From 781a6cc3de47a941a3c2ac09eedec73dee691ee1 Mon Sep 17 00:00:00 2001 From: tgpethan Date: Wed, 2 Sep 2020 10:15:41 +0100 Subject: [PATCH] Multiplayer bugfixes --- README.md | 1 - server/Multiplayer.js | 35 ++++++++++++++++++++++++++++++++--- server/Packets/ChannelPart.js | 2 ++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 620ea88..90558f1 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,6 @@ An implementation of osu!bancho in Javascript ## Bugs: - If a client clicks the plus button in the chat window to join another channel the client will "crash", the game will keep running but the user will be unable to do anything - - When a user leaves a multiplayer match they are not removed from the stream which will lead to a buildup of streams prefixed with mp_ as it is set to be removed when there are no users in it - BinatoStream can create duplicate streams ## How to connect: diff --git a/server/Multiplayer.js b/server/Multiplayer.js index 2936415..deee157 100644 --- a/server/Multiplayer.js +++ b/server/Multiplayer.js @@ -204,6 +204,8 @@ module.exports = { osuPacketWriter.ChannelJoinSuccess("#multiplayer"); currentUser.addActionToQueue(osuPacketWriter.toBuffer); + + this.updateMatchListing(); } catch (e) { const osuPacketWriter = new osu.Bancho.Writer; @@ -250,6 +252,8 @@ module.exports = { osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); + + this.updateMatchListing(); }, moveToSlot:function(currentUser, data) { @@ -276,6 +280,8 @@ module.exports = { osuPacketWriter.MatchUpdate(mpLobby); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); + + this.updateMatchListing(); }, kickPlayer:function(currentUser, data) { @@ -301,6 +307,8 @@ module.exports = { global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); + this.updateMatchListing(); + if (cachedPlayerId !== null || cachedPlayerId !== -1) { global.StreamsHandler.removeUserFromStream(global.matches[currentUser.currentMatch][0], cachedPlayerId); } @@ -349,6 +357,8 @@ module.exports = { osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); + + this.updateMatchListing(); }, startMatch(currentUser) { @@ -377,6 +387,8 @@ module.exports = { global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); this.sendMatchUpdate(currentUser); + + this.updateMatchListing(); }, setPlayerLoaded:function(currentUser) { @@ -454,6 +466,8 @@ module.exports = { global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); this.sendMatchUpdate(currentUser); + + this.updateMatchListing(); }, updatePlayerScore:function(currentUser, data) { @@ -471,6 +485,19 @@ module.exports = { leaveMatch:function(currentUser) { try { const mpLobby = global.matches[currentUser.currentMatch][1]; + + let containsUser = false; + for (let i = 0; i < mpLobby.slots.length; i++) { + const slot = mpLobby.slots[i]; + if (slot.playerId == currentUser.id) { + containsUser = true; + break; + } + } + + // Make sure we don't run more than once + if (!containsUser) return; + let osuPacketWriter = new osu.Bancho.Writer; for (let i = 0; i < mpLobby.slots.length; i++) { @@ -485,6 +512,8 @@ module.exports = { osuPacketWriter.MatchUpdate(mpLobby); + global.StreamsHandler.removeUserFromStream(global.matches[currentUser.currentMatch][0], currentUser.id); + global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); osuPacketWriter = new osu.Bancho.Writer; @@ -514,15 +543,15 @@ module.exports = { // Make sure we got a match index if (matchIndex == null) return; + // Remove this match from the list of active matches global.matches.splice(matchIndex, 1); - - } } catch (e) { } this.updateMatchListing(); + // Delay a 2nd match listing update setTimeout(() => { this.updateMatchListing(); - }, 500); + }, 1000); } } \ No newline at end of file diff --git a/server/Packets/ChannelPart.js b/server/Packets/ChannelPart.js index 4703e78..79db16f 100644 --- a/server/Packets/ChannelPart.js +++ b/server/Packets/ChannelPart.js @@ -1,3 +1,5 @@ module.exports = function(userClass, data) { + if (data == "#multiplayer") return; // Ignore requests for multiplayer + global.StreamsHandler.removeUserFromStream(data, userClass.id); } \ No newline at end of file