Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 568
Uzi Avatar asked May 16 '16 12:05

Uzi


1 Answers

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! :)

like image 180
Teyam Avatar answered Nov 02 '22 06:11

Teyam