17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 15:39:20 +02:00

multiplayer stage 8: state correction and surviving a dropped connection

Two things were still missing once a session ran for a while: a peer that had
drifted apart from the authority had no way back short of restarting, and a
connection that blinked cost the player their seat and handed their vehicle to
the AI while the other driver was still sitting in it.

- a client that disagrees with the authoritative digest for 120 steps in a row
  asks to be put back in line, and the server answers with a fresh snapshot.
  There is a cooldown between requests, so a correction that needs a moment to
  take hold does not turn into a stream of them
- the server hands out a session token with its hello and remembers it. Present
  it again on the next connection and you come back as the same peer, with the
  same id
- a lost connection no longer removes the peer from its crews: the seat is held
  for a minute. Come back in time and nothing changed; stay away and the seat
  is given up properly, handing the vehicle back to the AI only when that
  leaves the crew empty and the AI was driving it in the first place
- after applying a snapshot a peer that finds itself on a crew walks into that
  cab, which is what makes a reconnect land the player back where they were
- the vehicle roster is sent to a joining peer right before its snapshot, so
  the crew section resolves to names instead of waiting for the next broadcast
This commit is contained in:
2026-09-06 19:48:06 +00:00
parent 54d8b112b8
commit 30fa68cfd8
11 changed files with 209 additions and 5 deletions

View File

@@ -461,6 +461,15 @@ void eu07_application::request_vehicle_leave(network::NetworkEntityId const Enti
m_network->request_leave(Entity);
}
namespace {
// how many steps in a row may disagree with the authority before we ask to be corrected,
// and how long to leave the correction alone before asking again
uint64_t const NETWORK_RESYNC_THRESHOLD = 120;
uint64_t const NETWORK_RESYNC_COOLDOWN = 600;
} // namespace
void eu07_application::network_scenario_loaded()
{
if (m_network)
@@ -595,6 +604,16 @@ int eu07_application::run()
logtype::net);
}
Global.desync = (float)m_statemismatches;
// a short disagreement rides itself out; a lasting one will not,
// and calls for the authoritative state rather than a restart
if ((m_statemismatches >= NETWORK_RESYNC_THRESHOLD) &&
(m_lastresynctick == 0 || authoritative.tick > m_lastresynctick + NETWORK_RESYNC_COOLDOWN))
{
m_lastresynctick = authoritative.tick;
WriteLog("net: resync requested at tick " + std::to_string(authoritative.tick), logtype::net);
m_network->request_resync(authoritative.tick, statehash);
}
}
else
{