Player not disconnected when phone screen is locked

Options
luxel
luxel
Dear photon support,

Need your help here. We're dealing with a situation where player stuck in room and cannot be disconnected.

Our server environment: Self hosted loading balancing Master + Game server
Timeout config in PhotonServer.config:
MinimumTimeout="10000"
MaximumTimeout="30000"
Protocol: Udp

Steps to produce the issue:
1. Connect a player to the server and create a room. (Our client is Unity3D + PUN, testing device is Anroid OS)
2. While the player still in the room, directly lock the phone (the screen goes black)
3. After a few minutes, connect another client to server for a random match - and the client will enter the room which created by the first player! But the first player is totally unresponsive - which means we cannot start any actual match. Tried a few times, the first player is always stuck in the room, never disconnected. Then the room becomes a "ghost" room and it is very annoying.
4. If we just cut off the wifi on the first phone, then the first player will be disconnected immediately.

So the question is, how can we trigger the disconnection on server to the player who is inactive? Is there any background thread still keeping the connection with server even when the game process is in the background?

Thank you.

Comments

  • luxel
    Options
    After reading into the PUN code, and I found that PUN is creating a background thread to send ACK to server to keep the connection. What would be the solution? Shall we try to pause the background thread, or implement any other logic to detect the inactive client?
  • luxel
    Options
    To resolve our issue, temporarily I added code below. Please help review whether it is OK or there is better solution? ;)

    PhotonNetwork.cs:
    // HACK
    	/// <summary>
    	/// Whether the background thread (which sends ACK to server, see PhotonHandler) should be stopped when application is paused (app switched to background).
    	/// So the player will be disconnected from server when app becomes inactive for a long time.
    	/// Set this to false if the player is in a game and don't want to disconnect.
    	/// </summary>
    	public static bool StopBackgroundThreadWhenApplicationPause = true;
    	// END HACK
    

    PhotonHandler.cs:
    void OnApplicationPause(bool pauseStatus) {
    #if (UNITY_IPHONE || UNITY_ANDROID) && !UNITY_EDITOR
    		if (pauseStatus) {
    			if (PhotonNetwork.StopBackgroundThreadWhenApplicationPause) {
    				PhotonHandler.StopFallbackSendAckThread();
    			}
    		}
    		else {
    			PhotonHandler.StartFallbackSendAckThread ();
    		}
    #endif
    	}
    
  • vadim
    Options
    Hi,

    Why just not to call PhotonNetwork.LeaveRoom()?
  • luxel
    Options
    Hi vadim,

    You're right! that should be a solution. :oops:
  • Tobias
    Options
    Or PhotonNetwork.Disconnect() to simply disconnect entirely. Leave() will return you to the Master Server (if it can achieve that before the app is hibernated).