Binato/server/packets/StatusUpdate.ts

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-11-23 00:48:28 +00:00
import { SharedContent } from "../interfaces/SharedContent";
2022-11-19 01:06:03 +00:00
import { RankingModes } from "../enums/RankingModes";
import { User } from "../objects/User";
const osu = require("osu-packet");
2022-11-21 23:26:20 +00:00
export function StatusUpdate(arg0:User | SharedContent, id:number) {
2022-11-19 01:06:03 +00:00
if (id == 3) return; // Ignore Bot
// Create new osu packet writer
const osuPacketWriter = new osu.Bancho.Writer;
2022-11-21 23:26:20 +00:00
let sharedContent:SharedContent;
if (arg0 instanceof User) {
sharedContent = arg0.sharedContent;
} else {
sharedContent = arg0;
}
2022-11-19 01:06:03 +00:00
// Get user's class
2022-11-21 23:26:20 +00:00
const userData = sharedContent.users.getById(id);
2022-11-19 01:06:03 +00:00
if (userData == null) return;
let UserStatusObject = {
userId: userData.id,
status: userData.actionID,
statusText: userData.actionText,
beatmapChecksum: userData.beatmapChecksum,
currentMods: userData.currentMods,
playMode: userData.playMode,
beatmapId: userData.beatmapID,
rankedScore: userData.rankedScore,
accuracy: userData.accuracy * 0.01, // Scale from 0:100 to 0:1
playCount: userData.playCount,
totalScore: userData.totalScore,
rank: userData.rank,
performance: (userData.rankingMode == RankingModes.PP ? userData.pp : 0)
};
osuPacketWriter.HandleOsuUpdate(UserStatusObject);
// Send data to user's queue
2022-11-21 23:26:20 +00:00
if (arg0 instanceof User) {
arg0.addActionToQueue(osuPacketWriter.toBuffer);
}
return osuPacketWriter.toBuffer;
2022-11-19 01:06:03 +00:00
}