From cb6416024e358d59fe0c8e7a6f45cd585bdaa2dd Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Wed, 2 Jan 2019 20:10:37 +0100 Subject: [PATCH] Proper indening --- README.md | 2 +- server/main.lua | 158 ++++++++++++++++++++++-------------------------- 2 files changed, 73 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index a44b02e3..90cee8f9 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/server/main.lua b/server/main.lua index 220c6cc0..56ba8c47 100644 --- a/server/main.lua +++ b/server/main.lua @@ -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')