From 0efcbcb139a17a7e37a4a0c0a2406a94fcf11128 Mon Sep 17 00:00:00 2001 From: ArKaNeMaN Date: Tue, 16 Jan 2024 13:17:56 +0300 Subject: [PATCH 1/2] Fix error when key sets before user loaded --- scripting/player_prefs.sma | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripting/player_prefs.sma b/scripting/player_prefs.sma index 897d84a..e319635 100644 --- a/scripting/player_prefs.sma +++ b/scripting/player_prefs.sma @@ -349,6 +349,9 @@ public ThreadQuery_Handler(iFailState, Handle: hQuery, szError[], iError, szData if (iUserid != get_user_userid(iPlayer)) return; + if (g_iPlayerDatabaseId[iPlayer] <= 0) + return; + new iKeyId = szData[3] == 0 ? SQL_GetInsertId(hQuery) : szData[3]; formatex(g_szQuery, charsmax(g_szQuery), From 48f28ac0b551acd5cb73de80c1147312571f4ffa Mon Sep 17 00:00:00 2001 From: ArKaNeMaN Date: Wed, 17 Jan 2024 02:05:06 +0300 Subject: [PATCH 2/2] Add error message when preference sets before player loaded --- scripting/player_prefs.sma | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripting/player_prefs.sma b/scripting/player_prefs.sma index e319635..e7e76bd 100644 --- a/scripting/player_prefs.sma +++ b/scripting/player_prefs.sma @@ -33,7 +33,7 @@ enum _: IntertKey { value[256] }; -new g_iPlayerDatabaseId[MAX_PLAYERS + 1]; +new g_iPlayerDatabaseId[MAX_PLAYERS + 1] = {0, ...}; new Trie: g_tPlayerPreferences[MAX_PLAYERS + 1]; new Trie: g_tKeys; @@ -81,10 +81,7 @@ public bool: native_is_loaded(iPlugin, iArgs) { new iPlayer = get_param(arg_player_id); - if (!is_user_connected(iPlayer)) - return false; - - return bool: g_iPlayerDatabaseId[iPlayer]; + return IsUserLoaded(iPlayer); } public bool: native_get_preference(iPlugin, iArgs) { @@ -126,6 +123,11 @@ public bool: native_set_preference(iPlugin, iArgs) { if (!is_user_connected(iPlayer)) return false; + if (!IsUserLoaded(iPlayer)) { + log_error(0, "Attempt to set preference for not loaded player (%d).", iPlayer); + return false; + } + new szKey[32], szValue[256], szDefaultValue[256]; get_string(arg_key, szKey, charsmax(szKey)); @@ -167,6 +169,13 @@ public bool: native_set_key_default_value(iPlugin, iArgs) { return bool: TrieSetString(g_tKeys, szKey, szDefaultValue); } +bool:IsUserLoaded(const iPlayer) { + if (!is_user_connected(iPlayer)) + return false; + + return g_iPlayerDatabaseId[iPlayer] > 0; +} + stock LoadPreferences(iPlayer) { if (g_hSqlTuple == Empty_Handle) { ExecuteForward(g_iForwards[Forward_PlayerLoaded], _, iPlayer);