|
|
|
@ -33,6 +33,7 @@
|
|
|
|
|
#include "../timer/timer.h"
|
|
|
|
|
#include "../timer/timer_game_calendar.h"
|
|
|
|
|
#include "../timer/timer_game_economy.h"
|
|
|
|
|
#include "../timer/timer_game_realtime.h"
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <condition_variable>
|
|
|
|
|
|
|
|
|
@ -1491,29 +1492,6 @@ void NetworkUpdateClientInfo(ClientID client_id)
|
|
|
|
|
NetworkAdminClientUpdate(ci);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Check if we want to restart the map */
|
|
|
|
|
static void NetworkCheckRestartMap()
|
|
|
|
|
{
|
|
|
|
|
if (_settings_client.network.restart_game_year != 0 && TimerGameCalendar::year >= _settings_client.network.restart_game_year) {
|
|
|
|
|
Debug(net, 3, "Auto-restarting map: year {} reached", TimerGameCalendar::year);
|
|
|
|
|
|
|
|
|
|
_settings_newgame.game_creation.generation_seed = GENERATE_NEW_SEED;
|
|
|
|
|
switch(_file_to_saveload.abstract_ftype) {
|
|
|
|
|
case FT_SAVEGAME:
|
|
|
|
|
case FT_SCENARIO:
|
|
|
|
|
_switch_mode = SM_LOAD_GAME;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FT_HEIGHTMAP:
|
|
|
|
|
_switch_mode = SM_START_HEIGHTMAP;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
_switch_mode = SM_NEWGAME;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Check if the server has autoclean_companies activated
|
|
|
|
|
* Two things happen:
|
|
|
|
|
* 1) If a company is not protected, it is closed after 1 year (for example)
|
|
|
|
@ -1811,11 +1789,65 @@ void NetworkServer_Tick(bool send_frame)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Helper function to restart the map. */
|
|
|
|
|
static void NetworkRestartMap()
|
|
|
|
|
{
|
|
|
|
|
_settings_newgame.game_creation.generation_seed = GENERATE_NEW_SEED;
|
|
|
|
|
switch (_file_to_saveload.abstract_ftype) {
|
|
|
|
|
case FT_SAVEGAME:
|
|
|
|
|
case FT_SCENARIO:
|
|
|
|
|
_switch_mode = SM_LOAD_GAME;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FT_HEIGHTMAP:
|
|
|
|
|
_switch_mode = SM_START_HEIGHTMAP;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
_switch_mode = SM_NEWGAME;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Timer to restart a network server automatically based on real-time hours played. Initialized at zero to disable until settings are loaded. */
|
|
|
|
|
static IntervalTimer<TimerGameRealtime> _network_restart_map_timer({std::chrono::hours::zero(), TimerGameRealtime::UNPAUSED}, [](auto)
|
|
|
|
|
{
|
|
|
|
|
if (!_network_server) return;
|
|
|
|
|
|
|
|
|
|
/* If setting is 0, this feature is disabled. */
|
|
|
|
|
if (_settings_client.network.restart_hours == 0) return;
|
|
|
|
|
|
|
|
|
|
Debug(net, 3, "Auto-restarting map: {} hours played", _settings_client.network.restart_hours);
|
|
|
|
|
NetworkRestartMap();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Reset the automatic network restart time interval.
|
|
|
|
|
* @param reset Whether to reset the timer to zero.
|
|
|
|
|
*/
|
|
|
|
|
void ChangeNetworkRestartTime(bool reset)
|
|
|
|
|
{
|
|
|
|
|
if (!_network_server) return;
|
|
|
|
|
|
|
|
|
|
_network_restart_map_timer.SetInterval({ std::chrono::hours(_settings_client.network.restart_hours), TimerGameRealtime::UNPAUSED }, reset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Check if we want to restart the map based on the year. */
|
|
|
|
|
static void NetworkCheckRestartMapYear()
|
|
|
|
|
{
|
|
|
|
|
/* If setting is 0, this feature is disabled. */
|
|
|
|
|
if (_settings_client.network.restart_game_year == 0) return;
|
|
|
|
|
|
|
|
|
|
if (TimerGameCalendar::year >= _settings_client.network.restart_game_year) {
|
|
|
|
|
Debug(net, 3, "Auto-restarting map: year {} reached", TimerGameCalendar::year);
|
|
|
|
|
NetworkRestartMap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Calendar yearly "callback". Called whenever the calendar year changes. */
|
|
|
|
|
static IntervalTimer<TimerGameCalendar> _calendar_network_yearly({ TimerGameCalendar::YEAR, TimerGameCalendar::Priority::NONE }, [](auto) {
|
|
|
|
|
if (!_network_server) return;
|
|
|
|
|
|
|
|
|
|
NetworkCheckRestartMap();
|
|
|
|
|
NetworkCheckRestartMapYear();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/** Economy yearly "callback". Called whenever the economy year changes. */
|
|
|
|
|