summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-10 12:56:55 +0000
committerrubidium <rubidium@openttd.org>2009-04-10 12:56:55 +0000
commit7d3db3ee91945807c1041789e22e11a9844ec63d (patch)
tree0b5cc992be657457176933996ae1117a96bb2283
parentba200c6a92829235d3ef79cf339b6538eb90a0ca (diff)
downloadopenttd-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]
-rw-r--r--src/network/network.cpp25
-rw-r--r--src/network/network_func.h1
-rw-r--r--src/network/network_internal.h1
-rw-r--r--src/network/network_udp.cpp11
-rw-r--r--src/openttd.cpp5
-rw-r--r--src/settings.cpp1
-rw-r--r--src/settings_type.h1
-rw-r--r--src/table/settings.h1
8 files changed, 35 insertions, 11 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;
diff --git a/src/openttd.cpp b/src/openttd.cpp
index be74b3b6e..2d0bf65a9 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -544,7 +544,10 @@ int ttd_main(int argc, char *argv[])
if (_cur_resolution.height <= 0) _cur_resolution.height = 1;
#if defined(ENABLE_NETWORK)
- if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
+ if (dedicated_host) {
+ _network_bind_list.Clear();
+ *_network_bind_list.Append() = strdup(dedicated_host);
+ }
if (dedicated_port) _settings_client.network.server_port = dedicated_port;
if (_dedicated_forks && !dedicated) _dedicated_forks = false;
#endif /* ENABLE_NETWORK */
diff --git a/src/settings.cpp b/src/settings.cpp
index 63e099e3a..a8e8c9117 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1277,6 +1277,7 @@ static void HandleSettingDescs(IniFile *ini, SettingDescProc *proc, SettingDescP
proc(ini, _currency_settings,"currency", &_custom_currency);
#ifdef ENABLE_NETWORK
+ proc_list(ini, "server_bind_addresses", &_network_bind_list);
proc_list(ini, "servers", &_network_host_list);
proc_list(ini, "bans", &_network_ban_list);
#endif /* ENABLE_NETWORK */
diff --git a/src/settings_type.h b/src/settings_type.h
index 56015dc08..f52c77008 100644
--- a/src/settings_type.h
+++ b/src/settings_type.h
@@ -112,7 +112,6 @@ struct NetworkSettings {
uint8 frame_freq; ///< how often do we send commands to the clients
uint16 max_join_time; ///< maximum amount of time, in game ticks, a client may take to join
bool pause_on_join; ///< pause the game when people join
- char server_bind_ip[NETWORK_HOSTNAME_LENGTH]; ///< IP address the server binds to
uint16 server_port; ///< port the server listens on
char server_name[NETWORK_NAME_LENGTH]; ///< name of the server
char server_password[NETWORK_PASSWORD_LENGTH]; ///< passowrd for joining this server
diff --git a/src/table/settings.h b/src/table/settings.h
index 78a738d93..9f6409dab 100644
--- a/src/table/settings.h
+++ b/src/table/settings.h
@@ -563,7 +563,6 @@ const SettingDesc _settings[] = {
SDTC_VAR(network.frame_freq, SLE_UINT8,C|S,NO, 0, 0, 100, 0, STR_NULL, NULL),
SDTC_VAR(network.max_join_time, SLE_UINT16, S, NO, 500, 0, 32000, 0, STR_NULL, NULL),
SDTC_BOOL(network.pause_on_join, S, NO, true, STR_NULL, NULL),
- SDTC_STR(network.server_bind_ip, SLE_STRB, S, NO, "", STR_NULL, NULL),
SDTC_VAR(network.server_port, SLE_UINT16, S, NO,NETWORK_DEFAULT_PORT,0,65535,0,STR_NULL, NULL),
SDTC_BOOL(network.server_advertise, S, NO, false, STR_NULL, NULL),
SDTC_VAR(network.lan_internet, SLE_UINT8, S, NO, 0, 0, 1, 0, STR_NULL, NULL),