5 Commits

Author SHA1 Message Date
72a99b2b18 Merge branch 'master' of yunohost:minetest-mods/xban2 into nalc-1.2-dev 2019-12-22 16:08:18 +01:00
37cdbf014e Fix list of names in log message upon (un-)banning 2019-11-05 16:49:50 +01:00
e937f5ff67 Add /xban_cleanup command to purge unbanned entries (#20)
Add documentation for /xban_cleanup
2019-06-06 18:54:46 +02:00
43acd1c620 Merge branch 'master' into nalc-1.2 2019-05-10 02:25:27 +02:00
3b70045365 Update to 5.0 auth. 2019-02-12 16:53:03 -03:00
3 changed files with 42 additions and 5 deletions

View File

@ -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`

View File

@ -9,9 +9,7 @@ local ESC = minetest.formspec_escape
local function make_list(filter)
filter = filter or ""
local list, n, dropped = { }, 0, false
local enumerate, e1, e2, e3 = minetest.get_auth_handler().enumerate_auths
if enumerate then e1 = enumerate() else e1, e2, e3 = pairs(minetest.auth_table) end
for k in e1, e2, e3 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

@ -40,6 +40,14 @@ local function parse_time(t) --> secs
return secs
end
local function concat_keys(t, sep)
local keys = {}
for k, _ in pairs(t) do
keys[#keys + 1] = k
end
return table.concat(keys, sep)
end
function xban.find_entry(player, create) --> entry, index
for index, e in ipairs(db) do
for name in pairs(e.names) do
@ -111,7 +119,7 @@ function xban.ban_player(player, source, expires, reason) --> bool, err
end
ACTION("%s bans %s until %s for reason: %s", source, player,
date, reason)
ACTION("Banned Names/IPs: %s", table.concat(e.names, ", "))
ACTION("Banned Names/IPs: %s", concat_keys(e.names, ", "))
return true
end
@ -131,7 +139,7 @@ function xban.unban_player(player, source) --> bool, err
e.expires = nil
e.time = nil
ACTION("%s unbans %s", source, player)
ACTION("Unbanned Names/IPs: %s", table.concat(e.names, ", "))
ACTION("Unbanned Names/IPs: %s", concat_keys(e.names, ", "))
return true
end
@ -314,6 +322,7 @@ minetest.register_chatcommand("xban_wl", {
end,
})
local function check_temp_bans()
minetest.after(60, check_temp_bans)
local to_rm = { }
@ -374,6 +383,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()