Exemplo n.º 1
0
        public Channel GetJoinChannel(uint channelId, string name, AreaTableRecord zoneEntry = null)
        {
            if (channelId != 0) // builtin
            {
                ObjectGuid channelGuid = CreateBuiltinChannelGuid(channelId, zoneEntry);
                var        channel     = _channels.LookupByKey(channelGuid);
                if (channel != null)
                {
                    return(channel);
                }

                Channel newChannel = new(channelGuid, channelId, _team, zoneEntry);
                _channels[channelGuid] = newChannel;
                return(newChannel);
            }
            else // custom
            {
                var channel = _customChannels.LookupByKey(name.ToLower());
                if (channel != null)
                {
                    return(channel);
                }

                Channel newChannel = new(CreateCustomChannelGuid(), name, _team);
                _customChannels[name.ToLower()] = newChannel;
                return(newChannel);
            }
        }
Exemplo n.º 2
0
        bool IsAreaThatActivatesPvpTalents(uint areaID)
        {
            if (InBattleground())
            {
                return(true);
            }

            AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(areaID);

            if (area != null)
            {
                do
                {
                    if (area.IsSanctuary())
                    {
                        return(false);
                    }

                    if (area.Flags[0].HasAnyFlag(AreaFlags.Arena))
                    {
                        return(true);
                    }

                    if (Global.BattleFieldMgr.GetBattlefieldToZoneId(area.Id) != null)
                    {
                        return(true);
                    }

                    area = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
                } while (area != null);
            }

            return(false);
        }
Exemplo n.º 3
0
        public Channel(uint channelId, Team team = 0, AreaTableRecord zoneEntry = null)
        {
            _channelFlags = ChannelFlags.General;
            _channelId    = channelId;
            _channelTeam  = team;
            _zoneEntry    = zoneEntry;

            ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);

            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Trade))             // for trade channel
            {
                _channelFlags |= ChannelFlags.Trade;
            }

            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly2))        // for city only channels
            {
                _channelFlags |= ChannelFlags.City;
            }

            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Lfg))               // for LFG channel
            {
                _channelFlags |= ChannelFlags.Lfg;
            }
            else                                                // for all other channels
            {
                _channelFlags |= ChannelFlags.NotLfg;
            }
        }
Exemplo n.º 4
0
        void HandleHearthAndResurrect(HearthAndResurrect packet)
        {
            if (GetPlayer().IsInFlight())
            {
                return;
            }

            BattleField bf = Global.BattleFieldMgr.GetBattlefieldToZoneId(GetPlayer().GetZoneId());

            if (bf != null)
            {
                bf.PlayerAskToLeave(_player);
                return;
            }

            AreaTableRecord atEntry = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetAreaId());

            if (atEntry == null || !atEntry.Flags[0].HasAnyFlag(AreaFlags.CanHearthAndResurrect))
            {
                return;
            }

            GetPlayer().BuildPlayerRepop();
            GetPlayer().ResurrectPlayer(1.0f);
            GetPlayer().TeleportTo(GetPlayer().GetHomebind());
        }
Exemplo n.º 5
0
        public Channel GetJoinChannel(uint channelId, string name, AreaTableRecord zoneEntry = null)
        {
            if (channelId != 0) // builtin
            {
                ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
                uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;
                if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
                {
                    zoneId = 0;
                }

                Tuple <uint, uint> key = Tuple.Create(channelId, zoneId);
                var channel            = _channels.LookupByKey(key);
                if (channel != null)
                {
                    return(channel);
                }

                Channel newChannel = new Channel(channelId, _team, zoneEntry);
                _channels[key] = newChannel;
                return(newChannel);
            }
            else // custom
            {
                var channel = _customChannels.LookupByKey(name.ToLower());
                if (channel != null)
                {
                    return(channel);
                }

                Channel newChannel = new Channel(name, _team);
                _customChannels[name.ToLower()] = newChannel;
                return(newChannel);
            }
        }
Exemplo n.º 6
0
        ObjectGuid CreateBuiltinChannelGuid(uint channelId, AreaTableRecord zoneEntry = null)
        {
            ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
            uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;

            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
            {
                zoneId = 0;
            }

            ulong high = 0;

            high |= (ulong)HighGuid.ChatChannel << 58;
            high |= (ulong)Global.WorldMgr.GetRealmId().Index << 42;
            high |= 1ul << 25; // built-in
            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly2))
            {
                high |= 1ul << 24; // trade
            }
            high |= (ulong)(zoneId) << 10;
            high |= (ulong)(_team == Team.Alliance ? 3 : 5) << 4;

            ObjectGuid channelGuid = new();

            channelGuid.SetRawValue(high, channelId);
            return(channelGuid);
        }
Exemplo n.º 7
0
        void UpdateArea(uint newArea)
        {
            // FFA_PVP flags are area and not zone id dependent
            // so apply them accordingly
            m_areaUpdateId = newArea;

            AreaTableRecord area          = CliDB.AreaTableStorage.LookupByKey(newArea);
            bool            oldFFAPvPArea = pvpInfo.IsInFFAPvPArea;

            pvpInfo.IsInFFAPvPArea = area != null && area.Flags[0].HasAnyFlag(AreaFlags.Arena);
            UpdatePvPState(true);

            // check if we were in ffa arena and we left
            if (oldFFAPvPArea && !pvpInfo.IsInFFAPvPArea)
            {
                ValidateAttackersAndOwnTarget();
            }

            PhasingHandler.OnAreaChange(this);
            UpdateAreaDependentAuras(newArea);

            if (IsAreaThatActivatesPvpTalents(newArea))
            {
                EnablePvpRules();
            }
            else
            {
                DisablePvpRules();
            }

            // previously this was in UpdateZone (but after UpdateArea) so nothing will break
            pvpInfo.IsInNoPvPArea = false;
            if (area != null && area.IsSanctuary())    // in sanctuary
            {
                AddPvpFlag(UnitPVPStateFlags.Sanctuary);
                pvpInfo.IsInNoPvPArea = true;
                if (duel == null)
                {
                    CombatStopWithPets();
                }
            }
            else
            {
                RemovePvpFlag(UnitPVPStateFlags.Sanctuary);
            }

            AreaFlags areaRestFlag = (GetTeam() == Team.Alliance) ? AreaFlags.RestZoneAlliance : AreaFlags.RestZoneHorde;

            if (area != null && area.Flags[0].HasAnyFlag(areaRestFlag))
            {
                _restMgr.SetRestFlag(RestFlag.FactionArea);
            }
            else
            {
                _restMgr.RemoveRestFlag(RestFlag.FactionArea);
            }

            UpdateCriteria(CriteriaTypes.TravelledToArea, newArea);
        }
