Avoid teleporting player if /teleport coords are out-of-range
authortenplus1 <tenplus1@users.noreply.github.com>
Thu, 28 Apr 2016 13:59:54 +0000 (23:59 +1000)
committerCraig Robbins <kde.psych@gmail.com>
Thu, 28 Apr 2016 14:00:35 +0000 (00:00 +1000)
builtin/game/chatcommands.lua

index 7480446f2552625547ae3d81734631dd0bfd9360..3350140eea918d608d5cccef7f997ba23b6e8c58 100644 (file)
@@ -352,10 +352,16 @@ core.register_chatcommand("teleport", {
                p.x = tonumber(p.x)
                p.y = tonumber(p.y)
                p.z = tonumber(p.z)
-               teleportee = core.get_player_by_name(name)
-               if teleportee and p.x and p.y and p.z then
-                       teleportee:setpos(p)
-                       return true, "Teleporting to "..core.pos_to_string(p)
+               if p.x and p.y and p.z then
+                       local lm = tonumber(minetest.setting_get("map_generation_limit") or 31000)
+                       if p.x < -lm or p.x > lm or p.y < -lm or p.y > lm or p.z < -lm or p.z > lm then
+                               return false, "Cannot teleport out of map bounds!"
+                       end
+                       teleportee = core.get_player_by_name(name)
+                       if teleportee then
+                               teleportee:setpos(p)
+                               return true, "Teleporting to "..core.pos_to_string(p)
+                       end
                end
 
                local teleportee = nil