boardgameio / boardgame.io

State Management and Multiplayer Networking for Turn-Based Games
https://boardgame.io
MIT License
10.02k stars 708 forks source link

Handle GameState changes when Players leaves a match #1088

Open Neodark7 opened 2 years ago

Neodark7 commented 2 years ago

Hi ! i can't find any way to execute some logic when a players leaves a match.

I'd like to handle cases where a player leave a match (by closing it's browser for example). Right now i'm using Pusher which send webhooks to my api when a user quits the application, which handle calling the lobby leave endpoint (https://boardgame.io/documentation/#/api/Lobby?id=leaving-a-match) using the appropriate player ID and player credentials.

I have a custom players state in G to handle players score, position on the board, etc...

After a player leaves the match, i'd like to remove his state and remove him from the turn order to prevent other players being blocked.

But when a player has left the match (when his "isConnected" attribute is set to false) i can't find a way to execute some logic to do that.

Should i use a server middleware on the leave route to update the game state ? and how ? Or Is there a better solution to achieve that ?

Can someone guide me into doing this ?

liorsbg commented 2 years ago

Hey @Neodark7, I have the same issue. Did you find any good solutions?

Neodark7 commented 2 years ago

Not really, for now we made a fork of the library, and we added some logic to the master onConnectionChange method to call a new flow method we created that handle game state changes when some player join or leave a match but it doesn't works really well..

I really don't understand how it's possible that such thing is not already implemented. Like nobody ever tought of handling this ? 🤷‍♂️ i still feel that i'm missing something here but it looks like there is no way to handle player leaving a match 🤦‍♂️