Esempio n. 1
0
        public bool HasLowerSecurity(Player target, ObjectGuid guid, bool strong = false)
        {
            WorldSession target_session = null;
            uint         target_account = 0;

            if (target != null)
            {
                target_session = target.GetSession();
            }
            else if (!guid.IsEmpty())
            {
                target_account = Global.CharacterCacheStorage.GetCharacterAccountIdByGuid(guid);
            }

            if (target_session == null && target_account == 0)
            {
                SendSysMessage(CypherStrings.PlayerNotFound);
                _sentErrorMessage = true;
                return(true);
            }

            return(HasLowerSecurityAccount(target_session, target_account, strong));
        }
Esempio n. 2
0
        public void SetOwner(ObjectGuid guid, bool exclaim = true)
        {
            if (!_ownerGuid.IsEmpty())
            {
                // [] will re-add player after it possible removed
                var playerInfo = _playersStore.LookupByKey(_ownerGuid);
                if (playerInfo != null)
                {
                    playerInfo.SetOwner(false);
                }
            }

            _ownerGuid = guid;
            if (!_ownerGuid.IsEmpty())
            {
                ChannelMemberFlags oldFlag = GetPlayerFlags(_ownerGuid);
                var playerInfo             = _playersStore.LookupByKey(_ownerGuid);
                if (playerInfo == null)
                {
                    return;
                }

                playerInfo.SetModerator(true);
                playerInfo.SetOwner(true);

                ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(_ownerGuid, oldFlag, GetPlayerFlags(_ownerGuid)));
                SendToAll(builder);

                if (exclaim)
                {
                    ChannelNameBuilder ownerChangedBuilder = new ChannelNameBuilder(this, new OwnerChangedAppend(_ownerGuid));
                    SendToAll(ownerChangedBuilder);
                }

                UpdateChannelInDB();
            }
        }
Esempio n. 3
0
        void HandleCalendarInvite(CalendarInvitePkt calendarInvite)
        {
            ObjectGuid playerGuid = GetPlayer().GetGUID();

            ObjectGuid inviteeGuid    = ObjectGuid.Empty;
            Team       inviteeTeam    = 0;
            ulong      inviteeGuildId = 0;

            if (!ObjectManager.NormalizePlayerName(ref calendarInvite.Name))
            {
                return;
            }

            Player player = Global.ObjAccessor.FindPlayerByName(calendarInvite.Name);

            if (player)
            {
                // Invitee is online
                inviteeGuid    = player.GetGUID();
                inviteeTeam    = player.GetTeam();
                inviteeGuildId = player.GetGuildId();
            }
            else
            {
                // Invitee offline, get data from database
                ObjectGuid guid = Global.CharacterCacheStorage.GetCharacterGuidByName(calendarInvite.Name);
                if (!guid.IsEmpty())
                {
                    CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(guid);
                    if (characterInfo != null)
                    {
                        inviteeGuid    = guid;
                        inviteeTeam    = Player.TeamForRace(characterInfo.RaceId);
                        inviteeGuildId = characterInfo.GuildId;
                    }
                }
            }

            if (inviteeGuid.IsEmpty())
            {
                Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.PlayerNotFound);
                return;
            }

            if (GetPlayer().GetTeam() != inviteeTeam && !WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionCalendar))
            {
                Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NotAllied);
                return;
            }

            SQLResult result1 = DB.Characters.Query("SELECT flags FROM character_social WHERE guid = {0} AND friend = {1}", inviteeGuid, playerGuid);

            if (!result1.IsEmpty())
            {
                if (Convert.ToBoolean(result1.Read <byte>(0) & (byte)SocialFlag.Ignored))
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.IgnoringYouS, calendarInvite.Name);
                    return;
                }
            }

            if (!calendarInvite.Creating)
            {
                CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarInvite.EventID);
                if (calendarEvent != null)
                {
                    if (calendarEvent.IsGuildEvent() && calendarEvent.GuildId == inviteeGuildId)
                    {
                        // we can't invite guild members to guild events
                        Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
                        return;
                    }

                    CalendarInvite invite = new(Global.CalendarMgr.GetFreeInviteId(), calendarInvite.EventID, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
                    Global.CalendarMgr.AddInvite(calendarEvent, invite);
                }
                else
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid);
                }
            }
            else
            {
                if (calendarInvite.IsSignUp && inviteeGuildId == GetPlayer().GetGuildId())
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
                    return;
                }

                CalendarInvite invite = new(calendarInvite.EventID, 0, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
                Global.CalendarMgr.SendCalendarEventInvite(invite);
            }
        }
Esempio n. 4
0
        void KickOrBan(Player player, string badname, bool ban)
        {
            ObjectGuid good = player.GetGUID();

            if (!IsOn(good))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
                SendToOne(builder, good);
                return;
            }

            PlayerInfo info = _playersStore.LookupByKey(good);

            if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
                SendToOne(builder, good);
                return;
            }

            Player     bad    = Global.ObjAccessor.FindPlayerByName(badname);
            ObjectGuid victim = bad ? bad.GetGUID() : ObjectGuid.Empty;

            if (victim.IsEmpty() || !IsOn(victim))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(badname));
                SendToOne(builder, good);
                return;
            }

            bool changeowner = _ownerGuid == victim;

            if (!player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator) && changeowner && good != _ownerGuid)
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotOwnerAppend());
                SendToOne(builder, good);
                return;
            }

            if (ban && !IsBanned(victim))
            {
                _bannedStore.Add(victim);
                UpdateChannelInDB();

                if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
                {
                    ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerBannedAppend(good, victim));
                    SendToAll(builder);
                }
            }
            else if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerKickedAppend(good, victim));
                SendToAll(builder);
            }

            _playersStore.Remove(victim);
            bad.LeftChannel(this);

            if (changeowner && _ownershipEnabled && !_playersStore.Empty())
            {
                info.SetModerator(true);
                SetOwner(good);
            }
        }
Esempio n. 5
0
        public void LeaveChannel(Player player, bool send = true)
        {
            ObjectGuid guid = player.GetGUID();

            if (!IsOn(guid))
            {
                if (send)
                {
                    var builder = new ChannelNameBuilder(this, new NotMemberAppend());
                    SendToOne(builder, guid);
                }
                return;
            }

            player.LeftChannel(this);

            if (send)
            {
                /*
                 * ChannelNameBuilder<YouLeftAppend> builder = new ChannelNameBuilder(this, new YouLeftAppend());
                 * SendToOne(builder, guid);
                 */

                SendToOne(new ChannelNotifyLeftBuilder(this), guid);
            }

            PlayerInfo info        = _playersStore.LookupByKey(guid);
            bool       changeowner = info.IsOwner();

            _playersStore.Remove(guid);

            if (_announceEnabled && !player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
            {
                var builder = new ChannelNameBuilder(this, new LeftAppend(guid));
                SendToAll(builder);
            }

            LeaveNotify(player);

            if (!IsConstant())
            {
                // Update last_used timestamp in db
                UpdateChannelUseageInDB();

                // If the channel owner left and there are still playersStore inside, pick a new owner
                // do not pick invisible gm owner unless there are only invisible gms in that channel (rare)
                if (changeowner && _ownershipEnabled && !_playersStore.Empty())
                {
                    ObjectGuid newowner = ObjectGuid.Empty;
                    foreach (var key in _playersStore.Keys)
                    {
                        if (!_playersStore[key].IsInvisible())
                        {
                            newowner = key;
                            break;
                        }
                    }

                    if (newowner.IsEmpty())
                    {
                        newowner = _playersStore.First().Key;
                    }

                    _playersStore[newowner].SetModerator(true);

                    SetOwner(newowner);

                    // if the new owner is invisible gm, set flag to automatically choose a new owner
                    if (_playersStore[newowner].IsInvisible())
                    {
                        _isOwnerInvisible = true;
                    }
                }
            }
        }
Esempio n. 6
0
        public ulong ExtractLowGuidFromLink(StringArguments args, ref HighGuid guidHigh)
        {
            int type;

            string[] guidKeys =
            {
                "Hplayer",
                "Hcreature",
                "Hgameobject"
            };
            // |color|Hcreature:creature_guid|h[name]|h|r
            // |color|Hgameobject:go_guid|h[name]|h|r
            // |color|Hplayer:name|h[name]|h|r
            string idS = ExtractKeyFromLink(args, guidKeys, out type);

            if (string.IsNullOrEmpty(idS))
            {
                return(0);
            }

            switch (type)
            {
            case 0:
            {
                guidHigh = HighGuid.Player;
                if (!ObjectManager.NormalizePlayerName(ref idS))
                {
                    return(0);
                }

                Player player = Global.ObjAccessor.FindPlayerByName(idS);
                if (player)
                {
                    return(player.GetGUID().GetCounter());
                }

                ObjectGuid guid = Global.CharacterCacheStorage.GetCharacterGuidByName(idS);
                if (guid.IsEmpty())
                {
                    return(0);
                }

                return(guid.GetCounter());
            }

            case 1:
            {
                guidHigh = HighGuid.Creature;
                if (!ulong.TryParse(idS, out ulong lowguid))
                {
                    return(0);
                }
                return(lowguid);
            }

            case 2:
            {
                guidHigh = HighGuid.GameObject;
                if (!ulong.TryParse(idS, out ulong lowguid))
                {
                    return(0);
                }
                return(lowguid);
            }
            }

            // unknown type?
            return(0);
        }
Esempio n. 7
0
        void HandleCalendarEventInvite(CalendarEventInvite calendarEventInvite)
        {
            ObjectGuid playerGuid = GetPlayer().GetGUID();

            ObjectGuid inviteeGuid    = ObjectGuid.Empty;
            Team       inviteeTeam    = 0;
            ulong      inviteeGuildId = 0;

            Player player = Global.ObjAccessor.FindPlayerByName(calendarEventInvite.Name);

            if (player)
            {
                // Invitee is online
                inviteeGuid    = player.GetGUID();
                inviteeTeam    = player.GetTeam();
                inviteeGuildId = player.GetGuildId();
            }
            else
            {
                // Invitee offline, get data from database
                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_GUID_RACE_ACC_BY_NAME);
                stmt.AddValue(0, calendarEventInvite.Name);
                SQLResult result = DB.Characters.Query(stmt);
                if (!result.IsEmpty())
                {
                    inviteeGuid    = ObjectGuid.Create(HighGuid.Player, result.Read <ulong>(0));
                    inviteeTeam    = Player.TeamForRace((Race)result.Read <byte>(1));
                    inviteeGuildId = Player.GetGuildIdFromDB(inviteeGuid);
                }
            }

            if (inviteeGuid.IsEmpty())
            {
                Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.PlayerNotFound);
                return;
            }

            if (GetPlayer().GetTeam() != inviteeTeam && !WorldConfig.GetBoolValue(WorldCfg.AllowTwoSideInteractionCalendar))
            {
                Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NotAllied);
                return;
            }

            SQLResult result1 = DB.Characters.Query("SELECT flags FROM character_social WHERE guid = {0} AND friend = {1}", inviteeGuid, playerGuid);

            if (!result1.IsEmpty())
            {
                if (Convert.ToBoolean(result1.Read <byte>(0) & (byte)SocialFlag.Ignored))
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.IgnoringYouS, calendarEventInvite.Name);
                    return;
                }
            }

            if (!calendarEventInvite.Creating)
            {
                CalendarEvent calendarEvent = Global.CalendarMgr.GetEvent(calendarEventInvite.EventID);
                if (calendarEvent != null)
                {
                    if (calendarEvent.IsGuildEvent() && calendarEvent.GuildId == inviteeGuildId)
                    {
                        // we can't invite guild members to guild events
                        Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
                        return;
                    }

                    CalendarInvite invite = new CalendarInvite(Global.CalendarMgr.GetFreeInviteId(), calendarEventInvite.EventID, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
                    Global.CalendarMgr.AddInvite(calendarEvent, invite);
                }
                else
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.EventInvalid);
                }
            }
            else
            {
                if (calendarEventInvite.IsSignUp && inviteeGuildId == GetPlayer().GetGuildId())
                {
                    Global.CalendarMgr.SendCalendarCommandResult(playerGuid, CalendarError.NoGuildInvites);
                    return;
                }

                CalendarInvite invite = new CalendarInvite(calendarEventInvite.EventID, 0, inviteeGuid, playerGuid, SharedConst.CalendarDefaultResponseTime, CalendarInviteStatus.Invited, CalendarModerationRank.Player, "");
                Global.CalendarMgr.SendCalendarEventInvite(invite);
            }
        }
Esempio n. 8
0
 public bool IsAssigned()
 {
     return(!_assignedTo.IsEmpty());
 }
Esempio n. 9
0
 public bool IsClosed()
 {
     return(!_closedBy.IsEmpty());
 }
Esempio n. 10
0
        void HandlePetActionHelper(Unit pet, ObjectGuid guid1, uint spellid, ActiveStates flag, ObjectGuid guid2, float x, float y, float z)
        {
            CharmInfo charmInfo = pet.GetCharmInfo();

            if (charmInfo == null)
            {
                Log.outError(LogFilter.Network, "WorldSession.HandlePetAction(petGuid: {0}, tagGuid: {1}, spellId: {2}, flag: {3}): object (GUID: {4} Entry: {5} TypeId: {6}) is considered pet-like but doesn't have a charminfo!",
                             guid1, guid2, spellid, flag, pet.GetGUID().ToString(), pet.GetEntry(), pet.GetTypeId());
                return;
            }

            switch (flag)
            {
            case ActiveStates.Command:                                       //0x07
                switch ((CommandStates)spellid)
                {
                case CommandStates.Stay:                                  //flat=1792  //STAY
                    pet.StopMoving();
                    pet.GetMotionMaster().Clear(false);
                    pet.GetMotionMaster().MoveIdle();
                    charmInfo.SetCommandState(CommandStates.Stay);

                    charmInfo.SetIsCommandAttack(false);
                    charmInfo.SetIsAtStay(true);
                    charmInfo.SetIsCommandFollow(false);
                    charmInfo.SetIsFollowing(false);
                    charmInfo.SetIsReturning(false);
                    charmInfo.SaveStayPosition();
                    break;

                case CommandStates.Follow:                                //spellid=1792  //FOLLOW
                    pet.AttackStop();
                    pet.InterruptNonMeleeSpells(false);
                    pet.GetMotionMaster().MoveFollow(GetPlayer(), SharedConst.PetFollowDist, pet.GetFollowAngle());
                    charmInfo.SetCommandState(CommandStates.Follow);

                    charmInfo.SetIsCommandAttack(false);
                    charmInfo.SetIsAtStay(false);
                    charmInfo.SetIsReturning(true);
                    charmInfo.SetIsCommandFollow(true);
                    charmInfo.SetIsFollowing(false);
                    break;

                case CommandStates.Attack:                                //spellid=1792  //ATTACK
                {
                    // Can't attack if owner is pacified
                    if (GetPlayer().HasAuraType(AuraType.ModPacify))
                    {
                        // @todo Send proper error message to client
                        return;
                    }

                    // only place where pet can be player
                    Unit TargetUnit = Global.ObjAccessor.GetUnit(GetPlayer(), guid2);
                    if (!TargetUnit)
                    {
                        return;
                    }

                    Unit owner = pet.GetOwner();
                    if (owner)
                    {
                        if (!owner.IsValidAttackTarget(TargetUnit))
                        {
                            return;
                        }
                    }

                    pet.ClearUnitState(UnitState.Follow);
                    // This is true if pet has no target or has target but targets differs.
                    if (pet.GetVictim() != TargetUnit || (pet.GetVictim() == TargetUnit && !pet.GetCharmInfo().IsCommandAttack()))
                    {
                        if (pet.GetVictim())
                        {
                            pet.AttackStop();
                        }

                        if (!pet.IsTypeId(TypeId.Player) && pet.ToCreature().IsAIEnabled)
                        {
                            charmInfo.SetIsCommandAttack(true);
                            charmInfo.SetIsAtStay(false);
                            charmInfo.SetIsFollowing(false);
                            charmInfo.SetIsCommandFollow(false);
                            charmInfo.SetIsReturning(false);

                            pet.ToCreature().GetAI().AttackStart(TargetUnit);

                            //10% chance to play special pet attack talk, else growl
                            if (pet.IsPet() && pet.ToPet().getPetType() == PetType.Summon && pet != TargetUnit && RandomHelper.IRand(0, 100) < 10)
                            {
                                pet.SendPetTalk(PetTalk.Attack);
                            }
                            else
                            {
                                // 90% chance for pet and 100% chance for charmed creature
                                pet.SendPetAIReaction(guid1);
                            }
                        }
                        else                                            // charmed player
                        {
                            if (pet.GetVictim() && pet.GetVictim() != TargetUnit)
                            {
                                pet.AttackStop();
                            }

                            charmInfo.SetIsCommandAttack(true);
                            charmInfo.SetIsAtStay(false);
                            charmInfo.SetIsFollowing(false);
                            charmInfo.SetIsCommandFollow(false);
                            charmInfo.SetIsReturning(false);

                            pet.Attack(TargetUnit, true);
                            pet.SendPetAIReaction(guid1);
                        }
                    }
                    break;
                }

                case CommandStates.Abandon:                               // abandon (hunter pet) or dismiss (summoned pet)
                    if (pet.GetCharmerGUID() == GetPlayer().GetGUID())
                    {
                        GetPlayer().StopCastingCharm();
                    }
                    else if (pet.GetOwnerGUID() == GetPlayer().GetGUID())
                    {
                        Cypher.Assert(pet.IsTypeId(TypeId.Unit));
                        if (pet.IsPet())
                        {
                            if (pet.ToPet().getPetType() == PetType.Hunter)
                            {
                                GetPlayer().RemovePet(pet.ToPet(), PetSaveMode.AsDeleted);
                            }
                            else
                            {
                                //dismissing a summoned pet is like killing them (this prevents returning a soulshard...)
                                pet.setDeathState(DeathState.Corpse);
                            }
                        }
                        else if (pet.HasUnitTypeMask(UnitTypeMask.Minion))
                        {
                            ((Minion)pet).UnSummon();
                        }
                    }
                    break;

                case CommandStates.MoveTo:
                    pet.StopMoving();
                    pet.GetMotionMaster().Clear(false);
                    pet.GetMotionMaster().MovePoint(0, x, y, z);
                    charmInfo.SetCommandState(CommandStates.MoveTo);

                    charmInfo.SetIsCommandAttack(false);
                    charmInfo.SetIsAtStay(true);
                    charmInfo.SetIsFollowing(false);
                    charmInfo.SetIsReturning(false);
                    charmInfo.SaveStayPosition();
                    break;

                default:
                    Log.outError(LogFilter.Network, "WORLD: unknown PET flag Action {0} and spellid {1}.", flag, spellid);
                    break;
                }
                break;

            case ActiveStates.Reaction:                                      // 0x6
                switch ((ReactStates)spellid)
                {
                case ReactStates.Passive:                                 //passive
                    pet.AttackStop();
                    goto case ReactStates.Defensive;

                case ReactStates.Defensive:                               //recovery
                case ReactStates.Aggressive:                              //activete
                    if (pet.IsTypeId(TypeId.Unit))
                    {
                        pet.ToCreature().SetReactState((ReactStates)spellid);
                    }
                    break;
                }
                break;

            case ActiveStates.Disabled:                                      // 0x81    spell (disabled), ignore
            case ActiveStates.Passive:                                       // 0x01
            case ActiveStates.Enabled:                                       // 0xC1    spell
            {
                Unit unit_target = null;

                if (!guid2.IsEmpty())
                {
                    unit_target = Global.ObjAccessor.GetUnit(GetPlayer(), guid2);
                }

                // do not cast unknown spells
                SpellInfo spellInfo = Global.SpellMgr.GetSpellInfo(spellid);
                if (spellInfo == null)
                {
                    Log.outError(LogFilter.Network, "WORLD: unknown PET spell id {0}", spellid);
                    return;
                }

                foreach (SpellEffectInfo effect in spellInfo.GetEffectsForDifficulty(Difficulty.None))
                {
                    if (effect != null && (effect.TargetA.GetTarget() == Targets.UnitSrcAreaEnemy || effect.TargetA.GetTarget() == Targets.UnitDestAreaEnemy || effect.TargetA.GetTarget() == Targets.DestDynobjEnemy))
                    {
                        return;
                    }
                }

                // do not cast not learned spells
                if (!pet.HasSpell(spellid) || spellInfo.IsPassive())
                {
                    return;
                }

                //  Clear the flags as if owner clicked 'attack'. AI will reset them
                //  after AttackStart, even if spell failed
                if (pet.GetCharmInfo() != null)
                {
                    pet.GetCharmInfo().SetIsAtStay(false);
                    pet.GetCharmInfo().SetIsCommandAttack(true);
                    pet.GetCharmInfo().SetIsReturning(false);
                    pet.GetCharmInfo().SetIsFollowing(false);
                }

                Spell spell = new Spell(pet, spellInfo, TriggerCastFlags.None);

                SpellCastResult result = spell.CheckPetCast(unit_target);

                //auto turn to target unless possessed
                if (result == SpellCastResult.UnitNotInfront && !pet.isPossessed() && !pet.IsVehicle())
                {
                    Unit unit_target2 = spell.m_targets.GetUnitTarget();
                    if (unit_target)
                    {
                        pet.SetInFront(unit_target);
                        Player player = unit_target.ToPlayer();
                        if (player)
                        {
                            pet.SendUpdateToPlayer(player);
                        }
                    }
                    else if (unit_target2)
                    {
                        pet.SetInFront(unit_target2);
                        Player player = unit_target2.ToPlayer();
                        if (player)
                        {
                            pet.SendUpdateToPlayer(player);
                        }
                    }
                    Unit powner = pet.GetCharmerOrOwner();
                    if (powner)
                    {
                        Player player = powner.ToPlayer();
                        if (player)
                        {
                            pet.SendUpdateToPlayer(player);
                        }
                    }

                    result = SpellCastResult.SpellCastOk;
                }

                if (result == SpellCastResult.SpellCastOk)
                {
                    unit_target = spell.m_targets.GetUnitTarget();

                    //10% chance to play special pet attack talk, else growl
                    //actually this only seems to happen on special spells, fire shield for imp, torment for voidwalker, but it's stupid to check every spell
                    if (pet.IsPet() && (pet.ToPet().getPetType() == PetType.Summon) && (pet != unit_target) && (RandomHelper.IRand(0, 100) < 10))
                    {
                        pet.SendPetTalk(PetTalk.SpecialSpell);
                    }
                    else
                    {
                        pet.SendPetAIReaction(guid1);
                    }

                    if (unit_target && !GetPlayer().IsFriendlyTo(unit_target) && !pet.isPossessed() && !pet.IsVehicle())
                    {
                        // This is true if pet has no target or has target but targets differs.
                        if (pet.GetVictim() != unit_target)
                        {
                            if (pet.GetVictim())
                            {
                                pet.AttackStop();
                            }
                            pet.GetMotionMaster().Clear();
                            if (pet.ToCreature().IsAIEnabled)
                            {
                                pet.ToCreature().GetAI().AttackStart(unit_target);
                            }
                        }
                    }

                    spell.prepare(spell.m_targets);
                }
                else
                {
                    if (pet.isPossessed() || pet.IsVehicle())         // @todo: confirm this check
                    {
                        Spell.SendCastResult(GetPlayer(), spellInfo, spell.m_SpellVisual, spell.m_castId, result);
                    }
                    else
                    {
                        spell.SendPetCastResult(result);
                    }

                    if (!pet.GetSpellHistory().HasCooldown(spellid))
                    {
                        pet.GetSpellHistory().ResetCooldown(spellid, true);
                    }

                    spell.finish(false);
                    spell.Dispose();

                    // reset specific flags in case of spell fail. AI will reset other flags
                    if (pet.GetCharmInfo() != null)
                    {
                        pet.GetCharmInfo().SetIsCommandAttack(false);
                    }
                }
                break;
            }

            default:
                Log.outError(LogFilter.Network, "WORLD: unknown PET flag Action {0} and spellid {1}.", flag, spellid);
                break;
            }
        }
