[Dvars] Add flag to protect archive dvars

This commit is contained in:
Diavolo 2022-06-26 14:58:45 +02:00
parent 9cf686f5b2
commit 998c221d80
No known key found for this signature in database
GPG Key ID: FA77F074E98D98A5
3 changed files with 23 additions and 0 deletions

View File

@ -42,6 +42,7 @@
| `-version` | Print IW4x build info on startup. |
| `-zonebuilder` | Start the interactive zonebuilder tool console instead of starting the game. |
| `-nosteam` | Disable friends feature and do not update Steam about the game's current status just like an invisible mode. |
| `-protect-saved-dvars` | Block the server from modifying saved/archive dvars. |
## Disclaimer

View File

@ -283,6 +283,18 @@ namespace Components
Game::Dvar_SetFromStringByNameFromSource(dvarName, string, Game::DvarSetSource::DVAR_SOURCE_EXTERNAL);
}
bool Dvar::AreArchiveDvarsProtected()
{
static std::optional<bool> flag;
if (!flag.has_value())
{
flag.emplace(Flags::HasFlag("protect-saved-dvars"));
}
return flag.value();
}
void Dvar::SaveArchiveDvar(const Game::dvar_t* var)
{
if (!Utils::IO::FileExists(Dvar::ArchiveDvarPath))
@ -301,6 +313,15 @@ namespace Components
const auto* dvar = Game::Dvar_FindVar(dvarName);
if (dvar != nullptr && dvar->flags & Game::dvar_flag::DVAR_ARCHIVE)
{
if (Dvar::AreArchiveDvarsProtected())
{
Logger::Print(Game::CON_CHANNEL_CONSOLEONLY, "Not allowing server to override saved dvar '{}'\n", dvarName);
return;
}
#ifdef DEBUG_DVARS
Logger::Print(Game::CON_CHANNEL_CONSOLEONLY, "Server is overriding saved dvar '{}'\n", dvarName);
#endif
Dvar::SaveArchiveDvar(dvar);
}

View File

@ -57,6 +57,7 @@ namespace Components
static void SetFromStringByNameExternal(const char* dvar, const char* value);
static void SetFromStringByNameSafeExternal(const char* dvar, const char* value);
static bool AreArchiveDvarsProtected();
static void SaveArchiveDvar(const Game::dvar_t* var);
static void DvarSetFromStringByNameStub(const char* dvarName, const char* value);
};