[Release] enferList (another whitelist script)

I’ve seen a lot of people release whitelist scripts but, only for Databases. I couldn’t find one that worked without a Database so, I decided to make my own that uses a file.

I made it so you can change the file name the resource looks for (so you can have multiple whitelist servers running with the same instance of the resource), just set the convar in the server.cfg file (i.e. set enfer.whitelist "second-whitelist.json"). Make sure this file exists in the same directory as the Lua files. If it’s not, it will not load them.

You can download the files here: whitelist.zip (1.6 KB)

If you just want to look at how it’s written, look below.

__resource.lua
resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937"

server_scripts {
    'whitelist.lua'
}
whitelist.lua
--[[
	Simple whitelist script to check if a player's identifier is inside
		a file.
		
	Copyright 2018, Tony Enfer, All rights reserved.
	
	You may modify this resource but NOT, under any circumstances, redistribute it.
]]

-- The whitelist array
local whitelistArray = {}

-- Read the "whitelist.json" file.
local data = LoadResourceFile(GetCurrentResourceName(), GetConvar("enfer.whitelist", "whitelist.json"))

-- If we got data from it, parse it and store it.
if data then
    whitelistArray = json.decode(data)
    print("Loaded " .. #whitelistArray .. " whitelisted identifiers")
end

--[[
	When a player joins, check if they're in the whitelistArray.
	
	If they are, allow them to join. Otherwise don't let them.
]]
AddEventHandler("playerConnecting", function(playerName, setKickReason, deferrals)
    -- Tell the connection to defer until we have done
	deferrals.defer()
	
	-- Just in case "source" gets lost, store it
    local s = source
	
	-- If the player has been allowed to join the server
	local joined = false
	
	-- Tell the user we're checking stuff (not shown for long)
    deferrals.update("Please wait, checking whitelist")
	
	-- Needed, not sure why.
	Wait(100)
	
	-- A bunch of variables for calculating percentage
	local totalInWhitelist = #whitelistArray -- Total no of IDs in the array
	local noIdentifiers = #GetPlayerIdentifiers(s) -- How many Identifiers the player has (usually 2 or 3)
	local currentId = 0 -- The index of the id we're checking
	local totalChecksNeeded = totalInWhitelist * noIdentifiers -- The total number of interations we need (to check the entire array)
	
	-- Loop though the player's identifiers
    for myIdx,identifier in pairs(GetPlayerIdentifiers(s)) do
	
		-- Loop through the whitelist array
        for wIdx,i in ipairs(whitelistArray) do
			
			-- Check if the player exists in the array.
            if(string.lower(i) == string.lower(identifier))then
                deferrals.done() -- They're in it... Let them in!
                joined = true 
				break -- no longer need to loop 
            end
			
			-- Tell user how much we've done
			deferrals.update(string.format("Checking whitelist: %.2f%%", (currentId / totalChecksNeeded)*100))

			Wait(1)
			currentId = currentId +1
        end
    end
	if joined then
		return
	end
	
	-- Tell them to get lost. They're not in the array!
	deferrals.done("You are not whitelisted.")
end)

And an example JSON file

[
	"steam:11000010abeb8a3",
	"ip:127.0.0.1"
]
12 Likes

Moved it for ya :wink:

1 Like

Thank you. I did flag for moderators. I guess I can tell them you did it :stuck_out_tongue:

1 Like

Works Perfect Cheers Mate Best One I have seen that works thanks so much keep up the good work bro hope to see more releases from you :slight_smile:

Great Script Keep Up The Good Work!

Nice. Will give it a whirl. Hopefully easier to restart without having to restart server (for those ppl who are always late to the party).

can you please make how to install tuto?

1 Like

I think all you need to do is go to the whitelist.json and add the steam id’s or ip’s of the people you want whitelisted

1 Like

Yes. This is exactly it. You just need to know the people’s identifiers. You can then add them to the JSON file (by default it’s called “whitelist.json”)

1 Like

it still says im not whitelisted

Do you want to PM me with your whitelist.json file and i’ll take a look?

yes i will
20 charachter

There was a problem with the script when people put capital letters in the identifiers. I have fixed this in the latest version. Make sure to download the latest one.

It’s the one with this on line 56: if(string.lower(i) == string.lower(identifier))then.

Thank you @Officer_Kifflom for pointing it out :smiley:

Nice Script guy:see_no_evil:

oh im am so happy you fixed it @Enfer

@Enfer This is great, works very well. Is it possible to get the “you are not whitelisted” message to come up at all times? Often my users get “unknown client” as the error when trying to join and not the “not whitelisted” message.

has how to do for UserID? Or the only options in this script is SteamID and IP?

Where can i get the IP? Like friends and my IP? Do you mean IP Adress

I don’t know why this happens. I thought I fixed it when I added the joined variable… Apparently not :confused:

What is UserID? This script only work with License, Steam and IPs (the identifiers you can get from the natives).

UserID is something of the VRP, do not know if it has in others, but it is basically the ID of the person within the server