mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-29 01:01:24 +00:00
MySQL Updates
This commit is contained in:
@@ -328,13 +328,13 @@ end
|
||||
|
||||
function QBCore.Functions.IsPlayerBanned(source)
|
||||
local plicense = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
local result = MySQL.Sync.fetchSingle('SELECT * FROM bans WHERE license = ?', { plicense })
|
||||
local result = MySQL.single.await('SELECT * FROM bans WHERE license = ?', { plicense })
|
||||
if not result then return false end
|
||||
if os.time() < result.expire then
|
||||
local timeTable = os.date('*t', tonumber(result.expire))
|
||||
return true, 'You have been banned from the server:\n' .. result.reason .. '\nYour ban expires ' .. timeTable.day .. '/' .. timeTable.month .. '/' .. timeTable.year .. ' ' .. timeTable.hour .. ':' .. timeTable.min .. '\n'
|
||||
else
|
||||
MySQL.Async.execute('DELETE FROM bans WHERE id = ?', { result.id })
|
||||
MySQL.query('DELETE FROM bans WHERE id = ?', { result.id })
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
+13
-13
@@ -9,7 +9,7 @@ function QBCore.Player.Login(source, citizenid, newData)
|
||||
if source and source ~= '' then
|
||||
if citizenid then
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
local PlayerData = MySQL.Sync.prepare('SELECT * FROM players where citizenid = ?', { citizenid })
|
||||
local PlayerData = MySQL.prepare.await('SELECT * FROM players where citizenid = ?', { citizenid })
|
||||
if PlayerData and license == PlayerData.license then
|
||||
PlayerData.money = json.decode(PlayerData.money)
|
||||
PlayerData.job = json.decode(PlayerData.job)
|
||||
@@ -445,7 +445,7 @@ function QBCore.Player.Save(source)
|
||||
local pcoords = GetEntityCoords(ped)
|
||||
local PlayerData = QBCore.Players[source].PlayerData
|
||||
if PlayerData then
|
||||
MySQL.Async.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
|
||||
MySQL.insert('INSERT INTO players (citizenid, cid, license, name, money, charinfo, job, gang, position, metadata) VALUES (:citizenid, :cid, :license, :name, :money, :charinfo, :job, :gang, :position, :metadata) ON DUPLICATE KEY UPDATE cid = :cid, name = :name, money = :money, charinfo = :charinfo, job = :job, gang = :gang, position = :position, metadata = :metadata', {
|
||||
citizenid = PlayerData.citizenid,
|
||||
cid = tonumber(PlayerData.cid),
|
||||
license = PlayerData.license,
|
||||
@@ -483,7 +483,7 @@ local playertables = { -- Add tables as needed
|
||||
|
||||
function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
local license = QBCore.Functions.GetIdentifier(source, 'license')
|
||||
local result = MySQL.Sync.fetchScalar('SELECT license FROM players where citizenid = ?', { citizenid })
|
||||
local result = MySQL.scalar.await('SELECT license FROM players where citizenid = ?', { citizenid })
|
||||
if license == result then
|
||||
local query = "DELETE FROM %s WHERE citizenid = ?"
|
||||
local tableCount = #playertables
|
||||
@@ -494,7 +494,7 @@ function QBCore.Player.DeleteCharacter(source, citizenid)
|
||||
queries[i] = {query = query:format(v.table), values = { citizenid }}
|
||||
end
|
||||
|
||||
MySQL.Async.transaction(queries, function(result2)
|
||||
MySQL.transaction(queries, function(result2)
|
||||
if result2 then
|
||||
TriggerEvent('qb-log:server:CreateLog', 'joinleave', 'Character Deleted', 'red', '**' .. GetPlayerName(source) .. '** ' .. license .. ' deleted **' .. citizenid .. '**..')
|
||||
end
|
||||
@@ -509,7 +509,7 @@ end
|
||||
|
||||
function QBCore.Player.LoadInventory(PlayerData)
|
||||
PlayerData.items = {}
|
||||
local inventory = MySQL.Sync.prepare('SELECT inventory FROM players WHERE citizenid = ?', { PlayerData.citizenid })
|
||||
local inventory = MySQL.prepare.await('SELECT inventory FROM players WHERE citizenid = ?', { PlayerData.citizenid })
|
||||
local missingItems = {}
|
||||
if inventory then
|
||||
inventory = json.decode(inventory)
|
||||
@@ -565,9 +565,9 @@ function QBCore.Player.SaveInventory(source)
|
||||
}
|
||||
end
|
||||
end
|
||||
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
|
||||
MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { json.encode(ItemsJson), PlayerData.citizenid })
|
||||
else
|
||||
MySQL.Async.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
|
||||
MySQL.prepare('UPDATE players SET inventory = ? WHERE citizenid = ?', { '[]', PlayerData.citizenid })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -608,7 +608,7 @@ function QBCore.Player.CreateCitizenId()
|
||||
local CitizenId = nil
|
||||
while not UniqueFound do
|
||||
CitizenId = tostring(QBCore.Shared.RandomStr(3) .. QBCore.Shared.RandomInt(5)):upper()
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE citizenid = ?', { CitizenId })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
@@ -622,7 +622,7 @@ function QBCore.Functions.CreateAccountNumber()
|
||||
while not UniqueFound do
|
||||
AccountNumber = 'US0' .. math.random(1, 9) .. 'QBCore' .. math.random(1111, 9999) .. math.random(1111, 9999) .. math.random(11, 99)
|
||||
local query = '%' .. AccountNumber .. '%'
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
@@ -636,7 +636,7 @@ function QBCore.Functions.CreatePhoneNumber()
|
||||
while not UniqueFound do
|
||||
PhoneNumber = math.random(100,999) .. math.random(1000000,9999999)
|
||||
local query = '%' .. PhoneNumber .. '%'
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE charinfo LIKE ?', { query })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
@@ -650,7 +650,7 @@ function QBCore.Player.CreateFingerId()
|
||||
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))
|
||||
local query = '%' .. FingerId .. '%'
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM `players` WHERE `metadata` LIKE ?', { query })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
@@ -664,7 +664,7 @@ function QBCore.Player.CreateWalletId()
|
||||
while not UniqueFound do
|
||||
WalletId = 'QB-' .. math.random(11111111, 99999999)
|
||||
local query = '%' .. WalletId .. '%'
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
@@ -678,7 +678,7 @@ function QBCore.Player.CreateSerialNumber()
|
||||
while not UniqueFound do
|
||||
SerialNumber = math.random(11111111, 99999999)
|
||||
local query = '%' .. SerialNumber .. '%'
|
||||
local result = MySQL.Sync.prepare('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
|
||||
local result = MySQL.prepare.await('SELECT COUNT(*) as count FROM players WHERE metadata LIKE ?', { query })
|
||||
if result == 0 then
|
||||
UniqueFound = true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user