Multiplayer Optimisations

This commit is contained in:
tgpethan 2021-02-12 23:16:12 +00:00
parent 0d2d825148
commit 69de312cf0

View file

@ -187,27 +187,16 @@ module.exports = class {
moveToSlot(MatchUser, SlotToMoveTo) { moveToSlot(MatchUser, SlotToMoveTo) {
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
const oldSlot = this.slots[MatchUser.matchSlotId];
let currentUserData, slotIndex;
// Loop through all slots in the match
for (let i = 0; i < this.slots.length; i++) {
const slot = this.slots[i];
// Make sure the user in this slot is the user we want
if (slot.playerId != MatchUser.id) continue;
currentUserData = slot;
slotIndex = i;
break;
}
// Set the new slot's data to the user's old slot data // Set the new slot's data to the user's old slot data
this.slots[SlotToMoveTo].playerId = currentUserData.playerId; this.slots[SlotToMoveTo].playerId = MatchUser.id;
MatchUser.matchSlotId = SlotToMoveTo; MatchUser.matchSlotId = SlotToMoveTo;
this.slots[SlotToMoveTo].status = currentUserData.status; this.slots[SlotToMoveTo].status = 4;
// Set the old slot's data to open // Set the old slot's data to open
this.slots[slotIndex].playerId = -1; oldSlot.playerId = -1;
this.slots[slotIndex].status = 1; oldSlot.status = 1;
osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); osuPacketWriter.MatchUpdate(this.createOsuMatchJSON());
@ -220,11 +209,7 @@ module.exports = class {
changeTeam(MatchUser) { changeTeam(MatchUser) {
const slot = this.slots[MatchUser.matchSlotId]; const slot = this.slots[MatchUser.matchSlotId];
if (slot.team == 0) { slot.team = slot.team == 0 ? 1 : 0;
slot.team = 1;
} else {
slot.team = 0;
}
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
@ -267,19 +252,20 @@ module.exports = class {
// Get the data of the slot at the index sent by the client // Get the data of the slot at the index sent by the client
const slot = this.slots[MatchUserToKick]; const slot = this.slots[MatchUserToKick];
let cachedPlayerToken = getUserById(slot.playerId).uuid;
// If the slot is empty lock instead of kicking let isSlotEmpty = true;
if (slot.playerId === -1) { // Slot is empty, lock it
if (slot.status === 1) slot.status = 2; // If the slot is empty lock/unlock instead of kicking
else slot.status = 1; if (slot.playerId === -1)
} slot.status = slot.status === 1 ? 2 : 1;
// The slot isn't empty, prepare to kick the player
// The slot isn't empty, kick the player
else { else {
const kickedPlayer = getUserById(slot.playerId); const kickedPlayer = getUserById(slot.playerId);
kickedPlayer.matchSlotId = -1; kickedPlayer.matchSlotId = -1;
slot.playerId = -1; slot.playerId = -1;
slot.status = 1; slot.status = 1;
isSlotEmpty = false;
} }
osuPacketWriter.MatchUpdate(this.createOsuMatchJSON()); osuPacketWriter.MatchUpdate(this.createOsuMatchJSON());
@ -290,11 +276,15 @@ module.exports = class {
// Update the match listing in the lobby listing to reflect this change // Update the match listing in the lobby listing to reflect this change
global.MultiplayerManager.updateMatchListing(); global.MultiplayerManager.updateMatchListing();
if (!isSlotEmpty) {
let cachedPlayerToken = getUserById(slot.playerId).uuid;
if (cachedPlayerToken !== null && cachedPlayerToken !== "") { if (cachedPlayerToken !== null && cachedPlayerToken !== "") {
// Remove the kicked user from the match stream // Remove the kicked user from the match stream
global.StreamsHandler.removeUserFromStream(this.matchStreamName, cachedPlayerToken); global.StreamsHandler.removeUserFromStream(this.matchStreamName, cachedPlayerToken);
} }
} }
}
missingBeatmap(MatchUser) { missingBeatmap(MatchUser) {
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
@ -356,13 +346,16 @@ module.exports = class {
// All players have finished playing, finish the match // All players have finished playing, finish the match
if (allSkipped) { if (allSkipped) {
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.MatchPlayerSkipped(MatchUser.id); osuPacketWriter.MatchPlayerSkipped(MatchUser.id);
osuPacketWriter.MatchSkip(); osuPacketWriter.MatchSkip();
global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null);
this.matchSkippedSlots = null; this.matchSkippedSlots = null;
} else { } else {
const osuPacketWriter = new osu.Bancho.Writer; const osuPacketWriter = new osu.Bancho.Writer;
osuPacketWriter.MatchPlayerSkipped(MatchUser.id); osuPacketWriter.MatchPlayerSkipped(MatchUser.id);
global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null); global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null);