Exemplo n.º 8
0
        // Hack to store map because this code is just shit
        public void SetMapFromZone(uint zone)
        {
            AreaTableRecord areaTable = CliDB.AreaTableStorage.LookupByKey(zone);

            Contract.Assert(areaTable != null);
            Map map = Global.MapMgr.CreateBaseMap(areaTable.MapId);

            Contract.Assert(!map.Instanceable());
            m_map = map;
        }
Exemplo n.º 9
0
        void UpdateArea(uint newArea)
        {
            // FFA_PVP flags are area and not zone id dependent
            // so apply them accordingly
            m_areaUpdateId = newArea;

            AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(newArea);

            pvpInfo.IsInFFAPvPArea = area != null && area.Flags[0].HasAnyFlag(AreaFlags.Arena);
            UpdatePvPState(true);

            UpdateAreaDependentAuras(newArea);
            PhasingHandler.OnAreaChange(this);

            if (IsAreaThatActivatesPvpTalents(newArea))
            {
                EnablePvpRules();
            }
            else
            {
                DisablePvpRules();
            }

            // previously this was in UpdateZone (but after UpdateArea) so nothing will break
            pvpInfo.IsInNoPvPArea = false;
            if (area != null && area.IsSanctuary())    // in sanctuary
            {
                SetByteFlag(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, UnitBytes2Flags.Sanctuary);
                pvpInfo.IsInNoPvPArea = true;
                if (duel == null)
                {
                    CombatStopWithPets();
                }
            }
            else
            {
                RemoveByteFlag(UnitFields.Bytes2, UnitBytes2Offsets.PvpFlag, UnitBytes2Flags.Sanctuary);
            }

            AreaFlags areaRestFlag = (GetTeam() == Team.Alliance) ? AreaFlags.RestZoneAlliance : AreaFlags.RestZoneHorde;

            if (area != null && area.Flags[0].HasAnyFlag(areaRestFlag))
            {
                _restMgr.SetRestFlag(RestFlag.FactionArea);
            }
            else
            {
                _restMgr.RemoveRestFlag(RestFlag.FactionArea);
            }
        }
Exemplo n.º 10
0
        public Channel GetSystemChannel(uint channelId, AreaTableRecord zoneEntry = null)
        {
            ObjectGuid channelGuid    = CreateBuiltinChannelGuid(channelId, zoneEntry);
            var        currentChannel = _channels.LookupByKey(channelGuid);

            if (currentChannel != null)
            {
                return(currentChannel);
            }

            Channel newChannel = new Channel(channelGuid, channelId, _team, zoneEntry);

            _channels[channelGuid] = newChannel;
            return(newChannel);
        }
Exemplo n.º 11
0
        public void LeftChannel(uint channelId, AreaTableRecord zoneEntry)
        {
            var guid    = CreateBuiltinChannelGuid(channelId, zoneEntry);
            var channel = _channels.LookupByKey(guid);

            if (channel == null)
            {
                return;
            }

            if (channel.GetNumPlayers() == 0)
            {
                _channels.Remove(guid);
            }
        }
Exemplo n.º 12
0
        void HandleLeaveChannel(LeaveChannel packet)
        {
            if (string.IsNullOrEmpty(packet.ChannelName) && packet.ZoneChannelID == 0)
            {
                return;
            }

            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetZoneId());

            if (packet.ZoneChannelID != 0)
            {
                ChatChannelsRecord channel = CliDB.ChatChannelsStorage.LookupByKey(packet.ZoneChannelID);
                if (channel == null)
                {
                    return;
                }

                if (zone == null || !GetPlayer().CanJoinConstantChannelInZone(channel, zone))
                {
                    return;
                }
            }

            ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam());

            if (cMgr != null)
            {
                Channel channel = cMgr.GetChannel((uint)packet.ZoneChannelID, packet.ChannelName, GetPlayer(), true, zone);
                if (channel != null)
                {
                    channel.LeaveChannel(GetPlayer(), true);
                }

                if (packet.ZoneChannelID != 0)
                {
                    cMgr.LeftChannel((uint)packet.ZoneChannelID, zone);
                }
                else
                {
                    cMgr.LeftChannel(packet.ChannelName);
                }
            }
        }
Exemplo n.º 13
0
        void HandleJoinChannel(JoinChannel packet)
        {
            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetZoneId());

            if (packet.ChatChannelId != 0)
            {
                ChatChannelsRecord channel = CliDB.ChatChannelsStorage.LookupByKey(packet.ChatChannelId);
                if (channel == null)
                {
                    return;
                }

                if (zone == null || !GetPlayer().CanJoinConstantChannelInZone(channel, zone))
                {
                    return;
                }
            }

            if (string.IsNullOrEmpty(packet.ChannelName))
            {
                return;
            }

            if (packet.ChannelName.IsNumber())
            {
                return;
            }

            ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam());

            if (cMgr != null)
            {
                Channel channel = cMgr.GetJoinChannel((uint)packet.ChatChannelId, packet.ChannelName, zone);
                if (channel != null)
                {
                    channel.JoinChannel(GetPlayer(), packet.Password);
                }
            }
        }
