Example #1
0
 public ChatMessage(ChatMessageType type, string message)
 {
     Type = type;
     Message = message;
     UserId = string.Empty;
     Timestamp = null;
 }
Example #2
0
 public ChatMessage(ChatMessageType type, string message, string userId, DateTime timestamp)
 {
     Type = type;
     Message = message;
     UserId = userId;
     Timestamp = timestamp;
 }
        public ChatMessage()
        {
            this.chatMessageType = ChatMessageType.SystemMessage;
            Variables = new List<InlineVariable>();
            Styles = new List<ChatStyle>();

            Clear(false);
        }
        public ChatMessage(ChatMessageType MessageType)
        {
            this.chatMessageType = MessageType;
            Variables = new List<InlineVariable>();
            Styles = new List<ChatStyle>();

            Clear(false);
        }
Example #5
0
 public static void BroadcastChat(McChatMessage message, ChatMessageType chattype, Player sender)
 {
     foreach (var lvl in LevelManager.GetLevels())
     {
         lvl.BroadcastChat(message, chattype, sender);
     }
     LevelManager.MainLevel.BroadcastChat(message, chattype, sender);
 }
Example #6
0
        public ChatMessage(DateTime time, ChatMessageType type, string nick, string message)
        {
            Time = time;
            Type = type;
            Nick = nick;
            Message = message;

            UID = Interlocked.Increment(ref nextUID).ToString();
        }
 public ChatMessage Add(string sender, ChatMessageType type, 
     ChatMessageDirection direction, string message)
 {
     ChatMessage chatMessage = new ChatMessage(sender, type,
         direction,  message, this);
     Messages.Add(chatMessage);
     LastUpdateTime = DateTime.Now;
     return chatMessage;
 }
 public ParsedChatTextInterceptEventArgs(string rawText, int target, int color, string source, Util.ChatChannels channel, ChatMessageType messageType)
 {
     this.RawText = rawText;
     this.Target = target;
     this.Color = color;
     this.Source = source;
     this.Channel = channel;
     this.MessageType = messageType;
 }
Example #9
0
 public ChatMessage(string sender, ChatMessageType type,
     ChatMessageDirection direction, string message,
     ChatBotConversation conversation)
 {
     Sender = sender;
     Type = type;
     Direction = direction;
     Message = message;
     Conversation = conversation;
     MessageTime = direction == ChatMessageDirection.In
         ? DateTime.Now
         : DateTime.Now.AddSeconds(message.Length / 2 + 5);
 }
        public ChatMessage(
            ChatMessageType MessageType, 
            LockingDictionary<uint, string> StringResources, 
            uint ResourceID, 
            List<InlineVariable> Variables,
            List<ChatStyle> Styles)
        {
            this.chatMessageType = MessageType;
            this.stringResources = StringResources;
            this.Variables = Variables;
            this.Styles = Styles;

            this.resourceID = ResourceID;
        }
Example #11
0
        /// <summary>
        /// Indicates whether a ChatMessageType is supposed to be used by NPCs.
        /// </summary>
        /// <returns>
        /// true, if the type is supposed to be used by NPCs; otherwise, false.
        /// </returns>
        public static bool IsNPCMessageType(ChatMessageType type)
        {
            switch (type)
            {
                case ChatMessageType.MonsterSay:
                case ChatMessageType.MonsterParty:
                case ChatMessageType.MonsterYell:
                case ChatMessageType.MonsterWhisper:
                case ChatMessageType.MonsterEmote:
                case ChatMessageType.RaidBossWhisper:
                case ChatMessageType.RaidBossEmote:
                    return true;
            }

            return false;
        }
Example #12
0
        public PSMessageChat(ChatMessageType type, ChatMessageLanguage language, ulong GUID, string message, string channelName = null)
            : base(WorldOpcodes.SMSG_MESSAGECHAT)
        {
            this.Write((byte)type);
            this.Write((uint)language);

            if (type == ChatMessageType.CHAT_MSG_CHANNEL)
            {
                this.Write(Encoding.UTF8.GetBytes(channelName + '\0'));
                this.Write((uint)0);
            }

            this.Write((ulong)GUID);

            if (type == ChatMessageType.CHAT_MSG_SAY || type == ChatMessageType.CHAT_MSG_YELL
                || type == ChatMessageType.CHAT_MSG_PARTY)
            {
                this.Write(GUID);
            }

            this.Write((uint)message.Length + 1);
            this.Write(Encoding.UTF8.GetBytes(message + '\0'));
            this.Write((byte)0);
        }
Example #13
0
 public ChatMessage(string message, ChatMessageType type)
 {
     Message = message;
     Type = type;
 }
Example #14
0
 internal ChatSendingEventArgs([NotNull] Player player,
                               [NotNull] string message,
                               [NotNull] string formattedMessage,
                               ChatMessageType messageType,
                               [NotNull] IEnumerable<Player> recipientList) {
     Player = player;
     Message = message;
     MessageType = messageType;
     RecipientList = recipientList;
     FormattedMessage = formattedMessage;
 }
Example #15
0
        /// <summary>
        /// Changes properties based on a known StyleChar
        /// </summary>
        /// <param name="StyleCharacter"></param>
        /// <param name="MessageType"></param>
        public void ProcessStyleCharacter(char StyleCharacter, ChatMessageType MessageType)
        {
            switch (StyleCharacter)
            {
                // colors
                case STYLEBLACK:
                    Color = ChatColor.Black;
                    break;

                case STYLEWHITE:
                    Color = ChatColor.White;
                    break;

                case STYLERED:
                    Color = ChatColor.Red;
                    break;

                case STYLEGREEN:
                    Color = ChatColor.Green;
                    break;

                case STYLEBLUE:
                    Color = ChatColor.Blue;
                    break;

                case STYLEPURPLE:
                    Color = ChatColor.Purple;
                    break;

#if !VANILLA
                case STYLEBRIGHTRED:
                    Color = ChatColor.BrightRed;
                    break;

                case STYLELIGHTGREEN:
                    Color = ChatColor.LightGreen;
                    break;

                case STYLEYELLOW:
                    Color = ChatColor.Yellow;
                    break;

                case STYLEPINK:
                    Color = ChatColor.Pink;
                    break;

                case STYLEORANGE:
                    Color = ChatColor.Orange;
                    break;

                case STYLEAQUAMARINE:
                    Color = ChatColor.Aquamarine;
                    break;

                case STYLECYAN:
                    Color = ChatColor.Cyan;
                    break;

                case STYLETEAL:
                    Color = ChatColor.Teal;
                    break;

                case STYLEDARKGREY:
                    Color = ChatColor.DarkGrey;
                    break;

                case STYLEVIOLET:
                    Color = ChatColor.Violet;
                    break;

                case STYLEMAGENTA:
                    Color = ChatColor.Magenta;
                    break;
#endif

                // modifiers
                case STYLEBOLD:
                    IsBold = !IsBold;
                    break;

                case STYLECURSIVE:
                    IsCursive = !IsCursive;
                    break;
                
                case STYLEUNDERLINE:
                    IsUnderline = !IsUnderline;
                    break;

                case STYLENORMAL:
                    switch (MessageType)
                    {
                        case ChatMessageType.ObjectChatMessage:
                            Color = ChatColor.White;
                            break;

                        case ChatMessageType.ServerChatMessage:
                            Color = ChatColor.Purple;
                            break;

                        case ChatMessageType.SystemMessage:
                            Color = ChatColor.Blue;
                            break;

                        default:
                            Color = ChatColor.White;
                            break;
                    }
                    
                    IsBold = false;
                    IsCursive = false;
                    IsUnderline = false;
                    break;
            }
        }
Example #16
0
 public void SendMessage(ChatMessageType type, string message)
 {
     //调用发送信息的函数
     cs.SendMessage(type, message);
 }
Example #17
0
 public ChatMessage(string message, ChatMessageType type, float timestamp, int newlines)
 {
     this.message = message;
     this.type = type;
     this.timestamp = timestamp;
     this.newlines = newlines;
 }
Example #18
0
 void OnMessage( ChatMessageType chatmessagetype, string sender, string message )
 {
     //LogFile.WriteLine( "informclient: " + message );
     if( IMReceived != null )
     {
         IMReceived( this, new IMReceivedArgs( chatmessagetype, sender, message ) );
     }
 }
Example #19
0
 public ChatMessage(ChatMessageType type, IMessage msg)
 {
     this.Type     = type;
     this.Content  = ConvertHelper.Serialize(msg);
     this.DateTime = DateTimeHelper.GetUnixTick();
 }
