mitigate the effects of malicious sandbox code - infinite recursion
This commit is contained in:
parent
8be654c25b
commit
0c3f06a428
11
commands.lua
11
commands.lua
@ -40,14 +40,12 @@ basic_robot.commands.move = function(name,dir)
|
|||||||
obj:moveto(pos, true)
|
obj:moveto(pos, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
basic_robot.commands.turn = function (name, angle)
|
basic_robot.commands.turn = function (name, angle)
|
||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
local yaw = obj:getyaw()+angle;
|
local yaw = obj:getyaw()+angle;
|
||||||
obj:setyaw(yaw);
|
obj:setyaw(yaw);
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
basic_robot.commands.dig = function(name,dir)
|
basic_robot.commands.dig = function(name,dir)
|
||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
local pos = pos_in_dir(obj, dir)
|
local pos = pos_in_dir(obj, dir)
|
||||||
@ -71,6 +69,11 @@ basic_robot.commands.read_node = function(name,dir)
|
|||||||
return minetest.get_node(pos).name or ""
|
return minetest.get_node(pos).name or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
basic_robot.commands.read_text = function(name,dir)
|
||||||
|
local obj = basic_robot.data[name].obj;
|
||||||
|
local pos = pos_in_dir(obj, dir)
|
||||||
|
return minetest.get_meta(pos):get_string("infotext") or ""
|
||||||
|
end
|
||||||
|
|
||||||
basic_robot.commands.place = function(name,nodename, dir)
|
basic_robot.commands.place = function(name,nodename, dir)
|
||||||
local obj = basic_robot.data[name].obj;
|
local obj = basic_robot.data[name].obj;
|
||||||
@ -80,15 +83,11 @@ basic_robot.commands.place = function(name,nodename, dir)
|
|||||||
if minetest.get_node(pos).name~="air" then return end
|
if minetest.get_node(pos).name~="air" then return end
|
||||||
|
|
||||||
local spos = obj:get_luaentity().spawnpos;
|
local spos = obj:get_luaentity().spawnpos;
|
||||||
|
|
||||||
local meta = minetest.get_meta(spos);
|
local meta = minetest.get_meta(spos);
|
||||||
|
|
||||||
|
|
||||||
local inv = meta:get_inventory();
|
local inv = meta:get_inventory();
|
||||||
if not inv then return end
|
if not inv then return end
|
||||||
if not inv:contains_item("main", ItemStack(nodename)) and meta:get_int("admin")~=1 then return end
|
if not inv:contains_item("main", ItemStack(nodename)) and meta:get_int("admin")~=1 then return end
|
||||||
inv:remove_item("main", ItemStack(nodename));
|
inv:remove_item("main", ItemStack(nodename));
|
||||||
|
|
||||||
|
|
||||||
minetest.set_node(pos,{name = nodename})
|
minetest.set_node(pos,{name = nodename})
|
||||||
end
|
end
|
41
init.lua
41
init.lua
@ -20,12 +20,12 @@ function getSandboxEnv (name)
|
|||||||
pcall=pcall,
|
pcall=pcall,
|
||||||
ram = basic_robot.data[name].ram, -- "ram" - used to store variables
|
ram = basic_robot.data[name].ram, -- "ram" - used to store variables
|
||||||
move = { -- changes position of robot
|
move = { -- changes position of robot
|
||||||
left = function() commands.move(name,1) end,
|
left = function() return commands.move(name,1) end,
|
||||||
right = function() commands.move(name,2) end,
|
right = function() return commands.move(name,2) end,
|
||||||
forward = function() commands.move(name,3) end,
|
forward = function() return commands.move(name,3) end,
|
||||||
backward = function() commands.move(name,4) end,
|
backward = function() return commands.move(name,4) end,
|
||||||
up = function() commands.move(name,5) end,
|
up = function() return commands.move(name,5) end,
|
||||||
down = function() commands.move(name,6) end,
|
down = function() return commands.move(name,6) end,
|
||||||
},
|
},
|
||||||
|
|
||||||
turn = {
|
turn = {
|
||||||
@ -79,6 +79,15 @@ function getSandboxEnv (name)
|
|||||||
up = function() return commands.read_node(name,5) end,
|
up = function() return commands.read_node(name,5) end,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
read_text = { -- returns node name
|
||||||
|
left = function() return commands.read_text(name,1) end,
|
||||||
|
right = function() return commands.read_text(name,2) end,
|
||||||
|
forward = function() return commands.read_text(name,3) end,
|
||||||
|
backward = function() return commands.read_text(name,4) end,
|
||||||
|
down = function() return commands.read_text(name,6) end,
|
||||||
|
up = function() return commands.read_text(name,5) end,
|
||||||
|
},
|
||||||
|
|
||||||
say = function(text)
|
say = function(text)
|
||||||
minetest.chat_send_all("<robot ".. name .. "> " .. text)
|
minetest.chat_send_all("<robot ".. name .. "> " .. text)
|
||||||
end,
|
end,
|
||||||
@ -227,14 +236,17 @@ minetest.register_entity("basic_robot:robot",{
|
|||||||
timer = 0,
|
timer = 0,
|
||||||
timestep = 1, -- run every 1 second
|
timestep = 1, -- run every 1 second
|
||||||
spawnpos = "",
|
spawnpos = "",
|
||||||
|
--visual="mesh",
|
||||||
|
--mesh = "character.b3d",
|
||||||
|
--textures={"character.png"},
|
||||||
visual="cube",
|
visual="cube",
|
||||||
|
textures={"arrow.png","basic_machine_side.png","face.png","basic_machine_side.png","basic_machine_side.png","basic_machine_side.png"},
|
||||||
|
|
||||||
visual_size={x=1,y=1},
|
visual_size={x=1,y=1},
|
||||||
running = 0, -- does it run code or is it idle?
|
running = 0, -- does it run code or is it idle?
|
||||||
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
|
||||||
physical=true,
|
physical=true,
|
||||||
|
|
||||||
textures={"arrow.png","basic_machine_side.png","face.png","basic_machine_side.png","basic_machine_side.png","basic_machine_side.png"},
|
|
||||||
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
|
|
||||||
-- how to make it remember owner when it reactivates ?? staticdata seems to be empty
|
-- how to make it remember owner when it reactivates ?? staticdata seems to be empty
|
||||||
@ -302,6 +314,18 @@ minetest.register_entity("basic_robot:robot",{
|
|||||||
if err then
|
if err then
|
||||||
minetest.chat_send_player(self.owner,"#ROBOT ERROR : " .. err)
|
minetest.chat_send_player(self.owner,"#ROBOT ERROR : " .. err)
|
||||||
self.running = 0; -- stop execution
|
self.running = 0; -- stop execution
|
||||||
|
|
||||||
|
if string.find(err,"stack overflow") then -- remove stupid player privs and spawner, ban player ip
|
||||||
|
local owner = self.owner;
|
||||||
|
local pos = basic_robot.data[owner].spawnpos;
|
||||||
|
minetest.set_node(pos, {name = "air"});
|
||||||
|
|
||||||
|
local privs = core.get_player_privs(owner);privs.interact = false;
|
||||||
|
|
||||||
|
core.set_player_privs(owner, privs); minetest.auth_reload()
|
||||||
|
minetest.ban_player(owner)
|
||||||
|
|
||||||
|
end
|
||||||
self.object:remove();
|
self.object:remove();
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -425,6 +449,7 @@ minetest.register_node("basic_robot:spawner", {
|
|||||||
"move.direction(), where direction is forward, backward, left,right, up, down\n"..
|
"move.direction(), where direction is forward, backward, left,right, up, down\n"..
|
||||||
"turn.left(), turn.right(), turn.angle(45)\n"..
|
"turn.left(), turn.right(), turn.angle(45)\n"..
|
||||||
"dig.direction(), place.direction(\"default:dirt\")\nread_node.direction() tells you names of nodes\n"..
|
"dig.direction(), place.direction(\"default:dirt\")\nread_node.direction() tells you names of nodes\n"..
|
||||||
|
"read_text.direction() reads text of signs, chests and other blocks\n"..
|
||||||
"find_nodes(\"default:dirt\",3) is true if node can be found at radius 3 around robot, otherwise false\n"..
|
"find_nodes(\"default:dirt\",3) is true if node can be found at radius 3 around robot, otherwise false\n"..
|
||||||
"selfpos() returns table {x=pos.x,y=pos.y,z=pos.z}\n"..
|
"selfpos() returns table {x=pos.x,y=pos.y,z=pos.z}\n"..
|
||||||
"say(\"hello\") will speak";
|
"say(\"hello\") will speak";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user