fix multiplayer after 68c0f1a
broke it
This commit is contained in:
parent
82bef6018b
commit
b7a4e8c451
2 changed files with 35 additions and 39 deletions
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -90,39 +90,29 @@ 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];
|
||||||
|
|
||||||
// Set the slot's status to avaliable
|
// Set the slot's status to avaliable
|
||||||
slot.playerId = -1;
|
slot.playerId = -1;
|
||||||
slot.status = 1;
|
slot.status = 1;
|
||||||
|
|
||||||
MatchUser.currentMatch = null;
|
// Remove the leaving user from the match's stream
|
||||||
MatchUser.matchSlotId = -1;
|
global.StreamsHandler.removeUserFromStream(this.matchStreamName, MatchUser.uuid);
|
||||||
|
global.StreamsHandler.removeUserFromStream(this.matchChatStreamName, MatchUser.uuid);
|
||||||
|
|
||||||
MatchUser.inMatch = false;
|
// Send this after removing the user from match streams to avoid a leave notification for self
|
||||||
|
this.sendMatchUpdate();
|
||||||
|
|
||||||
this.sendMatchUpdate();
|
const osuPacketWriter = new osu.Bancho.Writer;
|
||||||
|
|
||||||
// Remove the leaving user from the match's stream
|
// Remove user from the multiplayer channel for the match
|
||||||
global.StreamsHandler.removeUserFromStream(this.matchStreamName, MatchUser.uuid);
|
osuPacketWriter.ChannelRevoked("#multiplayer");
|
||||||
global.StreamsHandler.removeUserFromStream(this.matchChatStreamName, MatchUser.uuid);
|
|
||||||
|
|
||||||
const osuPacketWriter = new osu.Bancho.Writer;
|
MatchUser.addActionToQueue(osuPacketWriter.toBuffer);
|
||||||
|
|
||||||
// Remove user from the multiplayer channel for the match
|
|
||||||
osuPacketWriter.ChannelRevoked("#multiplayer");
|
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue