Multiplayer bugfixes

This commit is contained in:
tgpethan 2020-09-02 10:15:41 +01:00
parent 1386fc2207
commit 781a6cc3de
3 changed files with 34 additions and 4 deletions

View file

@ -16,7 +16,6 @@ An implementation of osu!bancho in Javascript
## Bugs: ## 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 - 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 - BinatoStream can create duplicate streams
## How to connect: ## How to connect:

View file

@ -204,6 +204,8 @@ module.exports = {
osuPacketWriter.ChannelJoinSuccess("#multiplayer"); osuPacketWriter.ChannelJoinSuccess("#multiplayer");
currentUser.addActionToQueue(osuPacketWriter.toBuffer); currentUser.addActionToQueue(osuPacketWriter.toBuffer);
this.updateMatchListing();
} catch (e) { } catch (e) {
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
@ -250,6 +252,8 @@ module.exports = {
osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]); osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]);
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.updateMatchListing();
}, },
moveToSlot:function(currentUser, data) { moveToSlot:function(currentUser, data) {
@ -276,6 +280,8 @@ module.exports = {
osuPacketWriter.MatchUpdate(mpLobby); osuPacketWriter.MatchUpdate(mpLobby);
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.updateMatchListing();
}, },
kickPlayer:function(currentUser, data) { kickPlayer:function(currentUser, data) {
@ -301,6 +307,8 @@ module.exports = {
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.updateMatchListing();
if (cachedPlayerId !== null || cachedPlayerId !== -1) { if (cachedPlayerId !== null || cachedPlayerId !== -1) {
global.StreamsHandler.removeUserFromStream(global.matches[currentUser.currentMatch][0], cachedPlayerId); global.StreamsHandler.removeUserFromStream(global.matches[currentUser.currentMatch][0], cachedPlayerId);
} }
@ -349,6 +357,8 @@ module.exports = {
osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]); osuPacketWriter.MatchUpdate(global.matches[currentUser.currentMatch][1]);
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.updateMatchListing();
}, },
startMatch(currentUser) { startMatch(currentUser) {
@ -377,6 +387,8 @@ module.exports = {
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.sendMatchUpdate(currentUser); this.sendMatchUpdate(currentUser);
this.updateMatchListing();
}, },
setPlayerLoaded:function(currentUser) { setPlayerLoaded:function(currentUser) {
@ -454,6 +466,8 @@ module.exports = {
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
this.sendMatchUpdate(currentUser); this.sendMatchUpdate(currentUser);
this.updateMatchListing();
}, },
updatePlayerScore:function(currentUser, data) { updatePlayerScore:function(currentUser, data) {
@ -471,6 +485,19 @@ module.exports = {
leaveMatch:function(currentUser) { leaveMatch:function(currentUser) {
try { try {
const mpLobby = global.matches[currentUser.currentMatch][1]; 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; let osuPacketWriter = new osu.Bancho.Writer;
for (let i = 0; i < mpLobby.slots.length; i++) { for (let i = 0; i < mpLobby.slots.length; i++) {
@ -485,6 +512,8 @@ module.exports = {
osuPacketWriter.MatchUpdate(mpLobby); osuPacketWriter.MatchUpdate(mpLobby);
global.StreamsHandler.removeUserFromStream(global.matches[currentUser.currentMatch][0], currentUser.id);
global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(global.matches[currentUser.currentMatch][0], osuPacketWriter.toBuffer, null);
osuPacketWriter = new osu.Bancho.Writer; osuPacketWriter = new osu.Bancho.Writer;
@ -514,15 +543,15 @@ module.exports = {
// Make sure we got a match index // Make sure we got a match index
if (matchIndex == null) return; if (matchIndex == null) return;
// Remove this match from the list of active matches
global.matches.splice(matchIndex, 1); global.matches.splice(matchIndex, 1);
} }
} catch (e) { } } catch (e) { }
this.updateMatchListing(); this.updateMatchListing();
// Delay a 2nd match listing update
setTimeout(() => { setTimeout(() => {
this.updateMatchListing(); this.updateMatchListing();
}, 500); }, 1000);
} }
} }

View file

@ -1,3 +1,5 @@
module.exports = function(userClass, data) { module.exports = function(userClass, data) {
if (data == "#multiplayer") return; // Ignore requests for multiplayer
global.StreamsHandler.removeUserFromStream(data, userClass.id); global.StreamsHandler.removeUserFromStream(data, userClass.id);
} }