Peer.DisconnectByOtherPeer

Options
caozane
caozane
edited August 2013 in Photon Server
So I have upgraded my project to 3.2 and found this function:

Peer.DisconnectByOtherPeer(PeerBase otherPeer, OperationRequest otherRequest, SendParameters sendParameters);

The function possibly solves a join issue when a user is trying to join the same room from different machines. Please see my attached disconnect handling code snippet.

Could you please verify the following assumptions which my disconnect logic is based upon:
1) When using a message to remove a peer from a room rather than doing it directly from an operation means that no other operations are executed at that point?
2) Peer.DisconnectByOtherPeer does not seem to trigger a peer status change e.g. status change to StatusCode.Disconnect?
3) To disconnect the duplicate peer when using Peer.DisconnectByOtherPeer I have to explicitly call Peer.Disconnect?
4) Is it in any way guaranteed when I use a message to RemovePeerFromGame, as I do in OnDisconnect, that the peer is removed when DisconnectByOtherPeer resumes the Join operation?

Comments

  • Hello caozane,

    the current implementation does indeed not call Peer.Disconnect() - this is the reason why there are no status changes and the peer is not disconnected at all.
    So for now, you'd need to add a call to Peer.Disconnect() in the OnDisconnectByOtherPeer() method, and then you should get the status changes etc.

    This does not look like intended behavior to me - I've asked the original developer to have a look and answer your questions in more detail.
  • caozane
    Options
    Hello Nicole
    Thx for the answer! Did you get more details from the original developer?
  • Hey Caozane,

    sorry that we did not come up with a more detailed answer earlier.

    1. Each operation is executed on a peer's fiber. (Everything that is enqueued on a fiber is executed on a single thread, and the order is preserved).
    If two clients call an operation simultaneously, the code for these operations are executed simultaneously on their fibers. If the operation needs to modify the room (for example, the room's actor list), the operations need to be synchronized. So they push a message pushed to the room - it is enqueued to the room's fiber, and all the messages are again executed on a single thread for that room.

    So - yes, the room message makes sure that only one operation is executed at the same time for that room.

    2. & 3. - for the missing status change - to work around the issue, please add the call to peer.Disconnect() yourself.

    4. I'm not sure if I understood your workflow correctly, but I think this happens:

    1. Peer A is in Game X.
    2. Peer B tries to join X and calls A.DisconnectByOtherPeer().
    3. A.DisconnectByOtherPeer calls A.OnDisconnectByOther, which calls A.Disconnect().

    Then, there are two possibilities about the order of the next calls:

    Option 1 (more likely):
    4. B.Join() continues and B joins the room. At this time, A + B are both in the room.
    5. callback to A.OnDisconnect() is made, which calls RemovePeerFromGame.
    6. A is removed from the game and only B is left.

    Option 2:
    4. callback to A.OnDisconnect() is made, which calls RemovePeerFromGame.
    5. A is removed from the game. Technically, there is no player in the room right now - so make sure that peer B already holds a reference to the room, so that it is not cleaned up.
    6. B.Join() continues and B joins the Game, being the only player there.

    I hope this helps.
  • caozane
    Options
    Hi Nicole :)
    I got one other question:
    1. Peer A is in Game X.
    2. Peer B tries to join X and call A.DisconnectByOtherPeer.
    What triggers the callback of the join operation of peer B? Is it when peer A, property Connected== false? Or is when peer A does not have a room reference anymore or something else?