Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_connected_players wrongly returns empty list in register_on_shutdown #14736

Closed
appgurueu opened this issue Jun 7, 2024 · 5 comments · Fixed by #14739
Closed

get_connected_players wrongly returns empty list in register_on_shutdown #14736

appgurueu opened this issue Jun 7, 2024 · 5 comments · Fixed by #14739
Labels
Blocker The issue needs to be addressed before the next release. Bug Issues that were confirmed to be a bug Regression Something that used to work no longer does
Milestone

Comments

@appgurueu
Copy link
Contributor

appgurueu commented Jun 7, 2024

Minetest version

Reported by BluebirdGrey51 on IRC on version 5.9.0-dev-87232358d. I can also reproduce this.

Summary

get_connected_players wrongly returns an empty list in register_on_shutdown - 5.8.0 returned a list containing the connected players, as it should. There isn't even a good way for modders to work around this since register_on_leaveplayer doesn't get run on shutdown. Hence, if modders want to do something with players on shutdown (in BluebirdGrey51's example, setting some metadata values), they need this to work.

Steps to reproduce

minetest.register_on_shutdown(function()
	print("# connected players", #minetest.get_connected_players())
end)

On 5.8.0: Start singleplayer game. Exit to OS. Output on terminal: # connected players 1.

Now do the same on 5.9-dev. Output: # connected players 0.

@appgurueu appgurueu added Bug Issues that were confirmed to be a bug Blocker The issue needs to be addressed before the next release. Regression Something that used to work no longer does labels Jun 7, 2024
@appgurueu
Copy link
Contributor Author

Possible culprits (not tested yet): e7dbd32 and 32f68f3. @SmallJoker

@wsor4035 wsor4035 added this to the 5.9.0 milestone Jun 8, 2024
@wsor4035
Copy link
Contributor

wsor4035 commented Jun 8, 2024

related #14711

@sfan5
Copy link
Member

sfan5 commented Jun 8, 2024

Needless to say we should add some test code to devtest for these cases.

@SmallJoker
Copy link
Member

SmallJoker commented Jun 8, 2024

Since ef0009a, the disconnected players are now unloaded properly explicitly before ServerEnvironment destruction. Hence these objects no longer appeared in get_connected_players because they are (and already in were in 5.8.0) - in fact - already disconnected at this point.

EDIT:

get_connected_players wrongly returns an empty list in register_on_shutdown - 5.8.0 returned a list containing the connected players, as it should.

This behaviour is not documented. Intuitively it would however indeed make sense to me to still have the player list available there - even if they're already gone.

@appgurueu
Copy link
Contributor Author

This behaviour is not documented.

Indeed we should document it.

Intuitively it would however indeed make sense to me to still have the player list available there - even if they're already gone.

It's not just intuition. It's pretty much a necessity if you want to do any player-related things on shutdown, such as persisting data to player meta, since register_on_leaveplayer doesn't run on shutdown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Blocker The issue needs to be addressed before the next release. Bug Issues that were confirmed to be a bug Regression Something that used to work no longer does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants