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.
master
Gabriel Pérez-Cerezo 2019-06-29 02:22:11 +02:00
commit 9456ffb8db
3 changed files with 44 additions and 4 deletions

View File

@ -116,3 +116,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`

View File

@ -9,7 +9,7 @@ local ESC = minetest.formspec_escape
local function make_list(filter)
filter = filter or ""
local list, n, dropped = { }, 0, false
for k in pairs(minetest.auth_table) do
for k in minetest.get_auth_handler().iterate() do
if strfind(k, filter, 1, true) then
if n >= MAXLISTSIZE then
dropped = true

View File

@ -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()