Skip to content

Commit c62dcff

Browse files
committed
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
1 parent e1151d0 commit c62dcff

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

server/player.lua

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -529,42 +529,65 @@ end
529529

530530
-- Delete character
531531

532-
local playertables = { -- Add tables as needed
533-
{ table = 'players' },
534-
{ table = 'apartments' },
535-
{ table = 'bank_accounts' },
536-
{ table = 'crypto_transactions' },
537-
{ table = 'phone_invoices' },
538-
{ table = 'phone_messages' },
539-
{ table = 'playerskins' },
540-
{ table = 'player_contacts' },
541-
{ table = 'player_houses' },
542-
{ table = 'player_mails' },
543-
{ table = 'player_outfits' },
544-
{ table = 'player_vehicles' }
532+
local playertables = { -- Add tables as needed
533+
---
534+
--- 'table' is the new SQL table name
535+
--- 'key' is the column name which contains the 'citizenid'
536+
---
537+
--Tables where primary key = 'citizenid'
538+
{ table = 'players', key = 'citizenid' },
539+
{ table = 'apartments', key = 'citizenid' },
540+
{ table = 'bank_accounts', key = 'citizenid' },
541+
{ table = 'bank_statements', key = 'citizenid' },
542+
{ table = 'crypto_transactions', key = 'citizenid' },
543+
{ table = 'player_houses', key = 'citizenid' },
544+
{ table = 'player_outfits', key = 'citizenid' },
545+
{ table = 'player_vehicles', key = 'citizenid' },
546+
{ table = 'playerskins', key = 'citizenid' },
547+
548+
--Tables where primary key = 'cid'
549+
{ table = 'phone_invoices', key = 'cid' },
550+
{ table = 'phone_messages', key = 'cid' },
551+
552+
--Tables where primary key = 'identifier'
553+
{ table = 'player_contacts', key = 'identifier' },
554+
{ table = 'bank_cards', key = 'identifier' },
555+
{ table = 'bank_history', key = 'identifier' },
556+
{ table = 'casino_players', key = 'identifier' },
557+
{ table = 'cd_garage_privategarage', key = 'identifier' },
558+
{ table = 'inventory_clothes', key = 'identifier' },
559+
{ table = 'lation_detecting', key = 'identifier' },
560+
{ table = 'm_hunting', key = 'identifier' },
561+
562+
--Tables with other citizenid labels
563+
{ table = 'bank_process', key = 'owner' },
564+
{ table = 'mail_accounts', key = 'owner' },
565+
{ table = 'lation_chopshop', key = 'player_identifier' },
545566
}
546567

547568
function QBCore.Player.DeleteCharacter(source, citizenid)
548569
local license = QBCore.Functions.GetIdentifier(source, 'license')
549570
local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
550571
if license == result then
551-
local query = 'DELETE FROM %s WHERE citizenid = ?'
572+
local query = 'DELETE FROM %s WHERE %s = ?'
552573
local tableCount = #playertables
553574
local queries = table.create(tableCount, 0)
554575

555576
for i = 1, tableCount do
556577
local v = playertables[i]
557-
queries[i] = { query = query:format(v.table), values = { citizenid } }
578+
queries[i] = { query = query:format(v.table, v.key), values = { citizenid } }
558579
end
559580

560581
MySQL.transaction(queries, function(result2)
561582
if result2 then
562-
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
583+
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red',
584+
'**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
563585
end
564586
end)
565587
else
566588
DropPlayer(source, Lang:t('info.exploit_dropped'))
567-
TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white', GetPlayerName(source) .. ' Has Been Dropped For Character Deletion Exploit', true)
589+
TriggerEvent('qb-log:server:CreateLog', 'anticheat', 'Anti-Cheat', 'white',
590+
GetPlayerName(source) .. ' Has Been Dropped For Character Deletion Exploit', true)
568591
end
569592
end
570593

@@ -581,12 +604,13 @@ function QBCore.Player.ForceDeleteCharacter(citizenid)
581604
end
582605
for i = 1, tableCount do
583606
local v = playertables[i]
584-
queries[i] = { query = query:format(v.table), values = { citizenid } }
607+
queries[i] = { query = query:format(v.table, v.key), values = { citizenid } }
585608
end
586609

587610
MySQL.transaction(queries, function(result2)
588611
if result2 then
589-
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red', 'Character **' .. citizenid .. '** got deleted')
612+
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Force Deleted', 'red',
613+
'Character **' .. citizenid .. '** got deleted')
590614
end
591615
end)
592616
end

0 commit comments

Comments
 (0)