Skip to content

Commit 3e93b93

Browse files
authored
Validate user inputs (#39)
1 parent 79b72e8 commit 3e93b93

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

moremesecons_adjustable_player_detector/init.lua

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
-- Detects players in a certain radius
33
-- The radius can be changes by right-click (by default 6)
44

5+
local MAX_RADIUS = moremesecons.setting("adjustable_player_detector", "max_radius", 16, 0)
6+
57
local function make_formspec(meta)
68
meta:set_string("formspec", "size[9,5]" ..
79
"field[0.3, 0;9,2;scanname;Comma-separated list of the names of players to scan for (empty for any):;${scanname}]"..
@@ -36,7 +38,7 @@ local object_detector_scan = function (pos)
3638
local scanname = meta:get_string("scanname")
3739
local scan_all = scanname == ""
3840
local scan_names = scanname:split(',')
39-
local radius = meta:get_int("radius")
41+
local radius = math.min(meta:get_int("radius"), MAX_RADIUS)
4042
if radius <= 0 then
4143
radius = 6
4244
end
@@ -76,11 +78,11 @@ local object_detector_digiline = {
7678
make_formspec(meta)
7779
end
7880
end
79-
if msg.scanname then
81+
if type(msg.scanname) == "string" then
8082
meta:set_string("scanname", msg.scanname)
8183
make_formspec(meta)
8284
end
83-
if msg.command and msg.command == "get" then
85+
if msg.command == "get" then
8486
local found, name = object_detector_scan(pos)
8587
if not found then
8688
name = ""

moremesecons_entity_detector/init.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
-- Detects entitys in a certain radius
33
-- The radius can be changes by right-click (by default 6)
44

5+
local MAX_RADIUS = moremesecons.setting("entity_detector", "max_radius", 16, 0)
6+
57
local function make_formspec(meta)
68
meta:set_string("formspec", "size[9,5]" ..
79
"field[0.3, 0;9,2;scanname;Comma-separated list of the names (itemstring) of entities to scan for (empty for any):;${scanname}]"..
@@ -26,8 +28,7 @@ local function object_detector_on_receive_fields(pos, _, fields, player)
2628
meta:set_string("digiline_channel", fields.digiline_channel)
2729
local r = tonumber(fields.radius)
2830
if r then
29-
local max_radius = moremesecons.setting("entity_detector", "max_radius", 16, 0)
30-
meta:set_int("radius", math.min(r, max_radius))
31+
meta:set_int("radius", math.min(r, MAX_RADIUS))
3132
end
3233
end
3334

@@ -37,8 +38,7 @@ local object_detector_scan = function (pos)
3738
local scanname = meta:get_string("scanname")
3839
local scan_all = scanname == ""
3940
local scan_names = scanname:split(',')
40-
local max_radius = moremesecons.setting("entity_detector", "max_radius", 16, 0)
41-
local radius = math.min(tonumber(meta:get("radius")) or 6, max_radius)
41+
local radius = math.min(tonumber(meta:get("radius")) or 6, MAX_RADIUS)
4242
for _,obj in pairs(minetest.get_objects_inside_radius(pos, radius)) do
4343
local luaentity = obj:get_luaentity()
4444
if luaentity then
@@ -62,7 +62,7 @@ local object_detector_digiline = {
6262
action = function (pos, node, channel, msg)
6363
local meta = minetest.get_meta(pos)
6464
local active_channel = meta:get_string("digiline_channel")
65-
if channel ~= active_channel then
65+
if channel ~= active_channel or type(msg) ~= "string" then
6666
return
6767
end
6868
meta:set_string("scanname", msg)

settingtypes.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Minimal interval authorized. Any lower will be set to it.
44
moremesecons_adjustable_blinky_plant.min_interval (Minimum Interval) float 0.5
55

6+
[Adjustable Player Detector]
7+
8+
moremesecons_adjustable_player_detector.max_radius (Maximum adjustable player detector radius) float 16 0
9+
610
[Craftable Commandblock]
711

812
# Space-separated list of authorized commands

0 commit comments

Comments
 (0)