Exemplo n.º 14
0
        public void LeftChannel(uint channelId, AreaTableRecord zoneEntry)
        {
            ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
            uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;

            if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
            {
                zoneId = 0;
            }

            Tuple <uint, uint> key = Tuple.Create(channelId, zoneId);
            var channel            = _channels.LookupByKey(key);

            if (channel == null)
            {
                return;
            }

            if (channel.GetNumPlayers() == 0)
            {
                _channels.Remove(key);
            }
        }
Exemplo n.º 15
0
 public static void GetChannelName(ref string channelName, uint channelId, LocaleConstant locale, AreaTableRecord zoneEntry)
 {
     if (channelId != 0)
     {
         ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
         if (!channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global))
         {
             if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.CityOnly))
             {
                 channelName = string.Format(channelEntry.Name[locale].ConvertFormatSyntax(), Global.ObjectMgr.GetCypherString(CypherStrings.ChannelCity, locale));
             }
             else
             {
                 channelName = string.Format(channelEntry.Name[locale].ConvertFormatSyntax(), zoneEntry.AreaName[locale]);
             }
         }
         else
         {
             channelName = channelEntry.Name[locale];
         }
     }
 }
Exemplo n.º 16
0
        public bool ExecuteCommandInTable(ICollection <ChatCommand> table, string text, string fullcmd)
        {
            StringArguments args = new(text);
            string          cmd  = args.NextString();

            foreach (var command in table)
            {
                if (!HasStringAbbr(command.Name, cmd))
                {
                    continue;
                }

                bool match = false;
                if (command.Name.Length > cmd.Length)
                {
                    foreach (var command2 in table)
                    {
                        if (!HasStringAbbr(command2.Name, cmd))
                        {
                            continue;
                        }

                        if (command2.Name.Equals(cmd))
                        {
                            match = true;
                            break;
                        }
                    }
                }
                if (match)
                {
                    continue;
                }

                if (!command.ChildCommands.Empty())
                {
                    string arg = args.NextString("");
                    if (!ExecuteCommandInTable(command.ChildCommands, arg, fullcmd))
                    {
                        if (_session != null && !_session.HasPermission(RBACPermissions.CommandsNotifyCommandNotFoundError))
                        {
                            return(false);
                        }

                        if (!arg.IsEmpty())
                        {
                            SendSysMessage(CypherStrings.NoSubcmd);
                        }
                        else
                        {
                            SendSysMessage(CypherStrings.CmdSyntax);
                        }

                        ShowHelpForCommand(command.ChildCommands, arg);
                    }

                    return(true);
                }

                // must be available and have handler
                if (!command.HasHandler() || !IsAvailable(command))
                {
                    continue;
                }

                _sentErrorMessage = false;
                if (command.Invoke(this, new StringArguments(!command.Name.IsEmpty() ? args.NextString("") : text)))
                {
                    if (GetSession() == null) // ignore console
                    {
                        return(true);
                    }

                    Player player = GetPlayer();
                    if (!Global.AccountMgr.IsPlayerAccount(GetSession().GetSecurity()))
                    {
                        ObjectGuid guid     = player.GetTarget();
                        uint       areaId   = player.GetAreaId();
                        string     areaName = "Unknown";
                        string     zoneName = "Unknown";

                        AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(areaId);
                        if (area != null)
                        {
                            var locale = GetSessionDbcLocale();
                            areaName = area.AreaName[locale];
                            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
                            if (zone != null)
                            {
                                zoneName = zone.AreaName[locale];
                            }
                        }

                        Log.outCommand(GetSession().GetAccountId(), "Command: {0} [Player: {1} ({2}) (Account: {3}) Postion: {4} Map: {5} ({6}) Area: {7} ({8}) Zone: {9} Selected: {10} ({11})]",
                                       fullcmd, player.GetName(), player.GetGUID().ToString(), GetSession().GetAccountId(), player.GetPosition(), player.GetMapId(),
                                       player.GetMap() ? player.GetMap().GetMapName() : "Unknown", areaId, areaName, zoneName, (player.GetSelectedUnit()) ? player.GetSelectedUnit().GetName() : "", guid.ToString());
                    }
                }
                else if (!HasSentErrorMessage())
                {
                    if (!command.Help.IsEmpty())
                    {
                        SendSysMessage(command.Help);
                    }
                    else
                    {
                        SendSysMessage(CypherStrings.CmdSyntax);
                    }
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 17
0
        public void UpdateZone(uint newZone, uint newArea)
        {
            if (m_zoneUpdateId != newZone)
            {
                Global.OutdoorPvPMgr.HandlePlayerLeaveZone(this, m_zoneUpdateId);
                Global.OutdoorPvPMgr.HandlePlayerEnterZone(this, newZone);
                Global.BattleFieldMgr.HandlePlayerLeaveZone(this, m_zoneUpdateId);
                Global.BattleFieldMgr.HandlePlayerEnterZone(this, newZone);
                SendInitWorldStates(newZone, newArea);              // only if really enters to new zone, not just area change, works strange...
                Guild guild = GetGuild();
                if (guild)
                {
                    guild.UpdateMemberData(this, GuildMemberData.ZoneId, newZone);
                }
            }

            // group update
            if (GetGroup())
            {
                SetGroupUpdateFlag(GroupUpdateFlags.Full);

                Pet pet = GetPet();
                if (pet)
                {
                    pet.SetGroupUpdateFlag(GroupUpdatePetFlags.Full);
                }
            }

            m_zoneUpdateId    = newZone;
            m_zoneUpdateTimer = 1 * Time.InMilliseconds;

            // zone changed, so area changed as well, update it
            UpdateArea(newArea);

            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(newZone);

            if (zone == null)
            {
                return;
            }

            if (WorldConfig.GetBoolValue(WorldCfg.Weather))
            {
                GetMap().GetOrGenerateZoneDefaultWeather(newZone);
            }

            GetMap().SendZoneDynamicInfo(newZone, this);

            Global.ScriptMgr.OnPlayerUpdateZone(this, newZone, newArea);

            // in PvP, any not controlled zone (except zone.team == 6, default case)
            // in PvE, only opposition team capital
            switch ((AreaTeams)zone.FactionGroupMask)
            {
            case AreaTeams.Ally:
                pvpInfo.IsInHostileArea = GetTeam() != Team.Alliance && (Global.WorldMgr.IsPvPRealm() || zone.Flags[0].HasAnyFlag(AreaFlags.Capital));
                break;

            case AreaTeams.Horde:
                pvpInfo.IsInHostileArea = GetTeam() != Team.Horde && (Global.WorldMgr.IsPvPRealm() || zone.Flags[0].HasAnyFlag(AreaFlags.Capital));
                break;

            case AreaTeams.None:
                // overwrite for Battlegrounds, maybe batter some zone flags but current known not 100% fit to this
                pvpInfo.IsInHostileArea = Global.WorldMgr.IsPvPRealm() || InBattleground() || zone.Flags[0].HasAnyFlag(AreaFlags.Wintergrasp);
                break;

            default:                                                // 6 in fact
                pvpInfo.IsInHostileArea = false;
                break;
            }

            // Treat players having a quest flagging for PvP as always in hostile area
            pvpInfo.IsHostile = pvpInfo.IsInHostileArea || HasPvPForcingQuest();

            if (zone.Flags[0].HasAnyFlag(AreaFlags.Capital))                     // Is in a capital city
            {
                if (!pvpInfo.IsInHostileArea || zone.IsSanctuary())
                {
                    _restMgr.SetRestFlag(RestFlag.City);
                }
                pvpInfo.IsInNoPvPArea = true;
            }
            else
            {
                _restMgr.RemoveRestFlag(RestFlag.City);
            }

            UpdatePvPState();

            // remove items with area/map limitations (delete only for alive player to allow back in ghost mode)
            // if player resurrected at teleport this will be applied in resurrect code
            if (IsAlive())
            {
                DestroyZoneLimitedItem(true, newZone);
            }

            // check some item equip limitations (in result lost CanTitanGrip at talent reset, for example)
            AutoUnequipOffhandIfNeed();

            // recent client version not send leave/join channel packets for built-in local channels
            UpdateLocalChannels(newZone);

            UpdateZoneDependentAuras(newZone);
        }
Exemplo n.º 18
0
        public void UpdateZone(uint newZone, uint newArea)
        {
            if (!IsInWorld)
            {
                return;
            }

            uint oldZone = m_zoneUpdateId;

            m_zoneUpdateId    = newZone;
            m_zoneUpdateTimer = 1 * Time.InMilliseconds;

            GetMap().UpdatePlayerZoneStats(oldZone, newZone);

            // call leave script hooks immedately (before updating flags)
            if (oldZone != newZone)
            {
                Global.OutdoorPvPMgr.HandlePlayerLeaveZone(this, oldZone);
                Global.BattleFieldMgr.HandlePlayerLeaveZone(this, oldZone);
            }

            // group update
            if (GetGroup())
            {
                SetGroupUpdateFlag(GroupUpdateFlags.Full);

                Pet pet = GetPet();
                if (pet)
                {
                    pet.SetGroupUpdateFlag(GroupUpdatePetFlags.Full);
                }
            }

            // zone changed, so area changed as well, update it
            UpdateArea(newArea);

            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(newZone);

            if (zone == null)
            {
                return;
            }

            if (WorldConfig.GetBoolValue(WorldCfg.Weather))
            {
                GetMap().GetOrGenerateZoneDefaultWeather(newZone);
            }

            GetMap().SendZoneDynamicInfo(newZone, this);

            UpdateHostileAreaState(zone);

            if (zone.HasFlag(AreaFlags.Capital))                     // Is in a capital city
            {
                if (!pvpInfo.IsInHostileArea || zone.IsSanctuary())
                {
                    _restMgr.SetRestFlag(RestFlag.City);
                }
                pvpInfo.IsInNoPvPArea = true;
            }
            else
            {
                _restMgr.RemoveRestFlag(RestFlag.City);
            }

            UpdatePvPState();

            // remove items with area/map limitations (delete only for alive player to allow back in ghost mode)
            // if player resurrected at teleport this will be applied in resurrect code
            if (IsAlive())
            {
                DestroyZoneLimitedItem(true, newZone);
            }

            // check some item equip limitations (in result lost CanTitanGrip at talent reset, for example)
            AutoUnequipOffhandIfNeed();

            // recent client version not send leave/join channel packets for built-in local channels
            UpdateLocalChannels(newZone);

            UpdateZoneDependentAuras(newZone);

            // call enter script hooks after everyting else has processed
            Global.ScriptMgr.OnPlayerUpdateZone(this, newZone, newArea);
            if (oldZone != newZone)
            {
                Global.OutdoorPvPMgr.HandlePlayerEnterZone(this, newZone);
                Global.BattleFieldMgr.HandlePlayerEnterZone(this, newZone);
                SendInitWorldStates(newZone, newArea);              // only if really enters to new zone, not just area change, works strange...
                Guild guild = GetGuild();
                if (guild)
                {
                    guild.UpdateMemberData(this, GuildMemberData.ZoneId, newZone);
                }
            }
        }
Exemplo n.º 19
0
        public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null)
        {
            Channel result = null;

            if (channelId != 0) // builtin
            {
                var channel = _channels.LookupByKey(CreateBuiltinChannelGuid(channelId, zoneEntry));
                if (channel != null)
                {
                    result = channel;
                }
            }
            else // custom
            {
                var channel = _customChannels.LookupByKey(name.ToLower());
                if (channel != null)
                {
                    result = channel;
                }
            }

            if (result == null && notify)
            {
                string channelName = name;
                Channel.GetChannelName(ref channelName, channelId, player.GetSession().GetSessionDbcLocale(), zoneEntry);

                SendNotOnChannelNotify(player, channelName);
            }

            return(result);
        }
Exemplo n.º 20
0
        public void UpdateHostileAreaState(AreaTableRecord area)
        {
            ZonePVPTypeOverride overrideZonePvpType = GetOverrideZonePVPType();

            pvpInfo.IsInHostileArea = false;

            if (area.IsSanctuary()) // sanctuary and arena cannot be overriden
            {
                pvpInfo.IsInHostileArea = false;
            }
            else if (area.HasFlag(AreaFlags.Arena))
            {
                pvpInfo.IsInHostileArea = true;
            }
            else if (overrideZonePvpType == ZonePVPTypeOverride.None)
            {
                if (area != null)
                {
                    if (InBattleground() || area.HasFlag(AreaFlags.Combat) || (area.PvpCombatWorldStateID != -1 && Global.WorldMgr.GetWorldState((WorldStates)area.PvpCombatWorldStateID) != 0))
                    {
                        pvpInfo.IsInHostileArea = true;
                    }
                    else if (Global.WorldMgr.IsPvPRealm() || area.HasFlag(AreaFlags.Unk3))
                    {
                        if (area.HasFlag(AreaFlags.ContestedArea))
                        {
                            pvpInfo.IsInHostileArea = Global.WorldMgr.IsPvPRealm();
                        }
                        else
                        {
                            FactionTemplateRecord factionTemplate = GetFactionTemplateEntry();
                            if (factionTemplate == null || factionTemplate.FriendGroup.HasAnyFlag(area.FactionGroupMask))
                            {
                                pvpInfo.IsInHostileArea = false;
                            }
                            else if (factionTemplate.EnemyGroup.HasAnyFlag(area.FactionGroupMask))
                            {
                                pvpInfo.IsInHostileArea = true;
                            }
                            else
                            {
                                pvpInfo.IsInHostileArea = Global.WorldMgr.IsPvPRealm();
                            }
                        }
                    }
                }
            }
            else
            {
                switch (overrideZonePvpType)
                {
                case ZonePVPTypeOverride.Friendly:
                    pvpInfo.IsInHostileArea = false;
                    break;

                case ZonePVPTypeOverride.Hostile:
                case ZonePVPTypeOverride.Contested:
                case ZonePVPTypeOverride.Combat:
                    pvpInfo.IsInHostileArea = true;
                    break;

                default:
                    break;
                }
            }

            // Treat players having a quest flagging for PvP as always in hostile area
            pvpInfo.IsHostile = pvpInfo.IsInHostileArea || HasPvPForcingQuest();
        }
Exemplo n.º 21
0
        public static void OnAreaChange(WorldObject obj)
        {
            PhaseShift          phaseShift           = obj.GetPhaseShift();
            PhaseShift          suppressedPhaseShift = obj.GetSuppressedPhaseShift();
            var                 oldPhases            = phaseShift.GetPhases(); // for comparison
            ConditionSourceInfo srcInfo = new ConditionSourceInfo(obj);

            obj.GetPhaseShift().ClearPhases();
            obj.GetSuppressedPhaseShift().ClearPhases();

            uint            areaId    = obj.GetAreaId();
            AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);

            while (areaEntry != null)
            {
                var newAreaPhases = Global.ObjectMgr.GetPhasesForArea(areaEntry.Id);
                if (!newAreaPhases.Empty())
                {
                    foreach (PhaseAreaInfo phaseArea in newAreaPhases)
                    {
                        if (phaseArea.SubAreaExclusions.Contains(areaId))
                        {
                            continue;
                        }

                        uint phaseId = phaseArea.PhaseInfo.Id;
                        if (Global.ConditionMgr.IsObjectMeetToConditions(srcInfo, phaseArea.Conditions))
                        {
                            phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), phaseArea.Conditions);
                        }
                        else
                        {
                            suppressedPhaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), phaseArea.Conditions);
                        }
                    }
                }

                areaEntry = CliDB.AreaTableStorage.LookupByKey(areaEntry.ParentAreaID);
            }

            bool changed = phaseShift.GetPhases() != oldPhases;
            Unit unit    = obj.ToUnit();

            if (unit)
            {
                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.Phase))
                {
                    uint phaseId = (uint)aurEff.GetMiscValueB();
                    changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null) || changed;
                }

                foreach (AuraEffect aurEff in unit.GetAuraEffectsByType(AuraType.PhaseGroup))
                {
                    var phasesInGroup = Global.DB2Mgr.GetPhasesForGroup((uint)aurEff.GetMiscValueB());
                    foreach (uint phaseId in phasesInGroup)
                    {
                        changed = phaseShift.AddPhase(phaseId, GetPhaseFlags(phaseId), null) || changed;
                    }
                }

                if (changed)
                {
                    unit.OnPhaseChange();
                }

                ForAllControlled(unit, controlled =>
                {
                    InheritPhaseShift(controlled, unit);
                });

                if (changed)
                {
                    unit.RemoveNotOwnSingleTargetAuras(true);
                }
            }

            UpdateVisibilityIfNeeded(obj, true, changed);
        }
Exemplo n.º 22
0
        static bool HandleGoZoneXYCommand(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player player = handler.GetSession().GetPlayer();

            if (!float.TryParse(args.NextString(), out float x))
            {
                return(false);
            }

            if (!float.TryParse(args.NextString(), out float y))
            {
                return(false);
            }

            // prevent accept wrong numeric args
            if (x == 0.0f || y == 0.0f)
            {
                return(false);
            }

            string idStr = handler.extractKeyFromLink(args, "Harea");       // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r

            if (!uint.TryParse(idStr, out uint areaId))
            {
                areaId = player.GetZoneId();
            }

            AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(areaId);

            if (x < 0 || x > 100 || y < 0 || y > 100 || areaEntry == null)
            {
                handler.SendSysMessage(CypherStrings.InvalidZoneCoord, x, y, areaId);
                return(false);
            }

            // update to parent zone if exist (client map show only zones without parents)
            AreaTableRecord zoneEntry = areaEntry.ParentAreaID != 0 ? CliDB.AreaTableStorage.LookupByKey(areaEntry.ParentAreaID) : areaEntry;

            Cypher.Assert(zoneEntry != null);

            Map map = Global.MapMgr.CreateBaseMap(zoneEntry.ContinentID);

            if (map.Instanceable())
            {
                handler.SendSysMessage(CypherStrings.InvalidZoneMap, areaId, areaEntry.AreaName[handler.GetSessionDbcLocale()], map.GetId(), map.GetMapName());
                return(false);
            }

            Global.DB2Mgr.Zone2MapCoordinates(areaEntry.ParentAreaID != 0 ? areaEntry.ParentAreaID : areaId, ref x, ref y);

            if (!GridDefines.IsValidMapCoord(zoneEntry.ContinentID, x, y))
            {
                handler.SendSysMessage(CypherStrings.InvalidTargetCoord, x, y, zoneEntry.ContinentID);
                return(false);
            }

            // stop flight if need
            if (player.IsInFlight())
            {
                player.GetMotionMaster().MovementExpired();
                player.CleanupAfterTaxiFlight();
            }
            // save only in non-flight case
            else
            {
                player.SaveRecallPosition();
            }

            float z = Math.Max(map.GetStaticHeight(PhasingHandler.EmptyPhaseShift, x, y, MapConst.MaxHeight), map.GetWaterLevel(PhasingHandler.EmptyPhaseShift, x, y));

            player.TeleportTo(zoneEntry.ContinentID, x, y, z, player.GetOrientation());
            return(true);
        }
Exemplo n.º 23
0
        void HandleJoinChannel(JoinChannel packet)
        {
            AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(GetPlayer().GetZoneId());

            if (packet.ChatChannelId != 0)
            {
                ChatChannelsRecord channel = CliDB.ChatChannelsStorage.LookupByKey(packet.ChatChannelId);
                if (channel == null)
                {
                    return;
                }

                if (zone == null || !GetPlayer().CanJoinConstantChannelInZone(channel, zone))
                {
                    return;
                }
            }

            if (packet.ChannelName.IsEmpty() || char.IsDigit(packet.ChannelName[0]))
            {
                ChannelNotify channelNotify = new();
                channelNotify.Type    = ChatNotify.InvalidNameNotice;
                channelNotify.Channel = packet.ChannelName;
                SendPacket(channelNotify);
                return;
            }

            if (packet.Password.Length > 127)
            {
                Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a password more than 127 characters long - blocked");
                return;
            }

            ChannelManager cMgr = ChannelManager.ForTeam(GetPlayer().GetTeam());

            if (cMgr != null)
            {
                if (packet.ChatChannelId != 0)
                {
                    // system channel
                    Channel channel = cMgr.GetSystemChannel((uint)packet.ChatChannelId, zone);
                    if (channel != null)
                    {
                        channel.JoinChannel(GetPlayer());
                    }
                }
                else
                {
                    // custom channel
                    if (packet.ChannelName.Length > 31)
                    {
                        Log.outError(LogFilter.Network, $"Player {GetPlayer().GetGUID()} tried to create a channel with a name more than 31 characters long - blocked");
                        return;
                    }

                    Channel channel = cMgr.GetCustomChannel(packet.ChannelName);
                    if (channel != null)
                    {
                        channel.JoinChannel(GetPlayer(), packet.Password);
                    }
                    else
                    {
                        channel = cMgr.CreateCustomChannel(packet.ChannelName);
                        if (channel != null)
                        {
                            channel.SetPassword(packet.Password);
                            channel.JoinChannel(GetPlayer(), packet.Password);
                        }
                    }
                }
            }
        }
