From dd7f69be6ed6ea90ec806c86957f10332206bcd6 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Sun, 11 Jul 2021 22:37:14 +0200 Subject: 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. --- src/network/network.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') 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); } -- cgit v1.2.3-70-g09d2