summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-07-11 22:37:14 +0200
committerGitHub <noreply@github.com>2021-07-11 22:37:14 +0200
commitdd7f69be6ed6ea90ec806c86957f10332206bcd6 (patch)
tree97164c5c8fe4a2d37762a7095ac8bb4c78f29a6c /src
parent178ea3196b0aed0a2a081801f92e1deb06d12628 (diff)
downloadopenttd-dd7f69be6ed6ea90ec806c86957f10332206bcd6.tar.xz
Fix: "Search LAN games" used the socket after it was closed (#9437)
Every outgoing connection, either TCP or UDP, triggered NetworkInitialize(), which triggered NetworkUDPInitialize() which first closes all connections. Now the problem was that "Search LAN games" found a server, added it to the list, after which (over TCP) it queries the server. This closes all UDP sockets (as that makes sense, I guess?), while the UDP was still reading from it. Solve this by simply stop initializing UDP every time we make an outgoing TCP connection; instead only do it on start-up.
Diffstat (limited to 'src')
-rw-r--r--src/network/network.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index d35fbe746..d5d6d8282 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -615,7 +615,6 @@ void NetworkClose(bool close_admins)
static void NetworkInitialize(bool close_admins = true)
{
InitializeNetworkPools(close_admins);
- NetworkUDPInitialize();
_sync_frame = 0;
_network_first_time = true;
@@ -907,6 +906,7 @@ bool NetworkServerStart()
NetworkDisconnect(false, false);
NetworkInitialize(false);
+ NetworkUDPInitialize();
Debug(net, 5, "Starting listeners for clients");
if (!ServerNetworkGameSocketHandler::Listen(_settings_client.network.server_port)) return false;
@@ -1292,6 +1292,7 @@ void NetworkStartUp()
_network_game_info = {};
NetworkInitialize();
+ NetworkUDPInitialize();
Debug(net, 3, "Network online, multiplayer available");
NetworkFindBroadcastIPs(&_broadcast_list);
}