Check chat command radius parameter & limit max to 100

This commit is contained in:
Jordan Irwin 2021-07-31 01:17:07 -07:00
parent 09d6475ce0
commit 95adf18f23

View file

@ -188,6 +188,23 @@ local function format_help(cmd)
end
local function check_radius(radius, pname)
local is_admin = core.check_player_privs(pname, {server=true})
if not is_admin and radius > 10 then
radius = 10
return radius, S("You do not have permission to set radius that high. Reduced to @1.", radius)
end
if radius > 100 then
radius = 100
return radius, S("Radius is too high. Reduced to @1.", radius)
end
return radius
end
--- Removes nearby entities.
--
-- @chatcmd remove_entities
@ -216,6 +233,11 @@ core.register_chatcommand(cmd_repo.entity.cmd, {
err = cmd_repo.param.mal_radius
end
local radius, msg = check_radius(radius, name)
if msg then
core.chat_send_player(name, msg)
end
if err then
return false, err .. "\n\n" .. format_help(cmd_repo.entity.cmd)
end
@ -271,6 +293,11 @@ core.register_chatcommand(cmd_repo.rem_node.cmd, {
err = cmd_repo.param.mal_radius
end
local radius, msg = check_radius(radius, name)
if msg then
core.chat_send_player(name, msg)
end
if err then
return false, err .. "\n\n" .. format_help(cmd_repo.rem_node.cmd)
end
@ -349,6 +376,11 @@ core.register_chatcommand(cmd_repo.rep_node.cmd, {
return false, cmd_repo.param.mal_radius .. "\n\n" .. help
end
local radius, msg = check_radius(radius, name)
if msg then
core.chat_send_player(name, msg)
end
if not core.registered_nodes[tgt] then
return false, S('Cannot use unknown node "@1" as replacement.', tgt)
end
@ -395,6 +427,11 @@ core.register_chatcommand(cmd_repo.find_node.cmd, {
return false, cmd_repo.param.mal_radius .. "\n\n" .. help
end
local radius, msg = check_radius(radius, name)
if msg then
core.chat_send_player(name, msg)
end
local ppos = core.get_player_by_name(name):get_pos()
local checked_nodes = {}