mirror of
https://github.com/luanti-org/luanti.git
synced 2025-09-15 18:57:08 +00:00
Fix connected_players on_shutdown (#14739)
This commit is contained in:
parent
bc23a610d3
commit
7a64527db5
4 changed files with 46 additions and 25 deletions
|
@ -186,6 +186,7 @@ dofile(modpath .. "/metadata.lua")
|
|||
dofile(modpath .. "/raycast.lua")
|
||||
dofile(modpath .. "/inventory.lua")
|
||||
dofile(modpath .. "/load_time.lua")
|
||||
dofile(modpath .. "/on_shutdown.lua")
|
||||
|
||||
--------------
|
||||
|
||||
|
|
22
games/devtest/mods/unittests/on_shutdown.lua
Normal file
22
games/devtest/mods/unittests/on_shutdown.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
-- Test whether players still exist on shutdown
|
||||
local players = {}
|
||||
|
||||
core.register_on_joinplayer(function(player)
|
||||
players[player:get_player_name()] = true
|
||||
end)
|
||||
|
||||
core.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name();
|
||||
assert(players[name], "Unrecorded player join.")
|
||||
players[name] = nil
|
||||
end)
|
||||
|
||||
core.register_on_shutdown(function()
|
||||
for _, player in pairs(core.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
assert(players[name], "Unrecorded player join or left too early.")
|
||||
players[name] = nil
|
||||
end
|
||||
|
||||
assert(not next(players), "Invalid connected players on shutdown.")
|
||||
end)
|
Loading…
Add table
Add a link
Reference in a new issue