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

@@ -10,6 +10,8 @@ test('check accepts valid client messages', () => {
assert.ok(P.check({ t: 'hello', v: 1, token: 'abc' }).ok);
assert.ok(P.check({ t: 'challenge', to: 'u1' }).ok);
assert.ok(P.check({ t: 'challenge.cancel' }).ok);
assert.ok(P.check({ t: 'ping', t0: 123.4 }).ok, 'ping with a timestamp (regression: t was checked instead of t0)');
assert.ok(P.check({ t: 'ping' }).ok);
assert.ok(P.check({ t: 'room', room: 'DE' }).ok);
assert.ok(P.check({ t: 'input', seq: 3, throttle: 1, turn: -0.5, fire: true, fire2: false, fire3: false }).ok);
});
@@ -34,7 +36,7 @@ test('input clamps ranges and coerces flags', () => {
function fakeSnap() {
return {
tick: 10, ack: [4, 7], away: [false, true], time: 1, left: 100, pitOpen: 0, pitAlarm: false, endIn: 0,
tick: 10, ack: [4, 7], away: [false, true], rtt: [20, 140], time: 1, left: 100, pitOpen: 0, pitAlarm: false, endIn: 0,
result: { winner: 0, reason: 'ko' },
press: { st: 'idle', y: 1 }, crane: { st: 'grab', x: 0, z: 0, who: 1 },
rockets: [{ kind: 'rocket', owner: 0, x: 1, z: 2, y: 0.5, a: 0 }],
@@ -62,6 +64,7 @@ test('toLocal for seat 1 mirrors every robot index', () => {
assert.equal(l.result.winner, 1, 'seat 0 won -> for seat 1 the winner is the opponent (local 1)');
assert.equal(l.ack, 7);
assert.deepEqual(l.away, [true, false], 'own connection first');
assert.deepEqual(l.rtt, [140, 20], 'own ping first');
assert.equal(l.crane.who, 0);
assert.equal(l.rockets[0].owner, 1);
assert.equal(l.mines[0].owner, 0);