private void Send_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtMessage.Text)) { return; } if (listUser.SelectedItem != null) { if (listUser.SelectedItem is User receiver) { SendTextMessage sendTextMessage = new SendTextMessage(receiver.Email, txtMessage.Text); if (CConnectionController.TrySendPackage(sendTextMessage, CConnectionController.ServerAddress)) { CDataController.Messages.Add(new Message(CConnectionController.LoginUser.Email, receiver.Email, DateTime.Now, txtMessage.Text)); UpdateMessage(); WaitForFeedback = true; timer.Enabled = true; } else { MessageBox.Show("Fehler beim Senden!"); } } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CConnectionController.Start(); Application.Run(new CLoginView()); if (CFormController.LoggedIn) { Application.Run(new CMainView()); } CConnectionController.Stop(); }
private void Connect_Click(object sender, EventArgs e) { if (!WaitForFeedback) { string address = txtAddress.TextWithoutWatermark; string email = txtEmail.TextWithoutWatermark; string password = txtPassword.TextWithoutWatermark; if (!IPAddress.TryParse(address, out IPAddress ipAddress)) { MessageBox.Show("Ungültige IP Addresse."); return; } if (string.IsNullOrWhiteSpace(email) || string.IsNullOrWhiteSpace(password)) { MessageBox.Show("Email und Passwort müssen ausgefühlt sein!"); return; } CConnectionController.ServerAddress = txtAddress.TextWithoutWatermark; LoginRequest login = new LoginRequest(email, Encode.GetHash(password)); CConnectionController.LoginUser = new User(login.Email, login.PasswordHash); if (!CConnectionController.TrySendPackage(login, CConnectionController.ServerAddress)) { return; } WaitForFeedback = true; timer.Enabled = true; } }
private void CMainView_FormClosed(object sender, FormClosedEventArgs e) { CConnectionController.Stop(); }
private void Register_Click(object sender, EventArgs e) { WaitForFeedback = true; string address = txtServerAddress.TextWithoutWatermark; string email = txtEmail.TextWithoutWatermark; string nickname = txtNickname.TextWithoutWatermark; string birthday = txtBirthday.TextWithoutWatermark; string password = txtPassword.TextWithoutWatermark; string password2 = txtPassword2.TextWithoutWatermark; if (string.IsNullOrWhiteSpace(email)) { MessageBox.Show("Sie müssen eine Email eingeben."); WaitForFeedback = false; return; } if (string.IsNullOrWhiteSpace(nickname)) { MessageBox.Show("Sie müssen einen Benutzername eingeben."); WaitForFeedback = false; return; } if (string.IsNullOrWhiteSpace(birthday)) { MessageBox.Show("Sie müssen ein Geburtsdatum eingeben."); WaitForFeedback = false; return; } if (string.IsNullOrWhiteSpace(password)) { MessageBox.Show("Sie müssen ein Passwort eingeben."); WaitForFeedback = false; return; } if (string.IsNullOrWhiteSpace(password2)) { MessageBox.Show("Sie müssen das Passwort bestätigen."); WaitForFeedback = false; return; } if (password != password2) { MessageBox.Show("Die Passwörter stimmen nicht überein."); WaitForFeedback = false; return; } if (!DateTime.TryParse(birthday, out DateTime date)) { MessageBox.Show("Geben Sie ein gültiges Datum ein. \n Tipp: dd.mm.yyyy"); WaitForFeedback = false; return; } if (!email.Contains('@') || !email.Contains('.')) { MessageBox.Show("Geben Sie eine gültige Email ein."); WaitForFeedback = false; return; } if (nickname.Length > 16 || nickname.Length < 4) { MessageBox.Show("Der Benutzername muss mindestens 4 und maximal 16 Zeichen haben."); WaitForFeedback = false; return; } if (password.Length < 8) { MessageBox.Show("Das Passwort muss mindestens 8 Zeichen lang sein."); WaitForFeedback = false; return; } if (DateConverter.GetAgeFromDate(date) < 12) { MessageBox.Show("Sie müssen mindestens 12 Jahre alt sein!"); WaitForFeedback = false; return; } if (!IPAddress.TryParse(address, out IPAddress ipAddress)) { MessageBox.Show("Ungültige IP Addresse."); WaitForFeedback = false; return; } CConnectionController.ServerAddress = ipAddress.ToString(); string hash = Encode.GetHash(password); RegistrationRequest registration = new RegistrationRequest(email, nickname, hash, date); if (!CConnectionController.TrySendPackage(registration, CConnectionController.ServerAddress)) { WaitForFeedback = false; return; } timer.Enabled = true; }