Add v2 database importer.

This commit is contained in:
Diego Martinez 2014-06-26 03:17:40 -03:00
parent 75c1be2f8e
commit ed621c5ce0
3 changed files with 37 additions and 0 deletions

View File

@ -3,6 +3,7 @@ xban.importers = { }
dofile(xban.MP.."/importers/minetest.lua")
dofile(xban.MP.."/importers/v1.lua")
dofile(xban.MP.."/importers/v2.lua")
minetest.register_chatcommand("xban_dbi", {
description = "Import old databases",

35
importers/v2.lua Normal file
View File

@ -0,0 +1,35 @@
function xban.importers.v2()
return pcall(function()
local f, e = io.open(minetest.get_worldpath().."/players.iplist.v2")
if not f then
error("Unable to open `players.iplist.v2': "..e)
end
local text = f:read("*a")
f:close()
local db = minetest.deserialize(text)
for _, e in ipairs(db) do
for name in pairs(e.names) do
local entry = xban.find_entry(name, true)
if entry.source ~= "xban:importer_v2" then
for nm in pairs(e.names) do
entry.names[nm] = true
end
if e.banned then
entry.banned = true
entry.reason = e.banned
entry.source = "xban:importer_v2"
entry.time = e.time
entry.expires = e.expires
table.insert(entry.record, {
source = entry.source,
reason = entry.reason,
time = entry.time,
expires = entry.expires,
})
end
end
end
end
end)
end

View File

@ -51,6 +51,7 @@ function xban.find_entry(player, create) --> entry, index
end
end
if create then
print(("Created new entry for `%s'"):format(player))
local e = {
names = { [player]=true },
banned = false,