Commit Graph

1327 Commits (f187708b3b6bcb95a0d92908f8a90c1431ca2578)

Author SHA1 Message Date
Patric Stout f187708b3b
Fix f7e390bd: getpeername() doesn't work on closed sockets (#9213) 3 years ago
rubidium42 e2774354b4
Codechange: [Network] Change ChatMessage's message to std::string and simplify some code 3 years ago
Patric Stout f7e390bdc0
Feature: use Happy Eyeballs to make network connections (TCP-only) (#9199)
Hostnames like "content.openttd.org" resolve into multiple IPv4 and IPv6.
It is possible that either of the IPs is not working, either due to
a poorly configured OS (having IPv6 but no valid route), broken network
paths, or a service that is temporary unavailable.

Instead of trying the IPs one by one, waiting for a 3s timeout between
each, be a bit more like browsers, and stack attempts on top of each
other with slight delays. This is called Happy Eyebells.

Initially, try the first IPv6 address. If within 250ms there is no
connection yet, try the first IPv4 address. 250ms later, try the
second IPv6 address, etc, till all addresses are tried.

If any connection is created, abort all the other (pending) connections
and use the one that is created. If all fail 3s after the last connect(),
trigger a timeout for all.
3 years ago
rubidium42 f1dfa661a1 Codechange: [Network] Use std::string for NetworkGameInfo 3 years ago
rubidium42 3d91eee919 Codechange: [Network] Move connection string parsing away from C-strings 3 years ago
rubidium42 6c4a65eeb8 Codechange: [Network] Use std::string for NetworkAddress' host name 3 years ago
rubidium42 dcef3209a6 Codechange: [Network] Use new/delete instead of calloc/free for NetworkGameList 3 years ago
Patric Stout f94fb93779
Codechange: use connection_string in favour of NetworkAddress (#9197)
We now resolve the connection_string to a NetworkAddress in a much
later state. This means there are fewer places constructing a NetworkAddress.

The main benefit of this is in later PRs that introduce different types
of NetworkAddresses. Storing this in things like NetworkGameList is
rather complex, especially as NetworkAddress has to be mutable at all
times.

Additionally, the NetworkAddress is a complex object to store simple
information: how to connect to this server.
3 years ago
Rubidium ead30dc725 Cleanup: [Network] Remove variable from NetworkGameInfo that is only used during deserialisation 3 years ago
rubidium42 e7581fd42d Change: [Network] Update server's NetworkServerGameInfo only when needed
Split the updating in a "static" version that only needs to be called when a new map is loaded or some settings are changed, and a "dynamic" version that updates everything that changes regularly such as the current game date or the number of spectators.
3 years ago
rubidium42 72bd62fd70 Codechange: [Network] Use a single NetworkServerGameInfo object at server side and serialize that for the clients 3 years ago
rubidium42 7bcc472f73 Add: [Network] Reading std::string from a packet 3 years ago
rubidium42 ba409e8c45 Add: [Network] Writing std::string to a packet 3 years ago
rubidium42 56aa6d0edd Fix: [Network] Reading beyond the length of the server's ID when hashing password
Under normal circumstances the server's ID is 32 characters excluding '\0', however this can be changed at the server. This ID is sent to the server for company name hashing. The client reads it into a statically allocated buffer of 33 bytes, but fills only the bytes it received from the server. However, the hash assumes all 33 bytes are set, thus potentially reading uninitialized data, or a part of the server ID of a previous game in the hashing routine.
It is still reading from memory assigned to the server ID, so nothing bad happens, except that company passwords might not work correctly.
3 years ago
rubidium42 e097c83c83 Codechange: move some OS abstraction method implementations out of the header 3 years ago
rubidium42 22720332eb Codechange: encapsulate network error handling 3 years ago
rubidium42 0eb17a70af Codechange: rename NetworkError to ShowNetworkError 3 years ago
rubidium42 05394d5216 Fix #6598: Prevent invalid memory accesses when abandoning a join from within a network game
One could join a network game from within an already running network game. This would call a NetworkDisconnect, but keeps the UI alive. If, during that process the join is aborted, e.g. by cancelling on a password dialog, you would still be in your network game but also get shown the server list.
Solve all the underlying problems by falling back to the main UI when (re)connecting to a(nother) server.
3 years ago
rubidium42 83985fe26f Codechange: Move join information into a single structure 3 years ago
rubidium42 3bd416bfdb Change: [Console] Show help when passing invalid company number 3 years ago
Peter Nelson 4791ff2862 Fix: Recalculate padding and minimum sizes when GUI or Font zoom is changed. 3 years ago
Patric Stout 69118d063f
Change: use TCP for everything except for master-server and initial server scan (#9130)
This means that pressing Refresh button and adding servers manually
now uses TCP.

The master-server and initial scan are still UDP as they will be
replaced by Game Coordinator; no need to change this now.

If we query a server that is too old, show a proper warning to the
user informing him the server is too old.
3 years ago
rubidium42 a61696d6c5 Change: [Network] Encapsulate logic about the connection string to the network code (#23) 3 years ago
Patric Stout be37a2cab8 Codechange: use NetworkAddress instead of two host/port variables where possible
This also means we no longer need last_host/last_port, but can
just use a single last_joined setting.
3 years ago
Patric Stout 99f998805b Codechange: use std::string over stack-based strings if possible 3 years ago
Patric Stout a8afbe74bf Cleanup: remove write-only variable "hostname" in NetworkGameList 3 years ago
Loïc Guilloux 356bbbb90a
Fix: [MinGW] Set minimum OS version to Windows XP (#9135) 3 years ago
Patric Stout 96dc0d04ec
Fix b3003dd1: swap SERVER_GAME_INFO with CLIENT_GAME_INFO (#9129)
The idea is that if you query an older server that does not support
this packet yet, the client receives an error. The assumption was
that on every "illegal packet" the connection would be closed. This
turns out to be false.

Now CLIENT_GAME_INFO aligns with the old PACKET_CLIENT_NEWGRFS_CHECKED,
which does a pre-check (which fails), and an error is sent back
and the connection is closed.

This is not a nice solution, but it is the best we got.
3 years ago
Milek7 a341852cd5
Fix: missing <limits> include in network/core/packet.h (#9123) 3 years ago
Patric Stout 31f1db2d3a Change: no longer use UDP when entering the lobby of a server
The lobby of a server requested some parts via UDP and some via
TCP. This is strictly seen fine, but for future extensions it
is a lot easier if just one protocol is used.
3 years ago
Patric Stout b57d845e55 Codechange: refactor CheckGameCompatibility() from existing function
Later commits use this function in other places too.
3 years ago
Patric Stout b3003dd163 Add: ability to retrieve game info from server over TCP 3 years ago
Patric Stout 84c75a7b9a Codechange: be explicit in pointer comparisons 3 years ago
Patric Stout cb2ef1ea4b Codechange: move all NetworkGameInfo related functions to a single file
It currently was a bit scattered over the place. Part of
NetworkGameInfo is also the GRF Identifiers that goes with it.
3 years ago
Patric Stout 8fa53f543a
Change: [Network] lower TCP connect() timeout to 3s (#9112)
Currently we use default OS timeout for TCP connections, which
is around 30s. 99% of the users will never notice this, but there
are a few cases where this is an issue:

- If you have a broken IPv6 connection, using Content Service is
  first tried over IPv6. Only after 30s it times out and tries
  IPv4. Nobody is waiting for that 30s.
- Upcoming STUN support has several methods of establishing a
  connection between client and server. This requires feedback
  from connect() to know if any method worked (they have to be
  tried one by one). With 30s, this would take a very long time.

What is good to mention, is that there is no good value here. Any
value will have edge-cases where the experience is suboptimal. But
with 3s we support most of the stable connections, and if it fails,
the user can just retry. On the other side of the spectrum, with 30s,
it means the user has no possibility to use the service. So worst case
we annoy a few users with them having the retry vs annoying a few
users which have no means of resolving the situation.
3 years ago
rubidium42 015e3b412e Cleanup: remove #ifdefs for compiling the old content server 3 years ago
rubidium42 84985c1223 Codechange: [Network] Do not leak os_abstraction.h via fios.h 3 years ago
rubidium42 cbad518bf3 Codechange: [Network] Do not leak os_abstraction.h via network_func 3 years ago
rubidium42 cf8c1aa860 Change: [Network] Use string error messages instead of numeric error numbers that need to be looked up 3 years ago
rubidium42 65c5a64719 Fix: [Network] errno and strerror do not handle network errors on Windows 3 years ago
Charles Pigott 43b6f6915b Fix 8a95fee4: Missing initialiser in Packet constructor 3 years ago
rubidium42 5afb090082 Change: [Network] Remove now defunct savegame transfer packet limiter 3 years ago
Rubidium a3c9eca722 Change: use 32 KiB packets to send requests to the content server 3 years ago
Rubidium 21f58ab437 Change: use 32 KiB packets to transfer the savegame 3 years ago
Rubidium d6000c2ec5 Codechange: differentiate between UDP, TCP and compatibility MTU values 3 years ago
Rubidium 8b302761d4 Codechange: allow different limits in packet sizes 3 years ago
rubidium42 65818db1f4 Fix: [Network] Prevent stalling save game transfer when compression is slow 3 years ago
Patric Stout fda1a590f6 Change: use icons to indicate you/host in Online Players GUI 3 years ago
Patric Stout a924b2ff81 Add: move "New Company" inside the Online Players GUI 3 years ago
Patric Stout c2e116a3d3 Change: track hover position on Online Players GUI
Especially if there are many players online, trying to chat with
the right one can be a visual challenge. This can be solved by
highlighting the row you are on. This visual cue is often enough
for humans to find the right row.
3 years ago