Blacklist certain countries from joining

Does anyone have an idea on how I can block certain countries from joining using global IP? And add a whitelist for certain IP’s.

Our server is Norwegian, and people from Germany etc tend to join so they can break all kinds of rules.

If someone could post an example code that would be great!

Thank you

See this magnificent little thread
http://forum.facepunch.com/showthread.php?t=1433512

That was the thread I was searching for, thank you
Would this work then?


hook.Add("PlayerInitialSpawn", "FetchPlayerCountry", function(ply)
    timer.Simple(1,function()
	http.Fetch("http://freegeoip.net/json/" .. (ply:IPAddress():Split(":")[1]), function(data)
		local tbl = util.JSONToTable(data)
		if tbl and IsValid(ply) then
			ply:SetNWString("countryname", tbl.country_name)
			ply:SetNWString("countrycode", tbl.country_code)
		end
    end, function() end)
    end)
end)


function player.GetRussians()
    local tbl = {}
    for k,v in pairs(player.GetAll()) do
        if v:GetNWString("countrycode","...") == "RU" then
        if v:GetNWString("countrycode","...") == "GB" then
        if v:GetNWString("countrycode","...") == "DE" then
        table.insert(tbl,v)
        end
    end
    return tbl
end


Now I just need to figure out how to whitelist certain IP’s hmm, help anyone?

This code will not work because 1. You didnt close your “if then” blocks 2. You are checking if they are Russian and British and German before adding them to your table.



 for k,v in pairs(player.GetAll()) do
        if v:GetNWString("countrycode","...") == "RU" then
        if v:GetNWString("countrycode","...") == "GB" then
        if v:GetNWString("countrycode","...") == "DE" then
        table.insert(tbl,v)
        end


This should work



 for k,v in pairs(player.GetAll()) do
       local country = v:GetNWString("countrycode","...")
       if country == "RU" or country == "GB" or country == "DE" then
               table.insert(tbl,v)
        end
end


wooa, got a little bit of profiling going on here :slight_smile:

you can also use this if you don’t want to contact outside websites

it’s not going to be as accurate (since it DOES return the LANGUAGE of the system - not the actual country)