Example #20
0
        public void HandleActionModifyCharacterSquelch(bool squelch, uint playerGuid, string playerName, ChatMessageType messageType)
        {
            //Console.WriteLine($"{Name}.HandleActionModifyCharacterSquelch({squelch}, {playerGuid:X8}, {playerName}, {messageType})");

            IPlayer player;

            if (playerGuid != 0)
            {
                player = PlayerManager.FindByGuid(new ObjectGuid(playerGuid));

                if (player == null)
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat("Couldn't find player to squelch.", ChatMessageType.Broadcast));
                    return;
                }
            }
            else
            {
                player = PlayerManager.FindByName(playerName);

                if (player == null)
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"{playerName} not found.", ChatMessageType.Broadcast));
                    return;
                }
            }

            if (player.Guid == Guid)
            {
                Session.Network.EnqueueSend(new GameMessageSystemChat("You can't squelch yourself!", ChatMessageType.Broadcast));
                return;
            }

            if (squelch)
            {
                if (Squelches.Characters.ContainsKey(player.Guid))
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"{player.Name} is already squelched.", ChatMessageType.Broadcast));
                    return;
                }

                Squelches.Characters.Add(player.Guid, new SquelchInfo(messageType, player.Name, false));

                Session.Network.EnqueueSend(new GameMessageSystemChat($"{player.Name} has been squelched.", ChatMessageType.Broadcast));
            }
            else
            {
                if (!Squelches.Characters.Remove(player.Guid))
                {
                    Session.Network.EnqueueSend(new GameMessageSystemChat($"{player.Name} is not squelched.", ChatMessageType.Broadcast));
                    return;
                }

                Session.Network.EnqueueSend(new GameMessageSystemChat($"{player.Name} has been unsquelched.", ChatMessageType.Broadcast));
            }

            Session.Network.EnqueueSend(new GameEventSetSquelchDB(Session, Squelches));
        }
Example #21
0
 public void HandleActionModifyGlobalSquelch(bool squelch, ChatMessageType messageType)
 {
     //Console.WriteLine($"{Name}.HandleActionModifyGlobalSquelch({squelch}, {messageType})");
 }
Example #22
0
 public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender, Client client = null, PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None)
 {
     return(new ChatMessage(senderName, text, type, sender, client ?? GameMain.NetworkMember?.ConnectedClients?.Find(c => c.Character != null && c.Character == sender), changeType));
 }
 public GameMessageHearDirectSpeech(WorldObject worldObject, string messageText, WorldObject targetObject, ChatMessageType chatMessageType)
     : base(GameMessageOpcode.HearDirectSpeech, GameMessageGroup.UIQueue)
 {
     Writer.WriteString16L(messageText);
     Writer.WriteString16L(worldObject.Name);
     Writer.WriteGuid(worldObject.Guid);
     Writer.WriteGuid(targetObject.Guid);
     Writer.Write((uint)chatMessageType);
     Writer.Write(0u); // secretFlags - doesn't seem to be used by the client
 }
Example #24
0
        public static void ServerRead(NetIncomingMessage msg, Client c)
        {
            c.KickAFKTimer = 0.0f;

            UInt16          ID   = msg.ReadUInt16();
            ChatMessageType type = (ChatMessageType)msg.ReadByte();
            string          txt  = "";

            int              orderIndex           = -1;
            Character        orderTargetCharacter = null;
            Entity           orderTargetEntity    = null;
            int              orderOptionIndex     = -1;
            OrderChatMessage orderMsg             = null;

            if (type == ChatMessageType.Order)
            {
                orderIndex           = msg.ReadByte();
                orderTargetCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
                orderTargetEntity    = Entity.FindEntityByID(msg.ReadUInt16()) as Entity;
                orderOptionIndex     = msg.ReadByte();

                if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
                {
                    DebugConsole.ThrowError("Invalid order message from client \"" + c.Name + "\" - order index out of bounds.");
                    return;
                }

                Order  order       = Order.PrefabList[orderIndex];
                string orderOption = orderOptionIndex < 0 || orderOptionIndex >= order.Options.Length ? "" : order.Options[orderOptionIndex];
                orderMsg = new OrderChatMessage(order, orderOption, orderTargetEntity, orderTargetCharacter, c.Character);
                txt      = orderMsg.Text;
            }
            else
            {
                txt = msg.ReadString() ?? "";
            }

            if (!NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID))
            {
                return;
            }

            c.LastSentChatMsgID = ID;

            if (txt.Length > MaxLength)
            {
                txt = txt.Substring(0, MaxLength);
            }

            c.LastSentChatMessages.Add(txt);
            if (c.LastSentChatMessages.Count > 10)
            {
                c.LastSentChatMessages.RemoveRange(0, c.LastSentChatMessages.Count - 10);
            }

            float similarity = 0.0f;

            //don't do message similarity checks on order messages
            if (orderMsg == null)
            {
                for (int i = 0; i < c.LastSentChatMessages.Count; i++)
                {
                    float closeFactor = 1.0f / (c.LastSentChatMessages.Count - i);
                    if (string.IsNullOrEmpty(txt))
                    {
                        similarity += closeFactor;
                    }
                    else
                    {
                        int levenshteinDist = ToolBox.LevenshteinDistance(txt, c.LastSentChatMessages[i]);
                        similarity += Math.Max((txt.Length - levenshteinDist) / (float)txt.Length * closeFactor, 0.0f);
                    }
                }
            }

            bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection;

            if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner)
            {
                GameMain.Server.KarmaManager.OnSpamFilterTriggered(c);

                c.ChatSpamCount++;
                if (c.ChatSpamCount > 3)
                {
                    //kick for spamming too much
                    GameMain.Server.KickClient(c, TextManager.Get("SpamFilterKicked"));
                }
                else
                {
                    ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                    c.ChatSpamTimer = 10.0f;
                    GameMain.Server.SendDirectChatMessage(denyMsg, c);
                }
                return;
            }

            c.ChatSpamSpeed += similarity + 0.5f;

            if (c.ChatSpamTimer > 0.0f && !isOwner)
            {
                ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                c.ChatSpamTimer = 10.0f;
                GameMain.Server.SendDirectChatMessage(denyMsg, c);
                return;
            }

            if (type == ChatMessageType.Order)
            {
                if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead)
                {
                    return;
                }

                ChatMessageType messageType = CanUseRadio(orderMsg.Sender) ? ChatMessageType.Radio : ChatMessageType.Default;
                if (orderMsg.Order.TargetAllCharacters)
                {
                    //do nothing
                }
                else if (orderTargetCharacter != null)
                {
                    orderTargetCharacter.SetOrder(
                        new Order(orderMsg.Order.Prefab, orderTargetEntity, (orderTargetEntity as Item)?.Components.FirstOrDefault(ic => ic.GetType() == orderMsg.Order.ItemComponentType)),
                        orderMsg.OrderOption, orderMsg.Sender);
                }

                GameMain.Server.SendOrderChatMessage(orderMsg);
            }
            else
            {
                GameMain.Server.SendChatMessage(txt, null, c);
            }
        }
 public static ChatMessage Create(string senderName, string text, ChatMessageType type, Character sender)
 {
     return(new ChatMessage(senderName, text, type, sender));
 }
