Add command to analyze lua entities
This commit is contained in:
parent
587c85411b
commit
82f277c1ab
@ -1,8 +1,8 @@
|
|||||||
-- LUALOCALS < ---------------------------------------------------------
|
-- LUALOCALS < ---------------------------------------------------------
|
||||||
local ipairs, minetest, string, table
|
local ipairs, minetest, pairs, string, table
|
||||||
= ipairs, minetest, string, table
|
= ipairs, minetest, pairs, string, table
|
||||||
local string_format, table_concat, table_remove
|
local string_format, table_concat, table_remove, table_sort
|
||||||
= string.format, table.concat, table.remove
|
= string.format, table.concat, table.remove, table.sort
|
||||||
-- LUALOCALS > ---------------------------------------------------------
|
-- LUALOCALS > ---------------------------------------------------------
|
||||||
|
|
||||||
-- Chat command to completely destroy a player account, including auth.
|
-- Chat command to completely destroy a player account, including auth.
|
||||||
@ -52,6 +52,35 @@ do
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Chat command to analyze entities
|
||||||
|
minetest.register_chatcommand("luaentities", {
|
||||||
|
description = "Summary of luaentities by type",
|
||||||
|
privs = {["debug"] = true},
|
||||||
|
func = function()
|
||||||
|
local sum = {}
|
||||||
|
local keys = {}
|
||||||
|
for _, ent in pairs(minetest.luaentities) do
|
||||||
|
local n = ent.name or "?"
|
||||||
|
if not sum[n] then
|
||||||
|
sum[n] = 1
|
||||||
|
keys[#keys + 1] = n
|
||||||
|
else
|
||||||
|
sum[n] = sum[n] + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table_sort(keys, function(a, b)
|
||||||
|
local sa = sum[a]
|
||||||
|
local sb = sum[b]
|
||||||
|
return sa == sb and a < b or sa > sb
|
||||||
|
end)
|
||||||
|
for i = 1, #keys do
|
||||||
|
local k = keys[i]
|
||||||
|
keys[i] = string_format("%q=%d", k, sum[k])
|
||||||
|
end
|
||||||
|
return true, table_concat(keys, ", ")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-- Moderators and admins can always bypass player limits,
|
-- Moderators and admins can always bypass player limits,
|
||||||
-- important for emergency access.
|
-- important for emergency access.
|
||||||
minetest.register_can_bypass_userlimit(function(name)
|
minetest.register_can_bypass_userlimit(function(name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user