mirror of
https://github.com/minetest-mods/xban2.git
synced 2025-04-30 13:41:40 -04:00
Replace counter with array length delta calculation
This commit is contained in:
parent
a646b66618
commit
9b2f4c55d2
1 changed files with 2 additions and 3 deletions
5
init.lua
5
init.lua
|
@ -379,14 +379,13 @@ minetest.register_chatcommand("xban_cleanup", {
|
||||||
description = "Removes all non-banned entries from the xban db",
|
description = "Removes all non-banned entries from the xban db",
|
||||||
privs = { server=true },
|
privs = { server=true },
|
||||||
func = function(name, params)
|
func = function(name, params)
|
||||||
local rm_count = 0
|
local old_count = #db
|
||||||
|
|
||||||
local i = 1
|
local i = 1
|
||||||
while i <= #db do
|
while i <= #db do
|
||||||
if not db[i].banned then
|
if not db[i].banned then
|
||||||
-- not banned, remove from db
|
-- not banned, remove from db
|
||||||
table.remove(db, i)
|
table.remove(db, i)
|
||||||
rm_count = rm_count + 1
|
|
||||||
else
|
else
|
||||||
-- banned, hold entry back
|
-- banned, hold entry back
|
||||||
i = i + 1
|
i = i + 1
|
||||||
|
@ -396,7 +395,7 @@ minetest.register_chatcommand("xban_cleanup", {
|
||||||
-- save immediately
|
-- save immediately
|
||||||
save_db()
|
save_db()
|
||||||
|
|
||||||
return true, "removed " .. rm_count .. " entries, new db entry-count: " .. #db
|
return true, "Removed " .. (old_count - #db) .. " entries, new db entry-count: " .. #db
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue