NetworkingPeer.CheckMasterClient C# (CSharp) Method

CheckMasterClient() private method

Picks the new master client from player list, if the current Master is leaving (leavingPlayerId) or if no master was assigned so far.
private CheckMasterClient ( int leavingPlayerId ) : void
leavingPlayerId int /// The ignored player is the one who's leaving and should not become master (again). Pass -1 to select any player from the list. ///
return void
    private void CheckMasterClient(int leavingPlayerId)
    {
        bool currentMasterIsLeaving = this.mMasterClientId == leavingPlayerId;
        bool someoneIsLeaving = leavingPlayerId > 0;

        // return early if SOME player (leavingId > 0) is leaving AND it's NOT the current master
        if (someoneIsLeaving && !currentMasterIsLeaving)
        {
            return;
        }

        // picking the player with lowest ID (longest in game).
        int lowestActorNumber;
        if (this.mActors.Count <= 1)
        {
            lowestActorNumber = this.mLocalActor.ID;
        }
        else
        {
            // keys in mActors are their actorNumbers
            lowestActorNumber = Int32.MaxValue;
            foreach (int key in this.mActors.Keys)
            {
                if (key < lowestActorNumber && key != leavingPlayerId)
                {
                    lowestActorNumber = key;
                }
            }
        }
        this.mMasterClientId = lowestActorNumber;

        // callback ONLY when the current master left
        if (someoneIsLeaving)
        {
            SendMonoMessage(PhotonNetworkingMessage.OnMasterClientSwitched, this.GetPlayerWithId(lowestActorNumber));
        }
    }
NetworkingPeer