Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: several bugs related to joining a network server #8755

Merged
merged 4 commits into from Feb 28, 2021

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Feb 27, 2021

Fixes #8751

Motivation / Problem

There are four bugs mentioned in the above ticket:

  1. waiting queue seems off by 1
  2. when client that is downloading disconnects, all others in queue will never start their download
  3. while in queue, you get after 5 seconds that the server is not responding
  4. if a client creates a new company and leaves while you are downloading a map, the client desyncs

Description

  1. is a linguistic issue. "1 person waiting" means 1 is being served while there is 1 more waiting. So when you are the next in line, there are 0 people waiting, so 0 people in front of you. But this just looks odd and weird. So let's ignore "strictly seen correct" and go with the more expected version: 1 people in front of you means that person is downloading the map.

  2. the state machine was poorly designed around unhappy flows. Now, if for what-ever reason the client disconnects while downloading the map, the savegame process is stopped and the next person is getting the map.

  3. every second all people in queue now receive a packet, letting them know the server is alive.

  4. after the server approved the CmdCompanyCtrl, clients and server could still reject it depending if they received that the client left the server. This is latency depending, and can cause desync. Introduced in f8f7feb, which originally avoided this situation, but stricter validation created the possibility to desync (the check changed from an out-of-bound check to a "does this still exist" check).

Limitations

Checklist for review

Some things are not automated, and forgotten often. This list is a reminder for the reviewers.

  • The bug fix is important enough to be backported? (label: 'backport requested')
  • This PR affects the save game format? (label 'savegame upgrade')
  • This PR affects the GS/AI API? (label 'needs review: Script API')
    • ai_changelog.hpp, gs_changelog.hpp need updating.
    • The compatibility wrappers (compat_*.nut) need updating.
  • This PR affects the NewGRF API? (label 'needs review: NewGRF')

Strictly seen, there are "N" people -waiting- in front of you
in the queue, but it is nicer to show "N + 1" for the person that
is currently downloading the map. Avoids it showing:
"0 clients in front of you". That just feels a bit off.
@TrueBrain TrueBrain force-pushed the send-map-fixes branch 2 times, most recently from 7e446d2 to f274b1b Compare February 27, 2021 12:34
@TrueBrain TrueBrain added this to the 1.11.0 milestone Feb 27, 2021
src/network/network_server.cpp Outdated Show resolved Hide resolved
src/network/network_server.cpp Outdated Show resolved Hide resolved
Also terminate creating of the savegame, as the client is gone,
there really is no need for that anymore.
Send all clients in the queue every game-day a packet that they
are still in the queue.
…ading map

When you are downloading a map, all the commands are queued up
for you. Clients joining/leaving is done by the network protocol,
and as such are processed immediately. This means that by the
time you are processing the commands, a client that triggered
it, might already have left.

So, all commands that do something with ClientID, shouldn't
error on an invalid ClientID when DC_EXEC is set, but
gracefully handle the command anyway, to make sure the
game-state is kept in sync with all the clients that did
execute the DoCommand while the now-gone client was still
there.

Additionally, in the small chance a client disconnects between
the server validating a DoCommand and the command being
executed, also just process the command as if the client was
still there. Otherwise, lag or latency can cause clients that
did not receive the disconnect yet to desync.
@ldpl
Copy link
Contributor

ldpl commented Feb 27, 2021

Not sure why is it happening but two clients can't connect at the same time now if they do it with "new company" button.
Screenshot from 2021-02-27 20-20-38

@James103
Copy link
Contributor

What was the "invalid or unexpected packet" that the client received?

Copy link
Contributor

@ldpl ldpl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that bug is unrelated so I'll open another issue.
Everything else looks fine

@TrueBrain TrueBrain merged commit 2d9062b into OpenTTD:master Feb 28, 2021
@TrueBrain TrueBrain deleted the send-map-fixes branch February 28, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disconnecting clients affect other clients in the queue
4 participants