Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Disallow placing entities outside safe boundaries
Entity positions are serialized as F1000. Disallow placing
entities outside safe borders with the minetest.add_entity
call.

Note that this patch only enforces those boundaries for
placing entities, moving entities that move outside boundaries
aren't affected.

Thanks to @nanepiwo for pointing this out.
  • Loading branch information
est31 committed Sep 15, 2015
1 parent 8e9c9e3 commit f61f817
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/environment.cpp
Expand Up @@ -1493,6 +1493,15 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
delete object;
return 0;
}

if (objectpos_over_limit(object->getBasePosition())) {

This comment has been minimized.

Copy link
@nerzhul

nerzhul Sep 15, 2015

Member

Warning: getBasePosition is equivalent to v3s16 * BS. Here you will remove all objets far from limits.
Divide getBasePosition / BS to have the correct limits for map nodes.

This comment has been minimized.

Copy link
@est31

est31 Sep 15, 2015

Author Contributor

Do you want to push a fix? Do we store position in BS format at other places as well? Perhaps then it would be better to fix it in the definition of objectpos_over_limit (with an explaining comment), as then we wouldn't have to do the multiplication/division at multiple places once we use that function more often.

errorstream << "ServerEnvironment::addActiveObjectRaw(): "
<< "object position outside maximum range" << std::endl;
if (object->environmentDeletes())
delete object;
return 0;
}

/*infostream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"added (id="<<object->getId()<<")"<<std::endl;*/

Expand Down
12 changes: 12 additions & 0 deletions src/mapblock.h
Expand Up @@ -637,6 +637,18 @@ class MapBlock /*: public NodeContainer*/

typedef std::vector<MapBlock*> MapBlockVect;

inline bool objectpos_over_limit(v3f p)
{
const static u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
g_settings->getU16("map_generation_limit"));
return (p.X < -map_gen_limit
|| p.X > map_gen_limit
|| p.Y < -map_gen_limit
|| p.Y > map_gen_limit
|| p.Z < -map_gen_limit
|| p.Z > map_gen_limit);
}

inline bool blockpos_over_limit(v3s16 p)
{
const static u16 map_gen_limit = MYMIN(MAX_MAP_GENERATION_LIMIT,
Expand Down

0 comments on commit f61f817

Please sign in to comment.