Generalize packet functions
This commit is contained in:
parent
99329d1c70
commit
05aefff23f
5 changed files with 54 additions and 33 deletions
|
@ -142,7 +142,7 @@ module.exports = class {
|
|||
}
|
||||
}
|
||||
|
||||
updateMatch(MatchData) {
|
||||
updateMatch(MatchUser, MatchData) {
|
||||
// Update match with new data
|
||||
this.inProgress = MatchData.inProgress;
|
||||
|
||||
|
@ -221,7 +221,7 @@ module.exports = class {
|
|||
global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null);
|
||||
}
|
||||
|
||||
setReadyState(MatchUser, ReadyState) {
|
||||
setStateReady(MatchUser) {
|
||||
// Get the match the user is in
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
|
||||
|
@ -230,9 +230,29 @@ module.exports = class {
|
|||
const slot = this.slots[i];
|
||||
// Check if the player in this slot is this user
|
||||
if (slot.playerId == MatchUser.id) {
|
||||
// Turn on or off the user's ready state
|
||||
if (ReadyState) slot.status = 8; // Ready
|
||||
else slot.status = 4; // Not Ready
|
||||
// Turn on the user's ready state
|
||||
slot.status = 8; // Ready
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
osuPacketWriter.MatchUpdate(this.createOsuMatchJSON());
|
||||
|
||||
// Send this update to all users in the stream
|
||||
global.StreamsHandler.sendToStream(this.matchStreamName, osuPacketWriter.toBuffer, null);
|
||||
}
|
||||
|
||||
setStateNotReady(MatchUser) {
|
||||
// Get the match the user is in
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
|
||||
// Loop though all slots in the match
|
||||
for (let i = 0; i < this.slots.length; i++) {
|
||||
const slot = this.slots[i];
|
||||
// Check if the player in this slot is this user
|
||||
if (slot.playerId == MatchUser.id) {
|
||||
// Turn off the user's ready state
|
||||
slot.status = 4; // Not Ready
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -364,7 +384,7 @@ module.exports = class {
|
|||
}
|
||||
}
|
||||
|
||||
transferHost(SlotIDToTransferTo) {
|
||||
transferHost(MatchUser, SlotIDToTransferTo) {
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
|
||||
// Set the lobby's host to the new user
|
||||
|
|
|
@ -14,7 +14,7 @@ module.exports = function(CurrentUser) {
|
|||
// Remove user from user list
|
||||
global.removeUser(CurrentUser);
|
||||
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
const osuPacketWriter = new osu.Bancho.Writer();
|
||||
osuPacketWriter.SendMessage({
|
||||
sendingClient: global.users["bot"].username,
|
||||
message: `User ${CurrentUser.username} has logged out.`,
|
||||
|
|
|
@ -3,13 +3,13 @@ const osu = require("osu-packet"),
|
|||
|
||||
module.exports = function(CurrentUser, CurrentPacket) {
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
const userSentTo = getUserByUsername(CurrentPacket.data.target);
|
||||
const userSentTo = getUserByUsername(CurrentPacket.target);
|
||||
|
||||
if (userSentTo == null) return;
|
||||
|
||||
osuPacketWriter.SendMessage({
|
||||
sendingClient: CurrentUser.username,
|
||||
message: CurrentPacket.data.message,
|
||||
message: CurrentPacket.message,
|
||||
target: CurrentUser.username,
|
||||
senderId: CurrentUser.id
|
||||
});
|
||||
|
|
|
@ -4,22 +4,22 @@ const osu = require("osu-packet"),
|
|||
module.exports = function(CurrentUser, CurrentPacket) {
|
||||
let isSendingChannelLocked = false;
|
||||
for (let i = 0; i < global.channels.length; i++) {
|
||||
if (!CurrentPacket.data.target.includes("#")) break;
|
||||
if (global.channels[i].channelName == CurrentPacket.data.target) {
|
||||
if (!CurrentPacket.target.includes("#")) break;
|
||||
if (global.channels[i].channelName == CurrentPacket.target) {
|
||||
isSendingChannelLocked = global.channels[i].locked;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSendingChannelLocked) {
|
||||
if (CurrentPacket.data.message.includes("!")) {
|
||||
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
|
||||
if (CurrentPacket.message.includes("!")) {
|
||||
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
|
||||
} else {
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
osuPacketWriter.SendMessage({
|
||||
sendingClient: global.users["bot"].username,
|
||||
message: "The channel you are currently trying to send to is locked, please check back later!",
|
||||
target: CurrentPacket.data.target,
|
||||
target: CurrentPacket.target,
|
||||
senderId: global.users["bot"].id
|
||||
});
|
||||
CurrentUser.addActionToQueue(osuPacketWriter.toBuffer);
|
||||
|
@ -27,29 +27,30 @@ module.exports = function(CurrentUser, CurrentPacket) {
|
|||
return;
|
||||
}
|
||||
|
||||
global.consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.data.target} sent: ${CurrentPacket.data.message}`);
|
||||
global.consoleHelper.printChat(`${CurrentUser.username} in ${CurrentPacket.target} sent: ${CurrentPacket.message}`);
|
||||
|
||||
const osuPacketWriter = new osu.Bancho.Writer;
|
||||
osuPacketWriter.SendMessage({
|
||||
sendingClient: CurrentUser.username,
|
||||
message: CurrentPacket.data.message,
|
||||
target: CurrentPacket.data.target,
|
||||
message: CurrentPacket.message,
|
||||
target: CurrentPacket.target,
|
||||
senderId: CurrentUser.id
|
||||
});
|
||||
|
||||
if (CurrentPacket.data.target == "#multiplayer") {
|
||||
if (CurrentPacket.target == "#multiplayer") {
|
||||
global.StreamsHandler.sendToStream(CurrentUser.currentMatch.matchChatStreamName, osuPacketWriter.toBuffer, CurrentUser.uuid);
|
||||
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentUser.currentMatch.matchChatStreamName, true);
|
||||
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentUser.currentMatch.matchChatStreamName, true);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check the stream that we're sending to even exists
|
||||
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.data.target)) return;
|
||||
if (!global.StreamsHandler.doesStreamExist(CurrentPacket.target)) return;
|
||||
|
||||
// Write chat message to stream asociated with chat channel
|
||||
global.StreamsHandler.sendToStream(CurrentPacket.data.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
|
||||
if (CurrentPacket.data.target == "#osu")
|
||||
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.data.message}`);
|
||||
botCommandHandler(CurrentUser, CurrentPacket.data.message, CurrentPacket.data.target);
|
||||
global.StreamsHandler.sendToStream(CurrentPacket.target, osuPacketWriter.toBuffer, CurrentUser.uuid);
|
||||
if (CurrentPacket.target == "#osu")
|
||||
global.addChatMessage(`${CurrentUser.username}: ${CurrentPacket.message}`);
|
||||
|
||||
botCommandHandler(CurrentUser, CurrentPacket.message, CurrentPacket.target);
|
||||
return;
|
||||
}
|
|
@ -132,7 +132,7 @@ const ChangeAction = require("./Packets/ChangeAction.js"),
|
|||
TourneyMatchLeaveChannel = require("./Packets/TourneyLeaveMatchChannel.js");
|
||||
|
||||
const emptyBuffer = Buffer.alloc(0);
|
||||
|
||||
|
||||
// A class for managing everything multiplayer
|
||||
global.MultiplayerManager = new MultiplayerManager();
|
||||
|
||||
|
@ -169,7 +169,7 @@ module.exports = async function(req, res) {
|
|||
for (let i = 0; i < PacketData.length; i++) {
|
||||
// Get current packet
|
||||
let CurrentPacket = PacketData[i];
|
||||
|
||||
|
||||
// This is getting a little big, swap this out for mapped functions?
|
||||
// Would require some standardisation
|
||||
switch (CurrentPacket.id) {
|
||||
|
@ -178,7 +178,7 @@ module.exports = async function(req, res) {
|
|||
break;
|
||||
|
||||
case packetIDs.client_sendPublicMessage:
|
||||
SendPublicMessage(PacketUser, CurrentPacket);
|
||||
SendPublicMessage(PacketUser, CurrentPacket.data);
|
||||
break;
|
||||
|
||||
case packetIDs.client_logout:
|
||||
|
@ -206,7 +206,7 @@ module.exports = async function(req, res) {
|
|||
break;
|
||||
|
||||
case packetIDs.client_sendPrivateMessage:
|
||||
SendPrivateMessage(PacketUser, CurrentPacket);
|
||||
SendPrivateMessage(PacketUser, CurrentPacket.data);
|
||||
break;
|
||||
|
||||
case packetIDs.client_joinLobby:
|
||||
|
@ -230,15 +230,15 @@ module.exports = async function(req, res) {
|
|||
break;
|
||||
|
||||
case packetIDs.client_matchReady:
|
||||
PacketUser.currentMatch.setReadyState(PacketUser, true);
|
||||
PacketUser.currentMatch.setStateReady(PacketUser);
|
||||
break;
|
||||
|
||||
case packetIDs.client_matchChangeSettings:
|
||||
PacketUser.currentMatch.updateMatch(CurrentPacket.data);
|
||||
PacketUser.currentMatch.updateMatch(PacketUser, CurrentPacket.data);
|
||||
break;
|
||||
|
||||
case packetIDs.client_matchNotReady:
|
||||
PacketUser.currentMatch.setReadyState(PacketUser, false);
|
||||
PacketUser.currentMatch.setStateNotReady(PacketUser);
|
||||
break;
|
||||
|
||||
case packetIDs.client_partMatch:
|
||||
|
@ -263,7 +263,7 @@ module.exports = async function(req, res) {
|
|||
break;
|
||||
|
||||
case packetIDs.client_matchTransferHost:
|
||||
PacketUser.currentMatch.transferHost(CurrentPacket.data);
|
||||
PacketUser.currentMatch.transferHost(PacketUser, CurrentPacket.data);
|
||||
break;
|
||||
|
||||
case packetIDs.client_matchChangeMods:
|
||||
|
@ -331,7 +331,7 @@ module.exports = async function(req, res) {
|
|||
break;
|
||||
|
||||
case packetIDs.client_userPresenceRequest:
|
||||
UserPresence(PacketUser, PacketUser.id);
|
||||
UserPresence(PacketUser, PacketUser.id); // Can't really think of a way to generalize this?
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue