From 486506ceff494e3f511fc0a039692ddffb821c5e Mon Sep 17 00:00:00 2001 From: NatureFreshMilk Date: Wed, 5 Jun 2019 13:48:34 +0200 Subject: [PATCH] add /xban_cleanup command to compact db / purge unbanned entries --- init.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/init.lua b/init.lua index 6f15f14..4256e92 100644 --- a/init.lua +++ b/init.lua @@ -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()