Support player ping in game telemetry
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user