Files
esx_core-esx-framework/server/main.lua
T
2020-02-17 22:12:33 +01:00

54 lines
1.1 KiB
Lua

WhiteList = {}
function loadWhiteList(cb)
Whitelist = {}
MySQL.Async.fetchAll('SELECT identifier FROM whitelist', {}, function(result)
for k,v in ipairs(result) do
WhiteList[v.identifier] = true
end
if cb then
cb()
end
end)
end
MySQL.ready(function()
loadWhiteList()
end)
AddEventHandler('playerConnecting', function(name, setCallback, deferrals)
-- Mark this connection as deferred, this is to prevent problems while checking player identifiers.
deferrals.defer()
local playerId, kickReason, identifier = source
-- Letting the user know what's going on.
deferrals.update(_U('whitelist_check'))
-- Needed, not sure why.
Citizen.Wait(100)
for k,v in ipairs(GetPlayerIdentifiers(playerId)) do
if string.match(v, 'license:') then
identifier = string.sub(v, 9)
break
end
end
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)