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:
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user