feat(net): server measures every player's ping and its own step cost, sent with each snapshot

Also fixes the ping message schema (it checked the field t, which is the message type).
This commit is contained in:
Benjamin Oezcan
2026-11-19 14:25:46 +01:00
parent 3dc770e34a
commit 593d69714b
6 changed files with 46 additions and 9 deletions

View File

@@ -24,7 +24,7 @@
// client -> server message schemas: field -> check
const C2S = {
hello: { v: v => Number.isInteger(v), token: v => isStr(v, 4096) },
ping: { t: v => v === undefined || isNum(v) },
ping: { t0: v => v === undefined || isNum(v) }, // (t is the message type itself)
room: { room: v => FLAGS.includes(v) || v === 'all' },
challenge: { to: v => isStr(v) },
'challenge.cancel': {},
@@ -89,6 +89,7 @@
robots,
ack: snap.ack ? snap.ack[seat] : 0,
away: snap.away ? (seat === 0 ? snap.away.slice() : [snap.away[1], snap.away[0]]) : undefined,
rtt: snap.rtt ? (seat === 0 ? snap.rtt.slice() : [snap.rtt[1], snap.rtt[0]]) : undefined, // ping of [me, opponent]
result: localResult(seat, snap.result),
crane: Object.assign({}, snap.crane, { who: m(snap.crane.who) }),
rockets: snap.rockets.map(k => Object.assign({}, k, { owner: m(k.owner) })),