Detect if other player left unintentionally (e.g. internet disconnection) and reconnect - Google play real time multiplayer
Asked Answered
E

1

6

I am implementing google play game service real time multiplayer.

Currently if I turn off the WIFI on one client the other client doesn't detect that the connection is lost. No PeerDisconnect events are called.

1 - Does the API provide anything to check if the peer is still connected?

2 - Is there any way to let the player reconnect to the room?

Enrichetta answered 16/5, 2016 at 12:16 Comment(0)
R
2

1 - Does the API provide anything to check if the peer is still connected?

As stated in Connecting players, you can monitor the connection status of the participants with the use of RoomStatusUpdateListener callbacks. As stated:

To be notified when all players are connected, your game can use the RoomUpdateListener.onRoomConnected() callback. Your game can also use the RoomStatusUpdateListener callbacks to monitor the connection status of the participants. Based on the participant connection status, your game can decide whether to start or cancel the gaming session.

2 - Is there any way to let the player reconnect to the room?

Real-time Multiplayer - Gameplay states that:

Once the required number of participants for a room have been connected, the room is considered to be 'filled' and gameplay can begin. After participants join a room, your game can allow them to leave the room (effectively dropping them out of the game). However, no new players can join a room after it is 'filled' (not even to fill a spot that a participant has vacated).

In addition to that, referring to best practice for Real-time multiplayer:

If you don't leave the room appropriately, Google Play games services will continue to send event and invitation notifications to the client. You should leave the active room whenever one of these scenarios occurs:

  • Gameplay is over (for example, a player has won the match).
  • When your game goes into the background.
  • On Android, leave the room when:
    • The player cancels the game in the waiting room UI.
    • The response code returned in the onActivityResult() callback is GamesActivityResultCodes.RESULT_LEFT_ROOM.
    • The Activity onStop() is called. This might indicate that your Activity is being destroyed. In this case, leave the room and call disconnect().

Hope those links covers up all your concerns. Happy coding! :)

Reuter answered 17/5, 2016 at 8:39 Comment(3)
1 - Thanks I'll look into that i.e. if the connection status of the participant whose internet is turned off changes for the other participant. 2 - So the short answer is that there is no way to reconnect to the same room after leaving. :)Enrichetta
UPDATE : Tested your solution for 1st question ---- When a participant's internet connection disconnects or even when it just switches between Data and Wifi, the connection status of the participant doesn't change. It still show that participant is connected until you call leave room on the other participant. But you cannot send any messages now!Enrichetta
I have the same problem and yes, implementing RoomStatusUpdateListener callbacks as @Reuter suggested doesn't help. The API just doesn't call any callaback when a peer loses connection. I'm planning to solve this by setting up watchdog timers on the clients that repeatedly ping peers to see if they're still connected.Homocentric

© 2022 - 2024 — McMap. All rights reserved.