Esempio n. 1
0
    private void ChooseHost()
    {
        if (forceHost)
        {
            if (fakeHostId == "it me")
            {
                CurrentHostId = fakeHostId;
            }

            return;
        }

        // Add the session id of all users connected to the match
        List <string> userSessionIds = new List <string>();

        foreach (IMatchmakerUser user in _pendingMatch.Users)
        {
            userSessionIds.Add(user.Presence.SessionId);
        }

        // Perform a lexicographical sort on list of user session ids
        userSessionIds.Sort();

        // First user from the sorted list will be the host of current match
        string hostSessionId = userSessionIds.First();

        // Get the user id from session id
        IMatchmakerUser hostUser = _pendingMatch.Users.First(x => x.Presence.SessionId == hostSessionId);

        CurrentHostId = hostUser.Presence.UserId;
        Debug.Log("HOST ID: " + CurrentHostId);
    }
        /// <summary>
        /// Chooses host in deterministic way
        /// </summary>
        private void ChooseHost(IMatchmakerMatched matched)
        {
            // Add the session id of all users connected to the match
            List <string> userSessionIds = new List <string>();

            foreach (IMatchmakerUser user in matched.Users)
            {
                userSessionIds.Add(user.Presence.SessionId);
            }

            // Perform a lexicographical sort on list of user session ids
            userSessionIds.Sort();

            // First user from the sorted list will be the host of current match
            string hostSessionId = userSessionIds.First();

            // Get the user id from session id
            IMatchmakerUser hostUser = matched.Users.First(x => x.Presence.SessionId == hostSessionId);

            HostId = hostUser.Presence.UserId;
        }