mirror of https://github.com/OpenTTD/OpenTTD
(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)release/0.4.5
parent
382b924b41
commit
9ced62e239
|
@ -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;
|
||||
}
|
||||
|
|
15
network.c
15
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();
|
||||
|
|
|
@ -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];
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
set server_ip 0.0.0.0
|
||||
set server_port 3979
|
|
@ -0,0 +1 @@
|
|||
set server_port 3979
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue