Make find_areas an admin-only command

Some regexes can be very slow.
This also fixes a bug with single-item result sets.
This commit is contained in:
ShadowNinja 2014-10-04 15:42:29 -04:00
parent 9871caf1e2
commit b3873fcfaf
1 changed files with 5 additions and 4 deletions

View File

@ -143,6 +143,7 @@ minetest.register_chatcommand("rename_area", {
minetest.register_chatcommand("find_areas", { minetest.register_chatcommand("find_areas", {
params = "<regexp>", params = "<regexp>",
description = "Find areas using a Lua regular expression", description = "Find areas using a Lua regular expression",
privs = areas.adminPrivs,
func = function(name, param) func = function(name, param)
if param == "" then if param == "" then
return false, "A regular expression is required." return false, "A regular expression is required."
@ -158,12 +159,12 @@ minetest.register_chatcommand("find_areas", {
local matches = {} local matches = {}
for id, area in pairs(areas.areas) do for id, area in pairs(areas.areas) do
if areas:isAreaOwner(id, name) and local str = areas:toString(id)
areas:toString(id):find(param) then if str:find(param) then
table.insert(matches, areas:toString(id)) table.insert(matches, str)
end end
end end
if #matches > 1 then if #matches > 0 then
return true, table.concat(matches, "\n") return true, table.concat(matches, "\n")
else else
return true, "No matches found." return true, "No matches found."