forked from minetest/minetest_game
Fix bed night skip race condition (#3067)
This commit is contained in:
parent
eba9012d05
commit
34942339c7
@ -181,6 +181,26 @@ function beds.skip_night()
|
|||||||
minetest.set_timeofday(0.23)
|
minetest.set_timeofday(0.23)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local update_scheduled = false
|
||||||
|
local function schedule_update()
|
||||||
|
if update_scheduled then
|
||||||
|
-- there already is an update scheduled; don't schedule more to prevent races
|
||||||
|
return
|
||||||
|
end
|
||||||
|
update_scheduled = true
|
||||||
|
minetest.after(2, function()
|
||||||
|
update_scheduled = false
|
||||||
|
if not is_sp then
|
||||||
|
update_formspecs(is_night_skip_enabled())
|
||||||
|
end
|
||||||
|
if is_night_skip_enabled() then
|
||||||
|
-- skip the night and let all players stand up
|
||||||
|
beds.skip_night()
|
||||||
|
beds.kick_players()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
function beds.on_rightclick(pos, player)
|
function beds.on_rightclick(pos, player)
|
||||||
local name = player:get_player_name()
|
local name = player:get_player_name()
|
||||||
local ppos = player:get_pos()
|
local ppos = player:get_pos()
|
||||||
@ -206,17 +226,8 @@ function beds.on_rightclick(pos, player)
|
|||||||
update_formspecs(false)
|
update_formspecs(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- skip the night and let all players stand up
|
|
||||||
if check_in_beds() then
|
if check_in_beds() then
|
||||||
minetest.after(2, function()
|
schedule_update()
|
||||||
if not is_sp then
|
|
||||||
update_formspecs(is_night_skip_enabled())
|
|
||||||
end
|
|
||||||
if is_night_skip_enabled() then
|
|
||||||
beds.skip_night()
|
|
||||||
beds.kick_players()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -249,13 +260,7 @@ minetest.register_on_leaveplayer(function(player)
|
|||||||
lay_down(player, nil, nil, false, true)
|
lay_down(player, nil, nil, false, true)
|
||||||
beds.player[name] = nil
|
beds.player[name] = nil
|
||||||
if check_in_beds() then
|
if check_in_beds() then
|
||||||
minetest.after(2, function()
|
schedule_update()
|
||||||
update_formspecs(is_night_skip_enabled())
|
|
||||||
if is_night_skip_enabled() then
|
|
||||||
beds.skip_night()
|
|
||||||
beds.kick_players()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user