Files
esx_core-esx-framework/server/main.lua
T
ElPumpo 29f64dd928 Use proper deferarals, endless improvements
- 4 tab indents
- Commands reworked
   - now supports source 0 (console)
   - toLower, and duplicate checks in db
- Fixed error messages
    - added seperate error message when `WhiteList` table is empty
    - fixed steam id check
2018-08-28 19:33:20 +02:00

70 lines
1.4 KiB
Lua

WhiteList = {}
local hasSqlRun = false
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())
end
hasSqlRun = true
if cb ~= nil then
cb()
end
end)
end
AddEventHandler('onMySQLReady', function()
loadWhiteList()
end)
Citizen.CreateThread(function()
Citizen.Wait(10000)
if not hasSqlRun then
loadWhiteList()
end
end)
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
-- Letting the user know what's going on.
deferrals.update(_U('whitelist_check'))
-- 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
end
if not whitelisted then
kickReason = _U('not_whitelisted')
end
end
if whitelisted then
deferrals.done()
else
deferrals.done(kickReason)
end
end)