From: est31 Date: Tue, 15 Sep 2015 16:37:58 +0000 (+0200) Subject: Disallow placing entities outside safe boundaries X-Git-Tag: 0.4.14~690 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=f61f817b9c170942a5b3ce3591125c2191645cd0;p=oweals%2Fminetest.git 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. --- diff --git a/src/environment.cpp b/src/environment.cpp index eb599668b..0b3c0347d 100644 --- a/src/environment.cpp +++ b/src/environment.cpp @@ -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="<getId()<<")"< 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,