Commit Graph

59 Commits

Author SHA1 Message Date
Peter Nelson 56085be9bd Codechange: Move includes for common STL headers to stdafx. 2023-05-17 10:14:41 +01:00
Rubidium ed7685910d Codechange: pass large objects by reference instead of value
Especially when they get passed on directly to the next function or via a
constructor into an instance variable
2023-01-28 13:43:21 +01:00
Rubidium ad89601c49 Codechange: do not use all upper case enumerators in a scoped enum 2021-12-05 21:41:43 +01:00
Patric Stout 8adade26ed Feature: allow the use of STUN to connect client and server together
This method doesn't require port-forwarding to be used, and works for
most common NAT routers in home setups. But, for sure it doesn't work
for all setups, and not everyone will be able to use this.
2021-07-16 19:50:29 +02:00
Patric Stout 55eed246b8 Codechange: allow Connect() to bind to a local address 2021-07-16 19:50:29 +02:00
Patric Stout 1baec41542 Change: groundwork to allow ServerAddress to use invite codes
Normally TCPConnecter will do a DNS resolving of the connection_string
and connect to it. But for SERVER_ADDRESS_INVITE_CODE this is different:
the Game Coordinator does the "resolving".

This means we need to allow TCPConnecter to not setup a connection
and allow it to be told when a connection has been setup by an external
(to TCPConnecter) part of the code. We do this by telling the (active)
socket for the connection.