Example #26
0
 public GameMessageCreatureMessage(string messageText, string senderName, uint senderID, ChatMessageType chatMessageType) : base(GameMessageOpcode.CreatureMessage)
 {
     Writer.WriteString16L(messageText);
     Writer.WriteString16L(senderName);
     Writer.Write(senderID);
     Writer.Write((uint)chatMessageType);
 }
        private void ReadFromStreamHandler(StreamHandler Reader, WowOpcodes opcode)
        {
            GameMasterMessage = (opcode == WowOpcodes.SMSG_GM_MESSAGECHAT);

            m_type = (ChatMessageType)Reader.ReadByte();
            if (m_type == ChatMessageType.Addon2)
            {
                m_type = ChatMessageType.Addon;
            }

            m_language      = (Language)Reader.ReadUInt32();
            m_senderGUID    = Reader.ReadGuid();
            m_unknownUInt32 = Reader.ReadUInt32();

            switch (m_type)
            {
            case ChatMessageType.MonsterSay:
            case ChatMessageType.MonsterParty:
            case ChatMessageType.MonsterYell:
            case ChatMessageType.MonsterWhisper:
            case ChatMessageType.MonsterEmote:
            case ChatMessageType.BattleNet:
            case ChatMessageType.RaidBossEmote:
            case ChatMessageType.RaidBossWhisper:
                Reader.Skip(4);
                m_senderName = Reader.ReadCString();
                m_targetGUID = Reader.ReadGuid();
                if (!m_targetGUID.IsEmpty &&
                    !m_targetGUID.IsPlayer &&
                    !m_targetGUID.IsPet)
                {
                    Reader.Skip(4);
                    m_targetName = Reader.ReadCString();
                }
                if (m_language == Language.Addon)
                {
                    m_addonPrefix = Reader.ReadCString();
                }
                Reader.Skip(4);
                m_text  = Reader.ReadCString();
                m_flags = (ChatMessageFlags)Reader.ReadByte();
                if (m_type == ChatMessageType.RaidBossEmote || m_type == ChatMessageType.RaidBossWhisper)
                {
                    m_displayTime  = Reader.ReadSingle();
                    m_suspendEvent = Reader.ReadBoolean();
                }
                break;

            case ChatMessageType.BGSystemNeutral:
            case ChatMessageType.BGSystemAlliance:
            case ChatMessageType.BGSystemHorde:
                m_targetGUID = Reader.ReadGuid();
                if (!m_targetGUID.IsEmpty &&
                    !m_targetGUID.IsPlayer)
                {
                    Reader.Skip(4);
                    m_targetName = Reader.ReadCString();
                }
                if (m_language == Language.Addon)
                {
                    m_addonPrefix = Reader.ReadCString();
                }
                Reader.Skip(4);
                m_text  = Reader.ReadCString();
                m_flags = (ChatMessageFlags)Reader.ReadByte();
                break;

            case ChatMessageType.Achievement:
            case ChatMessageType.GuildAchievement:
                m_targetGUID = Reader.ReadGuid();
                if (m_language == Language.Addon)
                {
                    m_addonPrefix = Reader.ReadCString();
                }
                Reader.Skip(4);
                m_text          = Reader.ReadCString();
                m_flags         = (ChatMessageFlags)Reader.ReadByte();
                m_achievementId = Reader.ReadUInt32();
                break;

            case ChatMessageType.WhisperForeign:
                Reader.Skip(4);
                m_senderName = Reader.ReadCString();
                m_targetGUID = Reader.ReadGuid();
                if (m_language == Language.Addon)
                {
                    m_addonPrefix = Reader.ReadCString();
                }
                Reader.Skip(4);
                m_text  = Reader.ReadCString();
                m_flags = (ChatMessageFlags)Reader.ReadByte();
                break;

            default:
                if (GameMasterMessage)
                {
                    Reader.Skip(4);
                    m_senderName = Reader.ReadCString();
                }
                if (m_type == ChatMessageType.Channel)
                {
                    m_channel = Reader.ReadCString();
                }
                m_targetGUID = Reader.ReadGuid();
                if (m_language == Language.Addon)
                {
                    m_addonPrefix = Reader.ReadCString();
                }
                Reader.Skip(4);
                m_text  = Reader.ReadCString();
                m_flags = (ChatMessageFlags)Reader.ReadByte();
                break;
            }
        }
Example #28
0
        public static async Task <ChatMessage> PostChatMessageAsync(MainRepository repo, ChatMessage param, Character chara, string ip, ChatMessageType type, uint typeData = default, uint typeData2 = default)
        {
            ChatMessage message;

            var reinforcement = await repo.Reinforcement.GetByCharacterIdAsync(chara.Id);

            message = new ChatMessage
            {
                CharacterId        = chara.Id,
                Character          = new CharacterChatData(chara, reinforcement.FirstOrDefault(r => r.Status == ReinforcementStatus.Active)),
                CharacterCountryId = chara.CountryId,
                Posted             = DateTime.Now,
                Message            = param.Message.TrimEnd(),
                IpAddress          = ip,
                Type        = type,
                TypeData    = typeData,
                TypeData2   = typeData2,
                ImageBase64 = param.ImageBase64,
            };
            if (param.CharacterIconId > 0)
            {
                message.CharacterIconId = param.CharacterIconId;
                message.CharacterIcon   = await repo.Character.GetCharacterIconByIdAsync(message.CharacterIconId);
            }
            else
            {
                var icons = await repo.Character.GetCharacterAllIconsAsync(chara.Id);

                var icon = icons.FirstOrDefault(i => i.IsMain) ?? icons.FirstOrDefault();
                if (icon == null)
                {
                    ErrorCode.CharacterIconNotFoundError.Throw();
                }
                message.CharacterIconId = icon.Id;
                message.CharacterIcon   = icon;
            }

            if (message.Type == ChatMessageType.Private || message.Type == ChatMessageType.Promotion || message.Type == ChatMessageType.PromotionRefused || message.Type == ChatMessageType.PromotionAccepted || message.Type == ChatMessageType.PromotionDenied)
            {
                var receiver = await repo.Character.GetByIdAsync(message.TypeData2).GetOrErrorAsync(ErrorCode.CharacterNotFoundError);

                message.ReceiverName = receiver.Name;
            }
            else if (message.Type == ChatMessageType.OtherCountry)
            {
                var receiver = await repo.Country.GetByIdAsync(message.TypeData2).GetOrErrorAsync(ErrorCode.CountryNotFoundError);

                message.ReceiverName = receiver.Name;
            }

            await repo.ChatMessage.AddMessageAsync(message);

            await repo.SaveChangesAsync();

            if (!string.IsNullOrEmpty(message.ImageBase64))
            {
                try
                {
                    await Task.Run(async() => await UploadImageAsync(message));
                }
                catch (Exception ex)
                {
                    repo.ChatMessage.RemoveMessage(message);
                    await repo.SaveChangesAsync();

                    ErrorCode.UploadImageFailedError.Throw(ex);
                }
            }

            return(message);
        }
        public string Format(string formatName, string message, ChatMessageType chatMessageType, int serverId = -1, string color = "")
        {
            if (char.IsLower(message.First()))
            {
                message = $"{char.ToUpper(message[0])}{message.Substring(1)}";
            }

            switch (chatMessageType)
            {
            case ChatMessageType.Normal:
                message = $"{formatName} mówi: {message}";
                color   = "#FFFFFF";
                break;

            case ChatMessageType.Quiet:
                message = $"{formatName} szepcze: {message}";
                color   = "#FFFFFF";
                break;

            case ChatMessageType.Loud:
                message = $"{formatName} krzyczy: {message}!";
                color   = "#FFFFFF";
                break;

            case ChatMessageType.Me:
                message = $"** {formatName} {message}";
                color   = "#C2A2DA";
                break;

            case ChatMessageType.ServerMe:
                message = $"* {formatName} {message}";
                color   = "#C2A2DA";
                break;

            case ChatMessageType.Do:
                message = $"** {message} (( {formatName} )) **";
                color   = "#847DB7";
                break;

            case ChatMessageType.PhoneOthers:
                message = $"{formatName} mówi(telefon): {message}";
                color   = "#FFFFFF";
                break;

            case ChatMessageType.ServerInfo:
                message = $"[INFO] ~w~ {message}";
                color   = "#6A9828";
                break;

            case ChatMessageType.ServerDo:
                message = $"** {message} **";
                color   = "#847DB7";
                break;

            case ChatMessageType.Megaphone:
                message = $"{formatName} \U0001F4E3 {message}";
                color   = "#FFDB00";
                break;

            case ChatMessageType.Phone:
                color = "#FFDB00";
                break;

            case ChatMessageType.Ooc:
                message = $"(( [{serverId}] {formatName} {message} ))";
                color   = "#CCCCCC";
                break;

            case ChatMessageType.GroupOoc:
                message = $"[{serverId}] {formatName}: {message}";
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(chatMessageType), chatMessageType, null);
            }

            if (message.Last() != '.' &&
                message.Last() != '!' &&
                message.Last() != '?')
            {
                message += '.';
            }

            return($"!{{{color}}} {message}");
        }
