mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-30 01:38:56 +00:00
Remove QBCore.Functions.ExecuteSql
This commit is contained in:
+96
-94
@@ -4,22 +4,21 @@ QBCore.Player = {}
|
||||
QBCore.Player.Login = function(source, citizenid, newData)
|
||||
if source ~= nil then
|
||||
if citizenid then
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..citizenid.."'", function(result)
|
||||
local PlayerData = result[1]
|
||||
if PlayerData ~= nil then
|
||||
PlayerData.money = json.decode(PlayerData.money)
|
||||
PlayerData.job = json.decode(PlayerData.job)
|
||||
PlayerData.position = json.decode(PlayerData.position)
|
||||
PlayerData.metadata = json.decode(PlayerData.metadata)
|
||||
PlayerData.charinfo = json.decode(PlayerData.charinfo)
|
||||
if PlayerData.gang ~= nil then
|
||||
PlayerData.gang = json.decode(PlayerData.gang)
|
||||
else
|
||||
PlayerData.gang = {}
|
||||
end
|
||||
local result = exports['ghmattimysql']:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = citizenid})
|
||||
local PlayerData = result[1]
|
||||
if PlayerData ~= nil then
|
||||
PlayerData.money = json.decode(PlayerData.money)
|
||||
PlayerData.job = json.decode(PlayerData.job)
|
||||
PlayerData.position = json.decode(PlayerData.position)
|
||||
PlayerData.metadata = json.decode(PlayerData.metadata)
|
||||
PlayerData.charinfo = json.decode(PlayerData.charinfo)
|
||||
if PlayerData.gang ~= nil then
|
||||
PlayerData.gang = json.decode(PlayerData.gang)
|
||||
else
|
||||
PlayerData.gang = {}
|
||||
end
|
||||
QBCore.Player.CheckPlayerData(source, PlayerData)
|
||||
end)
|
||||
end
|
||||
QBCore.Player.CheckPlayerData(source, PlayerData)
|
||||
else
|
||||
QBCore.Player.CheckPlayerData(source, newData)
|
||||
end
|
||||
@@ -417,35 +416,34 @@ end
|
||||
QBCore.Player.Save = function(source)
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
if PlayerData ~= nil then
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(result)
|
||||
if result[1] == nil then
|
||||
exports.ghmattimysql:execute('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (@citizenid, @cid, @license, @name, @money, @charinfo, @job, @gang, @position, @metadata)', {
|
||||
['@citizenid'] = PlayerData.citizenid,
|
||||
['@cid'] = tonumber(PlayerData.cid),
|
||||
['@license'] = PlayerData.license,
|
||||
['@name'] = PlayerData.name,
|
||||
['@money'] = json.encode(PlayerData.money),
|
||||
['@charinfo'] = json.encode(PlayerData.charinfo),
|
||||
['@job'] = json.encode(PlayerData.job),
|
||||
['@gang'] = json.encode(PlayerData.gang),
|
||||
['@position'] = json.encode(PlayerData.position),
|
||||
['@metadata'] = json.encode(PlayerData.metadata)
|
||||
})
|
||||
else
|
||||
exports.ghmattimysql:execute('UPDATE players SET license=@license, name=@name, money=@money, charinfo=@charinfo, job=@job, gang=@gang, position=@position, metadata=@metadata WHERE citizenid=@citizenid', {
|
||||
['@citizenid'] = PlayerData.citizenid,
|
||||
['@license'] = PlayerData.license,
|
||||
['@name'] = PlayerData.name,
|
||||
['@money'] = json.encode(PlayerData.money),
|
||||
['@charinfo'] = json.encode(PlayerData.charinfo),
|
||||
['@job'] = json.encode(PlayerData.job),
|
||||
['@gang'] = json.encode(PlayerData.gang),
|
||||
['@position'] = json.encode(PlayerData.position),
|
||||
['@metadata'] = json.encode(PlayerData.metadata)
|
||||
})
|
||||
end
|
||||
QBCore.Player.SaveInventory(source)
|
||||
end)
|
||||
local result = exports.ghmattimysql:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = citizenid})
|
||||
if result[1] == nil then
|
||||
exports.ghmattimysql:execute('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (@citizenid, @cid, @license, @name, @money, @charinfo, @job, @gang, @position, @metadata)', {
|
||||
['@citizenid'] = PlayerData.citizenid,
|
||||
['@cid'] = tonumber(PlayerData.cid),
|
||||
['@license'] = PlayerData.license,
|
||||
['@name'] = PlayerData.name,
|
||||
['@money'] = json.encode(PlayerData.money),
|
||||
['@charinfo'] = json.encode(PlayerData.charinfo),
|
||||
['@job'] = json.encode(PlayerData.job),
|
||||
['@gang'] = json.encode(PlayerData.gang),
|
||||
['@position'] = json.encode(PlayerData.position),
|
||||
['@metadata'] = json.encode(PlayerData.metadata)
|
||||
})
|
||||
else
|
||||
exports.ghmattimysql:execute('UPDATE players SET license=@license, name=@name, money=@money, charinfo=@charinfo, job=@job, gang=@gang, position=@position, metadata=@metadata WHERE citizenid=@citizenid', {
|
||||
['@citizenid'] = PlayerData.citizenid,
|
||||
['@license'] = PlayerData.license,
|
||||
['@name'] = PlayerData.name,
|
||||
['@money'] = json.encode(PlayerData.money),
|
||||
['@charinfo'] = json.encode(PlayerData.charinfo),
|
||||
['@job'] = json.encode(PlayerData.job),
|
||||
['@gang'] = json.encode(PlayerData.gang),
|
||||
['@position'] = json.encode(PlayerData.position),
|
||||
['@metadata'] = json.encode(PlayerData.metadata)
|
||||
})
|
||||
end
|
||||
QBCore.Player.SaveInventory(source)
|
||||
QBCore.ShowSuccess(GetCurrentResourceName(), PlayerData.name .." PLAYER SAVED!")
|
||||
else
|
||||
QBCore.ShowError(GetCurrentResourceName(), "ERROR QBCORE.PLAYER.SAVE - PLAYERDATA IS EMPTY!")
|
||||
@@ -463,7 +461,6 @@ local playertables = {
|
||||
{table = "players"},
|
||||
{table = "apartments"},
|
||||
{table = "bank_accounts"},
|
||||
{table = "bills"},
|
||||
{table = "crypto_transactions"},
|
||||
{table = "phone_invoices"},
|
||||
{table = "phone_messages"},
|
||||
@@ -477,43 +474,49 @@ local playertables = {
|
||||
}
|
||||
|
||||
QBCore.Player.DeleteCharacter = function(source, citizenid)
|
||||
for k,v in pairs(playertables) do
|
||||
QBCore.Functions.ExecuteSql(true, "DELETE FROM `"..v.table.."` WHERE `citizenid` = '"..citizenid.."'")
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
local result = exports.ghmattimysql:scalarSync('SELECT license FROM players where citizenid = ?', {citizenid})
|
||||
if license == result then
|
||||
for k,v in pairs(playertables) do
|
||||
exports.ghmattimysql:execute('DELETE FROM '..v.table..' WHERE citizenid = ?', {citizenid})
|
||||
end
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..QBCore.Functions.GetIdentifier(source, 'license')..") deleted **"..citizenid.."**..")
|
||||
else
|
||||
DropPlayer(source, 'You Have Been Kicked For Exploitation')
|
||||
TriggerEvent("qb-log:server:CreateLog", "anticheat", "Anti-Cheat", "white", GetPlayerName(source).." Has Been Dropped For Character Deletion Exploit", false)
|
||||
end
|
||||
TriggerEvent("qb-log:server:CreateLog", "joinleave", "Character Deleted", "red", "**".. GetPlayerName(source) .. "** ("..QBCore.Functions.GetIdentifier(source, 'license')..") deleted **"..citizenid.."**..")
|
||||
end
|
||||
|
||||
QBCore.Player.LoadInventory = function(PlayerData)
|
||||
PlayerData.items = {}
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT * FROM `players` WHERE `citizenid` = '"..PlayerData.citizenid.."'", function(result)
|
||||
if result[1] ~= nil then
|
||||
if result[1].inventory ~= nil then
|
||||
plyInventory = json.decode(result[1].inventory)
|
||||
if next(plyInventory) ~= nil then
|
||||
for _, item in pairs(plyInventory) do
|
||||
if item ~= nil then
|
||||
local itemInfo = QBCore.Shared.Items[item.name:lower()]
|
||||
PlayerData.items[item.slot] = {
|
||||
name = itemInfo["name"],
|
||||
amount = item.amount,
|
||||
info = item.info ~= nil and item.info or "",
|
||||
label = itemInfo["label"],
|
||||
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
|
||||
weight = itemInfo["weight"],
|
||||
type = itemInfo["type"],
|
||||
unique = itemInfo["unique"],
|
||||
useable = itemInfo["useable"],
|
||||
image = itemInfo["image"],
|
||||
shouldClose = itemInfo["shouldClose"],
|
||||
slot = item.slot,
|
||||
combinable = itemInfo["combinable"]
|
||||
}
|
||||
end
|
||||
local result = exports['ghmattimysql']:executeSync('SELECT * FROM players WHERE citizenid=@citizenid', {['@citizenid'] = PlayerData.citizenid})
|
||||
if result[1] ~= nil then
|
||||
if result[1].inventory ~= nil then
|
||||
plyInventory = json.decode(result[1].inventory)
|
||||
if next(plyInventory) ~= nil then
|
||||
for _, item in pairs(plyInventory) do
|
||||
if item ~= nil then
|
||||
local itemInfo = QBCore.Shared.Items[item.name:lower()]
|
||||
PlayerData.items[item.slot] = {
|
||||
name = itemInfo["name"],
|
||||
amount = item.amount,
|
||||
info = item.info ~= nil and item.info or "",
|
||||
label = itemInfo["label"],
|
||||
description = itemInfo["description"] ~= nil and itemInfo["description"] or "",
|
||||
weight = itemInfo["weight"],
|
||||
type = itemInfo["type"],
|
||||
unique = itemInfo["unique"],
|
||||
useable = itemInfo["useable"],
|
||||
image = itemInfo["image"],
|
||||
shouldClose = itemInfo["shouldClose"],
|
||||
slot = item.slot,
|
||||
combinable = itemInfo["combinable"]
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
return PlayerData
|
||||
end
|
||||
|
||||
@@ -578,11 +581,10 @@ QBCore.Player.CreateCitizenId = function()
|
||||
|
||||
while not UniqueFound do
|
||||
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `citizenid` = '"..CitizenId.."'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
local result = exports.ghmattimysql:executeSync('SELECT COUNT(*) as count FROM players WHERE citizenid=@citizenid', {['@citizenid'] = CitizenId})
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end
|
||||
return CitizenId
|
||||
end
|
||||
@@ -592,11 +594,11 @@ QBCore.Player.CreateFingerId = function()
|
||||
local FingerId = nil
|
||||
while not UniqueFound do
|
||||
FingerId = tostring(QBCore.Shared.RandomStr(2) .. QBCore.Shared.RandomInt(3) .. QBCore.Shared.RandomStr(1) .. QBCore.Shared.RandomInt(2) .. QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(4))
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE '%"..FingerId.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
local query = '%'..FingerId..'%'
|
||||
local result = exports.ghmattimysql:executeSync('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE @query', {['@query'] = query})
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end
|
||||
return FingerId
|
||||
end
|
||||
@@ -606,11 +608,11 @@ QBCore.Player.CreateWalletId = function()
|
||||
local WalletId = nil
|
||||
while not UniqueFound do
|
||||
WalletId = "QB-"..math.random(11111111, 99999999)
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE '%"..WalletId.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
local query = '%'..WalletId..'%'
|
||||
local result = exports.ghmattimysql:executeSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE @query', {['@query'] = query})
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end
|
||||
return WalletId
|
||||
end
|
||||
@@ -621,11 +623,11 @@ QBCore.Player.CreateSerialNumber = function()
|
||||
|
||||
while not UniqueFound do
|
||||
SerialNumber = math.random(11111111, 99999999)
|
||||
QBCore.Functions.ExecuteSql(true, "SELECT COUNT(*) as count FROM players WHERE metadata LIKE '%"..SerialNumber.."%'", function(result)
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end)
|
||||
local query = '%'..SerialNumber..'%'
|
||||
local result = exports.ghmattimysql:executeSync('SELECT COUNT(*) as count FROM players WHERE metadata LIKE @query', {['@query'] = query})
|
||||
if result[1].count == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
end
|
||||
return SerialNumber
|
||||
end
|
||||
@@ -635,4 +637,4 @@ QBCore.EscapeSqli = function(str)
|
||||
return str:gsub( "['\"]", replacements ) -- or string.gsub( source, "['\"]", replacements )
|
||||
end
|
||||
|
||||
PaycheckLoop()
|
||||
PaycheckLoop()
|
||||
Reference in New Issue
Block a user