Exemplo n.º 24
0
            static bool HandleChannelSetOwnership(StringArguments args, CommandHandler handler)
            {
                if (args.Empty())
                {
                    return(false);
                }

                string channelStr = args.NextString();
                string argStr     = args.NextString("");

                if (channelStr.IsEmpty() || argStr.IsEmpty())
                {
                    return(false);
                }

                uint channelId = 0;

                foreach (var channelEntry in CliDB.ChatChannelsStorage.Values)
                {
                    if (channelEntry.Name[handler.GetSessionDbcLocale()].Equals(channelStr))
                    {
                        channelId = channelEntry.Id;
                        break;
                    }
                }

                AreaTableRecord zoneEntry = null;

                foreach (var entry in CliDB.AreaTableStorage.Values)
                {
                    if (entry.AreaName[handler.GetSessionDbcLocale()].Equals(channelStr))
                    {
                        zoneEntry = entry;
                        break;
                    }
                }

                Player  player  = handler.GetSession().GetPlayer();
                Channel channel = null;

                ChannelManager cMgr = ChannelManager.ForTeam(player.GetTeam());

                if (cMgr != null)
                {
                    channel = cMgr.GetChannel(channelId, channelStr, player, false, zoneEntry);
                }

                if (argStr.ToLower() == "on")
                {
                    if (channel != null)
                    {
                        channel.SetOwnership(true);
                    }
                    PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP);
                    stmt.AddValue(0, 1);
                    stmt.AddValue(1, channelStr);
                    DB.Characters.Execute(stmt);
                    handler.SendSysMessage(CypherStrings.ChannelEnableOwnership, channelStr);
                }
                else if (argStr.ToLower() == "off")
                {
                    if (channel != null)
                    {
                        channel.SetOwnership(false);
                    }
                    PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.UPD_CHANNEL_OWNERSHIP);
                    stmt.AddValue(0, 0);
                    stmt.AddValue(1, channelStr);
                    DB.Characters.Execute(stmt);
                    handler.SendSysMessage(CypherStrings.ChannelDisableOwnership, channelStr);
                }
                else
                {
                    return(false);
                }

                return(true);
            }
