Skip to content

Updated player deletion code to accommodate tables that do not use the column name citizenid #1187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,9 @@ function QBCore.Functions.CreateVehicle(source, model, vehtype, coords, warp)
end

function PaycheckInterval()
if not next(QBCore.Players) then
if not next(QBCore.Players) then
SetTimeout(QBCore.Config.Money.PayCheckTimeOut * (60 * 1000), PaycheckInterval) -- Prevent paychecks from stopping forever once 0 players
return
return
end
for _, Player in pairs(QBCore.Players) do
if not Player then return end
Expand Down
62 changes: 43 additions & 19 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down