/// <summary> /// Executed when a private message is sent from the PrivateMessageForm. /// </summary> /// <param name="message">The message.</param> /// <param name="receiver">The receiver of the message.</param> private void Instance_PrivateMessageSent(string message, string receiver) { if (this.InvokeRequired) { // Necessary for thread-safety PrivateMessageSentCallback d = new PrivateMessageSentCallback(Instance_PrivateMessageSent); this.BeginInvoke(d, message, receiver); return; } int index = CnCNetData.PMInfos.FindIndex(c => c.UserName == receiver); if (index == -1) { PrivateMessageInfo pmInfo = new PrivateMessageInfo(); pmInfo.UserName = receiver; pmInfo.Messages.Add(new MessageInfo(cDefaultChatColor, message)); pmInfo.IsSelfSent.Add(true); CnCNetData.PMInfos.Add(pmInfo); } else { CnCNetData.PMInfos[index].Messages.Add(new MessageInfo(cDefaultChatColor, message)); CnCNetData.PMInfos[index].IsSelfSent.Add(true); } if (!CnCNetData.isPMWindowOpen) { PrivateMessageForm pmWindow = new PrivateMessageForm(cDefaultChatColor, receiver); pmWindow.Show(); CnCNetData.isPMWindowOpen = true; } CnCNetData.ConnectionBridge.SendMessage("PRIVMSG " + receiver + " " + message); }
/// <summary> /// Opens the private message window when the user double-clicks on a player's /// name in the player list box. /// </summary> private void lbPlayerList_DoubleClick(object sender, EventArgs e) { if (lbPlayerList.SelectedIndex == -1) return; string userName = lbPlayerList.Items[lbPlayerList.SelectedIndex].ToString(); if (userName[0] == '@') userName = userName.Remove(0, 1); if (userName.Contains(" (Admin)")) userName = userName.Substring(0, userName.Length - 8); // Let the user send PMs by doubleclicking players in the player list if (!CnCNetData.isPMWindowOpen) { PrivateMessageForm pmForm = new PrivateMessageForm(cDefaultChatColor, userName); pmForm.Show(); CnCNetData.isPMWindowOpen = true; } else { DoConversationOpened(userName); } }
/// <summary> /// Executed when someone sends a private message to the user. /// </summary> /// <param name="message">The message.</param> /// <param name="sender">The sender of the message.</param> private void Instance_PrivateMessageParsed(string message, string sender) { if (this.InvokeRequired) { // Necessary for thread-safety PrivateMessageParsedCallback d = new PrivateMessageParsedCallback(Instance_PrivateMessageParsed); this.BeginInvoke(d, message, sender); return; } int index = CnCNetData.PMInfos.FindIndex(c => c.UserName == sender); if (index == -1) { // If the isn't in the private conversation list, add the user to it PrivateMessageInfo pmInfo = new PrivateMessageInfo(); pmInfo.UserName = sender; pmInfo.Messages.Add(new MessageInfo(cPmOtherUserColor, message)); pmInfo.IsSelfSent.Add(false); CnCNetData.PMInfos.Add(pmInfo); } else { // If we've talked with the user before, just add the message itself to the list of messages // we've had with that user CnCNetData.PMInfos[index].Messages.Add(new MessageInfo(cPmOtherUserColor, message)); CnCNetData.PMInfos[index].IsSelfSent.Add(false); } if (!CnCNetData.isPMWindowOpen) { if (gameInProgress) { // If a game is in progress, tell the user that they received a private message // so they are aware of checking it out later MessageInfos[currentChannelId].Add(new MessageInfo(Color.White, "You've received a private message from " + sender)); AddChannelMessageToListBox(currentChannelId); } else { // If a game isn't in progress, open the PrivateMessageForm PrivateMessageForm pmWindow = new PrivateMessageForm(cPmOtherUserColor, sender); pmWindow.Show(); CnCNetData.isPMWindowOpen = true; } } }