added some extra checks, re-run getauthstring on some users

This commit is contained in:
jenz 2024-09-29 18:33:19 +01:00
parent 93b8f48afc
commit 950fba2f5c

View File

@ -8,11 +8,12 @@
*/ */
class CBaseEntity; class CBaseEntity;
//class CBasePlayer;
uint8_t g_ClientIndex[SM_MAXPLAYERS + 1]; uint8_t g_ClientGiveNamedCounter[SM_MAXPLAYERS + 1];
char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][32]; char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][32];
char g_ClientNameMap[SM_MAXPLAYERS + 1][32]; char g_ClientNameMap[SM_MAXPLAYERS + 1][32];
int g_Capacity = 8; int g_Capacity = 20;
//https://sm.alliedmods.net/doxygen/index.html //https://sm.alliedmods.net/doxygen/index.html
@ -49,18 +50,52 @@ size_t strlcpy(char *dst, const char *src, size_t dsize)
DETOUR_DECL_MEMBER2(GiveNamedItem, void, char*, pszName, int, iSubType) DETOUR_DECL_MEMBER2(GiveNamedItem, void, char*, pszName, int, iSubType)
{ {
CBaseEntity *pPlayer = (CBaseEntity *)this; CBaseEntity *pEntity = (CBaseEntity *)this;
int idx = gamehelpers->EntityToBCompatRef(pPlayer); //int idx = gamehelpers->EntityToBCompatRef(pPlayer); //caused a crash
if (idx > 0 && idx < playerhelpers->GetMaxClients()) //should be in the index range for clients. /*
#0 0xeb7585a0 in CHalfLife2::EntityToBCompatRef (this=0xeb8605c0 <g_HL2>, pEntity=0x41)
at /home/gameservers/automate/sourcemod_1.12.0.7137/core/HalfLife2.cpp:1132
#1 0xeb75867e in non-virtual thunk to CHalfLife2::EntityToBCompatRef(CBaseEntity*) ()
from /home/gameservers/css_ze/cstrike/addons/sourcemod/bin/sourcemod.2.css.so
#2 0xe15a9d6a in GiveNamedItem (pContext=0x9cc6170, params=0xdbf85114) at /home/gameservers/automate/sourcemod_1.12.0.7137/extensions/sdktools/vnatives.cpp:327
*/
//CBasePlayer* pPlayer = (CBasePlayer*) this;
//CBasePlayer* pPlayer = CBasePlayer::GetLocalPlayer();
//CBasePlayer* pPlayer = ToBasePlayer(UTIL_GetCommandClient());
if (pEntity)
{
cell_t entRef = gamehelpers->EntityToReference(pEntity);
if (entRef)
{
int idx = gamehelpers->ReferenceToIndex(entRef);
if (idx > 0 && idx <= playerhelpers->GetMaxClients()) //should be in the index range for clients.
{ {
IGamePlayer* gp = playerhelpers->GetGamePlayer(idx); IGamePlayer* gp = playerhelpers->GetGamePlayer(idx);
if (gp->IsConnected()) if (gp && gp->IsConnected() && gp->IsInGame())
{
if (gp->IsFakeClient() || gp->IsSourceTV())
{ {
g_ClientIndex[idx]++;
smutils->LogMessage(myself, "got inside of DETOUR_DECL_MEMBER2. STEAMID: %s, playername: %s. pszName: %s. iSubType: %i. g_ClientIndex[idx]: %i",
g_ClientSteamIDMap[idx], g_ClientNameMap[idx], pszName, iSubType, g_ClientIndex[idx]);
DETOUR_MEMBER_CALL(GiveNamedItem)(pszName, iSubType); DETOUR_MEMBER_CALL(GiveNamedItem)(pszName, iSubType);
} }
else
{
g_ClientGiveNamedCounter[idx]++;
if (g_ClientGiveNamedCounter[idx] <= g_Capacity)
{
smutils->LogMessage(myself, "DETOUR_DECL_MEMBER2. STEAMID: %s, name: %s. pszName: %s. iSubType: %i. counter: %i",
g_ClientSteamIDMap[idx], g_ClientNameMap[idx], pszName, iSubType, g_ClientGiveNamedCounter[idx]);
DETOUR_MEMBER_CALL(GiveNamedItem)(pszName, iSubType);
}
else //log spammers
{
smutils->LogMessage(myself, "SPAMS A LOT. STEAMID: %s, name: %s. pszName: %s. iSubType: %i. counter: %i",
g_ClientSteamIDMap[idx], g_ClientNameMap[idx], pszName, iSubType, g_ClientGiveNamedCounter[idx]);
}
}
}
}
}
} }
} }
@ -82,7 +117,7 @@ bool GiveNamedItemTracker::SDK_OnLoad(char *error, size_t maxlength, bool late)
{ {
void *pBinary = dlopen("cstrike/bin/server_srv.so", RTLD_NOW); void *pBinary = dlopen("cstrike/bin/server_srv.so", RTLD_NOW);
if(!pBinary) if (!pBinary)
{ {
smutils->LogError(myself, "Could not dlopen cstrike/bin/server_srv.so"); smutils->LogError(myself, "Could not dlopen cstrike/bin/server_srv.so");
return false; return false;
@ -114,7 +149,7 @@ bool GiveNamedItemTracker::SDK_OnLoad(char *error, size_t maxlength, bool late)
void GiveNamedItemTracker::OnClientPostAdminCheck(int client) void GiveNamedItemTracker::OnClientPostAdminCheck(int client)
{ {
g_ClientIndex[client] = 0; g_ClientGiveNamedCounter[client] = 0;
IGamePlayer* gp = playerhelpers->GetGamePlayer(client); IGamePlayer* gp = playerhelpers->GetGamePlayer(client);
strlcpy(g_ClientSteamIDMap[client], gp->GetAuthString(), sizeof(*g_ClientSteamIDMap)); strlcpy(g_ClientSteamIDMap[client], gp->GetAuthString(), sizeof(*g_ClientSteamIDMap));
strlcpy(g_ClientNameMap[client], gp->GetName(), sizeof(*g_ClientNameMap)); strlcpy(g_ClientNameMap[client], gp->GetName(), sizeof(*g_ClientNameMap));
@ -122,25 +157,28 @@ void GiveNamedItemTracker::OnClientPostAdminCheck(int client)
void GiveNamedItemTracker::OnClientDisconnected(int client) void GiveNamedItemTracker::OnClientDisconnected(int client)
{ {
g_ClientIndex[client] = 0; g_ClientGiveNamedCounter[client] = 0;
strlcpy(g_ClientSteamIDMap[client], "", sizeof(*g_ClientSteamIDMap)); strlcpy(g_ClientSteamIDMap[client], "", sizeof(*g_ClientSteamIDMap));
strlcpy(g_ClientNameMap[client], "", sizeof(*g_ClientNameMap)); strlcpy(g_ClientNameMap[client], "", sizeof(*g_ClientNameMap));
} }
void GiveNamedItemTracker::OnTimer() void GiveNamedItemTracker::OnTimer()
{ {
for(int idx = 1; idx < playerhelpers->GetMaxClients(); idx++) for (int idx = 0; idx <= playerhelpers->GetMaxClients(); idx++)
{ {
if (strcmp(g_ClientSteamIDMap[idx], "") == 0)
{
//empty steamid. (null). idx: 2. name: mituju
//according to my logging does gp->GetAuthString() in DETOUR_DECL_MEMBER2 sometimes return null.
//therefore rerunning it here to try and re-assign them their steam ID if still missing.
IGamePlayer* gp = playerhelpers->GetGamePlayer(idx); IGamePlayer* gp = playerhelpers->GetGamePlayer(idx);
if (gp->IsConnected()) if (gp && gp->IsConnected() && gp->IsInGame())
{ {
if (g_ClientIndex[idx] > g_Capacity) strlcpy(g_ClientSteamIDMap[idx], gp->GetAuthString(), sizeof(*g_ClientSteamIDMap));
{ strlcpy(g_ClientNameMap[idx], gp->GetName(), sizeof(*g_ClientNameMap));
smutils->LogMessage(myself, "Client with more weapons than capacity %i: STEAMID: %s. playername: %s. g_ClientIndex[idx]: %i",
g_Capacity, g_ClientSteamIDMap[idx], g_ClientNameMap[idx], g_ClientIndex[idx]);
} }
g_ClientIndex[idx] = 0;
} }
g_ClientGiveNamedCounter[idx] = 0;
} }
} }