Skip to content

Instantly share code, notes, and snippets.

@SwadicalRag
Created April 21, 2017 11:58
Show Gist options
  • Save SwadicalRag/5c8214f33539610ce759829ec0fc950a to your computer and use it in GitHub Desktop.
Save SwadicalRag/5c8214f33539610ce759829ec0fc950a to your computer and use it in GitHub Desktop.
IP filter
IPFilter = {}
-- CONFIG
IPFilter.KickMessage = "Sorry %s, you have been kicked by the IP filter" -- %s = name
IPFilter.BlacklistedIPs = {
-- Lua patterns
-- "%d.%d%.%d.1",
}
IPFilter.BlacklistedCountries = {
-- country substrings, case insensitive
-- "France",
}
hook.Add("CheckPassword","IPFilter",function(steamID64,ip,_,_,username)
for _,pattern in ipairs(IPFilter.BlacklistedIPs) do
if ip:match(pattern) then return true,string.format(IPFilter.KickMessage,username) end
end
http.Fetch(string.format("http://ip-api.com/json/%s",ip),function(body)
local data = util.JSONToTable(body)
local country = tostring(data.country):lower()
for _,substring in ipairs(IPFilter.BlacklistedIPs) do
if country:find(substring:lower(),1,true) then
game.KickID(util.SteamIDFrom64(steamID64),string.format(IPFilter.KickMessage,username))
return
end
end
end)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment