Add sm_realclients to FakeClients and update several plugins

FakeClients: sm_realclients, autism bots counted separately.

Updated: Extend, HostnameManager, PlayerRankings_nohlstats.

Add shared include: BotTargeting.
This commit is contained in:
2026-11-24 03:21:45 +00:00
parent dd33584e57
commit 7c111cd0f8
5 changed files with 249 additions and 169 deletions
+135 -3
View File
@@ -2,9 +2,16 @@
#include <sdktools>
#include <cstrike>
#undef REQUIRE_PLUGIN
#include <AFKManager>
#include <BotTargeting>
#define REQUIRE_PLUGIN
#pragma semicolon 1
#pragma newdecls required
ConVar g_cvRealClientsAfkTime;
ArrayList g_hNames;
ArrayList g_hClanNames;
@@ -36,6 +43,9 @@ public void OnPluginStart()
{
RegAdminCmd("sm_debugfakes", Command_DebugFakes, ADMFLAG_GENERIC, "Shows the amount of fake-clients on server");
RegAdminCmd("sm_fakes", Command_Fakes, ADMFLAG_GENERIC, "Shows the fake-clients on server");
RegAdminCmd("sm_realclients", Command_RealClients, ADMFLAG_GENERIC, "Shows the real clients on server, split into active and spec/afk");
g_cvRealClientsAfkTime = CreateConVar("sm_realclients_afk_time", "30", "Seconds idle (AFKManager) before sm_realclients lists a player on a team as AFK", 0, true, 0.0);
int arraySize = ByteCountToCells(MAX_NAME_LENGTH);
g_hNames = CreateArray(arraySize);
@@ -418,6 +428,7 @@ public Action Command_DebugFakes(int client, int argc)
{
int iFakes = 0;
int iFakesInTeam = 0;
int iAutismBots = 0;
int iPlayers = GetClientCount(false);
for(int i = 1; i <= MaxClients; i++)
@@ -430,15 +441,30 @@ public Action Command_DebugFakes(int client, int argc)
{
iFakes++;
iPlayers--;
if (IsClientInGame(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR)
iFakesInTeam++;
}
if (IsFakeClient(i) && GetClientTeam(i) > CS_TEAM_SPECTATOR)
iFakesInTeam++;
else if (IsAutismBot(i))
{
iAutismBots++;
iPlayers--;
}
}
ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate. Real Clients %d", iFakes, iFakes - iFakesInTeam, iPlayers);
ReplyToCommand(client, "[SM] There are currently %d Fake-Clients, from which %d are in Spectate. Autism Bots %d. Real Clients %d", iFakes, iFakes - iFakesInTeam, iAutismBots, iPlayers);
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: autism bots are real Steam clients (BotTargeting SteamID list) that statistics treat as fakes
//----------------------------------------------------------------------------------------------------
bool IsAutismBot(int client)
{
return GetFeatureStatus(FeatureType_Native, "IsClientAutismBot") == FeatureStatus_Available
&& IsClientInGame(client) && IsClientAuthorized(client) && !IsFakeClient(client)
&& IsClientAutismBot(client);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@@ -457,6 +483,12 @@ public Action Command_Fakes(int client, int args)
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), ", ");
}
else if(IsAutismBot(i))
{
GetClientName(i, aBuf2, sizeof(aBuf2));
StrCat(aBuf, sizeof(aBuf), aBuf2);
StrCat(aBuf, sizeof(aBuf), " (autism bot), ");
}
}
}
@@ -471,6 +503,106 @@ public Action Command_Fakes(int client, int args)
return Plugin_Handled;
}
//----------------------------------------------------------------------------------------------------
// Purpose: lists real clients split into active (on a team, not idle) and spec/afk
//----------------------------------------------------------------------------------------------------
public Action Command_RealClients(int client, int args)
{
bool bAfkKnown = GetFeatureStatus(FeatureType_Native, "GetClientIdleTime") == FeatureStatus_Available;
int iAfkTime = g_cvRealClientsAfkTime.IntValue;
int iActive[MAXPLAYERS + 1], iInactive[MAXPLAYERS + 1], iAutism[MAXPLAYERS + 1];
int iActiveCount = 0, iInactiveCount = 0, iAutismCount = 0;
for(int i = 1; i <= MaxClients; i++)
{
if(!IsClientInGame(i) || IsFakeClient(i) || IsClientSourceTV(i))
continue;
if(IsAutismBot(i))
{
iAutism[iAutismCount++] = i;
continue;
}
if(GetClientTeam(i) > CS_TEAM_SPECTATOR && !(bAfkKnown && iAfkTime > 0 && GetClientIdleTime(i) >= iAfkTime))
iActive[iActiveCount++] = i;
else
iInactive[iInactiveCount++] = i;
}
// Name lists overflow a chat line, so they always go to console.
if(GetCmdReplySource() == SM_REPLY_TO_CHAT)
ReplyToCommand(client, "[SM] Real clients: %d (active %d, spec/afk %d). See console for the list.", iActiveCount + iInactiveCount, iActiveCount, iInactiveCount);
char sBar[64];
BuildProgressBar(sBar, sizeof(sBar), iActiveCount + iInactiveCount, MaxClients);
PrintRealClientsLine(client, "Real %s %d/%d", sBar, iActiveCount + iInactiveCount, MaxClients);
BuildProgressBar(sBar, sizeof(sBar), iActiveCount, MaxClients);
PrintRealClientsLine(client, "Active %s %d/%d", sBar, iActiveCount, MaxClients);
PrintRealClientsLine(client, "[SM] Real clients: %d (active %d, spec/afk %d)%s", iActiveCount + iInactiveCount, iActiveCount, iInactiveCount,
bAfkKnown ? "" : ", AFKManager not loaded so only spectators count as inactive");
PrintRealClientsLine(client, "Active (%d):", iActiveCount);
for(int j = 0; j < iActiveCount; j++)
PrintRealClientsLine(client, " %N", iActive[j]);
PrintRealClientsLine(client, "Spec/AFK (%d):", iInactiveCount);
for(int j = 0; j < iInactiveCount; j++)
{
int i = iInactive[j];
int iTeam = GetClientTeam(i);
int iIdle = bAfkKnown ? GetClientIdleTime(i) : 0;
if(iTeam > CS_TEAM_SPECTATOR)
PrintRealClientsLine(client, " %N (afk %dm%02ds, %s)", i, iIdle / 60, iIdle % 60, iTeam == CS_TEAM_CT ? "CT" : "T");
else if(bAfkKnown)
PrintRealClientsLine(client, " %N (%s, idle %dm%02ds)", i, iTeam == CS_TEAM_SPECTATOR ? "spec" : "unassigned", iIdle / 60, iIdle % 60);
else
PrintRealClientsLine(client, " %N (%s)", i, iTeam == CS_TEAM_SPECTATOR ? "spec" : "unassigned");
}
if(GetFeatureStatus(FeatureType_Native, "IsClientAutismBot") != FeatureStatus_Available)
{
PrintRealClientsLine(client, "Autism bots: unknown, BotTargeting not loaded so they count as real clients above");
}
else if(iAutismCount)
{
PrintRealClientsLine(client, "Autism bots, counted as fakes (%d):", iAutismCount);
for(int j = 0; j < iAutismCount; j++)
PrintRealClientsLine(client, " %N", iAutism[j]);
}
return Plugin_Handled;
}
// [##########--------------------] style bar, filled in proportion to value/max.
void BuildProgressBar(char[] buffer, int maxlen, int value, int max, int width = 32)
{
int iFilled = max > 0 ? RoundToNearest(float(value) / float(max) * float(width)) : 0;
if(iFilled > width)
iFilled = width;
int iPos = 0;
buffer[iPos++] = '[';
for(int i = 0; i < width && iPos < maxlen - 2; i++)
buffer[iPos++] = i < iFilled ? '#' : '-';
buffer[iPos++] = ']';
buffer[iPos] = '\0';
}
void PrintRealClientsLine(int client, const char[] format, any ...)
{
char sLine[256];
VFormat(sLine, sizeof(sLine), format, 3);
if(client == 0)
PrintToServer("%s", sLine);
else
PrintToConsole(client, "%s", sLine);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------