Example #1
0
        /// <summary>
        /// Receives a tell from another <see cref="ChatSession"/>.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="message"> </param>
        void ReceiveTell(ChatSession sender, string message)
        {
            // sending back the message to the sender (acknowledges message sent)
            var sentMessage = new ChatMessageReceived
            {
                MessageType = (byte)MessageType.Tell,
                Sender      = sender.name,
                Receiver    = this.Name,
                Message     = message
            };

            sender.SendEvent(sentMessage, new MessageParameters {
                ChannelId = PeerSettings.ChatEventChannel
            });

            // sending the receiver the message
            var receivedMessage = new ChatMessageReceived
            {
                MessageType = (byte)MessageType.Tell,
                Sender      = sender.name,
                Message     = message
            };

            this.SendEvent(receivedMessage, new MessageParameters {
                ChannelId = PeerSettings.ChatEventChannel
            });
        }
Example #2
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 ChatSession(addSession.SessionId, addSession.CharacterName, this, chat);

            // 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);
            }
        }
Example #3
0
        /// <summary>
        /// Removes a(n) <see cref="ChatSession"/> from the chat
        /// </summary>
        /// <param name="session"></param>
        public bool RemoveSession(ChatSession session)
        {
            // using a while loop for the lock-timeout
            while (!sessionCache.RemoveSession(session))
            {
                ChatSession existingSession;
                if (!sessionCache.TryGetSessionBySessionName(session.Name, out existingSession))
                {
                    return(false);
                }
            }

            return(true);
        }