mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r13334) -Codechange: move the network settings variables from network/network_internal to settings.
This commit is contained in:
parent
61507ffeab
commit
c33164831d
|
@ -1307,12 +1307,12 @@ DEF_CONSOLE_CMD(ConSayClient)
|
|||
|
||||
DEF_CONSOLE_HOOK(ConHookServerPW)
|
||||
{
|
||||
if (strcmp(_network_server_password, "*") == 0) {
|
||||
_network_server_password[0] = '\0';
|
||||
_network_game_info.use_password = 0;
|
||||
if (strcmp(_settings_client.network.server_password, "*") == 0) {
|
||||
_settings_client.network.server_password[0] = '\0';
|
||||
_network_game_info.use_password = false;
|
||||
} else {
|
||||
ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_server_password));
|
||||
_network_game_info.use_password = 1;
|
||||
ttd_strlcpy(_network_game_info.server_password, _settings_client.network.server_password, sizeof(_network_game_info.server_password));
|
||||
_network_game_info.use_password = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1320,10 +1320,11 @@ DEF_CONSOLE_HOOK(ConHookServerPW)
|
|||
|
||||
DEF_CONSOLE_HOOK(ConHookRconPW)
|
||||
{
|
||||
if (strcmp(_network_rcon_password, "*") == 0)
|
||||
_network_rcon_password[0] = '\0';
|
||||
if (strcmp(_settings_client.network.rcon_password, "*") == 0) {
|
||||
_settings_client.network.rcon_password[0] = '\0';
|
||||
}
|
||||
|
||||
ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_game_info.rcon_password));
|
||||
ttd_strlcpy(_network_game_info.rcon_password, _settings_client.network.rcon_password, sizeof(_network_game_info.rcon_password));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1368,13 +1369,13 @@ DEF_CONSOLE_HOOK(ConProcPlayerName)
|
|||
if (ci == NULL) return false;
|
||||
|
||||
/* Don't change the name if it is the same as the old name */
|
||||
if (strcmp(ci->client_name, _network_player_name) != 0) {
|
||||
if (strcmp(ci->client_name, _settings_client.network.player_name) != 0) {
|
||||
if (!_network_server) {
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_network_player_name);
|
||||
SEND_COMMAND(PACKET_CLIENT_SET_NAME)(_settings_client.network.player_name);
|
||||
} else {
|
||||
if (NetworkFindName(_network_player_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _network_player_name);
|
||||
ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
|
||||
if (NetworkFindName(_settings_client.network.player_name)) {
|
||||
NetworkTextMessage(NETWORK_ACTION_NAME_CHANGE, CC_DEFAULT, false, ci->client_name, "%s", _settings_client.network.player_name);
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
|
||||
NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
|
||||
}
|
||||
}
|
||||
|
@ -1385,7 +1386,7 @@ DEF_CONSOLE_HOOK(ConProcPlayerName)
|
|||
|
||||
DEF_CONSOLE_HOOK(ConHookServerName)
|
||||
{
|
||||
ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name));
|
||||
ttd_strlcpy(_network_game_info.server_name, _settings_client.network.server_name, sizeof(_network_game_info.server_name));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1407,7 +1408,7 @@ DEF_CONSOLE_CMD(ConProcServerIP)
|
|||
if (argc != 1) return false;
|
||||
|
||||
_network_server_bind_ip = (strcmp(argv[0], "all") == 0) ? inet_addr("0.0.0.0") : inet_addr(argv[0]);
|
||||
snprintf(_network_server_bind_ip_host, sizeof(_network_server_bind_ip_host), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
|
||||
snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
|
||||
IConsolePrintF(CC_WARNING, "'server_ip' changed to: %s", inet_ntoa(*(struct in_addr *)&_network_server_bind_ip));
|
||||
return true;
|
||||
}
|
||||
|
@ -1594,16 +1595,16 @@ void IConsoleStdLibRegister()
|
|||
IConsoleCmdHookAdd("unpause", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
|
||||
/*** Networking variables ***/
|
||||
IConsoleVarRegister("net_frame_freq", &_network_frame_freq, ICONSOLE_VAR_BYTE, "The amount of frames before a command will be (visibly) executed. Default value: 1");
|
||||
IConsoleVarRegister("net_frame_freq", &_settings_client.network.frame_freq, ICONSOLE_VAR_BYTE, "The amount of frames before a command will be (visibly) executed. Default value: 1");
|
||||
IConsoleVarHookAdd("net_frame_freq", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarRegister("net_sync_freq", &_network_sync_freq, ICONSOLE_VAR_UINT16, "The amount of frames to check if the game is still in sync. Default value: 100");
|
||||
IConsoleVarRegister("net_sync_freq", &_settings_client.network.sync_freq, ICONSOLE_VAR_UINT16, "The amount of frames to check if the game is still in sync. Default value: 100");
|
||||
IConsoleVarHookAdd("net_sync_freq", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
|
||||
IConsoleVarStringRegister("server_pw", &_network_server_password, sizeof(_network_server_password), "Set the server password to protect your server. Use '*' to clear the password");
|
||||
IConsoleVarStringRegister("server_pw", &_settings_client.network.server_password, sizeof(_settings_client.network.server_password), "Set the server password to protect your server. Use '*' to clear the password");
|
||||
IConsoleVarHookAdd("server_pw", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("server_pw", ICONSOLE_HOOK_POST_ACTION, ConHookServerPW);
|
||||
IConsoleAliasRegister("server_password", "server_pw %+");
|
||||
IConsoleVarStringRegister("rcon_pw", &_network_rcon_password, sizeof(_network_rcon_password), "Set the rcon-password to change server behaviour. Use '*' to disable rcon");
|
||||
IConsoleVarStringRegister("rcon_pw", &_settings_client.network.rcon_password, sizeof(_settings_client.network.rcon_password), "Set the rcon-password to change server behaviour. Use '*' to disable rcon");
|
||||
IConsoleVarHookAdd("rcon_pw", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("rcon_pw", ICONSOLE_HOOK_POST_ACTION, ConHookRconPW);
|
||||
IConsoleAliasRegister("rcon_password", "rcon_pw %+");
|
||||
|
@ -1612,20 +1613,20 @@ void IConsoleStdLibRegister()
|
|||
IConsoleVarProcAdd("company_pw", NetworkChangeCompanyPassword);
|
||||
IConsoleAliasRegister("company_password", "company_pw %+");
|
||||
|
||||
IConsoleVarStringRegister("name", &_network_player_name, sizeof(_network_player_name), "Set your name for multiplayer");
|
||||
IConsoleVarStringRegister("name", &_settings_client.network.player_name, sizeof(_settings_client.network.player_name), "Set your name for multiplayer");
|
||||
IConsoleVarHookAdd("name", ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);
|
||||
IConsoleVarHookAdd("name", ICONSOLE_HOOK_POST_ACTION, ConProcPlayerName);
|
||||
IConsoleVarStringRegister("server_name", &_network_server_name, sizeof(_network_server_name), "Set the name of the server for multiplayer");
|
||||
IConsoleVarStringRegister("server_name", &_settings_client.network.server_name, sizeof(_settings_client.network.server_name), "Set the name of the server for multiplayer");
|
||||
IConsoleVarHookAdd("server_name", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("server_name", ICONSOLE_HOOK_POST_ACTION, ConHookServerName);
|
||||
|
||||
IConsoleVarRegister("server_port", &_network_server_port, ICONSOLE_VAR_UINT32, "Set the server port. Changes take effect the next time you start a server");
|
||||
IConsoleVarRegister("server_port", &_settings_client.network.server_port, ICONSOLE_VAR_UINT32, "Set the server port. Changes take effect the next time you start a server");
|
||||
IConsoleVarRegister("server_ip", &_network_server_bind_ip, ICONSOLE_VAR_UINT32, "Set the IP the server binds to. Changes take effect the next time you start a server. Use 'all' to bind to any IP.");
|
||||
IConsoleVarProcAdd("server_ip", ConProcServerIP);
|
||||
IConsoleAliasRegister("server_bind_ip", "server_ip %+");
|
||||
IConsoleAliasRegister("server_ip_bind", "server_ip %+");
|
||||
IConsoleAliasRegister("server_bind", "server_ip %+");
|
||||
IConsoleVarRegister("server_advertise", &_network_advertise, ICONSOLE_VAR_BOOLEAN, "Set if the server will advertise to the master server and show up there");
|
||||
IConsoleVarRegister("server_advertise", &_settings_client.network.server_advertise, ICONSOLE_VAR_BOOLEAN, "Set if the server will advertise to the master server and show up there");
|
||||
IConsoleVarHookAdd("server_advertise", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("server_advertise", ICONSOLE_HOOK_POST_ACTION, ConHookServerAdvertise);
|
||||
|
||||
|
@ -1639,24 +1640,24 @@ void IConsoleStdLibRegister()
|
|||
IConsoleVarHookAdd("max_spectators", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("max_spectators", ICONSOLE_HOOK_POST_ACTION, ConHookValidateMaxSpectatorsCount);
|
||||
|
||||
IConsoleVarRegister("max_join_time", &_network_max_join_time, ICONSOLE_VAR_UINT16, "Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500");
|
||||
IConsoleVarRegister("max_join_time", &_settings_client.network.max_join_time, ICONSOLE_VAR_UINT16, "Set the maximum amount of time (ticks) a client is allowed to join. Default value: 500");
|
||||
|
||||
IConsoleVarRegister("pause_on_join", &_network_pause_on_join, ICONSOLE_VAR_BOOLEAN, "Set if the server should pause gameplay while a client is joining. This might help slow users");
|
||||
IConsoleVarRegister("pause_on_join", &_settings_client.network.pause_on_join, ICONSOLE_VAR_BOOLEAN, "Set if the server should pause gameplay while a client is joining. This might help slow users");
|
||||
IConsoleVarHookAdd("pause_on_join", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
|
||||
IConsoleVarRegister("autoclean_companies", &_network_autoclean_companies, ICONSOLE_VAR_BOOLEAN, "Automatically shut down inactive companies to free them up for other players. Customize with 'autoclean_(un)protected'");
|
||||
IConsoleVarRegister("autoclean_companies", &_settings_client.network.autoclean_companies, ICONSOLE_VAR_BOOLEAN, "Automatically shut down inactive companies to free them up for other players. Customize with 'autoclean_(un)protected'");
|
||||
IConsoleVarHookAdd("autoclean_companies", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarRegister("autoclean_protected", &_network_autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically remove the password from an inactive company after the given amount of months");
|
||||
IConsoleVarRegister("autoclean_protected", &_settings_client.network.autoclean_protected, ICONSOLE_VAR_BYTE, "Automatically remove the password from an inactive company after the given amount of months");
|
||||
IConsoleVarHookAdd("autoclean_protected", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarRegister("autoclean_unprotected", &_network_autoclean_unprotected, ICONSOLE_VAR_BYTE, "Automatically shut down inactive companies after the given amount of months");
|
||||
IConsoleVarRegister("autoclean_unprotected", &_settings_client.network.autoclean_unprotected, ICONSOLE_VAR_BYTE, "Automatically shut down inactive companies after the given amount of months");
|
||||
IConsoleVarHookAdd("autoclean_unprotected", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarRegister("restart_game_year", &_network_restart_game_year, ICONSOLE_VAR_UINT16, "Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this");
|
||||
IConsoleVarRegister("restart_game_year", &_settings_client.network.restart_game_year, ICONSOLE_VAR_UINT16, "Auto-restart the server when Jan 1st of the set year is reached. Use '0' to disable this");
|
||||
IConsoleVarHookAdd("restart_game_year", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
|
||||
IConsoleVarRegister("min_players", &_network_min_players, ICONSOLE_VAR_BYTE, "Automatically pause the game when the number of active players passes below the given amount");
|
||||
IConsoleVarRegister("min_players", &_settings_client.network.min_players, ICONSOLE_VAR_BYTE, "Automatically pause the game when the number of active players passes below the given amount");
|
||||
IConsoleVarHookAdd("min_players", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
IConsoleVarHookAdd("min_players", ICONSOLE_HOOK_POST_ACTION, ConHookCheckMinPlayers);
|
||||
IConsoleVarRegister("reload_cfg", &_network_reload_cfg, ICONSOLE_VAR_BOOLEAN, "reload the entire config file between the end of this game, and starting the next new game - dedicated servers");
|
||||
IConsoleVarRegister("reload_cfg", &_settings_client.network.reload_cfg, ICONSOLE_VAR_BOOLEAN, "reload the entire config file between the end of this game, and starting the next new game - dedicated servers");
|
||||
IConsoleVarHookAdd("reload_cfg", ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
|
||||
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
|
|
@ -216,8 +216,8 @@ uint NetworkCalculateLag(const NetworkTCPSocketHandler *cs)
|
|||
// This client has missed his ACK packet after 1 DAY_TICKS..
|
||||
// so we increase his lag for every frame that passes!
|
||||
// The packet can be out by a max of _net_frame_freq
|
||||
if (cs->last_frame_server + DAY_TICKS + _network_frame_freq < _frame_counter)
|
||||
lag += _frame_counter - (cs->last_frame_server + DAY_TICKS + _network_frame_freq);
|
||||
if (cs->last_frame_server + DAY_TICKS + _settings_client.network.frame_freq < _frame_counter)
|
||||
lag += _frame_counter - (cs->last_frame_server + DAY_TICKS + _settings_client.network.frame_freq);
|
||||
|
||||
return lag;
|
||||
}
|
||||
|
@ -332,7 +332,7 @@ void CheckMinPlayers()
|
|||
{
|
||||
if (!_network_dedicated) return;
|
||||
|
||||
if (NetworkCountPlayers() < _network_min_players) {
|
||||
if (NetworkCountPlayers() < _settings_client.network.min_players) {
|
||||
if (_min_players_paused) return;
|
||||
|
||||
_min_players_paused = true;
|
||||
|
@ -662,7 +662,7 @@ void NetworkCloseClient(NetworkTCPSocketHandler *cs)
|
|||
}
|
||||
|
||||
/* When the client was PRE_ACTIVE, the server was in pause mode, so unpause */
|
||||
if (cs->status == STATUS_PRE_ACTIVE && _network_pause_on_join) {
|
||||
if (cs->status == STATUS_PRE_ACTIVE && _settings_client.network.pause_on_join) {
|
||||
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused", NETWORK_SERVER_INDEX);
|
||||
}
|
||||
|
@ -802,7 +802,7 @@ static bool NetworkListen()
|
|||
SOCKET ls;
|
||||
struct sockaddr_in sin;
|
||||
|
||||
DEBUG(net, 1, "Listening on %s:%d", _network_server_bind_ip_host, _network_server_port);
|
||||
DEBUG(net, 1, "Listening on %s:%d", _settings_client.network.server_bind_ip, _settings_client.network.server_port);
|
||||
|
||||
ls = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (ls == INVALID_SOCKET) {
|
||||
|
@ -823,7 +823,7 @@ static bool NetworkListen()
|
|||
|
||||
sin.sin_family = AF_INET;
|
||||
sin.sin_addr.s_addr = _network_server_bind_ip;
|
||||
sin.sin_port = htons(_network_server_port);
|
||||
sin.sin_port = htons(_settings_client.network.server_port);
|
||||
|
||||
if (bind(ls, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
|
||||
ServerStartError("bind() failed");
|
||||
|
@ -923,7 +923,7 @@ void NetworkAddServer(const char *b)
|
|||
|
||||
ttd_strlcpy(host, b, lengthof(host));
|
||||
|
||||
ttd_strlcpy(_network_default_ip, b, lengthof(_network_default_ip));
|
||||
ttd_strlcpy(_settings_client.network.connect_to_ip, b, lengthof(_settings_client.network.connect_to_ip));
|
||||
rport = NETWORK_DEFAULT_PORT;
|
||||
|
||||
ParseConnectionString(&player, &port, host);
|
||||
|
@ -961,8 +961,8 @@ bool NetworkClientConnectGame(const char *host, uint16 port)
|
|||
|
||||
if (port == 0) return false;
|
||||
|
||||
ttd_strlcpy(_network_last_host, host, sizeof(_network_last_host));
|
||||
_network_last_port = port;
|
||||
ttd_strlcpy(_settings_client.network.last_host, host, sizeof(_settings_client.network.last_host));
|
||||
_settings_client.network.last_port = port;
|
||||
|
||||
NetworkDisconnect();
|
||||
NetworkUDPCloseAll();
|
||||
|
@ -987,11 +987,16 @@ static void NetworkInitGameInfo()
|
|||
{
|
||||
NetworkClientInfo *ci;
|
||||
|
||||
ttd_strlcpy(_network_game_info.server_name, _network_server_name, sizeof(_network_game_info.server_name));
|
||||
ttd_strlcpy(_network_game_info.server_password, _network_server_password, sizeof(_network_server_password));
|
||||
ttd_strlcpy(_network_game_info.rcon_password, _network_rcon_password, sizeof(_network_rcon_password));
|
||||
if (_network_game_info.server_name[0] == '\0')
|
||||
_network_game_info.clients_max = _settings_client.network.max_clients;
|
||||
_network_game_info.companies_max = _settings_client.network.max_companies;
|
||||
_network_game_info.spectators_max = _settings_client.network.max_spectators;
|
||||
_network_game_info.server_lang = _settings_client.network.server_lang;
|
||||
ttd_strlcpy(_network_game_info.server_name, _settings_client.network.server_name, sizeof(_network_game_info.server_name));
|
||||
ttd_strlcpy(_network_game_info.server_password, _settings_client.network.server_password, sizeof(_network_game_info.server_password));
|
||||
ttd_strlcpy(_network_game_info.rcon_password, _settings_client.network.rcon_password, sizeof(_network_game_info.rcon_password));
|
||||
if (StrEmpty(_network_game_info.server_name)) {
|
||||
snprintf(_network_game_info.server_name, sizeof(_network_game_info.server_name), "Unnamed Server");
|
||||
}
|
||||
|
||||
ttd_strlcpy(_network_game_info.server_revision, _openttd_revision, sizeof(_network_game_info.server_revision));
|
||||
|
||||
|
@ -1014,7 +1019,7 @@ static void NetworkInitGameInfo()
|
|||
_network_game_info.map_height = MapSizeY();
|
||||
_network_game_info.map_set = _settings_game.game_creation.landscape;
|
||||
|
||||
_network_game_info.use_password = (_network_server_password[0] != '\0');
|
||||
_network_game_info.use_password = !StrEmpty(_settings_client.network.server_password);
|
||||
|
||||
// We use _network_client_info[MAX_CLIENT_INFO - 1] to store the server-data in it
|
||||
// The index is NETWORK_SERVER_INDEX ( = 1)
|
||||
|
@ -1024,8 +1029,8 @@ static void NetworkInitGameInfo()
|
|||
ci->client_index = NETWORK_SERVER_INDEX;
|
||||
ci->client_playas = _network_dedicated ? PLAYER_SPECTATOR : _local_player;
|
||||
|
||||
ttd_strlcpy(ci->client_name, _network_player_name, sizeof(ci->client_name));
|
||||
ttd_strlcpy(ci->unique_id, _network_unique_id, sizeof(ci->unique_id));
|
||||
ttd_strlcpy(ci->client_name, _settings_client.network.player_name, sizeof(ci->client_name));
|
||||
ttd_strlcpy(ci->unique_id, _settings_client.network.network_id, sizeof(ci->unique_id));
|
||||
}
|
||||
|
||||
bool NetworkServerStart()
|
||||
|
@ -1041,7 +1046,7 @@ bool NetworkServerStart()
|
|||
|
||||
// Try to start UDP-server
|
||||
_network_udp_server = true;
|
||||
_network_udp_server = _udp_server_socket->Listen(_network_server_bind_ip, _network_server_port, false);
|
||||
_network_udp_server = _udp_server_socket->Listen(_network_server_bind_ip, _settings_client.network.server_port, false);
|
||||
|
||||
_network_server = true;
|
||||
_networking = true;
|
||||
|
@ -1332,7 +1337,7 @@ void NetworkGameLoop()
|
|||
_frame_counter++;
|
||||
// Update max-frame-counter
|
||||
if (_frame_counter > _frame_counter_max) {
|
||||
_frame_counter_max = _frame_counter + _network_frame_freq;
|
||||
_frame_counter_max = _frame_counter + _settings_client.network.frame_freq;
|
||||
send_frame = true;
|
||||
}
|
||||
|
||||
|
@ -1382,7 +1387,7 @@ static void NetworkGenerateUniqueId()
|
|||
sprintf(hex_output + di * 2, "%02x", digest[di]);
|
||||
|
||||
/* _network_unique_id is our id */
|
||||
snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output);
|
||||
snprintf(_settings_client.network.network_id, sizeof(_settings_client.network.network_id), "%s", hex_output);
|
||||
}
|
||||
|
||||
void NetworkStartDebugLog(const char *hostname, uint16 port)
|
||||
|
@ -1429,12 +1434,12 @@ void NetworkStartUp()
|
|||
_network_advertise_retries = 0;
|
||||
|
||||
/* Load the ip from the openttd.cfg */
|
||||
_network_server_bind_ip = inet_addr(_network_server_bind_ip_host);
|
||||
_network_server_bind_ip = inet_addr(_settings_client.network.server_bind_ip);
|
||||
/* 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));
|
||||
snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%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();
|
||||
if (StrEmpty(_settings_client.network.network_id)) NetworkGenerateUniqueId();
|
||||
|
||||
{
|
||||
byte cl_max = _network_game_info.clients_max;
|
||||
|
|
|
@ -17,7 +17,6 @@ extern bool _network_server; ///< network-server is active
|
|||
extern bool _network_available; ///< is network mode available?
|
||||
extern bool _network_dedicated; ///< are we a dedicated server?
|
||||
extern bool _network_advertise; ///< is the server advertising to the master server?
|
||||
extern bool _network_reload_cfg; ///< will we reload the entire config for the next game?
|
||||
|
||||
#else /* ENABLE_NETWORK */
|
||||
/* Network function stubs when networking is disabled */
|
||||
|
|
|
@ -84,7 +84,7 @@ void HashCurrentCompanyPassword()
|
|||
if (StrEmpty(_network_player_info[_local_player].password)) return;
|
||||
|
||||
_password_game_seed = _settings_game.game_creation.generation_seed;
|
||||
ttd_strlcpy(_password_server_unique_id, _network_unique_id, sizeof(_password_server_unique_id));
|
||||
ttd_strlcpy(_password_server_unique_id, _settings_client.network.network_id, sizeof(_password_server_unique_id));
|
||||
|
||||
const char *new_pw = GenerateCompanyPasswordHash(_network_player_info[_local_player].password);
|
||||
ttd_strlcpy(_network_player_info[_local_player].password, new_pw, sizeof(_network_player_info[_local_player].password));
|
||||
|
@ -131,10 +131,10 @@ DEF_CLIENT_SEND_COMMAND(PACKET_CLIENT_JOIN)
|
|||
|
||||
p = NetworkSend_Init(PACKET_CLIENT_JOIN);
|
||||
p->Send_string(_openttd_revision);
|
||||
p->Send_string(_network_player_name); // Player name
|
||||
p->Send_string(_settings_client.network.player_name); // Player name
|
||||
p->Send_uint8 (_network_playas); // PlayAs
|
||||
p->Send_uint8 (NETLANG_ANY); // Language
|
||||
p->Send_string(_network_unique_id);
|
||||
p->Send_string(_settings_client.network.network_id);
|
||||
MY_CLIENT->Send_Packet(p);
|
||||
}
|
||||
|
||||
|
|
|
@ -240,7 +240,7 @@ protected:
|
|||
public:
|
||||
NetworkGameWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
|
||||
{
|
||||
ttd_strlcpy(this->edit_str_buf, _network_player_name, lengthof(this->edit_str_buf));
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.player_name, lengthof(this->edit_str_buf));
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 120);
|
||||
|
||||
|
@ -290,7 +290,7 @@ public:
|
|||
sel->info.grfconfig == NULL);
|
||||
|
||||
SetDParam(0, 0x00);
|
||||
SetDParam(1, _lan_internet_types_dropdown[_network_lan_internet]);
|
||||
SetDParam(1, _lan_internet_types_dropdown[_settings_client.network.lan_internet]);
|
||||
this->DrawWidgets();
|
||||
|
||||
/* Edit box to set player name */
|
||||
|
@ -315,7 +315,7 @@ public:
|
|||
y += NET_PRC__SIZE_OF_ROW;
|
||||
}
|
||||
|
||||
const NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_network_last_host), _network_last_port);
|
||||
const NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_settings_client.network.last_host), _settings_client.network.last_port);
|
||||
/* Draw the last joined server, if any */
|
||||
if (last_joined != NULL) this->DrawServerLine(last_joined, y = this->widget[NGWW_LASTJOINED].top + 3, last_joined == sel);
|
||||
|
||||
|
@ -406,7 +406,7 @@ public:
|
|||
break;
|
||||
|
||||
case NGWW_CONN_BTN: // 'Connection' droplist
|
||||
ShowDropDownMenu(this, _lan_internet_types_dropdown, _network_lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
|
||||
ShowDropDownMenu(this, _lan_internet_types_dropdown, _settings_client.network.lan_internet, NGWW_CONN_BTN, 0, 0); // do it for widget NSSW_CONN_BTN
|
||||
break;
|
||||
|
||||
case NGWW_NAME: // Sort by name
|
||||
|
@ -432,7 +432,7 @@ public:
|
|||
} break;
|
||||
|
||||
case NGWW_LASTJOINED: {
|
||||
NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_network_last_host), _network_last_port);
|
||||
NetworkGameList *last_joined = NetworkGameListAddItem(inet_addr(_settings_client.network.last_host), _settings_client.network.last_port);
|
||||
if (last_joined != NULL) {
|
||||
this->server = last_joined;
|
||||
this->SetDirty();
|
||||
|
@ -440,7 +440,7 @@ public:
|
|||
} break;
|
||||
|
||||
case NGWW_FIND: // Find server automatically
|
||||
switch (_network_lan_internet) {
|
||||
switch (_settings_client.network.lan_internet) {
|
||||
case 0: NetworkUDPSearchGame(); break;
|
||||
case 1: NetworkUDPQueryMasterServer(); break;
|
||||
}
|
||||
|
@ -448,7 +448,7 @@ public:
|
|||
|
||||
case NGWW_ADD: // Add a server
|
||||
ShowQueryString(
|
||||
BindCString(_network_default_ip),
|
||||
BindCString(_settings_client.network.connect_to_ip),
|
||||
STR_NETWORK_ENTER_IP,
|
||||
31 | 0x1000, // maximum number of characters OR
|
||||
250, // characters up to this width pixels, whichever is satisfied first
|
||||
|
@ -461,8 +461,8 @@ public:
|
|||
|
||||
case NGWW_JOIN: // Join Game
|
||||
if (this->server != NULL) {
|
||||
snprintf(_network_last_host, sizeof(_network_last_host), "%s", inet_ntoa(*(struct in_addr *)&this->server->ip));
|
||||
_network_last_port = this->server->port;
|
||||
snprintf(_settings_client.network.last_host, sizeof(_settings_client.network.last_host), "%s", inet_ntoa(*(struct in_addr *)&this->server->ip));
|
||||
_settings_client.network.last_port = this->server->port;
|
||||
ShowNetworkLobbyWindow(this->server);
|
||||
}
|
||||
break;
|
||||
|
@ -481,7 +481,7 @@ public:
|
|||
{
|
||||
switch (widget) {
|
||||
case NGWW_CONN_BTN:
|
||||
_network_lan_internet = index;
|
||||
_settings_client.network.lan_internet = index;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -521,9 +521,9 @@ public:
|
|||
|
||||
/* The name is only allowed when it starts with a letter! */
|
||||
if (!StrEmpty(this->edit_str_buf) && this->edit_str_buf[0] != ' ') {
|
||||
ttd_strlcpy(_network_player_name, this->edit_str_buf, lengthof(_network_player_name));
|
||||
ttd_strlcpy(_settings_client.network.player_name, this->edit_str_buf, lengthof(_settings_client.network.player_name));
|
||||
} else {
|
||||
ttd_strlcpy(_network_player_name, "Player", lengthof(_network_player_name));
|
||||
ttd_strlcpy(_settings_client.network.player_name, "Player", lengthof(_settings_client.network.player_name));
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
@ -665,7 +665,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
|
||||
NetworkStartServerWindow(const WindowDesc *desc) : QueryStringBaseWindow(desc)
|
||||
{
|
||||
ttd_strlcpy(this->edit_str_buf, _network_server_name, lengthof(this->edit_str_buf));
|
||||
ttd_strlcpy(this->edit_str_buf, _settings_client.network.server_name, lengthof(this->edit_str_buf));
|
||||
|
||||
_saveload_mode = SLD_NEW_GAME;
|
||||
BuildFileList();
|
||||
|
@ -676,7 +676,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
InitializeTextBuffer(&this->text, this->edit_str_buf, lengthof(this->edit_str_buf), 160);
|
||||
|
||||
this->field = NSSW_GAMENAME;
|
||||
_network_game_info.use_password = !StrEmpty(_network_server_password);
|
||||
_network_game_info.use_password = !StrEmpty(_settings_client.network.server_password);
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
|
||||
case NSSW_SETPWD: // Set password button
|
||||
this->widget_id = NSSW_SETPWD;
|
||||
ShowQueryString(BindCString(_network_server_password), STR_NETWORK_SET_PASSWORD, 20, 250, this, CS_ALPHANUMERAL);
|
||||
ShowQueryString(BindCString(_settings_client.network.server_password), STR_NETWORK_SET_PASSWORD, 20, 250, this, CS_ALPHANUMERAL);
|
||||
break;
|
||||
|
||||
case NSSW_SELMAP: { // Select map
|
||||
|
@ -862,7 +862,7 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
if (this->field == NSSW_GAMENAME) {
|
||||
if (this->HandleEditBoxKey(NSSW_GAMENAME, key, keycode, state) == 1) return state; // enter pressed
|
||||
|
||||
ttd_strlcpy(_network_server_name, this->text.buf, sizeof(_network_server_name));
|
||||
ttd_strlcpy(_settings_client.network.server_name, this->text.buf, sizeof(_settings_client.network.server_name));
|
||||
}
|
||||
|
||||
return state;
|
||||
|
@ -873,8 +873,8 @@ struct NetworkStartServerWindow : public QueryStringBaseWindow {
|
|||
if (str == NULL) return;
|
||||
|
||||
if (this->widget_id == NSSW_SETPWD) {
|
||||
ttd_strlcpy(_network_server_password, str, lengthof(_network_server_password));
|
||||
_network_game_info.use_password = !StrEmpty(_network_server_password);
|
||||
ttd_strlcpy(_settings_client.network.server_password, str, lengthof(_settings_client.network.server_password));
|
||||
_network_game_info.use_password = !StrEmpty(_settings_client.network.server_password);
|
||||
} else {
|
||||
int32 value = atoi(str);
|
||||
this->InvalidateWidget(this->widget_id);
|
||||
|
@ -1104,22 +1104,22 @@ struct NetworkLobbyWindow : public Window {
|
|||
case NLWW_JOIN: // Join company
|
||||
/* Button can be clicked only when it is enabled */
|
||||
_network_playas = this->company;
|
||||
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
break;
|
||||
|
||||
case NLWW_NEW: // New company
|
||||
_network_playas = PLAYER_NEW_COMPANY;
|
||||
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
break;
|
||||
|
||||
case NLWW_SPECTATE: // Spectate game
|
||||
_network_playas = PLAYER_SPECTATOR;
|
||||
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
break;
|
||||
|
||||
case NLWW_REFRESH: // Refresh
|
||||
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
|
||||
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
||||
NetworkTCPQueryServer(_settings_client.network.last_host, _settings_client.network.last_port); // company info
|
||||
NetworkUDPQueryServer(_settings_client.network.last_host, _settings_client.network.last_port); // general data
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1162,8 +1162,8 @@ static void ShowNetworkLobbyWindow(NetworkGameList *ngl)
|
|||
{
|
||||
DeleteWindowById(WC_NETWORK_WINDOW, 0);
|
||||
|
||||
NetworkTCPQueryServer(_network_last_host, _network_last_port); // company info
|
||||
NetworkUDPQueryServer(_network_last_host, _network_last_port); // general data
|
||||
NetworkTCPQueryServer(_settings_client.network.last_host, _settings_client.network.last_port); // company info
|
||||
NetworkUDPQueryServer(_settings_client.network.last_host, _settings_client.network.last_port); // general data
|
||||
|
||||
new NetworkLobbyWindow(&_network_lobby_window_desc, ngl);
|
||||
}
|
||||
|
@ -1894,7 +1894,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
|||
{
|
||||
this->parent = parent;
|
||||
this->afilter = CS_ALPHANUMERAL;
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, min(lengthof(_network_default_company_pass), lengthof(this->edit_str_buf)), 0);
|
||||
InitializeTextBuffer(&this->text, this->edit_str_buf, min(lengthof(_settings_client.network.default_company_pass), lengthof(this->edit_str_buf)), 0);
|
||||
|
||||
this->FindWindowPlacementAndResize(desc);
|
||||
}
|
||||
|
@ -1902,7 +1902,7 @@ struct NetworkCompanyPasswordWindow : public QueryStringBaseWindow {
|
|||
void OnOk()
|
||||
{
|
||||
if (this->IsWidgetLowered(NCPWW_SAVE_AS_DEFAULT_PASSWORD)) {
|
||||
snprintf(_network_default_company_pass, lengthof(_network_default_company_pass), "%s", this->edit_str_buf);
|
||||
snprintf(_settings_client.network.default_company_pass, lengthof(_settings_client.network.default_company_pass), "%s", this->edit_str_buf);
|
||||
}
|
||||
|
||||
/* empty password is a '*' because of console argument */
|
||||
|
|
|
@ -130,11 +130,7 @@ VARDEF NetworkGameInfo _network_game_info;
|
|||
VARDEF NetworkPlayerInfo _network_player_info[MAX_PLAYERS];
|
||||
VARDEF NetworkClientInfo _network_client_info[MAX_CLIENT_INFO];
|
||||
|
||||
VARDEF char _network_player_name[NETWORK_CLIENT_NAME_LENGTH];
|
||||
VARDEF char _network_default_ip[NETWORK_HOSTNAME_LENGTH];
|
||||
|
||||
VARDEF uint16 _network_own_client_index;
|
||||
VARDEF char _network_unique_id[NETWORK_UNIQUE_ID_LENGTH]; // Our own unique ID
|
||||
|
||||
VARDEF uint32 _frame_counter_server; // The frame_counter of the server, if in network-mode
|
||||
VARDEF uint32 _frame_counter_max; // To where we may go with our clients
|
||||
|
@ -144,26 +140,11 @@ VARDEF uint32 _last_sync_frame; // Used in the server to store the last time a s
|
|||
// networking settings
|
||||
VARDEF uint32 _broadcast_list[MAX_INTERFACES + 1];
|
||||
|
||||
VARDEF uint16 _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];
|
||||
VARDEF char _network_server_password[NETWORK_PASSWORD_LENGTH];
|
||||
VARDEF char _network_rcon_password[NETWORK_PASSWORD_LENGTH];
|
||||
VARDEF char _network_default_company_pass[NETWORK_PASSWORD_LENGTH];
|
||||
|
||||
VARDEF uint16 _network_max_join_time; ///< Time a client can max take to join
|
||||
VARDEF bool _network_pause_on_join; ///< Pause the game when a client tries to join (more chance of succeeding join)
|
||||
|
||||
VARDEF uint16 _redirect_console_to_client;
|
||||
|
||||
VARDEF uint16 _network_sync_freq;
|
||||
VARDEF uint8 _network_frame_freq;
|
||||
|
||||
VARDEF uint32 _sync_seed_1, _sync_seed_2;
|
||||
VARDEF uint32 _sync_frame;
|
||||
VARDEF bool _network_first_time;
|
||||
|
@ -173,27 +154,16 @@ VARDEF uint8 _network_join_waiting;
|
|||
VARDEF uint16 _network_join_kbytes;
|
||||
VARDEF uint16 _network_join_kbytes_total;
|
||||
|
||||
VARDEF char _network_last_host[NETWORK_HOSTNAME_LENGTH];
|
||||
VARDEF short _network_last_port;
|
||||
VARDEF uint32 _network_last_host_ip;
|
||||
VARDEF uint8 _network_reconnect;
|
||||
|
||||
VARDEF bool _network_udp_server;
|
||||
VARDEF uint16 _network_udp_broadcast;
|
||||
|
||||
VARDEF byte _network_lan_internet;
|
||||
|
||||
VARDEF bool _network_need_advertise;
|
||||
VARDEF uint32 _network_last_advertise_frame;
|
||||
VARDEF uint8 _network_advertise_retries;
|
||||
|
||||
VARDEF bool _network_autoclean_companies;
|
||||
VARDEF uint8 _network_autoclean_unprotected; // Remove a company after X months
|
||||
VARDEF uint8 _network_autoclean_protected; // Unprotect a company after X months
|
||||
|
||||
VARDEF Year _network_restart_game_year; // If this year is reached, the server automaticly restarts
|
||||
VARDEF uint8 _network_min_players; // Minimum number of players for game to unpause
|
||||
|
||||
void NetworkTCPQueryServer(const char* host, unsigned short port);
|
||||
|
||||
byte NetworkSpectatorCount();
|
||||
|
|
|
@ -230,7 +230,7 @@ DEF_SERVER_SEND_COMMAND_PARAM(PACKET_SERVER_NEED_PASSWORD)(NetworkTCPSocketHandl
|
|||
Packet *p = NetworkSend_Init(PACKET_SERVER_NEED_PASSWORD);
|
||||
p->Send_uint8(type);
|
||||
p->Send_uint32(_settings_game.game_creation.generation_seed);
|
||||
p->Send_string(_network_unique_id);
|
||||
p->Send_string(_settings_client.network.network_id);
|
||||
cs->Send_Packet(p);
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ DEF_SERVER_SEND_COMMAND(PACKET_SERVER_WELCOME)
|
|||
p = NetworkSend_Init(PACKET_SERVER_WELCOME);
|
||||
p->Send_uint16(cs->index);
|
||||
p->Send_uint32(_settings_game.game_creation.generation_seed);
|
||||
p->Send_string(_network_unique_id);
|
||||
p->Send_string(_settings_client.network.network_id);
|
||||
cs->Send_Packet(p);
|
||||
|
||||
// Transmit info about all the active clients
|
||||
|
@ -800,7 +800,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_MAP_OK)
|
|||
}
|
||||
}
|
||||
|
||||
if (_network_pause_on_join) {
|
||||
if (_settings_client.network.pause_on_join) {
|
||||
/* Now pause the game till the client is in sync */
|
||||
DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
|
||||
|
||||
|
@ -1021,7 +1021,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_ACK)
|
|||
/* Now he is! Unpause the game */
|
||||
cs->status = STATUS_ACTIVE;
|
||||
|
||||
if (_network_pause_on_join) {
|
||||
if (_settings_client.network.pause_on_join) {
|
||||
DoCommandP(0, 0, 0, NULL, CMD_PAUSE);
|
||||
NetworkServer_HandleChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_BROADCAST, 0, "Game unpaused (client connected)", NETWORK_SERVER_INDEX);
|
||||
}
|
||||
|
@ -1365,7 +1365,7 @@ void NetworkUpdateClientInfo(uint16 client_index)
|
|||
/* Check if we want to restart the map */
|
||||
static void NetworkCheckRestartMap()
|
||||
{
|
||||
if (_network_restart_game_year != 0 && _cur_year >= _network_restart_game_year) {
|
||||
if (_settings_client.network.restart_game_year != 0 && _cur_year >= _settings_client.network.restart_game_year) {
|
||||
DEBUG(net, 0, "Auto-restarting map. Year %d reached", _cur_year);
|
||||
|
||||
StartNewGameWithoutGUI(GENERATE_NEW_SEED);
|
||||
|
@ -1384,7 +1384,7 @@ static void NetworkAutoCleanCompanies()
|
|||
const Player *p;
|
||||
bool clients_in_company[MAX_PLAYERS];
|
||||
|
||||
if (!_network_autoclean_companies) return;
|
||||
if (!_settings_client.network.autoclean_companies) return;
|
||||
|
||||
memset(clients_in_company, 0, sizeof(clients_in_company));
|
||||
|
||||
|
@ -1409,13 +1409,13 @@ static void NetworkAutoCleanCompanies()
|
|||
_network_player_info[p->index].months_empty++;
|
||||
|
||||
/* Is the company empty for autoclean_unprotected-months, and is there no protection? */
|
||||
if (_network_player_info[p->index].months_empty > _network_autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') {
|
||||
if (_network_player_info[p->index].months_empty > _settings_client.network.autoclean_unprotected && _network_player_info[p->index].password[0] == '\0') {
|
||||
/* Shut the company down */
|
||||
DoCommandP(0, 2, p->index, NULL, CMD_PLAYER_CTRL);
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-cleaned company #%d", p->index + 1);
|
||||
}
|
||||
/* Is the compnay empty for autoclean_protected-months, and there is a protection? */
|
||||
if (_network_player_info[p->index].months_empty > _network_autoclean_protected && _network_player_info[p->index].password[0] != '\0') {
|
||||
if (_network_player_info[p->index].months_empty > _settings_client.network.autoclean_protected && _network_player_info[p->index].password[0] != '\0') {
|
||||
/* Unprotect the company */
|
||||
_network_player_info[p->index].password[0] = '\0';
|
||||
IConsolePrintF(CC_DEFAULT, "Auto-removed protection from company #%d", p->index+1);
|
||||
|
@ -1510,7 +1510,7 @@ void NetworkServer_Tick(bool send_frame)
|
|||
#endif
|
||||
|
||||
#ifndef ENABLE_NETWORK_SYNC_EVERY_FRAME
|
||||
if (_frame_counter >= _last_sync_frame + _network_sync_freq) {
|
||||
if (_frame_counter >= _last_sync_frame + _settings_client.network.sync_freq) {
|
||||
_last_sync_frame = _frame_counter;
|
||||
send_sync = true;
|
||||
}
|
||||
|
@ -1542,8 +1542,8 @@ void NetworkServer_Tick(bool send_frame)
|
|||
}
|
||||
} else if (cs->status == STATUS_PRE_ACTIVE) {
|
||||
int lag = NetworkCalculateLag(cs);
|
||||
if (lag > _network_max_join_time) {
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _network_max_join_time);
|
||||
if (lag > _settings_client.network.max_join_time) {
|
||||
IConsolePrintF(CC_ERROR,"Client #%d is dropped because it took longer than %d ticks for him to join", cs->index, _settings_client.network.max_join_time);
|
||||
NetworkCloseClient(cs);
|
||||
}
|
||||
} else if (cs->status == STATUS_INACTIVE) {
|
||||
|
|
|
@ -428,7 +428,7 @@ static void NetworkUDPBroadCast(NetworkUDPSocketHandler *socket)
|
|||
struct sockaddr_in out_addr;
|
||||
|
||||
out_addr.sin_family = AF_INET;
|
||||
out_addr.sin_port = htons(_network_server_port);
|
||||
out_addr.sin_port = htons(_settings_client.network.server_port);
|
||||
out_addr.sin_addr.s_addr = _broadcast_list[i];
|
||||
|
||||
DEBUG(net, 4, "[udp] broadcasting to %s", inet_ntoa(out_addr.sin_addr));
|
||||
|
@ -535,7 +535,7 @@ void NetworkUDPRemoveAdvertise()
|
|||
Packet p(PACKET_UDP_SERVER_UNREGISTER);
|
||||
/* Packet is: Version, server_port */
|
||||
p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
|
||||
p.Send_uint16(_network_server_port);
|
||||
p.Send_uint16(_settings_client.network.server_port);
|
||||
_udp_master_socket->SendPacket(&p, &out_addr);
|
||||
}
|
||||
|
||||
|
@ -584,7 +584,7 @@ void NetworkUDPAdvertise()
|
|||
/* Packet is: WELCOME_MESSAGE, Version, server_port */
|
||||
p.Send_string(NETWORK_MASTER_SERVER_WELCOME_MESSAGE);
|
||||
p.Send_uint8 (NETWORK_MASTER_SERVER_VERSION);
|
||||
p.Send_uint16(_network_server_port);
|
||||
p.Send_uint16(_settings_client.network.server_port);
|
||||
_udp_master_socket->SendPacket(&p, &out_addr);
|
||||
}
|
||||
|
||||
|
|
|
@ -485,8 +485,8 @@ int ttd_main(int argc, char *argv[])
|
|||
if (_cur_resolution[1] == 0) _cur_resolution[1] = 1;
|
||||
|
||||
#if defined(ENABLE_NETWORK)
|
||||
if (dedicated_host) snprintf(_network_server_bind_ip_host, NETWORK_HOSTNAME_LENGTH, "%s", dedicated_host);
|
||||
if (dedicated_port) _network_server_port = dedicated_port;
|
||||
if (dedicated_host) snprintf(_settings_client.network.server_bind_ip, sizeof(_settings_client.network.server_bind_ip), "%s", dedicated_host);
|
||||
if (dedicated_port) _settings_client.network.server_port = dedicated_port;
|
||||
if (_dedicated_forks && !dedicated) _dedicated_forks = false;
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
||||
|
@ -680,8 +680,8 @@ static void MakeNewGameDone()
|
|||
#ifdef ENABLE_NETWORK
|
||||
/* We are the server, we start a new player (not dedicated),
|
||||
* so set the default password *if* needed. */
|
||||
if (_network_server && !StrEmpty(_network_default_company_pass)) {
|
||||
char *password = _network_default_company_pass;
|
||||
if (_network_server && !StrEmpty(_settings_client.network.default_company_pass)) {
|
||||
char *password = _settings_client.network.default_company_pass;
|
||||
NetworkChangeCompanyPassword(1, &password);
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
@ -822,7 +822,7 @@ void SwitchMode(int new_mode)
|
|||
/* But not if we are going to the menu */
|
||||
if (new_mode != SM_MENU) {
|
||||
/* check if we should reload the config */
|
||||
if (_network_reload_cfg) {
|
||||
if (_settings_client.network.reload_cfg) {
|
||||
LoadFromConfig();
|
||||
_settings_game = _settings_newgame;
|
||||
ResetGRFConfig(false);
|
||||
|
@ -1102,7 +1102,7 @@ void GameLoop()
|
|||
if (_network_reconnect > 0 && --_network_reconnect == 0) {
|
||||
/* This means that we want to reconnect to the last host
|
||||
* We do this here, because it means that the network is really closed */
|
||||
NetworkClientConnectGame(_network_last_host, _network_last_port);
|
||||
NetworkClientConnectGame(_settings_client.network.last_host, _settings_client.network.last_port);
|
||||
}
|
||||
/* Singleplayer */
|
||||
StateGameLoop();
|
||||
|
|
|
@ -865,8 +865,8 @@ CommandCost CmdPlayerCtrl(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
assert(_local_player == PLAYER_SPECTATOR);
|
||||
SetLocalPlayer(p->index);
|
||||
#ifdef ENABLE_NETWORK
|
||||
if (!StrEmpty(_network_default_company_pass)) {
|
||||
char *password = _network_default_company_pass;
|
||||
if (!StrEmpty(_settings_client.network.default_company_pass)) {
|
||||
char *password = _settings_client.network.default_company_pass;
|
||||
NetworkChangeCompanyPassword(1, &password);
|
||||
}
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
|
|
@ -1501,33 +1501,33 @@ static const SettingDescGlobVarList _misc_settings[] = {
|
|||
|
||||
#ifdef ENABLE_NETWORK
|
||||
static const SettingDescGlobVarList _network_settings[] = {
|
||||
SDTG_VAR("sync_freq", SLE_UINT16,C|S,0, _network_sync_freq, 100, 0, 100, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("frame_freq", SLE_UINT8,C|S,0, _network_frame_freq, 0, 0, 100, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_join_time", SLE_UINT16, S, 0, _network_max_join_time, 500, 0, 32000, 0, STR_NULL, NULL),
|
||||
SDTG_BOOL("pause_on_join", S, 0, _network_pause_on_join, true, STR_NULL, NULL),
|
||||
SDTG_STR("server_bind_ip", SLE_STRB, S, 0, _network_server_bind_ip_host, "0.0.0.0", STR_NULL, NULL),
|
||||
SDTG_VAR("server_port", SLE_UINT16, S, 0, _network_server_port, NETWORK_DEFAULT_PORT, 0, 65535, 0, STR_NULL, NULL),
|
||||
SDTG_BOOL("server_advertise", S, 0, _network_advertise, false, STR_NULL, NULL),
|
||||
SDTG_VAR("lan_internet", SLE_UINT8, S, 0, _network_lan_internet, 0, 0, 1, 0, STR_NULL, NULL),
|
||||
SDTG_STR("player_name", SLE_STRB, S, 0, _network_player_name, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("server_password", SLE_STRB, S, 0, _network_server_password, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("rcon_password", SLE_STRB, S, 0, _network_rcon_password, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("default_company_pass", SLE_STRB, S, 0, _network_default_company_pass, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("server_name", SLE_STRB, S, 0, _network_server_name, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("connect_to_ip", SLE_STRB, S, 0, _network_default_ip, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("network_id", SLE_STRB, S, 0, _network_unique_id, NULL, STR_NULL, NULL),
|
||||
SDTG_BOOL("autoclean_companies", S, 0, _network_autoclean_companies, false, STR_NULL, NULL),
|
||||
SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _network_autoclean_unprotected,12, 0, 60, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("autoclean_protected", SLE_UINT8, S, 0, _network_autoclean_protected, 36, 0, 180, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_companies", SLE_UINT8, S, 0, _network_game_info.companies_max, 8, 1, MAX_PLAYERS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_clients", SLE_UINT8, S, 0, _network_game_info.clients_max, 10, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_spectators", SLE_UINT8, S, 0, _network_game_info.spectators_max, 10, 0, MAX_CLIENTS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("restart_game_year", SLE_INT32, S,D0, _network_restart_game_year, 0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL),
|
||||
SDTG_VAR("min_players", SLE_UINT8, S, 0, _network_min_players, 0, 0, 10, 0, STR_NULL, NULL),
|
||||
SDTG_OMANY("server_lang", SLE_UINT8, S, 0, _network_game_info.server_lang, 0, 35, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN", STR_NULL, NULL),
|
||||
SDTG_BOOL("reload_cfg", S, 0, _network_reload_cfg, false, STR_NULL, NULL),
|
||||
SDTG_STR("last_host", SLE_STRB, S, 0, _network_last_host, "0.0.0.0", STR_NULL, NULL),
|
||||
SDTG_VAR("last_port", SLE_UINT16, S, 0, _network_last_port, 0, 0, UINT16_MAX, 0, STR_NULL ,NULL),
|
||||
SDTG_VAR("sync_freq", SLE_UINT16,C|S,0, _settings_client.network.sync_freq, 100, 0, 100, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("frame_freq", SLE_UINT8,C|S,0, _settings_client.network.frame_freq, 0, 0, 100, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_join_time", SLE_UINT16, S, 0, _settings_client.network.max_join_time, 500, 0, 32000, 0, STR_NULL, NULL),
|
||||
SDTG_BOOL("pause_on_join", S, 0, _settings_client.network.pause_on_join, true, STR_NULL, NULL),
|
||||
SDTG_STR("server_bind_ip", SLE_STRB, S, 0, _settings_client.network.server_bind_ip, "0.0.0.0", STR_NULL, NULL),
|
||||
SDTG_VAR("server_port", SLE_UINT16, S, 0, _settings_client.network.server_port, NETWORK_DEFAULT_PORT, 0, 65535, 0, STR_NULL, NULL),
|
||||
SDTG_BOOL("server_advertise", S, 0, _settings_client.network.server_advertise, false, STR_NULL, NULL),
|
||||
SDTG_VAR("lan_internet", SLE_UINT8, S, 0, _settings_client.network.lan_internet, 0, 0, 1, 0, STR_NULL, NULL),
|
||||
SDTG_STR("player_name", SLE_STRB, S, 0, _settings_client.network.player_name, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("server_password", SLE_STRB, S, 0, _settings_client.network.server_password, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("rcon_password", SLE_STRB, S, 0, _settings_client.network.rcon_password, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("default_company_pass", SLE_STRB, S, 0, _settings_client.network.default_company_pass, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("server_name", SLE_STRB, S, 0, _settings_client.network.server_name, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("connect_to_ip", SLE_STRB, S, 0, _settings_client.network.connect_to_ip, NULL, STR_NULL, NULL),
|
||||
SDTG_STR("network_id", SLE_STRB, S, 0, _settings_client.network.network_id, NULL, STR_NULL, NULL),
|
||||
SDTG_BOOL("autoclean_companies", S, 0, _settings_client.network.autoclean_companies, false, STR_NULL, NULL),
|
||||
SDTG_VAR("autoclean_unprotected",SLE_UINT8, S, 0, _settings_client.network.autoclean_unprotected,12, 0, 60, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("autoclean_protected", SLE_UINT8, S, 0, _settings_client.network.autoclean_protected, 36, 0, 180, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_companies", SLE_UINT8, S, 0, _settings_client.network.max_companies, 8, 1, MAX_PLAYERS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_clients", SLE_UINT8, S, 0, _settings_client.network.max_clients, 10, 2, MAX_CLIENTS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("max_spectators", SLE_UINT8, S, 0, _settings_client.network.max_spectators, 10, 0, MAX_CLIENTS, 0, STR_NULL, NULL),
|
||||
SDTG_VAR("restart_game_year", SLE_INT32, S,D0, _settings_client.network.restart_game_year, 0, MIN_YEAR, MAX_YEAR, 1, STR_NULL, NULL),
|
||||
SDTG_VAR("min_players", SLE_UINT8, S, 0, _settings_client.network.min_players, 0, 0, 10, 0, STR_NULL, NULL),
|
||||
SDTG_OMANY("server_lang", SLE_UINT8, S, 0, _settings_client.network.server_lang, 0, 35, "ANY|ENGLISH|GERMAN|FRENCH|BRAZILIAN|BULGARIAN|CHINESE|CZECH|DANISH|DUTCH|ESPERANTO|FINNISH|HUNGARIAN|ICELANDIC|ITALIAN|JAPANESE|KOREAN|LITHUANIAN|NORWEGIAN|POLISH|PORTUGUESE|ROMANIAN|RUSSIAN|SLOVAK|SLOVENIAN|SPANISH|SWEDISH|TURKISH|UKRAINIAN|AFRIKAANS|CROATIAN|CATALAN|ESTONIAN|GALICIAN|GREEK|LATVIAN", STR_NULL, NULL),
|
||||
SDTG_BOOL("reload_cfg", S, 0, _settings_client.network.reload_cfg, false, STR_NULL, NULL),
|
||||
SDTG_STR("last_host", SLE_STRB, S, 0, _settings_client.network.last_host, "0.0.0.0", STR_NULL, NULL),
|
||||
SDTG_VAR("last_port", SLE_UINT16, S, 0, _settings_client.network.last_port, 0, 0, UINT16_MAX, 0, STR_NULL ,NULL),
|
||||
SDTG_END()
|
||||
};
|
||||
#endif /* ENABLE_NETWORK */
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "date_type.h"
|
||||
#include "town_type.h"
|
||||
#include "transport_type.h"
|
||||
#include "network/core/config.h"
|
||||
|
||||
/** Settings related to the difficulty of the game */
|
||||
struct DifficultySettings {
|
||||
|
@ -82,6 +83,40 @@ struct GUISettings {
|
|||
byte news_message_timeout; ///< how much longer than the news message "age" should we keep the message in the history
|
||||
};
|
||||
|
||||
/** All settings related to the network. */
|
||||
struct NetworkSettings {
|
||||
#ifdef ENABLE_NETWORK
|
||||
uint16 sync_freq;
|
||||
uint8 frame_freq;
|
||||
uint16 max_join_time;
|
||||
bool pause_on_join;
|
||||
char server_bind_ip[NETWORK_HOSTNAME_LENGTH];
|
||||
uint16 server_port;
|
||||
bool server_advertise;
|
||||
uint8 lan_internet;
|
||||
char player_name[NETWORK_NAME_LENGTH];
|
||||
char server_password[NETWORK_PASSWORD_LENGTH];
|
||||
char rcon_password[NETWORK_PASSWORD_LENGTH];
|
||||
char default_company_pass[NETWORK_PASSWORD_LENGTH];
|
||||
char server_name[NETWORK_NAME_LENGTH];
|
||||
char connect_to_ip[NETWORK_HOSTNAME_LENGTH];
|
||||
char network_id[NETWORK_UNIQUE_ID_LENGTH];
|
||||
bool autoclean_companies;
|
||||
uint8 autoclean_unprotected;
|
||||
uint8 autoclean_protected;
|
||||
uint8 max_companies;
|
||||
uint8 max_clients;
|
||||
uint8 max_spectators;
|
||||
Year restart_game_year;
|
||||
uint8 min_players;
|
||||
uint8 server_lang;
|
||||
bool reload_cfg;
|
||||
char last_host[NETWORK_HOSTNAME_LENGTH];
|
||||
uint16 last_port;
|
||||
#else /* ENABLE_NETWORK */
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Settings related to the creation of games. */
|
||||
struct GameCreationSettings {
|
||||
uint32 generation_seed; ///< noise seed for world generation
|
||||
|
@ -281,6 +316,7 @@ struct GameSettings {
|
|||
/** All settings that are only important for the local client. */
|
||||
struct ClientSettings {
|
||||
GUISettings gui; ///< settings related to the GUI
|
||||
NetworkSettings network; ///< settings related to the network
|
||||
};
|
||||
|
||||
/** The current settings for this game. */
|
||||
|
|
Loading…
Reference in New Issue