[OUTDATED][How-to] put whitelist to your server

MOD REQUIRED: Essential-Mode !
Warning: make a backup of your script before running this tutorial
(I would not be responsible for any loss, it is at your own risk)

Please, Before reading this tutorial, excuse me for my bad English, I try to do my best.

Hello everyone.
Today I will explain how to put whitelist to your server.

You have nothing to add in your server folder, only scripts to edit and one table to be added in your database.

  1. add this to your database:

whitelist.sql (1.1 KB)

  1. go in your _/resources/essential-mode/server/ folder and edit main.lua.

  2. Add this below the line 12 (line 12 =[‘banReason’]):

[‘listmsg’] = “You are not whitelisted !”,

like this:

  1. Always in main.lua, add this below the line 43 (below the first AddEventHandler):

AddEventHandler(‘playerConnecting’, function(name, setCallback)
local identifiers = GetPlayerIdentifiers(source)

for i = 1, #identifiers do
local identifier = identifiers[i]
debugMsg('Checking user whitelist: ’ … identifier … " (" … name … “)”)

  local listed = isWhiteListed(identifier)
  if(listed)then
  	if(type(settings.defaultSettings.listmsg) == "string")then
  		setCallback(settings.defaultSettings.listmsg)
  	elseif(type(settings.defaultSettings.listmsg) == "function")then
  		setCallback(settings.defaultSettings.listmsg(identifier, name))
  	else
  		setCallback("Not whitelisted !")
  	end
  	CancelEvent()
  end

end
end)

like this:

  1. go in your _/resources/essential-mode/server/player/ folder and edit login.lua

  2. Add this below the line 54 (below the isIdentifierBanned function):

function isWhiteListed(identifier)
local executed_query = MySQL:executeQuery(“SELECT * FROM whitelist WHERE identifier = ‘@name’”, {[‘@name’] = identifier})
local result = MySQL:getResults(executed_query, {‘listed’}, “identifier”)

if(result)then
for k,v in ipairs(result)do
if v.listed == 1 then
return false
end
end
end

return true
end

like this:

After this, just insert in whitelist table the identifier of your user (like in your users table) and replace the “0” by “1” in listed.

(by default) 0 = Player not whitelisted
and 1 = Player whitelisted

[Whitelist] add user by steamID64:
first, go to this website and take the user ID:
https://steamid.io/ (or other website).

  1. Go to this website and put the steamid64 of your user to the Decimal Value field and convert it.
    Decimal to Hexadecimal Converter

After this, put the Hexadecimal Value to your database.
dont forget to put steam: before the Hexadecimal Value :wink:
Exemple: steam:11000010ABCDEF123

[Whitelist] add user by IP adress:
Put The ip adress of your user to the whitelist.
http://whatismyipaddress.com (or other website).
dont forget to put ip: before the ip adress :wink:
Exemple: ip:127.0.0.1

And your user will be on white list and will be able to join you !
Enjoy !

4 Likes

wow ! thanks for this ! i can convert steamid64 to fivem steamid ?

2 Likes

Yes, take this:
http://www.binaryhexconverter.com/decimal-to-hex-converter

put your steamid64 to the Decimal Value field and convert.
after this, put the Hexadecimal Value to your database.
dont forget the steam: or ip before your Hexadecimal Value :wink:

1 Like

Whow ! thanks you :smiley:

1 Like

Humm, player no whitelist can join my server you have a fixe for this ?

Did you follow the tutorial correctly ?
Because the whitelisted function is the inverse of the ban, it prevents everyone from entering except those that are accepted.

Try to see in the tutorial if you have not forgotten anything.

Same problem for me. Some random players can join my server, i don’t know how. Whitelist works, if i’m not whitelisted i can’t join, but some players can.

do you have enabled steam authentication in your citmp-server.yml

DisableAuth: false

Of course, before your whitelist i’m using ACL Whitelist, works perfectly, so i don’t know why

Same problem for me, some other players can join the server !

1 Like

by default do you use essentials or some other basic mode ?

I have done some tests, I use the basic mode essential, I do not encounter problems, I look at all the same if there are no errors

Essentials mode yup. I don’t have errors in the server console, the basic “SELECT xxx whitelist (steam:ffzefzefzp)”

But sometimes, randoms can join my server.

I use essential-mode as you asked in your topic

ok i found this

Replace the 2 addeventhandler (ban included) with this (in your /resources/essential-mode/main.lua:

AddEventHandler(‘playerConnecting’, function(name, setCallback)
local identifiers = GetPlayerIdentifiers(source)

for i = 1, #identifiers do
local identifier = identifiers[i]
debugMsg('Checking user ban: ’ … identifier … " (" … name … “)”)

  local banned = isIdentifierBanned(identifier)
  if(banned)then
  	if(type(settings.defaultSettings.banreason) == "string")then
  		setCallback(settings.defaultSettings.banreason)
  	elseif(type(settings.defaultSettings.banreason) == "function")then
  		setCallback(settings.defaultSettings.banreason(identifier, name))
  	else
  		setCallback("Default ban reason error")
  	end
  	CancelEvent()
  end

end
end)

AddEventHandler(‘playerConnecting’, function(name, setCallback)
local identifiers = GetPlayerIdentifiers(source)

for i = 1, #identifiers do
local identifier = identifiers[i]
debugMsg('Checking user whitelist: ’ … identifier … " (" … name … “)”)

  local listed = isWhiteListed(identifier)
  if(listed)then
  	if(type(settings.defaultSettings.listmsg) == "string")then
  		setCallback(settings.defaultSettings.listmsg)
  	elseif(type(settings.defaultSettings.listmsg) == "function")then
  		setCallback(settings.defaultSettings.listmsg(identifier, name))
  	else
  		setCallback("Not whitelisted !")
  	end
  	CancelEvent()
  end

end
end)

and this 2 functions:

function isIdentifierBanned(id)
local executed_query = MySQL:executeQuery(“SELECT * FROM bans WHERE banned = ‘@name’”, {[‘@name’] = id})
local result = MySQL:getResults(executed_query, {‘expires’, ‘reason’, ‘timestamp’}, “identifier”)

if(result)then
for k,v in ipairs(result)do
if v.expires > v.timestamp then
return true
end
end
end

return false
end

function isWhiteListed(identifier)
local executed_query = MySQL:executeQuery(“SELECT * FROM whitelist WHERE identifier = ‘@name’”, {[‘@name’] = identifier})
local result = MySQL:getResults(executed_query, {‘listed’}, “identifier”)

if(result)then
for k,v in ipairs(result)do
if v.listed == 1 then
return false
end
end
end

return true
end

I already fixed that

same, already fixed that, no changes.

EDIT: well i’m gonna try for a while this modifications ( with ban handler )

I tell you later if it work or not.

Did you create a database yourself or did you take my file?

Because if you created it yourself, you must set in “listed” (int 11 and not null {0 by default}) and identifier must be primary in varchar 200

It could come from that :slight_smile:

Personally it works very well i realy don’t understand why some player can join without whitelist i try my best for the comunity and i try to fix that wih you.

I took your sql file

Ok change the default value from listed, set to 0

Even after all the changes, one man without being whitelisted is in my server…