Example #1
0
 private void BotonEnviar(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(txtMessage.Text) && txtMessage.Text.Length < 8100)
     {
         ChatMessage newMessage = new ChatMessage();
         if (txtChat.Visible == true)
         {
             newMessage.Date    = DateTime.Now;
             newMessage.Message = Cifrado.CifradoTexto(txtMessage.Text);
             newMessage.User    = clientUser;
             remoteProxy.SendNewMessage(newMessage);
             InsertarMensaje(newMessage);
         }
         else
         {
             if (ListaPrivados.Count > 0)
             {
                 newMessage.Date    = DateTime.Now;
                 newMessage.Message = Cifrado.CifradoTexto($"[Privado]{txtMessage.Text}");
                 newMessage.User    = clientUser;
                 remoteProxy.SendNewMessagePrivado(newMessage, ListaPrivados);
                 InsertarMensaje(newMessage);
             }
             else
             {
                 MessageBox.Show("No has aƱadido ningun usuario");
             }
         }
         txtMessage.Text = String.Empty;
     }
     else
     {
         if (txtMessage.Text.Length < 8100)
         {
             MessageBox.Show("Longuitud del mensaje demasiado grande");
         }
     }
 }
Example #2
0
        private void InsertarMensaje(ChatMessage message)
        {
            string mensajeDescifrado = Cifrado.DescifradoTexto(message.Message);
            int    inicio            = 9;

            if (message.User.UserName.Equals(lastuser))
            {
                txtChat.SelectionColor = Ctexto;
                if (txtChatPrivado.Visible && string.IsNullOrEmpty(txtChatPrivado.Text))
                {
                    txtChatPrivado.AppendText($"{message.User}\n");
                }
                if (message.User.UserName.Equals(clientUser.UserName))
                {
                    if (!mensajeDescifrado.Contains("[Privado]"))
                    {
                        txtChat.SelectionColor = CmiNombre;
                    }
                    else
                    {
                        txtChatPrivado.SelectionColor = CmiNombre;
                    }
                }
                if (!mensajeDescifrado.Contains("[Privado]"))
                {
                    txtChat.AppendText($"{mensajeDescifrado}\n");
                }
                else
                {
                    int longuitud = mensajeDescifrado.Length - inicio;
                    txtChatPrivado.AppendText($"{mensajeDescifrado.Substring(inicio, longuitud)}\n");
                }
            }
            else
            {
                if (message.User.UserName.Equals(clientUser.UserName))
                {
                    if (!mensajeDescifrado.Contains("[Privado]"))
                    {
                        txtChat.SelectionColor = CmiNombre;
                        txtChat.AppendText(message.User.UserName); //+ " (" + message.Date + "):"
                    }
                    else
                    {
                        txtChatPrivado.SelectionColor = CmiNombre;
                        int longuitud = mensajeDescifrado.Length - inicio;
                        txtChatPrivado.AppendText($"{mensajeDescifrado.Substring(inicio, longuitud)}\n");
                    }
                }
                else
                {
                    if (!mensajeDescifrado.Contains("[Privado]"))
                    {
                        txtChat.SelectionColor = Cnombres;
                        txtChat.AppendText(message.User.UserName);
                        txtChat.SelectionColor = Ctexto;
                    }
                    else
                    {
                        txtChatPrivado.SelectionColor = Cnombres;
                        int longuitud = mensajeDescifrado.Length - inicio;
                        txtChatPrivado.AppendText($"{mensajeDescifrado.Substring(inicio, longuitud)}\n");
                        txtChatPrivado.SelectionColor = Ctexto;
                    }
                }
                if (!mensajeDescifrado.Contains("[Privado]"))
                {
                    txtChat.AppendText($"\n{mensajeDescifrado} \n");
                }
                else
                {
                    int longuitud = mensajeDescifrado.Length - inicio;
                    txtChatPrivado.AppendText($"{mensajeDescifrado.Substring(inicio, longuitud)}\n");
                }
            }
            lastuser = message.User.UserName;
        }