Refactor: ESX Whitelist

This commit is contained in:
Mycroft
2022-03-26 18:58:59 +00:00
committed by GitHub
parent 6ecf43379f
commit 9b9ce38938
7 changed files with 52 additions and 84 deletions
-26
View File
@@ -1,32 +1,6 @@
# esx_whitelist
## Download & Installation
### Using [fvm](https://github.com/qlaffont/fvm-installer)
```
fvm install --save --folder=esx esx-org/esx_whitelist
```
### Using Git
```
cd resources
git clone https://github.com/ESX-Org/esx_whitelist [esx]/esx_whitelist
```
### Manually
- Download https://github.com/ESX-Org/esx_whitelist/archive/master.zip
- Put it in the `[esx]` directory
## Installation
- Import `esx_whitelist.sql` to your database
- Add this in your `server.cfg`:
```
start esx_whitelist
```
# Legal
### License
esx_whitelist - Whitelist script
Copyright (C) 2015-2022 Jérémie N'gadi
@@ -1,8 +0,0 @@
USE `es_extended`;
CREATE TABLE `whitelist` (
`identifier` varchar(60) NOT NULL,
PRIMARY KEY (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
+3 -3
View File
@@ -6,12 +6,12 @@ description 'ESX Whitelist'
version '1.6.5'
server_only 'yes'
server_scripts {
'@es_extended/imports.lua',
'@oxmysql/lib/MySQL.lua',
'@es_extended/locale.lua',
'config.lua',
'locales/*.lua',
'server/main.lua',
'server/commands.lua'
'server/main.lua'
}
+4 -4
View File
@@ -1,8 +1,8 @@
Locales['en'] = {
['whitelist_check'] = 'making sure you\'re whitelisted on this server . . .',
['not_whitelisted'] = 'you are not whitelisted on this server',
['whitelist_empty'] = 'the whitelist hasn\'t been loaded yet, or alternatively no one has been whitelisted!',
['license_missing'] = 'your license could not be found',
['whitelist_check'] = 'Checking you are Allowlisted.',
['not_whitelisted'] = 'You Must be Allowlisted to join this server!',
['whitelist_empty'] = 'There Are no whitelists saved for this server.',
['license_missing'] = 'Error: Your Identifier is missing!',
['help_whitelist_add'] = 'add someone to the whitelist',
['help_whitelist_load'] = 'reload the whitelist',
}
+1
View File
@@ -0,0 +1 @@
[]
@@ -1,26 +0,0 @@
ESX.RegisterCommand('wlrefresh', 'admin', function(xPlayer, args, showError)
loadWhiteList(function()
showError('Whitelist reloaded')
end)
end, true, {help = _U('help_whitelist_load')})
ESX.RegisterCommand('wladd', 'admin', function(xPlayer, args, showError)
args.license = args.license:lower()
if string.len(args.license) == 40 then
if WhiteList[args.license] then
showError('The player is already whitelisted on this server!')
else
MySQL.update('INSERT INTO whitelist (identifier) VALUES (@identifier)', {
['@identifier'] = args.license
}, function(rowsChanged)
WhiteList[args.license] = true
showError('The player has been whitelisted!')
end)
end
else
showError('Invalid license ID length!')
end
end, true, {help = _U('help_whitelist_add'), validate = true, arguments = {
{name = 'license', help = 'the player license', type = 'string'}
}})
+44 -17
View File
@@ -1,28 +1,20 @@
WhiteList = {}
function loadWhiteList(cb)
Whitelist = {}
function loadWhiteList()
Whitelist = nil
MySQL.query('SELECT identifier FROM whitelist', function(result)
for k,v in ipairs(result) do
WhiteList[v.identifier] = true
end
if cb then
cb()
end
end)
local List = LoadResourceFile(GetCurrentResourceName(),'players.json')
if List then
Whitelist = json.decode(List)
end
end
MySQL.ready(function()
loadWhiteList()
end)
loadWhiteList()
AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
if #GetPlayers() < Config.MinPlayer then
if #(GetPlayers()) < Config.MinPlayer then
deferrals.done()
end
else
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers.
deferrals.defer()
@@ -49,4 +41,39 @@ AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
else
deferrals.done()
end
end
end)
ESX.RegisterCommand('wlrefresh', 'admin', function(xPlayer, args, showError)
loadWhiteList(function()
showError('Whitelist reloaded')
end)
end, true, {help = _U('help_whitelist_load')})
ESX.RegisterCommand('wladd', 'admin', function(xPlayer, args, showError)
args.license = args.license:lower()
if WhiteList[args.license] then
showError('The player is already allowlisted on this server!')
else
WhiteList[args.license] = true
SaveResourceFile(GetCurrentResourceName(), 'players.json', json.encode(WhiteList))
loadWhiteList()
end
end, true, {help = _U('help_whitelist_add'), validate = true, arguments = {
{name = 'license', help = 'the player license', type = 'string'}
}})
ESX.RegisterCommand('wlremove', 'admin', function(xPlayer, args, showError)
args.license = args.license:lower()
if WhiteList[args.license] then
WhiteList[args.license] = nil
SaveResourceFile(GetCurrentResourceName(), 'players.json', json.encode(WhiteList))
loadWhiteList()
else
showError('Identifier is not Allowlisted on this server!')
end
end, true, {help = _U('help_whitelist_add'), validate = true, arguments = {
{name = 'license', help = 'the player license', type = 'string'}
}})