mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-17 18:35:20 +02:00
Fix connected_players on_shutdown (#14739)
This commit is contained in:
@@ -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)
|
Reference in New Issue
Block a user