Esempio n. 11
0
        void HandleSendMail(SendMail packet)
        {
            if (packet.Info.Attachments.Count > SharedConst.MaxMailItems)                      // client limit
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.TooManyAttachments);
                return;
            }

            if (!CanOpenMailBox(packet.Info.Mailbox))
            {
                return;
            }

            if (string.IsNullOrEmpty(packet.Info.Target))
            {
                return;
            }

            Player player = GetPlayer();

            if (player.getLevel() < WorldConfig.GetIntValue(WorldCfg.MailLevelReq))
            {
                SendNotification(CypherStrings.MailSenderReq, WorldConfig.GetIntValue(WorldCfg.MailLevelReq));
                return;
            }

            ObjectGuid receiverGuid = ObjectGuid.Empty;

            if (ObjectManager.NormalizePlayerName(ref packet.Info.Target))
            {
                receiverGuid = Global.CharacterCacheStorage.GetCharacterGuidByName(packet.Info.Target);
            }

            if (receiverGuid.IsEmpty())
            {
                Log.outInfo(LogFilter.Network, "Player {0} is sending mail to {1} (GUID: not existed!) with subject {2}" +
                            "and body {3} includes {4} items, {5} copper and {6} COD copper with StationeryID = {7}",
                            GetPlayerInfo(), packet.Info.Target, packet.Info.Subject, packet.Info.Body,
                            packet.Info.Attachments.Count, packet.Info.SendMoney, packet.Info.Cod, packet.Info.StationeryID);
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.RecipientNotFound);
                return;
            }

            if (packet.Info.SendMoney < 0)
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.InternalError);
                Log.outWarn(LogFilter.Server, "Player {0} attempted to send mail to {1} ({2}) with negative money value (SendMoney: {3})",
                            GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.SendMoney);
                return;
            }

            if (packet.Info.Cod < 0)
            {
                GetPlayer().SendMailResult(0, MailResponseType.Send, MailResponseResult.InternalError);
                Log.outWarn(LogFilter.Server, "Player {0} attempted to send mail to {1} ({2}) with negative COD value (Cod: {3})",
                            GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.Cod);
                return;
            }

            Log.outInfo(LogFilter.Network, "Player {0} is sending mail to {1} ({2}) with subject {3} and body {4}" +
                        "includes {5} items, {6} copper and {7} COD copper with StationeryID = {8}",
                        GetPlayerInfo(), packet.Info.Target, receiverGuid.ToString(), packet.Info.Subject,
                        packet.Info.Body, packet.Info.Attachments.Count, packet.Info.SendMoney, packet.Info.Cod, packet.Info.StationeryID);

            if (player.GetGUID() == receiverGuid)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.CannotSendToSelf);
                return;
            }

            uint cost = (uint)(!packet.Info.Attachments.Empty() ? 30 * packet.Info.Attachments.Count : 30);  // price hardcoded in client

            long reqmoney = cost + packet.Info.SendMoney;

            // Check for overflow
            if (reqmoney < packet.Info.SendMoney)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotEnoughMoney);
                return;
            }

            if (!player.HasEnoughMoney(reqmoney) && !player.IsGameMaster())
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotEnoughMoney);
                return;
            }

            Player receiver = Global.ObjAccessor.FindPlayer(receiverGuid);

            Team receiverTeam          = 0;
            byte mailsCount            = 0;                       //do not allow to send to one player more than 100 mails
            byte receiverLevel         = 0;
            uint receiverAccountId     = 0;
            uint receiverBnetAccountId = 0;

            if (receiver)
            {
                receiverTeam          = receiver.GetTeam();
                mailsCount            = (byte)receiver.GetMails().Count;
                receiverLevel         = (byte)receiver.getLevel();
                receiverAccountId     = receiver.GetSession().GetAccountId();
                receiverBnetAccountId = receiver.GetSession().GetBattlenetAccountId();
            }
            else
            {
                CharacterCacheEntry characterInfo = Global.CharacterCacheStorage.GetCharacterCacheByGuid(receiverGuid);
                if (characterInfo != null)
                {
                    receiverTeam      = Player.TeamForRace(characterInfo.RaceId);
                    receiverLevel     = characterInfo.Level;
                    receiverAccountId = characterInfo.AccountId;
                }

                PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.SEL_MAIL_COUNT);
                stmt.AddValue(0, receiverGuid.GetCounter());

                SQLResult result = DB.Characters.Query(stmt);
                if (!result.IsEmpty())
                {
                    mailsCount = (byte)result.Read <ulong>(0);
                }

                receiverBnetAccountId = Global.BNetAccountMgr.GetIdByGameAccount(receiverAccountId);
            }

            // do not allow to have more than 100 mails in mailbox.. mails count is in opcode byte!!! - so max can be 255..
            if (mailsCount > 100)
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.RecipientCapReached);
                return;
            }

            // test the receiver's Faction... or all items are account bound
            bool accountBound = !packet.Info.Attachments.Empty();

            foreach (var att in packet.Info.Attachments)
            {
                Item item = player.GetItemByGuid(att.ItemGUID);
                if (item)
                {
                    ItemTemplate itemProto = item.GetTemplate();
                    if (itemProto == null || !itemProto.GetFlags().HasAnyFlag(ItemFlags.IsBoundToAccount))
                    {
                        accountBound = false;
                        break;
                    }
                }
            }

            if (!accountBound && player.GetTeam() != receiverTeam && !HasPermission(RBACPermissions.TwoSideInteractionMail))
            {
                player.SendMailResult(0, MailResponseType.Send, MailResponseResult.NotYourTeam);
                return;
            }

            if (receiverLevel < WorldConfig.GetIntValue(WorldCfg.MailLevelReq))
            {
                SendNotification(CypherStrings.MailReceiverReq, WorldConfig.GetIntValue(WorldCfg.MailLevelReq));
                return;
            }

            List <Item> items = new List <Item>();

            foreach (var att in packet.Info.Attachments)
            {
                if (att.ItemGUID.IsEmpty())
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.MailAttachmentInvalid);
                    return;
                }

                Item item = player.GetItemByGuid(att.ItemGUID);

                // prevent sending bag with items (cheat: can be placed in bag after adding equipped empty bag to mail)
                if (!item)
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.MailAttachmentInvalid);
                    return;
                }

                if (!item.CanBeTraded(true))
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.MailBoundItem);
                    return;
                }

                if (item.IsBoundAccountWide() && item.IsSoulBound() && player.GetSession().GetAccountId() != receiverAccountId)
                {
                    if (!item.IsBattlenetAccountBound() || player.GetSession().GetBattlenetAccountId() == 0 || player.GetSession().GetBattlenetAccountId() != receiverBnetAccountId)
                    {
                        player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.NotSameAccount);
                        return;
                    }
                }

                if (item.GetTemplate().GetFlags().HasAnyFlag(ItemFlags.Conjured) || item.m_itemData.Expiration != 0)
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.MailBoundItem);
                    return;
                }

                if (packet.Info.Cod != 0 && item.HasItemFlag(ItemFieldFlags.Wrapped))
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.CantSendWrappedCod);
                    return;
                }

                if (item.IsNotEmptyBag())
                {
                    player.SendMailResult(0, MailResponseType.Send, MailResponseResult.EquipError, InventoryResult.DestroyNonemptyBag);
                    return;
                }

                items.Add(item);
            }

            player.SendMailResult(0, MailResponseType.Send, MailResponseResult.Ok);

            player.ModifyMoney(-reqmoney);
            player.UpdateCriteria(CriteriaTypes.GoldSpentForMail, cost);

            bool needItemDelay = false;

            MailDraft draft = new MailDraft(packet.Info.Subject, packet.Info.Body);

            SQLTransaction trans = new SQLTransaction();

            if (!packet.Info.Attachments.Empty() || packet.Info.SendMoney > 0)
            {
                bool log = HasPermission(RBACPermissions.LogGmTrade);
                if (!packet.Info.Attachments.Empty())
                {
                    foreach (var item in items)
                    {
                        if (log)
                        {
                            Log.outCommand(GetAccountId(), "GM {0} ({1}) (Account: {2}) mail item: {3} (Entry: {4} Count: {5}) to player: {6} ({7}) (Account: {8})",
                                           GetPlayerName(), GetPlayer().GetGUID().ToString(), GetAccountId(), item.GetTemplate().GetName(), item.GetEntry(), item.GetCount(),
                                           packet.Info.Target, receiverGuid.ToString(), receiverAccountId);
                        }

                        item.SetNotRefundable(GetPlayer()); // makes the item no longer refundable
                        player.MoveItemFromInventory(item.GetBagSlot(), item.GetSlot(), true);

                        item.DeleteFromInventoryDB(trans);     // deletes item from character's inventory
                        item.SetOwnerGUID(receiverGuid);
                        item.SetState(ItemUpdateState.Changed);
                        item.SaveToDB(trans);                  // recursive and not have transaction guard into self, item not in inventory and can be save standalone

                        draft.AddItem(item);
                    }

                    // if item send to character at another account, then apply item delivery delay
                    needItemDelay = player.GetSession().GetAccountId() != receiverAccountId;
                }

                if (log && packet.Info.SendMoney > 0)
                {
                    Log.outCommand(GetAccountId(), "GM {0} ({1}) (Account: {{2}) mail money: {3} to player: {4} ({5}) (Account: {6})",
                                   GetPlayerName(), GetPlayer().GetGUID().ToString(), GetAccountId(), packet.Info.SendMoney, packet.Info.Target, receiverGuid.ToString(), receiverAccountId);
                }
            }

            // If theres is an item, there is a one hour delivery delay if sent to another account's character.
            uint deliver_delay = needItemDelay ? WorldConfig.GetUIntValue(WorldCfg.MailDeliveryDelay) : 0;

            // Mail sent between guild members arrives instantly
            Guild guild = Global.GuildMgr.GetGuildById(player.GetGuildId());

            if (guild)
            {
                if (guild.IsMember(receiverGuid))
                {
                    deliver_delay = 0;
                }
            }

            // don't ask for COD if there are no items
            if (packet.Info.Attachments.Empty())
            {
                packet.Info.Cod = 0;
            }

            // will delete item or place to receiver mail list
            draft.AddMoney((ulong)packet.Info.SendMoney).AddCOD((uint)packet.Info.Cod).SendMailTo(trans, new MailReceiver(receiver, receiverGuid.GetCounter()), new MailSender(player), string.IsNullOrEmpty(packet.Info.Body) ? MailCheckMask.Copied : MailCheckMask.HasBody, deliver_delay);

            player.SaveInventoryAndGoldToDB(trans);
            DB.Characters.CommitTransaction(trans);
        }
