From ed621c5ce02a340890e45b2f86a7969f0cfdcd6d Mon Sep 17 00:00:00 2001 From: Diego Martinez Date: Thu, 26 Jun 2014 03:17:40 -0300 Subject: [PATCH] Add v2 database importer. --- dbimport.lua | 1 + importers/v2.lua | 35 +++++++++++++++++++++++++++++++++++ init.lua | 1 + 3 files changed, 37 insertions(+) create mode 100644 importers/v2.lua diff --git a/dbimport.lua b/dbimport.lua index 22fef27..ec9293d 100644 --- a/dbimport.lua +++ b/dbimport.lua @@ -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", diff --git a/importers/v2.lua b/importers/v2.lua new file mode 100644 index 0000000..fd29966 --- /dev/null +++ b/importers/v2.lua @@ -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 diff --git a/init.lua b/init.lua index 7156255..3199e50 100644 --- a/init.lua +++ b/init.lua @@ -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,