mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
chore(repo): Initial commit
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
# esx_license
|
||||
FXServer ESX License
|
||||
|
||||
[INSTALLATION]
|
||||
|
||||
[INSTALLATION]
|
||||
|
||||
1) Using [fvm](https://github.com/qlaffont/fvm-installer)
|
||||
```
|
||||
fvm install --save --folder=esx esx-org/esx_license
|
||||
|
||||
```
|
||||
|
||||
2) Manually
|
||||
|
||||
- Download https://github.com/ESX-Org/esx_license/releases/latest
|
||||
- Put it in [esx] directory
|
||||
|
||||
|
||||
1) Import esx_license.sql in your database
|
||||
2) Add this in your server.cfg :
|
||||
|
||||
```
|
||||
start esx_license
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
|
||||
|
||||
description 'ESX License'
|
||||
|
||||
version '1.0.0'
|
||||
|
||||
server_scripts {
|
||||
'@async/async.lua',
|
||||
'@mysql-async/lib/MySQL.lua',
|
||||
'server/main.lua'
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
USE `essentialmode`;
|
||||
|
||||
CREATE TABLE `licenses` (
|
||||
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`type` varchar(255) NOT NULL,
|
||||
`label` varchar(255) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
+206
@@ -0,0 +1,206 @@
|
||||
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)
|
||||
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
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
function GetLicensesList(cb)
|
||||
|
||||
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)
|
||||
|
||||
end
|
||||
)
|
||||
|
||||
end
|
||||
|
||||
RegisterNetEvent('esx_license:addLicense')
|
||||
AddEventHandler('esx_license:addLicense', function(target, type, cb)
|
||||
AddLicense(target, type, cb)
|
||||
end)
|
||||
|
||||
RegisterNetEvent('esx_license:removeLicense')
|
||||
AddEventHandler('esx_license:removeLicense', function(target, type, cb)
|
||||
RemoveLicense(target, type, cb)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_license:getLicense', function(type, cb)
|
||||
GetLicense(type, cb)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_license:getLicenses', function(target, cb)
|
||||
GetLicenses(target, cb)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_license:checkLicense', function(target, type, cb)
|
||||
CheckLicense(target, type, cb)
|
||||
end)
|
||||
|
||||
AddEventHandler('esx_license:getLicensesList', function(cb)
|
||||
GetLicensesList(cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_license:getLicense', function(source, cb, type)
|
||||
GetLicense(type, cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_license:getLicenses', function(source, cb, target)
|
||||
GetLicenses(target, cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_license:checkLicense', function(source, cb, target, type)
|
||||
CheckLicense(target, type, cb)
|
||||
end)
|
||||
|
||||
ESX.RegisterServerCallback('esx_license:getLicensesList', function(source, cb)
|
||||
GetLicensesList(cb)
|
||||
end)
|
||||
Reference in New Issue
Block a user