Skip to content

Instantly share code, notes, and snippets.

@cm8263
Created September 9, 2019 05:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cm8263/d66f75ded21d435aba88282aae7d3d0c to your computer and use it in GitHub Desktop.
Save cm8263/d66f75ded21d435aba88282aae7d3d0c to your computer and use it in GitHub Desktop.
-- Whitelist check on server join
RegisterServerEvent("Whitelist:WhitelistCheck")
AddEventHandler("Whitelist:WhitelistCheck", function(Whitelist)
-- Loop though all whitelist entries
for i in pairs(Whitelist) do
-- Set all entries to pending
Whitelist[i] = "pending"
end
-- Collect all the data from the whitelist.json file
local Data = LoadResourceFile(GetCurrentResourceName(), "whitelist.json")
-- If able to collect data
if Data then
-- Place the decoded whitelist into the array
local Entries = json.decode(Data)
-- Loop through the whitelist array
for _, Entry in ipairs(Entries) do
-- Check if the player exists in the array.
if GetPlayerIdentifier(source):lower() == Entry.steamhex:lower() then
-- Loop though all values in whitelist entry
for i in pairs(Entry) do
-- If the value is not the player's steam hex
if i ~= "steamhex" then
-- If whitelist value is true, aka they have access to that entry
if Entry[i] then
-- If command is a valid command
if Whitelist[i] then
-- Allow player to use that command
Whitelist[i] = true
-- If entry is not valid
else
-- Print error message to server console
print("===================================================================")
print("==============================WARNING==============================")
print("/" .. i .. " is not a valid whitelist entry, but is listed in ")
print(Entry.steamhex:lower() .. "'s whitelist entry. Please correct this")
print("issue, and reload the resource.")
print("===================================================================")
end
end
end
end
-- Break the loop once whitelist entry found
break
end
end
-- If unable to load JSON file
else
-- Print error message to server console
print("===================================================================")
print("==============================WARNING==============================")
print("Unable to load whitelist file for" .. GetCurrentResourceName())
print("Whitelist has been disabled. This message will appear every time so")
print("meone joins the server until the issue is corrected.")
print("===================================================================")
-- Loop through all whitelist entries
for i in pairs(Whitelist) do
-- Grant players all permissions
Whitelist[i] = true
end
-- Override whitelist permission for specific entry
-- Uncomment and edit this if you want to deny access
-- to a specific entry for all players when the whitelist
-- fails to load, otherwise it will be true
-- Whitelist.SomethingImportantThatShouldBeDenied = false
end
-- Loop through all whitelist entries
for i in pairs(Whitelist) do
-- If entry is still pending
if Whitelist[i] == "pending" then
-- Deny access
Whitelist[i] = false
end
end
-- Return whietlist object to client
TriggerClientEvent("Whitelist:Return:WhitelistCheck", source, Whitelist)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment