mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 16:23:21 +00:00
Proper indening
This commit is contained in:
@@ -25,7 +25,7 @@ git clone https://github.com/ESX-Org/esx_license [esx]/esx_license
|
|||||||
start esx_license
|
start esx_license
|
||||||
```
|
```
|
||||||
|
|
||||||
### Available triggers (server side)
|
### Available triggers
|
||||||
- `'esx_license:addLicense', function(target, type, cb)`
|
- `'esx_license:addLicense', function(target, type, cb)`
|
||||||
- `'esx_license:removeLicense', function(target, type, cb)`
|
- `'esx_license:removeLicense', function(target, type, cb)`
|
||||||
- `'esx_license:getLicense', function(source, cb, type)` (callback)
|
- `'esx_license:getLicense', function(source, cb, type)` (callback)
|
||||||
|
|||||||
+72
-86
@@ -4,125 +4,111 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
|
|||||||
|
|
||||||
function AddLicense(target, type, cb)
|
function AddLicense(target, type, cb)
|
||||||
local xPlayer = ESX.GetPlayerFromId(target)
|
local xPlayer = ESX.GetPlayerFromId(target)
|
||||||
MySQL.Async.execute(
|
|
||||||
'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)',
|
MySQL.Async.execute('INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
|
||||||
{
|
['@type'] = type,
|
||||||
['@type'] = type,
|
['@owner'] = xPlayer.identifier
|
||||||
['@owner'] = xPlayer.identifier
|
}, function(rowsChanged)
|
||||||
}, function(rowsChanged)
|
if cb ~= nil then
|
||||||
if cb ~= nil then
|
cb()
|
||||||
cb()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function RemoveLicense(target, type, cb)
|
function RemoveLicense(target, type, cb)
|
||||||
local xPlayer = ESX.GetPlayerFromId(target)
|
local xPlayer = ESX.GetPlayerFromId(target)
|
||||||
MySQL.Async.execute(
|
|
||||||
'DELETE FROM user_licenses WHERE type = @type AND owner = @owner',
|
MySQL.Async.execute('DELETE FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||||
{
|
['@type'] = type,
|
||||||
['@type'] = type,
|
['@owner'] = xPlayer.identifier
|
||||||
['@owner'] = xPlayer.identifier
|
}, function(rowsChanged)
|
||||||
}, function(rowsChanged)
|
if cb ~= nil then
|
||||||
if cb ~= nil then
|
cb()
|
||||||
cb()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetLicense(type, cb)
|
function GetLicense(type, cb)
|
||||||
MySQL.Async.fetchAll(
|
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||||
'SELECT * FROM licenses WHERE type = @type',
|
['@type'] = type
|
||||||
{
|
}, function(result)
|
||||||
['@type'] = type
|
local data = {
|
||||||
}, function(result)
|
type = type,
|
||||||
local data = {
|
label = result[1].label
|
||||||
type = type,
|
}
|
||||||
label = result[1].label
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(data)
|
cb(data)
|
||||||
end
|
end)
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetLicenses(target, cb)
|
function GetLicenses(target, cb)
|
||||||
local xPlayer = ESX.GetPlayerFromId(target)
|
local xPlayer = ESX.GetPlayerFromId(target)
|
||||||
MySQL.Async.fetchAll(
|
|
||||||
'SELECT * FROM user_licenses WHERE owner = @owner',
|
|
||||||
{
|
|
||||||
['@owner'] = xPlayer.identifier
|
|
||||||
}, function(result)
|
|
||||||
local licenses = {}
|
|
||||||
local asyncTasks = {}
|
|
||||||
|
|
||||||
for i=1, #result, 1 do
|
MySQL.Async.fetchAll('SELECT * FROM user_licenses WHERE owner = @owner', {
|
||||||
|
['@owner'] = xPlayer.identifier
|
||||||
|
}, function(result)
|
||||||
|
local licenses = {}
|
||||||
|
local asyncTasks = {}
|
||||||
|
|
||||||
local scope = function(type)
|
for i=1, #result, 1 do
|
||||||
table.insert(asyncTasks, function(cb)
|
|
||||||
MySQL.Async.fetchAll(
|
|
||||||
'SELECT * FROM licenses WHERE type = @type',
|
|
||||||
{
|
|
||||||
['@type'] = type
|
|
||||||
}, function(result2)
|
|
||||||
|
|
||||||
table.insert(licenses, {
|
local scope = function(type)
|
||||||
type = type,
|
table.insert(asyncTasks, function(cb)
|
||||||
label = result2[1].label
|
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||||
})
|
['@type'] = type
|
||||||
cb()
|
}, function(result2)
|
||||||
end
|
table.insert(licenses, {
|
||||||
)
|
type = type,
|
||||||
|
label = result2[1].label
|
||||||
|
})
|
||||||
|
|
||||||
|
cb()
|
||||||
end)
|
end)
|
||||||
end
|
end)
|
||||||
scope(result[i].type)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Async.parallel(asyncTasks, function(results)
|
scope(result[i].type)
|
||||||
cb(licenses)
|
|
||||||
end)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
)
|
|
||||||
|
Async.parallel(asyncTasks, function(results)
|
||||||
|
cb(licenses)
|
||||||
|
end)
|
||||||
|
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function CheckLicense(target, type, cb)
|
function CheckLicense(target, type, cb)
|
||||||
local xPlayer = ESX.GetPlayerFromId(target)
|
local xPlayer = ESX.GetPlayerFromId(target)
|
||||||
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
|
|
||||||
|
|
||||||
|
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
|
||||||
)
|
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GetLicensesList(cb)
|
function GetLicensesList(cb)
|
||||||
MySQL.Async.fetchAll(
|
MySQL.Async.fetchAll('SELECT * FROM licenses', {
|
||||||
'SELECT * FROM licenses',
|
['@type'] = type
|
||||||
{
|
}, function(result)
|
||||||
['@type'] = type
|
local licenses = {}
|
||||||
}, function(result)
|
|
||||||
local licenses = {}
|
|
||||||
|
|
||||||
for i=1, #result, 1 do
|
for i=1, #result, 1 do
|
||||||
table.insert(licenses, {
|
table.insert(licenses, {
|
||||||
type = result[i].type,
|
type = result[i].type,
|
||||||
label = result[i].label
|
label = result[i].label
|
||||||
})
|
})
|
||||||
end
|
|
||||||
cb(licenses)
|
|
||||||
end
|
end
|
||||||
)
|
|
||||||
|
cb(licenses)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
RegisterNetEvent('esx_license:addLicense')
|
RegisterNetEvent('esx_license:addLicense')
|
||||||
|
|||||||
Reference in New Issue
Block a user