GetUser() 공개 메소드

public GetUser ( int i ) : User
i int
리턴 User
예제 #1
0
        public User GetUserById(long userId)
        {
            User retval = null;

            userIdToUser.TryGetValue(userId, out retval);

            if (retval == null)
            {
                Session currentSession = this.sessionManager.GetCurrentSession();
                if (currentSession != null)
                {
                    int userCount = currentSession.GetUserCount();
                    for (int index = 0; index < userCount; index++)
                    {
                        User user = currentSession.GetUser(index);
                        if ((long)user.GetID() == userId)
                        {
                            retval = user;
                            break;
                        }
                    }
                }
            }

            return(retval);
        }
예제 #2
0
        /// <summary>
        /// Returns an unused username that can be used for this session.
        /// </summary>
        /// <param name="session">Session object for which this is being called.</param>
        /// <param name="baseName">Base name to use for the username.</param>
        /// <param name="excludedUserId">
        ///     User ID whose username excluded from the unique name check.
        ///     If not specified, all users in the session will be taken into account to find
        ///     a unique name.
        /// </param>
        /// <param name="cachedList">Cached list that can be provided to avoid extra memory allocations.
        /// </param>
        /// <returns></returns>
        public static string GetUnusedName(this Session session, string baseName, int excludedUserId, List <string> cachedList)
        {
            cachedList.Clear();

            for (int i = 0; i < session.GetUserCount(); i++)
            {
                using (var user = session.GetUser(i))
                    using (var userName = user.GetName())
                    {
                        string userNameString = userName.GetString();
                        if (user.GetID() != excludedUserId && userNameString.StartsWith(baseName))
                        {
                            cachedList.Add(userNameString);
                        }
                    }
            }

            cachedList.Sort();

            int    counter     = 0;
            string currentName = baseName;

            while (cachedList.Contains(currentName))
            {
                currentName = baseName + (++counter);
            }

            return(currentName);
        }
예제 #3
0
 public SessionData(Session s)
 {
     SessionName = s.GetName().ToString();
     SessionUserCount = s.GetUserCount().ToString();
     SessionType = s.GetSessionType().ToString();
     _users = new List<User>();
     for (var i = 0; i < s.GetUserCount(); i++)
     {
         _users.Add(s.GetUser(i));
     }
     UpdateUserNames();
 }
        private void OnCurrentUserJoinedSession(Session joinedSession)
        {
            //Debug.LogFormat("Joining session {0}.", joinedSession.GetName());

            // If joining a new session, any user in the previous session (if any) have left
            ClearCurrentSession();

            // Send a join event for every user currently in the session we joined
            for (int i = 0; i < joinedSession.GetUserCount(); i++)
            {
                User user = joinedSession.GetUser(i);
                CurrentUsers.Add(user);
                UserJoined.RaiseEvent(user);
            }
        }
예제 #5
0
        void Update()
        {
            // Get an instance of the SessionManager if one does not exist.
            if (sessionManager == null && SharingStage.Instance != null && SharingStage.Instance.Manager != null)
            {
                this.sessionManager = SharingStage.Instance.Manager.GetSessionManager();
            }

            // Only poll every second.
            if (Time.frameCount % pollingFrequency == 0 && this.sessionManager != null && sessionManager.GetSessionCount() > 0)
            {
                Session currentSession = this.sessionManager.GetCurrentSession();
                if (currentSession != null)
                {
                    int userCount = currentSession.GetUserCount();

                    // If we have fewer users in the current session than are
                    // tracked locally then one or more users have exited.
                    // We need to figure out which ones.
                    if (userCount < userIds.Count)
                    {
                        // Gather all of the new users into a new array.
                        List <long> updatedUserIds = new List <long>();

                        for (int index = 0; index < userCount; index++)
                        {
                            User user   = currentSession.GetUser(index);
                            long userId = user.GetID();
                            updatedUserIds.Add(userId);
                            Debug.Log(index + ": id: " + user.GetID() + " or: " + userId);

                            // It's an edge case, but if a user joins and a user exits at the same
                            // time, we need to handle that.
                            if (userIds.Contains(userId) == false)
                            {
                                SendJoinEvent(user);
                            }
                        }

                        // Now check to see which IDs are in the old userIds list, but not in the new updatedUserIds list.
                        for (int index = 0; index < userIds.Count; index++)
                        {
                            if (updatedUserIds.Contains(userIds[index]) == false)
                            {
                                SendLeaveEvent(userIds[index]);
                            }
                        }

                        userIds = updatedUserIds;
                    }
                    else // Same or more users in the session.
                    {
                        for (int index = 0; index < userCount; index++)
                        {
                            User user   = currentSession.GetUser(index);
                            long userId = user.GetID();
                            if (userIds.Contains(userId) == false)
                            {
                                userIds.Add(userId);
                                SendJoinEvent(user);
                            }
                        }
                    }
                }
            }
        }