AntiBhopCheat: fix logging to discord

This commit is contained in:
BotoX 2019-08-11 15:06:30 +02:00
parent 23100c4475
commit 75404ef3f5

View File

@ -23,8 +23,6 @@ CPlayer g_aPlayers[MAXPLAYERS + 1];
// Api // Api
Handle g_hOnClientDetected; Handle g_hOnClientDetected;
char g_sStats[4096];
public Plugin myinfo = public Plugin myinfo =
{ {
name = "AntiBhopCheat", name = "AntiBhopCheat",
@ -312,7 +310,7 @@ void CheckStats(CPlayer Player, CStreak Streak)
if(iStreakJumps >= 6) if(iStreakJumps >= 6)
{ {
float HackRatio = Streak.iHackJumps / float(iStreakJumps); float HackRatio = Streak.iHackJumps / float(iStreakJumps);
if(HackRatio >= 0.85) if(HackRatio >= 0.80)
{ {
Player.iHackFlagged += 1; Player.iHackFlagged += 1;
char sBuffer[32]; char sBuffer[32];
@ -321,7 +319,7 @@ void CheckStats(CPlayer Player, CStreak Streak)
} }
float HyperRatio = Streak.iHyperJumps / float(iStreakJumps); float HyperRatio = Streak.iHyperJumps / float(iStreakJumps);
if(HyperRatio >= 0.85) if(HyperRatio >= 0.80)
{ {
Player.iHyperFlagged += 1; Player.iHyperFlagged += 1;
CPrintToChat(client, "{green}[SM]{default} Turn off your bhop macro/script or hyperscroll!"); CPrintToChat(client, "{green}[SM]{default} Turn off your bhop macro/script or hyperscroll!");
@ -370,13 +368,19 @@ NotifyAdmins(int client, const char[] sReason)
{ {
if(IsClientInGame(i) && !IsFakeClient(i) && CheckCommandAccess(i, "sm_stats", ADMFLAG_GENERIC)) if(IsClientInGame(i) && !IsFakeClient(i) && CheckCommandAccess(i, "sm_stats", ADMFLAG_GENERIC))
{ {
CPrintToChat(i, "{green}[SM]{default} %L has been detected for {red}%s{default}, please check your console!", client, sReason) CPrintToChat(i, "{green}[SM]{default} %L has been detected for {red}%s{default}, please check your console!", client, sReason);
PrintStats(i, client); FormatStats(i, client);
PrintStreak(i, client, -1, true); PrintToConsole(client, "%s", "\n");
FormatStreak(i, client, 0);
} }
} }
Forward_OnDetected(client, sReason, g_sStats) char sBuffer[2000];
int len = FormatStats(-1, client, sBuffer, sizeof(sBuffer));
sBuffer[len++] = '\n';
len += FormatStreak(-1, client, 0, sBuffer[len], sizeof(sBuffer) - len);
Forward_OnDetected(client, sReason, sBuffer);
} }
public Action Command_Stats(int client, int argc) public Action Command_Stats(int client, int argc)
@ -403,51 +407,19 @@ public Action Command_Stats(int client, int argc)
for(int i = 0; i < iTargetCount; i++) for(int i = 0; i < iTargetCount; i++)
{ {
PrintStats(client, iTargets[i]); FormatStats(client, iTargets[i]);
PrintToConsole(client, "%s", "\n");
for(int j = 0; j < 3; j++)
{
FormatStreak(client, iTargets[i], j);
PrintToConsole(client, "%s", "\n");
}
} }
return Plugin_Handled; return Plugin_Handled;
} }
void PrintStats(int client, int iTarget)
{
PrintToConsole(client, "[SM] Bunnyhop stats for %L", iTarget);
CPlayer Player = g_aPlayers[iTarget];
ArrayList hStreaks = Player.hStreaks;
CStreak hStreak = Player.hStreak;
int iStreaks = hStreaks.Length;
// Try showing latest valid streak
if(!hStreak.bValid)
{
if(iStreaks)
hStreak = hStreaks.Get(iStreaks - 1);
}
int iGlobalJumps = Player.iJumps;
float HyperRatio = Player.iHyperJumps / float(iGlobalJumps);
float HackRatio = Player.iHackJumps / float(iGlobalJumps);
PrintToConsole(client, "Global jumps: %d | Hyper?: %.1f%% | Hack?: %.1f%%",
iGlobalJumps, HyperRatio * 100.0, HackRatio * 100.0);
PrintToConsole(client, "bHackGlobal: %d | bHyperGlobal: %d | iHackFlagged: %d | iHyperFlagged: %d",
Player.bHackGlobal, Player.bHyperGlobal, Player.iHackFlagged, Player.iHyperFlagged);
int aGlobalJumps[3];
Player.GetJumps(aGlobalJumps);
PrintToConsole(client, "Global jumps perf group (1 2 +): %1.f%% %1.f%% %1.f%%",
(aGlobalJumps[0] / float(iGlobalJumps)) * 100.0,
(aGlobalJumps[1] / float(iGlobalJumps)) * 100.0,
(aGlobalJumps[2] / float(iGlobalJumps)) * 100.0);
PrintStreak(client, iTarget, 0);
PrintStreak(client, iTarget, 1);
PrintStreak(client, iTarget, 2);
}
public Action Command_Streak(int client, int argc) public Action Command_Streak(int client, int argc)
{ {
if(argc < 1 || argc > 2) if(argc < 1 || argc > 2)
@ -480,21 +452,42 @@ public Action Command_Streak(int client, int argc)
for(int i = 0; i < iTargetCount; i++) for(int i = 0; i < iTargetCount; i++)
{ {
PrintStreak(client, iTargets[i], iStreak); FormatStreak(client, iTargets[i], iStreak);
} }
return Plugin_Handled; return Plugin_Handled;
} }
void PrintStreak(int client, int iTarget, int iStreak, bool bDetected=false) int FormatStats(int client, int iTarget, char[] sBuf=0, int len=0)
{ {
g_sStats = ""; int iBuf = ConsoleFormat(client, sBuf, len, "[SM] Bunnyhop stats for %L\n", iTarget);
PrintToConsole(client, "[SM] Bunnyhop streak %d for %L", iStreak, iTarget); CPlayer Player = g_aPlayers[iTarget];
if (bDetected) int iGlobalJumps = Player.iJumps;
Format(g_sStats, sizeof(g_sStats), "%sBunnyhop streak %d for %L\n", float HyperRatio = Player.iHyperJumps / float(iGlobalJumps);
g_sStats, iStreak, iTarget); float HackRatio = Player.iHackJumps / float(iGlobalJumps);
iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "Global jumps: %d | Hyper?: %.1f%% | Hack?: %.1f%%\n",
iGlobalJumps, HyperRatio * 100.0, HackRatio * 100.0);
iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "bHackGlobal: %d | bHyperGlobal: %d | iHackFlagged: %d | iHyperFlagged: %d\n",
Player.bHackGlobal, Player.bHyperGlobal, Player.iHackFlagged, Player.iHyperFlagged);
int aGlobalJumps[3];
Player.GetJumps(aGlobalJumps);
iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "Global jumps perf group (1 2 +): %1.f%% %1.f%% %1.f%%\n",
(aGlobalJumps[0] / float(iGlobalJumps)) * 100.0,
(aGlobalJumps[1] / float(iGlobalJumps)) * 100.0,
(aGlobalJumps[2] / float(iGlobalJumps)) * 100.0);
return iBuf;
}
int FormatStreak(int client, int iTarget, int iStreak, char[] sBuf=0, int len=0)
{
int iBuf = ConsoleFormat(client, sBuf, len, "[SM] Bunnyhop streak %d for %L\n", iStreak, iTarget);
CPlayer Player = g_aPlayers[iTarget]; CPlayer Player = g_aPlayers[iTarget];
ArrayList hStreaks = Player.hStreaks; ArrayList hStreaks = Player.hStreaks;
@ -511,15 +504,15 @@ void PrintStreak(int client, int iTarget, int iStreak, bool bDetected=false)
{ {
if(iStreak > MAX_STREAKS) if(iStreak > MAX_STREAKS)
{ {
ReplyToCommand(client, "[SM] Streak is out of bounds (max. %d)!", MAX_STREAKS); iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "[SM] Streak is out of bounds (max. %d)!\n", MAX_STREAKS);
return; return iBuf;
} }
int iIndex = iStreaks - iStreak; int iIndex = iStreaks - iStreak;
if(iIndex < 0) if(iIndex < 0)
{ {
ReplyToCommand(client, "[SM] Only %d streaks are available for this player right now!", iStreaks); iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "[SM] Only %d streaks are available for this player right now!\n", iStreaks);
return; return iBuf;
} }
hStreak = hStreaks.Get(iIndex); hStreak = hStreaks.Get(iIndex);
@ -529,35 +522,20 @@ void PrintStreak(int client, int iTarget, int iStreak, bool bDetected=false)
float HyperRatio = hStreak.iHyperJumps / float(iStreakJumps); float HyperRatio = hStreak.iHyperJumps / float(iStreakJumps);
float HackRatio = hStreak.iHackJumps / float(iStreakJumps); float HackRatio = hStreak.iHackJumps / float(iStreakJumps);
PrintToConsole(client, "Streak jumps: %d | Hyper?: %.1f%% | Hack?: %.1f%%", iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "Streak jumps: %d | Hyper?: %.1f%% | Hack?: %.1f%%\n",
iStreakJumps, HyperRatio * 100.0, HackRatio * 100.0); iStreakJumps, HyperRatio * 100.0, HackRatio * 100.0);
if (bDetected)
Format(g_sStats, sizeof(g_sStats), "%sStreak jumps: %d | Hyper?: %.1f%% | Hack?: %.1f%%\n",
g_sStats, iStreakJumps, HyperRatio * 100.0, HackRatio * 100.0);
int aStreakJumps[3]; int aStreakJumps[3];
hStreak.GetJumps(aStreakJumps); hStreak.GetJumps(aStreakJumps);
PrintToConsole(client, "Streak jumps perf group (1 2 +): %1.f%% %1.f%% %1.f%%", iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "Streak jumps perf group (1 2 +): %1.f%% %1.f%% %1.f%%\n",
(aStreakJumps[0] / float(iStreakJumps)) * 100.0, (aStreakJumps[0] / float(iStreakJumps)) * 100.0,
(aStreakJumps[1] / float(iStreakJumps)) * 100.0, (aStreakJumps[1] / float(iStreakJumps)) * 100.0,
(aStreakJumps[2] / float(iStreakJumps)) * 100.0); (aStreakJumps[2] / float(iStreakJumps)) * 100.0);
if (bDetected) iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "#%2s %5s %7s %7s %5s %5s %8s %4s %6s %s\n",
Format(g_sStats, sizeof(g_sStats), "%sStreak jumps perf group (1 2 +): %1.f%% %1.f%% %1.f%%\n",
g_sStats,
(aStreakJumps[0] / float(iStreakJumps)) * 100.0,
(aStreakJumps[1] / float(iStreakJumps)) * 100.0,
(aStreakJumps[2] / float(iStreakJumps)) * 100.0);
PrintToConsole(client, "#%2s %5s %7s %7s %5s %5s %8s %4s %6s %s",
"id", " diff", " invel", " outvel", " gain", " comb", " avgdist", " num", " avg+-", "pattern"); "id", " diff", " invel", " outvel", " gain", " comb", " avgdist", " num", " avg+-", "pattern");
if (bDetected)
Format(g_sStats, sizeof(g_sStats), "%s#%2s %5s %7s %7s %5s %5s %8s %4s %6s %s\n",
g_sStats, "id", " diff", " invel", " outvel", " gain", " comb", " avgdist", " num", " avg+-", "pattern");
ArrayList hJumps = hStreak.hJumps; ArrayList hJumps = hStreak.hJumps;
float fPrevVel = 0.0; float fPrevVel = 0.0;
int iPrevEndTick = -1; int iPrevEndTick = -1;
@ -627,21 +605,7 @@ void PrintStreak(int client, int iTarget, int iStreak, bool bDetected=false)
if(fPrevVel == 0.0) if(fPrevVel == 0.0)
fPrevVel = fInVel; fPrevVel = fInVel;
PrintToConsole(client, "#%2d %4d%% %7.1f %7.1f %4d%% %4d%% %8.2f %4d %6.2f %s", iBuf += ConsoleFormat(client, sBuf[iBuf], len-iBuf, "#%2d %4d%% %7.1f %7.1f %4d%% %4d%% %8.2f %4d %6.2f %s\n",
i,
fPrevVel == 0.0 ? 100 : RoundFloat((fInVel / fPrevVel) * 100.0 - 100.0),
fInVel,
fOutVel,
fInVel == 0.0 ? 100 : RoundFloat((fOutVel / fInVel) * 100.0 - 100.0),
fPrevVel == 0.0 ? 100 : RoundFloat((fOutVel / fPrevVel) * 100.0 - 100.0),
fAvgDist,
iPresses,
fAvgDownUp,
sPattern);
if (bDetected)
Format(g_sStats, sizeof(g_sStats), "%s#%2d %4d%% %7.1f %7.1f %4d%% %4d%% %8.2f %4d %6.2f %s\n",
g_sStats,
i, i,
fPrevVel == 0.0 ? 100 : RoundFloat((fInVel / fPrevVel) * 100.0 - 100.0), fPrevVel == 0.0 ? 100 : RoundFloat((fInVel / fPrevVel) * 100.0 - 100.0),
fInVel, fInVel,
@ -656,6 +620,8 @@ void PrintStreak(int client, int iTarget, int iStreak, bool bDetected=false)
iPrevEndTick = iEndTick; iPrevEndTick = iEndTick;
fPrevVel = fOutVel; fPrevVel = fOutVel;
} }
return iBuf;
} }
bool Forward_OnDetected(int client, const char[] reason, const char[] stats) bool Forward_OnDetected(int client, const char[] reason, const char[] stats)
@ -665,6 +631,19 @@ bool Forward_OnDetected(int client, const char[] reason, const char[] stats)
Call_PushString(reason); Call_PushString(reason);
Call_PushString(stats); Call_PushString(stats);
Call_Finish(); Call_Finish();
}
g_sStats = "";
stock int ConsoleFormat(int client, char[] buffer, int maxlength, const char[] format, any ...)
{
if(client >= 1 && client <= MAXPLAYERS)
{
char sBuf[1024];
sBuf[VFormat(sBuf, sizeof(sBuf), format, 5) - 1] = 0;
PrintToConsole(client, "%s", sBuf);
}
if(maxlength > 0)
return VFormat(buffer, maxlength, format, 5);
return 0;
} }