public bool DoStep(NetworkClient networkClient, GameClient client) { DateTime now = DateTime.Now; ChatMessage[] outChatMessages = _outChatMessages.Where(cm => cm.MessageTime <= now ).ToArray(); if (outChatMessages.Length > 0) { foreach (ChatMessage chatMessage in outChatMessages) { _outChatMessages.Remove(chatMessage); //1: From, 2: To, 3: Type, 4: Message string message = Packet.BuildPacket(FromClient.CHAT_MESSAGE, Chat.POST, client.Login, chatMessage.Sender, chatMessage.Type, chatMessage.Message); networkClient.SendChatData(message); //Play notification for private message _soundPlayer.Play(); //Out chat message string logMessage = string.Format("[{0}] {1} [{2}] {3}", client.Login, chatMessage.Type == ChatMessageType.Pivate ? "private" : "to", chatMessage.Sender, chatMessage.Message); networkClient.OutChatMessage(logMessage); } return true; } return false; }
public bool DoStep(NetworkClient networkClient, GameClient client) { Packet[] packets = networkClient.InputQueue.PopAll(FromServer.CHAT_MESSAGE); if (!networkClient.OutChatMessages || packets.Length == 0) { return false; } foreach (Packet packet in packets) { //Get chat message data string messageData = packet["@text"]; if (string.IsNullOrEmpty(messageData) || packet["@html"] == "1") { continue; } //Get sender name string sender = _regexChatSender.Match(messageData).Groups["SENDER"].Value; //Check if the message is private or personal bool isPrivateMessage = false, isPersonalMessage = false; MatchCollection matchesUsers = _regexChatUsers.Matches(messageData); foreach (Match matchUser in matchesUsers) { string user = matchUser.Groups["USER"].Value; if (user.Equals(client.Login, StringComparison.InvariantCultureIgnoreCase)) { isPrivateMessage |= matchUser.Groups["PRIVATE"].Success; isPersonalMessage |= matchUser.Groups["PERSONAL"].Success; } } //Out only private or personal messages if (isPrivateMessage || isPersonalMessage) { //Check if the message has more than one recipients bool isMultiUserMessage = matchesUsers.Count > 1; //Play notification for private message if (isPrivateMessage) { _soundPlayer.Play(); } //Get chat message content string message = _regexChatMessage.Match(messageData).Groups["MESSAGE"].Value; //Get full chat message content string fullMessage = _regexChatFullMessage.Match(messageData).Groups["MESSAGE"].Value; //Out full incoming chat message networkClient.OutChatMessage(fullMessage); //Post this message to the chat bot GameSystemStep_ChatBot.AppendIncomingMessage(sender, isPrivateMessage, isPersonalMessage, isMultiUserMessage, message); } } return true; }