[Dvars] Add flag to protect archive dvars
This commit is contained in:
parent
9cf686f5b2
commit
998c221d80
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user