Example #30
0
        internal static void OnMessageChat(RealmServerSession session, PacketReader handler)
        {
            ChatMessageType     msgType     = (ChatMessageType)handler.ReadUInt32();
            ChatMessageLanguage msgLanguage = (ChatMessageLanguage)handler.ReadUInt32();

            string toUser  = null;
            string channel = null;

            if (msgType == ChatMessageType.CHAT_MSG_CHANNEL)
            {
                channel = handler.ReadCString();
            }

            if (msgType == ChatMessageType.CHAT_MSG_WHISPER)
            {
                toUser = handler.ReadCString();
            }

            string message = handler.ReadCString();

            // Call Commands
            new CommandsHelper(session, message);

            switch ((ChatMessageType)msgType)
            {
            case ChatMessageType.CHAT_MSG_SAY:
            case ChatMessageType.CHAT_MSG_YELL:
            case ChatMessageType.CHAT_MSG_EMOTE:
                session.SendPacket(new SmsgMessagechat(msgType, ChatMessageLanguage.LANG_UNIVERSAL, (ulong)session.Character.Id, message));
                session.Entity.KnownPlayers.ForEach(s => s.Session.SendPacket(new SmsgMessagechat(msgType, ChatMessageLanguage.LANG_UNIVERSAL, (ulong)session.Character.Id, message)));
                break;

            case ChatMessageType.CHAT_MSG_WHISPER:
                try
                {
                    RealmServerSession remoteSession = RealmServerSession.GetSessionByPlayerName(toUser);

                    // Check if player is the same faction?

                    // Send packet
                    session.SendPacket(new SmsgMessagechat(ChatMessageType.CHAT_MSG_WHISPER_INFORM,
                                                           ChatMessageLanguage.LANG_UNIVERSAL, (ulong)remoteSession.Character.Id, message));
                    remoteSession.SendPacket(new SmsgMessagechat(msgType, ChatMessageLanguage.LANG_UNIVERSAL,
                                                                 (ulong)session.Character.Id, message));
                }
                catch (Exception e)
                {
                    // Envia mensagem que nao achou
                    Console.WriteLine($@"naoa chei nada {e.Message}");
                }
                break;

            default:
                Console.WriteLine($@"veio aqui algo [{msgType}]");
                session.SendPacket(new SmsgMessagechat(msgType, ChatMessageLanguage.LANG_UNIVERSAL, (ulong)session.Character.Id, message));
                break;
            }

            /*
             *  2 - Raid
             *  3 - Guild
             *  4 - Officer
             *  6 - Whisper From
             *  7 - Whisper To
             *  8 - Emote
             *  9 - nao sei
             *  10 - Server
             *  17 - nao sei  cinza
             *  20 - AFK
             *  21 - DND
             *  22 - Ignore
             *  23 - nao sei azul
             *  24 - verde
             *              Write((byte) type);
             *              Write((uint) msgLanguage);
             *              Write(characterId);
             *              Write((uint) message.Length + 1);
             *              Write(Encoding.UTF8.GetBytes(message + '\0'));
             *              Write((byte)0); // Flag????
             *
             *  13 - ti´po emote
             *  26 - whispers: algo
             *              Write((byte) type);
             *              Write((uint) msgLanguage);
             *              Write((uint) 0);
             *              Write(characterId);
             *              Write((uint) message.Length + 1);
             *              Write(Encoding.UTF8.GetBytes(message + '\0'));
             *              Write((byte) 0); // 0 = normal / 1 = AFK / 2 = DND / 3 = GM
             *
             *  11 - npc Says
             *  12 - npc Yells
             *              Write((byte) type);
             *              Write((uint) msgLanguage);
             *              Write((uint) 0);
             *              Write(characterId);
             *              Write(characterId);
             *              Write((uint) message.Length + 1);
             *              Write(Encoding.UTF8.GetBytes(message + '\0'));
             *              Write((byte) 0); // 0 = normal / 1 = AFK / 2 = DND / 3 = GM
             *
             *  0- say
             *  1 - party
             *  5 - yell
             *              Write((byte) type);
             *              Write((uint) msgLanguage);
             *              Write(characterId);
             *              Write(characterId);
             *              Write((uint) message.Length + 1);
             *              Write(Encoding.UTF8.GetBytes(message + '\0'));
             *              Write((byte) 0); // 0 = normal / 1 = AFK / 2 = DND / 3 = GM
             */
        }
Example #31
0
 /// <inheritdoc/>
 public void ChatMessage(string message, string sender, ChatMessageType type)
 {
     this.player.Connection?.SendChatMessage(ConvertChatMessageType(type), sender, message);
 }
Example #32
0
        public static void ServerRead(IReadMessage msg, Client c)
        {
            c.KickAFKTimer = 0.0f;

            UInt16          ID   = msg.ReadUInt16();
            ChatMessageType type = (ChatMessageType)msg.ReadByte();
            string          txt;

            Character        orderTargetCharacter = null;
            Entity           orderTargetEntity    = null;
            OrderChatMessage orderMsg             = null;
            OrderTarget      orderTargetPosition  = null;

            Order.OrderTargetType orderTargetType = Order.OrderTargetType.Entity;
            int?wallSectionIndex = null;

            if (type == ChatMessageType.Order)
            {
                int orderIndex = msg.ReadByte();
                orderTargetCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
                orderTargetEntity    = Entity.FindEntityByID(msg.ReadUInt16()) as Entity;
                int orderOptionIndex = msg.ReadByte();
                orderTargetType = (Order.OrderTargetType)msg.ReadByte();
                if (msg.ReadBoolean())
                {
                    var x    = msg.ReadSingle();
                    var y    = msg.ReadSingle();
                    var hull = Entity.FindEntityByID(msg.ReadUInt16()) as Hull;
                    orderTargetPosition = new OrderTarget(new Vector2(x, y), hull, true);
                }
                else if (orderTargetType == Order.OrderTargetType.WallSection)
                {
                    wallSectionIndex = msg.ReadByte();
                }

                if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
                {
                    DebugConsole.ThrowError($"Invalid order message from client \"{c.Name}\" - order index out of bounds ({orderIndex}, {orderOptionIndex}).");
                    if (NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID))
                    {
                        c.LastSentChatMsgID = ID;
                    }
                    return;
                }

                Order  orderPrefab = Order.PrefabList[orderIndex];
                string orderOption = orderOptionIndex < 0 || orderOptionIndex >= orderPrefab.Options.Length ? "" : orderPrefab.Options[orderOptionIndex];
                orderMsg = new OrderChatMessage(orderPrefab, orderOption, orderTargetPosition ?? orderTargetEntity as ISpatialEntity, orderTargetCharacter, c.Character)
                {
                    WallSectionIndex = wallSectionIndex
                };
                txt = orderMsg.Text;
            }
            else
            {
                txt = msg.ReadString() ?? "";
            }

            if (!NetIdUtils.IdMoreRecent(ID, c.LastSentChatMsgID))
            {
                return;
            }

            c.LastSentChatMsgID = ID;

            if (txt.Length > MaxLength)
            {
                txt = txt.Substring(0, MaxLength);
            }

            c.LastSentChatMessages.Add(txt);
            if (c.LastSentChatMessages.Count > 10)
            {
                c.LastSentChatMessages.RemoveRange(0, c.LastSentChatMessages.Count - 10);
            }

            float similarity = 0.0f;

            for (int i = 0; i < c.LastSentChatMessages.Count; i++)
            {
                float closeFactor = 1.0f / (c.LastSentChatMessages.Count - i);

                if (string.IsNullOrEmpty(txt))
                {
                    similarity += closeFactor;
                }
                else
                {
                    int levenshteinDist = ToolBox.LevenshteinDistance(txt, c.LastSentChatMessages[i]);
                    similarity += Math.Max((txt.Length - levenshteinDist) / (float)txt.Length * closeFactor, 0.0f);
                }
            }
            //order/report messages can be sent a little faster than normal messages without triggering the spam filter
            if (orderMsg != null)
            {
                similarity *= 0.25f;
            }

            bool isOwner = GameMain.Server.OwnerConnection != null && c.Connection == GameMain.Server.OwnerConnection;

            if (similarity + c.ChatSpamSpeed > 5.0f && !isOwner)
            {
                GameMain.Server.KarmaManager.OnSpamFilterTriggered(c);

                c.ChatSpamCount++;
                if (c.ChatSpamCount > 3)
                {
                    //kick for spamming too much
                    GameMain.Server.KickClient(c, TextManager.Get("SpamFilterKicked"));
                }
                else
                {
                    ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                    c.ChatSpamTimer = 10.0f;
                    GameMain.Server.SendDirectChatMessage(denyMsg, c);
                }
                return;
            }

            c.ChatSpamSpeed += similarity + 0.5f;

            if (c.ChatSpamTimer > 0.0f && !isOwner)
            {
                ChatMessage denyMsg = Create("", TextManager.Get("SpamFilterBlocked"), ChatMessageType.Server, null);
                c.ChatSpamTimer = 10.0f;
                GameMain.Server.SendDirectChatMessage(denyMsg, c);
                return;
            }

            if (type == ChatMessageType.Order)
            {
                if (c.Character == null || c.Character.SpeechImpediment >= 100.0f || c.Character.IsDead)
                {
                    return;
                }
                Order order = null;
                if (orderMsg.Order.IsReport)
                {
                    HumanAIController.ReportProblem(orderMsg.Sender, orderMsg.Order);
                }
                else if (orderTargetCharacter != null && !orderMsg.Order.TargetAllCharacters)
                {
                    switch (orderTargetType)
                    {
                    case Order.OrderTargetType.Entity:
                        order = new Order(orderMsg.Order.Prefab, orderTargetEntity, orderMsg.Order.Prefab?.GetTargetItemComponent(orderTargetEntity as Item), orderGiver: orderMsg.Sender);
                        break;

                    case Order.OrderTargetType.Position:
                        order = new Order(orderMsg.Order.Prefab, orderTargetPosition, orderGiver: orderMsg.Sender);
                        break;
                    }
                    if (order != null)
                    {
                        orderTargetCharacter.SetOrder(order, orderMsg.OrderOption, orderMsg.Sender);
                    }
                }
                else if (orderMsg.Order.IsIgnoreOrder)
                {
                    switch (orderTargetType)
                    {
                    case Order.OrderTargetType.Entity:
                        (orderTargetEntity as MapEntity)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
                        break;

                    case Order.OrderTargetType.WallSection:
                        if (!wallSectionIndex.HasValue)
                        {
                            break;
                        }
                        (orderTargetEntity as Structure)?.GetSection(wallSectionIndex.Value)?.SetIgnoreByAI(orderMsg.Order.Identifier == "ignorethis");
                        break;
                    }
                }
                GameMain.Server.SendOrderChatMessage(orderMsg);
            }
            else
            {
                GameMain.Server.SendChatMessage(txt, null, c);
            }
        }
