/// <summary> /// Parses through a list of all the current chatrooms /// </summary> /// <param name="message">Message with the chatroom list.</param> private void ParseChatroomList(TCPMessage message) { string[] idNames = message.message.Split(','); if (idNames.Length % 2 == 1) { for (int i = 0; i < idNames.Length - 1; i += 2) { // don't add already existing chatrooms if (chatroomList.Any(x => x.id == int.Parse(idNames[i]))) { continue; } Chatroom temp = new Chatroom(int.Parse(idNames[i]), idNames[i + 1]); chatroomListBox.Items.Add(temp); chatroomList.Add(temp); } } else { } //Bad formating chatroomListBox.SetSelected(0, true); selectedChatroomInListBox = chatroomListBox.SelectedItem; undoBtn.Enabled = false; }
/// <summary> /// When the send buttton is clicked: make a new TCPMessage and add the inputed text into it, try to send it /// and get the status, set the status label, clear the message field if successful, and set the status label. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void sendButton_Click(object sender, EventArgs e) { TCPMessage tcpMessage = new TCPMessage(); tcpMessage.message = messageField.Text; // send chatroom message if (chatroomListBox.SelectedIndex >= 0) { tcpMessage.chatID = ((Chatroom)(chatroomListBox.SelectedItem)).id; } else if (userListBox.SelectedIndex >= 0) // TODO send direct message { //String temp = "000" + (userListBox.SelectedItem.ToString()).to; } EnumMessageStatus status = messageService.SendMessage(tcpMessage); if (status == EnumMessageStatus.successful) { messageField.Clear(); } setResponseMessage(EnumExtensions.GetEnumDescription(status)); }
/// <summary> /// Disconnect correctly by sending a CLOSE message to the server. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_FormClosed(object sender, FormClosedEventArgs e) { TCPMessage tcpMessage = new TCPMessage(); tcpMessage.chatID = 0; tcpMessage.command = "CLOSE"; tcpMessage.message = "0"; messageService.SendMessage(tcpMessage); }
/// <summary> /// Sign out of the user account and return to the startup form when the signout button is clicked. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void logOutToolStripMenuItem_Click(object sender, EventArgs e) { TCPMessage tcpMessage = new TCPMessage(); tcpMessage.chatID = 0; tcpMessage.command = "CLOSE"; tcpMessage.message = "0"; messageService.SendMessage(tcpMessage); this.Hide(); var startupForm = new StartupForm(); startupForm.FormClosed += (s, args) => this.Close(); startupForm.Show(); }