Esempio n. 12
0
        void HandleChat(ChatMsg type, Language lang, string msg, string target = "", ObjectGuid channelGuid = default)
        {
            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)
            var languageData = Global.LanguageMgr.GetLanguageDescById(lang);

            if (languageData.Empty())
            {
                SendNotification(CypherStrings.UnknownLanguage);
                return;
            }

            if (!languageData.Any(langDesc => langDesc.SkillId == 0 || sender.HasSkill((SkillType)langDesc.SkillId)))
            {
                // also check SPELL_AURA_COMPREHEND_LANGUAGE (client offers option to speak in that language)
                if (!sender.HasAuraTypeWithMiscvalue(AuraType.ComprehendLanguage, (int)lang))
                {
                    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 - GameTime.GetGameTime()));
                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;
                }

                // Apply checks only if receiver is not already in whitelist and if receiver is not a GM with ".whisper on"
                if (!receiver.IsInWhisperWhiteList(sender.GetGUID()) && !receiver.IsGameMasterAcceptingWhispers())
                {
                    if (!sender.IsGameMaster() && sender.GetLevel() < WorldConfig.GetIntValue(WorldCfg.ChatWhisperLevelReq))
                    {
                        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();
                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();
                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();
                //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 = !channelGuid.IsEmpty() ? ChannelManager.GetChannelForPlayerByGuid(channelGuid, sender) : 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();
                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;
            }
        }
