Support player ping in game telemetry

This commit is contained in:
2026-10-06 21:10:25 -04:00
parent 2520735850
commit 675d9b1576
6 changed files with 61 additions and 4 deletions
+9 -1
View File
@@ -1,6 +1,8 @@
export interface TelemetryPlayer {
name: string;
guid: string;
/** Server-measured latency in milliseconds; absent/null when unavailable. */
ping?: number | null;
}
export interface TelemetryPlayerStats extends TelemetryPlayer {
@@ -51,7 +53,13 @@ export function parseGameEvent(value: unknown): GameEvent {
for (const key of ['name', 'guid'] as const) {
if (typeof player[key] !== 'string' || !player[key].trim()) throw new Error(`players[${index}].${key} must be a nonempty string`);
}
const identity = { name: player.name as string, guid: player.guid as string };
const identity: TelemetryPlayer = { name: player.name as string, guid: player.guid as string };
if (player.ping !== undefined) {
if (player.ping !== null && (!Number.isSafeInteger(player.ping) || (player.ping as number) < 0)) {
throw new Error(`players[${index}].ping must be a nonnegative integer or null`);
}
identity.ping = player.ping as number | null;
}
if (guids.has(identity.guid)) throw new Error(`players[${index}].guid must be unique within the report`);
guids.add(identity.guid);
if (body.event === 'game_start') return identity;