示例#1
0
        /// <summary>
        /// Adds a(n) <see cref="ISession"/>.
        /// </summary>
        /// <param name="addSession"></param>
        private void HandleAddSession(AddSession addSession)
        {
            ISession existingSession;

            // making sure we dont already have a session with the same session id
            if (sessions.TryGetValue(addSession.SessionId, out existingSession))
            {
                // since adding sessions is controlled by the master rather than the client
                // we will not notify the client rather throw out an error
                Logger.ErrorFormat("[HandleAddSession]: Destroying existing Session (Name={0})", existingSession.Name);
                // destroy the exisiting session
                // we dont need to destroy the requested session since they both have the same session id, both (if possible) will be destroyed
                existingSession.Destroy(DestroySessionReason.KickedByExistingSession);
                return;
            }

            ISession session = new SocialSession(addSession.SessionId, addSession.CharacterName, this, social);

            // if a lock wait time is used (not -1) use a while loop to counter lock timeouts
            if (!sessions.Add(addSession.SessionId, session))
            {
                // this will not happen but Murphy's law states otherwise
                Logger.ErrorFormat("[HandleAddSession]: Session (Name={0}) cannot be added", addSession.CharacterName);
                session.Destroy(DestroySessionReason.KickedByServer);
            }
        }
示例#2
0
        /// <summary>
        /// Removes a(n) <see cref="SocialSession"/> from the social
        /// </summary>
        /// <param name="session"></param>
        public bool RemoveSession(SocialSession session)
        {
            // using a while loop for the lock-timeout
            while (!this.sessionCache.RemoveSession(session))
            {
                SocialSession existingSession;
                if (!this.sessionCache.TryGetSessionBySessionName(session.Name, out existingSession))
                {
                    return(false);
                }
            }

            return(true);
        }