summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2004-12-13 17:47:21 +0000
committertruelight <truelight@openttd.org>2004-12-13 17:47:21 +0000
commit9ced62e239c6ff424659cc1151632766d366da20 (patch)
tree01af336ac91325c4ce99a24b1968cfe7078c5e6b
parent382b924b41f1448ef5a843fd6ce07d31415afb99 (diff)
downloadopenttd-9ced62e239c6ff424659cc1151632766d366da20.tar.xz
(svn r1059) -Fix: [Console] Renamed 'set port' to 'set server_port'
-Add: [Network] Add ip-bind ('set server_bind_ip <ip>' in console or use scripts/pre_dedicated.scr)
-rw-r--r--console_cmds.c33
-rw-r--r--network.c15
-rw-r--r--network.h5
-rw-r--r--network_udp.c4
-rw-r--r--scripts/pre_dedicated.scr.example2
-rw-r--r--scripts/pre_server.scr.example1
-rw-r--r--scripts/readme.txt2
-rw-r--r--settings.c1
-rw-r--r--settings_gui.c4
9 files changed, 56 insertions, 11 deletions
diff --git a/console_cmds.c b/console_cmds.c
index d344d8e95..f9b8d7271 100644
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -657,8 +657,8 @@ DEF_CONSOLE_CMD(ConSet) {
return NULL;
}
- // setting the server name
- if (strcmp(argv[1],"port") == 0) {
+ // setting the server port
+ if (strcmp(argv[1],"server_port") == 0) {
if (argc == 3 && atoi(argv[2]) != 0) {
_network_server_port = atoi(argv[2]);
IConsolePrintF(_iconsole_color_warning, "Server-port changed to '%d'", _network_server_port);
@@ -670,7 +670,22 @@ DEF_CONSOLE_CMD(ConSet) {
return NULL;
}
-#endif
+ // setting the server ip
+ if (strcmp(argv[1],"server_bind_ip") == 0 || strcmp(argv[1],"server_ip_bind") == 0 ||
+ strcmp(argv[1],"server_ip") == 0 || strcmp(argv[1],"server_bind") == 0) {
+ if (argc == 3) {
+ _network_server_bind_ip = inet_addr(argv[2]);
+ snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
+ IConsolePrintF(_iconsole_color_warning, "Server-bind-ip changed to '%s'", _network_server_bind_ip_host);
+ IConsolePrintF(_iconsole_color_warning, "Changes will take effect the next time you start a server.");
+ } else {
+ IConsolePrintF(_iconsole_color_default, "Current server-bind-ip is '%s'", _network_server_bind_ip_host);
+ IConsolePrint(_iconsole_color_warning, "Usage: set server_bind_ip <ip>.");
+ }
+ return NULL;
+ }
+
+#endif /* ENABLE_NETWORK */
// Patch-options
if (strcmp(argv[1],"patch") == 0) {
@@ -688,7 +703,17 @@ DEF_CONSOLE_CMD(ConSet) {
}
- IConsolePrintF(_iconsole_color_error,"Unknown setting");
+ IConsolePrint(_iconsole_color_error, "Unknown setting");
+ IConsolePrint(_iconsole_color_error, "Known settings are:");
+#ifdef ENABLE_NETWORK
+ IConsolePrint(_iconsole_color_error, " - server_pw \"<password>\"");
+ IConsolePrint(_iconsole_color_error, " - company_pw \"<password>\"");
+ IConsolePrint(_iconsole_color_error, " - name \"<playername>\"");
+ IConsolePrint(_iconsole_color_error, " - servername \"<name>\"");
+ IConsolePrint(_iconsole_color_error, " - server_port <port>");
+ IConsolePrint(_iconsole_color_error, " - server_bind_ip <ip>");
+#endif /* ENABLE_NETWORK */
+ IConsolePrint(_iconsole_color_error, " - patch <patch_name> [<value>]");
return NULL;
}
diff --git a/network.c b/network.c
index ddab48f2c..836ccb6e0 100644
--- a/network.c
+++ b/network.c
@@ -623,7 +623,7 @@ bool NetworkListen(void)
port = _network_server_port;
- DEBUG(net, 1) ("[NET] Listening on port %d", port);
+ DEBUG(net, 1) ("[NET] Listening on %s:%d", _network_server_bind_ip_host, port);
ls = socket(AF_INET, SOCK_STREAM, 0);
if (ls == INVALID_SOCKET) {
@@ -652,7 +652,7 @@ bool NetworkListen(void)
}
sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = 0;
+ sin.sin_addr.s_addr = _network_server_bind_ip;
sin.sin_port = htons(port);
if (bind(ls, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
@@ -841,13 +841,17 @@ bool NetworkServerStart(void)
{
if (!_network_available) return false;
+ /* Call the pre-scripts */
+ IConsoleCmdExec("exec scripts/pre_server.scr 0");
+ if (_network_dedicated) IConsoleCmdExec("exec scripts/pre_dedicated.scr 0");
+
NetworkInitialize();
if (!NetworkListen())
return false;
// Try to start UDP-server
_network_udp_server = true;
- _network_udp_server = NetworkUDPListen(0, _network_server_port);
+ _network_udp_server = NetworkUDPListen(_network_server_bind_ip, _network_server_port);
_network_server = true;
_networking = true;
@@ -1157,6 +1161,11 @@ void NetworkStartUp(void)
_network_available = true;
_network_dedicated = false;
+ /* Load the ip from the openttd.cfg */
+ _network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
+ /* And put the data back in it in case it was an invalid ip */
+ snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
+
/* Generate an unique id when there is none yet */
if (_network_unique_id[0] == '\0')
NetworkGenerateUniqueId();
diff --git a/network.h b/network.h
index 7b8674211..d7092383d 100644
--- a/network.h
+++ b/network.h
@@ -138,6 +138,11 @@ VARDEF uint16 _network_game_count;
VARDEF uint16 _network_lobby_company_count;
VARDEF uint _network_server_port;
+/* We use bind_ip and bind_ip_host, where bind_ip_host is the readable form of
+ bind_ip_host, and bind_ip the numeric value, because we want a nice number
+ in the openttd.cfg, but we wants to use the uint32 internally.. */
+VARDEF uint32 _network_server_bind_ip;
+VARDEF char _network_server_bind_ip_host[NETWORK_HOSTNAME_LENGTH];
VARDEF bool _is_network_server; // Does this client wants to be a network-server?
VARDEF char _network_server_name[NETWORK_NAME_LENGTH];
diff --git a/network_udp.c b/network_udp.c
index 030901aee..dd249591b 100644
--- a/network_udp.c
+++ b/network_udp.c
@@ -182,7 +182,7 @@ bool NetworkUDPListen(uint32 host, uint16 port)
sin.sin_port = htons(port);
if (bind(udp, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
- DEBUG(net, 1) ("[NET][UDP] error: bind failed on port %i", port);
+ DEBUG(net, 1) ("[NET][UDP] error: bind failed on %s:%i", inet_ntoa(*(struct in_addr *)&host), port);
return false;
}
@@ -200,7 +200,7 @@ bool NetworkUDPListen(uint32 host, uint16 port)
else
_udp_client_socket = udp;
- DEBUG(net, 1)("[NET][UDP] Listening on port %d", port);
+ DEBUG(net, 1)("[NET][UDP] Listening on port %s:%d", inet_ntoa(*(struct in_addr *)&host), port);
return true;
}
diff --git a/scripts/pre_dedicated.scr.example b/scripts/pre_dedicated.scr.example
new file mode 100644
index 000000000..c4a9e2e8f
--- /dev/null
+++ b/scripts/pre_dedicated.scr.example
@@ -0,0 +1,2 @@
+set server_ip 0.0.0.0
+set server_port 3979
diff --git a/scripts/pre_server.scr.example b/scripts/pre_server.scr.example
new file mode 100644
index 000000000..25e8756f2
--- /dev/null
+++ b/scripts/pre_server.scr.example
@@ -0,0 +1 @@
+set server_port 3979
diff --git a/scripts/readme.txt b/scripts/readme.txt
index 99535e37c..3cd4e4c32 100644
--- a/scripts/readme.txt
+++ b/scripts/readme.txt
@@ -6,6 +6,8 @@ OpenTTD supports scripts.
- 'on_client.scr' is executed when you join a server as client
- 'on_server.scr' is executed when you start a server / dedicated server
- 'on_dedicated.scr' is additionally executed when you start a dedicated server
+ - 'pre_server.scr' is executed before the server is started
+ - 'pre_dedeicated.scr' is additionally executed when you start a dedicated server
For examples how a script can look, check the .example examples.
diff --git a/settings.c b/settings.c
index ef8862e20..dfa22e53d 100644
--- a/settings.c
+++ b/settings.c
@@ -725,6 +725,7 @@ static const SettingDesc misc_settings[] = {
static const SettingDesc network_settings[] = {
{"sync_freq", SDT_UINT16 | SDT_NOSAVE, (void*)100, &_network_sync_freq, NULL},
{"frame_freq", SDT_UINT8 | SDT_NOSAVE, (void*)0, &_network_frame_freq, NULL},
+ {"server_bind_ip", SDT_STRINGBUF | (lengthof(_network_server_bind_ip_host) << 16), NULL, &_network_server_bind_ip_host, NULL},
{"server_port", SDT_UINT, (void*)NETWORK_DEFAULT_PORT, &_network_server_port, NULL},
{"player_name", SDT_STRINGBUF | (lengthof(_network_player_name) << 16), NULL, &_network_player_name, NULL},
{"server_password", SDT_STRINGBUF | (lengthof(_network_game_info.server_password) << 16), NULL, &_network_game_info.server_password, NULL},
diff --git a/settings_gui.c b/settings_gui.c
index ed7076199..20a5696a1 100644
--- a/settings_gui.c
+++ b/settings_gui.c
@@ -1005,7 +1005,7 @@ void ConsoleSetPatchSetting(char *name, char *value)
/* We did not found the patch setting */
if (!found) {
- IConsolePrintF(_iconsole_color_warning, "'%s' is an unkown patch settings", name);
+ IConsolePrintF(_iconsole_color_warning, "'%s' is an unkown patch setting", name);
return;
}
@@ -1063,7 +1063,7 @@ void ConsoleGetPatchSetting(char *name)
/* We did not found the patch setting */
if (!found) {
- IConsolePrintF(_iconsole_color_warning, "'%s' is an unkown patch settings", name);
+ IConsolePrintF(_iconsole_color_warning, "'%s' is an unkown patch setting", name);
return;
}