add /xban_cleanup command to compact db / purge unbanned entries

This commit is contained in:
NatureFreshMilk 2019-06-05 13:48:34 +02:00
parent 3b70045365
commit 486506ceff
1 changed files with 26 additions and 0 deletions

View File

@ -314,6 +314,7 @@ minetest.register_chatcommand("xban_wl", {
end,
})
local function check_temp_bans()
minetest.after(60, check_temp_bans)
local to_rm = { }
@ -374,6 +375,31 @@ local function load_db()
end
end
minetest.register_chatcommand("xban_cleanup", {
description = "Removes all non-banned entries from the xban db",
privs = { server=true },
func = function(name, params)
local rm_count = 0
local i = 1
while i <= #db do
if not db[i].banned then
-- not banned, remove from db
table.remove(db, i)
rm_count = rm_count + 1
else
-- banned, hold entry back
i = i + 1
end
end
-- save immediately
save_db()
return true, "removed " .. rm_count .. " entries, new db entry-count: " .. #db
end,
})
minetest.register_on_shutdown(save_db)
minetest.after(SAVE_INTERVAL, save_db)
load_db()