Exemplo n.º 25
0
        static string GetZoneName(uint zoneId, Locale locale)
        {
            AreaTableRecord zoneEntry = CliDB.AreaTableStorage.LookupByKey(zoneId);

            return(zoneEntry != null ? zoneEntry.AreaName[locale] : "<unknown zone>");
        }
Exemplo n.º 26
0
        void HandleWho(WhoRequestPkt whoRequest)
        {
            WhoRequest request = whoRequest.Request;

            // zones count, client limit = 10 (2.0.10)
            // can't be received from real client or broken packet
            if (whoRequest.Areas.Count > 10)
            {
                return;
            }

            // user entered strings count, client limit=4 (checked on 2.0.10)
            // can't be received from real client or broken packet
            if (request.Words.Count > 4)
            {
                return;
            }

            // @todo: handle following packet values
            // VirtualRealmNames
            // ShowEnemies
            // ShowArenaPlayers
            // ExactName
            // ServerInfo

            request.Words.ForEach(p => p = p.ToLower());

            request.Name  = request.Name.ToLower();
            request.Guild = request.Guild.ToLower();

            // client send in case not set max level value 100 but we support 255 max level,
            // update it to show GMs with characters after 100 level
            if (whoRequest.Request.MaxLevel >= 100)
            {
                whoRequest.Request.MaxLevel = 255;
            }

            var team = GetPlayer().GetTeam();

            uint gmLevelInWhoList = WorldConfig.GetUIntValue(WorldCfg.GmLevelInWhoList);

            WhoResponsePkt response = new WhoResponsePkt();

            foreach (var target in Global.ObjAccessor.GetPlayers())
            {
                // player can see member of other team only if CONFIG_ALLOW_TWO_SIDE_WHO_LIST
                if (target.GetTeam() != team && !HasPermission(RBACPermissions.TwoSideWhoList))
                {
                    continue;
                }

                // player can see MODERATOR, GAME MASTER, ADMINISTRATOR only if CONFIG_GM_IN_WHO_LIST
                if (target.GetSession().GetSecurity() > (AccountTypes)gmLevelInWhoList && !HasPermission(RBACPermissions.WhoSeeAllSecLevels))
                {
                    continue;
                }

                // do not process players which are not in world
                if (!target.IsInWorld)
                {
                    continue;
                }

                // check if target is globally visible for player
                if (!target.IsVisibleGloballyFor(GetPlayer()))
                {
                    continue;
                }

                // check if target's level is in level range
                uint lvl = target.getLevel();
                if (lvl < request.MinLevel || lvl > request.MaxLevel)
                {
                    continue;
                }

                // check if class matches classmask
                int class_ = (byte)target.GetClass();
                if (!Convert.ToBoolean(request.ClassFilter & (1 << class_)))
                {
                    continue;
                }

                // check if race matches racemask
                int race = (int)target.GetRace();
                if (!Convert.ToBoolean(request.RaceFilter & (1 << race)))
                {
                    continue;
                }

                if (!whoRequest.Areas.Empty())
                {
                    if (whoRequest.Areas.Contains((int)target.GetZoneId()))
                    {
                        continue;
                    }
                }

                string wTargetName = target.GetName().ToLower();
                if (!string.IsNullOrEmpty(request.Name) && !wTargetName.Equals(request.Name))
                {
                    continue;
                }

                string wTargetGuildName = "";
                Guild  targetGuild      = target.GetGuild();
                if (targetGuild)
                {
                    wTargetGuildName = targetGuild.GetName().ToLower();
                }

                if (!string.IsNullOrEmpty(request.Guild) && !wTargetGuildName.Equals(request.Guild))
                {
                    continue;
                }

                if (!request.Words.Empty())
                {
                    string          aname     = "";
                    AreaTableRecord areaEntry = CliDB.AreaTableStorage.LookupByKey(target.GetZoneId());
                    if (areaEntry != null)
                    {
                        aname = areaEntry.AreaName[GetSessionDbcLocale()].ToLower();
                    }

                    bool show = false;
                    for (int i = 0; i < request.Words.Count; ++i)
                    {
                        if (!string.IsNullOrEmpty(request.Words[i]))
                        {
                            if (wTargetName.Equals(request.Words[i]) ||
                                wTargetGuildName.Equals(request.Words[i]) ||
                                aname.Equals(request.Words[i]))
                            {
                                show = true;
                                break;
                            }
                        }
                    }

                    if (!show)
                    {
                        continue;
                    }
                }

                WhoEntry whoEntry = new WhoEntry();
                if (!whoEntry.PlayerData.Initialize(target.GetGUID(), target))
                {
                    continue;
                }

                if (targetGuild)
                {
                    whoEntry.GuildGUID = targetGuild.GetGUID();
                    whoEntry.GuildVirtualRealmAddress = Global.WorldMgr.GetVirtualRealmAddress();
                    whoEntry.GuildName = targetGuild.GetName();
                }

                whoEntry.AreaID = (int)target.GetZoneId();
                whoEntry.IsGM   = target.IsGameMaster();

                response.Response.Add(whoEntry);

                // 50 is maximum player count sent to client
                if (response.Response.Count >= 50)
                {
                    break;
                }
            }

            SendPacket(response);
        }
