Exemplo n.º 1
0
        void HandleChatAddon(ChatMsg type, string prefix, string text, bool isLogged, string target = "")
        {
            Player sender = GetPlayer();

            if (string.IsNullOrEmpty(prefix) || prefix.Length > 16)
            {
                return;
            }

            // Disabled addon channel?
            if (!WorldConfig.GetBoolValue(WorldCfg.AddonChannel))
            {
                return;
            }

            switch (type)
            {
            case ChatMsg.Guild:
            case ChatMsg.Officer:
                if (sender.GetGuildId() != 0)
                {
                    Guild guild = Global.GuildMgr.GetGuildById(sender.GetGuildId());
                    if (guild)
                    {
                        guild.BroadcastAddonToGuild(this, type == ChatMsg.Officer, text, prefix, isLogged);
                    }
                }
                break;

            case ChatMsg.Whisper:
                // @todo implement cross realm whispers (someday)
                ExtendedPlayerName extName = ObjectManager.ExtractExtendedPlayerName(target);

                if (!ObjectManager.NormalizePlayerName(ref extName.Name))
                {
                    break;
                }

                Player receiver = Global.ObjAccessor.FindPlayerByName(extName.Name);
                if (!receiver)
                {
                    break;
                }

                sender.WhisperAddon(text, prefix, isLogged, receiver);
                break;

            // Messages sent to "RAID" while in a party will get delivered to "PARTY"
            case ChatMsg.Party:
            case ChatMsg.Raid:
            case ChatMsg.InstanceChat:
            {
                Group group    = null;
                int   subGroup = -1;
                if (type != ChatMsg.InstanceChat)
                {
                    group = sender.GetOriginalGroup();
                }

                if (!group)
                {
                    group = sender.GetGroup();
                    if (!group)
                    {
                        break;
                    }

                    if (type == ChatMsg.Party)
                    {
                        subGroup = sender.GetSubGroup();
                    }
                }

                ChatPkt data = new ChatPkt();
                data.Initialize(type, isLogged ? Language.AddonLogged : Language.Addon, sender, null, text, 0, "", LocaleConstant.enUS, prefix);
                group.BroadcastAddonMessagePacket(data, prefix, true, subGroup, sender.GetGUID());
                break;
            }

            case ChatMsg.Channel:
                Channel chn = ChannelManager.GetChannelForPlayerByNamePart(target, sender);
                if (chn != null)
                {
                    chn.AddonSay(sender.GetGUID(), prefix, text, isLogged);
                }
                break;

            default:
                Log.outError(LogFilter.Server, "HandleAddonMessagechat: unknown addon message type {0}", type);
                break;
            }
        }
Exemplo n.º 2
0
        void HandleChat(ChatMsg type, Language lang, string msg, string target = "")
        {
            Player sender = GetPlayer();

            if (lang == Language.Universal && type != ChatMsg.Emote)
            {
                Log.outError(LogFilter.Network, "CMSG_MESSAGECHAT: Possible hacking-attempt: {0} tried to send a message in universal language", GetPlayerInfo());
                SendNotification(CypherStrings.UnknownLanguage);
                return;
            }

            // prevent talking at unknown language (cheating)
            LanguageDesc langDesc = ObjectManager.GetLanguageDescByID(lang);

            if (langDesc == null)
            {
                SendNotification(CypherStrings.UnknownLanguage);
                return;
            }

            if (langDesc.skill_id != 0 && !sender.HasSkill((SkillType)langDesc.skill_id))
            {
                // also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
                var  langAuras = sender.GetAuraEffectsByType(AuraType.ComprehendLanguage);
                bool foundAura = false;
                foreach (var eff in langAuras)
                {
                    if (eff.GetMiscValue() == (int)lang)
                    {
                        foundAura = true;
                        break;
                    }
                }
                if (!foundAura)
                {
                    SendNotification(CypherStrings.NotLearnedLanguage);
                    return;
                }
            }

            // send in universal language if player in .gm on mode (ignore spell effects)
            if (sender.IsGameMaster())
            {
                lang = Language.Universal;
            }
            else
            {
                // send in universal language in two side iteration allowed mode
                if (HasPermission(RBACPermissions.TwoSideInteractionChat))
                {
                    lang = Language.Universal;
                }
                else
                {
                    switch (type)
                    {
                    case ChatMsg.Party:
                    case ChatMsg.Raid:
                    case ChatMsg.RaidWarning:
                        // allow two side chat at group channel if two side group allowed
                        if (WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionGroup))
                        {
                            lang = Language.Universal;
                        }
                        break;

                    case ChatMsg.Guild:
                    case ChatMsg.Officer:
                        // allow two side chat at guild channel if two side guild allowed
                        if (WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionGuild))
                        {
                            lang = Language.Universal;
                        }
                        break;
                    }
                }
                // but overwrite it by SPELL_AURA_MOD_LANGUAGE auras (only single case used)
                var ModLangAuras = sender.GetAuraEffectsByType(AuraType.ModLanguage);
                if (!ModLangAuras.Empty())
                {
                    lang = (Language)ModLangAuras.FirstOrDefault().GetMiscValue();
                }
            }

            if (!CanSpeak())
            {
                string timeStr = Time.secsToTimeString((ulong)(m_muteTime - Time.UnixTime));
                SendNotification(CypherStrings.WaitBeforeSpeaking, timeStr);
                return;
            }

            if (sender.HasAura(1852) && type != ChatMsg.Whisper)
            {
                SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.GmSilence), sender.GetName());
                return;
            }

            if (string.IsNullOrEmpty(msg))
            {
                return;
            }

            if (new CommandHandler(this).ParseCommand(msg))
            {
                return;
            }

            switch (type)
            {
            case ChatMsg.Say:
                // Prevent cheating
                if (!sender.IsAlive())
                {
                    return;
                }

                if (sender.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatSayLevelReq))
                {
                    SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.SayReq), WorldConfig.GetIntValue(WorldCfg.ChatSayLevelReq));
                    return;
                }

                sender.Say(msg, lang);
                break;

            case ChatMsg.Emote:
                // Prevent cheating
                if (!sender.IsAlive())
                {
                    return;
                }

                if (sender.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatEmoteLevelReq))
                {
                    SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.SayReq), WorldConfig.GetIntValue(WorldCfg.ChatEmoteLevelReq));
                    return;
                }

                sender.TextEmote(msg);
                break;

            case ChatMsg.Yell:
                // Prevent cheating
                if (!sender.IsAlive())
                {
                    return;
                }

                if (sender.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatYellLevelReq))
                {
                    SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.SayReq), WorldConfig.GetIntValue(WorldCfg.ChatYellLevelReq));
                    return;
                }

                sender.Yell(msg, lang);
                break;

            case ChatMsg.Whisper:
                // @todo implement cross realm whispers (someday)
                ExtendedPlayerName extName = ObjectManager.ExtractExtendedPlayerName(target);

                if (!ObjectManager.NormalizePlayerName(ref extName.Name))
                {
                    SendChatPlayerNotfoundNotice(target);
                    break;
                }

                Player receiver = Global.ObjAccessor.FindPlayerByName(extName.Name);
                if (!receiver || (lang != Language.Addon && !receiver.IsAcceptWhispers() && receiver.GetSession().HasPermission(RBACPermissions.CanFilterWhispers) && !receiver.IsInWhisperWhiteList(sender.GetGUID())))
                {
                    SendChatPlayerNotfoundNotice(target);
                    return;
                }
                if (!sender.IsGameMaster() && sender.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatWhisperLevelReq) && !receiver.IsInWhisperWhiteList(sender.GetGUID()))
                {
                    SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.WhisperReq), WorldConfig.GetIntValue(WorldCfg.ChatWhisperLevelReq));
                    return;
                }

                if (GetPlayer().GetTeam() != receiver.GetTeam() && !HasPermission(RBACPermissions.TwoSideInteractionChat) && !receiver.IsInWhisperWhiteList(sender.GetGUID()))
                {
                    SendChatPlayerNotfoundNotice(target);
                    return;
                }

                if (GetPlayer().HasAura(1852) && !receiver.IsGameMaster())
                {
                    SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.GmSilence), GetPlayer().GetName());
                    return;
                }

                if (receiver.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatWhisperLevelReq) ||
                    (HasPermission(RBACPermissions.CanFilterWhispers) && !sender.IsAcceptWhispers() && !sender.IsInWhisperWhiteList(receiver.GetGUID())))
                {
                    sender.AddWhisperWhiteList(receiver.GetGUID());
                }

                GetPlayer().Whisper(msg, lang, receiver);
                break;

            case ChatMsg.Party:
            {
                // if player is in Battleground, he cannot say to Battlegroundmembers by /p
                Group group = GetPlayer().GetOriginalGroup();
                if (!group)
                {
                    group = GetPlayer().GetGroup();
                    if (!group || group.IsBGGroup())
                    {
                        return;
                    }
                }

                if (group.IsLeader(GetPlayer().GetGUID()))
                {
                    type = ChatMsg.PartyLeader;
                }

                Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, group);

                ChatPkt data = new ChatPkt();
                data.Initialize(type, lang, sender, null, msg);
                group.BroadcastPacket(data, false, group.GetMemberGroup(GetPlayer().GetGUID()));
            }
            break;

            case ChatMsg.Guild:
                if (GetPlayer().GetGuildId() != 0)
                {
                    Guild guild = Global.GuildMgr.GetGuildById(GetPlayer().GetGuildId());
                    if (guild)
                    {
                        Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, guild);

                        guild.BroadcastToGuild(this, false, msg, lang == Language.Addon ? Language.Addon : Language.Universal);
                    }
                }
                break;

            case ChatMsg.Officer:
                if (GetPlayer().GetGuildId() != 0)
                {
                    Guild guild = Global.GuildMgr.GetGuildById(GetPlayer().GetGuildId());
                    if (guild)
                    {
                        Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, guild);

                        guild.BroadcastToGuild(this, true, msg, lang == Language.Addon ? Language.Addon : Language.Universal);
                    }
                }
                break;

            case ChatMsg.Raid:
            {
                Group group = GetPlayer().GetGroup();
                if (!group || !group.IsRaidGroup() || group.IsBGGroup())
                {
                    return;
                }

                if (group.IsLeader(GetPlayer().GetGUID()))
                {
                    type = ChatMsg.RaidLeader;
                }

                Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, group);

                ChatPkt data = new ChatPkt();
                data.Initialize(type, lang, sender, null, msg);
                group.BroadcastPacket(data, false);
            }
            break;

            case ChatMsg.RaidWarning:
            {
                Group group = GetPlayer().GetGroup();
                if (!group || !(group.IsRaidGroup() || WorldConfig.GetBoolValue(WorldCfg.ChatPartyRaidWarnings)) || !(group.IsLeader(GetPlayer().GetGUID()) || group.IsAssistant(GetPlayer().GetGUID())) || group.IsBGGroup())
                {
                    return;
                }

                Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, group);

                ChatPkt data = new ChatPkt();
                //in Battleground, raid warning is sent only to players in Battleground - code is ok
                data.Initialize(ChatMsg.RaidWarning, lang, sender, null, msg);
                group.BroadcastPacket(data, false);
            }
            break;

            case ChatMsg.Channel:
                if (!HasPermission(RBACPermissions.SkipCheckChatChannelReq))
                {
                    if (GetPlayer().GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatChannelLevelReq))
                    {
                        SendNotification(Global.ObjectMgr.GetCypherString(CypherStrings.ChannelReq), WorldConfig.GetIntValue(WorldCfg.ChatChannelLevelReq));
                        return;
                    }
                }
                Channel chn = ChannelManager.GetChannelForPlayerByNamePart(target, sender);
                if (chn != null)
                {
                    Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, chn);
                    chn.Say(GetPlayer().GetGUID(), msg, lang);
                }
                break;

            case ChatMsg.InstanceChat:
            {
                Group group = GetPlayer().GetGroup();
                if (!group)
                {
                    return;
                }

                if (group.IsLeader(GetPlayer().GetGUID()))
                {
                    type = ChatMsg.InstanceChatLeader;
                }

                Global.ScriptMgr.OnPlayerChat(GetPlayer(), type, lang, msg, group);

                ChatPkt packet = new ChatPkt();
                packet.Initialize(type, lang, sender, null, msg);
                group.BroadcastPacket(packet, false);
                break;
            }

            default:
                Log.outError(LogFilter.ChatSystem, "CHAT: unknown message type {0}, lang: {1}", type, lang);
                break;
            }
        }