mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-01 19:01:51 +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
|
||||
```
|
||||
|
||||
### Available triggers (server side)
|
||||
### Available triggers
|
||||
- `'esx_license:addLicense', function(target, type, cb)`
|
||||
- `'esx_license:removeLicense', function(target, type, cb)`
|
||||
- `'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)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)',
|
||||
{
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
|
||||
MySQL.Async.execute('INSERT INTO user_licenses (type, owner) VALUES (@type, @owner)', {
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
function RemoveLicense(target, type, cb)
|
||||
local xPlayer = ESX.GetPlayerFromId(target)
|
||||
MySQL.Async.execute(
|
||||
'DELETE FROM user_licenses WHERE type = @type AND owner = @owner',
|
||||
{
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
|
||||
MySQL.Async.execute('DELETE FROM user_licenses WHERE type = @type AND owner = @owner', {
|
||||
['@type'] = type,
|
||||
['@owner'] = xPlayer.identifier
|
||||
}, function(rowsChanged)
|
||||
if cb ~= nil then
|
||||
cb()
|
||||
end
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
function GetLicense(type, cb)
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses WHERE type = @type',
|
||||
{
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local data = {
|
||||
type = type,
|
||||
label = result[1].label
|
||||
}
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local data = {
|
||||
type = type,
|
||||
label = result[1].label
|
||||
}
|
||||
|
||||
cb(data)
|
||||
end
|
||||
)
|
||||
cb(data)
|
||||
end)
|
||||
end
|
||||
|
||||
function GetLicenses(target, cb)
|
||||
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)
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses WHERE type = @type',
|
||||
{
|
||||
['@type'] = type
|
||||
}, function(result2)
|
||||
for i=1, #result, 1 do
|
||||
|
||||
table.insert(licenses, {
|
||||
type = type,
|
||||
label = result2[1].label
|
||||
})
|
||||
cb()
|
||||
end
|
||||
)
|
||||
local scope = function(type)
|
||||
table.insert(asyncTasks, function(cb)
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses WHERE type = @type', {
|
||||
['@type'] = type
|
||||
}, function(result2)
|
||||
table.insert(licenses, {
|
||||
type = type,
|
||||
label = result2[1].label
|
||||
})
|
||||
|
||||
cb()
|
||||
end)
|
||||
end
|
||||
scope(result[i].type)
|
||||
end)
|
||||
end
|
||||
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
cb(licenses)
|
||||
end)
|
||||
scope(result[i].type)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
Async.parallel(asyncTasks, function(results)
|
||||
cb(licenses)
|
||||
end)
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
function CheckLicense(target, type, cb)
|
||||
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
|
||||
|
||||
function GetLicensesList(cb)
|
||||
MySQL.Async.fetchAll(
|
||||
'SELECT * FROM licenses',
|
||||
{
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
MySQL.Async.fetchAll('SELECT * FROM licenses', {
|
||||
['@type'] = type
|
||||
}, function(result)
|
||||
local licenses = {}
|
||||
|
||||
for i=1, #result, 1 do
|
||||
table.insert(licenses, {
|
||||
type = result[i].type,
|
||||
label = result[i].label
|
||||
})
|
||||
end
|
||||
cb(licenses)
|
||||
for i=1, #result, 1 do
|
||||
table.insert(licenses, {
|
||||
type = result[i].type,
|
||||
label = result[i].label
|
||||
})
|
||||
end
|
||||
)
|
||||
|
||||
cb(licenses)
|
||||
end)
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx_license:addLicense')
|
||||
|
||||
Reference in New Issue
Block a user