Exemplo n.º 27
0
        static bool HandleGroupListCommand(StringArguments args, CommandHandler handler)
        {
            // Get ALL the variables!
            Player     playerTarget;
            ObjectGuid guidTarget;
            string     nameTarget;
            string     zoneName    = "";
            string     onlineState = "";

            // Parse the guid to uint32...
            ObjectGuid parseGUID = ObjectGuid.Create(HighGuid.Player, args.NextUInt64());

            // ... and try to extract a player out of it.
            if (Global.CharacterCacheStorage.GetCharacterNameByGuid(parseGUID, out nameTarget))
            {
                playerTarget = Global.ObjAccessor.FindPlayer(parseGUID);
                guidTarget   = parseGUID;
            }
            // If not, we return false and end right away.
            else if (!handler.extractPlayerTarget(args, out playerTarget, out guidTarget, out nameTarget))
            {
                return(false);
            }

            // Next, we need a group. So we define a group variable.
            Group groupTarget = null;

            // We try to extract a group from an online player.
            if (playerTarget)
            {
                groupTarget = playerTarget.GetGroup();
            }

            // If not, we extract it from the SQL.
            if (!groupTarget)
            {
                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GROUP_MEMBER);
                stmt.AddValue(0, guidTarget.GetCounter());
                SQLResult resultGroup = DB.Characters.Query(stmt);
                if (!resultGroup.IsEmpty())
                {
                    groupTarget = Global.GroupMgr.GetGroupByDbStoreId(resultGroup.Read <uint>(0));
                }
            }

            // If both fails, players simply has no party. Return false.
            if (!groupTarget)
            {
                handler.SendSysMessage(CypherStrings.GroupNotInGroup, nameTarget);
                return(false);
            }

            // We get the group members after successfully detecting a group.
            var members = groupTarget.GetMemberSlots();

            // To avoid a cluster f**k, namely trying multiple queries to simply get a group member count...
            handler.SendSysMessage(CypherStrings.GroupType, (groupTarget.isRaidGroup() ? "raid" : "party"), members.Count);
            // ... we simply move the group type and member count print after retrieving the slots and simply output it's size.

            // While rather dirty codestyle-wise, it saves space (if only a little). For each member, we look several informations up.
            foreach (var slot in members)
            {
                // Check for given flag and assign it to that iterator
                string flags = "";
                if (slot.flags.HasAnyFlag(GroupMemberFlags.Assistant))
                {
                    flags = "Assistant";
                }

                if (slot.flags.HasAnyFlag(GroupMemberFlags.MainTank))
                {
                    if (!string.IsNullOrEmpty(flags))
                    {
                        flags += ", ";
                    }
                    flags += "MainTank";
                }

                if (slot.flags.HasAnyFlag(GroupMemberFlags.MainAssist))
                {
                    if (!string.IsNullOrEmpty(flags))
                    {
                        flags += ", ";
                    }
                    flags += "MainAssist";
                }

                if (string.IsNullOrEmpty(flags))
                {
                    flags = "None";
                }

                // Check if iterator is online. If is...
                Player p      = Global.ObjAccessor.FindPlayer(slot.guid);
                string phases = "";
                if (p && p.IsInWorld)
                {
                    // ... than, it prints information like "is online", where he is, etc...
                    onlineState = "online";
                    phases      = PhasingHandler.FormatPhases(p.GetPhaseShift());

                    AreaTableRecord area = CliDB.AreaTableStorage.LookupByKey(p.GetAreaId());
                    if (area != null)
                    {
                        AreaTableRecord zone = CliDB.AreaTableStorage.LookupByKey(area.ParentAreaID);
                        if (zone != null)
                        {
                            zoneName = zone.AreaName[handler.GetSessionDbcLocale()];
                        }
                    }
                }
                else
                {
                    // ... else, everything is set to offline or neutral values.
                    zoneName    = "<ERROR>";
                    onlineState = "Offline";
                }

                // Now we can print those informations for every single member of each group!
                handler.SendSysMessage(CypherStrings.GroupPlayerNameGuid, slot.name, onlineState,
                                       zoneName, phases, slot.guid.ToString(), flags, LFGQueue.GetRolesString(slot.roles));
            }

            // And finish after every iterator is done.
            return(true);
        }
Exemplo n.º 28
0
 public AreaListBoxItem(AreaTableRecord record)
 {
     Name   = record.AreaName;
     AreaID = record.ID;
     MapId  = record.ContinentID;
 }
Exemplo n.º 29
0
        public Channel GetChannel(uint channelId, string name, Player player, bool notify = true, AreaTableRecord zoneEntry = null)
        {
            Channel result = null;

            if (channelId != 0) // builtin
            {
                ChatChannelsRecord channelEntry = CliDB.ChatChannelsStorage.LookupByKey(channelId);
                uint zoneId = zoneEntry != null ? zoneEntry.Id : 0;
                if (channelEntry.Flags.HasAnyFlag(ChannelDBCFlags.Global | ChannelDBCFlags.CityOnly))
                {
                    zoneId = 0;
                }

                Tuple <uint, uint> key = Tuple.Create(channelId, zoneId);
                var channel            = _channels.LookupByKey(key);
                if (channel != null)
                {
                    result = channel;
                }
            }
            else // custom
            {
                var channel = _customChannels.LookupByKey(name.ToLower());
                if (channel != null)
                {
                    result = channel;
                }
            }

            if (result == null && notify)
            {
                string channelName = name;
                Channel.GetChannelName(ref channelName, channelId, player.GetSession().GetSessionDbcLocale(), zoneEntry);

                SendNotOnChannelNotify(player, channelName);
            }

            return(result);
        }