How can I allow a disconnected player (and only him !) to connect back in the game ?

Options
Hi everyone,

I'd like to handle the case of a disconnected player who would like to come back in the game. Ideally, I'd like the room to be invisible and/or non-joinable for everyone except for the disconnected player(s).
I'm a beginner on PUN, and I tried to manipulate the ExpectedUsers feature, but I'm not sure I'm on the right way. I have encountered a few problems :
1. I'd like to reserve the slots for the current players but only from a special moment (basically, when the game "really" starts. But it seems impossible to modify the ExpectedUsers field outside the JoinRoom / CreateRoom call).
2. When the disconnected player comes back in the lobby and get the room list, I can't find a way to test if a room has an ExpectedUsers field which contains my own ID (ExpectedUsers are not available in the RoomInfo ?)
3. Again, ideally, the room should be visible only for the disconnected player(s). Actually, it might be the same problem. If I could test if a room has an ExpectedUsers field which does NOT contain my own ID, I could simply make it not appear in the UI.

So... What can I do ?

Best Answer

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @AlexKhundar,

    Thank you for choosing Photon!

    If you use unique UserId per player you can create rooms and set roomOptions.PlayerTTL to a proper value (in milliseconds, -1 is forever) and players can disconnect and rejoin within the period you set.
    If you do not save and load room states, you may need to increase the roomOptions.EmptyRoomTTL to be greater or equal than roomOptions.PlayerTTL.
  • AlexKhundar
    Options
    Hi @JohnTube, Thanks for your help!

    This partially solves the problem, as in case of connection issues, this timeout seems to work fine. But I'd like to handle the case in, for instance, the game crashes in one of the client, and he has to completely restart the game.
    Ideally, the room should be invisible except for him, but I had another idea : I guess I could save locally the room's name (which pretty much works like an ID as far as I understand), and automatically try to connect back the player when he restarts the game. But what if during the restart time lapse, this particular room is destroyed, and another room with the exact same name is created ? Player will connect to the wrong room...
    I still don't know how to handle that case. I do use unique UserId per player, if that can help, and the UserId stay the same from one game session to another, as long as it is the same device.

    By the way, with the PlayerTTL field initialized, if the player restarts the game during the PlayerTTL time lapse, the room slot is still taken, by "himself", and is freed only when the timeout is finished. I'd like to allow this particular user to connect back and take back his own slot.
  • AlexKhundar
    Options
    Thanks, I think this exactly what I was looking for and what I was missing.
    Thanks a lot for your support !