Add ConVar to auto-reload the server after x seconds.

This should allow users to host dedicated servers without looking back, as you should reload/restart a server every 3 hours (a full process restart is the most recommended option, but a 'soft' reload works like a charm most of the time).
This commit is contained in:
Kawe Mazidjatari 2022-09-15 01:37:45 +02:00
parent 9dd49af1dc
commit d9ddb575e2
5 changed files with 17 additions and 0 deletions

View File

@ -216,6 +216,7 @@ FORCEINLINE void CHostState::Think(void) const
static bool bInitialized = false;
static CFastTimer banListTimer;
static CFastTimer pylonTimer;
static CFastTimer reloadTimer;
static CFastTimer statsTimer;
if (!bInitialized) // Initialize clocks.
@ -226,6 +227,7 @@ FORCEINLINE void CHostState::Think(void) const
pylonTimer.Start();
#endif // DEDICATED
statsTimer.Start();
reloadTimer.Start();
#endif // !CLIENT_DLL
bInitialized = true;
}
@ -263,6 +265,14 @@ FORCEINLINE void CHostState::Think(void) const
}
#endif // DEDICATED
#ifndef CLIENT_DLL
if (sv_autoReloadRate->GetBool())
{
if (reloadTimer.GetDurationInProgress().GetSeconds() > sv_autoReloadRate->GetDouble())
{
Cbuf_AddText(Cbuf_GetCurrentPlayer(), "reload\n", cmd_source_t::kCommandSrcCode);
reloadTimer.Start();
}
}
if (statsTimer.GetDurationInProgress().GetSeconds() > sv_statusRefreshInterval->GetDouble())
{
string svCurrentPlaylist = KeyValues_GetCurrentPlaylist();

View File

@ -104,6 +104,8 @@ void ConVar::Init(void) const
sv_pylonRefreshInterval = ConVar::Create("sv_pylonRefreshInterval" , "5.0", FCVAR_RELEASE, "Pylon server host request post update interval (seconds).", true, 2.f, true, 8.f, nullptr, nullptr);
sv_banlistRefreshInterval = ConVar::Create("sv_banlistRefreshInterval", "1.0", FCVAR_RELEASE, "Banlist refresh interval (seconds).", true, 1.f, false, 0.f, nullptr, nullptr);
sv_statusRefreshInterval = ConVar::Create("sv_statusRefreshInterval" , "0.5", FCVAR_RELEASE, "Server status bar update interval (seconds).", false, 0.f, false, 0.f, nullptr, nullptr);
sv_autoReloadRate = ConVar::Create("sv_autoReloadRate" , "0", FCVAR_RELEASE, "Time in seconds between each server auto-reload (disabled if null). ", true, 0.f, false, 0.f, nullptr, nullptr);
#ifdef DEDICATED
sv_rcon_debug = ConVar::Create("sv_rcon_debug" , "0" , FCVAR_RELEASE, "Show rcon debug information ( !slower! ).", false, 0.f, false, 0.f, nullptr, nullptr);
sv_rcon_sendlogs = ConVar::Create("sv_rcon_sendlogs" , "0" , FCVAR_RELEASE, "Network console logs to connected and authenticated sockets.", false, 0.f, false, 0.f, nullptr, nullptr);

View File

@ -421,6 +421,7 @@ void ConCommand::InitShipped(void)
"launchplaylist",
"quit",
"exit",
"reload",
"restart",
"status",
"version",

View File

@ -67,6 +67,8 @@ ConVar* sv_pylonRefreshInterval = nullptr;
ConVar* sv_banlistRefreshInterval = nullptr;
ConVar* sv_statusRefreshInterval = nullptr;
ConVar* sv_autoReloadRate = nullptr;
#ifdef DEDICATED
ConVar* sv_rcon_debug = nullptr;
ConVar* sv_rcon_sendlogs = nullptr;

View File

@ -63,6 +63,8 @@ extern ConVar* sv_pylonRefreshInterval;
extern ConVar* sv_banlistRefreshInterval;
extern ConVar* sv_statusRefreshInterval;
extern ConVar* sv_autoReloadRate;
#ifdef DEDICATED
extern ConVar* sv_rcon_debug;
extern ConVar* sv_rcon_sendlogs;