private void btnSendRequest_Click(object sender, EventArgs e) { ResetWindow(); // If there is no contact name entered. if (tbxContactName.Text == "") { lblContactName.ForeColor = Color.Red; tbxContactName.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You did not enter a contact name."; return; } // You can't add your self. (The Server also checks this.) if (tbxContactName.Text == ChatTwo_Client_Protocol.User.Name) { lblContactName.ForeColor = Color.Red; tbxContactName.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You can't add your self."; return; } btnSendRequest.Enabled = false; btnCancel.Enabled = false; tbxContactName.ReadOnly = true; lblResult.Text = "Contacting server..."; _waitingForAddContactReply = true; ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.ContactRequest, null, tbxContactName.Text); timer1.Start(); }
private void btnLogin_Click(object sender, EventArgs e) { ResetWindow(); // If there is no username entered. if (tbxUsername.Text == "") { lblUsername.ForeColor = Color.Red; tbxUsername.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You did not enter a username."; return; } // If there is no password entered. if (tbxPassword.Text == "") { lblPassword.ForeColor = Color.Red; tbxPassword.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You did not enter a password."; return; } btnLogin.Enabled = false; btnRegister.Enabled = false; tbxUsername.ReadOnly = true; tbxPassword.ReadOnly = true; lblResult.Text = "Contacting server..."; _waitingForLoginReply = true; byte[] passwordHash = ByteHelper.GetHashBytes(Encoding.Unicode.GetBytes(tbxPassword.Text)); ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.Login, passwordHash, tbxUsername.Text); timer1.Start(); }
private static void Keepalive() // Threaded looping method. { try { while (_loggedIn) { Thread.Sleep(500); List <ContactObj> onlineContacts = _contacts.FindAll(x => x.Online == true); byte[] contactIds = new byte[0]; foreach (ContactObj contact in onlineContacts) { byte[] contactId = BitConverter.GetBytes(contact.ID); contactIds = ByteHelper.ConcatinateArray(contactIds, contactId); } ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.Status, contactIds, null); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("### " + _threadKeepalive.Name + " has crashed:"); System.Diagnostics.Debug.WriteLine("### " + ex.Message); System.Diagnostics.Debug.WriteLine("### " + ex.ToString()); } }
private void btnRegister_Click(object sender, EventArgs e) { ResetWindow(); // If there is no username entered. if (tbxUsername.Text == "") { lblUsername.ForeColor = Color.Red; tbxUsername.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You did not enter a username."; return; } // If the username is too long. if (tbxUsername.Text.Length > 30) { lblUsername.ForeColor = Color.Red; tbxUsername.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "The username is too long. Please use 30 or less characters."; return; } // If there is no password entered. if (tbxPassword1.Text == "") { lblPassword1.ForeColor = Color.Red; tbxPassword1.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "You did not enter a password."; return; } // If the password and the confirm password textboxes aren't the same. if (tbxPassword1.Text != tbxPassword2.Text) { lblPassword2.ForeColor = Color.Red; tbxPassword2.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "The two passwords are not the same."; return; } // If the password is too short. // (I hate strict password rules! If it is not a bank or social security thing, don't force the uesr to make insane passwords.) if (tbxPassword1.Text.Length < 4) { lblPassword1.ForeColor = Color.Red; tbxPassword1.ForeColor = Color.Red; lblResult.ForeColor = Color.Red; lblResult.Text = "The password is too short. Please use 4 or more characters."; return; } btnRegister.Enabled = false; btnCancel.Enabled = false; tbxUsername.ReadOnly = true; tbxPassword1.ReadOnly = true; tbxPassword2.ReadOnly = true; lblResult.Text = "Contacting server..."; _waitingForCreateUserReply = true; byte[] passwordHash = ByteHelper.GetHashBytes(Encoding.Unicode.GetBytes(tbxPassword1.Text)); ChatTwo_Client_Protocol.MessageToServer(ChatTwo_Protocol.MessageType.CreateUser, passwordHash, tbxUsername.Text); timer1.Start(); }