Disallow placing entities outside safe boundaries
authorest31 <MTest31@outlook.com>
Tue, 15 Sep 2015 16:37:58 +0000 (18:37 +0200)
committerest31 <MTest31@outlook.com>
Tue, 15 Sep 2015 17:45:17 +0000 (19:45 +0200)
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.

src/environment.cpp
src/mapblock.h

index eb599668b82333b644d616c89457c729887bd464..0b3c0347d56ed5d89be54efd8d4c0f8a41a1b7f5 100644 (file)
@@ -1493,6 +1493,15 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
                        delete object;
                return 0;
        }
+
+       if (objectpos_over_limit(object->getBasePosition())) {
+               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;*/
 
index 197d58ec746961bd0b013247bb353d898e7ee763..b2d5f98faa633742b20d39727605cca95da62cdd 100644 (file)
@@ -637,6 +637,18 @@ private:
 
 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,