private void DisconnectButton_Click(object sender, RoutedEventArgs e)
        {
            client.Disconnect();
            ConnectionWindow window = new ConnectionWindow();

            window.Show();
            Close();
        }
        public void LeaveServer()
        {
            MessageBox.Show("Połączenie z serwerem zostało zerwane");

            Application.Current.Dispatcher.Invoke(new Action(() =>
            {
                callingService.DisposeTcpListener();
                if (callingService.isBusy)
                {
                    callingService.BreakCall(true);
                }
                client.Disconnect();
                ConnectionWindow loginWindow = new ConnectionWindow();
                loginWindow.Show();
                this.Close();
            }));
        }
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            if (!EmailValidator.IsValid(EmailTextBox.Text))
            {
                MessageBox.Show("Adres email niepoprawny!");
                return;
            }

            try
            {
                CscUserData userData = new CscUserData()
                {
                    Email    = EmailTextBox.Text,
                    Password = CscSHA512Generator.get_SHA512_hash_as_string(CscSHA512Generator.get_SHA512_hash_as_string(PasswordTextBox.Password) + client.salt)
                };
                var bytesToSend = protocol.CreateLoginMessageEncrypted(userData, client.DH.Key);
                client.SendBytes(bytesToSend);
                //MessageBox.Show("wysyłam hasło z solą " + userData.Password);
                client.UserProfile.Email = EmailTextBox.Text;//n

                var response = client.ReceiveBytes();
                //var length = BitConverter.ToInt16(response.Skip(1).Take(2).ToArray(), 0);
                var messageEncrypted = response.Skip(3).ToArray();
                var message          = client.AES.DecryptStringFromBytes(messageEncrypted);
                if (response[0] == 12)
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(message, 0, length));//witaj na serwerze

                    //Create main window
                    client.initialized = true;
                    ClientMainWindow mainWindow = new ClientMainWindow(client, false);
                    mainWindow.Show();
                    this.Close();
                }
                if (response[0] == 13)
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(message, 0, length));
                    MessageBox.Show(message);
                    return;
                }
                else
                {
                    //MessageBox.Show(Encoding.Unicode.GetString(response));
                }
            }
            catch (SocketException ex)
            {
                MessageBox.Show("Nastąpiło rozłączenie z serwerem: " + ex.Message);
                client.Disconnect();
                ConnectionWindow window = new ConnectionWindow();
                window.Show();
                Close();
            }
            catch (IOException)
            {
                MessageBox.Show("Nie otrzymano odpowiedzi od serwera");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Wystąpił nieznany błąd: " + ex.Message);
            }
        }