aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Rudin <thomas@rudin.li>2019-06-06 18:54:46 +0200
committerSmallJoker <SmallJoker@users.noreply.github.com>2019-06-06 18:54:46 +0200
commite937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd (patch)
tree7ce2c9714eafdc797b69066d9b2d5b932e924e19
parent3b700453651e7119c2c48c62d009ed2edf336c93 (diff)
downloadxban2-e937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd.tar.gz
xban2-e937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd.tar.bz2
xban2-e937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd.zip
Add /xban_cleanup command to purge unbanned entries (#20)
Add documentation for /xban_cleanup
-rw-r--r--README.md6
-rw-r--r--init.lua25
2 files changed, 31 insertions, 0 deletions
diff --git a/README.md b/README.md
index 90eed0d..75f8e88 100644
--- a/README.md
+++ b/README.md
@@ -104,3 +104,9 @@ the supported import plugins at the time of writing:
* `v2`: Old format used by xban (`players.iplist.v2`).
**Example:** `/xban_dbi minetest`
+
+### `xban_cleanup`
+
+Removes all non-banned entries from the xban db.
+
+**Usage:** `/xban_cleanup`
diff --git a/init.lua b/init.lua
index 6f15f14..68a3508 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,30 @@ 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 old_count = #db
+
+ local i = 1
+ while i <= #db do
+ if not db[i].banned then
+ -- not banned, remove from db
+ table.remove(db, i)
+ else
+ -- banned, hold entry back
+ i = i + 1
+ end
+ end
+
+ -- save immediately
+ save_db()
+
+ return true, "Removed " .. (old_count - #db) .. " entries, new db entry-count: " .. #db
+ end,
+})
+
minetest.register_on_shutdown(save_db)
minetest.after(SAVE_INTERVAL, save_db)
load_db()