Skip to content

Commit

Permalink
log to debug.txt too
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed May 20, 2021
1 parent 538aea0 commit 29e3d7c
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,33 @@ function geoip.lookup(ip, callback)
end)
end

local function format_result(result)
if result and result.status == "success" and result.data and result.data.geo then
local txt = "Geoip result: "
if result.data.geo.country_name then
txt = txt .. " Country: " .. result.data.geo.country_name
end
if result.data.geo.city then
txt = txt .. " City: " .. result.data.geo.city
end
if result.data.geo.timezone then
txt = txt .. " Timezone: " .. result.data.geo.timezone
end
if result.data.geo.asn then
txt = txt .. " ASN: " .. result.data.geo.asn
end
if result.data.geo.isp then
txt = txt .. " ISP: " .. result.data.geo.isp
end
if result.data.geo.ip then
txt = txt .. " IP: " .. result.data.geo.ip
end
return txt
else
return false
end
end

-- function(name, result)
geoip.joinplayer_callback = function() end

Expand All @@ -45,6 +72,12 @@ minetest.register_on_joinplayer(function(player)
end

geoip.lookup(ip, function(data)
-- log to debug.txt
local txt = format_result(data)
if txt then
minetest.log("action", "[geoip] result for player " .. name .. ": " .. txt)
end

-- execute callback
geoip.joinplayer_callback(name, data)
end)
Expand Down Expand Up @@ -74,27 +107,11 @@ minetest.register_chatcommand("geoip", {
end

geoip.lookup(ip, function(result)
local txt = "Geoip result: "

if result and result.status == "success" and result.data and result.data.geo then
if result.data.geo.country_name then
txt = txt .. " Country: " .. result.data.geo.country_name
end
if result.data.geo.city then
txt = txt .. " City: " .. result.data.geo.city
end
if result.data.geo.timezone then
txt = txt .. " Timezone: " .. result.data.geo.timezone
end
if result.data.geo.asn then
txt = txt .. " ASN: " .. result.data.geo.asn
end
if result.data.geo.isp then
txt = txt .. " ISP: " .. result.data.geo.isp
end
txt = txt .. " IP: " .. ip
else
local txt = format_result(result)

if not txt then
minetest.chat_send_player(name, "Geoip error: " .. (result.description or "unknown error"))
return
end

minetest.log("action", "[geoip] result for player " .. param .. ": " .. txt)
Expand Down

0 comments on commit 29e3d7c

Please sign in to comment.