From 93dfff65ee74518c427a26eef0bc5c924e4479c2 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sat, 16 Aug 2014 09:53:41 +0200 Subject: [PATCH] Timestamp! --- functions.lua | 15 +++++++-------- init.lua | 5 +++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/functions.lua b/functions.lua index f3a0e73..d43826c 100644 --- a/functions.lua +++ b/functions.lua @@ -12,10 +12,10 @@ function ipnames.command_whois(name, param) return end - local ip = ipnames.data[param] + local ip = ipnames.data[param][1] local names = "" for k, v in pairs(ipnames.data) do - if v == ip then + if v[1] == ip then names = names.." "..k end end @@ -61,13 +61,14 @@ function ipnames.load_data() end if #data >= 3 and not ignore then -- Remove IP after 2 weeks - local cd = tonumber(data[3]) - if t - cd > (3600 * 24 * 14) then + data[3] = tonumber(data[3]) + if t - data[3] > (3600 * 24 * 14) then ignore = true end end if not ignore then - ipnames.data[data[1]] = data[2] + data[3] = data[3] or 0 + ipnames.data[data[1]] = {data[2], data[3]} end end end @@ -82,9 +83,7 @@ function ipnames.save_data() ipnames.changes = false local file = io.open(ipnames.file, "w") for k, v in pairs(ipnames.data) do - if v ~= nil then - file:write(k.."|"..v.."\n") - end + file:write(k.."|"..v[1].."|"..v[2].."\n") end io.close(file) end diff --git a/init.lua b/init.lua index c0af625..1c36959 100644 --- a/init.lua +++ b/init.lua @@ -63,7 +63,7 @@ minetest.register_on_prejoinplayer(function(name, ip) local count = 1 local names = "" for k, v in pairs(ipnames.data) do - if v == ip then + if v[1] == ip then if ipnames.whitelist[k] then count = 0 break @@ -82,7 +82,8 @@ end) -- Save IP if player joined minetest.register_on_joinplayer(function(player) local name = player:get_player_name() - ipnames.data[name] = ipnames.tmp_data[name] + local t = os.time() + ipnames.data[name] = {ipnames.tmp_data[name], t} ipnames.tmp_data[name] = nil ipnames.changes = true end)