How to instanlty remove an actorID from a room while PlayerTtl is set to several minutes

Options
Hello guys!

I'm creating a network room with the following options:
RoomOptions roomOptions = new RoomOptions();
roomOptions.MaxPlayers = 2;
roomOptions.CleanupCacheOnLeave = false;
roomOptions.EmptyRoomTtl = 120000;
roomOptions.PlayerTtl = 120000;
When a player quits the game, a new player should be able to immediately join the room. But in my case new players won't be able to join this room within 2 minutes, because roomOptions.PlayerTtl is set to 2 minutes. From my understanding it causes the room to store the acotorID of the player that quit and during this time the room is considered full and new players can't join.

I can't set PlayerTtl to 0 because I actually need the room to remember the player in case he looses internet connection and then tries to reconnect.

But I also need to be able to kick his actorID out of the room immediately (for example when the player pressed Quit button).

Could you please suggest any ways to do it?

Also as a workaround could it be possible to initially set roomOptions.PlayerTtl to 0 but then later change it to 120? I actually need PlayerTtl to be 0 only during the specific phase of my game and therefore it could work for me.

Thank you!

Answers

  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @1_Mad_Developer,

    There are 2 possible solutions:

    1. PlayerTTL == 0

    The room is created with PlayerTTL = 0.
    The players join the room, once the room is full, hide the room from the lobby so no other player can join it later. To hide it, set "IsVisible" to false. If a player unexpectedly disconnects he will be able to join the room by name. So you need to cache the room name and when the player rejoins he will get a new actor number.

    2. PlayerTTL != 0

    If a player hits Quit button and decides to leave the room for good you can call OpLeaveRoom(false) and the actor will be removed from the room and an empty slot will be available for others to join. Otherwise if the player unexpectedly disconnects from the room he can join it later and he will have the same actor number.
  • 1_Mad_Developer
    edited December 2016
    Options
    Great answer @JohnTube !

    Very informative, and actually both solutions should be useful in different situations. Thanks for helping me understand PUN better!

    One last question :) How do I mark your answer as an answer? I dont see any buttons for this:

    https://postimg.org/image/ikmulv70r/
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @1_Mad_Developer,

    I edited the original post's type from "Discussion" to "Question". Please make sure to use proper type next time! Thanks.