Beispiel #1
0
        /// <summary>
        /// обработка выхода нового пользозвателя
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public async Task newClient(chatClient client)
        {
            onlineClients.Add(client);

            //формирование сообщения
            chatMessage chatMessage = new chatMessage();

            chatMessage.authCommand(client.user);
            chatMessage.text = "Вошел в чат";

            await broadcast(chatMessage);
        }
Beispiel #2
0
        /// <summary>
        /// обработка выхода пользователя
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public async Task closeClient(chatUser user)
        {
            //закрываем сокет
            chatClient chatClient = onlineClients.Where(client => client.user.id == user.id).First();

            onlineClients = onlineClients.Where(client => client.user.id != user.id).ToList();
            using (chatMessage m = new chatMessage())
            {
                m.command    = chatPacket.Commands.CLOSE;
                m.text       = "Вышел из сети";
                m.type       = chatPacket.TypeMessage.SYSTEM;
                m.userSender = user;
                await broadcast(m);
            }
            //await chatClient.socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Normal Closure", CancellationToken.None);
        }