private void SendChatMessage() { ChatTwo_Client_Protocol.MessageToUser(_contact.ID, ChatTwo_Protocol.MessageType.Message, null, tbxSend.Text); WriteMessage(ChatTwo_Client_Protocol.User.Name + ": " + tbxSend.Text, Color.Blue.ToArgb()); tbxSend.Clear(); tbxSend.Focus(); }
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 void dgvContacts_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { // Get currentRow. DataGridViewRow currentRow = dgvContacts.CurrentRow; ContactObj contact = ChatTwo_Client_Protocol.Contacts.Find(x => x.ID == (int)currentRow.Cells["dgvContactsId"].Value); ChatTwo_Client_Protocol.OpenChat((int)currentRow.Cells["dgvContactsId"].Value); }
private void logoutToolStripMenuItem_Click(object sender, EventArgs e) { btnAddContact.Enabled = false; dgvContacts.Enabled = false; logoutToolStripMenuItem.Enabled = false; ChatTwo_Client_Protocol.LogOut(); loginToolStripMenuItem.Enabled = true; toolStripStatusLabel1.Text = "Logged out"; MessageBox.Show(this, "This feature is sadly not fully implemented yet." + Environment.NewLine + "" + Environment.NewLine + "Currently the server just detects that you have timed out." + Environment.NewLine + "So wait 10 seconds before trying to log in again.", "Logout", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void FormMain_FormClosing(object sender, FormClosingEventArgs e) { // Check if we are exiting the program, or just hiding it. if (!_closing) { e.Cancel = true; this.Hide(); TrayBalloonTip("Minimized to tray", ToolTipIcon.None); return; } // We are exting the program, stop all threaded workers and stuff. if (ChatTwo_Client_Protocol.LoggedIn) { ChatTwo_Client_Protocol.LogOut(); } _client.Stop(); }
private void dgvContacts_KeyDown(object sender, KeyEventArgs e) { // Based on: http://stackoverflow.com/questions/1718389/right-click-context-menu-for-datagrid. DataGridView dgv = (sender as DataGridView); DataGridViewCell currentCell = dgv.CurrentCell; if (currentCell != null) { cmsContactList_Opening(null, null); if ((e.KeyCode == Keys.F10 && !e.Control && e.Shift) || e.KeyCode == Keys.Apps) { dgv.ContextMenuStrip = cmsContactList; Rectangle r = currentCell.DataGridView.GetCellDisplayRectangle(currentCell.ColumnIndex, currentCell.RowIndex, false); Point p = new Point(r.X + r.Width, r.Y + r.Height); dgv.ContextMenuStrip.Show(currentCell.DataGridView, p); dgv.ContextMenuStrip = null; } else if (e.KeyCode == Keys.Enter && !e.Control && !e.Shift && !e.Alt) { ChatTwo_Client_Protocol.OpenChat((int)dgv.Rows[currentCell.RowIndex].Cells["dgvContactsId"].Value); } } }
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(); }