Exemplo n.º 1
0
        public void UserDisconnected(ushort userId)
        {
            var message = new UserOfflineMessage();

            message.UsersId = userId;

            RemoveUser(userId);

            _clientWriter.WriteMessageToAllClients(message);
        }
Exemplo n.º 2
0
        private void ProcessUserOffline(UserOfflineMessage message)
        {
            if (Chats.ContainsKey(message.UsersId))
            {
                Chats.Remove(message.UsersId);
            }


            if (Chats.Count > 1)
            {
                CallCallbacks(Chats.First().Key);
            }
        }
Exemplo n.º 3
0
        public async Task <IMessage> ReadAndDecodeMessage(Header header, NetworkStream networkStream)
        {
            byte[] dataBuffer = new byte[header.MessageSize];

            await networkStream.ReadAsync(dataBuffer, 0, dataBuffer.Length);

            Console.WriteLine("message type being read in network service: " + header.MessageType);

            var dataBufferList = dataBuffer.ToList();

            switch (header.MessageType)
            {
            case MessageType.NotSet:
                return(null);

            case MessageType.Connect:
                return(ConnectRequestMessage.Decode(dataBufferList));

            case MessageType.Chat:
                return(ChatMessage.Decode(dataBufferList));

            case MessageType.Image:
                return(ImageMessage.Decode(dataBufferList));

            case MessageType.NewUserOnline:
                return(NewUserOnlineMessage.Decode(dataBufferList));

            case MessageType.UserLogoff:
                return(UserLogoffMessage.Decode(dataBufferList));

            case MessageType.UserOffline:
                return(UserOfflineMessage.Decode(dataBufferList));

            case MessageType.Typing:
                return(UserTypingMessage.Decode(dataBufferList));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }