Is there a bether way of resolving ip on Linux (Ubuntu) ?
Code:
<globalevent name="resolve_ip" interval="60" event="script" value="resolve_ip.lua"/>
Code:
require("socket")
function onThink(interval, lastExecution, thinkInterval)
local begin_time=socket.gettime()
local master= socket.dns.toip(getConfigInfo('ip'))
local page_retrieve_time=(socket.gettime()-begin_time)
local row = db.getResult("SELECT `id`, timestamp, ip, count FROM z_resolve_ip order by id desc limit 1;")
if(row:getID() == -1) then
db.executeQuery("INSERT z_resolve_ip (timestamp, ip, count) VALUES (" .. os.time() .. ", '" .. master .. "', 1, " .. os.time() .. ");")
return true
end
local ID = row:getDataString("id")
local ip = row:getDataString("ip")
local count = row:getDataString("count")
if(ip == master) then
db.executeQuery("update z_resolve_ip set count = count+1, lasttime = " .. os.time() .. " where id = " .. ID .. ";")
else
doSetGameState(GAMESTATE_CLOSED)
db.executeQuery("INSERT z_resolve_ip (timestamp, ip, count, lasttime) VALUES (" .. os.time() .. ", '" .. master .. "', 1, " .. os.time() .. ");")
doSetGameState(GAMESTATE_SHUTDOWN)
end
return true
end