2022-11-20 23:37:39 +00:00
|
|
|
import { SharedContent } from "./BanchoServer";
|
2022-11-21 23:26:20 +00:00
|
|
|
import { SlotStatus } from "./enums/SlotStatus";
|
2022-11-19 01:06:03 +00:00
|
|
|
import { DataStream } from "./objects/DataStream";
|
|
|
|
import { DataStreamArray } from "./objects/DataStreamArray";
|
|
|
|
import { FunkyArray } from "./objects/FunkyArray";
|
2022-11-20 23:37:39 +00:00
|
|
|
import { Match, MatchData } from "./objects/Match";
|
2022-11-19 01:06:03 +00:00
|
|
|
import { User } from "./objects/User";
|
2022-11-21 23:26:20 +00:00
|
|
|
import { StatusUpdate } from "./packets/StatusUpdate";
|
|
|
|
import { UserPresence } from "./packets/UserPresence";
|
|
|
|
import { UserPresenceBundle } from "./packets/UserPresenceBundle";
|
|
|
|
const osu = require("osu-packet");
|
2022-11-19 01:06:03 +00:00
|
|
|
|
|
|
|
export class MultiplayerManager {
|
2022-11-20 23:37:39 +00:00
|
|
|
private readonly sharedContent:SharedContent;
|
2022-11-19 01:06:03 +00:00
|
|
|
private matches:FunkyArray<Match> = new FunkyArray<Match>();
|
|
|
|
private readonly lobbyStream:DataStream;
|
|
|
|
|
2022-11-20 23:37:39 +00:00
|
|
|
public constructor(sharedContent:SharedContent) {
|
|
|
|
this.sharedContent = sharedContent;
|
|
|
|
this.lobbyStream = sharedContent.streams.CreateStream("multiplayer:lobby", false);
|
2022-11-19 01:06:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public JoinLobby(user:User) {
|
|
|
|
if (user.currentMatch != null) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2022-11-20 23:37:39 +00:00
|
|
|
|
2022-11-21 23:26:20 +00:00
|
|
|
public UpdateLobbyListing() {
|
|
|
|
this.lobbyStream.Send(this.GenerateLobbyListing());
|
|
|
|
}
|
|
|
|
|
|
|
|
public GenerateLobbyListing(user?:User) : Buffer {
|
|
|
|
const osuPacketWriter = new osu.Bancho.Writer;
|
|
|
|
let bufferToSend = UserPresenceBundle(this.sharedContent);
|
|
|
|
|
|
|
|
for (let match of this.matches.getIterableItems()) {
|
|
|
|
for (let slot of match.slots) {
|
|
|
|
if (!(slot.player instanceof User) || slot.status === SlotStatus.Locked) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const presenceBuffer = UserPresence(this.sharedContent, slot.player.id);
|
|
|
|
const statusBuffer = StatusUpdate(this.sharedContent, slot.player.id);
|
|
|
|
bufferToSend = Buffer.concat([bufferToSend, presenceBuffer, statusBuffer], bufferToSend.length + presenceBuffer.length + statusBuffer.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
osuPacketWriter.MatchNew(match.generateMatchJSON());
|
|
|
|
}
|
|
|
|
|
|
|
|
const osuBuffer = osuPacketWriter.toBuffer;
|
|
|
|
bufferToSend = Buffer.concat([bufferToSend, osuBuffer], bufferToSend.length + osuBuffer.length);
|
|
|
|
|
|
|
|
if (user instanceof User) {
|
|
|
|
user.addActionToQueue(bufferToSend);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bufferToSend;
|
|
|
|
}
|
|
|
|
|
2022-11-20 23:37:39 +00:00
|
|
|
public async CreateMatch(user:User, matchData:MatchData) {
|
|
|
|
const match = await Match.createMatch(user, matchData, this.sharedContent);
|
|
|
|
this.matches.add(match.matchId.toString(), match);
|
|
|
|
}
|
2022-11-17 00:29:07 +00:00
|
|
|
}
|