Example #33
0
 public ChatMessage(ushort ownerConId, int unk, string senderName, string msg, ChatMessageType type, ChatMessageTitle govType, int unk2)
 {
     OwnerConId  = ownerConId;
     _unk        = unk;
     _senderName = senderName;
     _msg        = msg;
     _type       = type;
     _govType    = govType;
     _unk2       = unk2;
 }
Example #34
0
 public static void SendMessage(string msg, ChatMessageType messageType = ChatMessageType.Server, Client sender = null, Character character = null)
 {
     GameMain.Server.SendChatMessage(msg, messageType, sender, character);
 }
Example #35
0
        public static void ClientRead(IReadMessage msg)
        {
            UInt16                     ID         = msg.ReadUInt16();
            ChatMessageType            type       = (ChatMessageType)msg.ReadByte();
            PlayerConnectionChangeType changeType = PlayerConnectionChangeType.None;
            string                     txt        = "";

            if (type != ChatMessageType.Order)
            {
                changeType = (PlayerConnectionChangeType)msg.ReadByte();
                txt        = msg.ReadString();
            }

            string    senderName         = msg.ReadString();
            Character senderCharacter    = null;
            bool      hasSenderCharacter = msg.ReadBoolean();

            if (hasSenderCharacter)
            {
                senderCharacter = Entity.FindEntityByID(msg.ReadUInt16()) as Character;
                if (senderCharacter != null)
                {
                    senderName = senderCharacter.Name;
                }
            }

            if (type == ChatMessageType.ServerMessageBox)
            {
                txt = TextManager.GetServerMessage(txt);
            }
            else if (type == ChatMessageType.Order)
            {
                int       orderIndex        = msg.ReadByte();
                UInt16    targetCharacterID = msg.ReadUInt16();
                Character targetCharacter   = Entity.FindEntityByID(targetCharacterID) as Character;
                Entity    targetEntity      = Entity.FindEntityByID(msg.ReadUInt16());
                int       optionIndex       = msg.ReadByte();

                Order order = null;
                if (orderIndex < 0 || orderIndex >= Order.PrefabList.Count)
                {
                    DebugConsole.ThrowError("Invalid order message - order index out of bounds.");
                    if (NetIdUtils.IdMoreRecent(ID, LastID))
                    {
                        LastID = ID;
                    }
                    return;
                }
                else
                {
                    order = Order.PrefabList[orderIndex];
                }
                string orderOption = "";
                if (optionIndex >= 0 && optionIndex < order.Options.Length)
                {
                    orderOption = order.Options[optionIndex];
                }
                txt = order.GetChatMessage(targetCharacter?.Name, senderCharacter?.CurrentHull?.DisplayName, givingOrderToSelf: targetCharacter == senderCharacter, orderOption: orderOption);

                if (GameMain.Client.GameStarted && Screen.Selected == GameMain.GameScreen)
                {
                    if (order.TargetAllCharacters)
                    {
                        GameMain.GameSession?.CrewManager?.AddOrder(
                            new Order(order.Prefab, targetEntity, (targetEntity as Item)?.Components.FirstOrDefault(ic => ic.GetType() == order.ItemComponentType), orderGiver: senderCharacter),
                            order.Prefab.FadeOutTime);
                    }
                    else if (targetCharacter != null)
                    {
                        targetCharacter.SetOrder(
                            new Order(order.Prefab, targetEntity, (targetEntity as Item)?.Components.FirstOrDefault(ic => ic.GetType() == order.ItemComponentType), orderGiver: senderCharacter),
                            orderOption, senderCharacter);
                    }
                }

                if (NetIdUtils.IdMoreRecent(ID, LastID))
                {
                    GameMain.Client.AddChatMessage(
                        new OrderChatMessage(order, orderOption, txt, targetEntity, targetCharacter, senderCharacter));
                    LastID = ID;
                }
                return;
            }

            if (NetIdUtils.IdMoreRecent(ID, LastID))
            {
                switch (type)
                {
                case ChatMessageType.MessageBox:
                case ChatMessageType.ServerMessageBox:
                    //only show the message box if the text differs from the text in the currently visible box
                    if ((GUIMessageBox.VisibleBox as GUIMessageBox)?.Text?.Text != txt)
                    {
                        new GUIMessageBox("", txt);
                    }
                    break;

                case ChatMessageType.Console:
                    DebugConsole.NewMessage(txt, MessageColor[(int)ChatMessageType.Console]);
                    break;

                case ChatMessageType.ServerLog:
                    if (!Enum.TryParse(senderName, out ServerLog.MessageType messageType))
                    {
                        return;
                    }
                    GameMain.Client.ServerSettings.ServerLog?.WriteLine(txt, messageType);
                    break;

                default:
                    GameMain.Client.AddChatMessage(txt, type, senderName, senderCharacter, changeType);
                    break;
                }
                LastID = ID;
            }
        }
 public ParsedChatTextInterceptEventArgs(ChatTextInterceptEventArgs eventArgs, string source, Util.ChatChannels channel, ChatMessageType messageType)
     : this(eventArgs.Text, eventArgs.Target, eventArgs.Color, source, channel, messageType)
 {
 }
Example #37
0
        public void DoWorldBroadcast(string message, ChatMessageType messageType)
        {
            GameMessageSystemChat sysMessage = new GameMessageSystemChat(message, messageType);

            WorldManager.BroadcastToAll(sysMessage);
        }
Example #38
0
 /// <summary>
 /// Initializes a new instance of ChatMessage.
 /// </summary>
 /// <param name="type">Type of the current ChatMessage.</param>
 /// <param name="lang">Language of the current ChatMessage.</param>
 /// <param name="sender">Current ChatMessage's sender's GUID.</param>
 /// <param name="target">Current ChatMessage's target's GUID.</param>
 /// <param name="text">The actual text of the current ChatMessage.</param>
 public ServerChatMessage(ChatMessageType type, Language lang, WowGuid sender, WowGuid target, String text)
 {
     m_type = type;
     m_language = lang;
     m_senderGUID = sender;
     m_targetGUID = target;
     m_text = text;
 }
Example #39
0
        /// <summary>
        /// Returns a list of TextStyles for a given Text
        /// </summary>
        /// <param name="Text"></param>
        /// <param name="MessageType"></param>
        /// <returns></returns>
        public static List<ChatStyle> GetStyles(string Text, ChatMessageType MessageType)
        {
            // styles we will parse
            List<ChatStyle> list = new List<ChatStyle>();

            // the startcolor depends on messagetype
            ChatColor startColor;
            switch (MessageType)
            {
                case ChatMessageType.ServerChatMessage:
#if !VANILLA
                    startColor = ChatColor.Violet;
#else
                    startColor = ChatColor.Purple;
#endif
                    break;

                case ChatMessageType.SystemMessage:
                    startColor = ChatColor.Blue;
                    break;

                case ChatMessageType.ObjectChatMessage:
                default:
                    startColor = ChatColor.White;
                    break;
            }

            // first/default style
            ChatStyle style = new ChatStyle(0, 0, false, false, false, startColor);
            list.Add(style);
           
            // walk the characters up to the lastone-1
            for (int i = 0; i < Text.Length - 1; i++)
            {
                // check if this is an inline style
                if (IsInlineStyle(Text, i))
                {
                    // get the index of this new style in a string without inline styles
                    int index = GetIndexWithoutInlineStyle(Text, i);

                    // if this index is bigger than our last one
                    // we have a new style to create
                    if (index > style.StartIndex)
                    {
                        // set length in last style
                        style.Length = index - style.StartIndex;
                        
                        // create a new style definition
                        // use the existing one to start from
                        style = new ChatStyle(index, 0, style.IsBold, style.IsCursive, style.IsUnderline, style.Color);

                        // process this stylechar
                        style.ProcessStyleCharacter(Text[i + 1], MessageType);
                        list.Add(style);
                    }
                    else
                    {
                        // process this inline style in existing style
                        style.ProcessStyleCharacter(Text[i + 1], MessageType);
                    }

                    // skip the next character, we already processed it
                    i++;
                }
            }

            // set length in last style
            style.Length = GetIndexWithoutInlineStyle(Text, Text.Length) - style.StartIndex;

            return list;
        }
Example #40
0
 public void AddChatMessage(string message, ChatMessageType type, string senderName = "", Character senderCharacter = null)
 {
     AddChatMessage(ChatMessage.Create(senderName, message, type, senderCharacter));
 }
