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

multiplayer stage 4: server-authoritative input, permissions, per-source holds

Three things stood in the way of two people sharing a cab and of a client not
being able to reach past its own vehicle.

Vehicle commands were addressed by TTrain::id(), which every peer hands out
locally from its own counter, so the same number means a different vehicle on
a different peer. Commands now travel with the session wide NetworkEntityId
and are translated back to the local cab on arrival; outside of multiplayer
the registry is empty and both directions are a no-op, so singleplayer is
untouched.

A client could send any command it liked, including setweather, queueevent or
spawntrainset. The server now validates every incoming command: a player may
work the controls of the vehicle whose crew they are on and nothing else, and
world wide commands stay with the host until dispatcher roles exist. The
source is stamped by the server, never taken from what the peer sent, and
rejections are logged once per peer/command instead of every frame. Host input
runs through the very same validation, just without the transport.

Continuous commands were tracked per command and recipient only, so with two
people in one cab the release sent by one of them cancelled the other one's
hold. command_data now carries the source peer and the active set is keyed by
{source, recipient, command}.

Also: a client asking to quit no longer replicates quitsimulation, which would
have shut down everybody else's session.
This commit is contained in:
2026-09-06 18:24:21 +00:00
parent 3f62fd5927
commit c3bf261934
7 changed files with 229 additions and 17 deletions

View File

@@ -438,7 +438,9 @@ double eu07_application::generate_sync()
void eu07_application::queue_quit(bool direct)
{
if (direct || !m_modes[m_modestack.top()]->is_command_processor())
// a network client leaving is its own business; replicating the request would shut
// down everybody else's session as well
if (direct || is_client() || !m_modes[m_modestack.top()]->is_command_processor())
{
glfwSetWindowShouldClose(m_windows[0], GLFW_TRUE);
return;
@@ -510,6 +512,10 @@ int eu07_application::run()
// if we're the server
if (m_network && m_network->servers)
{
// our own input goes through the same authority layer as everybody
// else's, only without the transport in between
network::filter_commands(network::PEER_HOST, local_commands);
// fetch from network layer command requests received from clients
command_queue::commands_map remote_commands = m_network->servers->pop_commands();