From 95adf18f235145196076298036920be54cb23dc4 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Sat, 31 Jul 2021 01:17:07 -0700 Subject: [PATCH] Check chat command radius parameter & limit max to 100 --- chat.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/chat.lua b/chat.lua index 29fba41..fe45ac0 100644 --- a/chat.lua +++ b/chat.lua @@ -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 = {}