From f3e14bb2c55e0d881caf72046e531177247df325 Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sat, 21 Apr 2018 11:51:28 +0200 Subject: [PATCH] Cleanup, added available triggers to readme --- README.md | 8 ++++++++ server/main.lua | 52 +++++++------------------------------------------ 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 532cc780..bfc94f1b 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,11 @@ fvm install --save --folder=esx esx-org/esx_license ``` start esx_license ``` + +### Available triggers (server side) +- `'esx_license:addLicense', function(target, type, cb)` +- `'esx_license:removeLicense', function(target, type, cb)` +- `'esx_license:getLicense', function(source, cb, type)` (callback) +- `'esx_license:getLicenses', function(source, cb, target)` (callback) +- `'esx_license:checkLicense', function(source, cb, target, type)` (callback) +- `'esx_license:getLicensesList', function(source, cb)` (callback) diff --git a/server/main.lua b/server/main.lua index 119eee0e..220c6cc0 100644 --- a/server/main.lua +++ b/server/main.lua @@ -3,107 +3,81 @@ ESX = nil 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) + }, 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) + }, 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) - + }, function(result) local data = { type = type, label = result[1].label } 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) - + }, function(result) local licenses = {} local 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', { ['@type'] = type - }, - function(result2) + }, function(result2) table.insert(licenses, { type = type, label = result2[1].label }) - cb() - end ) - end) - end - scope(result[i].type) - end Async.parallel(asyncTasks, function(results) @@ -112,21 +86,16 @@ function GetLicenses(target, cb) 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) - + }, function(result) if tonumber(result[1].count) > 0 then cb(true) else @@ -135,18 +104,14 @@ function CheckLicense(target, type, cb) end ) - end function GetLicensesList(cb) - MySQL.Async.fetchAll( 'SELECT * FROM licenses', { ['@type'] = type - }, - function(result) - + }, function(result) local licenses = {} for i=1, #result, 1 do @@ -155,12 +120,9 @@ function GetLicensesList(cb) label = result[i].label }) end - cb(licenses) - end ) - end RegisterNetEvent('esx_license:addLicense')