Esempio n. 13
0
        public void LoadFromDB(SQLResult petsResult, SQLResult slotsResult)
        {
            if (!petsResult.IsEmpty())
            {
                do
                {
                    uint       species   = petsResult.Read <uint>(1);
                    ObjectGuid ownerGuid = !petsResult.IsNull(11) ? ObjectGuid.Create(HighGuid.Player, petsResult.Read <ulong>(11)) : ObjectGuid.Empty;

                    BattlePetSpeciesRecord speciesEntry = CliDB.BattlePetSpeciesStorage.LookupByKey(species);
                    if (speciesEntry != null)
                    {
                        if (speciesEntry.GetFlags().HasFlag(BattlePetSpeciesFlags.NotAccountWide))
                        {
                            if (ownerGuid.IsEmpty())
                            {
                                Log.outError(LogFilter.Misc, $"Battlenet account with id {_owner.GetBattlenetAccountId()} has battle pet of species {species} with BattlePetSpeciesFlags::NotAccountWide but no owner");
                                continue;
                            }
                        }
                        else
                        {
                            if (!ownerGuid.IsEmpty())
                            {
                                Log.outError(LogFilter.Misc, $"Battlenet account with id {_owner.GetBattlenetAccountId()} has battle pet of species {species} without BattlePetSpeciesFlags::NotAccountWide but with owner");
                                continue;
                            }
                        }

                        if (HasMaxPetCount(speciesEntry, ownerGuid))
                        {
                            if (ownerGuid.IsEmpty())
                            {
                                Log.outError(LogFilter.Misc, $"Battlenet account with id {_owner.GetBattlenetAccountId()} has more than maximum battle pets of species {species}");
                            }
                            else
                            {
                                Log.outError(LogFilter.Misc, $"Battlenet account with id {_owner.GetBattlenetAccountId()} has more than maximum battle pets of species {species} for player {ownerGuid}");
                            }

                            continue;
                        }

                        BattlePet pet = new();
                        pet.PacketInfo.Guid       = ObjectGuid.Create(HighGuid.BattlePet, petsResult.Read <ulong>(0));
                        pet.PacketInfo.Species    = species;
                        pet.PacketInfo.Breed      = petsResult.Read <ushort>(2);
                        pet.PacketInfo.DisplayID  = petsResult.Read <uint>(3);
                        pet.PacketInfo.Level      = petsResult.Read <ushort>(4);
                        pet.PacketInfo.Exp        = petsResult.Read <ushort>(5);
                        pet.PacketInfo.Health     = petsResult.Read <uint>(6);
                        pet.PacketInfo.Quality    = petsResult.Read <byte>(7);
                        pet.PacketInfo.Flags      = petsResult.Read <ushort>(8);
                        pet.PacketInfo.Name       = petsResult.Read <string>(9);
                        pet.NameTimestamp         = petsResult.Read <long>(10);
                        pet.PacketInfo.CreatureID = speciesEntry.CreatureID;

                        if (!petsResult.IsNull(12))
                        {
                            pet.DeclinedName = new();
                            for (byte i = 0; i < SharedConst.MaxDeclinedNameCases; ++i)
                            {
                                pet.DeclinedName.name[i] = petsResult.Read <string>(12 + i);
                            }
                        }

                        if (!ownerGuid.IsEmpty())
                        {
                            pet.PacketInfo.OwnerInfo.Value      = new();
                            pet.PacketInfo.OwnerInfo.Value.Guid = ownerGuid;
                            pet.PacketInfo.OwnerInfo.Value.PlayerVirtualRealm = Global.WorldMgr.GetVirtualRealmAddress();
                            pet.PacketInfo.OwnerInfo.Value.PlayerNativeRealm  = Global.WorldMgr.GetVirtualRealmAddress();
                        }

                        pet.SaveInfo = BattlePetSaveInfo.Unchanged;
                        pet.CalculateStats();
                        _pets[pet.PacketInfo.Guid.GetCounter()] = pet;
                    }
                } while (petsResult.NextRow());
            }

            if (!slotsResult.IsEmpty())
            {
                byte i = 0; // slots.GetRowCount() should equal MAX_BATTLE_PET_SLOTS

                do
                {
                    _slots[i].Index = slotsResult.Read <byte>(0);
                    var battlePet = _pets.LookupByKey(slotsResult.Read <ulong>(1));
                    if (battlePet != null)
                    {
                        _slots[i].Pet = battlePet.PacketInfo;
                    }
                    _slots[i].Locked = slotsResult.Read <bool>(2);
                    i++;
                } while (slotsResult.NextRow());
            }
        }