BeamMP / BeamMP-Server

Server for the multiplayer mod BeamMP for BeamNG.drive
https://beammp.com
GNU Affero General Public License v3.0
127 stars 53 forks source link

MP.GetPlayerCount() don't update until some time after onPlayerDisconnect #271

Open emlodnaor opened 8 months ago

emlodnaor commented 8 months ago

Fill out general information OS (windows, linux, ...): Windows BeamMP-Server Version: 3.2.2

MP.GetPlayerCount() don't update until some time after onPlayerDisconnect. Trying to use the event onPlayerDisconnect to update the number of players on the server, but MP.GetPlayerCount() is not updated to reflect that 1 player has left.

To Reproduce The code I pasted here: https://discord.com/channels/601558901657305098/749321846763290676/1201957744895332442 It an example of code that that reproduce this bug.

Expected behavior I expected the PlayerCount to be updated before the onPlayerDisconnect is triggered.

Logs Including log from the output of the code pasted in the link above: Goodpai has JOINED, there are 1 players connected! Sk0g1 has JOINED, there are 2 players connected! emlodnaor has JOINED, there are 3 players connected! Sk0g1 has DISCONNECTED, there are 3 players connected! Goodpai has DISCONNECTED, there are 2 players connected! emlodnaor has DISCONNECTED, there are 1 players connected!

Additional context Initial question about this on discord: https://discord.com/channels/601558901657305098/749321846763290676/1202325980853571684

lionkor commented 8 months ago

It's actually not clear to me what the behavior should be.

onPlayerDisconnect should fire when the player is disconnecting - it's not onPlayerDisconnected, as you said on discord. Not sure what the better behavior is.

On one hand, it feels like it would be useful to have the player count there be accurate to what it's going to be immediately after the event is done, but it's not clear from the name alone what should happen.

I'll ask around a bit more.

emlodnaor commented 8 months ago

I agree with this, adding a onPlayerDisconnected, and/or MP.GetActivePlayerCount() could very well be a more correct answer!

lionkor commented 8 months ago

As of #256, we'll have specific states each client is in, so maybe we can make use of that.