Sign In Register

How can we help you today?

Start a new topic
Answered

Sometimes RTSession will keep Ready even when gs available is false

So Im starting to polish connection management for our game, and started to test turning internet on and off mid game to see what happens (by disconnecting or even unplugging the usb wifi).


Something I noticed is that you only receive OnPlayerDisconnect callbacks if a peer willfully disconnects from the session: if a peer connection is lost, you dont receive anything. And even if the peer manages to reconnect to the session, no one receives OnPlayerConnected either.  And meanwhile the number of active peers on the RTSession keeps unchanged.


#Question 1# Can I relly on OnPlayerDisconnect to be sent only when a player willfully disconnects? Cause if so I dont need to expect a reconnection and just 'kill' the player from the game.

This is opportune, cause otherwise I will have to implement my own "peer willfully quit" packets, I rather not. 


Some times RTSession wont change its ' Ready' to false, even after receiving GameSparksAvailable(false). Makes no sense, and its actually a pain to work around this. When GameSparksAvailable(true) is received, the session is still Ready==true, which isnt really true.

 I check that 'Ready' to reconnect to the session after connection problems, it works fine when Ready is set to false (player successful gets back to the game).

So far, calling RTSession.Disconnect when GameSparksAvailable(false) is received seems to work, but its hackish, plus I need to handle as special case cause it will generate OnReady(false), that it normally dont when connection is lost.

#Question 2# Is that a bug? Why wouldnt RTSession become "unready" if theres no connection. What exactly are the conditions?


Plus, I think documentation on these topics is really raw. I mean "OnPlayerDisconnected, called when a player is disconnected" doesnt really tell anything other than the callback name already does.



Best Answer

Hey Giuliano,

They RT service does not rely on the websocket for connection, instead an auth-token, url and port are sent from the RT server to the client. Once the RT server gets a login from the client the server can proceed to send data even if the player is logged out of GameSparks. This is why the Ready state does not change when GameSparksAvaialble() changes. They are not connected.

This is also the reason OnPlayerDisconnected does not get called when a connection is dropped. The server effectively cannot know the player is gone if they cannot receive anything from the player, and GameSparks does not use a 'keep-alive' packet to check, as this would eat into your bandwidth. So you can rely on OnPlayerDisconnected(), and if you want to check if the player is will connected (and just not sending anything) i would implement a timer to send a packet from the server to the player at intervals (maybe 30secs) and the player will respond when they get the packet. If they dont response, then the server know they are no longer connected and can broadcast that info to all other players.


Does that make sense?
Sean


Well, you can't keep having onPeerDisconnect called while on mobile devices, then you'd have a mess. This is why they have a configuration option for timing out a player. From what I understand of networking systems, if the server doesn't receive anything from the peer in X seconds (X being what you put in), it will consider the peer to have disconnected.

Answer

Hey Giuliano,

They RT service does not rely on the websocket for connection, instead an auth-token, url and port are sent from the RT server to the client. Once the RT server gets a login from the client the server can proceed to send data even if the player is logged out of GameSparks. This is why the Ready state does not change when GameSparksAvaialble() changes. They are not connected.

This is also the reason OnPlayerDisconnected does not get called when a connection is dropped. The server effectively cannot know the player is gone if they cannot receive anything from the player, and GameSparks does not use a 'keep-alive' packet to check, as this would eat into your bandwidth. So you can rely on OnPlayerDisconnected(), and if you want to check if the player is will connected (and just not sending anything) i would implement a timer to send a packet from the server to the player at intervals (maybe 30secs) and the player will respond when they get the packet. If they dont response, then the server know they are no longer connected and can broadcast that info to all other players.


Does that make sense?
Sean


1 person likes this
Login to post a comment