Version MFF.

This commit is contained in:
sys4-fr 2018-09-08 23:57:28 +02:00
parent 8e576d69c8
commit a70a6b7b77
3 changed files with 34 additions and 16 deletions

0
README.md Normal file → Executable file
View File

0
depends.txt Normal file → Executable file
View File

34
init.lua Normal file → Executable file
View File

@ -19,13 +19,7 @@ local waiting_list = {}
} }
]] ]]
minetest.register_globalstep(function(dtime) local function tick()
count = count + dtime
if count < 3 then
return
end
count = 0
for k, v in pairs(waiting_list) do for k, v in pairs(waiting_list) do
if v.player and v.player:is_player() then if v.player and v.player:is_player() then
local pos = get_surface_pos(v.pos) local pos = get_surface_pos(v.pos)
@ -53,6 +47,21 @@ minetest.register_globalstep(function(dtime)
local name = player:get_player_name() local name = player:get_player_name()
if not waiting_list[name] then if not waiting_list[name] then
local pos = vector.round(player:getpos()) 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 local newpos = nil
if pos.x >= edge then if pos.x >= edge then
newpos = {x = -newedge, y = 10, z = pos.z} newpos = {x = -newedge, y = 10, z = pos.z}
@ -62,8 +71,14 @@ minetest.register_globalstep(function(dtime)
if pos.z >= edge then if pos.z >= edge then
newpos = {x = pos.x, y = 10, z = -newedge} 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 elseif pos.z <= -edge then
newpos = {x = pos.x, y = 10, z = newedge} 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 end
-- Teleport the player -- Teleport the player
@ -80,7 +95,10 @@ minetest.register_globalstep(function(dtime)
end end
end end
end end
end) end
minetest.after(3, tick)
end
tick()
function get_surface_pos(pos) function get_surface_pos(pos)
local minp = { local minp = {