mirror of
https://github.com/minetest-mods/xban2.git
synced 2024-11-14 12:20:18 +01:00
Allow importing old databases.
Currently: - Minetest (`ipban.txt') - xban v1 (`players.iplist')
This commit is contained in:
parent
51097eee6b
commit
d47e87e390
37
dbimport.lua
Normal file
37
dbimport.lua
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
xban.importers = { }
|
||||
|
||||
dofile(xban.MP.."/importers/minetest.lua")
|
||||
dofile(xban.MP.."/importers/v1.lua")
|
||||
|
||||
minetest.register_chatcommand("xban_dbi", {
|
||||
description = "Import old databases",
|
||||
params = "<importer>",
|
||||
privs = { server=true },
|
||||
func = function(name, params)
|
||||
if params == "--list" then
|
||||
local names = { }
|
||||
for name in pairs(xban.importers) do
|
||||
table.insert(names, name)
|
||||
end
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Known importers: %s"):format(
|
||||
table.concat(names, ", ")))
|
||||
return
|
||||
elseif not xban.importers[params] then
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Unknown importer `%s'"):format(params))
|
||||
minetest.chat_send_player(name, "[xban] Try `--list'")
|
||||
return
|
||||
end
|
||||
local f = xban.importers[params]
|
||||
local ok, err = f()
|
||||
if ok then
|
||||
minetest.chat_send_player(name,
|
||||
"[xban] Import successfull")
|
||||
else
|
||||
minetest.chat_send_player(name,
|
||||
("[xban] Import failed: %s"):format(err))
|
||||
end
|
||||
end,
|
||||
})
|
29
importers/minetest.lua
Normal file
29
importers/minetest.lua
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
function xban.importers.minetest()
|
||||
local f, e = io.open(minetest.get_worldpath().."/ipban.txt")
|
||||
if not f then
|
||||
return false, "Unable to open `ipban.txt': "..e
|
||||
end
|
||||
for line in f:lines() do
|
||||
local ip, name = line:match("([^|]+)%|(.+)")
|
||||
if ip and name then
|
||||
local entry
|
||||
entry = xban.find_entry(ip, true)
|
||||
entry.banned = true
|
||||
entry.reason = "Banned in `ipban.txt'"
|
||||
entry.names[name] = true
|
||||
entry.names[ip] = true
|
||||
entry.time = os.time()
|
||||
entry.expires = nil
|
||||
entry.source = "xban:importer_minetest"
|
||||
table.insert(entry.record, {
|
||||
source = entry.source,
|
||||
reason = entry.reason,
|
||||
time = entry.time,
|
||||
expires = nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
33
importers/v1.lua
Normal file
33
importers/v1.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
|
||||
function xban.importers.v1()
|
||||
local f, e = io.open(minetest.get_worldpath().."/players.iplist")
|
||||
if not f then
|
||||
return false, "Unable to open `players.iplist': "..e
|
||||
end
|
||||
for line in f:lines() do
|
||||
local list = line:split("|")
|
||||
if #list >= 2 then
|
||||
local banned = (list[1]:sub(1, 1) == "!")
|
||||
local entry
|
||||
entry = xban.find_entry(list[1], true)
|
||||
entry.banned = banned
|
||||
for _, name in ipairs(list) do
|
||||
entry.names[name] = true
|
||||
end
|
||||
if banned then
|
||||
entry.reason = "Banned in `players.iplist'"
|
||||
entry.time = os.time()
|
||||
entry.expires = nil
|
||||
entry.source = "xban:importer_v1"
|
||||
table.insert(entry.record, {
|
||||
source = entry.source,
|
||||
reason = entry.reason,
|
||||
time = entry.time,
|
||||
expires = nil,
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
f:close()
|
||||
return true
|
||||
end
|
8
init.lua
8
init.lua
|
@ -1,9 +1,7 @@
|
|||
|
||||
xban = { }
|
||||
xban = { MP = minetest.get_modpath(minetest.get_current_modname()) }
|
||||
|
||||
local MP = minetest.get_modpath(minetest.get_current_modname())
|
||||
|
||||
dofile(MP.."/serialize.lua")
|
||||
dofile(xban.MP.."/serialize.lua")
|
||||
|
||||
local db = { }
|
||||
local tempbans = { }
|
||||
|
@ -262,3 +260,5 @@ minetest.register_on_shutdown(save_db)
|
|||
minetest.after(SAVE_INTERVAL, save_db)
|
||||
load_db()
|
||||
xban.db = db
|
||||
|
||||
dofile(xban.MP.."/dbimport.lua")
|
||||
|
|
Loading…
Reference in New Issue
Block a user