This means the rest of the code doesn't need to know the TCPConnecter
is not doing a simple resolve+connect. The rest of the code only
cares the connection is established; not how it was established.
2021-07-11 20:38:42 +02:00
Patric Stout cee8174d02 Codechange: track servers with a ServerAddress instead of a NetworkAddress
This allows future extensions to have different ways of referencing
a server, instead of forcing to use IP:port.
2021-07-11 20:38:42 +02:00
Patric Stout a403653805
Codechange: [Network] split CloseSocket and CloseConnection more clearly (#9261)
* Codechange: [Network] split CloseSocket and CloseConnection more clearly

- CloseSocket now closes the actual OS socket.
- CloseConnection frees up the resources to just before CloseSocket.
- dtors call CloseSocket / CloseConnection where needed.
2021-05-13 11:46:51 +02:00
Patric Stout d7ce61f106
Fix #9255: [Network] TCPConnecter crashes when hostname not found (#9259) 2021-05-13 08:13:48 +02:00
Patric Stout 1b75a29d12 Fix: destroying a TCPConnecter that was still resolving made illegal writes
Basically, we should join the resolve thread before we destruct
the object.
2021-05-08 17:26:10 +02:00
Patric Stout 664a8c3e85 Codechange: move connection_string to private for TCPConnecter
The most common case never needs access to it anymore. Make the
one exception to this explicit. This means the fact that we
store it is now an implementation detail.
2021-05-08 17:26:10 +02:00
Patric Stout f187708b3b
Fix f7e390bd: getpeername() doesn't work on closed sockets (#9213) 2021-05-08 11:57:41 +02:00
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.
2021-05-06 23:13:35 +02:00
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.
2021-05-05 23:21:14 +02:00
Jonathan G Rennison b0f192abc4 Fix: Racy use of flags in TCPConnecter::CheckCallbacks
conected and aborted flags are used concurrently from multiple threads.
2020-06-18 19:57:34 +02:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
Michael Lutz 05bc2ed7cb Codechange: Replace custom thread code with C++11 thread objects.
We assume a conforming C++11 compiler environment that has a valid <thread>-header.
Failure to run a real thread is handled gracefully.
2019-04-06 11:27:39 +02:00
peter1138 07de9d6c3f Codechange: Use override keyword in networking classes. 2019-03-24 17:38:42 +00:00
Patric Stout e3c639a09f Remove: ENABLE_NETWORK switch
This switch has been a pain for years. Often disabling broke
compilation, as no developer compiles OpenTTD without, neither do
any of our official binaries.

Additionaly, it has grown so hugely in our codebase, that it
clearly shows that the current solution was a poor one. 350+
instances of "#ifdef ENABLE_NETWORK" were in the code, of which
only ~30 in the networking code itself. The rest were all around
the code to do the right thing, from GUI to NewGRF.

A more proper solution would be to stub all the functions, and
make sure the rest of the code can simply assume network is
available. This was also partially done, and most variables were
correct if networking was disabled. Despite that, often the #ifdefs
were still used.

With the recent removal of DOS, there is also no platform anymore
which we support where networking isn't working out-of-the-box.

All in all, it is time to remove the ENABLE_NETWORK switch. No
replacement is planned, but if you feel we really need this option,
we welcome any Pull Request which implements this in a way that
doesn't crawl through the code like this diff shows we used to.
2019-03-20 19:24:55 +01:00
planetmaker c24374f99c (svn r24900) -Fix [FS#5389]: Comments with typos (most fixes supplied by Eagle_rainbow) 2013-01-08 22:46:42 +00:00
rubidium 6247bdbdb4 (svn r24642) -Codechange: add helper function to see if there is anything in the send queue 2012-10-28 21:26:57 +00:00
rubidium adfd648031 (svn r22068) -Codechange/Fix: return "connection lost" instead of "okay" when SendPackets closed the connection 2011-02-12 21:09:34 +00:00
rubidium eb299736c1 (svn r21886) -Codechange: move documentation towards the code to make it more likely to be updated [n]. 2011-01-22 09:53:15 +00:00
rubidium 216e48cd07 (svn r21399) -Change/Feature/Fix [FS#4284]: perform the compression of savegames to send to the client asynchroniously. This will reduce the lag of the other clients to the time it takes to make the memory dump and it will speed up downloading the map as the download starts earlier (possibly with a slightly lower bandwidth due to slow compression). This should also fix the lag message people get when the savegame compression takes more than a few seconds. 2010-12-05 14:48:39 +00:00
rubidium fd752ca2b0 (svn r21363) -Add: support for limiting the amount of (accepted) incoming data 2010-11-30 20:01:26 +00:00
rubidium b6c2216749 (svn r21358) -Codechange: make some network function names conform to coding style 2010-11-30 13:38:46 +00:00
rubidium f555e6d72e (svn r20933) -Codechange: move some more client related methods and such to network_client.cpp 2010-10-15 19:33:08 +00:00
rubidium 82fc28f77f (svn r18809) -Codechange/Cleanup: remove unneeded headers from some files, if a header require a header make it include that header 2010-01-15 16:41:15 +00:00
rubidium f89d6bea0e (svn r18801) -Fix: in some cases error messages weren't properly sent to the client before closing the connection. As a result the client would say 'connection lost' when the cause was something completely different. 2010-01-14 21:48:42 +00:00
rubidium df75db67eb (svn r17742) -Codechange: remove unused variable from Recv_Packet 2009-10-07 20:58:14 +00:00
rubidium 5ff6053326 (svn r17699) -Codechange: move #ifdef ENABLE_NETWORK till after the 'generic' includes so compilation without network support doesn't get broken as easily by changes in header files 2009-10-04 20:00:56 +00:00
rubidium 7fbc33dae1 (svn r17248) -Fix: add GPL license notice where appropriate 2009-08-21 20:21:05 +00:00
rubidium 9b156c1bd4 (svn r16601) -Fix [FS#2880]: try 2... hopefully better this time 2009-06-19 20:26:18 +00:00
rubidium 2a6e9288fd (svn r15971) -Codechange: make it possible for UDP socket handlers to bind to multiple sockets. 2009-04-07 20:27:13 +00:00
rubidium 4f5a8b15ed (svn r15206) -Fix [FS#2567]: memory corruption due to not properly cleanup up the mess when cancelling a download 2009-01-22 10:09:56 +00:00
rubidium 28a641066e (svn r15163) -Change/Fix: use a non-blocking method to resolve the hostname and connect to game servers. 2009-01-20 11:28:18 +00:00
rubidium e18c24cdb5 (svn r15079) -Codechange: split tcp 'backend' and in-game handling like it is for UDP. 2009-01-14 12:50:13 +00:00
rubidium 427e2d30c5 (svn r14915) -Codechange: unify the receiving and sending of commands, and thus unifying most of the validity checking too. 2009-01-08 14:40:18 +00:00
rubidium e198bf02ab (svn r14766) -Fix (r14730ish): remove unused typedef. 2008-12-29 11:17:12 +00:00
rubidium e626e07bd3 (svn r14759) -Fix (r14730): tab completion causing out-of-bounds read. 2008-12-28 21:07:45 +00:00
rubidium afddfcb2b1 (svn r14730) -Codechange: remove the need for networkclientsockets and networkclientinfo structs to be in a contiguous piece of memory and put them in a pool.
-Note: 255 should really be enough for now... making it any more means network protocol bumps.
2008-12-23 20:52:27 +00:00
rubidium 52fb6b7d7c (svn r14724) -Codechange: move some NetworkClientSocket related function/definitions closer together. 2008-12-23 11:43:32 +00:00
rubidium 9476a49763 (svn r14723) -Codechange: shuffling some stuff around to reduce indirect #include dependencies. 2008-12-23 11:06:52 +00:00
rubidium ae96ca635c (svn r14721) -Codechange: s/NetworkTCPSocketHandler/NetworkClientSocket/ as it's (way) more descriptive what it's used for. 2008-12-23 09:47:42 +00:00
rubidium b4734ee9a4 (svn r14719) -Codechange: replace DEREF_CLIENT with an instance function and replace looping socket structs with info structs when the loop is only interested in the info structs (i.e. not derefing the info from sockets when one can loop info directly and the socket isn't used) 2008-12-23 08:39:30 +00:00
rubidium 782b80eff7 (svn r14709) -Codechange: make a clearer distinction between 'unique' client identification ids and the indices into the clients/client info arrays. 2008-12-22 12:59:31 +00:00
rubidium 3b798599b6 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with. 2008-09-30 20:39:50 +00:00
rubidium ac528411df (svn r11818) -Codechange: split player.h into smaller pieces. 2008-01-12 14:10:35 +00:00
rubidium 872e74c028 (svn r10501) -Fix [FS#1015]: error dialog was sometimes shown on all clients when a command failed instead of only the client that actually did the command. 2007-07-10 20:59:41 +00:00