Binato/server/packets/StatusUpdate.ts

50 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-10 12:59:22 +01:00
import Shared from "../objects/Shared";
2023-10-07 13:09:10 +01:00
import { RankingMode } from "../enums/RankingMode";
2023-09-10 12:59:22 +01:00
import User from "../objects/User";
import osu from "../../osuTyping";
2022-11-19 01:06:03 +00:00
2023-09-10 12:59:22 +01:00
export default function StatusUpdate(arg0:User | Shared, id:number) {
2023-10-07 13:09:10 +01:00
// Ignore Bot
if (id == 3) {
return Buffer.allocUnsafe(0);
}
2022-11-19 01:06:03 +00:00
// Create new osu packet writer
2023-08-20 13:03:01 +01:00
const osuPacketWriter = osu.Bancho.Writer();
let shared:Shared;
2022-11-21 23:26:20 +00:00
if (arg0 instanceof User) {
2023-08-20 13:03:01 +01:00
shared = arg0.shared;
2022-11-21 23:26:20 +00:00
} else {
2023-08-20 13:03:01 +01:00
shared = arg0;
2022-11-21 23:26:20 +00:00
}
2022-11-19 01:06:03 +00:00
// Get user's class
2023-08-20 13:03:01 +01:00
const userData = shared.users.getById(id);
2022-11-19 01:06:03 +00:00
2023-10-07 13:09:10 +01:00
if (userData == null) {
return Buffer.allocUnsafe(0);
}
2022-11-19 01:06:03 +00:00
2023-10-03 10:09:44 +01:00
osuPacketWriter.HandleOsuUpdate({
2022-11-19 01:06:03 +00:00
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,
2023-10-07 13:09:10 +01:00
performance: (userData.rankingMode == RankingMode.PP ? userData.pp : 0)
2023-10-03 10:09:44 +01:00
});
2022-11-19 01:06:03 +00:00
// 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
}