Example #41
0
 NSString GetReuseId(ChatMessageType msgType)
 {
     return msgType == ChatMessageType.Incoming ? IncomingCellId : OutgoingCellId;
 }
Example #42
0
 public void HandleActionWorldBroadcast(string message, ChatMessageType messageType)
 {
     ActionChain chain = new ActionChain();
     chain.AddAction(this, () => DoWorldBroadcast(message, messageType));
     chain.EnqueueChain();
 }
Example #43
0
            public static void SendDirectChatMessage(string sendername, string text, Character sender, ChatMessageType messageType = ChatMessageType.Private, Client client = null)
            {
                ChatMessage cm = ChatMessage.Create(sendername, text, messageType, sender, client);

                GameMain.Server.SendDirectChatMessage(cm, client);
            }
Example #44
0
 public ChatMessage(string message, ChatMessageType type, float timestamp)
 {
     this.message = message;
     this.type = type;
     this.timestamp = timestamp;
 }
Example #45
0
        public void addChatMessage(string chatString, ChatMessageType chatType, float timestamp)
        {
            string[] text = chatString.Split(' ');
            string textFull = "";
            string textLine = "";
            int newlines = 0;

            float curWidth = 0;
            for (int i = 0; i < text.Length; i++)
            {//each(string part in text){
                string part = text[i];
                if (i != text.Length - 1)
                    part += ' '; //Correct for lost spaces
                float incr = interfaceEngine.uiFont.MeasureString(part).X;
                curWidth += incr;
                if (curWidth > 1024 - 64) //Assume default resolution, unfortunately
                {
                    if (textLine.IndexOf(' ') < 0)
                    {
                        curWidth = 0;
                        textFull = textFull + "\n" + textLine;
                        textLine = "";
                    }
                    else
                    {
                        curWidth = incr;
                        textFull = textFull + "\n" + textLine;
                        textLine = part;
                    }
                    newlines++;
                }
                else
                {
                    textLine = textLine + part;
                }
            }
            if (textLine != "")
            {
                textFull += "\n" + textLine;
                newlines++;
            }

            if (textFull == "")
                textFull = chatString;

            ChatMessage chatMsg = new ChatMessage(textFull, chatType, 10,newlines);

            chatBuffer.Insert(0, chatMsg);
            chatFullBuffer.Insert(0, chatMsg);
            PlaySound(InfiniminerSound.ClickLow);
        }
Example #46
0
 public GameMessageSystemChat(string message, ChatMessageType chatMessageType)
     : base(GameMessageOpcode.ServerMessage, GameMessageGroup.Group09)
 {
     Writer.WriteString16L(message);
     Writer.Write((int)chatMessageType);
 }
Example #47
0
        private void ReadFromStreamHandler(StreamHandler Reader, WowOpcodes opcode)
        {
            GameMasterMessage = (opcode == WowOpcodes.SMSG_GM_MESSAGECHAT);

            m_type = (ChatMessageType)Reader.ReadByte();
            if (m_type == ChatMessageType.Addon2)
                m_type = ChatMessageType.Addon;

            m_language = (Language)Reader.ReadUInt32();
            m_senderGUID = Reader.ReadGuid();
            m_unknownUInt32 = Reader.ReadUInt32();

            switch (m_type)
            {
                case ChatMessageType.MonsterSay:
                case ChatMessageType.MonsterParty:
                case ChatMessageType.MonsterYell:
                case ChatMessageType.MonsterWhisper:
                case ChatMessageType.MonsterEmote:
                case ChatMessageType.BattleNet:
                case ChatMessageType.RaidBossEmote:
                case ChatMessageType.RaidBossWhisper:
                    Reader.Skip(4);
                    m_senderName = Reader.ReadCString();
                    m_targetGUID = Reader.ReadGuid();
                    if (!m_targetGUID.IsEmpty
                        && !m_targetGUID.IsPlayer
                        && !m_targetGUID.IsPet)
                    {
                        Reader.Skip(4);
                        m_targetName = Reader.ReadCString();
                    }
                    if (m_language == Language.Addon)
                        m_addonPrefix = Reader.ReadCString();
                    Reader.Skip(4);
                    m_text = Reader.ReadCString();
                    m_flags = (ChatMessageFlags)Reader.ReadByte();
                    if (m_type == ChatMessageType.RaidBossEmote || m_type == ChatMessageType.RaidBossWhisper)
                    {
                        m_displayTime = Reader.ReadSingle();
                        m_suspendEvent = Reader.ReadBoolean();
                    }
                    break;
                case ChatMessageType.BGSystemNeutral:
                case ChatMessageType.BGSystemAlliance:
                case ChatMessageType.BGSystemHorde:
                    m_targetGUID = Reader.ReadGuid();
                    if (!m_targetGUID.IsEmpty
                        && !m_targetGUID.IsPlayer)
                    {
                        Reader.Skip(4);
                        m_targetName = Reader.ReadCString();
                    }
                    if (m_language == Language.Addon)
                        m_addonPrefix = Reader.ReadCString();
                    Reader.Skip(4);
                    m_text = Reader.ReadCString();
                    m_flags = (ChatMessageFlags)Reader.ReadByte();
                    break;
                case ChatMessageType.Achievement:
                case ChatMessageType.GuildAchievement:
                    m_targetGUID = Reader.ReadGuid();
                    if (m_language == Language.Addon)
                        m_addonPrefix = Reader.ReadCString();
                    Reader.Skip(4);
                    m_text = Reader.ReadCString();
                    m_flags = (ChatMessageFlags)Reader.ReadByte();
                    m_achievementId = Reader.ReadUInt32();
                    break;
                case ChatMessageType.WhisperForeign:
                    Reader.Skip(4);
                    m_senderName = Reader.ReadCString();
                    m_targetGUID = Reader.ReadGuid();
                    if (m_language == Language.Addon)
                        m_addonPrefix = Reader.ReadCString();
                    Reader.Skip(4);
                    m_text = Reader.ReadCString();
                    m_flags = (ChatMessageFlags)Reader.ReadByte();
                    break;
                default:
                    if (GameMasterMessage)
                    {
                        Reader.Skip(4);
                        m_senderName = Reader.ReadCString();
                    }
                    if (m_type == ChatMessageType.Channel)
                        m_channel = Reader.ReadCString();
                    m_targetGUID = Reader.ReadGuid();
                    if (m_language == Language.Addon)
                        m_addonPrefix = Reader.ReadCString();
                    Reader.Skip(4);
                    m_text = Reader.ReadCString();
                    m_flags = (ChatMessageFlags)Reader.ReadByte();
                    break;
            }
        }
Example #48
0
 public ChatMessageCommand(Guid userId,
                           string command,
                           ChatMessageType messageType = ChatMessageType.COMMAND) : base(userId, messageType)
 {
     Command = command;
 }
        public unsafe ChatMessage(
            ChatMessageType MessageType, 
            LockingDictionary<uint, string> StringResources,
            ref byte* Buffer)
        {
            this.chatMessageType = MessageType;
            this.stringResources = StringResources;

            Variables = new List<InlineVariable>();
            Styles = new List<ChatStyle>();
            ReadFrom(ref Buffer);
        }
Example #50
0
 public IMReceivedArgs( ChatMessageType chatmessagetype, string sender, string text )
 {
     this.chatmessagetype = chatmessagetype;
     this.Sender = sender;
     MessageText = text;
 }
Example #51
0
 public void BroadcastChat(McChatMessage message, ChatMessageType messagetype, Player sender)
 {
     foreach (var i in OnlinePlayers.Values)
     {
         if (i == sender)
         {
             continue;
         }
         new ChatMessage(i.Wrapper) { Message = @message }.Write();
     }
 }
Example #52
0
        public ServerString(
            ChatMessageType MessageType,
			StringDictionary StringResources, 
            uint ResourceID, 
            List<InlineVariable> Variables,
            List<ChatStyle> Styles)
        {
            this.chatMessageType = MessageType;            
            this.stringResources = StringResources;
            this.Variables = Variables;
            this.Styles = Styles;

            this.resourceID = ResourceID;       
        }
        public ChatMessage(
            ChatMessageType MessageType, 
            LockingDictionary<uint, string> StringResources, 
            byte[] Buffer, 
            int StartIndex = 0)
        {
            this.chatMessageType = MessageType;
            this.stringResources = StringResources;

            Variables = new List<InlineVariable>();
            Styles = new List<ChatStyle>();
            ReadFrom(Buffer, StartIndex);
        }
Example #54
0
 public ChatMessage(ChatMessageType type, string content)
 {
     this.Type     = type;
     this.Content  = content;
     this.DateTime = DateTimeHelper.GetUnixTick();
 }
