public void AddMessage(string sender, string recipient, string message) { try { MessagesBox.Invoke(new Action(() => { AppendTextExt(MessagesBox, sender + " -> " + recipient + " : ", Color.Red); MessagesBox.AppendText("\r\n"); MessagesBox.AppendText(message); MessagesBox.AppendText("\r\n"); })); } catch (Exception ex) { } }
/* * Deals with all server based messsages */ public void Receiver() { bool cancel = false; do { Message msg = Net.rcvMsg(comm); if (msg is TopicInfo) { // View Topics Response ListTopics.Items.Clear(); ListTopics.Items.AddRange(((TopicInfo)msg).TList.ToArray()); } else if (msg is ChatMessage) { ChatMessage message = (ChatMessage)msg; if (message is DirectMessage) { DMsBox.AppendText(message + Environment.NewLine); } else { if (message.MType == (int)MTypes.CHATLEAVE) { cancel = true; } else if (message.MType == (int)MTypes.CHATWELCOME) { MessagesBox.AppendText(message.Sender + " joined the Topic!" + Environment.NewLine); } else { MessagesBox.AppendText(message + Environment.NewLine); } } } } while (!cancel); }