Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
basic_robot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Illuna-Minetest
basic_robot
Commits
0c3f06a4
Commit
0c3f06a4
authored
8 years ago
by
rnd1
Browse files
Options
Downloads
Patches
Plain Diff
mitigate the effects of malicious sandbox code - infinite recursion
parent
8be654c2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
commands.lua
+6
-7
6 additions, 7 deletions
commands.lua
init.lua
+33
-8
33 additions, 8 deletions
init.lua
with
39 additions
and
15 deletions
commands.lua
+
6
−
7
View file @
0c3f06a4
...
...
@@ -36,18 +36,16 @@ basic_robot.commands.move = function(name,dir)
minetest
.
get_node
({
x
=
pos
.
x
,
y
=
pos
.
y
-
2
,
z
=
pos
.
z
}).
name
==
"air"
then
return
end
obj
:
moveto
(
pos
,
true
)
end
basic_robot
.
commands
.
turn
=
function
(
name
,
angle
)
local
obj
=
basic_robot
.
data
[
name
].
obj
;
local
yaw
=
obj
:
getyaw
()
+
angle
;
obj
:
setyaw
(
yaw
);
end
basic_robot
.
commands
.
dig
=
function
(
name
,
dir
)
local
obj
=
basic_robot
.
data
[
name
].
obj
;
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
""
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
)
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
local
spos
=
obj
:
get_luaentity
().
spawnpos
;
local
meta
=
minetest
.
get_meta
(
spos
);
local
inv
=
meta
:
get_inventory
();
if
not
inv
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
));
minetest
.
set_node
(
pos
,{
name
=
nodename
})
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
init.lua
+
33
−
8
View file @
0c3f06a4
...
...
@@ -20,12 +20,12 @@ function getSandboxEnv (name)
pcall
=
pcall
,
ram
=
basic_robot
.
data
[
name
].
ram
,
-- "ram" - used to store variables
move
=
{
-- changes position of robot
left
=
function
()
commands
.
move
(
name
,
1
)
end
,
right
=
function
()
commands
.
move
(
name
,
2
)
end
,
forward
=
function
()
commands
.
move
(
name
,
3
)
end
,
backward
=
function
()
commands
.
move
(
name
,
4
)
end
,
up
=
function
()
commands
.
move
(
name
,
5
)
end
,
down
=
function
()
commands
.
move
(
name
,
6
)
end
,
left
=
function
()
return
commands
.
move
(
name
,
1
)
end
,
right
=
function
()
return
commands
.
move
(
name
,
2
)
end
,
forward
=
function
()
return
commands
.
move
(
name
,
3
)
end
,
backward
=
function
()
return
commands
.
move
(
name
,
4
)
end
,
up
=
function
()
return
commands
.
move
(
name
,
5
)
end
,
down
=
function
()
return
commands
.
move
(
name
,
6
)
end
,
},
turn
=
{
...
...
@@ -79,6 +79,15 @@ function getSandboxEnv (name)
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
)
minetest
.
chat_send_all
(
"<robot "
..
name
..
"> "
..
text
)
end
,
...
...
@@ -227,13 +236,16 @@ minetest.register_entity("basic_robot:robot",{
timer
=
0
,
timestep
=
1
,
-- run every 1 second
spawnpos
=
""
,
--visual="mesh",
--mesh = "character.b3d",
--textures={"character.png"},
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
},
running
=
0
,
-- does it run code or is it idle?
collisionbox
=
{
-
0
.
5
,
-
0
.
5
,
-
0
.
5
,
0
.
5
,
0
.
5
,
0
.
5
},
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
)
...
...
@@ -302,6 +314,18 @@ minetest.register_entity("basic_robot:robot",{
if
err
then
minetest
.
chat_send_player
(
self
.
owner
,
"#ROBOT ERROR : "
..
err
)
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
();
end
...
...
@@ -425,6 +449,7 @@ minetest.register_node("basic_robot:spawner", {
"move.direction(), where direction is forward, backward, left,right, up, down\n"
..
"turn.left(), turn.right(), turn.angle(45)\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"
..
"selfpos() returns table {x=pos.x,y=pos.y,z=pos.z}\n"
..
"say(\"
hello
\
") will speak"
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment