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/Feature: (re)introduce NewGRF names for (unknown) NewGRFs #9449

Merged
merged 2 commits into from Jul 18, 2021

Conversation

@rubidium42
Copy link
Contributor

@rubidium42 rubidium42 commented Jul 18, 2021

Note: this is currently only deployed on staging. Use OTTD_COORDINATOR_CS="coordinator.openttd.org:4976" OTTD_STUN_CS="stun.staging.openttd.org:4975" to test this PR.

Motivation / Problem

With the removal of the UDP packets in lieu of the Game Coordinator listing, the ability to get the names for unknown NewGRFs for a server was lost.

Description

Introduce a new version for the Game Info packet that allows to specify the way the NewGRFs are serialized. This could be only GRF ID + MD5 checksum, GRF ID + MD5 checksum + name, or an index into a lookup table (more details later). For clients requesting information from a server, the names of the NewGRFs will automatically be sent.
Updates of a game server to the Game Coordinator will not send the names, except for the first registration of that game.

A new version of the Game Coordinator protocol was added so the Game Coordinator can provide a lookup table for the NewGRF ID + MD5 checksum + name for the NewGRFs in the listing. Upon further requests for the listing, in the same connection with the Game Coordinator, only minimal updates for the lookup table need to be sent.

Assuming about 500 unique NewGRFs used by all the servers combined, and 3000 server-NewGRF combinations this will save about 25 kB for the initial listing and 45 kB for subsequent listings.

Saving 3000*16 bytes = 48 kB in the listing.
    replacing GRF ID + MD5 checksum with index reduces 16 bytes per server-NewGRF combination.
Adding at most 500*(4+16+80) = 50 kB in the lookup table.
   GRF ID + MD5 checksum + maximum length of GRF name.
However, the average number characters of unique BaNaNaS NewGRF names is about 20.5 characters long (21.5 with '\0'),
so it costs closer to 21-25 kB in the first lookup table update. Updates after that only need to send new NewGRFs, 
which will usually 0 NewGRFs or at most a few NewGRFs.

Limitations

  • Slightly more load for the Game Coordinator.
  • Clients get names of NewGRFs that they might not need as they have the NewGRF locally.

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')
@rubidium42 rubidium42 marked this pull request as draft Jul 18, 2021
src/network/core/game_info.cpp Outdated Show resolved Hide resolved
Loading
src/network/core/game_info.h Outdated Show resolved Hide resolved
Loading
src/network/core/game_info.h Show resolved Hide resolved
Loading
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
src/network/network_coordinator.cpp Outdated Show resolved Hide resolved
Loading
Before 8a2da49 the NewGRF names were synchronized using UDP packets, however
those have been removed. With this a new version of the GameInfo packet is
introduced that allows to specify the type of serialisation happens for
NewGRFs. Either only the GRF ID and checksum, or those two plus the name of
the NewGRF.
On this request for local servers will send the NewGRFs names.
The Game Coordinator will get the names on the first registration, and after
that only the GRF ID and checksum.
@rubidium42 rubidium42 force-pushed the gc_optimisations branch from 45fc1d8 to 51c24cc Jul 18, 2021
@rubidium42 rubidium42 marked this pull request as ready for review Jul 18, 2021
src/network/core/tcp_coordinator.h Outdated Show resolved Hide resolved
Loading
@rubidium42 rubidium42 force-pushed the gc_optimisations branch from 51c24cc to 106a6e3 Jul 18, 2021
@rubidium42 rubidium42 merged commit 386ef4d into OpenTTD:master Jul 18, 2021
15 checks passed
Loading
@rubidium42 rubidium42 deleted the gc_optimisations branch Jul 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants