diff --git a/README.md b/README.md old mode 100644 new mode 100755 diff --git a/depends.txt b/depends.txt old mode 100644 new mode 100755 diff --git a/init.lua b/init.lua old mode 100644 new mode 100755 index bbf914a..36f22b2 --- a/init.lua +++ b/init.lua @@ -19,13 +19,7 @@ local waiting_list = {} } ]] -minetest.register_globalstep(function(dtime) - count = count + dtime - if count < 3 then - return - end - count = 0 - +local function tick() for k, v in pairs(waiting_list) do if v.player and v.player:is_player() then local pos = get_surface_pos(v.pos) @@ -53,19 +47,40 @@ minetest.register_globalstep(function(dtime) local name = player:get_player_name() if not waiting_list[name] then local pos = vector.round(player:getpos()) + + -- Sanity check for insane coordinates + if pos.x > 31000 or pos.y > 31000 or pos.z > 31000 + or pos.x < -31000 or pos.y < -31000 or pos.z < -31000 then + -- Move to spawn asap + -- The server probably set invalid/insane coordinates. We have not saved the previous ones, + -- So we need to teleport the player to the spawn to save them from an endless loop of + -- Teleportation. + local spawn = minetest.string_to_pos(minetest.setting_get("static_spawnpoint") or "0,0,0") + minetest.chat_send_player(player:get_player_name(), "An internal error has occured. Your coordinates were corrupted. You are now teleported to the spawn." .. + " Please report it to any staff member.") + minetest.log("error", "[WorldEdge] Corrupted position detected for player " .. player:get_player_name()) + player:setpos(spawn) + else -- Indent skipped, too many lines to change... We'll wait for "continue" to be introduced in Lua5.2 + local newpos = nil if pos.x >= edge then newpos = {x = -newedge, y = 10, z = pos.z} elseif pos.x <= -edge then newpos = {x = newedge, y = 10, z = pos.z} end - + if pos.z >= edge then newpos = {x = pos.x, y = 10, z = -newedge} + if get_surface_pos(newpos) then + newpos.y = get_surface_pos(newpos).y+1 -- /MFF (Mg|19/05//15) + end -- /MFF (Mg|14/07/15) elseif pos.z <= -edge then newpos = {x = pos.x, y = 10, z = newedge} + if get_surface_pos(newpos) then + newpos.y = get_surface_pos(newpos).y+1 -- /MFF (Mg|19/05/15) + end -- /MFF (Mg|14/07/15) end - + -- Teleport the player if newpos then minetest.chat_send_player(name, "Please wait a few seconds. We will teleport you soon.") @@ -78,9 +93,12 @@ minetest.register_globalstep(function(dtime) } obj:setpos(newpos) end + end end end -end) + minetest.after(3, tick) +end +tick() function get_surface_pos(pos) local minp = { @@ -93,19 +111,19 @@ function get_surface_pos(pos) y = 50, z = pos.z + radius - 1 } - + local c_air = minetest.get_content_id("air") local c_ignore = minetest.get_content_id("ignore") - + local vm = minetest.get_voxel_manip() local emin, emax = vm:read_from_map(minp, maxp) local area = VoxelArea:new{MinEdge = emin, MaxEdge = emax} local data = vm:get_data() - + local seen_air = false local deepest_place = vector.new(pos) deepest_place.y = 50 - + for x = minp.x, maxp.x do for z = minp.z, maxp.z do local solid = 0 @@ -125,7 +143,7 @@ function get_surface_pos(pos) end end end - + if seen_air then return deepest_place else @@ -140,4 +158,4 @@ minetest.register_entity("worldedge:lock", { on_activate = function(staticdata, dtime_s) --self.object:set_armor_groups({immortal = 1}) end -}) \ No newline at end of file +})