From 66069aa2d1364c989ee1d003b24f5384945325cf Mon Sep 17 00:00:00 2001 From: Adrian Cirstea <54354938+ShadowsAdi@users.noreply.github.com> Date: Fri, 6 Sep 2024 12:07:53 +0300 Subject: [PATCH 1/2] Improved `amx_change_pass` command --- addons/amxmodx/scripting/csgo_remake.sma | 63 ++++++++++++++++++------ 1 file changed, 49 insertions(+), 14 deletions(-) diff --git a/addons/amxmodx/scripting/csgo_remake.sma b/addons/amxmodx/scripting/csgo_remake.sma index 1786a73..0214d37 100644 --- a/addons/amxmodx/scripting/csgo_remake.sma +++ b/addons/amxmodx/scripting/csgo_remake.sma @@ -10348,30 +10348,65 @@ public concmd_changepass(id, level, cid) read_argv(1, arg1, charsmax(arg1)) read_argv(2, arg2, charsmax(arg2)) - new target = cmd_target(id, arg1, CMDTARGET_ALLOW_SELF) - - if (!target) + if (strlen(arg2) < 6) { - console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_T_NOT_FOUND", arg1) + console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_T_PASSWORD_SHORT", arg2) return PLUGIN_HANDLED } - - new len = strlen(g_szUser_SavedPass[target]) - if (len > 6) + new szQuery[95] + formatex(szQuery, charsmax(szQuery), "SELECT `Password` FROM `csgor_data` WHERE `Name` = ^"%s^";", arg1) + + new szData[35 + MAX_NAME_LENGTH] + formatex(szData, charsmax(szData), "%d;%s=%s", id, arg1, arg2) + + SQL_ThreadQuery(g_hSqlTuple, "QueryPlayerChangePW", szQuery, szData, charsmax(szData)) + + return PLUGIN_HANDLED +} + +public QueryPlayerChangePW(iFailState, Handle:iQuery, Error[], Errcode, szData[], iSize, Float:flQueueTime) +{ + switch(iFailState) + { + case TQUERY_CONNECT_FAILED: + { + log_to_file("csgo_remake_errors.log", "[SQL Error] Connection failed (%i): %s", Errcode, Error) + } + case TQUERY_QUERY_FAILED: + { + log_to_file("csgo_remake_errors.log", "[SQL Error] Query failed (%i): %s", Errcode, Error) + } + } + + new arg1[MAX_NAME_LENGTH], arg2[32], index[3], id + + strtok(szData, index, charsmax(index), szData, iSize, ';') + + id = str_to_num(index) + + strtok(szData, arg1, charsmax(arg1), szData, iSize, '=') + + strtok(szData, arg2, charsmax(arg2), szData, iSize) + + if(iFailState) { - copy(g_szUser_SavedPass[target], charsmax(g_szUser_SavedPass[]), arg2) - console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_PASSWORD_CHANGED", target, arg2) - client_print_color(target, print_chat, "^4%s ^1%L", CSGO_TAG, LANG_SERVER, "CSGOR_ADMIN_CHANGED_PASSWORD", g_szName[id], arg2) + console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_ERROR_QUERYING") + return } - else + + console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_PASSWORD_CHANGED", arg1, arg2) + + new target = get_user_index(arg1) + if(is_user_connected(target)) { - console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_T_NOT_FOUND_IN_DBASE", target) + client_print_color(target, print_chat, "^4%s ^1%L", CSGO_TAG, LANG_SERVER, "CSGOR_ADMIN_CHANGED_PASSWORD", id ? g_szName[id] : "Administrator", arg2) } - _Save(target) + new szQuery[95] + formatex(szQuery, charsmax(szQuery), "UPDATE `csgor_data` SET `Password` = ^"%s%^" WHERE `Name` = ^"%s^";", arg2, arg1) - return PLUGIN_HANDLED + SQL_ThreadQuery(g_hSqlTuple, "QueryHandler", szQuery) } public concmd_getinfo(id, level, cid) From 86ed5494ff2e8563fc6f242ef9b29001838d2f64 Mon Sep 17 00:00:00 2001 From: Adrian Cirstea <54354938+ShadowsAdi@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:54:21 +0300 Subject: [PATCH 2/2] Administration commands improvements and fixes - fixed `amx_nick_csgo` command - reworked `amx_resetdata` command and added mode 2 ( resetting only specific data: Kills, Points, Rank, etc ) --- addons/amxmodx/data/lang/csgor_language.txt | 26 ++++ addons/amxmodx/scripting/csgo_remake.sma | 139 +++++++++++++------- 2 files changed, 116 insertions(+), 49 deletions(-) diff --git a/addons/amxmodx/data/lang/csgor_language.txt b/addons/amxmodx/data/lang/csgor_language.txt index a6e90c9..7b4b71f 100644 --- a/addons/amxmodx/data/lang/csgor_language.txt +++ b/addons/amxmodx/data/lang/csgor_language.txt @@ -306,6 +306,19 @@ CSGOR_GIVEAWAY_CLOSED = Giveaway-ul este ^4inchis ^1pentru moment. CSGOR_LOADING_DATA = Datele tale sunt in curs de ^4incarcare^1. CSGOR_DATA_LOADED = Datele tale au fost ^4incarcate cu succes^1. +CSGOR_ADMIN_CHANGE_X_NICK = Adminul ^4%s^1 a schimbat numele lui ^4%s^1 in ^4%s^1. +CSGOR_CHANGED_NICK = Adminul ^4%s^1 ti-a schimbat numele in ^4%s^1. + +CSGOR_T_PASSWORD_SHORT = Parola %s este prea scurta! + +CSGOR_ERROR_QUERYING = Eroare in interogarea bazei de date! +CSGOR_INVALID_ARGUMENT = Argumentul %d este invalid: %s + +CSGOR_ACCOUNT_RESET = Contul %s a fost resetat +CSGOR_ACCOUNT_REMOVED = Contul %s a fost sters +CSGOR_ACCOUNT_RESET_ITEM = Contului %s i-a fost resetat %s +CSOGR_ACCOUNT_NOT_FOUND = Contul %s nu a fost gasit! + [en] CSGOR_NO_DROP_SKINS = There are no drop type skins! CSGOR_NO_CRAFT_SKINS = There are no craft type skins! @@ -614,3 +627,16 @@ CSGOR_GIVEAWAY_CLOSED = Giveaway is ^4closed ^1for now. CSGOR_LOADING_DATA = Your account is being ^4loaded^1 please wait. CSGOR_DATA_LOADED = Your data has been ^4successfully loaded^1. + +CSGOR_ADMIN_CHANGE_X_NICK = Admin ^4%s^1 has changed ^4%s^1's name in ^4%s^1. +CSGOR_CHANGED_NICK = Admin ^4%s^1 has changed your name in ^4%s^1. + +CSGOR_T_PASSWORD_SHORT = The password %s is too short! + +CSGOR_ERROR_QUERYING = Error querying the database! +CSGOR_INVALID_ARGUMENT = Invalid argument number %d: %s + +CSGOR_ACCOUNT_RESET = Account %s has been reset +CSGOR_ACCOUNT_REMOVED = Account %s has been removed +CSGOR_ACCOUNT_RESET_ITEM = Account's %s got %s reset +CSOGR_ACCOUNT_NOT_FOUND = Account %s has not been found! \ No newline at end of file diff --git a/addons/amxmodx/scripting/csgo_remake.sma b/addons/amxmodx/scripting/csgo_remake.sma index 0214d37..1ab59c4 100644 --- a/addons/amxmodx/scripting/csgo_remake.sma +++ b/addons/amxmodx/scripting/csgo_remake.sma @@ -10196,7 +10196,7 @@ public concmd_finddata(id, level, cid) if(!SQL_Execute(iQuery)) { SQL_QueryError(iQuery, g_szSqlError, charsmax(g_szSqlError)) - log_to_file("csgo_remake_errors.log", "test %s", g_szSqlError) + log_to_file("csgo_remake_errors.log", "SQL Error: %s", g_szSqlError) SQL_FreeHandle(iQuery) } @@ -10218,7 +10218,7 @@ public concmd_finddata(id, level, cid) if(!SQL_Execute(iQuery)) { SQL_QueryError(iQuery, g_szSqlError, charsmax(g_szSqlError)) - log_to_file("csgo_remake_errors.log", "test2 %s", g_szSqlError) + log_to_file("csgo_remake_errors.log", "%s", g_szSqlError) } if(SQL_NumResults(iQuery) > 0) @@ -10257,81 +10257,121 @@ public concmd_resetdata(id, level, cid) log_to_file("csgor_debug_logs.log", "concmd_resetdata()") #endif - if (!cmd_access(id, level, cid, 3, false) || !is_user_connected(id)) + if (!cmd_access(id, level, cid, 3, false)) return PLUGIN_HANDLED new arg1[32] new arg2[4] + new arg3[17] read_argv(1, arg1, charsmax(arg1)) read_argv(2, arg2, charsmax(arg2)) - // TODO: REWORK FOR SQL - /* + new type = str_to_num(arg2) + new szQuery[200] - if (g_Vault == INVALID_HANDLE) + new Handle:iQuery = SQL_PrepareQuery(g_iSqlConnection, "SELECT * FROM `csgor_data` WHERE `Name` = ^"%s^"", arg1) + if(!SQL_Execute(iQuery)) { - console_print(id, "%s Reading from vault has failed !", CSGO_TAG) - return PLUGIN_HANDLED + SQL_QueryError(iQuery, g_szSqlError, charsmax(g_szSqlError)) + log_to_file("csgo_remake_errors.log", "SQL Error: %s", g_szSqlError) } - new g_szData[MAX_SKINS * 3 + 94] - new g_iWeapszBuffer[MAX_SKINS * 2] - new Timestamp + if(!SQL_NumResults(iQuery)) + { + console_print(id, "%s %L", CSGO_TAG, id, "CSOGR_ACCOUNT_NOT_FOUND", arg1) + return PLUGIN_HANDLED + } - if (nvault_lookup(g_Vault, arg1, g_szData, charsmax(g_szData), Timestamp)) + switch(type) { - new index = get_user_index(arg1) - if(index) + case 0: { - g_bLogged[index] = false + formatex(szQuery, charsmax(szQuery), "DELETE FROM `csgor_skins` WHERE `Name` = ^"%s^";", arg1) } - - if (0 < type) + case 1: { - nvault_remove(g_Vault, arg1) - nvault_remove(g_nVault, arg1) - nvault_remove(g_sVault, arg1) - nvault_remove(g_pVault, arg1) - ResetData(id, true) - console_print(id, "%s The account has been removed: %s", CSGO_TAG, arg1) - return PLUGIN_HANDLED + formatex(szQuery, charsmax(szQuery), "SET SQL_SAFE_UPDATES = 0; \ + DELETE FROM `csgor_data` WHERE `Name` = ^"%s^"; \ + DELETE FROM `csgor_skins` WHERE `Name` = ^"%s^"; \ + SET SQL_SAFE_UPDATES = 1;", arg1, arg1) } + case 2: + { + read_argv(3, arg3, charsmax(arg3)) - new infoBuffer[MAX_SKIN_NAME] - new skinBuffer[MAX_SKINS] - new password[16] + if(strlen(arg3) < 4) + { + console_print(id, "%L", id, "CSGOR_INVALID_ARGUMENT", 3, arg3) + return PLUGIN_HANDLED + } - strtok(g_szData, password, charsmax(password), g_szData, charsmax(g_szData), '=', 0) + formatex(szQuery, charsmax(szQuery), "UPDATE `csgor_data` SET `%s`= 0 WHERE `Name` = ^"%s^";", arg3, arg1) + } + } - formatex(infoBuffer, charsmax(infoBuffer), "%s=,;%d,%d,%d,%d,%d,%d", password, 0, 0, 0, 0, 0, 0) - formatex(g_iWeapszBuffer, charsmax(g_iWeapszBuffer), "%d", 0) + new index = get_user_index(arg1) + if(index) + g_bLogged[index] = false - for (new i = 1; i < MAX_SKINS; i++) - { - format(g_iWeapszBuffer, charsmax(g_iWeapszBuffer), "%s,0", g_iWeapszBuffer) - } + new szData[MAX_NAME_LENGTH + 5 + 6 + 18] + formatex(szData, charsmax(szData), "%s;%s#%s=%d", arg1, arg2, arg3, id) - formatex(skinBuffer, charsmax(skinBuffer), "%d", 0) + SQL_ThreadQuery(g_hSqlTuple, "QueryResetData", szQuery, szData, charsmax(szData)) - for (new i = 2; i <= 30; i++) + return PLUGIN_HANDLED +} + +public QueryResetData(iFailState, Handle:iQuery, Error[], Errcode, szData[], iSize, Float:flQueueTime) +{ + switch(iFailState) + { + case TQUERY_CONNECT_FAILED: { - format(skinBuffer, charsmax(skinBuffer), "%s,0", skinBuffer) + log_to_file("csgo_remake_errors.log", "[SQL Error] Connection failed (%i): %s", Errcode, Error) } + case TQUERY_QUERY_FAILED: + { + log_to_file("csgo_remake_errors.log", "[SQL Error] Query failed (%i): %s", Errcode, Error) + } + } + + new arg1[MAX_NAME_LENGTH], arg2[4], arg3[17], index[3], id + + strtok(szData, arg1, charsmax(arg1), szData, iSize, ';') + + strtok(szData, arg2, charsmax(arg2), szData, iSize, '#') - formatex(g_szData, charsmax(g_szData), "%s*%s#%s", infoBuffer, g_iWeapszBuffer, skinBuffer) - nvault_set(g_Vault, arg1, g_szData) + strtok(szData, arg3, charsmax(arg3), szData, iSize, '=') - console_print(id, "%s The account has been reseted: %s", CSGO_TAG, arg1) + strtok(szData, index, charsmax(index), szData, iSize) - ResetData(id, true) - _Save(index) + id = str_to_num(index) + + if(iFailState) + { + console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_ERROR_QUERYING") + return } - else + + switch(arg2[0]) { - console_print(id, "%s The account was not found: %s", CSGO_TAG, arg1) - }*/ + case '0': + { + console_print(id, "%s %L", CSGO_TAG, id, "CSGOR_ACCOUNT_RESET", arg1) + } + case '1': + { + console_print(id, "%s %L", CSGO_TAG, id, "CSGOR_ACCOUNT_REMOVED", arg1) + } + case '2': + { + console_print(id, "%s %L", CSGO_TAG, id, "CSGOR_ACCOUNT_RESET_ITEM", arg1, arg3) + } + } - return PLUGIN_HANDLED + new pid = get_user_index(arg1) + if(pid) + _Load(pid) } public concmd_changepass(id, level, cid) @@ -10504,14 +10544,15 @@ public concmd_nick(id, level, cid) } g_eEnumBooleans[player][IsChangeNotAllowed] = true - set_user_info(player, "name", arg2) client_print_color(0, print_chat, "^4%s^1 %L", CSGO_TAG, LANG_SERVER, "CSGOR_ADMIN_CHANGE_X_NICK", g_szName[id], g_szName[player], arg2) - set_task(0.5, "task_Reset_Name", id + TASK_RESET_NAME) - console_print(id, "%s %L", CSGO_TAG, LANG_SERVER, "CSGOR_CHANGED_NICK", g_szName[player], arg2) + copy(g_szName[player], charsmax(g_szName[]), arg2) + + set_task(0.5, "task_Reset_Name", id + TASK_RESET_NAME) + return PLUGIN_HANDLED }