move anti-sv_cheats to own file

This commit is contained in:
rtldg 2021-10-08 10:30:52 +00:00
parent 611d0131c8
commit 77265805ac
2 changed files with 105 additions and 86 deletions

View File

@ -0,0 +1,100 @@
Convar gCV_DisableSvCheats = null;
#if !DEBUG
ConVar sv_cheats = null;
char gS_CheatCommands[][] = {
"ent_setpos",
"setpos",
"setpos_exact",
"setpos_player",
// can be used to kill other players
"explode",
"explodevector",
"kill",
"killvector",
"give",
};
#endif
void Anti_sv_cheats_cvars()
{
gCV_DisableSvCheats = new Convar("shavit_core_disable_sv_cheats", "1", "Force sv_cheats to 0.", 0, true, 0.0, true, 1.0);
#if !DEBUG
sv_cheats = FindConVar("sv_cheats");
sv_cheats.AddChangeHook(sv_cheats_hook);
for (int i = 0; i < sizeof(gS_CheatCommands); i++)
{
AddCommandListener(Command_Cheats, gS_CheatCommands[i]);
}
#endif
}
void Anti_sv_cheats_OnConfigsExecuted()
{
if (gCV_DisableSvCheats.BoolValue)
{
#if !DEBUG
sv_cheats.SetInt(0);
#endif
}
}
void Remove_sv_cheat_Impluses(int client, int &impulse)
{
#if !DEBUG
if (impulse && sv_cheats.BoolValue && !(GetUserFlagBits(client) & ADMFLAG_ROOT))
{
// Block cheat impulses
switch (impulse)
{
case 76, 81, 82, 83, 102, 195, 196, 197, 202, 203:
{
impulse = 0;
}
}
}
#endif
}
#if !DEBUG
public void sv_cheats_hook(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (gCV_DisableSvCheats.BoolValue)
{
sv_cheats.SetInt(0);
}
}
public Action Command_Cheats(int client, const char[] command, int args)
{
if (!sv_cheats.BoolValue || client == 0)
{
return Plugin_Continue;
}
if (StrContains(command, "kill") != -1 || StrContains(command, "explode") != -1)
{
bool bVector = StrContains(command, "vector") != -1;
bool bKillOther = args > (bVector ? 3 : 0);
if (!bKillOther)
{
return Plugin_Continue;
}
}
if (!(GetUserFlagBits(client) & ADMFLAG_ROOT))
{
return Plugin_Handled;
}
return Plugin_Continue;
}
#endif

View File

@ -122,7 +122,6 @@ Convar gCV_StaticPrestrafe = null;
Convar gCV_UseOffsets = null;
Convar gCV_TimeInMessages;
Convar gCV_DebugOffsets = null;
Convar gCV_DisableSvCheats = null;
// cached cvars
int gI_DefaultStyle = 0;
bool gB_StyleCookies = true;
@ -156,25 +155,7 @@ char gS_StyleOverride[STYLE_LIMIT][32];
// kz support
bool gB_KZMap = false;
#if !DEBUG
ConVar sv_cheats = null;
char gS_CheatCommands[][] = {
"ent_setpos",
"setpos",
"setpos_exact",
"setpos_player",
// can be used to kill other players
"explode",
"explodevector",
"kill",
"killvector",
"give",
};
#endif
#include <shavit/shavit-anti-sv_cheats.sp>
#include <shavit/shavit-core-style-settings.sp>
public Plugin myinfo =
@ -369,21 +350,12 @@ public void OnPluginStart()
gCV_StaticPrestrafe = new Convar("shavit_core_staticprestrafe", "1", "Force prestrafe for every pistol.\n250 is the default value and some styles will have 260.\n0 - Disabled\n1 - Enabled", 0, true, 0.0, true, 1.0);
gCV_TimeInMessages = new Convar("shavit_core_timeinmessages", "0", "Whether to prefix SayText2 messages with the time.", 0, true, 0.0, true, 1.0);
gCV_DebugOffsets = new Convar("shavit_core_debugoffsets", "0", "Print offset upon leaving or entering a zone?", 0, true, 0.0, true, 1.0);
gCV_DisableSvCheats = new Convar("shavit_core_disable_sv_cheats", "1", "Force sv_cheats to 0.", 0, true, 0.0, true, 1.0);
gCV_DefaultStyle.AddChangeHook(OnConVarChanged);
Anti_sv_cheats_cvars();
Convar.AutoExecConfig();
#if !DEBUG
sv_cheats = FindConVar("sv_cheats");
sv_cheats.AddChangeHook(sv_cheats_hook);
for (int i = 0; i < sizeof(gS_CheatCommands); i++)
{
AddCommandListener(Command_Cheats, gS_CheatCommands[i]);
}
#endif
sv_airaccelerate = FindConVar("sv_airaccelerate");
sv_airaccelerate.Flags &= ~(FCVAR_NOTIFY | FCVAR_REPLICATED);
@ -526,42 +498,6 @@ public void OnConVarChanged(ConVar convar, const char[] oldValue, const char[] n
gI_DefaultStyle = StringToInt(newValue[1]);
}
#if !DEBUG
public void sv_cheats_hook(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (gCV_DisableSvCheats.BoolValue)
{
sv_cheats.SetInt(0);
}
}
public Action Command_Cheats(int client, const char[] command, int args)
{
if (!sv_cheats.BoolValue || client == 0)
{
return Plugin_Continue;
}
if (StrContains(command, "kill") != -1 || StrContains(command, "explode") != -1)
{
bool bVector = StrContains(command, "vector") != -1;
bool bKillOther = args > (bVector ? 3 : 0);
if (!bKillOther)
{
return Plugin_Continue;
}
}
if (!(GetUserFlagBits(client) & ADMFLAG_ROOT))
{
return Plugin_Handled;
}
return Plugin_Continue;
}
#endif
public void OnLibraryAdded(const char[] name)
{
if(StrEqual(name, "shavit-zones"))
@ -645,12 +581,7 @@ public void OnMapStart()
public void OnConfigsExecuted()
{
if (gCV_DisableSvCheats.BoolValue)
{
#if !DEBUG
sv_cheats.SetInt(0);
#endif
}
Anti_sv_cheats_OnConfigsExecuted();
}
public void OnMapEnd()
@ -3255,19 +3186,7 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
return Plugin_Continue;
}
#if !DEBUG
if (impulse && sv_cheats.BoolValue && !(GetUserFlagBits(client) & ADMFLAG_ROOT))
{
// Block cheat impulses
switch (impulse)
{
case 76, 81, 82, 83, 102, 195, 196, 197, 202, 203:
{
impulse = 0;
}
}
}
#endif
Remove_sv_cheat_Impluses(client, impulse);
int flags = GetEntityFlags(client);