Advertisement
Guest User

flying pancakes

a guest
Sep 23rd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 0
  1.  
  2. --               GEOIP Announce / Log
  3. -- need geoip-bin on linux
  4.  
  5. function os.capture(cmd, raw)
  6.   local f = assert(io.popen(cmd, 'r'))
  7.   local s = assert(f:read('*a'))
  8.   f:close()
  9.   if raw then return s end
  10.   s = string.gsub(s, '^%s+', '')
  11.   s = string.gsub(s, '%s+$', '')
  12.   s = string.gsub(s, '[\n\r]+', ' ')
  13.   return s
  14. end
  15.  
  16. minetest.register_on_joinplayer(function(player)
  17.     local playername = player:get_player_name()
  18.     local ip = minetest.get_player_ip(playername)
  19.     local location = os.capture("geoiplookup "..ip)
  20.     location = location:gsub('GeoIP Country Edition: ','')
  21.     location = location:gsub('IP Address not found','location unknown')
  22.    
  23.     minetest.chat_send_all(playername..' from '..location)
  24.     minetest.log('action','[GEOIP] '.. playername.. " from "..location)
  25. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement