fix multiplayer after 68c0f1a broke it

This commit is contained in:
Holly Stubbs 2022-07-05 08:13:45 +01:00
parent 82bef6018b
commit b7a4e8c451
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E
2 changed files with 35 additions and 39 deletions

View file

@ -2,7 +2,8 @@ const osu = require("osu-packet"),
UserPresenceBundle = require("./Packets/UserPresenceBundle.js"), UserPresenceBundle = require("./Packets/UserPresenceBundle.js"),
UserPresence = require("./Packets/UserPresence.js"), UserPresence = require("./Packets/UserPresence.js"),
StatusUpdate = require("./Packets/StatusUpdate.js"), StatusUpdate = require("./Packets/StatusUpdate.js"),
MultiplayerMatch = require("./MultiplayerMatch.js"); MultiplayerMatch = require("./MultiplayerMatch.js"),
User = require("./User.js");
module.exports = class { module.exports = class {
constructor() { constructor() {
@ -164,16 +165,18 @@ module.exports = class {
} }
} }
leaveMultiplayerMatch(MatchUser) { leaveMultiplayerMatch(MatchUser = new User) {
// Make sure the user is in a match // Make sure the user is in a match
if (MatchUser.currentMatch == null) return; if (MatchUser.currentMatch == null) return;
const mpLobby = MatchUser.currentMatch.leaveMatch(MatchUser); const mpMatch = MatchUser.currentMatch;
mpMatch.leaveMatch(MatchUser);
let empty = true; let empty = true;
// Check if the match is empty // Check if the match is empty
for (let i = 0; i < mpLobby.slots.length; i++) { for (let i = 0; i < mpMatch.slots.length; i++) {
const slot = mpLobby.slots[i]; const slot = mpMatch.slots[i];
// Check if the slot is avaliable // Check if the slot is avaliable
if (slot.playerId === -1) continue; if (slot.playerId === -1) continue;
@ -204,6 +207,8 @@ module.exports = class {
MatchUser.currentMatch = null; MatchUser.currentMatch = null;
MatchUser.matchSlotId = -1; MatchUser.matchSlotId = -1;
MatchUser.inMatch = false;
// Update the match listing to reflect this change (either removal or user leaving) // Update the match listing to reflect this change (either removal or user leaving)
this.updateMatchListing(); this.updateMatchListing();

View file

@ -90,9 +90,8 @@ module.exports = class {
} }
leaveMatch(MatchUser = new User) { leaveMatch(MatchUser = new User) {
try {
// Make sure this leave call is valid // Make sure this leave call is valid
if (MatchUser.inMatch) return; if (!MatchUser.inMatch) return;
// Get the user's slot // Get the user's slot
const slot = this.slots[MatchUser.matchSlotId]; const slot = this.slots[MatchUser.matchSlotId];
@ -101,28 +100,19 @@ module.exports = class {
slot.playerId = -1; slot.playerId = -1;
slot.status = 1; slot.status = 1;
MatchUser.currentMatch = null;
MatchUser.matchSlotId = -1;
MatchUser.inMatch = false;
this.sendMatchUpdate();
// Remove the leaving user from the match's stream // Remove the leaving user from the match's stream
global.StreamsHandler.removeUserFromStream(this.matchStreamName, MatchUser.uuid); global.StreamsHandler.removeUserFromStream(this.matchStreamName, MatchUser.uuid);
global.StreamsHandler.removeUserFromStream(this.matchChatStreamName, MatchUser.uuid); global.StreamsHandler.removeUserFromStream(this.matchChatStreamName, MatchUser.uuid);
// Send this after removing the user from match streams to avoid a leave notification for self
this.sendMatchUpdate();
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
// Remove user from the multiplayer channel for the match // Remove user from the multiplayer channel for the match
osuPacketWriter.ChannelRevoked("#multiplayer"); osuPacketWriter.ChannelRevoked("#multiplayer");
MatchUser.addActionToQueue(osuPacketWriter.toBuffer); MatchUser.addActionToQueue(osuPacketWriter.toBuffer);
return this;
} catch (e) {
console.error(e);
}
} }
updateMatch(MatchUser = new User, MatchData) { updateMatch(MatchUser = new User, MatchData) {
@ -192,7 +182,7 @@ module.exports = class {
} }
setStateReady(MatchUser = new User) { setStateReady(MatchUser = new User) {
if (MatchUser.inMatch) return; if (!MatchUser.inMatch) return;
// Set the user's ready state to ready // Set the user's ready state to ready
this.slots[MatchUser.matchSlotId].status = 8; this.slots[MatchUser.matchSlotId].status = 8;
@ -201,7 +191,7 @@ module.exports = class {
} }
setStateNotReady(MatchUser = new User) { setStateNotReady(MatchUser = new User) {
if (MatchUser.inMatch) return; if (!MatchUser.inMatch) return;
// Set the user's ready state to not ready // Set the user's ready state to not ready
this.slots[MatchUser.matchSlotId].status = 4; this.slots[MatchUser.matchSlotId].status = 4;
@ -399,7 +389,8 @@ module.exports = class {
this.matchLoadSlots = null; this.matchLoadSlots = null;
this.playerScores = []; this.playerScores = [];
for (let slot of this.slots) { for (let i = 0; i < this.slots.length; i++) {
const slot = this.slots[i];
if (slot.playerId === -1 || slot.status === 1 || slot.status === 2) continue; if (slot.playerId === -1 || slot.status === 1 || slot.status === 2) continue;
this.playerScores.push({playerId: slot.playerId, slotId: i, score: 0, isCurrentlyFailed: false}); this.playerScores.push({playerId: slot.playerId, slotId: i, score: 0, isCurrentlyFailed: false});
@ -482,10 +473,10 @@ module.exports = class {
MatchScoreData.id = MatchPlayer.matchSlotId; MatchScoreData.id = MatchPlayer.matchSlotId;
// Update the playerScores array accordingly // Update the playerScores array accordingly
for (let i = 0; i < this.playerScores.length; i++) { for (let playerScore of this.playerScores) {
if (this.playerScores[i].playerId == MatchPlayer.id) { if (playerScore.playerId == MatchPlayer.id) {
this.playerScores[i].score = MatchScoreData.totalScore; playerScore.score = MatchScoreData.totalScore;
this.playerScores[i].isCurrentlyFailed = MatchScoreData.currentHp == 254; playerScore.isCurrentlyFailed = MatchScoreData.currentHp == 254;
break; break;
} }
} }