10 Commits

3 changed files with 46 additions and 4 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`). * `v2`: Old format used by xban (`players.iplist.v2`).
**Example:** `/xban_dbi minetest` **Example:** `/xban_dbi minetest`
### `xban_cleanup`
Removes all non-banned entries from the xban db.
**Usage:** `/xban_cleanup`

View File

@ -61,7 +61,8 @@ local function make_fs(name)
"size[16,12]", "size[16,12]",
"label[0,-.1;Filter]", "label[0,-.1;Filter]",
"field[1.5,0;12.8,1;filter;;"..ESC(filter).."]", "field[1.5,0;12.8,1;filter;;"..ESC(filter).."]",
"button[14,-.3;2,1;search;Search]", "field_close_on_enter[filter;false]",
"button[14,-.3;2,1;search_submit;Search]",
} }
local fsn = #fs local fsn = #fs
fsn=fsn+1 fs[fsn] = format("textlist[0,.8;4,9.3;player;%s;%d;0]", fsn=fsn+1 fs[fsn] = format("textlist[0,.8;4,9.3;player;%s;%d;0]",
@ -122,7 +123,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end end
return return
end end
if fields.search then if fields.search_submit or fields.filter then
local filter = fields.filter or "" local filter = fields.filter or ""
state.filter = filter state.filter = filter
state.list = make_list(filter) state.list = make_list(filter)

View File

@ -40,6 +40,14 @@ local function parse_time(t) --> secs
return secs return secs
end 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 function xban.find_entry(player, create) --> entry, index
for index, e in ipairs(db) do for index, e in ipairs(db) do
for name in pairs(e.names) do for name in pairs(e.names) do
@ -111,7 +119,7 @@ function xban.ban_player(player, source, expires, reason) --> bool, err
end end
ACTION("%s bans %s until %s for reason: %s", source, player, ACTION("%s bans %s until %s for reason: %s", source, player,
date, reason) date, reason)
ACTION("Banned Names/IPs: %s", table.concat(e.names, ", ")) ACTION("Banned Names/IPs: %s", concat_keys(e.names, ", "))
return true return true
end end
@ -131,7 +139,7 @@ function xban.unban_player(player, source) --> bool, err
e.expires = nil e.expires = nil
e.time = nil e.time = nil
ACTION("%s unbans %s", source, player) 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 return true
end end
@ -314,6 +322,7 @@ minetest.register_chatcommand("xban_wl", {
end, end,
}) })
local function check_temp_bans() local function check_temp_bans()
minetest.after(60, check_temp_bans) minetest.after(60, check_temp_bans)
local to_rm = { } local to_rm = { }
@ -374,6 +383,30 @@ local function load_db()
end end
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.register_on_shutdown(save_db)
minetest.after(SAVE_INTERVAL, save_db) minetest.after(SAVE_INTERVAL, save_db)
load_db() load_db()
@ -383,3 +416,5 @@ minetest.after(1, check_temp_bans)
dofile(xban.MP.."/dbimport.lua") dofile(xban.MP.."/dbimport.lua")
dofile(xban.MP.."/gui.lua") dofile(xban.MP.."/gui.lua")
minetest.log("action", "[xban2] loaded.")