Country Whitelist

Hi, I was wondering like how to make a sort of country whitelist. I know that this has to do with the IP but I don’t know what :smiley:

If you’re asking what I think you’re asking and only want players from a certain country to join your server, I think this is what you’re looking for:

Client-side



hook.Add("InitPostEntity", "CheckPlayerCountry", function()
    local countryCode = system.GetCountry();
    if countryCode != INSERT_YOUR_COUNTRY_CODE_HERE then
        net.Start("FailedWhitelist");
        net.SendToServer();
    end
end);


Server-side



util.AddNetworkString("FailedWhitelist");
net.Receive("FailedWhitelist", function(len, ply)
    ply:Kick("You are not on the server whitelist!");
end);


Country codes can be found here. If you want to include more than one country, store the country codes in a table and reference them client side in the ‘if’ condition.

Thanks man you helped me a lot :smiley:

[editline]28th July 2015[/editline]

Just Like the country code should be written like :


hook.Add("InitPostEntity", "RegardeLeCountryCode", function()
    local countryCode = system.GetCountry();
    if countryCode != ISO 3166-2:UM then
        net.Start("FailedWhitelist");
        net.SendToServer();
    end
end); 

ISO 3166-2:UM ?

[editline]28th July 2015[/editline]

Or just 3166-2:UM
or 3166-2

It needs to be the two letter code, and it also needs to be a string. So, if you want to only allow people from the USA, you need to write:



 if countryCode != "US" then
-- code
end


I tried A few Times and it didn’t really worked…

Can I see your code/where you put it? You changed the INSERT_YOUR_COUNTRY_CODE_HERE variable, correct?

EDIT: Saw your edit, see AK’s post.
Use country codes from this column:

There you go :

cl_init.lua




hook.Add("InitPostEntity", "CheckPlayerCountry", function()
    local countryCode = system.GetCountry();
    if countryCode != "UK" then
        net.Start("FailedWhitelist");
        net.SendToServer();
    end
end);


init.lua



AddCSLuaFile("cl_init.lua")

util.AddNetworkString("FailedWhitelist");
net.Receive("FailedWhitelist", function(len, ply)
    ply:Kick("You are not on the server whitelist!");
end);


[editline]28th July 2015[/editline]

An idea ?

Works fine on my end. Do you have any console output to post?

It kicks you ?

It does, since I’m not in the UK. Since I assume you’re in France from your forum profile, it should do the same. Are there any errors in your console?

EDIT : THERE WERE MY IP SO DELETED IT !

[editline]28th July 2015[/editline]

No Errors but I don’t know why…

[editline]28th July 2015[/editline]

I placed thoses guys like this : addons/paddyfloch_country-whitelist/lua/autorun/cl_init.lua and init.lua

[editline]28th July 2015[/editline]

So… What do I do ?

Put the cl_init.lua file into addons/paddyfloch_country-whitelist/lua/autorun/client/ and init.lua into addons/paddyfloch_country-whitelist/lua/autorun/server/ and see if that changes anything.

Nothing happened ;(

[editline]28th July 2015[/editline]

Another idea ?

[editline]28th July 2015[/editline]

Try to connect on my server

[editline]28th July 2015[/editline]

Search for CreationnyMod in the DarkRP Panel

[editline]28th July 2015[/editline]

And you’ll tel me

That’s not normal. Are you using leaked addons?

I do not own this server :slight_smile: my friend told me to make a script for him so yeah but he doesnt use any leaks

You seem to have two copies, I’d remove one before debugging any further.

No first one is in CAPital letter so unreadable for linux

Any idea ?

do note that system.GetCountry returns the computer’s locale setting and NOT geoip

Maybe something like this? I haven’t testing it but it should work

[lua]

CountryWhitelist = {
“GB”,
“US”
}

hook.Add( “PlayerAuthed”, “CountryWhitelist”, function( Pl )

http.Fetch( string.format( "http://www.telize.com/geoip/%s", Pl:IPAddress( ) ), function( body )

	local data = util.JSONToTable( body )
	if ( data ) then
	
		if ( not table.HasValue( CountryWhitelist, data.country_code ) ) then
			Pl:Kick( "We don' like your kind 'ere" )
		end

	end

end)

end)
[/lua]