Skip to content

Commit

Permalink
Partical Fix for #15
Browse files Browse the repository at this point in the history
+Added File for checking Cvar existence to resolve #15
+Added an Selfcheck for not existing ConVars
*Fixed #15 for CSGO
*Simplyfied a Client Check
-Removed useless Note
  • Loading branch information
DJPlaya committed Nov 23, 2019
1 parent 9242abe commit c572ada
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 78 deletions.
60 changes: 60 additions & 0 deletions Cvar_Check_23.11.19.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
clear;
0penscript;
bat_version;
beetlesmod_version;
est_version;
eventscripts_ver;
fm_attackmode;
lua_open;
Lua-Engine;
mani_admin_plugin_version;
ManiAdminHacker;
ManiAdminTakeOver;
metamod_version;
openscript;
openscript_version;
runnscript;
SmAdminTakeover;
sourcemod_version;
tb_enabled;
zb_version;
sv_cheats;
sv_consistency;
sv_gravity;
r_drawothermodels;
cl_clock_correction;
cl_leveloverview;
cl_overdraw_test;
cl_particle_show_bbox;
cl_particles_show_bbox;
cl_phys_timescale;
cl_showevents;
fog_enable ;
host_timescale;
mat_dxlevel;
mat_fillrate;
mat_measurefillrate;
mat_proxy;
mat_showlowresimage;
mat_wireframe;
mem_force_flush;
snd_show;
snd_visualize;
r_aspectratio;
r_colorstaticprops;
r_DispWalkable;
r_DrawBeams;
r_drawbrushmodels;
r_drawclipbrushes;
r_drawdecals;
r_drawentities;
r_drawmodelstatsoverlay;
r_drawopaqueworld;
r_drawparticles;
r_drawrenderboxes;
r_drawskybox;
r_drawtranslucentworld;
r_shadowwireframe;
r_skybox;
r_visocclusion;
vcollide_wireframe
Binary file modified plugins/kigen-ac_redux.smx
Binary file not shown.
Binary file modified plugins/kigen-ac_redux_legacy.smx
Binary file not shown.
16 changes: 8 additions & 8 deletions scripting/1.10/kigen-ac_redux/commands.sp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Commands_OnPluginStart()
Commands_OnAllPluginsLoaded()
{
Handle f_hConCommand;
char f_sName[64];
char cConVar[64];
bool f_bIsCommand, f_iFlags;

g_hBlockedCmds = new StringMap(); // CreateTrie();
Expand Down Expand Up @@ -166,24 +166,24 @@ Commands_OnAllPluginsLoaded()
// Leaving this in as a fall back incase game isn't compatible with the command listener.
if (GetFeatureStatus(FeatureType_Capability, FEATURECAP_COMMANDLISTENER) != FeatureStatus_Available || !AddCommandListener(Commands_CommandListener))
{
f_hConCommand = FindFirstConCommand(f_sName, sizeof(f_sName), f_bIsCommand, f_iFlags);
f_hConCommand = FindFirstConCommand(cConVar, sizeof(cConVar), f_bIsCommand, f_iFlags);
if (f_hConCommand == INVALID_HANDLE)
SetFailState("Failed getting first ConCommand");

do
{
if (!f_bIsCommand || StrEqual(f_sName, "sm"))
if (!f_bIsCommand || StrEqual(cConVar, "sm"))
continue;

if (StrContains(f_sName, "es_") != -1 && !StrEqual(f_sName, "es_version"))
RegConsoleCmd(f_sName, Commands_ClientCheck);
if (StrContains(cConVar, "es_") != -1 && !StrEqual(cConVar, "es_version"))
RegConsoleCmd(cConVar, Commands_ClientCheck);

else
RegConsoleCmd(f_sName, Commands_SpamCheck);
RegConsoleCmd(cConVar, Commands_SpamCheck);

}

while (FindNextConCommand(f_hConCommand, f_sName, sizeof(f_sName), f_bIsCommand, f_iFlags));
while (FindNextConCommand(f_hConCommand, cConVar, sizeof(cConVar), f_bIsCommand, f_iFlags));

CloseHandle(f_hConCommand);
}
Expand Down Expand Up @@ -423,7 +423,7 @@ public Action Commands_BlockEntExploit(client, args)

public Action Commands_CommandListener(iClient, const char[] command, argc)
{
if (!iClient || iClient == -1)
if (iClient > 0)
return Plugin_Continue;

if (g_bIsFake[iClient]) // We could have added this in the first Check but the Client index can be -1 and wont match any entry in the array
Expand Down
114 changes: 83 additions & 31 deletions scripting/1.10/kigen-ac_redux/cvars.sp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool g_bCVarsEnabled = true;
CVars_OnPluginStart()
{
Handle f_hConCommand, f_hConVar;
char f_sName[64];
char cConVar[64];
bool f_bIsCommand;
int f_iFlags;

Expand Down Expand Up @@ -123,15 +123,21 @@ CVars_OnPluginStart()
CVars_AddCVar("cl_clock_correction", COMP_EQUAL, ACTION_BAN, "1.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("cl_leveloverview", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("cl_overdraw_test", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("cl_particle_show_bbox", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL); // cl_particles_show_bbox

if (hGame != Engine_CSGO)
CVars_AddCVar("cl_particle_show_bbox", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL);

else
CVars_AddCVar("cl_particles_show_bbox", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL);

CVars_AddCVar("cl_phys_timescale", COMP_EQUAL, ACTION_BAN, "1.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("cl_showevents", COMP_EQUAL, ACTION_BAN, "0.0", 0.0, PRIORITY_NORMAL);

if (hGame == Engine_Insurgency)
CVars_AddCVar("fog_enable", COMP_EQUAL, ACTION_KICK, "1.0", 0.0, PRIORITY_NORMAL);
if (hGame != Engine_Insurgency)
CVars_AddCVar("fog_enable", COMP_EQUAL, ACTION_BAN, "1.0", 0.0, PRIORITY_NORMAL);

else
CVars_AddCVar("fog_enable", COMP_EQUAL, ACTION_BAN, "1.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("fog_enable", COMP_EQUAL, ACTION_KICK, "1.0", 0.0, PRIORITY_NORMAL);

CVars_AddCVar("host_timescale", COMP_EQUAL, ACTION_BAN, "1.0", 0.0, PRIORITY_NORMAL);
CVars_AddCVar("mat_dxlevel", COMP_GREATER, ACTION_KICK, "80.0", 0.0, PRIORITY_NORMAL);
Expand Down Expand Up @@ -165,15 +171,15 @@ CVars_OnPluginStart()

//- Replication Protection -//

f_hConCommand = FindFirstConCommand(f_sName, sizeof(f_sName), f_bIsCommand, f_iFlags);
f_hConCommand = FindFirstConCommand(cConVar, sizeof(cConVar), f_bIsCommand, f_iFlags);
if (f_hConCommand == INVALID_HANDLE)
SetFailState("Failed getting first ConVar");

do
{
if (!f_bIsCommand && (f_iFlags & FCVAR_REPLICATED))
{
f_hConVar = FindConVar(f_sName);
f_hConVar = FindConVar(cConVar);
if (f_hConVar == INVALID_HANDLE)
continue;

Expand All @@ -182,7 +188,7 @@ CVars_OnPluginStart()
}
}

while (FindNextConCommand(f_hConCommand, f_sName, sizeof(f_sName), f_bIsCommand, f_iFlags));
while (FindNextConCommand(f_hConCommand, cConVar, sizeof(cConVar), f_bIsCommand, f_iFlags));

CloseHandle(f_hConCommand);

Expand Down Expand Up @@ -405,7 +411,7 @@ public Action CVars_PeriodicTimer(Handle timer, any client)
if (!g_bConnected[client])
return Plugin_Stop;

char f_sName[64];
char cConVar[64];
Handle f_hCVar;
int f_iIndex;

Expand All @@ -427,9 +433,9 @@ public Action CVars_PeriodicTimer(Handle timer, any client)

if (GetArrayCell(f_hCVar, CELL_CHANGED) == INVALID_HANDLE)
{
GetArrayString(f_hCVar, 0, f_sName, sizeof(f_sName));
GetArrayString(f_hCVar, 0, cConVar, sizeof(cConVar));
g_hCurrentQuery[client] = f_hCVar;
QueryClientConVar(client, f_sName, CVars_QueryCallback, client);
QueryClientConVar(client, cConVar, CVars_QueryCallback, client);
g_hReplyTimer[client] = CreateTimer(30.0, CVars_ReplyTimer, GetClientUserId(client)); // We'll wait 30 seconds for a reply.
}

Expand All @@ -454,7 +460,7 @@ public Action CVars_ReplyTimer(Handle timer, any userid)

else
{
char f_sName[64];
char cConVar[64];
Handle f_hCVar;

if (g_iSize < 1)
Expand All @@ -468,8 +474,8 @@ public Action CVars_ReplyTimer(Handle timer, any userid)

if (GetArrayCell(f_hCVar, CELL_CHANGED) == INVALID_HANDLE)
{
GetArrayString(f_hCVar, 0, f_sName, sizeof(f_sName));
QueryClientConVar(client, f_sName, CVars_QueryCallback, client);
GetArrayString(f_hCVar, 0, cConVar, sizeof(cConVar));
QueryClientConVar(client, cConVar, CVars_QueryCallback, client);
g_hReplyTimer[client] = CreateTimer(15.0, CVars_ReplyTimer, GetClientUserId(client)); // We'll wait 15 seconds for a reply.
}

Expand All @@ -482,10 +488,10 @@ public Action CVars_ReplyTimer(Handle timer, any userid)

public void CVars_ReplicateTimer(any f_hConVar)
{
char f_sName[64];
char cConVar[64];

GetConVarName(f_hConVar, f_sName, sizeof(f_sName));
if (g_bCVarsEnabled && StrEqual(f_sName, "sv_cheats") && GetConVarInt(f_hConVar) != 0)
GetConVarName(f_hConVar, cConVar, sizeof(cConVar));
if (g_bCVarsEnabled && StrEqual(cConVar, "sv_cheats") && GetConVarInt(f_hConVar) != 0)
SetConVarInt(f_hConVar, 0);

CVars_ReplicateConVar(f_hConVar);
Expand Down Expand Up @@ -617,6 +623,44 @@ public void CVars_QueryCallback(QueryCookie cookie, client, ConVarQueryResult re
return;
}

if(result == ConVarQuery_NotFound) // Selfcheck so we can prevent Problems with missing Vars
{
int iCvarExistence, iActuallyUsefull;
for (int iCount = 1; iCount <= MaxClients; iCount++)
if(g_hPeriodicTimer[iCount] != INVALID_HANDLE) // Client is definitly valid and can be queried
{
QueryClientConVar(iCount, cvarName, CVars_Selfcheck_QueryCallback, iCvarExistence); // TODO ADD check for "Not Found"
iActuallyUsefull++; // Better then checking the Contents of g_hPeriodicTimer
}

if(((iCvarExistence / iActuallyUsefull) * 100) < 80) // More then 80% dont have it
{
if(iActuallyUsefull < 8) // Real Clients, no Bots
{
//if(iActuallyUsefull > 2)
// Error, received "Not Found" from '%i' of '%i' Clients('%d%') using '%s', iCvarExistence, iActuallyUsefull, ((iCvarExistence / iActuallyUsefull) * 100, cvarName // TODO Report Back here#27

return;
}

else if(CVars_RemoveCVar(cvarName))
{
// Error, received "Not Found" from '%i' of '%i' Clients('%d%') using '%s', iCvarExistence, iActuallyUsefull, ((iCvarExistence / iActuallyUsefull) * 100, cvarName // TODO Report Back here#27
KACR_Log("[Error] ConVar '%s' was reported as not existing by '%i' of '%i' Clients('%d%'). Removed that CVar from the Active Checkerlist.", cvarName, iCvarExistence, iActuallyUsefull, ((iCvarExistence / iActuallyUsefull) * 100)); // TODO: add "and reported the Error"
}

else // Failed to remove
{
// Error, received "Not Found" from '%i' of '%i' Clients('%d%') using '%s' but removing this ConVar failed!, iCvarExistence, iActuallyUsefull, ((iCvarExistence / iActuallyUsefull) * 100, cvarName // TODO Report Back here#27
KACR_Log("[Error] ConVar '%s' was reported as not existing by '%i' of '%i' Clients('%d%'). Couldent remove this CVar from the Checkerlist.", cvarName, iCvarExistence, iActuallyUsefull, ((iCvarExistence / iActuallyUsefull) * 100)); // TODO: add "and reported the Error"
}

return;
}

return;
}

if (result != ConVarQuery_Okay) // ConVar should exist. // TODO: Add an CVar to decide
{
KACR_Log("Bad CVar Query Result: '%L'<%s> returned Query Result \"%s\" (expected Okay) on ConVar \"%s\" (Value \"%s\").", client, f_sIP, g_sQueryResult[result], cvarName, cvarValue);
Expand Down Expand Up @@ -858,15 +902,23 @@ public void CVars_QueryCallback(QueryCookie cookie, client, ConVarQueryResult re
g_hPeriodicTimer[client] = CreateTimer(GetRandomFloat(0.5, 2.0), CVars_PeriodicTimer, client);
}

public void CVars_Selfcheck_QueryCallback(QueryCookie hCookie, iClient, ConVarQueryResult hResult, const char[] cCvarName, const char[] cCvarValue, any iCvarExistence)
{
if (hResult != ConVarQuery_NotFound)
iCvarExistence++;

return;
}


//- Hook -//
//- Hooks -//

public void CVars_Replicate(Handle convar, const char[] oldvalue, const char[] newvalue)
{
Handle f_hCVarIndex, f_hTimer;
char f_sName[64];
GetConVarName(convar, f_sName, sizeof(f_sName));
if (g_hCVarIndex.GetValue(f_sName, f_hCVarIndex))
char cConVar[64];
GetConVarName(convar, cConVar, sizeof(cConVar));
if (g_hCVarIndex.GetValue(cConVar, f_hCVarIndex))
{
f_hTimer = GetArrayCell(f_hCVarIndex, CELL_CHANGED);
if (f_hTimer != INVALID_HANDLE)
Expand Down Expand Up @@ -903,20 +955,20 @@ public void CVars_EnableChange(Handle convar, const char[] oldValue, const char[
* @param iImportance Priority (PRIORITY_...)
* @param cAlternative URL to show to the Player
*/
bool CVars_AddCVar(char[] f_sName, f_iComparisonType, f_iAction, const char[] f_sValue, float f_fValue2, f_iImportance, const char f_sAlternative[] = "")
bool CVars_AddCVar(char[] cConVar, f_iComparisonType, f_iAction, const char[] f_sValue, float f_fValue2, f_iImportance, const char f_sAlternative[] = "")
{
Handle f_hConVar = INVALID_HANDLE, f_hArray;

f_hConVar = FindConVar(f_sName);
f_hConVar = FindConVar(cConVar);
if (f_hConVar != INVALID_HANDLE && (GetConVarFlags(f_hConVar) & FCVAR_REPLICATED) && (f_iComparisonType == COMP_EQUAL || f_iComparisonType == COMP_STRING))
f_iComparisonType = COMP_EQUAL;

else
f_hConVar = INVALID_HANDLE;

if (g_hCVarIndex.GetValue(f_sName, f_hArray)) // Check if CVar check already exists.
if (g_hCVarIndex.GetValue(cConVar, f_hArray)) // Check if CVar check already exists.
{
SetArrayString(f_hArray, CELL_NAME, f_sName); // Name 0
SetArrayString(f_hArray, CELL_NAME, cConVar); // Name 0
SetArrayCell(f_hArray, CELL_COMPTYPE, f_iComparisonType); // Comparison Type 1
SetArrayCell(f_hArray, CELL_HANDLE, f_hConVar); // CVar Handle 2
SetArrayCell(f_hArray, CELL_ACTION, f_iAction); // Action Type 3
Expand All @@ -930,7 +982,7 @@ bool CVars_AddCVar(char[] f_sName, f_iComparisonType, f_iAction, const char[] f_
else
{
f_hArray = CreateArray(64);
PushArrayString(f_hArray, f_sName); // Name 0
PushArrayString(f_hArray, cConVar); // Name 0
PushArrayCell(f_hArray, f_iComparisonType); // Comparison Type 1
PushArrayCell(f_hArray, f_hConVar); // CVar Handle 2
PushArrayCell(f_hArray, f_iAction); // Action Type 3
Expand All @@ -940,10 +992,10 @@ bool CVars_AddCVar(char[] f_sName, f_iComparisonType, f_iAction, const char[] f_
PushArrayCell(f_hArray, f_iImportance); // Importance 7
PushArrayCell(f_hArray, INVALID_HANDLE); // Changed 8

if (!g_hCVarIndex.SetValue(f_sName, f_hArray))
if (!g_hCVarIndex.SetValue(cConVar, f_hArray))
{
CloseHandle(f_hArray);
KACR_Log("Unable to add ConVar to Trie Link List '%s'", f_sName);
KACR_Log("Unable to add ConVar to Trie Link List '%s'", cConVar);
return false;
}

Expand All @@ -957,12 +1009,12 @@ bool CVars_AddCVar(char[] f_sName, f_iComparisonType, f_iAction, const char[] f_
return true;
}

stock bool CVars_RemoveCVar(char[] f_sName)
stock bool CVars_RemoveCVar(const char[] cConVar)
{
Handle f_hConVar;
int f_iIndex;

if (!g_hCVarIndex.GetValue(f_sName, f_hConVar))
if (!g_hCVarIndex.GetValue(cConVar, f_hConVar))
return false;

f_iIndex = FindValueInArray(g_hCVars, f_hConVar);
Expand All @@ -974,7 +1026,7 @@ stock bool CVars_RemoveCVar(char[] f_sName)
g_hCurrentQuery[i] = INVALID_HANDLE;

RemoveFromArray(g_hCVars, f_iIndex);
g_hCVarIndex.Remove(f_sName);
g_hCVarIndex.Remove(cConVar);
CloseHandle(f_hConVar);
g_iSize = GetArraySize(g_hCVars);

Expand Down
Loading

0 comments on commit c572ada

Please sign in to comment.