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
@@ -14,7 +14,6 @@ bool g_bEngineCSGO;
bool g_bHideCrown[MAXPLAYERS+1];
bool g_bHideDialog[MAXPLAYERS+1];
bool g_bProtection[MAXPLAYERS+1];
bool g_bTitleSet[MAXPLAYERS+1];
/* COOKIES */
Handle g_hCookie_HideCrown;
@@ -31,14 +30,6 @@ ConVar g_hCVar_Display;
ConVar g_hCVar_HudChannel;
ConVar g_hCVar_HudX;
ConVar g_hCVar_HudY;
ConVar g_hCVar_Hostname;
ConVar g_hCVar_HostIP;
ConVar g_hCVar_HostPort;
ConVar g_hCVar_Password;
/* STRINGS */
char g_sRankTitle[MAXPLAYERS+1][128];
char g_sTitleSent[MAXPLAYERS+1][128];
/* INTERGERS */
int g_iDialogLevel = 100000;
@@ -85,17 +76,12 @@ public void OnPluginStart()
g_hCVar_ProtectionMinimal2 = CreateConVar("sm_topdefenders_minimal_2", "30", "", FCVAR_NONE, true, 1.0, true, 64.0);
g_hCVar_ProtectionMinimal3 = CreateConVar("sm_topdefenders_minimal_3", "45", "", FCVAR_NONE, true, 1.0, true, 64.0);
g_hCVar_Grenade = CreateConVar("sm_topdefenders_grenade", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_Display = CreateConVar("sm_topdefenders_display", "2", "Rank display: 0 off, 1 dialog, 2 hudtext, 3 scoreboard title (set sm_hostname_send_to_clients 0 so HostnameManager doesn't overwrite it)", FCVAR_NONE, true, 0.0, true, 3.0);
g_hCVar_Display = CreateConVar("sm_topdefenders_display", "1", "Rank display: 0 off, 1 dialog, 2 hudtext", FCVAR_NONE, true, 0.0, true, 2.0);
g_hCVar_HudChannel = CreateConVar("sm_topdefenders_hud_channel", "5", "Hudtext channel for the rank display (0-5)", FCVAR_NONE, true, 0.0, true, 5.0);
g_hCVar_HudX = CreateConVar("sm_topdefenders_hud_x", "0.01", "Hudtext x position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
g_hCVar_HudY = CreateConVar("sm_topdefenders_hud_y", "0.01", "Hudtext y position for the rank display (-1 centres)", FCVAR_NONE, true, -1.0, true, 1.0);
AutoExecConfig(true);
g_hCVar_Hostname = FindConVar("hostname");
g_hCVar_HostIP = FindConVar("hostip");
g_hCVar_HostPort = FindConVar("hostport");
g_hCVar_Password = FindConVar("sv_password");
g_hCookie_HideCrown = RegClientCookie("topdefenders_hidecrown", "", CookieAccess_Private);
g_hCookie_HideDialog = RegClientCookie("topdefenders_hidedialog", "", CookieAccess_Private);
g_hCookie_Protection = RegClientCookie("topdefenders_protection", "", CookieAccess_Private);
@@ -117,14 +103,6 @@ public void OnPluginStart()
SetCookieMenuItem(MenuHandler_CookieMenu, 0, "Player Rankings");
}
//----------------------------------------------------------------------------------------------------
// Purpose: Hand everyone showing a rank title the real hostname back.
//----------------------------------------------------------------------------------------------------
public void OnPluginEnd()
{
ResetAllTitles();
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
@@ -318,21 +296,11 @@ public void OnClientCookiesCached(int client)
g_bProtection[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientPutInServer(int client)
{
g_bTitleSet[client] = false;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public void OnClientDisconnect(int client)
{
g_bTitleSet[client] = false;
g_iPlayerDamage[client] = 0;
g_iPlayerDamageHits[client] = 0;
g_iPlayerDamageFrom1K[client] = 0;
@@ -392,23 +360,14 @@ public Action UpdateDialog(Handle timer)
{
int iDisplay = g_hCVar_Display.IntValue;
if (iDisplay != 3 || g_iDialogLevel <= 0)
ResetAllTitles();
if (g_bEngineCSGO || g_iDialogLevel <= 0 || iDisplay <= 0)
return;
// Hudtext (held for 1s) and the scoreboard title only need a refresh every 0.5s, the dialog keeps the 0.1s rate.
// Hudtext (held for 1s) only needs a refresh every 0.5s, the dialog keeps the 0.1s rate.
static int iHudTick;
if (iDisplay >= 2 && (iHudTick++ % 5) != 0)
if (iDisplay == 2 && (iHudTick++ % 5) != 0)
return;
if (iDisplay == 3)
{
for (int client = 1; client <= MaxClients; client++)
g_sRankTitle[client][0] = '\0';
}
int iSortedList[MAXPLAYERS+1][2];
int iSortedCount;
@@ -425,27 +384,39 @@ public Action UpdateDialog(Handle timer)
SortCustom2D(iSortedList, iSortedCount, SortRankingsList);
char sBuffer[128];
char sRank[16], sDamage[16], sGap[16], sFirst[16];
for (int rank = 0; rank < iSortedCount; rank++)
{
FormatCommas(rank + 1, sRank, sizeof(sRank));
FormatCommas(iSortedList[rank][1], sDamage, sizeof(sDamage));
switch(rank)
{
case(0): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | P: -%d)", rank + 1, iSortedList[rank][1], iSortedList[rank][1] - iSortedList[rank + 1][1]);
case(1): Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1]);
default: Format(sBuffer, sizeof(sBuffer), "#%d (D: %d | N: +%d | F: +%d)", rank + 1, iSortedList[rank][1], iSortedList[rank - 1][1] - iSortedList[rank][1], iSortedList[0][1] - iSortedList[rank][1]);
case(0):
{
FormatCommas(iSortedList[rank][1] - iSortedList[rank + 1][1], sGap, sizeof(sGap));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | P: -%s)", sRank, sDamage, sGap);
}
case(1):
{
FormatCommas(iSortedList[rank - 1][1] - iSortedList[rank][1], sGap, sizeof(sGap));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | N: +%s)", sRank, sDamage, sGap);
}
default:
{
FormatCommas(iSortedList[rank - 1][1] - iSortedList[rank][1], sGap, sizeof(sGap));
FormatCommas(iSortedList[0][1] - iSortedList[rank][1], sFirst, sizeof(sFirst));
Format(sBuffer, sizeof(sBuffer), "#%s (D: %s | N: +%s | F: +%s)", sRank, sDamage, sGap, sFirst);
}
}
if (iDisplay == 1)
SendDialog(iSortedList[rank][0], "%s", g_iDialogLevel, 1, sBuffer);
else if (iDisplay == 2)
SendRankHud(iSortedList[rank][0], sBuffer);
else
Format(g_sRankTitle[iSortedList[rank][0]], sizeof(g_sRankTitle[]), "[UNLOZE] Pos. %s", sBuffer);
SendRankHud(iSortedList[rank][0], sBuffer);
}
if (iDisplay == 3)
UpdateTitles();
g_iDialogLevel--;
}
@@ -515,11 +486,14 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedCountDefenders)
{
char sBuffer[512];
char sDamage[16], sHits[16];
Format(sBuffer, sizeof(sBuffer), "TOP DEFENDERS:");
if (iSortedListDefenders[0][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[0][0], iSortedListDefenders[0][1], iSortedListDefenders[0][2]);
FormatCommas(iSortedListDefenders[0][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[0][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[0][0], sDamage, sHits);
g_iPlayerWinner[0] = GetSteamAccountID(iSortedListDefenders[0][0]);
@@ -527,7 +501,9 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListDefenders[1][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[1][0], iSortedListDefenders[1][1], iSortedListDefenders[1][2]);
FormatCommas(iSortedListDefenders[1][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[1][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[1][0], sDamage, sHits);
g_iPlayerWinner[1] = GetSteamAccountID(iSortedListDefenders[1][0]);
@@ -535,7 +511,9 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListDefenders[2][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d damage in %d hits", sBuffer, iSortedListDefenders[2][0], iSortedListDefenders[2][1], iSortedListDefenders[2][2]);
FormatCommas(iSortedListDefenders[2][1], sDamage, sizeof(sDamage));
FormatCommas(iSortedListDefenders[2][2], sHits, sizeof(sHits));
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %s damage in %s hits", sBuffer, iSortedListDefenders[2][0], sDamage, sHits);
g_iPlayerWinner[2] = GetSteamAccountID(iSortedListDefenders[2][0]);
@@ -566,11 +544,13 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedCountInfectors)
{
char sBuffer[512];
char sInfections[16];
Format(sBuffer, sizeof(sBuffer), "TOP INFECTORS:");
if (iSortedListInfectors[0][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %d infections", sBuffer, iSortedListInfectors[0][0], iSortedListInfectors[0][1]);
FormatCommas(iSortedListInfectors[0][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n1. %N - %s infections", sBuffer, iSortedListInfectors[0][0], sInfections);
g_iPlayerWinner[3] = GetSteamAccountID(iSortedListInfectors[0][0]);
@@ -578,7 +558,8 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListInfectors[1][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %d infections", sBuffer, iSortedListInfectors[1][0], iSortedListInfectors[1][1]);
FormatCommas(iSortedListInfectors[1][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n2. %N - %s infections", sBuffer, iSortedListInfectors[1][0], sInfections);
g_iPlayerWinner[4] = GetSteamAccountID(iSortedListInfectors[1][0]);
@@ -586,7 +567,8 @@ public void OnRoundEnding(Event hEvent, const char[] sEvent, bool bDontBroadcast
if (iSortedListInfectors[2][0])
{
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %d infections", sBuffer, iSortedListInfectors[2][0], iSortedListInfectors[2][1]);
FormatCommas(iSortedListInfectors[2][1], sInfections, sizeof(sInfections));
Format(sBuffer, sizeof(sBuffer), "%s\n3. %N - %s infections", sBuffer, iSortedListInfectors[2][0], sInfections);
g_iPlayerWinner[5] = GetSteamAccountID(iSortedListInfectors[2][0]);
@@ -1134,118 +1116,31 @@ void SendRankHud(int client, const char[] text)
}
//----------------------------------------------------------------------------------------------------
// Purpose: Rank line as the scoreboard title. Unranked spectators see the title of the player they
// watch in first or third person, everyone else gets the real hostname back.
// Purpose: Writes value with thousands separators, 1487 -> "1,487".
//----------------------------------------------------------------------------------------------------
void UpdateTitles()
void FormatCommas(int value, char[] buffer, int maxlen)
{
for (int client = 1; client <= MaxClients; client++)
char sDigits[16];
IntToString(value, sDigits, sizeof(sDigits));
int iStart = (sDigits[0] == '-') ? 1 : 0;
int iLength = strlen(sDigits);
int iPos;
for (int i = 0; i < iLength && iPos < maxlen - 1; i++)
{
if (!IsClientInGame(client) || IsFakeClient(client))
continue;
int source = client;
if (!g_sRankTitle[client][0] && IsClientObserver(client))
if (i > iStart && (iLength - i) % 3 == 0)
{
int specMode = GetClientSpectatorMode(client);
int specTarget = GetClientSpectatorTarget(client);
buffer[iPos++] = ',';
if ((specMode == SPECMODE_FIRSTPERSON || specMode == SPECMODE_THIRDPERSON) && specTarget >= 1 && specTarget <= MaxClients)
source = specTarget;
if (iPos >= maxlen - 1)
break;
}
if (g_bHideDialog[client] || !g_sRankTitle[source][0])
ResetTitle(client);
else
SetTitle(client, g_sRankTitle[source]);
buffer[iPos++] = sDigits[i];
}
}
//----------------------------------------------------------------------------------------------------
// Purpose: Only sends when the title changes.
//----------------------------------------------------------------------------------------------------
void SetTitle(int client, const char[] title)
{
if (g_bTitleSet[client] && strcmp(g_sTitleSent[client], title, true) == 0)
return;
SendClientHostname(client, title);
strcopy(g_sTitleSent[client], sizeof(g_sTitleSent[]), title);
g_bTitleSet[client] = true;
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
void ResetTitle(int client)
{
if (!g_bTitleSet[client])
return;
g_bTitleSet[client] = false;
if (!IsClientInGame(client))
return;
char sHostname[128];
g_hCVar_Hostname.GetString(sHostname, sizeof(sHostname));
SendClientHostname(client, sHostname);
}
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
void ResetAllTitles()
{
for (int client = 1; client <= MaxClients; client++)
ResetTitle(client);
}
//----------------------------------------------------------------------------------------------------
// Purpose: Copied from HostnameManager. The scoreboard only reads the hostname from server_spawn,
// which the client's engine fires locally from svc_ServerInfo on connect. Send a copy
// straight to the client so it never reaches server-side listeners, and fill every field so
// other client listeners (mumble, abuse report, steam share) see the values they got on connect.
//----------------------------------------------------------------------------------------------------
void SendClientHostname(int client, const char[] hostname)
{
Event hEvent = CreateEvent("server_spawn", true);
if (hEvent == null)
return;
int iIP = g_hCVar_HostIP.IntValue;
int iPort = g_hCVar_HostPort.IntValue;
char sAddress[32];
Format(sAddress, sizeof(sAddress), "%d.%d.%d.%d:%d", (iIP >>> 24) & 0xFF, (iIP >>> 16) & 0xFF, (iIP >>> 8) & 0xFF, iIP & 0xFF, iPort);
char sGame[32];
GetGameFolderName(sGame, sizeof(sGame));
char sMap[PLATFORM_MAX_PATH];
GetCurrentMap(sMap, sizeof(sMap));
char sPassword[64];
g_hCVar_Password.GetString(sPassword, sizeof(sPassword));
hEvent.SetString("hostname", hostname);
hEvent.SetString("address", sAddress);
hEvent.SetInt("ip", iIP);
hEvent.SetInt("port", iPort);
hEvent.SetString("game", sGame);
hEvent.SetString("mapname", sMap);
hEvent.SetInt("maxplayers", MaxClients);
hEvent.SetString("os", "LINUX");
hEvent.SetBool("dedicated", IsDedicatedServer());
hEvent.SetBool("password", sPassword[0] != '\0');
hEvent.FireToClient(client);
// FireToClient does not free the event.
hEvent.Cancel();
buffer[iPos] = '\0';
}
//----------------------------------------------------------------------------------------------------