aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-06-29 02:22:11 +0200
committerGabriel Pérez-Cerezo <gabriel@gpcf.eu>2019-06-29 02:22:11 +0200
commit9456ffb8db652fe6659121c6ccba99ae72c31ceb (patch)
tree54a3e161b4a5e787e5bbaf7c18b8d6afad6a06c2 /init.lua
parentc6c91787e0d04758bd93e6ca791b97d2aa2118b8 (diff)
parente937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd (diff)
downloadxban2-9456ffb8db652fe6659121c6ccba99ae72c31ceb.tar.gz
xban2-9456ffb8db652fe6659121c6ccba99ae72c31ceb.tar.bz2
xban2-9456ffb8db652fe6659121c6ccba99ae72c31ceb.zip
Merge https://github.com/minetest-mods/xban2, Cleanup function
Modify cleanup function to remove only uninteresting entries, not only not banned users. This makes the function more suitable to an xban mod where ban is not the only type of entry available.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua40
1 files changed, 37 insertions, 3 deletions
diff --git a/init.lua b/init.lua
index 5777fab..6cf4691 100644
--- a/init.lua
+++ b/init.lua
@@ -181,9 +181,8 @@ function xban.add_whitelist(name_or_ip, source)
}
return true
end
-
-function xban.get_alt_accounts(player)
- local e = xban.find_entry(player)
+function xban.get_account_names(e)
+ -- get accounts associated with entry
local names = {}
if not e then
return nil, ("No entry for `%s'"):format(player)
@@ -196,6 +195,11 @@ function xban.get_alt_accounts(player)
return names
end
+function xban.get_alt_accounts(player)
+ local e = xban.find_entry(player)
+ return xban.get_account_names(e)
+end
+
function xban.get_record(player)
local e = xban.find_entry(player)
if not e then
@@ -408,6 +412,7 @@ minetest.register_chatcommand("xban_wl", {
end,
})
+
local function clean_db()
-- Removes old IP addresses for data protection and false positive
-- prevention
@@ -427,6 +432,7 @@ local function clean_db()
end
ACTION("Cleaned %d old IP addresses.", cleaned)
end
+
local function check_temp_bans()
minetest.after(60, check_temp_bans)
local to_rm = { }
@@ -492,6 +498,34 @@ local function load_db()
end
end
+local function has_alt_accounts (e)
+ local a = xban.get_account_names(e)
+ return a and #a > 1
+end
+
+minetest.register_chatcommand("xban_cleanup", {
+ description = "Removes all uninteresting entries from the xban db",
+ privs = { server=true },
+ func = function(name, params)
+ local old_count = #db
+
+ local i = 1
+ while i <= #db do
+ if #db[i].record == 0 and not has_alt_accounts(db[i]) 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()