public async Task SendFile()
        {
            try
            {
                if (this.panelListFile.Controls.Count > 0)
                {
                    foreach (var item in files)
                    {
                        AddFileToListChat(FrmMain.me, "-1", item.Name);
                        //Gửi
                        byte[] data = File.ReadAllBytes(item.FullName);
                        Guid   id   = Guid.NewGuid();

                        byte[] tempbuff = Encoding.UTF8.GetBytes("STARTSENDFILE%" + group.ID + "%" + data.Length.ToString() + "%" + item.Name + "%" + item.Extension + "%"
                                                                 + id.ToString() + "%" + "Public");
                        SmallPackage Smallpackage = new SmallPackage(0, 1024, "M", tempbuff, "0");
                        await FrmMain.server.GetStream().WriteAsync(Smallpackage.Packing(), 0, Smallpackage.Packing().Length);

                        FrmMain.client.SendFileToServer(data, "F", id.ToString());;
                    }
                    this.files.Clear();
                    this.panelListFile.Controls.Clear();
                    this.panelListFile.Visible = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #2
0
 private void txtCreate_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         try
         {
             if (string.IsNullOrEmpty(txtCreate.Text))
             {
                 MessageBox.Show("Please enter group name!", "Error create group", MessageBoxButtons.OK, MessageBoxIcon.Warning);
             }
             else
             {
                 if (txtCreate.Text.Length > 32)
                 {
                     MessageBox.Show("Name is shorter than 32", "Name is not invalid", MessageBoxButtons.OK);
                     return;
                 }
                 else
                 {
                     byte[]       buff         = Encoding.UTF8.GetBytes(string.Format("CREATEGR%{0}%{1}", txtCreate.Text, FrmMain.me.Id));
                     SmallPackage smallPackage = new SmallPackage(0, 1024, "M", buff, "0");
                     FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);
                     this.txtCreate.Text = "";
                 }
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
     }
 }
Beispiel #3
0
        private void txtCreate_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (string.IsNullOrEmpty(this.txtCreate.Text))

                {
                    MessageBox.Show("Please enter contact name!", "Error create contact", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    try
                    {
                        byte[]       tempBuff     = Encoding.UTF8.GetBytes(string.Format("CREATECB%{0}", this.txtCreate.Text));
                        SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "Server");
                        FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);
                        txtCreate.Clear();
                    }
                    catch
                    {
                        MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }
        }
Beispiel #4
0
 public async void SendRemoveFriendToServer()
 {
     try
     {
         var temp = MessageBox.Show("Remove Friend", "Remove Friend", MessageBoxButtons.YesNo);
         if (temp == DialogResult.Yes)
         {
             byte[]       tempbuff = Encoding.UTF8.GetBytes("REMOVEFRIEND%" + FrmMain.me.Id + "%" + user.Id);
             SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
             FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Beispiel #5
0
        private void CheckPasswordFromServer()
        {
            try
            {
                UserVerification verification = new UserVerification();

                byte[] tempBuff = Encoding.UTF8.GetBytes(string.Format("CHECKPASS%{0}%{1}%{2}",
                                                                       FrmMain.me.Id,
                                                                       verification.GetSHA256(txtOldPassword.Text),
                                                                       verification.GetSHA256(txtNewPassword.Text)));
                SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "Server");
                FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #6
0
        private async void SendVoiceToServer()
        {
            try
            {
                if (voice.GetWave() == null)
                {
                    return;
                }
                voice.DisposeAll();

                byte[] data = File.ReadAllBytes(voice.Path);
                Guid   id   = Guid.NewGuid();
                if (user != null)
                {
                    byte[] tempBuff = Encoding.UTF8.GetBytes(string.Format("STARTSENDVOICE%{0}%{1}%{2}%{3}",
                                                                           user.Id,
                                                                           data.Length,
                                                                           id.ToString(), "Private"));
                    SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "0");
                    FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);
                    FrmMain.client.SendFileToServer(data, "V", id.ToString());

                    userForm.AddVoiceMessage(FrmMain.me, voice.Path);
                }
                else
                {
                    byte[] tempBuff = Encoding.UTF8.GetBytes(string.Format("STARTSENDVOICE%{0}%{1}%{2}%{3}",
                                                                           group.ID,
                                                                           data.Length,
                                                                           id.ToString(), "Public"));
                    SmallPackage smallPackage = new SmallPackage(0, 1024, "M", tempBuff, "0");
                    FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);
                    FrmMain.client.SendFileToServer(data, "V", id.ToString());

                    groupForm.AddVoiceMessage(FrmMain.me, voice.Path);
                }
                // Process when record sent
                voice.Path = voice.GetNextPath();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #7
0
        private void pictureDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure remove this contact!", "Remove Contact", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    byte[]       buff         = Encoding.UTF8.GetBytes("DELETECONTACT%" + this._ID);
                    SmallPackage smallPackage = new SmallPackage(0, 1024, "M", buff, "Server");
                    FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);

                    _RemoveThis();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #8
0
 private async void pictureBox2_Click(object sender, EventArgs e)
 {
     try
     {
         if (ucParent != null)
         {
             fileId = ucParent.ID;
         }
         byte[]       tempbuff = Encoding.UTF8.GetBytes("SENDFILE%" + fileId + "%" + fileName);
         SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
         FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
         PictureBox temp = sender as PictureBox;
         //temp.Image = Image.FromFile(@"..\..\images\check.png");
         //temp.Enabled = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        private void label3_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult rs = MessageBox.Show("Are you sure Out this Group", "Remove Group", MessageBoxButtons.YesNo);
                if (rs == DialogResult.Yes)
                {
                    byte[]       buff         = Encoding.UTF8.GetBytes("OUTGR%" + group.ID + "%" + (group.admin == FrmMain.me ? "true" : "false") + "%" + FrmMain.me.Id);
                    SmallPackage smallPackage = new SmallPackage(0, 1024, "M", buff, "0");
                    FrmMain.server.GetStream().WriteAsync(smallPackage.Packing(), 0, smallPackage.Packing().Length);

                    frmMain.GroupUI.Dispose();
                    mainForm.GroupUIs.Remove(frmMain.GroupUI);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #10
0
 private void label3_Click(object sender, EventArgs e)
 {
     try
     {
         var temp = MessageBox.Show("Remove Friend", "Remove Friend", MessageBoxButtons.YesNo);
         if (temp == DialogResult.Yes)
         {
             byte[]       tempbuff = Encoding.UTF8.GetBytes("REMOVEFRIEND%" + FrmMain.me.Id + "%" + user.Id);
             SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
             FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
         }
         FrmMain.frmFriend.RemoveFriend(frmMain.userUI);
         frmMain.userUI.DisableRemove();
         frmMain.userUI.EnableADD();
         this.user.IsFriend = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        public async Task SendMessage()
        {
            try
            {
                if (TextBoxEnterChat.Text.Trim() != "")
                {
                    byte[] tempbuff = Encoding.UTF8.GetBytes("GSEND%" + group.ID + "%" +
                                                             FrmMain.me.Id + "%" +
                                                             this.TextBoxEnterChat.Text);
                    SmallPackage package = new SmallPackage(0, 1024, "M", tempbuff, "0");
                    FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);

                    this.AddItemToListChat(FrmMain.me, "-1", this.TextBoxEnterChat.Text);
                    this.GroupUI.AddMessageIntoInteract(FrmMain.me.Name, TextBoxEnterChat.Text);
                    TextBoxEnterChat.Text = string.Empty;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        private async void lbSave_Click(object sender, EventArgs e)
        {
            DialogResult ds = MessageBox.Show("Are you sure change this message", "Edit Message", MessageBoxButtons.YesNo);

            if (ds == DialogResult.Yes)
            {
                try
                {
                    byte[]       tempbuff = Encoding.UTF8.GetBytes("EDITMESSAGE%" + pnparent.ID + "%" + pnparent.IDParent + "%" + textBox1.Text);
                    SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
                    FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
                    ucmessshow.Visible = true;
                    ucmessshow.SetText(textBox1.Text);
                    pnparent._RemoveEditControls(this);
                    pnparent.isTurnOnEdit = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Beispiel #13
0
 public async Task SendMessage()
 {
     try
     {
         if (TextBoxEnterChat.Text != "")
         {
             // Gửi tin nhắn qua server
             byte[]       tempbuff = Encoding.UTF8.GetBytes("SEND%" + FrmMain.me.Id + "%" + user.Id + "%" + this.TextBoxEnterChat.Text);
             SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
             FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
             // tạo một panel chat
             this.AddItemInToListChat(FrmMain.me, "-1", this.TextBoxEnterChat.Text);
             this.userUI.AddMessageIntoInteract(FrmMain.me.Name, TextBoxEnterChat.Text);
             //clear textbox nhập chat
             TextBoxEnterChat.Text = "";
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
        private void picDelete_Click(object sender, EventArgs e)
        {
            try
            {
                DialogResult temp = MessageBox.Show("Are you sure delete this message", "Delete Message", MessageBoxButtons.OKCancel);
                if (temp == DialogResult.OK)
                {
                    if (this.User.Id != FrmMain.me.Id)
                    {
                        this.Visible = false;
                    }
                    else if (isFile)
                    {
                        byte[]       tempbuff = Encoding.UTF8.GetBytes("DELETEMESSAGE%" + this.ID + "%" + IDParent);
                        SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
                        FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
                        this.ucfileshow.DeleteMessage();
                        this.DisableEdit();
                        this.DisableDelete();
                    }
                    else
                    {
                        byte[]       tempbuff = Encoding.UTF8.GetBytes("DELETEMESSAGE%" + this.ID + "%" + IDParent);
                        SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
                        FrmMain.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);
                        this.ucmessshow.DeleteMessage();
                        this.DisableEdit();
                        this.DisableDelete();
                    }

                    acceptFocus = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Beispiel #15
0
        private async void button1_Click(object sender, EventArgs e)
        {
            if (kiemtradulieu() == false)
            {
                MessageBox.Show("Vui long nhap du lieu day du!");
            }
            if (kiemtramatkhau() == false)
            {
                MessageBox.Show("Mat khau khong trung khop!");
                txtNhaplaimatkhau.PasswordChar = '\0';
                txtNhaplaimatkhau.Text         = "Nhap lai mat khau";
            }
            else
            {
                try
                {
                    UserManager.UserVerification userVerification = new UserManager.UserVerification();
                    string pass = userVerification.GetSHA256(txtMatkhau.Text);

                    byte[]       tempbuff = Encoding.UTF8.GetBytes("SIGNUP%" + this.txtTendangnhap.Text + "%" + pass);
                    SmallPackage package  = new SmallPackage(0, 1024, "M", tempbuff, "0");
                    await FrmLogin.server.GetStream().WriteAsync(package.Packing(), 0, package.Packing().Length);

                    byte[] buffReceive = new byte[1024];
                    await FrmLogin.server.GetStream().ReadAsync(buffReceive, 0, buffReceive.Length);

                    SmallPackage packageReceive = new SmallPackage();
                    packageReceive.DividePackage(buffReceive);

                    string[] data = (Encoding.UTF8.GetString(packageReceive.Data).Trim('\0', '\t', '\n')).Split('%');
                    if (data[0].Trim('\0', '\r', '\n') == "SIGNUPOKE")
                    {
                        MessageBox.Show("SIGN UP successfully");
                        this.login.Show();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Tai khoan da ton tai");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
        public async void SendRequest(string account, string pass, string action)
        {
            try
            {
                UserManager.UserVerification userVerification = new UserManager.UserVerification();
                pass = userVerification.GetSHA256(pass);
                byte[]       tempBuff    = Encoding.UTF8.GetBytes(action + "%" + account + "%" + pass);
                SmallPackage package     = new SmallPackage(1024, 1024, "M", tempBuff, "0");
                byte[]       buffMessage = package.Packing();
                await server.GetStream().WriteAsync(buffMessage, 0, buffMessage.Length);

                byte[] buffReceive = new byte[1024];
                await server.GetStream().ReadAsync(buffReceive, 0, buffReceive.Length);

                SmallPackage packageReceive = new SmallPackage();
                packageReceive.DividePackage(buffReceive);

                string[] data = (Encoding.UTF8.GetString(packageReceive.Data).Trim('\0', '\t', '\n')).Split('%');
                if (data[0] == "LOGINOKE")
                {
                    User    user     = new User(data[1], account, true, @"./images/avatarDefault/avatarDefault.png");
                    FrmMain mainform = new FrmMain(this, user, client, server, data[2]);
                    mainform.Show();
                    this.Hide();
                    label2.Visible = false;
                }
                else if (data[0] == "ERRORLOGINED")
                {
                    MessageBox.Show("Account was logined in other computer", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    label2.Text    = "Tai khoan hoac mat khau khong chinh xac";
                    label2.Visible = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Please check the connection again or the server could not be found!", "Error Connected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.lnConnect.Text = "No connection";
            }
        }
Beispiel #17
0
 private async void LoadContactBook()
 {
     byte[]       tempbuff       = Encoding.UTF8.GetBytes("LOADCONTACTBOOK%");
     SmallPackage packageReceive = new SmallPackage(0, 1024, "M", tempbuff, "0");
     await server.GetStream().WriteAsync(packageReceive.Packing(), 0, packageReceive.Packing().Length);
 }
Beispiel #18
0
 private async void LoadGroupData()
 {
     byte[]       tempbuff       = Encoding.UTF8.GetBytes("LOADGROUPDATA%" + me.Id);
     SmallPackage packageReceive = new SmallPackage(0, 1024, "M", tempbuff, "0");
     await server.GetStream().WriteAsync(packageReceive.Packing(), 0, packageReceive.Packing().Length);
 }