Example #55
0
        /// <summary>
        /// Called when adding or removing a character squelch
        /// </summary>
        public void HandleActionModifyCharacterSquelch(bool squelch, uint playerGuid, string playerName, ChatMessageType messageType)
        {
            //Console.WriteLine($"{Player.Name}.HandleActionModifyCharacterSquelch({squelch}, {playerGuid:X8}, {playerName}, {messageType})");

            if (messageType != ChatMessageType.AllChannels && !IsLegalChannel(messageType))
            {
                Player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{messageType} is not a legal squelch channel", ChatMessageType.Broadcast));
                return;
            }

            IPlayer player;

            if (playerGuid != 0)
            {
                player = PlayerManager.FindByGuid(new ObjectGuid(playerGuid));

                if (player == null)
                {
                    Player.Session.Network.EnqueueSend(new GameMessageSystemChat("Couldn't find player to squelch.", ChatMessageType.Broadcast));
                    return;
                }
            }
            else
            {
                if (string.IsNullOrWhiteSpace(playerName))
                {
                    return;
                }

                player = PlayerManager.FindByName(playerName);

                if (player == null)
                {
                    Player.Session.Network.EnqueueSend(new GameMessageSystemChat($"{playerName} not found.", ChatMessageType.Broadcast));
                    return;
                }
            }

            if (player.Guid == Player.Guid)
            {
                Player.Session.Network.EnqueueSend(new GameMessageSystemChat("You can't squelch yourself!", ChatMessageType.Broadcast));
                return;
            }


            if (squelch)
            {
                SquelchCharacter(player, messageType);
            }
            else
            {
                UnsquelchCharacter(player, messageType);
            }

            UpdateSquelchDB();

            SendSquelchDB();
        }
Example #56
0
 public void SendChatMessage(string message, ChatMessageType messageType)
 {
     this.NetworkComponent.SendChatMessage(message, messageType);
 }
Example #57
0
        /// <summary>
        /// Changes properties based on a known StyleChar
        /// </summary>
        /// <param name="StyleCharacter"></param>
        /// <param name="MessageType"></param>
        public void ProcessStyleCharacter(char StyleCharacter, ChatMessageType MessageType)
        {
            switch (StyleCharacter)
            {
            // colors
            case STYLEBLACK:
                Color = ChatColor.Black;
                break;

            case STYLEWHITE:
                Color = ChatColor.White;
                break;

            case STYLERED:
                Color = ChatColor.Red;
                break;

            case STYLEGREEN:
                Color = ChatColor.Green;
                break;

            case STYLEBLUE:
                Color = ChatColor.Blue;
                break;

            case STYLEPURPLE:
                Color = ChatColor.Purple;
                break;

#if !VANILLA
            case STYLEBRIGHTRED:
                Color = ChatColor.BrightRed;
                break;

            case STYLELIGHTGREEN:
                Color = ChatColor.LightGreen;
                break;

            case STYLEYELLOW:
                Color = ChatColor.Yellow;
                break;

            case STYLEPINK:
                Color = ChatColor.Pink;
                break;

            case STYLEORANGE:
                Color = ChatColor.Orange;
                break;

            case STYLEAQUAMARINE:
                Color = ChatColor.Aquamarine;
                break;

            case STYLECYAN:
                Color = ChatColor.Cyan;
                break;

            case STYLETEAL:
                Color = ChatColor.Teal;
                break;

            case STYLEDARKGREY:
                Color = ChatColor.DarkGrey;
                break;

            case STYLEVIOLET:
                Color = ChatColor.Violet;
                break;

            case STYLEMAGENTA:
                Color = ChatColor.Magenta;
                break;
#endif

            // modifiers
            case STYLEBOLD:
                IsBold = !IsBold;
                break;

            case STYLECURSIVE:
                IsCursive = !IsCursive;
                break;

            case STYLEUNDERLINE:
                IsUnderline = !IsUnderline;
                break;

            case STYLENORMAL:
                switch (MessageType)
                {
                case ChatMessageType.ObjectChatMessage:
                    Color = ChatColor.White;
                    break;

                case ChatMessageType.ServerChatMessage:
                    Color = ChatColor.Purple;
                    break;

                case ChatMessageType.SystemMessage:
                    Color = ChatColor.Blue;
                    break;

                default:
                    Color = ChatColor.White;
                    break;
                }

                IsBold      = false;
                IsCursive   = false;
                IsUnderline = false;
                break;
            }
        }
 public override void Unpack(BinaryReader reader)
 {
     base.Unpack(reader);
     Add     = reader.ReadBool32();
     MsgType = (ChatMessageType)reader.ReadUInt32();
 }
Example #59
0
 internal ChatSentEventArgs( Player player, string message, string formattedMessage,
                             ChatMessageType messageType, IEnumerable<Player> recepientList, int recepientCount )
 {
     Player = player;
     Message = message;
     MessageType = messageType;
     RecepientList = recepientList;
     FormattedMessage = formattedMessage;
     RecepientCount = recepientCount;
 }
