Knife Madness: add cvar restrictions

This commit is contained in:
neon 2019-09-27 02:03:50 +02:00
parent ee087d6b6f
commit 8755cca66f

View File

@ -46,6 +46,9 @@ public void OnClientSpawn(Event hEvent, const char[] sEvent, bool bDontBroadcast
g_bClientKnifed[client] = false; g_bClientKnifed[client] = false;
g_bSupressDeath[client] = false; g_bSupressDeath[client] = false;
if (!IsFakeClient(client))
QueryClient(client);
} }
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
@ -150,6 +153,78 @@ public Action KillZM(Handle timer, DataPack pack)
hEvent.Fire(); 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: // Purpose:
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------