How to reconnect before connection timeout?

Hello, I experience this behavior of photon server plugin:
1) I am an user in a room X (player TTL is 1sec, Room TTL 3mins)
2) the client dies (without proper disconnect)
3) I immediately try to reconnect and re-join to the same room with the same user (before connection timeout expires)
4) re-join attempt fails. related log messages on server side:
WARN Photon.Hive.HiveGame -
JoinApplyGameStateChanges: Game 'Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705' userId 'sgl:gikx-syrk-n3in-nd65' failed to join. msg:Join failed: UserId 'sgl:gikx-syrk-n3in-nd65' already joined the specified game (JoinMode=3). -- peer:GameClientPeer: PID 15, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 10/16/2018 3:22:06 PM in Room Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705, IP 192.168.2.55:41673,
5) join attempt fails too
WARN Photon.Hive.HiveGame -
JoinApplyGameStateChanges: Game 'Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705' userId 'sgl:gikx-syrk-n3in-nd65' failed to join. msg:Join failed: UserId 'sgl:gikx-syrk-n3in-nd65' already joined the specified game (JoinMode=0). -- peer:GameClientPeer: PID 17, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 10/16/2018 3:22:07 PM in Room Room_sgl:gikx-syrk-n3in-nd65_Singleplayer_491705, IP 192.168.2.55:40362,

If I wait for cca 1min, the client connection timeotes and I am able to join the same room with the same user. But I need to do this BEFORE the timeout. Any suggestion?
than you

Answers

  • hi, @dcerny

    What auth mode are you using? you should use token auth. and during rejoining you should provide a token from the previous session. Otherwise, it will not allow you to rejoin

    best,
    Ilya
  • dcernydcerny
    edited October 2018
    we use custom authentication. And we provide auth data during connection. The problem is not in establishing connection, but in rejoin/jion. The workflow is (PUN code):
    1) PhotonNetwork.AuthValues = new AuthenticationValues {...}
    2) PhotonNetwork.ConnectUsingSettings(version) - SUCCESS
    3) PhotonNetwork.CreateorJoinRoom(...) - SUCCESS
    4) kill client
    5) repeat steps 1+2 - SUCCESS
    6) PhotonNetwork.ReJoinRoom() - FAILURE
    7) PhotonNetwork.JoinRoom() - FAILURE
  • hi, @dcerny

    you do not need to repeat 1) and 2) when you rejoin. That your main mistake. I'm not sure how to do this right on the client side. @JohnTube please help here.

    best,
    ilya
  • JohnTubeJohnTube mod
    edited November 2018
    Hi @dcerny,

    Thank you for choosing Photon!
    Sorry about my late comment I was on vacation.

    OK, I see the issue.
    I think it's because the current Photon Server version does not support "sessions" if token changes, @chvetsov can confirm, clarify or rectify.
    If the client disconnects unexpectedly, the server may keep an active connection for a peer in the room for a while, during this period it won't accept any new connection with the same UserId and different token.

    What you could do to double check:

    1. Try reconnect and rejoin (keeps the same token, connects to the game server directly): If you do not kill the client but instead force a client timeout disconnect (e.g. move the app to the background and then foreground again after client connection timeout 10 seconds without keep-alive/acks only background thread if applicable) and try ReconnectAndRejoin it should work with self-hosted server.

    2. You could also try LeaveRoom(true) then Rejoin() once on master server.

    3. Try same repro steps from your previous comment but on Photon Cloud.
  • Hi @JohnTube ,

    I am facing the same problem, when our players get disconnected, they won't be able to rejoin too soon, I see the error
    2018-11-29 19:25:03,603 [12] WARN Photon.Hive.HiveGame - JoinApplyGameStateChanges: Game '868787ae-07a0-425b-bf04-a4bb4a4ff5c9' userId '8' failed to join. msg:Join failed: UserId '8' already joined the specified game (JoinMode=3). -- peer:GameClientPeer: PID 14, IsConnected: True, IsDisposed: False, Last Activity: Operation 226 at UTC 11/29/2018 11:25:03 AM in Room 868787ae-07a0-425b-bf04-a4bb4a4ff5c9, IP 192.168.1.15:37781,


    is there anyway to "force" a rejoin? I have tried LeaveRoom(true) before calling Rejoin and it does not seem to be working, (At that point i am not even connected to the game server, i don't think it's going to help the game server finding out i am already disconnected)

    Thanks for your help
    Ting

  • JohnTubeJohnTube mod
    edited November 2018
    Hi @ltx,

    You could cache (on device between 'app sessions') the room name, AuthenticationValues.Token, the Game Server's IP address of the previous 'server/connection/auth session' and reuse it in the new 'server/connection/auth session' and perform a ReconnectAndRejoin (this a PUN feature where you do a quick reconnect, shortcut to Game Server and rejoin the room) or cache the room name and AuthenticationValues.Token to perform a Rejoin.

    I did not test this and it may require changes in client code to allow injecting AuthenticationValues.Token and server address/type.
  • I'm having the exact same problem.
    Sadly, @JohnTube 's post didn't help much, for one reason: AuthenticationValues.Token always returns empty. I thought that token would be synced automatically between the server and Unity, but nope it's always empty. And I have no idea how to even access that token in my Plugin code so that I could maybe even send the token itself through an event to the player.
  • hi, @cesarnavie

    Your post contains two questions.
    1. is client side issue. Please ask in corresponding forum section. you will get more help
    2. in your plugin you do not get access to token. The only thing you have access is AuthCookie. AuthenticationCookie is part of token and can be set using Custom Authentication. Here you may find some description: https://doc.photonengine.com/en-us/server/v4/applications/loadbalancing/custom-authentication/#advanced_features. Look for AuthCookie

    best,
    ilya
Sign In or Register to comment.