Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GEOIP Announce / Log
- -- need geoip-bin on linux
- function os.capture(cmd, raw)
- local f = assert(io.popen(cmd, 'r'))
- local s = assert(f:read('*a'))
- f:close()
- if raw then return s end
- s = string.gsub(s, '^%s+', '')
- s = string.gsub(s, '%s+$', '')
- s = string.gsub(s, '[\n\r]+', ' ')
- return s
- end
- minetest.register_on_joinplayer(function(player)
- local playername = player:get_player_name()
- local ip = minetest.get_player_ip(playername)
- local location = os.capture("geoiplookup "..ip)
- location = location:gsub('GeoIP Country Edition: ','')
- location = location:gsub('IP Address not found','location unknown')
- minetest.chat_send_all(playername..' from '..location)
- minetest.log('action','[GEOIP] '.. playername.. " from "..location)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement