Advertisement
Guest User

Untitled

a guest
May 24th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local GeoIP = "http://www.telize.com/geoip/" -- A GeoIP API
  2.  
  3. local function isLocalIP(ip)
  4.     return ip == '127.0.0.1' or string.sub(ip, 1, 8) == '192.168.'
  5. end
  6.  
  7. function proxyCheck()
  8.     --IP Proxy Check
  9.     local thePlayer = source
  10.     local ip = getPlayerIP(thePlayer)
  11.    
  12.     if not ip then
  13.         outputDebugString("[BANS] Couldn't get player IP, letting him in..")
  14.         return false
  15.     end
  16.  
  17.     callRemote(GeoIP .. ip, function(data)
  18.         if type(data) ~= "table" then -- Error
  19.             outputDebugString("[BANS] Issue retriveing proxy information: "..data)
  20.             return false
  21.         end
  22.  
  23.         local country_code = data.country_code
  24.         local longitude = data.longitude
  25.         local latitude = data.latitude
  26.         local count = 0
  27.         for _ in pairs(data) do count = count + 1 end
  28.  
  29.         -- Conditions
  30.  
  31.         if (count == 0) then -- Failed to retrieve information. Let them in.
  32.             outputDebugString("[BANS] Couldn't get any info..")
  33.             return false
  34.         elseif isLocalIP( ip ) then
  35.             outputDebugString( "[BANS] Local IP detected: "..ip )
  36.             return false
  37.         elseif count == 1 then -- Only returned the IP address meaning either their IP is spoofed or internal.
  38.             outputDebugString("[BANS] Spoofed: ".. ip)
  39.             outputChatBox("There is a issue with your IP address. Please contact us at www.olwgaming.net", thePlayer, 255, 0, 0)
  40.             kickPlayer(thePlayer, "There is a issue with your IP address.")
  41.             return true
  42.         elseif (not country_code) or (country_code == "A1") or (not longitude) or (not latitude) or (longitude == 0 and latitude == 0) then
  43.             outputChatBox("Your IP address is not genuine. Please connct without using a proxy service.", thePlayer, 255, 0, 0)
  44.             exports.global:sendMessageToAdmins("[BANS] Rejected connection from IP: '"..ip.."' as it has automatically been detected as non-genuine.")
  45.             kickPlayer(thePlayer, "Your IP address is not genuine.")
  46.             return true
  47.         end
  48.     end )
  49.     return false
  50. end
  51. addEventHandler("onPlayerJoin", getRootElement(), proxyCheck)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement