mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 11:18:53 +00:00
Code cleanup
This commit is contained in:
@@ -29,7 +29,7 @@ start esx_whitelist
|
||||
### License
|
||||
esx_whitelist - Whitelist script
|
||||
|
||||
Copyright (C) 2015-2018 Jérémie N'gadi
|
||||
Copyright (C) 2015-2020 Jérémie N'gadi
|
||||
|
||||
This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.
|
||||
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
USE `essentialmode`;
|
||||
|
||||
CREATE TABLE `whitelist` (
|
||||
`identifier` varchar(60) NOT NULL,
|
||||
`identifier` varchar(40) NOT NULL,
|
||||
|
||||
PRIMARY KEY (`identifier`)
|
||||
);
|
||||
|
||||
+1
-1
@@ -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',
|
||||
['steamid_error'] = 'your Steam ID was not found, is Steam running?',
|
||||
['whitelist_empty'] = 'the whitelist hasn\'t been loaded yet, or alternatively no one has been whitelisted!',
|
||||
['license_missing'] = 'your license could not be found',
|
||||
['help_whitelist_add'] = 'add someone to the whitelist',
|
||||
['help_whitelist_load'] = 'reload the whitelist',
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
Locales['fr'] = {
|
||||
['whitelist_check'] = 'making sure you\'re whitelisted on this server . . .',
|
||||
['not_whitelisted'] = 'ceci est un serveur avec whitelist',
|
||||
['steamid_error'] = 'nous n\'arrivons pas à lire votre SteamID',
|
||||
['whitelist_empty'] = 'the whitelist hasn\'t been loaded yet, or alternatively no one has been whitelisted!',
|
||||
['license_missing'] = 'your license could not be found',
|
||||
['help_whitelist_add'] = 'ajouter quelqu\'un dans la Whitelist',
|
||||
['help_whitelist_load'] = 'recharger la Whitelist',
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,8 +1,8 @@
|
||||
Locales['sv'] = {
|
||||
['whitelist_check'] = 'making sure you\'re whitelisted on this server . . .',
|
||||
['not_whitelisted'] = 'du är inte whitelistad på denna server!',
|
||||
['steamid_error'] = 'ditt Steam ID kunde ej hittas, är Steam påslaget?',
|
||||
['whitelist_empty'] = 'whitelisten har ännu inte laddats in, eller så är ingen whitelitad!',
|
||||
['license_missing'] = 'din licens kunde ej hittas',
|
||||
['help_whitelist_add'] = 'lägg till någon till whitelisten',
|
||||
['help_whitelist_load'] = 'ladda om whitelist',
|
||||
}
|
||||
|
||||
+16
-32
@@ -1,42 +1,26 @@
|
||||
TriggerEvent('es:addGroupCommand', 'wlrefresh', 'admin', function (source, args, user)
|
||||
ESX.RegisterCommand('wlrefresh', 'admin', function(xPlayer, args, showError)
|
||||
loadWhiteList(function()
|
||||
TriggerEvent('esx_whitelist:sendMessage', source, 'Whitelist', 'Whitelist reloaded')
|
||||
showError('Whitelist reloaded')
|
||||
end)
|
||||
end, function (source, args, user)
|
||||
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficienct permissions!' } })
|
||||
end, { help = _U('help_whitelist_load') })
|
||||
end, true, {help = _U('help_whitelist_load')})
|
||||
|
||||
TriggerEvent('es:addGroupCommand', 'wladd', 'admin', function (source, args, user)
|
||||
local steamID = 'steam:' .. args[1]:lower()
|
||||
ESX.RegisterCommand('wladd', 'admin', function(xPlayer, args, showError)
|
||||
args.license = args.license:lower()
|
||||
|
||||
if string.len(steamID) ~= 21 then
|
||||
TriggerEvent('esx_whitelist:sendMessage', source, '^1SYSTEM', 'Invalid steam ID length!')
|
||||
return
|
||||
end
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM whitelist WHERE identifier = @identifier', {
|
||||
['@identifier'] = steamID
|
||||
}, function(result)
|
||||
if result[1] ~= nil then
|
||||
TriggerEvent('esx_whitelist:sendMessage', source, '^1SYSTEM', 'The player is already whitelisted on this server!')
|
||||
if string.len(args.license) == 40 then
|
||||
if WhiteList[args.license] then
|
||||
showError('The player is already whitelisted on this server!')
|
||||
else
|
||||
MySQL.Async.execute('INSERT INTO whitelist (identifier) VALUES (@identifier)', {
|
||||
['@identifier'] = steamID
|
||||
}, function (rowsChanged)
|
||||
table.insert(WhiteList, steamID)
|
||||
TriggerEvent('esx_whitelist:sendMessage', source, 'Whitelist', 'The player has been whitelisted!')
|
||||
['@identifier'] = args.license
|
||||
}, function(rowsChanged)
|
||||
WhiteList[args.license] = true
|
||||
showError('The player has been whitelisted!')
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end, function (source, args, user)
|
||||
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficienct permissions!' } })
|
||||
end, { help = _U('help_whitelist_add'), params = { steam = 'SteamID', help = 'SteamID formated to hex, begins with 11' }})
|
||||
|
||||
-- console / rcon can also utilize es:command events, but breaks since the source isn't a connected player, ending up in error messages
|
||||
AddEventHandler('esx_whitelist:sendMessage', function(source, title, message)
|
||||
if source ~= 0 then
|
||||
TriggerClientEvent('chat:addMessage', source, { args = { title, message } })
|
||||
else
|
||||
print('esx_whitelist: ' .. message)
|
||||
showError('Invalid steam ID length!')
|
||||
end
|
||||
end)
|
||||
end, true, {help = _U('help_whitelist_add'), validate = true, arguments = {
|
||||
{name = 'license', help = 'the player license', type = 'string'}
|
||||
}})
|
||||
|
||||
+21
-27
@@ -1,14 +1,14 @@
|
||||
WhiteList = {}
|
||||
WhiteList = {}
|
||||
|
||||
function loadWhiteList(cb)
|
||||
Whitelist = {}
|
||||
|
||||
MySQL.Async.fetchAll('SELECT * FROM whitelist', {}, function (identifiers)
|
||||
for i=1, #identifiers, 1 do
|
||||
table.insert(WhiteList, tostring(identifiers[i].identifier):lower())
|
||||
MySQL.Async.fetchAll('SELECT identifier FROM whitelist', {}, function(result)
|
||||
for k,v in ipairs(result) do
|
||||
WhiteList[v.identifier] = true
|
||||
end
|
||||
|
||||
if cb ~= nil then
|
||||
if cb then
|
||||
cb()
|
||||
end
|
||||
end)
|
||||
@@ -22,7 +22,7 @@ AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
|
||||
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers.
|
||||
deferrals.defer()
|
||||
|
||||
local _source = source
|
||||
local playerId, kickReason, identifier = source
|
||||
|
||||
-- Letting the user know what's going on.
|
||||
deferrals.update(_U('whitelist_check'))
|
||||
@@ -30,30 +30,24 @@ AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
|
||||
-- Needed, not sure why.
|
||||
Citizen.Wait(100)
|
||||
|
||||
local whitelisted, kickReason, steamID = false, nil, GetPlayerIdentifiers(_source)[1]
|
||||
|
||||
if #WhiteList == 0 then
|
||||
kickReason = _U('whitelist_empty')
|
||||
elseif not string.match(steamID, 'steam:1') then
|
||||
kickReason = _U('steamid_error')
|
||||
else
|
||||
|
||||
for i = 1, #WhiteList, 1 do
|
||||
if tostring(WhiteList[i]) == tostring(steamID) then
|
||||
whitelisted = true
|
||||
break
|
||||
end
|
||||
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
|
||||
if string.match(v, 'license:') then
|
||||
identifier = string.sub(v, 9)
|
||||
break
|
||||
end
|
||||
|
||||
if not whitelisted then
|
||||
kickReason = _U('not_whitelisted')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if whitelisted then
|
||||
deferrals.done()
|
||||
else
|
||||
if ESX.Table.SizeOf(WhiteList) == 0 then
|
||||
kickReason = _U('whitelist_empty')
|
||||
elseif not identifier then
|
||||
kickReason = _U('license_missing')
|
||||
elseif not WhiteList[identifier] then
|
||||
kickReason = _U('not_whitelisted')
|
||||
end
|
||||
|
||||
if kickReason then
|
||||
deferrals.done(kickReason)
|
||||
else
|
||||
deferrals.done()
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user