diff options
author | rubidium <rubidium@openttd.org> | 2009-04-08 19:36:51 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-08 19:36:51 +0000 |
commit | 08e37a6f1026bdb2ae28d90e605230c7f864b4b9 (patch) | |
tree | 40dc224e750c9c08a9e69b9b9b8dc8802494e77b | |
parent | 9c814d64f4e33f0c1ebeb3d954c085a1a620ac4b (diff) | |
download | openttd-08e37a6f1026bdb2ae28d90e605230c7f864b4b9.tar.xz |
(svn r15987) -Fix: make the master socket only listen on the IP the server is bound to.
-rw-r--r-- | src/network/network.cpp | 6 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 34 | ||||
-rw-r--r-- | src/network/network_udp.h | 2 |
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 */ |