From c62dcffa0e3a5f69d025e9c58709a41befd9cadf Mon Sep 17 00:00:00 2001 From: tlsharkie <135812037+tlsharkie@users.noreply.github.com> Date: Fri, 14 Mar 2025 23:20:36 -0700 Subject: [PATCH 1/2] Update server/player.lua Updated `Delete character` code to handle database tables where primary key is not `citizenid` Changed `playertables` format to handle any primary key Updated `DeleteCharater()` and `ForceDeleteCharater()` SQL commands --- server/player.lua | 62 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/server/player.lua b/server/player.lua index 4f73c0d30..57987f11c 100644 --- a/server/player.lua +++ b/server/player.lua @@ -529,42 +529,65 @@ end -- Delete character -local playertables = { -- Add tables as needed - { table = 'players' }, - { table = 'apartments' }, - { table = 'bank_accounts' }, - { table = 'crypto_transactions' }, - { table = 'phone_invoices' }, - { table = 'phone_messages' }, - { table = 'playerskins' }, - { table = 'player_contacts' }, - { table = 'player_houses' }, - { table = 'player_mails' }, - { table = 'player_outfits' }, - { table = 'player_vehicles' } +local playertables = { -- Add tables as needed + --- + --- 'table' is the new SQL table name + --- 'key' is the column name which contains the 'citizenid' + --- + --Tables where primary key = 'citizenid' + { table = 'players', key = 'citizenid' }, + { table = 'apartments', key = 'citizenid' }, + { table = 'bank_accounts', key = 'citizenid' }, + { table = 'bank_statements', key = 'citizenid' }, + { table = 'crypto_transactions', key = 'citizenid' }, + { table = 'player_houses', key = 'citizenid' }, + { table = 'player_outfits', key = 'citizenid' }, + { table = 'player_vehicles', key = 'citizenid' }, + { table = 'playerskins', key = 'citizenid' }, + + --Tables where primary key = 'cid' + { table = 'phone_invoices', key = 'cid' }, + { table = 'phone_messages', key = 'cid' }, + + --Tables where primary key = 'identifier' + { table = 'player_contacts', key = 'identifier' }, + { table = 'bank_cards', key = 'identifier' }, + { table = 'bank_history', key = 'identifier' }, + { table = 'casino_players', key = 'identifier' }, + { table = 'cd_garage_privategarage', key = 'identifier' }, + { table = 'inventory_clothes', key = 'identifier' }, + { table = 'lation_detecting', key = 'identifier' }, + { table = 'm_hunting', key = 'identifier' }, + + --Tables with other citizenid labels + { table = 'bank_process', key = 'owner' }, + { table = 'mail_accounts', key = 'owner' }, + { table = 'lation_chopshop', key = 'player_identifier' }, } function QBCore.Player.DeleteCharacter(source, citizenid) local license = QBCore.Functions.GetIdentifier(source, 'license') local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid }) if license == result then - local query = 'DELETE FROM %s WHERE citizenid = ?' + local query = 'DELETE FROM %s WHERE %s = ?' local tableCount = #playertables local queries = table.create(tableCount, 0) for i = 1, tableCount do local v = playertables[i] - queries[i] = { query = query:format(v.table), values = { citizenid } } + queries[i] = { query = query:format(v.table, v.key), values = { citizenid } } end MySQL.transaction(queries, function(result2) if result2 then - TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..') + TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', + '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..') end end) else DropPlayer(source, Lang:t('info.exploit_dropped')) - TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', GetPlayerName(source) .. ' Has Been Dropped For Character Deletion Exploit', true) + TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', + GetPlayerName(source) .. ' Has Been Dropped For Character Deletion Exploit', true) end end @@ -581,12 +604,13 @@ function QBCore.Player.ForceDeleteCharacter(citizenid) end for i = 1, tableCount do local v = playertables[i] - queries[i] = { query = query:format(v.table), values = { citizenid } } + queries[i] = { query = query:format(v.table, v.key), values = { citizenid } } end MySQL.transaction(queries, function(result2) if result2 then - TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red', 'Character **' .. citizenid .. '** got deleted') + TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red', + 'Character **' .. citizenid .. '** got deleted') end end) end From 9a543d9c3b5be27991a0fbe1d5c2b74146550679 Mon Sep 17 00:00:00 2001 From: tlsharkie <135812037+tlsharkie@users.noreply.github.com> Date: Wed, 1 Oct 2025 14:16:25 -0700 Subject: [PATCH 2/2] Update player.lua Updated player.lua to only include default QBCore tables for the character deletion. --- server/player.lua | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/server/player.lua b/server/player.lua index 57987f11c..1f53203cf 100644 --- a/server/player.lua +++ b/server/player.lua @@ -530,39 +530,25 @@ end -- Delete character local playertables = { -- Add tables as needed - --- --- 'table' is the new SQL table name --- 'key' is the column name which contains the 'citizenid' - --- - --Tables where primary key = 'citizenid' + + -- Tables where primary key = 'citizenid' { table = 'players', key = 'citizenid' }, { table = 'apartments', key = 'citizenid' }, { table = 'bank_accounts', key = 'citizenid' }, - { table = 'bank_statements', key = 'citizenid' }, { table = 'crypto_transactions', key = 'citizenid' }, { table = 'player_houses', key = 'citizenid' }, { table = 'player_outfits', key = 'citizenid' }, { table = 'player_vehicles', key = 'citizenid' }, { table = 'playerskins', key = 'citizenid' }, + { table = 'phone_invoices', key = 'citizenid' }, + { table = 'phone_messages', key = 'citizenid' }, + { table = 'player_contacts', key = 'citizenid' }, - --Tables where primary key = 'cid' - { table = 'phone_invoices', key = 'cid' }, - { table = 'phone_messages', key = 'cid' }, - - --Tables where primary key = 'identifier' - { table = 'player_contacts', key = 'identifier' }, - { table = 'bank_cards', key = 'identifier' }, - { table = 'bank_history', key = 'identifier' }, - { table = 'casino_players', key = 'identifier' }, - { table = 'cd_garage_privategarage', key = 'identifier' }, - { table = 'inventory_clothes', key = 'identifier' }, - { table = 'lation_detecting', key = 'identifier' }, - { table = 'm_hunting', key = 'identifier' }, - - --Tables with other citizenid labels - { table = 'bank_process', key = 'owner' }, - { table = 'mail_accounts', key = 'owner' }, - { table = 'lation_chopshop', key = 'player_identifier' }, + --- + --- Tables where primary key is not 'citizenid' + --- Example: { table = 'TABLE_NAME', key = 'CITIZEN_IDENTIFIER' }, } function QBCore.Player.DeleteCharacter(source, citizenid)