Beispiel #1
0
        public void SendMessage(string message)
        {
            ChatMessageText messageText = ChatMessageText.Create(message);

            mChatCore.SendMessage(ChatMessage.Create(GetMessageCodeByRecipient(RoomsManager.CurrentRoom.Recipient),
                                                     mUser, RoomsManager.CurrentRoom.Recipient, DateTime.Now, messageText));
        }
Beispiel #2
0
        private void OnRegistration(ChatMessage message)
        {
            Logger.Debug($"Registration new user: {message.Sender.Name}.");

            Clients[message.Sender.Id].Name = message.Sender.Name;


            ChatMail.SendMessage(ChatMessage.Create(MessageCode.NewUser, ServerUser, null, DateTime.Now, ChatMessageText.Create(message.Sender.ToString())));
            ChatMail.SendMessage(ChatMessage.Create(MessageCode.ServerUsers, ServerUser, message.Sender,
                                                    DateTime.Now, ChatMessageText.Create(String.Join(" ", Clients.RegestredUsers.Where(user => user.Id != message.Sender.Id).Select(user => user.User)))), message.Sender.Id);
        }
Beispiel #3
0
        public void TestSendPaymentChat()
        {
            var paymentChatMap = new Dictionary <string, object>();
            var chatId         = PaymentChat.Create(API_CONTEXT, paymentChatMap, USER_ID, MONETARTY_ACCOUNT_ID,
                                                    CreatePaymentAndGetId()).Value;

            var chatMessageMap = new Dictionary <string, object>
            {
                { ChatMessageText.FIELD_TEXT, MESSAGE_TEXT }
            };

            ChatMessageText.Create(API_CONTEXT, chatMessageMap, USER_ID, chatId);
        }
Beispiel #4
0
        private void HandleClients(object clientId)
        {
            int       id = (int)clientId;
            TcpClient client;

            lock (Locker)
                client = (Clients[id] as ChatClient)?.Client;

            try
            {
                while (true)
                {
                    NetworkStream stream     = client.GetStream();
                    byte[]        buffer     = new byte[Constants.MessageSize];
                    int           byte_count = stream.Read(buffer, 0, buffer.Length);

                    if (byte_count == 0)
                    {
                        break;
                    }

                    string data = Encoding.UTF8.GetString(buffer, 0, byte_count);
                    HandleMessage(ChatMessage.Parse(data));
                }
            }
            catch (Exception e)
            {
                Logger.Error(e.Message);
                Logger.Error($"Error: #{id} lost connection.");
            }
            finally
            {
                lock (Locker)
                    Clients.Remove(id);

                ChatMail.SendMessage(ChatMessage.Create(MessageCode.UserLeave, ServerUser,
                                                        null, DateTime.Now, ChatMessageText.Create(id.ToString())));

                Logger.Info($"#{id} has left.");

                client.Client.Shutdown(SocketShutdown.Both);
                client.Close();
            }
        }
        public void TestSendPaymentChat()
        {
            var chatId = PaymentChat.Create(CreatePaymentAndGetId()).Value;

            ChatMessageText.Create(chatId, MESSAGE_TEXT);
        }