From d740a39e62661ac32b2343e36c154d88912be033 Mon Sep 17 00:00:00 2001 From: Rushaway Date: Wed, 28 Oct 2026 15:36:56 +0100 Subject: [PATCH] fix(sql): stop the group color list from growing on every reload - OnSQLSelect_Color reset nothing and had no bound: every sm_admins_config_mode change appended the sb_srvgroups rows again until the 255-entry array overflowed. Reset it and stop at the max. - Reuse the open connection instead of reconnecting on each cvar change, ignore a second connect while one is in flight, close a non-MySQL handle, retry a failed connect after 30 seconds. Co-Authored-By: Claude Opus 5.5 --- .../sourcemod/scripting/AdvancedAdminList.sp | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/addons/sourcemod/scripting/AdvancedAdminList.sp b/addons/sourcemod/scripting/AdvancedAdminList.sp index ceeab02..c225425 100644 --- a/addons/sourcemod/scripting/AdvancedAdminList.sp +++ b/addons/sourcemod/scripting/AdvancedAdminList.sp @@ -38,6 +38,8 @@ bool g_bMapEnd = false; bool g_bRebuildInProgress = false; Database g_hDatabase = null; +bool g_bSQLConnecting = false; +Handle g_hSQLRetryTimer = null; char g_sColorList[COLOR_LIST_MAX_LENGTH][2][COLOR_LIST_MAX_LENGTH]; char g_sColorListOverride[COLOR_LIST_MAX_LENGTH][2][COLOR_LIST_MAX_LENGTH]; @@ -53,7 +55,7 @@ public Plugin myinfo = name = "Advanced Admin List", author = "maxime1907, .Rushaway", description = "An advanced admin list system", - version = "2.1.9", + version = "2.1.10", url = "" }; @@ -146,37 +148,63 @@ stock bool LoadConfigOverride(char[] sFilename) stock void SQLInitialize() { + // Keep the connection we already have, just reload the colors if (g_hDatabase != null) - delete g_hDatabase; + { + SQLSelect_Colors(); + return; + } + + // The pending connect will load the colors + if (g_bSQLConnecting) + return; if (SQL_CheckConfig(DATABASE_NAME)) + { + g_bSQLConnecting = true; Database.Connect(OnSQLConnected, DATABASE_NAME); + } else SetFailState("Could not find \"%s\" entry in databases.cfg.", DATABASE_NAME); } public void OnSQLConnected(Database db, const char[] err, any data) { + g_bSQLConnecting = false; + if (db == null) { - LogError("Failed to connect to database \"%s\". (%s)", DATABASE_NAME, err); + LogError("Failed to connect to database \"%s\", retrying in 30 seconds. (%s)", DATABASE_NAME, err); + if (g_hSQLRetryTimer == null) + g_hSQLRetryTimer = CreateTimer(30.0, Timer_SQLRetry); return; } char sDriver[16]; - g_hDatabase = db; db.Driver.GetIdentifier(sDriver, sizeof(sDriver)); if (strncmp(sDriver, "my", 2, false)) { LogError("Only mysql is supported for \"%s\".", DATABASE_NAME); + delete db; return; - } + g_hDatabase = db; + SQLSelect_Colors(); } +public Action Timer_SQLRetry(Handle hTimer) +{ + g_hSQLRetryTimer = null; + + if (g_cAdminsConfigMode.IntValue == 0 || g_cAdminsConfigMode.IntValue == 1) + SQLInitialize(); + + return Plugin_Stop; +} + stock void SQLSelect_Colors() { @@ -197,7 +225,9 @@ public void OnSQLSelect_Color(Database hParent, DBResultSet hChild, const char[] return; } - while (hChild.FetchRow()) + // Replace the list, a reload must not append to the previous one + g_iColorListSize = 0; + while (g_iColorListSize < COLOR_LIST_MAX_LENGTH && hChild.FetchRow()) { hChild.FetchString(0, g_sColorList[g_iColorListSize][0], sizeof(g_sColorList[][])); hChild.FetchString(1, g_sColorList[g_iColorListSize][1], sizeof(g_sColorList[][]));