mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
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
This commit is contained in:
+37
-18
@@ -1,23 +1,42 @@
|
||||
function displayPermissionIssue ()
|
||||
TriggerClientEvent('chatMessage', source, 'SYSTEM', { 255, 0, 0 }, 'Insufficienct permissions!')
|
||||
end
|
||||
|
||||
TriggerEvent('es:addGroupCommand', 'whitelist:load', 'admin', function (source, args, user)
|
||||
loadWhiteList()
|
||||
TriggerEvent('es:addGroupCommand', 'wlrefresh', 'admin', function (source, args, user)
|
||||
loadWhiteList(function()
|
||||
TriggerEvent('esx_whitelist:sendMessage', source, 'Whitelist', 'Whitelist reloaded')
|
||||
end)
|
||||
end, function (source, args, user)
|
||||
displayPermissionIssue(source)
|
||||
TriggerClientEvent('chat:addMessage', source, { args = { '^1SYSTEM', 'Insufficienct permissions!' } })
|
||||
end, { help = _U('help_whitelist_load') })
|
||||
|
||||
TriggerEvent('es:addGroupCommand', 'whitelist:add', 'admin', function (source, args, user)
|
||||
local steamID = 'steam:' .. args[1]
|
||||
TriggerEvent('es:addGroupCommand', 'wladd', 'admin', function (source, args, user)
|
||||
local steamID = 'steam:' .. args[1]:lower()
|
||||
|
||||
MySQL.Async.execute(
|
||||
'INSERT INTO whitelist (identifier) VALUES (@identifier)',
|
||||
{ ['@identifier'] = tostring(steamID) },
|
||||
function ()
|
||||
loadWhiteList()
|
||||
end
|
||||
)
|
||||
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!')
|
||||
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!')
|
||||
end)
|
||||
end
|
||||
end)
|
||||
end, function (source, args, user)
|
||||
displayPermissionIssue(source)
|
||||
end, { help = _U('help_whitelist_add'), params = { steam = 'SteamID', help = 'SteamID formated to hex' }})
|
||||
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)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user