summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/network/network.cpp6
-rw-r--r--src/network/network_udp.cpp34
-rw-r--r--src/network/network_udp.h2
3 files changed, 19 insertions, 23 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 1bb207ff0..5fd68650b 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -587,7 +587,7 @@ static void NetworkClose()
_listensockets.Clear();
DEBUG(net, 1, "Closed listener");
}
- NetworkUDPCloseAll();
+ NetworkUDPClose();
TCPConnecter::KillAll();
@@ -606,6 +606,7 @@ static void NetworkClose()
static void NetworkInitialize()
{
InitializeNetworkPools();
+ NetworkUDPInitialize();
_sync_frame = 0;
_network_first_time = true;
@@ -743,6 +744,7 @@ bool NetworkServerStart()
IConsoleCmdExec("exec scripts/pre_server.scr 0");
if (_network_dedicated) IConsoleCmdExec("exec scripts/pre_dedicated.scr 0");
+ NetworkDisconnect();
NetworkInitialize();
if (!NetworkListen()) return false;
@@ -1077,7 +1079,6 @@ void NetworkStartUp()
memset(&_network_game_info, 0, sizeof(_network_game_info));
- NetworkUDPInitialize();
NetworkInitialize();
DEBUG(net, 3, "[core] network online, multiplayer available");
NetworkFindBroadcastIPs(&_broadcast_list);
@@ -1087,7 +1088,6 @@ void NetworkStartUp()
void NetworkShutDown()
{
NetworkDisconnect();
- NetworkUDPShutdown();
DEBUG(net, 3, "[core] shutting down network");
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index f9c2f98ca..c1da7df43 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -48,6 +48,7 @@ protected:
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_ACK_REGISTER);
DECLARE_UDP_RECEIVE_COMMAND(PACKET_UDP_MASTER_SESSION_KEY);
public:
+ MasterNetworkUDPSocketHandler(NetworkAddressList *addresses) : NetworkUDPSocketHandler(addresses) {}
virtual ~MasterNetworkUDPSocketHandler() {}
};
@@ -354,21 +355,6 @@ void ClientNetworkUDPSocketHandler::HandleIncomingNetworkGameInfoGRFConfig(GRFCo
SetBit(config->flags, GCF_COPY);
}
-/* Close UDP connection */
-void NetworkUDPCloseAll()
-{
- DEBUG(net, 1, "[udp] closed listeners");
-
- _network_udp_mutex->BeginCritical();
- _udp_server_socket->Close();
- _udp_master_socket->Close();
- _udp_client_socket->Close();
- _network_udp_mutex->EndCritical();
-
- _network_udp_server = false;
- _network_udp_broadcast = 0;
-}
-
/* Broadcast to all ips */
static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
{
@@ -534,6 +520,7 @@ void NetworkUDPAdvertise()
void NetworkUDPInitialize()
{
+ DEBUG(net, 1, "[udp] initializing listeners");
assert(_udp_client_socket == NULL && _udp_server_socket == NULL && _udp_master_socket == NULL);
_network_udp_mutex->BeginCritical();
@@ -543,18 +530,23 @@ void NetworkUDPInitialize()
_udp_client_socket = new ClientNetworkUDPSocketHandler();
_udp_server_socket = new ServerNetworkUDPSocketHandler(&server);
- _udp_master_socket = new MasterNetworkUDPSocketHandler();
+
+ for (NetworkAddress *iter = server.Begin(); iter != server.End(); iter++) {
+ iter->SetPort(0);
+ }
+ _udp_master_socket = new MasterNetworkUDPSocketHandler(&server);
_network_udp_server = false;
_network_udp_broadcast = 0;
_network_udp_mutex->EndCritical();
}
-void NetworkUDPShutdown()
+void NetworkUDPClose()
{
- NetworkUDPCloseAll();
-
_network_udp_mutex->BeginCritical();
+ _udp_server_socket->Close();
+ _udp_master_socket->Close();
+ _udp_client_socket->Close();
delete _udp_client_socket;
delete _udp_server_socket;
delete _udp_master_socket;
@@ -562,6 +554,10 @@ void NetworkUDPShutdown()
_udp_server_socket = NULL;
_udp_master_socket = NULL;
_network_udp_mutex->EndCritical();
+
+ _network_udp_server = false;
+ _network_udp_broadcast = 0;
+ DEBUG(net, 1, "[udp] closed listeners");
}
#endif /* ENABLE_NETWORK */
diff --git a/src/network/network_udp.h b/src/network/network_udp.h
index 736524c00..57a29a49c 100644
--- a/src/network/network_udp.h
+++ b/src/network/network_udp.h
@@ -13,7 +13,7 @@ void NetworkUDPQueryMasterServer();
void NetworkUDPQueryServer(NetworkAddress address, bool manually = false);
void NetworkUDPAdvertise();
void NetworkUDPRemoveAdvertise();
-void NetworkUDPShutdown();
+void NetworkUDPClose();
#endif /* ENABLE_NETWORK */