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:
@@ -46,6 +46,16 @@ test('old protocol version is told to reload', async () => {
|
||||
assert.equal((await c.closed).code, 4002);
|
||||
});
|
||||
|
||||
test('ping is answered with pong (for the latency overlay)', async () => {
|
||||
const a = await S.account();
|
||||
const c = await S.client(a.idToken);
|
||||
c.send({ t: 'ping', t0: 42 });
|
||||
const p = await c.next('pong');
|
||||
assert.equal(p.t0, 42);
|
||||
assert.equal(typeof p.serverTime, 'number');
|
||||
c.close();
|
||||
});
|
||||
|
||||
test('invalid messages get an error, the socket stays open', async () => {
|
||||
const a = await S.account();
|
||||
const c = await S.client(a.idToken);
|
||||
@@ -112,7 +122,11 @@ test('full live match over WebSocket: both get start, snapshots, and mirrored re
|
||||
const winner = la === 0 ? ea : lb === 0 ? eb : null;
|
||||
if (winner) assert.ok(winner.reward.ach.some(x => x.id === 'first_win'), 'first win pays out');
|
||||
assert.equal(eb.save.games, 1);
|
||||
assert.ok(ca.inbox.some(m => m.t === 'snap'), 'snapshots arrived before the end');
|
||||
const snap = ca.inbox.find(m => m.t === 'snap');
|
||||
assert.ok(snap, 'snapshots arrived before the end');
|
||||
assert.ok(Array.isArray(snap.rtt) && snap.rtt.length === 2, 'snapshot carries both pings');
|
||||
assert.equal(typeof snap.tickMs, 'number', 'snapshot carries the server step cost');
|
||||
assert.equal(typeof snap.sent, 'number');
|
||||
|
||||
// rewards were booked on the server
|
||||
const sA = await S.json('GET', '/api/online', undefined, a.idToken);
|
||||
|
||||
Reference in New Issue
Block a user