(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)
This commit is contained in:
truelight 2004-12-13 17:47:21 +00:00
parent 382b924b41
commit 9ced62e239
9 changed files with 56 additions and 11 deletions

View File

@ -657,8 +657,8 @@ DEF_CONSOLE_CMD(ConSet) {
return NULL; return NULL;
} }
// setting the server name // setting the server port
if (strcmp(argv[1],"port") == 0) { if (strcmp(argv[1],"server_port") == 0) {
if (argc == 3 && atoi(argv[2]) != 0) { if (argc == 3 && atoi(argv[2]) != 0) {
_network_server_port = atoi(argv[2]); _network_server_port = atoi(argv[2]);
IConsolePrintF(_iconsole_color_warning, "Server-port changed to '%d'", _network_server_port); IConsolePrintF(_iconsole_color_warning, "Server-port changed to '%d'", _network_server_port);
@ -670,7 +670,22 @@ DEF_CONSOLE_CMD(ConSet) {
return NULL; 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 // Patch-options
if (strcmp(argv[1],"patch") == 0) { 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; return NULL;
} }

View File

@ -623,7 +623,7 @@ bool NetworkListen(void)
port = _network_server_port; 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); ls = socket(AF_INET, SOCK_STREAM, 0);
if (ls == INVALID_SOCKET) { if (ls == INVALID_SOCKET) {
@ -652,7 +652,7 @@ bool NetworkListen(void)
} }
sin.sin_family = AF_INET; 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); sin.sin_port = htons(port);
if (bind(ls, (struct sockaddr*)&sin, sizeof(sin)) != 0) { if (bind(ls, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
@ -841,13 +841,17 @@ bool NetworkServerStart(void)
{ {
if (!_network_available) return false; 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(); NetworkInitialize();
if (!NetworkListen()) if (!NetworkListen())
return false; return false;
// Try to start UDP-server // Try to start UDP-server
_network_udp_server = true; _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; _network_server = true;
_networking = true; _networking = true;
@ -1157,6 +1161,11 @@ void NetworkStartUp(void)
_network_available = true; _network_available = true;
_network_dedicated = false; _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 */ /* Generate an unique id when there is none yet */
if (_network_unique_id[0] == '\0') if (_network_unique_id[0] == '\0')
NetworkGenerateUniqueId(); NetworkGenerateUniqueId();

View File

@ -138,6 +138,11 @@ VARDEF uint16 _network_game_count;
VARDEF uint16 _network_lobby_company_count; VARDEF uint16 _network_lobby_company_count;
VARDEF uint _network_server_port; 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 bool _is_network_server; // Does this client wants to be a network-server?
VARDEF char _network_server_name[NETWORK_NAME_LENGTH]; VARDEF char _network_server_name[NETWORK_NAME_LENGTH];

View File

@ -182,7 +182,7 @@ bool NetworkUDPListen(uint32 host, uint16 port)
sin.sin_port = htons(port); sin.sin_port = htons(port);
if (bind(udp, (struct sockaddr*)&sin, sizeof(sin)) != 0) { 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; return false;
} }
@ -200,7 +200,7 @@ bool NetworkUDPListen(uint32 host, uint16 port)
else else
_udp_client_socket = udp; _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; return true;
} }

View File

@ -0,0 +1,2 @@
set server_ip 0.0.0.0
set server_port 3979

View File

@ -0,0 +1 @@
set server_port 3979

View File

@ -6,6 +6,8 @@ OpenTTD supports scripts.
- 'on_client.scr' is executed when you join a server as client - '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_server.scr' is executed when you start a server / dedicated server
- 'on_dedicated.scr' is additionally executed when you start a 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. For examples how a script can look, check the .example examples.

View File

@ -725,6 +725,7 @@ static const SettingDesc misc_settings[] = {
static const SettingDesc network_settings[] = { static const SettingDesc network_settings[] = {
{"sync_freq", SDT_UINT16 | SDT_NOSAVE, (void*)100, &_network_sync_freq, NULL}, {"sync_freq", SDT_UINT16 | SDT_NOSAVE, (void*)100, &_network_sync_freq, NULL},
{"frame_freq", SDT_UINT8 | SDT_NOSAVE, (void*)0, &_network_frame_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}, {"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}, {"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}, {"server_password", SDT_STRINGBUF | (lengthof(_network_game_info.server_password) << 16), NULL, &_network_game_info.server_password, NULL},

View File

@ -1005,7 +1005,7 @@ void ConsoleSetPatchSetting(char *name, char *value)
/* We did not found the patch setting */ /* We did not found the patch setting */
if (!found) { 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; return;
} }
@ -1063,7 +1063,7 @@ void ConsoleGetPatchSetting(char *name)
/* We did not found the patch setting */ /* We did not found the patch setting */
if (!found) { 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; return;
} }