Exemple #1
0
        /// <summary>
        /// 把一个用户从版块中移除。警告:本方法不是线程安全的,需自行加锁
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="onlineGuest"></param>
        private void RemoveForumOnlineGuest(int forumID, OnlineGuest onlineGuest)
        {
            OnlineGuestCollection onlineGuestsInForum;

            //从原来的版块中移除
            if (m_ForumOnlineGuests.TryGetValue(forumID, out onlineGuestsInForum))
            {
                OnlineGuestCollection newOnlineGuestsInForum = new OnlineGuestCollection(onlineGuestsInForum);
                newOnlineGuestsInForum.Remove(onlineGuest);
                m_ForumOnlineGuests[forumID] = newOnlineGuestsInForum;
            }
        }
Exemple #2
0
        /// <summary>
        /// 将一个游客从在线列表中移除。本方法线程安全,无需自行加锁
        /// </summary>
        /// <param name="guestID"></param>
        /// <param name="onlineGuest"></param>
        /// <returns></returns>
        private bool RemoveOnlineGuest(string guestID, out OnlineGuest onlineGuest)
        {
            bool result = false;
            onlineGuest = null;

            if (m_OnlineGuestTable.ContainsKey(guestID))
            {
                lock (m_OnlineGuests_Locker)
                {
                    if (m_OnlineGuestTable.TryGetValue(guestID, out onlineGuest))
                    {
                        result = true;
                        lock (onlineGuest)
                        {
                            int oldForumID = onlineGuest.ForumID;

                            //-1表示其实已经被移除了
                            if (oldForumID == -1)
                            {
                                LogHelper.CreateDebugLog("线程安全问题1");
                                return false;
                            }

                            if (oldForumID != 0)
                            {
                                lock (GetForumOnlineGuestLocker(oldForumID))
                                {
                                    //从原来的版块移除
                                    RemoveForumOnlineGuest(oldForumID, onlineGuest);
                                }
                            }

                            onlineGuest.ForumID = -1;

                            //把这个游客的IP从游客IP表中去除
                            lock (m_OnlineGuestsInIps_Locker)
                            {
                                OnlineGuestsInIp onlineGuestIp;
                                if (m_OnlineGuestsInIps.TryGetValue(onlineGuest.IP, out onlineGuestIp))
                                {
                                    onlineGuestIp.GuestIds.Remove(onlineGuest.GuestID);

                                    if (onlineGuestIp.GuestIds.Count == 0)
                                        m_OnlineGuestsInIps.Remove(onlineGuest.IP);
                                }
                            }

                            m_OnlineGuestTable.Remove(guestID);
                            OnlineGuestCollection newOnlineGuests = new OnlineGuestCollection(m_OnlineGuests);
                            newOnlineGuests.Remove(onlineGuest);
                            m_OnlineGuests = newOnlineGuests;
                        }
                    }
                }
            }

            return result;
        }
Exemple #3
0
        /// <summary>
        /// 把一个用户从版块中移除。警告:本方法不是线程安全的,需自行加锁
        /// </summary>
        /// <param name="forumID"></param>
        /// <param name="onlineGuest"></param>
        private void RemoveForumOnlineGuest(int forumID, OnlineGuest onlineGuest)
        {
            OnlineGuestCollection onlineGuestsInForum;

            //从原来的版块中移除
            if (m_ForumOnlineGuests.TryGetValue(forumID, out onlineGuestsInForum))
            {
                OnlineGuestCollection newOnlineGuestsInForum = new OnlineGuestCollection(onlineGuestsInForum);
                newOnlineGuestsInForum.Remove(onlineGuest);
                m_ForumOnlineGuests[forumID] = newOnlineGuestsInForum;
            }
        }
Exemple #4
0
        /// <summary>
        /// 将一个游客从在线列表中移除。本方法线程安全,无需自行加锁
        /// </summary>
        /// <param name="guestID"></param>
        /// <param name="onlineGuest"></param>
        /// <returns></returns>
        private bool RemoveOnlineGuest(string guestID, out OnlineGuest onlineGuest)
        {
            bool result = false;

            onlineGuest = null;

            if (m_OnlineGuestTable.ContainsKey(guestID))
            {
                lock (m_OnlineGuests_Locker)
                {
                    if (m_OnlineGuestTable.TryGetValue(guestID, out onlineGuest))
                    {
                        result = true;
                        lock (onlineGuest)
                        {
                            int oldForumID = onlineGuest.ForumID;

                            //-1表示其实已经被移除了
                            if (oldForumID == -1)
                            {
                                LogHelper.CreateDebugLog("线程安全问题1");
                                return(false);
                            }

                            if (oldForumID != 0)
                            {
                                lock (GetForumOnlineGuestLocker(oldForumID))
                                {
                                    //从原来的版块移除
                                    RemoveForumOnlineGuest(oldForumID, onlineGuest);
                                }
                            }

                            onlineGuest.ForumID = -1;

                            //把这个游客的IP从游客IP表中去除
                            lock (m_OnlineGuestsInIps_Locker)
                            {
                                OnlineGuestsInIp onlineGuestIp;
                                if (m_OnlineGuestsInIps.TryGetValue(onlineGuest.IP, out onlineGuestIp))
                                {
                                    onlineGuestIp.GuestIds.Remove(onlineGuest.GuestID);

                                    if (onlineGuestIp.GuestIds.Count == 0)
                                    {
                                        m_OnlineGuestsInIps.Remove(onlineGuest.IP);
                                    }
                                }
                            }

                            m_OnlineGuestTable.Remove(guestID);
                            OnlineGuestCollection newOnlineGuests = new OnlineGuestCollection(m_OnlineGuests);
                            newOnlineGuests.Remove(onlineGuest);
                            m_OnlineGuests = newOnlineGuests;
                        }
                    }
                }
            }

            return(result);
        }