• Blacklist certain countries from joining
    5 replies, posted
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 [url]http://facepunch.com/showthread.php?t=1433512[/url]
[QUOTE=NiandraLades;46505466]See this magnificent little thread [url]http://facepunch.com/showthread.php?t=1433512[/url][/QUOTE] That was the thread I was searching for, thank you Would this work then? [CODE]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 [/CODE] 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. [code] 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 [/code] This should work [code] 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 [/code]
wooa, got a little bit of profiling going on here :-)
you can also use this if you don't want to contact outside websites [url]http://wiki.garrysmod.com/page/system/GetCountry[/url] it's not going to be as accurate (since it DOES return the LANGUAGE of the system - not the actual country)
Sorry, you need to Log In to post a reply to this thread.