mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 03:08:52 +00:00
Fix for latest ESX
This commit is contained in:
+48
-37
@@ -3,33 +3,45 @@ ESX = nil
|
||||
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
||||
|
||||
function AddLicense(target, type, cb)
|
||||
local identifier = GetPlayerIdentifier(target, 0)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.execute('INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
|
||||
['@type'] = type,
|
||||
['@owner'] = identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
if xPlayer then
|
||||
MySQL.Async.execute('INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
else
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function RemoveLicense(target, type, cb)
|
||||
local identifier = GetPlayerIdentifier(target, 0)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.execute('DELETE FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||
['@type'] = type,
|
||||
['@owner'] = identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
if xPlayer then
|
||||
MySQL.Async.execute('DELETE FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
else
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
function GetLicense(type, cb)
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||
MySQL.Async.fetchAll('SELECT label FROM licenses WHERE type = @type', {
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local data = {
|
||||
@@ -42,19 +54,17 @@ function GetLicense(type, cb)
|
||||
end
|
||||
|
||||
function GetLicenses(target, cb)
|
||||
local identifier = GetPlayerIdentifier(target, 0)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM user_licenses WHERE owner = @owner', {
|
||||
['@owner'] = identifier
|
||||
MySQL.Async.fetchAll('SELECT type FROM user_licenses WHERE owner = @owner', {
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
local asyncTasks = {}
|
||||
local licenses, asyncTasks = {}, {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
|
||||
local scope = function(type)
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||
MySQL.Async.fetchAll('SELECT label FROM licenses WHERE type = @type', {
|
||||
['@type'] = type
|
||||
}, function(result2)
|
||||
table.insert(licenses, {
|
||||
@@ -68,34 +78,35 @@ function GetLicenses(target, cb)
|
||||
end
|
||||
|
||||
scope(result[i].type)
|
||||
|
||||
end
|
||||
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
cb(licenses)
|
||||
end)
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
function CheckLicense(target, type, cb)
|
||||
local identifier = GetPlayerIdentifier(target, 0)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
|
||||
MySQL.Async.fetchAll('SELECT COUNT(*) as count FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||
['@type'] = type,
|
||||
['@owner'] = identifier
|
||||
}, function(result)
|
||||
if tonumber(result[1].count) > 0 then
|
||||
cb(true)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
|
||||
end)
|
||||
if xPlayer then
|
||||
MySQL.Async.fetchAll('SELECT COUNT(*) as count FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(result)
|
||||
if tonumber(result[1].count) > 0 then
|
||||
cb(true)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
end)
|
||||
else
|
||||
cb(false)
|
||||
end
|
||||
end
|
||||
|
||||
function GetLicensesList(cb)
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses', {
|
||||
MySQL.Async.fetchAll('SELECT type, label FROM licenses', {
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
|
||||
Reference in New Issue
Block a user