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

@@ -104,6 +104,7 @@ function createLobby({ runner, economy, matches, now = () => Date.now() }) {
id, seed,
players: seats.map(f => ({ uid: f.uid, name: f.name, build: f.build, paint: f.paint, flag: f.flag })),
send: (seat, msg) => tell(seats[seat].uid, msg),
rttOf: seat => { const p = players.get(seats[seat].uid); return p ? p.rtt : 0; },
onEnd: finish,
});
if (matches) matches.start.run(id, seed, room.arena, seats[0].uid, seats[1].uid, now());
@@ -143,10 +144,13 @@ function createLobby({ runner, economy, matches, now = () => Date.now() }) {
}
}
// ping of a player, measured by the hub (WebSocket ping/pong)
function setRtt(uid, ms) { const p = players.get(uid); if (p) p.rtt = p.rtt ? p.rtt * 0.7 + ms * 0.3 : ms; }
// the profile changed (robot, flag, fame): show it to everyone
function refresh(uid) { const p = players.get(uid); if (p) setState(p, p.state); }
return { join, leave, handle, refresh, startMatch, players, pending, inMatch };
return { join, leave, handle, refresh, setRtt, startMatch, players, pending, inMatch };
}
module.exports = { createLobby, CHALLENGE_TTL };