diff options
author | rubidium <rubidium@openttd.org> | 2009-04-10 12:56:55 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-10 12:56:55 +0000 |
commit | 7d3db3ee91945807c1041789e22e11a9844ec63d (patch) | |
tree | 0b5cc992be657457176933996ae1117a96bb2283 /src/network | |
parent | ba200c6a92829235d3ef79cf339b6538eb90a0ca (diff) | |
download | openttd-7d3db3ee91945807c1041789e22e11a9844ec63d.tar.xz |
(svn r16014) -Feature(-ish): allow binding to several IPs; [network]:server_bind_ip doesn't exist anymore. Add the IPs/hostnames to [server_bind_addresses]
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/network.cpp | 25 | ||||
-rw-r--r-- | src/network/network_func.h | 1 | ||||
-rw-r--r-- | src/network/network_internal.h | 1 | ||||
-rw-r--r-- | src/network/network_udp.cpp | 11 |
4 files changed, 30 insertions, 8 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp index 59a5cf55f..3965d8ef7 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -55,6 +55,7 @@ ClientID _redirect_console_to_client; bool _network_need_advertise; uint32 _network_last_advertise_frame; uint8 _network_reconnect; +StringList _network_bind_list; StringList _network_host_list; StringList _network_ban_list; uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode @@ -542,9 +543,12 @@ static bool NetworkListen() { assert(_listensockets.Length() == 0); - NetworkAddress address(_settings_client.network.server_bind_ip, _settings_client.network.server_port); + NetworkAddressList addresses; + GetBindAddresses(&addresses, _settings_client.network.server_port); - address.Listen(SOCK_STREAM, &_listensockets); + for (NetworkAddress *address = addresses.Begin(); address != addresses.End(); address++) { + address->Listen(SOCK_STREAM, &_listensockets); + } if (_listensockets.Length() == 0) { ServerStartError("Could not create listening socket"); @@ -664,6 +668,23 @@ void NetworkAddServer(const char *b) } } +/** + * Get the addresses to bind to. + * @param addresses the list to write to. + * @param port the port to bind to. + */ +void GetBindAddresses(NetworkAddressList *addresses, uint16 port) +{ + for (char **iter = _network_bind_list.Begin(); iter != _network_bind_list.End(); iter++) { + *addresses->Append() = NetworkAddress(*iter, port); + } + + /* No address, so bind to everything. */ + if (addresses->Length() == 0) { + *addresses->Append() = NetworkAddress("", port); + } +} + /* Generates the list of manually added hosts from NetworkGameList and * dumps them into the array _network_host_list. This array is needed * by the function that generates the config file. */ diff --git a/src/network/network_func.h b/src/network/network_func.h index faece9093..88a4329a4 100644 --- a/src/network/network_func.h +++ b/src/network/network_func.h @@ -21,6 +21,7 @@ extern ClientID _redirect_console_to_client; extern bool _network_need_advertise; extern uint32 _network_last_advertise_frame; extern uint8 _network_reconnect; +extern StringList _network_bind_list; extern StringList _network_host_list; extern StringList _network_ban_list; diff --git a/src/network/network_internal.h b/src/network/network_internal.h index c813e316a..48aaa0530 100644 --- a/src/network/network_internal.h +++ b/src/network/network_internal.h @@ -123,6 +123,7 @@ extern CompanyMask _network_company_passworded; void NetworkTCPQueryServer(NetworkAddress address); +void GetBindAddresses(NetworkAddressList *addresses, uint16 port); void NetworkAddServer(const char *b); void NetworkRebuildHostList(); void UpdateNetworkGameWindow(bool unselect); diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp index a087297e7..74c732710 100644 --- a/src/network/network_udp.cpp +++ b/src/network/network_udp.cpp @@ -546,15 +546,14 @@ void NetworkUDPInitialize() _network_udp_mutex->BeginCritical(); - NetworkAddressList server; - *server.Append() = NetworkAddress(_settings_client.network.server_bind_ip, _settings_client.network.server_port); - _udp_client_socket = new ClientNetworkUDPSocketHandler(); + + NetworkAddressList server; + GetBindAddresses(&server, _settings_client.network.server_port); _udp_server_socket = new ServerNetworkUDPSocketHandler(&server); - for (NetworkAddress *iter = server.Begin(); iter != server.End(); iter++) { - iter->SetPort(0); - } + server.Clear(); + GetBindAddresses(&server, 0); _udp_master_socket = new MasterNetworkUDPSocketHandler(&server); _network_udp_server = false; |