From 8755cca66f5a6743984dfd78b58f8c042103b6f7 Mon Sep 17 00:00:00 2001 From: neon <> Date: Fri, 27 Sep 2019 02:03:50 +0200 Subject: [PATCH] Knife Madness: add cvar restrictions --- .../scripting/UNLOZE_KnifeMadness.sp | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp b/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp index e35cedd8..5053285f 100644 --- a/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp +++ b/UNLOZE_KnifeMadness/scripting/UNLOZE_KnifeMadness.sp @@ -46,6 +46,9 @@ public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast g_bClientKnifed[client] = false; g_bSupressDeath[client] = false; + + if (!IsFakeClient(client)) + QueryClient(client); } //---------------------------------------------------------------------------------------------------- @@ -150,6 +153,78 @@ public Action KillZM(Handle timer, DataPack pack) hEvent.Fire(); } +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void QueryClient(int client) +{ + if (QueryClientConVar(client, "cl_updaterate", OnConVarQueryFinished, GetClientSerial(client)) == QUERYCOOKIE_FAILED) + LogError("Could not query ConVar \"cl_updaterate\" for %N", client); + + if (QueryClientConVar(client, "cl_cmdrate", OnConVarQueryFinished, GetClientSerial(client)) == QUERYCOOKIE_FAILED) + LogError("Could not query ConVar \"cl_cmdrate\" for %N", client); + + if (QueryClientConVar(client, "cl_lagcompensation", OnConVarQueryFinished, GetClientSerial(client)) == QUERYCOOKIE_FAILED) + LogError("Could not query ConVar \"cl_lagcompensation\" for %N", client); +} + +//---------------------------------------------------------------------------------------------------- +// Purpose: +//---------------------------------------------------------------------------------------------------- +public void OnConVarQueryFinished(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue, int iSerial) +{ + if (GetClientFromSerial(iSerial) != client) + return; + + if (result == ConVarQuery_NotFound) + { + LogError("Could not find ConVar \"cvarName\" for %N", client); + return; + } + + if (result == ConVarQuery_Okay) + { + float fValue = StringToFloat(cvarValue); + + if (StrEqual(cvarName, "cl_updaterate", false)) + { + if (!(20.0 <= fValue <= 130.0)) + { + LogAction(client, -1, "\"%L\" ConVar Violation: cl_updaterate (Value: %f)", client, fValue); + KickClient(client, "ConVar Violation: cl_updaterate must be set between 20 and 130"); + return; + } + } + else if (StrEqual(cvarName, "cl_cmdrate", false)) + { + if (!(20.0 <= fValue <= 130.0)) + { + LogAction(client, -1, "\"%L\" ConVar Violation: cl_cmdrate (Value: %f)", client, fValue); + KickClient(client, "ConVar Violation: cl_cmdrate must be set between 20 and 130"); + return; + } + } + else if (StrEqual(cvarName, "cl_lagcompensation", false)) + { + if (!fValue) + { + LogAction(client, -1, "\"%L\" ConVar Violation: cl_lagcompensation (Value: %f)", client, fValue); + KickClient(client, "ConVar Violation: cl_lagcompensation must be set to 1"); + return; + } + } + else if (StrEqual(cvarName, "cl_interp", false)) + { + if ((!(fValue >= 0.1)) && (fValue != 0.0)) + { + LogAction(client, -1, "\"%L\" ConVar Violation: cl_interp (Value: %f)", client, fValue); + KickClient(client, "ConVar Violation: cl_interp must not be lower than 0.1"); + return; + } + } + } +} + //---------------------------------------------------------------------------------------------------- // Purpose: //----------------------------------------------------------------------------------------------------