From a54ecf9d0c100aca9477dc63243c8f5fc3037e34 Mon Sep 17 00:00:00 2001 From: ufame Date: Mon, 23 Oct 2023 23:12:19 +0500 Subject: [PATCH 1/3] IntertKey enum moved to global scope --- scripting/player_prefs.sma | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/scripting/player_prefs.sma b/scripting/player_prefs.sma index 8ebfde3..8d65e4d 100644 --- a/scripting/player_prefs.sma +++ b/scripting/player_prefs.sma @@ -22,6 +22,14 @@ enum _: Forwards { Forward_PlayerSaved }; +enum _: IntertKey { + query_state, + player_id, + player_userid, + key_id, + value[256] +}; + new g_iPlayerDatabaseId[MAX_PLAYERS + 1]; new Trie: g_tPlayerPreferences[MAX_PLAYERS + 1]; @@ -189,16 +197,7 @@ stock SetPreference(iPlayer, szKey[], szValue[], szDefaultValue[]) { szKey, szDefaultValue ); - // TODO: Было бы неплохо в глобаг скоп выкинуть - enum data { - query_state, - player_id, - player_userid, - key_id, - value[256] - }; - - new szData[data]; + new szData[IntertKey]; szData[query_state] = State_InsertKey; szData[player_id] = iPlayer; From 5165c4783fd6d07c7a7ac85b2680b2ba71680842 Mon Sep 17 00:00:00 2001 From: ufame Date: Mon, 23 Oct 2023 23:14:19 +0500 Subject: [PATCH 2/3] Bump version --- scripting/player_prefs.sma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripting/player_prefs.sma b/scripting/player_prefs.sma index 8d65e4d..af11ee6 100644 --- a/scripting/player_prefs.sma +++ b/scripting/player_prefs.sma @@ -45,7 +45,7 @@ new Handle: g_hSqlTuple; new bool: g_bDebugMode; public plugin_init() { - register_plugin("Player preferences", "1.1.0", "ufame"); + register_plugin("Player preferences", "1.1.1", "ufame"); CreateForwards(); CreateCvars(); From 1a3645f741bc29339b6eeb8ed62b67fb9f0f28ef Mon Sep 17 00:00:00 2001 From: ufame Date: Thu, 2 Nov 2023 01:24:01 +0500 Subject: [PATCH 3/3] fix: inability to connect to db at server startup --- configs/player_prefs.json | 6 ++++++ scripting/player_prefs.sma | 19 ++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 configs/player_prefs.json diff --git a/configs/player_prefs.json b/configs/player_prefs.json new file mode 100644 index 0000000..abc2326 --- /dev/null +++ b/configs/player_prefs.json @@ -0,0 +1,6 @@ +{ + "host": "127.0.0.1", + "user": "", + "pass": "", + "db": "server_db" +} \ No newline at end of file diff --git a/scripting/player_prefs.sma b/scripting/player_prefs.sma index af11ee6..1eb515f 100644 --- a/scripting/player_prefs.sma +++ b/scripting/player_prefs.sma @@ -1,11 +1,14 @@ #include #include #include +#include #pragma semicolon 1 const MAX_QUERY_LENGTH = 4096; +new const CONFIG_FILE[] = "addons/amxmodx/configs/player_prefs.json"; + enum { State_LoadKeys, State_LoadPlayer, @@ -48,7 +51,7 @@ public plugin_init() { register_plugin("Player preferences", "1.1.1", "ufame"); CreateForwards(); - CreateCvars(); + ReadDbCreadentials(); g_bDebugMode = bool: (plugin_flags() & AMX_FLAG_DEBUG); } @@ -379,13 +382,15 @@ public ThreadQuery_Handler(iFailState, Handle: hQuery, szError[], iError, szData } } -CreateCvars() { - bind_pcvar_string(create_cvar("pp_host", "Host", FCVAR_SPONLY | FCVAR_PROTECTED | FCVAR_UNLOGGED), g_szSqlHost, charsmax(g_szSqlHost)); - bind_pcvar_string(create_cvar("pp_user", "User", FCVAR_SPONLY | FCVAR_PROTECTED | FCVAR_UNLOGGED), g_szSqlUser, charsmax(g_szSqlUser)); - bind_pcvar_string(create_cvar("pp_pass", "Password", FCVAR_SPONLY | FCVAR_PROTECTED | FCVAR_UNLOGGED), g_szSqlPassword, charsmax(g_szSqlPassword)); - bind_pcvar_string(create_cvar("pp_db", "Database", FCVAR_SPONLY | FCVAR_PROTECTED | FCVAR_UNLOGGED), g_szSqlDatabase, charsmax(g_szSqlDatabase)); +ReadDbCreadentials() { + new JSON: credsConfig = json_parse(CONFIG_FILE, true); + + json_object_get_string(credsConfig, "host", g_szSqlHost, charsmax(g_szSqlHost)); + json_object_get_string(credsConfig, "user", g_szSqlUser, charsmax(g_szSqlUser)); + json_object_get_string(credsConfig, "pass", g_szSqlPassword, charsmax(g_szSqlPassword)); + json_object_get_string(credsConfig, "db", g_szSqlDatabase, charsmax(g_szSqlDatabase)); - AutoExecConfig(); + json_free(credsConfig); ConnectionTest(); }