Bugfix a lot of multiplayer
This commit is contained in:
parent
f66c867d17
commit
aff53f1ab9
4 changed files with 43 additions and 5 deletions
|
@ -66,6 +66,7 @@ import TourneyMatchLeaveChannel from "./packets/TourneyMatchLeaveChannel";
|
||||||
import AddFriend from "./packets/AddFriend";
|
import AddFriend from "./packets/AddFriend";
|
||||||
import RemoveFriend from "./packets/RemoveFriend";
|
import RemoveFriend from "./packets/RemoveFriend";
|
||||||
import PrivateChannel from "./objects/PrivateChannel";
|
import PrivateChannel from "./objects/PrivateChannel";
|
||||||
|
import MultiplayerInvite from "./packets/MultiplayerInvite";
|
||||||
|
|
||||||
// User timeout interval
|
// User timeout interval
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
|
@ -181,7 +182,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_PartMatch:
|
case Packets.Client_PartMatch:
|
||||||
await PacketUser.match?.leaveMatch(PacketUser);
|
await shared.multiplayerManager.LeaveMatch(PacketUser);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_MatchLock:
|
case Packets.Client_MatchLock:
|
||||||
|
@ -269,7 +270,7 @@ export default async function HandleRequest(req:IncomingMessage, res:ServerRespo
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_Invite:
|
case Packets.Client_Invite:
|
||||||
//MultiplayerInvite(PacketUser, CurrentPacket.data);
|
MultiplayerInvite(PacketUser, CurrentPacket.data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Packets.Client_UserPresenceRequest:
|
case Packets.Client_UserPresenceRequest:
|
||||||
|
|
|
@ -11,6 +11,7 @@ import MatchArray from "./objects/MatchArray";
|
||||||
import MatchJoinData from "./interfaces/MatchJoinData";
|
import MatchJoinData from "./interfaces/MatchJoinData";
|
||||||
import MatchData from "./interfaces/MatchData";
|
import MatchData from "./interfaces/MatchData";
|
||||||
import osu from "../osuTyping";
|
import osu from "../osuTyping";
|
||||||
|
import TourneyMatchSpecialInfo from "./packets/TourneyMatchSpecialInfo";
|
||||||
|
|
||||||
export default class MultiplayerManager {
|
export default class MultiplayerManager {
|
||||||
private readonly shared:Shared;
|
private readonly shared:Shared;
|
||||||
|
@ -86,7 +87,7 @@ export default class MultiplayerManager {
|
||||||
|
|
||||||
const osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
|
|
||||||
osuPacketWriter.MatchJoinSuccess(match.generateMatchJSON());
|
osuPacketWriter.MatchJoinSuccess(match.serialiseMatch());
|
||||||
|
|
||||||
user.addActionToQueue(osuPacketWriter.toBuffer);
|
user.addActionToQueue(osuPacketWriter.toBuffer);
|
||||||
|
|
||||||
|
@ -126,7 +127,7 @@ export default class MultiplayerManager {
|
||||||
bufferToSend = Buffer.concat([bufferToSend, presenceBuffer, statusBuffer], bufferToSend.length + presenceBuffer.length + statusBuffer.length);
|
bufferToSend = Buffer.concat([bufferToSend, presenceBuffer, statusBuffer], bufferToSend.length + presenceBuffer.length + statusBuffer.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
osuPacketWriter.MatchNew(match.generateMatchJSON());
|
osuPacketWriter.MatchNew(match.serialiseMatch());
|
||||||
}
|
}
|
||||||
|
|
||||||
const osuBuffer = osuPacketWriter.toBuffer;
|
const osuBuffer = osuPacketWriter.toBuffer;
|
||||||
|
@ -148,4 +149,21 @@ export default class MultiplayerManager {
|
||||||
this.matches.add(match.matchId.toString(), match);
|
this.matches.add(match.matchId.toString(), match);
|
||||||
this.JoinMatch(user, match.matchId);
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
19
server/packets/MultiplayerInvite.ts
Normal file
19
server/packets/MultiplayerInvite.ts
Normal file
|
@ -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}]`);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ export default function TourneyMatchSpecialInfo(user:User, matchId:number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const osuPacketWriter = osu.Bancho.Writer();
|
const osuPacketWriter = osu.Bancho.Writer();
|
||||||
osuPacketWriter.MatchUpdate(match.generateMatchJSON());
|
osuPacketWriter.MatchUpdate(match.serialiseMatch());
|
||||||
|
|
||||||
for (const slot of match.slots) {
|
for (const slot of match.slots) {
|
||||||
if (slot.player === undefined) {
|
if (slot.player === undefined) {
|
||||||
|
|
Loading…
Reference in a new issue