2023-06-20 11:43:13 -04:00
|
|
|
|
2023-06-21 22:00:15 -04:00
|
|
|
function format_result_geoip(result)
|
2023-06-20 11:43:13 -04:00
|
|
|
if result and result.status == "success" and result.data and result.data.geo then
|
2023-06-21 18:02:28 -04:00
|
|
|
local txt = " Place: "
|
|
|
|
if result.data.geo.ip then
|
|
|
|
if result.data.geo.ip == "127.0.0.1" then return txt .. " seems localhost " ..".. <_< ." end
|
|
|
|
end
|
|
|
|
if result.data.geo.continent_name then
|
|
|
|
if result.data.geo.continent_name ~= "" then txt = txt .. result.data.geo.continent_name .."," end
|
|
|
|
end
|
2023-06-20 11:43:13 -04:00
|
|
|
if result.data.geo.country_name then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.country_name ~= "" then txt = txt .. result.data.geo.country_name .."," end
|
|
|
|
end
|
|
|
|
if result.data.geo.region_name then
|
|
|
|
if result.data.geo.region_name ~= "" then txt = txt .. result.data.geo.region_name .. "," end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
if result.data.geo.city then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.city ~= "" then txt = txt .. result.data.geo.city .."" end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
if result.data.geo.timezone then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.timezone ~= "" then txt = txt .. " Timezone: " .. result.data.geo.timezone end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
if result.data.geo.asn then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.asn ~= "" then txt = txt .. " ASN: " .. result.data.geo.asn end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
if result.data.geo.isp then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.isp ~= "" then txt = txt .. " ISP: " .. result.data.geo.isp end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
if result.data.geo.ip then
|
2023-06-21 18:02:28 -04:00
|
|
|
if result.data.geo.ip ~= "" then txt = txt .. " IP: " .. result.data.geo.ip end
|
2023-06-20 11:43:13 -04:00
|
|
|
end
|
|
|
|
return txt
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-06-21 13:58:09 -04:00
|
|
|
if not governing.modgeoip then
|
2023-06-21 16:41:24 -04:00
|
|
|
minetest.register_privilege("geoip", {
|
|
|
|
description = "can do geoip lookups on players for governing",
|
|
|
|
give_to_singleplayer = false
|
|
|
|
})
|
2023-06-21 18:02:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
governing.joinplayer_callback = function() end -- function(name, result)
|
|
|
|
|
|
|
|
minetest.register_on_joinplayer(function(player) -- query ip on join, record in logs and execute callback
|
2023-06-20 11:43:13 -04:00
|
|
|
|
2023-06-21 16:41:24 -04:00
|
|
|
|
2023-06-21 18:02:28 -04:00
|
|
|
if not governing.modgeoip then
|
|
|
|
if not player then return end
|
|
|
|
if not player:is_player() then return end
|
|
|
|
if not minetest.get_player_ip then return end
|
|
|
|
local name = player:get_player_name()
|
|
|
|
local ip = minetest.get_player_ip(name)
|
|
|
|
if not ip then return end
|
|
|
|
governing.lookup(ip, function(data) -- log, but TODO: record in storage log file
|
2023-06-21 22:00:15 -04:00
|
|
|
local txt = format_result_geoip(data)
|
2023-06-21 18:02:28 -04:00
|
|
|
if txt then minetest.log("warning", "[goberning/geoip] joined player, " .. name .. ":" .. ip .. "," .. txt)
|
|
|
|
else minetest.log("error", "[goberning/geoip] joined player, " .. name .. ":" .. ip .. ", seems fails")
|
|
|
|
end
|
|
|
|
governing.joinplayer_callback(name, data) -- execute callback
|
2023-06-20 11:43:13 -04:00
|
|
|
end)
|
2023-06-21 13:58:09 -04:00
|
|
|
end
|
2023-06-21 18:02:28 -04:00
|
|
|
end)
|