diff options
author | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-06-29 02:22:11 +0200 |
---|---|---|
committer | Gabriel Pérez-Cerezo <gabriel@gpcf.eu> | 2019-06-29 02:22:11 +0200 |
commit | 9456ffb8db652fe6659121c6ccba99ae72c31ceb (patch) | |
tree | 54a3e161b4a5e787e5bbaf7c18b8d6afad6a06c2 | |
parent | c6c91787e0d04758bd93e6ca791b97d2aa2118b8 (diff) | |
parent | e937f5ff67eaf1dc87f8d9b0502dd0825ed9b5bd (diff) | |
download | xban2-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.
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | gui.lua | 2 | ||||
-rw-r--r-- | init.lua | 40 |
3 files changed, 44 insertions, 4 deletions
@@ -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` @@ -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 @@ -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() |