diff --git a/server/BanchoServer.ts b/server/BanchoServer.ts index 7983e50..edabed5 100644 --- a/server/BanchoServer.ts +++ b/server/BanchoServer.ts @@ -66,6 +66,7 @@ import TourneyMatchLeaveChannel from "./packets/TourneyMatchLeaveChannel"; import AddFriend from "./packets/AddFriend"; import RemoveFriend from "./packets/RemoveFriend"; import PrivateChannel from "./objects/PrivateChannel"; +import MultiplayerInvite from "./packets/MultiplayerInvite"; // User timeout interval setInterval(() => { @@ -181,7 +182,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_PartMatch: - await PacketUser.match?.leaveMatch(PacketUser); + await shared.multiplayerManager.LeaveMatch(PacketUser); break; case Packets.Client_MatchLock: @@ -269,7 +270,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo break; case Packets.Client_Invite: - //MultiplayerInvite(PacketUser, CurrentPacket.data); + MultiplayerInvite(PacketUser, CurrentPacket.data); break; case Packets.Client_UserPresenceRequest: diff --git a/server/MultiplayerManager.ts b/server/MultiplayerManager.ts index d419aea..4a59690 100644 --- a/server/MultiplayerManager.ts +++ b/server/MultiplayerManager.ts @@ -11,6 +11,7 @@ import MatchArray from "./objects/MatchArray"; import MatchJoinData from "./interfaces/MatchJoinData"; import MatchData from "./interfaces/MatchData"; import osu from "../osuTyping"; +import TourneyMatchSpecialInfo from "./packets/TourneyMatchSpecialInfo"; export default class MultiplayerManager { private readonly shared:Shared; @@ -86,7 +87,7 @@ export default class MultiplayerManager { const osuPacketWriter = osu.Bancho.Writer(); - osuPacketWriter.MatchJoinSuccess(match.generateMatchJSON()); + osuPacketWriter.MatchJoinSuccess(match.serialiseMatch()); user.addActionToQueue(osuPacketWriter.toBuffer); @@ -126,7 +127,7 @@ export default class MultiplayerManager { bufferToSend = Buffer.concat([bufferToSend, presenceBuffer, statusBuffer], bufferToSend.length + presenceBuffer.length + statusBuffer.length); } - osuPacketWriter.MatchNew(match.generateMatchJSON()); + osuPacketWriter.MatchNew(match.serialiseMatch()); } const osuBuffer = osuPacketWriter.toBuffer; @@ -148,4 +149,21 @@ export default class MultiplayerManager { this.matches.add(match.matchId.toString(), match); this.JoinMatch(user, match.matchId); } + + public async LeaveMatch(user:User) { + if (user.match instanceof Match) { + user.match.leaveMatch(user); + let usersInMatch = false; + for (const slot of user.match.slots) { + if (slot.player !== undefined) { + usersInMatch = true; + break; + } + } + if (!usersInMatch) { + this.matches.remove(user.match.matchId.toString()); + } + this.UpdateLobbyListing(); + } + } } \ No newline at end of file diff --git a/server/packets/MultiplayerInvite.ts b/server/packets/MultiplayerInvite.ts new file mode 100644 index 0000000..09f0a2e --- /dev/null +++ b/server/packets/MultiplayerInvite.ts @@ -0,0 +1,19 @@ +import PrivateChannel from "../objects/PrivateChannel"; +import User from "../objects/User"; + +export default function MultiplayerInvite(user:User, invitedUserId:number) { + const invitedUser = user.shared.users.getById(invitedUserId); + if (invitedUser instanceof User) { + let channel = user.shared.privateChatManager.GetChannelByName(`${user.username}${invitedUser.username}`); + if (!(channel instanceof PrivateChannel)) { + // Try it the other way around + channel = user.shared.privateChatManager.GetChannelByName(`${invitedUser.username}${user.username}`); + } + + if (!(channel instanceof PrivateChannel)) { + channel = user.shared.privateChatManager.AddChannel(user, invitedUser); + } + + channel.SendMessage(user, `Come join my multiplayer match: [osump://${user.match?.matchId}/ ${user.match?.gameName}]`); + } +} \ No newline at end of file diff --git a/server/packets/TourneyMatchSpecialInfo.ts b/server/packets/TourneyMatchSpecialInfo.ts index c3ce745..70a9d03 100644 --- a/server/packets/TourneyMatchSpecialInfo.ts +++ b/server/packets/TourneyMatchSpecialInfo.ts @@ -11,7 +11,7 @@ export default function TourneyMatchSpecialInfo(user:User, matchId:number) { } const osuPacketWriter = osu.Bancho.Writer(); - osuPacketWriter.MatchUpdate(match.generateMatchJSON()); + osuPacketWriter.MatchUpdate(match.serialiseMatch()); for (const slot of match.slots) { if (slot.player === undefined) {