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

Handle GameState changes when Players leaves a match #1088

Open
Neodark7 opened this issue Aug 9, 2022 · 2 comments
Open

Handle GameState changes when Players leaves a match #1088

Neodark7 opened this issue Aug 9, 2022 · 2 comments
Labels

Comments

@Neodark7
Copy link

Neodark7 commented Aug 9, 2022

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 ?

@Neodark7 Neodark7 changed the title Hook when a player leaves a match Handle GameState changes when Players leaves a match Aug 9, 2022
@liorsbg
Copy link

liorsbg commented Sep 20, 2022

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

@Neodark7
Copy link
Author

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 🤦‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants