Example #1
0
        /// <summary>
        /// Invokes the chat to prevent cross-threaded errors
        /// Chat goes by type
        /// </summary>
        /// <param name="richTextBox"></param>
        /// <param name="chatMessage"></param>
        /// <param name="msg"></param>
        private void InvokeChat(RichTextBox richTextBox, ChatMessage chatMessage = null, string msg = null)
        {
            if (chatMessage != null)
            {
                switch (chatMessage.Type)
                {
                    case ChatType.CHAT_TYPE_SYSTEM:
                        BeginInvoke(new MethodInvoker(delegate
                        {
                            if (!string.IsNullOrEmpty(chatMessage.Message))
                                richTextBox.AppendText(string.Format("{0} \n", WorldMgr.Server.ReceiveCMDSyntax()));
                            chatMessage.Message = null;
                            WorldMgr.Server.CmdList.Clear();
                        }));
                        break;
                    case ChatType.CHAT_TYPE_SAY:
                    case ChatType.CHAT_TYPE_YELL:
                        if (string.IsNullOrEmpty(chatMessage.Name))
                            return;

                        BeginInvoke(new MethodInvoker(delegate
                        {
                            if (!string.IsNullOrEmpty(chatMessage.Message))
                                richTextBox.AppendText(string.Format("[{0}] says: {1} \n", chatMessage.Name, chatMessage.Message));
                            chatMessage.Message = null;
                            chatMessage.Name = null;
                        }));
                        break;
                    case ChatType.CHAT_TYPE_CHANNEL:
                        if (string.IsNullOrEmpty(chatMessage.Name) || string.IsNullOrEmpty(chatMessage.ChannelName))
                            return;

                        BeginInvoke(new MethodInvoker(delegate
                        {
                            if (!string.IsNullOrEmpty(chatMessage.Message))
                                richTextBox.AppendText(string.Format("[{0}] [{1}]: {2} \n", chatMessage.ChannelName, chatMessage.Name, chatMessage.Message));
                            chatMessage.Message = null;
                        }));
                        break;

                }
            }

            if (!string.IsNullOrEmpty(msg))
            {
                BeginInvoke(new MethodInvoker(delegate
                {
                    richTextBox.AppendText(string.Format("{0} \n", msg));
                    msg = null;
                }));
            }
        }
Example #2
0
        void HandleServerChatMessage(PacketReader reader)
        {
            ChatType type = (ChatType)reader.ReadByte();
            Language language;
            UInt64 targetGUID;
            UInt64 targetGUIDOther;
            UInt32 messageLength;
            string channelName = null;
            string message;

            if ((type != ChatType.CHAT_TYPE_CHANNEL && type != ChatType.CHAT_TYPE_WHISPER))
                language = (Language)reader.ReadUInt32();
            else
                language = (Language)reader.ReadUInt32();

            targetGUID = reader.ReadUInt64();
            reader.ReadUInt32();

            switch (type)
            {
                case ChatType.CHAT_TYPE_CHANNEL:
                    channelName = reader.ReadCString();
                    break;
            }

            targetGUIDOther = reader.ReadUInt64();
            messageLength = reader.ReadUInt32();
            message = reader.ReadCString();
            reader.ReadByte();

            PlayerName result = PlayerNameList.Find(
                delegate(PlayerName playerName)
                {
                    return playerName.GUID == targetGUID;
                });

            if (type == ChatType.CHAT_TYPE_SYSTEM)
            {
                foreach (string syntax in message.Split('\n'))
                    if (!CmdList.Contains(syntax)) // Prevent double message
                        CmdList.Add(syntax);
            }

            if (result != null)
            {
                QueryChatMessage.Type = type;
                QueryChatMessage.Message = message;
                QueryChatMessage.Name = result.Name;
                if (channelName != null)
                    QueryChatMessage.ChannelName = channelName;
                ReceiveMsg = QueryChatMessage;
            }
            else
            {
                QueryChatMessage.Type = type;
                QueryChatMessage.Message = message;
                if (channelName != null)
                    QueryChatMessage.ChannelName = channelName;
            }

            if (targetGUID > 0)
            {
                PacketWriter writer = new PacketWriter(Opcodes.CMSG_NAME_QUERY);
                writer.Write(targetGUID);
                Send(writer);
            }
        }