From e8b7eeef5678969a1c1c8b3b0b51d8875ca64fa3 Mon Sep 17 00:00:00 2001 From: jenz Date: Fri, 4 Oct 2024 12:12:19 +0100 Subject: [PATCH] extending buffers a bit. some extra checks. not reseting players that disconnected. initializing all indexes as -1 on loading --- extension.cpp | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/extension.cpp b/extension.cpp index 7b747b7..083dec0 100644 --- a/extension.cpp +++ b/extension.cpp @@ -10,9 +10,9 @@ class CBaseEntity; //class CBasePlayer; -uint8_t g_ClientGiveNamedCounter[SM_MAXPLAYERS + 1]; -char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][32]; -char g_ClientNameMap[SM_MAXPLAYERS + 1][32]; +uint32_t g_ClientGiveNamedCounter[SM_MAXPLAYERS + 1]; +char g_ClientSteamIDMap[SM_MAXPLAYERS + 1][64]; +char g_ClientNameMap[SM_MAXPLAYERS + 1][128]; int g_Capacity = 20; //https://sm.alliedmods.net/doxygen/index.html @@ -144,6 +144,12 @@ bool GiveNamedItemTracker::SDK_OnLoad(char *error, size_t maxlength, bool late) //set up timer for reseting GiveNamedItemTracker counts. g_pGiveNamedItemTimer = timersys->CreateTimer(&g_GiveNamedItemTracker, 2.0, NULL, TIMER_FLAG_REPEAT); + + for (int idx = 0; idx <= 65; idx++) + { + g_ClientGiveNamedCounter[idx] = -1; + } + return true; } @@ -157,7 +163,7 @@ void GiveNamedItemTracker::OnClientPostAdminCheck(int client) void GiveNamedItemTracker::OnClientDisconnected(int client) { - g_ClientGiveNamedCounter[client] = 0; + g_ClientGiveNamedCounter[client] = -1; strlcpy(g_ClientSteamIDMap[client], "", sizeof(*g_ClientSteamIDMap)); strlcpy(g_ClientNameMap[client], "", sizeof(*g_ClientNameMap)); } @@ -166,6 +172,11 @@ void GiveNamedItemTracker::OnTimer() { for (int idx = 0; idx <= playerhelpers->GetMaxClients(); idx++) { + if (g_ClientGiveNamedCounter[idx] == -1) + { + continue; + } + if (strcmp(g_ClientSteamIDMap[idx], "") == 0) { //empty steamid. (null). idx: 2. name: mituju @@ -174,8 +185,17 @@ void GiveNamedItemTracker::OnTimer() IGamePlayer* gp = playerhelpers->GetGamePlayer(idx); if (gp && gp->IsConnected() && gp->IsInGame()) { - strlcpy(g_ClientSteamIDMap[idx], gp->GetAuthString(), sizeof(*g_ClientSteamIDMap)); - strlcpy(g_ClientNameMap[idx], gp->GetName(), sizeof(*g_ClientNameMap)); + const char *steamID = gp->GetAuthString(); + const char *name = gp->GetName(); + if (steamID) + { + strlcpy(g_ClientSteamIDMap[idx], steamID, sizeof(*g_ClientSteamIDMap)); + } + //not too bad if we miss the name, just steam id is important + if (name) + { + strlcpy(g_ClientNameMap[idx], name, sizeof(*g_ClientNameMap)); + } } } g_ClientGiveNamedCounter[idx] = 0;