Example #60
0
        public void UpdateNetwork(GameTime gameTime)
        {
            // Update the server with our status.
            timeSinceLastUpdate += gameTime.ElapsedGameTime.TotalSeconds;
            if (timeSinceLastUpdate > 0.05)
            {
                timeSinceLastUpdate = 0;
                if (CurrentStateType == "Infiniminer.States.MainGameState")
                {
                    propertyBag.SendPlayerUpdate();
                }
            }

            // Recieve messages from the server.
            while ((msgBuffer = propertyBag.netClient.ReadMessage()) != null)
            {
                switch (msgBuffer.MessageType)
                {
                case NetIncomingMessageType.StatusChanged:
                {
                    if (propertyBag.netClient.ConnectionStatus == NetConnectionStatus.RespondedConnect)
                    {
                        anyPacketsReceived = true;
                    }
                    if (propertyBag.netClient.ConnectionStatus == NetConnectionStatus.Disconnected)
                    {
                        anyPacketsReceived = false;
                        try
                        {
                            string[] reason = msgBuffer.ReadString().Split(";".ToCharArray());
                            if (reason.Length < 2 || reason[0] == "VER")
                            {
                                System.Windows.Forms.MessageBox.Show("Error: client/server version incompability!\r\nServer: " + msgBuffer.ReadString() + "\r\nClient: " + Defines.INFINIMINER_VERSION);
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Error: you are banned from this server!");
                            }
                        }
                        catch { }
                        ChangeState("Infiniminer.States.ServerBrowserState");
                    }
                }
                break;

                case NetIncomingMessageType.Data:
                {
                    try
                    {
                        InfiniminerMessage dataType = (InfiniminerMessage)msgBuffer.ReadByte();
                        switch (dataType)
                        {
                        // TODO: Replace this entire switch statement with a call to the packet registry
                        case InfiniminerMessage.BlockBulkTransfer:
                        {
                            anyPacketsReceived = true;

                            BlockEngine blockEngine = propertyBag.GetEngine <BlockEngine>("blockEngine");

                            try
                            {
                                //This is either the compression flag or the x coordiante
                                byte isCompressed = msgBuffer.ReadByte();
                                byte x;
                                byte y;

                                //255 was used because it exceeds the map size - of course, bytes won't work anyway if map sizes are allowed to be this big, so this method is a non-issue
                                if (isCompressed == 255)
                                {
                                    var compressed       = msgBuffer.ReadBytes(msgBuffer.LengthBytes - (int)(msgBuffer.Position / 8));
                                    var compressedstream = new System.IO.MemoryStream(compressed);
                                    var decompresser     = new System.IO.Compression.GZipStream(compressedstream, System.IO.Compression.CompressionMode.Decompress);

                                    x = (byte)decompresser.ReadByte();
                                    y = (byte)decompresser.ReadByte();
                                    propertyBag.mapLoadProgress[x, y] = true;
                                    for (byte dy = 0; dy < 16; dy++)
                                    {
                                        for (byte z = 0; z < 64; z++)
                                        {
                                            BlockType blockType = (BlockType)decompresser.ReadByte();
                                            if (blockType != BlockType.None)
                                            {
                                                blockEngine.downloadList[x, y + dy, z] = blockType;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    x = isCompressed;
                                    y = msgBuffer.ReadByte();
                                    propertyBag.mapLoadProgress[x, y] = true;
                                    for (byte dy = 0; dy < 16; dy++)
                                    {
                                        for (byte z = 0; z < 64; z++)
                                        {
                                            BlockType blockType = (BlockType)msgBuffer.ReadByte();
                                            if (blockType != BlockType.None)
                                            {
                                                blockEngine.downloadList[x, y + dy, z] = blockType;
                                            }
                                        }
                                    }
                                }
                                bool downloadComplete = true;
                                for (x = 0; x < 64; x++)
                                {
                                    for (y = 0; y < 64; y += 16)
                                    {
                                        if (propertyBag.mapLoadProgress[x, y] == false)
                                        {
                                            downloadComplete = false;
                                            break;
                                        }
                                    }
                                }
                                if (downloadComplete)
                                {
                                    ChangeState("Infiniminer.States.TeamSelectionState");
                                    if (!NoSound)
                                    {
                                        MediaPlayer.Stop();
                                    }
                                    blockEngine.DownloadComplete();
                                }
                            }
                            catch (Exception e)
                            {
                                Console.OpenStandardError();
                                Console.Error.WriteLine(e.Message);
                                Console.Error.WriteLine(e.StackTrace);
                                Console.Error.Close();
                            }
                        }
                        break;

                        case InfiniminerMessage.SetBeacon:
                        {
                            Vector3    position = msgBuffer.ReadVector3();
                            string     text     = msgBuffer.ReadString();
                            PlayerTeam team     = (PlayerTeam)msgBuffer.ReadByte();

                            if (text == "")
                            {
                                if (propertyBag.BeaconList.ContainsKey(position))
                                {
                                    propertyBag.BeaconList.Remove(position);
                                }
                            }
                            else
                            {
                                Beacon newBeacon = new Beacon();
                                newBeacon.ID   = text;
                                newBeacon.Team = team;
                                propertyBag.BeaconList.Add(position, newBeacon);
                            }
                        }
                        break;

                        case InfiniminerMessage.TriggerConstructionGunAnimation:
                        {
                            propertyBag.PlayerContainer.ConstructionGunAnimation = msgBuffer.ReadFloat();
                            if (propertyBag.PlayerContainer.ConstructionGunAnimation <= -0.1)
                            {
                                propertyBag.PlaySound(InfiniminerSound.RadarSwitch);
                            }
                        }
                        break;

                        case InfiniminerMessage.ResourceUpdate:
                        {
                            // ore, cash, weight, max ore, max weight, team ore, red cash, blue cash, all uint
                            propertyBag.PlayerContainer.PlayerOre       = msgBuffer.ReadUInt32();
                            propertyBag.PlayerContainer.PlayerCash      = msgBuffer.ReadUInt32();
                            propertyBag.PlayerContainer.PlayerWeight    = msgBuffer.ReadUInt32();
                            propertyBag.PlayerContainer.PlayerOreMax    = msgBuffer.ReadUInt32();
                            propertyBag.PlayerContainer.PlayerWeightMax = msgBuffer.ReadUInt32();
                            propertyBag.teamOre      = msgBuffer.ReadUInt32();
                            propertyBag.teamRedCash  = msgBuffer.ReadUInt32();
                            propertyBag.teamBlueCash = msgBuffer.ReadUInt32();
                        }
                        break;

                        case InfiniminerMessage.BlockSet:
                        {
                            BlockEngine blockEngine = propertyBag.GetEngine <BlockEngine>("blockEngine");
                            // x, y, z, type, all bytes
                            byte      x         = msgBuffer.ReadByte();
                            byte      y         = msgBuffer.ReadByte();
                            byte      z         = msgBuffer.ReadByte();
                            BlockType blockType = (BlockType)msgBuffer.ReadByte();
                            if (blockType == BlockType.None)
                            {
                                if (blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None)
                                {
                                    blockEngine.RemoveBlock(x, y, z);
                                }
                            }
                            else
                            {
                                if (blockEngine.BlockAtPoint(new Vector3(x, y, z)) != BlockType.None)
                                {
                                    blockEngine.RemoveBlock(x, y, z);
                                }
                                blockEngine.AddBlock(x, y, z, blockType);
                                CheckForStandingInLava();
                            }
                        }
                        break;

                        case InfiniminerMessage.TriggerExplosion:
                        {
                            Vector3 blockPos = msgBuffer.ReadVector3();

                            // Play the explosion sound.
                            propertyBag.PlaySound(InfiniminerSound.Explosion, blockPos);

                            // Create some particles.
                            propertyBag.GetEngine <ParticleEngine>("particleEngine").CreateExplosionDebris(blockPos);

                            // Figure out what the effect is.
                            float distFromExplosive = (blockPos + 0.5f * Vector3.One - propertyBag.PlayerContainer.PlayerPosition).Length();
                            if (distFromExplosive < 3)
                            {
                                propertyBag.KillPlayer(Defines.deathByExpl);                //"WAS KILLED IN AN EXPLOSION!");
                            }
                            else if (distFromExplosive < 8)
                            {
                                // If we're not in explosion mode, turn it on with the minimum ammount of shakiness.
                                if (propertyBag.screenEffect != ScreenEffect.Explosion)
                                {
                                    propertyBag.screenEffect        = ScreenEffect.Explosion;
                                    propertyBag.screenEffectCounter = 2;
                                }
                                // If this bomb would result in a bigger shake, use its value.
                                propertyBag.screenEffectCounter = Math.Min(propertyBag.screenEffectCounter, (distFromExplosive - 2) / 5);
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerSetTeam:
                        {
                            uint playerId = msgBuffer.ReadUInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                Player player = propertyBag.playerList[playerId];
                                player.Team = (PlayerTeam)msgBuffer.ReadByte();
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerJoined:
                        {
                            uint   playerId    = msgBuffer.ReadUInt32();
                            string playerName  = msgBuffer.ReadString();
                            bool   thisIsMe    = msgBuffer.ReadBoolean();
                            bool   playerAlive = msgBuffer.ReadBoolean();
                            propertyBag.playerList[playerId]            = new Player(null, (Game)this);
                            propertyBag.playerList[playerId].Handle     = playerName;
                            propertyBag.playerList[playerId].ID         = playerId;
                            propertyBag.playerList[playerId].Alive      = playerAlive;
                            propertyBag.playerList[playerId].AltColours = customColours;
                            propertyBag.playerList[playerId].redTeam    = red;
                            propertyBag.playerList[playerId].blueTeam   = blue;
                            if (thisIsMe)
                            {
                                propertyBag.PlayerContainer.PlayerMyId = playerId;
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerLeft:
                        {
                            uint playerId = msgBuffer.ReadUInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                propertyBag.playerList.Remove(playerId);
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerDead:
                        {
                            uint playerId = msgBuffer.ReadUInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                Player player = propertyBag.playerList[playerId];
                                player.Alive = false;
                                propertyBag.GetEngine <ParticleEngine>("particleEngine").CreateBloodSplatter(player.Position, player.Team == PlayerTeam.Red ? Color.Red : Color.Blue);
                                if (playerId != propertyBag.PlayerContainer.PlayerMyId)
                                {
                                    propertyBag.PlaySound(InfiniminerSound.Death, player.Position);
                                }
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerAlive:
                        {
                            uint playerId = msgBuffer.ReadUInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                Player player = propertyBag.playerList[playerId];
                                player.Alive = true;
                            }
                        }
                        break;

                        case InfiniminerMessage.PlayerUpdate:
                        {
                            uint playerId = msgBuffer.ReadUInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                Player player = propertyBag.playerList[playerId];
                                player.UpdatePosition(msgBuffer.ReadVector3(), gameTime.TotalGameTime.TotalSeconds);
                                player.Heading   = msgBuffer.ReadVector3();
                                player.Tool      = (PlayerTools)msgBuffer.ReadByte();
                                player.UsingTool = msgBuffer.ReadBoolean();
                                player.Score     = (uint)(msgBuffer.ReadUInt16() * 100);
                            }
                        }
                        break;

                        case InfiniminerMessage.GameOver:
                        {
                            propertyBag.teamWinners = (PlayerTeam)msgBuffer.ReadByte();
                        }
                        break;

                        case InfiniminerMessage.ChatMessage:
                        {
                            ChatMessageType chatType   = (ChatMessageType)msgBuffer.ReadByte();
                            string          chatString = Defines.Sanitize(msgBuffer.ReadString());
                            //Time to break it up into multiple lines
                            propertyBag.addChatMessage(chatString, chatType, 10);
                        }
                        break;

                        case InfiniminerMessage.PlayerPing:
                        {
                            uint playerId = (uint)msgBuffer.ReadInt32();
                            if (propertyBag.playerList.ContainsKey(playerId))
                            {
                                if (propertyBag.playerList[playerId].Team == propertyBag.PlayerContainer.PlayerTeam)
                                {
                                    propertyBag.playerList[playerId].Ping = 1;
                                    propertyBag.PlaySound(InfiniminerSound.Ping);
                                }
                            }
                        }
                        break;

                        case InfiniminerMessage.PlaySound:
                        {
                            InfiniminerSound sound       = (InfiniminerSound)msgBuffer.ReadByte();
                            bool             hasPosition = msgBuffer.ReadBoolean();
                            if (hasPosition)
                            {
                                Vector3 soundPosition = msgBuffer.ReadVector3();
                                propertyBag.PlaySound(sound, soundPosition);
                            }
                            else
                            {
                                propertyBag.PlaySound(sound);
                            }
                        }
                        break;
                        }
                    }
                    catch { }         //Error in a received message
                }
                break;
                }
            }

            // Make sure our network thread actually gets to run.
            Thread.Sleep(1);
        }