diff options
Diffstat (limited to 'src')
42 files changed, 374 insertions, 311 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index 4ec0a93f71f..83d192e8a83 100644 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -3015,7 +3015,7 @@ void WorldObject::MovePosition(Position &pos, float dist, float angle) Trinity::NormalizeMapCoord(pos.m_positionX); Trinity::NormalizeMapCoord(pos.m_positionY); UpdateGroundPositionZ(pos.m_positionX, pos.m_positionY, pos.m_positionZ); - pos.m_orientation = m_orientation; + pos.SetOrientation(GetOrientation()); } void WorldObject::MovePositionToFirstCollision(Position &pos, float dist, float angle) diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h index 70a7bcd7f39..9acd3cc3026 100644 --- a/src/server/game/Entities/Object/Object.h +++ b/src/server/game/Entities/Object/Object.h @@ -104,7 +104,6 @@ class Creature; class CreatureAI; class DynamicObject; class GameObject; -class Map; class InstanceScript; class Player; class TempSummon; diff --git a/src/server/game/Entities/Object/Updates/UpdateData.h b/src/server/game/Entities/Object/Updates/UpdateData.h index fb4ec930c41..654db149ca0 100644 --- a/src/server/game/Entities/Object/Updates/UpdateData.h +++ b/src/server/game/Entities/Object/Updates/UpdateData.h @@ -20,6 +20,8 @@ #define __UPDATEDATA_H #include "ByteBuffer.h" +#include <set> + class WorldPacket; enum OBJECT_UPDATE_TYPE diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index d32c37975dc..990c315e052 100644 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -34,12 +34,12 @@ #define PET_XP_FACTOR 0.05f -Pet::Pet(Player* owner, PetType type) : Guardian(NULL, owner, true), - m_usedTalentCount(0), m_removed(false), - m_happinessTimer(7500), m_petType(type), m_duration(0), - m_auraRaidUpdateMask(0), m_loading(false), m_declinedname(NULL) +Pet::Pet(Player* owner, PetType type) : + Guardian(NULL, owner, true), m_usedTalentCount(0), m_removed(false), + m_happinessTimer(7500), m_petType(type), m_duration(0), m_auraRaidUpdateMask(0), m_loading(false), + m_declinedname(NULL) { - ASSERT(m_owner->GetTypeId() == TYPEID_PLAYER); + ASSERT(GetOwner()->GetTypeId() == TYPEID_PLAYER); m_unitTypeMask |= UNIT_MASK_PET; if (type == HUNTER_PET) @@ -563,7 +563,7 @@ void Pet::Update(uint32 diff) { if (owner->GetPetGUID() != GetGUID()) { - sLog->outError(LOG_FILTER_PETS, "Pet %u is not pet of owner %s, removed", GetEntry(), m_owner->GetName().c_str()); + sLog->outError(LOG_FILTER_PETS, "Pet %u is not pet of owner %s, removed", GetEntry(), GetOwner()->GetName().c_str()); Remove(getPetType() == HUNTER_PET?PET_SAVE_AS_DELETED:PET_SAVE_NOT_IN_SLOT); return; } @@ -832,19 +832,24 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) //Determine pet type PetType petType = MAX_PET_TYPE; - if (isPet() && m_owner->GetTypeId() == TYPEID_PLAYER) + if (isPet() && GetOwner()->GetTypeId() == TYPEID_PLAYER) { - if ((m_owner->getClass() == CLASS_WARLOCK) - || (m_owner->getClass() == CLASS_SHAMAN) // Fire Elemental - || (m_owner->getClass() == CLASS_DEATH_KNIGHT)) // Risen Ghoul + if (GetOwner()->getClass() == CLASS_WARLOCK + || GetOwner()->getClass() == CLASS_SHAMAN // Fire Elemental + || GetOwner()->getClass() == CLASS_DEATH_KNIGHT) // Risen Ghoul + { petType = SUMMON_PET; - else if (m_owner->getClass() == CLASS_HUNTER) + } + else if (GetOwner()->getClass() == CLASS_HUNTER) { petType = HUNTER_PET; m_unitTypeMask |= UNIT_MASK_HUNTER_PET; } else - sLog->outError(LOG_FILTER_PETS, "Unknown type pet %u is summoned by player class %u", GetEntry(), m_owner->getClass()); + { + sLog->outError(LOG_FILTER_PETS, "Unknown type pet %u is summoned by player class %u", + GetEntry(), GetOwner()->getClass()); + } } uint32 creature_ID = (petType == HUNTER_PET) ? 1 : cinfo->Entry; @@ -911,12 +916,14 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) { case SUMMON_PET: { - //the damage bonus used for pets is either fire or shadow damage, whatever is higher - uint32 fire = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); - uint32 shadow = m_owner->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); - uint32 val = (fire > shadow) ? fire : shadow; - SetBonusDamage(int32 (val * 0.15f)); - //bonusAP += val * 0.57; + // the damage bonus used for pets is either fire or shadow damage, whatever is higher + int32 fire = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_FIRE); + int32 shadow = GetOwner()->GetUInt32Value(PLAYER_FIELD_MOD_DAMAGE_DONE_POS + SPELL_SCHOOL_SHADOW); + int32 val = (fire > shadow) ? fire : shadow; + if (val < 0) + val = 0; + + SetBonusDamage(val * 0.15f); SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4))); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4))); @@ -941,14 +948,14 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) { case 510: // mage Water Elemental { - SetBonusDamage(int32(m_owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST) * 0.33f)); + SetBonusDamage(int32(GetOwner()->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST) * 0.33f)); break; } case 1964: //force of nature { if (!pInfo) SetCreateHealth(30 + 30*petlevel); - float bonusDmg = m_owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_NATURE) * 0.15f; + float bonusDmg = GetOwner()->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_NATURE) * 0.15f; SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 2.5f - (petlevel / 2) + bonusDmg)); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 2.5f + (petlevel / 2) + bonusDmg)); break; @@ -968,7 +975,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetCreateHealth(40*petlevel); SetCreateMana(28 + 10*petlevel); } - SetBonusDamage(int32(m_owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FIRE) * 0.5f)); + SetBonusDamage(int32(GetOwner()->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FIRE) * 0.5f)); SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel * 4 - petlevel)); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel * 4 + petlevel)); break; @@ -980,7 +987,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetCreateMana(28 + 10*petlevel); SetCreateHealth(28 + 30*petlevel); } - int32 bonus_dmg = (int32(m_owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SHADOW)* 0.3f)); + int32 bonus_dmg = int32(GetOwner()->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SHADOW)* 0.3f); SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float((petlevel * 4 - petlevel) + bonus_dmg)); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float((petlevel * 4 + petlevel) + bonus_dmg)); @@ -1009,16 +1016,16 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float((petlevel * 4 - petlevel))); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float((petlevel * 4 + petlevel))); - SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(m_owner->GetArmor()) * 0.35f); // Bonus Armor (35% of player armor) - SetModifierValue(UNIT_MOD_STAT_STAMINA, BASE_VALUE, float(m_owner->GetStat(STAT_STAMINA)) * 0.3f); // Bonus Stamina (30% of player stamina) + SetModifierValue(UNIT_MOD_ARMOR, BASE_VALUE, float(GetOwner()->GetArmor()) * 0.35f); // Bonus Armor (35% of player armor) + SetModifierValue(UNIT_MOD_STAT_STAMINA, BASE_VALUE, float(GetOwner()->GetStat(STAT_STAMINA)) * 0.3f); // Bonus Stamina (30% of player stamina) if (!HasAura(58877))//prevent apply twice for the 2 wolves AddAura(58877, this);//Spirit Hunt, passive, Spirit Wolves' attacks heal them and their master for 150% of damage done. break; } case 31216: // Mirror Image { - SetBonusDamage(int32(m_owner->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST) * 0.33f)); - SetDisplayId(m_owner->GetDisplayId()); + SetBonusDamage(int32(GetOwner()->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_FROST) * 0.33f)); + SetDisplayId(GetOwner()->GetDisplayId()); if (!pInfo) { SetCreateMana(28 + 30*petlevel); @@ -1033,7 +1040,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) SetCreateMana(28 + 10*petlevel); SetCreateHealth(28 + 30*petlevel); } - SetBonusDamage(int32(m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * 0.5f)); + SetBonusDamage(int32(GetOwner()->GetTotalAttackPowerValue(BASE_ATTACK) * 0.5f)); SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - (petlevel / 4))); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel + (petlevel / 4))); break; @@ -1041,7 +1048,7 @@ bool Guardian::InitStatsForLevel(uint8 petlevel) case 28017: // Bloodworms { SetCreateHealth(4 * petlevel); - SetBonusDamage(int32(m_owner->GetTotalAttackPowerValue(BASE_ATTACK) * 0.006f)); + SetBonusDamage(int32(GetOwner()->GetTotalAttackPowerValue(BASE_ATTACK) * 0.006f)); SetBaseWeaponDamage(BASE_ATTACK, MINDAMAGE, float(petlevel - 30 - (petlevel / 4))); SetBaseWeaponDamage(BASE_ATTACK, MAXDAMAGE, float(petlevel - 30 + (petlevel / 4))); } diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 49d210fca2c..bed7d9642ac 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -12113,14 +12113,8 @@ void Player::RemoveAmmo() UpdateDamagePhysical(RANGED_ATTACK); } -Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId) -{ - AllowedLooterSet allowedLooters; - return StoreNewItem(dest, item, update, randomPropertyId, allowedLooters); -} - // Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case. -Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet& allowedLooters) +Item* Player::StoreNewItem(ItemPosCountVec const& dest, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet const& allowedLooters) { uint32 count = 0; for (ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr) @@ -12241,7 +12235,6 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool AddEnchantmentDurations(pItem); AddItemDurations(pItem); - const ItemTemplate* proto = pItem->GetTemplate(); for (uint8 i = 0; i < MAX_ITEM_PROTO_SPELLS; ++i) if (proto->Spells[i].SpellTrigger == ITEM_SPELLTRIGGER_ON_NO_DELAY_USE && proto->Spells[i].SpellId > 0) // On obtain trigger @@ -16172,6 +16165,7 @@ void Player::KilledMonsterCredit(uint32 entry, uint64 guid) { uint16 addkillcount = 1; uint32 real_entry = entry; + Creature* killed = NULL; if (guid) { Creature* killed = GetMap()->GetCreature(guid); @@ -16180,7 +16174,7 @@ void Player::KilledMonsterCredit(uint32 entry, uint64 guid) } StartTimedAchievement(ACHIEVEMENT_TIMED_TYPE_CREATURE, real_entry); // MUST BE CALLED FIRST - UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE, real_entry, addkillcount, guid ? GetMap()->GetCreature(guid) : NULL); + UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE, real_entry, addkillcount, killed); for (uint8 i = 0; i < MAX_QUEST_LOG_SIZE; ++i) { @@ -26013,7 +26007,7 @@ void Player::RefundItem(Item* item) { ItemPosCountVec dest; InventoryResult msg = CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itemid, count); - ASSERT(msg == EQUIP_ERR_OK) /// Already checked before + ASSERT(msg == EQUIP_ERR_OK); /// Already checked before Item* it = StoreNewItem(dest, itemid, true); SendNewItem(it, count, true, false, true); } diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 6458de47378..1c0fa4ea93d 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -907,13 +907,13 @@ class PlayerTaxi bool IsTaximaskNodeKnown(uint32 nodeidx) const { uint8 field = uint8((nodeidx - 1) / 32); - uint32 submask = 1<<((nodeidx-1)%32); + uint32 submask = 1 << ((nodeidx-1) % 32); return (m_taximask[field] & submask) == submask; } bool SetTaximaskNode(uint32 nodeidx) { uint8 field = uint8((nodeidx - 1) / 32); - uint32 submask = 1<<((nodeidx-1)%32); + uint32 submask = 1 << ((nodeidx-1) % 32); if ((m_taximask[field] & submask) != submask) { m_taximask[field] |= submask; @@ -1022,7 +1022,7 @@ class TradeData uint32 m_spell; // m_player apply spell to non-traded slot item uint64 m_spellCastItem; // applied spell casted by item use - uint64 m_items[TRADE_SLOT_COUNT]; // traded itmes from m_player side including non-traded slot + uint64 m_items[TRADE_SLOT_COUNT]; // traded items from m_player side including non-traded slot }; class KillRewarder @@ -1235,8 +1235,7 @@ class Player : public Unit, public GridObject<Player> InventoryResult CanUseItem(ItemTemplate const* pItem) const; InventoryResult CanUseAmmo(uint32 item) const; InventoryResult CanRollForItemInLFG(ItemTemplate const* item, WorldObject const* lootedObject) const; - Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0); - Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId, AllowedLooterSet &allowedLooters); + Item* StoreNewItem(ItemPosCountVec const& pos, uint32 item, bool update, int32 randomPropertyId = 0, AllowedLooterSet const& allowedLooters = AllowedLooterSet()); Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update); Item* EquipNewItem(uint16 pos, uint32 item, bool update); Item* EquipItem(uint16 pos, Item* pItem, bool update); @@ -2665,4 +2664,5 @@ template <class T> T Player::ApplySpellMod(uint32 spellId, SpellModOp op, T &bas basevalue = T((float)basevalue + diff); return T(diff); } + #endif diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp index 6f5927492bf..2b053995e1b 100644 --- a/src/server/game/Entities/Player/SocialMgr.cpp +++ b/src/server/game/Entities/Player/SocialMgr.cpp @@ -27,15 +27,8 @@ #include "Util.h" #include "AccountMgr.h" -PlayerSocial::PlayerSocial() -{ - m_playerGUID = 0; -} - -PlayerSocial::~PlayerSocial() -{ - m_playerSocialMap.clear(); -} +PlayerSocial::PlayerSocial(): m_playerGUID() +{ } uint32 PlayerSocial::GetNumberOfSocialsWithFlag(SocialFlag flag) { diff --git a/src/server/game/Entities/Player/SocialMgr.h b/src/server/game/Entities/Player/SocialMgr.h index 0e73af8f809..4f2a4fdde72 100644 --- a/src/server/game/Entities/Player/SocialMgr.h +++ b/src/server/game/Entities/Player/SocialMgr.h @@ -104,7 +104,6 @@ class PlayerSocial friend class SocialMgr; public: PlayerSocial(); - ~PlayerSocial(); // adding/removing bool AddToSocialList(uint32 friend_guid, bool ignore); void RemoveFromSocialList(uint32 friend_guid, bool ignore); diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index 4896f29d205..c972f97788f 100644 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -127,14 +127,32 @@ enum SpellValueMod SPELLVALUE_AURA_STACK }; -typedef std::pair<SpellValueMod, int32> CustomSpellValueMod; -class CustomSpellValues : public std::vector<CustomSpellValueMod> +class CustomSpellValues { - public: - void AddSpellMod(SpellValueMod mod, int32 value) - { - push_back(std::make_pair(mod, value)); - } + typedef std::pair<SpellValueMod, int32> CustomSpellValueMod; + typedef std::vector<CustomSpellValueMod> StorageType; + +public: + typedef StorageType::const_iterator const_iterator; + +public: + void AddSpellMod(SpellValueMod mod, int32 value) + { + storage_.push_back(CustomSpellValueMod(mod, value)); + } + + const_iterator begin() const + { + return storage_.begin(); + } + + const_iterator end() const + { + return storage_.end(); + } + +private: + StorageType storage_; }; enum SpellFacingFlags @@ -1411,10 +1429,13 @@ class Unit : public WorldObject void ProcDamageAndSpell(Unit* victim, uint32 procAttacker, uint32 procVictim, uint32 procEx, uint32 amount, WeaponAttackType attType = BASE_ATTACK, SpellInfo const* procSpell = NULL, SpellInfo const* procAura = NULL); void ProcDamageAndSpellFor(bool isVictim, Unit* target, uint32 procFlag, uint32 procExtra, WeaponAttackType attType, SpellInfo const* procSpell, uint32 damage, SpellInfo const* procAura = NULL); - void GetProcAurasTriggeredOnEvent(std::list<AuraApplication*>& aurasTriggeringProc, std::list<AuraApplication*>* procAuras, ProcEventInfo eventInfo); + void GetProcAurasTriggeredOnEvent(AuraApplicationList& aurasTriggeringProc, AuraApplicationList* procAuras, ProcEventInfo eventInfo); void TriggerAurasProcOnEvent(CalcDamageInfo& damageInfo); - void TriggerAurasProcOnEvent(std::list<AuraApplication*>* myProcAuras, std::list<AuraApplication*>* targetProcAuras, Unit* actionTarget, uint32 typeMaskActor, uint32 typeMaskActionTarget, uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, DamageInfo* damageInfo, HealInfo* healInfo); - void TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, std::list<AuraApplication*>& procAuras); + void TriggerAurasProcOnEvent(AuraApplicationList* myProcAuras, AuraApplicationList* targetProcAuras, + Unit* actionTarget, uint32 typeMaskActor, uint32 typeMaskActionTarget, + uint32 spellTypeMask, uint32 spellPhaseMask, uint32 hitMask, Spell* spell, + DamageInfo* damageInfo, HealInfo* healInfo); + void TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, AuraApplicationList& procAuras); void HandleEmoteCommand(uint32 anim_id); void AttackerStateUpdate (Unit* victim, WeaponAttackType attType = BASE_ATTACK, bool extra = false); diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp index 685ac9029ed..9141f77b852 100644 --- a/src/server/game/Events/GameEventMgr.cpp +++ b/src/server/game/Events/GameEventMgr.cpp @@ -205,7 +205,7 @@ void GameEventMgr::LoadFromDB() { { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 4 5 6 7 + // 0 1 2 3 4 5 6 7 QueryResult result = WorldDatabase.Query("SELECT eventEntry, UNIX_TIMESTAMP(start_time), UNIX_TIMESTAMP(end_time), occurence, length, holiday, description, world_event FROM game_event"); if (!result) { @@ -792,7 +792,7 @@ void GameEventMgr::LoadFromDB() { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 4 5 + // 0 1 2 3 4 5 QueryResult result = WorldDatabase.Query("SELECT eventEntry, guid, item, maxcount, incrtime, ExtendedCost FROM game_event_npc_vendor ORDER BY guid, slot ASC"); if (!result) diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index 0ea66a056fb..08075235bab 100644 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -47,6 +47,35 @@ ObjectAccessor::~ObjectAccessor() { } +template<class T> T* ObjectAccessor::GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/) +{ + T* obj = HashMapHolder<T>::Find(guid); + if (!obj || obj->GetMapId() != mapid) + return NULL; + + CellCoord p = Trinity::ComputeCellCoord(x, y); + if (!p.IsCoordValid()) + { + sLog->outError(LOG_FILTER_GENERAL, "ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord); + return NULL; + } + + CellCoord q = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); + if (!q.IsCoordValid()) + { + sLog->outError(LOG_FILTER_GENERAL, "ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord); + return NULL; + } + + int32 dx = int32(p.x_coord) - int32(q.x_coord); + int32 dy = int32(p.y_coord) - int32(q.y_coord); + + if (dx > -2 && dx < 2 && dy > -2 && dy < 2) + return obj; + else + return NULL; +} + Player* ObjectAccessor::GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/) { Player* player = HashMapHolder<Player>::Find(guid); diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h index 6a53d58c57f..1abe3550729 100644 --- a/src/server/game/Globals/ObjectAccessor.h +++ b/src/server/game/Globals/ObjectAccessor.h @@ -138,34 +138,7 @@ class ObjectAccessor return NULL; } - template<class T> static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/) - { - T* obj = HashMapHolder<T>::Find(guid); - if (!obj || obj->GetMapId() != mapid) - return NULL; - - CellCoord p = Trinity::ComputeCellCoord(x, y); - if (!p.IsCoordValid()) - { - sLog->outError(LOG_FILTER_GENERAL, "ObjectAccessor::GetObjectInWorld: invalid coordinates supplied X:%f Y:%f grid cell [%u:%u]", x, y, p.x_coord, p.y_coord); - return NULL; - } - - CellCoord q = Trinity::ComputeCellCoord(obj->GetPositionX(), obj->GetPositionY()); - if (!q.IsCoordValid()) - { - sLog->outError(LOG_FILTER_GENERAL, "ObjectAccessor::GetObjecInWorld: object (GUID: %u TypeId: %u) has invalid coordinates X:%f Y:%f grid cell [%u:%u]", obj->GetGUIDLow(), obj->GetTypeId(), obj->GetPositionX(), obj->GetPositionY(), q.x_coord, q.y_coord); - return NULL; - } - - int32 dx = int32(p.x_coord) - int32(q.x_coord); - int32 dy = int32(p.y_coord) - int32(q.y_coord); - - if (dx > -2 && dx < 2 && dy > -2 && dy < 2) - return obj; - else - return NULL; - } + template<class T> static T* GetObjectInWorld(uint32 mapid, float x, float y, uint64 guid, T* /*fake*/); // these functions return objects only if in map of specified object static WorldObject* GetWorldObject(WorldObject const&, uint64); diff --git a/src/server/game/Grids/GridDefines.h b/src/server/game/Grids/GridDefines.h index 14c0588c3b4..ad48e4fd128 100644 --- a/src/server/game/Grids/GridDefines.h +++ b/src/server/game/Grids/GridDefines.h @@ -85,13 +85,11 @@ template<uint32 LIMIT> struct CoordPair { CoordPair(uint32 x=0, uint32 y=0) - : x_coord(x) - , y_coord(y) + : x_coord(x), y_coord(y) {} CoordPair(const CoordPair<LIMIT> &obj) - : x_coord(obj.x_coord) - , y_coord(obj.y_coord) + : x_coord(obj.x_coord), y_coord(obj.y_coord) {} CoordPair<LIMIT> & operator=(const CoordPair<LIMIT> &obj) diff --git a/src/server/game/Grids/NGrid.h b/src/server/game/Grids/NGrid.h index f64c54c8c43..65cdd3a6033 100644 --- a/src/server/game/Grids/NGrid.h +++ b/src/server/game/Grids/NGrid.h @@ -78,15 +78,10 @@ class NGrid { public: typedef Grid<ACTIVE_OBJECT, WORLD_OBJECT_TYPES, GRID_OBJECT_TYPES> GridType; - NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) - : i_gridId(id) - , i_GridInfo(GridInfo(expiry, unload)) - , i_x(x) - , i_y(y) - , i_cellstate(GRID_STATE_INVALID) - , i_GridObjectDataLoaded(false) - { - } + NGrid(uint32 id, int32 x, int32 y, time_t expiry, bool unload = true) : + i_gridId(id), i_GridInfo(GridInfo(expiry, unload)), i_x(x), i_y(y), + i_cellstate(GRID_STATE_INVALID), i_GridObjectDataLoaded(false) + { } GridType& GetGridType(const uint32 x, const uint32 y) { diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index fe06c172e3f..8df65364b8a 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -1336,8 +1336,7 @@ void Group::CountTheRoll(Rolls::iterator rollI) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, item->GetAllowedLooters()); } else { @@ -1389,8 +1388,7 @@ void Group::CountTheRoll(Rolls::iterator rollI) item->is_looted = true; roll->getLoot()->NotifyItemRemoved(roll->itemSlot); roll->getLoot()->unlootedCount--; - AllowedLooterSet looters = item->GetAllowedLooters(); - player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, looters); + player->StoreNewItem(dest, roll->itemid, true, item->randomPropertyId, item->GetAllowedLooters()); } else { @@ -2126,7 +2124,7 @@ void Group::SetLfgRoles(uint64 guid, const uint8 roles) return; slot->roles = roles; - SendUpdate(); + SendUpdate(); } bool Group::IsFull() const @@ -2174,7 +2172,7 @@ uint32 Group::GetLowGUID() const return GUID_LOPART(m_guid); } -const char * Group::GetLeaderName() const +char const* Group::GetLeaderName() const { return m_leaderName.c_str(); } diff --git a/src/server/game/Instances/InstanceSaveMgr.cpp b/src/server/game/Instances/InstanceSaveMgr.cpp index c4967e46623..498abbdc597 100644 --- a/src/server/game/Instances/InstanceSaveMgr.cpp +++ b/src/server/game/Instances/InstanceSaveMgr.cpp @@ -51,14 +51,13 @@ InstanceSaveManager::~InstanceSaveManager() ++next; (*itr2)->UnbindInstance(save->GetMapId(), save->GetDifficulty(), true); } - save->m_playerList.clear(); for (InstanceSave::GroupListType::iterator itr2 = save->m_groupList.begin(), next = itr2; itr2 != save->m_groupList.end(); itr2 = next) { ++next; (*itr2)->UnbindInstance(save->GetMapId(), save->GetDifficulty(), true); } - save->m_groupList.clear(); + delete save; } } diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index bfd9bd62647..0b4c32500e0 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -403,6 +403,8 @@ void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= NULL*/, uint8 case ENCOUNTER_FRAME_ENGAGE: case ENCOUNTER_FRAME_DISENGAGE: case ENCOUNTER_FRAME_UPDATE_PRIORITY: + if (!unit) + return; data.append(unit->GetPackGUID()); data << uint8(param1); break; diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index da219c66b9b..fcef203738a 100644 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -861,17 +861,16 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv) { if (lv.permission == NONE_PERMISSION) { - b << uint32(0); //gold + b << uint32(0); // gold b << uint8(0); // item count - return b; // nothing output more + return b; } Loot &l = lv.loot; uint8 itemsShown = 0; - //gold - b << uint32(l.gold); + b << uint32(l.gold); //gold size_t count_pos = b.wpos(); // pos of item count byte b << uint8(0); // item count placeholder @@ -954,7 +953,7 @@ ByteBuffer& operator<<(ByteBuffer& b, LootView const& lv) break; } default: - return b; // nothing output more + return b; } LootSlotType slotType = lv.permission == OWNER_PERMISSION ? LOOT_SLOT_TYPE_OWNER : LOOT_SLOT_TYPE_ALLOW_LOOT; @@ -1226,15 +1225,11 @@ void LootTemplate::LootGroup::CheckLootRefs(LootTemplateMap const& /*store*/, Lo LootTemplate::~LootTemplate() { - while (!Entries.empty()) - { - delete Entries.back(); - Entries.pop_back(); - } + for (LootStoreItemList::iterator i = Entries.begin(); i != Entries.end(); ++i) + delete *i; for (size_t i = 0; i < Groups.size(); ++i) delete Groups[i]; - Groups.clear(); } // Adds an entry to the group (at loading stage) diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index 5c858a35242..d338f6f503b 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -100,7 +100,6 @@ enum LootSlotType class Player; class LootStore; -class ConditionMgr; struct LootStoreItem { diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index c2079c22e76..62fec9e4b20 100644 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -29,8 +29,6 @@ MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DUNGEON_DIFFICULTY_NORMAL) { - // initialize instanced maps list - m_InstancedMaps.clear(); // fill with zero memset(&GridMapReference, 0, MAX_NUMBER_OF_GRIDS*MAX_NUMBER_OF_GRIDS*sizeof(uint16)); } diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h index 76876044bb7..09e09a80148 100644 --- a/src/server/game/Maps/MapManager.h +++ b/src/server/game/Maps/MapManager.h @@ -104,21 +104,6 @@ class MapManager return IsValidMapCoord(loc.GetMapId(), loc.GetPositionX(), loc.GetPositionY(), loc.GetPositionZ(), loc.GetOrientation()); } - // modulos a radian orientation to the range of 0..2PI - static float NormalizeOrientation(float o) - { - // fmod only supports positive numbers. Thus we have - // to emulate negative numbers - if (o < 0) - { - float mod = o *-1; - mod = fmod(mod, 2.0f * static_cast<float>(M_PI)); - mod = -mod + 2.0f * static_cast<float>(M_PI); - return mod; - } - return fmod(o, 2.0f * static_cast<float>(M_PI)); - } - void DoDelayedMovesAndRemoves(); void LoadTransports(); diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h index bd351548255..73832a632c3 100644 --- a/src/server/game/Spells/Auras/SpellAuras.h +++ b/src/server/game/Spells/Auras/SpellAuras.h @@ -23,7 +23,6 @@ #include "SpellInfo.h" #include "Unit.h" -class Unit; class SpellInfo; struct SpellModifier; struct ProcTriggerSpell; @@ -153,7 +152,15 @@ class Aura bool IsArea() const; bool IsPassive() const; bool IsDeathPersistent() const; - bool IsRemovedOnShapeLost(Unit* target) const { return (GetCasterGUID() == target->GetGUID() && m_spellInfo->Stances && !(m_spellInfo->AttributesEx2 & SPELL_ATTR2_NOT_NEED_SHAPESHIFT) && !(m_spellInfo->Attributes & SPELL_ATTR0_NOT_SHAPESHIFT)); } + + bool IsRemovedOnShapeLost(Unit* target) const + { + return GetCasterGUID() == target->GetGUID() + && m_spellInfo->Stances + && !(m_spellInfo->AttributesEx2 & SPELL_ATTR2_NOT_NEED_SHAPESHIFT) + && !(m_spellInfo->Attributes & SPELL_ATTR0_NOT_SHAPESHIFT); + } + bool CanBeSaved() const; bool IsRemoved() const { return m_isRemoved; } bool CanBeSentToClient() const; @@ -166,7 +173,7 @@ class Aura void SetLoadedState(int32 maxduration, int32 duration, int32 charges, uint8 stackamount, uint8 recalculateMask, int32 * amount); // helpers for aura effects - bool HasEffect(uint8 effIndex) const { return bool(GetEffect(effIndex)); } + bool HasEffect(uint8 effIndex) const { return GetEffect(effIndex) != NULL; } bool HasEffectType(AuraType type) const; AuraEffect* GetEffect(uint8 effIndex) const { ASSERT (effIndex < MAX_SPELL_EFFECTS); return m_effects[effIndex]; } uint8 GetEffectMask() const { uint8 effMask = 0; for (uint8 i = 0; i < MAX_SPELL_EFFECTS; ++i) if (m_effects[i]) effMask |= 1<<i; return effMask; } @@ -175,7 +182,7 @@ class Aura // Helpers for targets ApplicationMap const & GetApplicationMap() {return m_applications;} - void GetApplicationList(std::list<AuraApplication*> & applicationList) const; + void GetApplicationList(Unit::AuraApplicationList& applicationList) const; const AuraApplication * GetApplicationOfTarget (uint64 guid) const { ApplicationMap::const_iterator itr = m_applications.find(guid); if (itr != m_applications.end()) return itr->second; return NULL; } AuraApplication * GetApplicationOfTarget (uint64 guid) { ApplicationMap::iterator itr = m_applications.find(guid); if (itr != m_applications.end()) return itr->second; return NULL; } bool IsAppliedOnTarget(uint64 guid) const { return m_applications.find(guid) != m_applications.end(); } diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h index 47ce299c05d..191a7461fe9 100644 --- a/src/server/game/Spells/Spell.h +++ b/src/server/game/Spells/Spell.h @@ -456,7 +456,7 @@ class Spell void SetAutoRepeat(bool rep) { m_autoRepeat = rep; } void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; } bool IsNextMeleeSwingSpell() const; - bool IsTriggered() const { return _triggeredCastFlags & TRIGGERED_FULL_MASK; }; + bool IsTriggered() const { return _triggeredCastFlags & TRIGGERED_FULL_MASK; } bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; } bool IsAutoActionResetSpell() const; @@ -491,7 +491,7 @@ class Spell Unit* const m_caster; - SpellValue * const m_spellValue; + SpellValue* const m_spellValue; uint64 m_originalCasterGUID; // real source of cast (aura caster/etc), used for spell targets selection // e.g. damage around area spell trigered by victim aura and damage enemies of aura caster diff --git a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp index 48bc162c82c..c36815b49f3 100644 --- a/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp +++ b/src/server/scripts/Northrend/ChamberOfAspects/RubySanctum/boss_halion.cpp @@ -1020,7 +1020,7 @@ class npc_meteor_strike_initial : public CreatureScript _meteorList.clear(); for (uint8 i = 0; i < 4; i++) { - angle[i] = MapManager::NormalizeOrientation(angle[i]); + angle[i] = Position::NormalizeOrientation(angle[i]); me->SetOrientation(angle[i]); me->GetNearPosition(newPos, 10.0f, 0.0f); // Exact distance if (Creature* meteor = me->SummonCreature(NPC_METEOR_STRIKE_NORTH + i, newPos, TEMPSUMMON_TIMED_DESPAWN, 30000)) diff --git a/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp b/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp index 7e72ad00a3c..7d508b154eb 100644 --- a/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp +++ b/src/server/scripts/Northrend/IcecrownCitadel/boss_lord_marrowgar.cpp @@ -19,7 +19,6 @@ #include "ScriptMgr.h" #include "ScriptedCreature.h" #include "SpellAuras.h" -#include "MapManager.h" #include "MoveSplineInit.h" #include "Player.h" #include "icecrown_citadel.h" @@ -372,7 +371,7 @@ class npc_coldflame : public CreatureScript if (owner->HasAura(SPELL_BONE_STORM)) { - float ang = MapManager::NormalizeOrientation(pos.GetAngle(me)); + float ang = Position::NormalizeOrientation(pos.GetAngle(me)); me->SetOrientation(ang); owner->GetNearPoint2D(pos.m_positionX, pos.m_positionY, 5.0f - owner->GetObjectSize(), ang); } @@ -385,7 +384,7 @@ class npc_coldflame : public CreatureScript return; } - float ang = MapManager::NormalizeOrientation(pos.GetAngle(target)); + float ang = Position::NormalizeOrientation(pos.GetAngle(target)); me->SetOrientation(ang); owner->GetNearPoint2D(pos.m_positionX, pos.m_positionY, 15.0f - owner->GetObjectSize(), ang); } diff --git a/src/server/scripts/Northrend/Nexus/Oculus/boss_varos.cpp b/src/server/scripts/Northrend/Nexus/Oculus/boss_varos.cpp index a2b5d340410..111e6b2c7aa 100644 --- a/src/server/scripts/Northrend/Nexus/Oculus/boss_varos.cpp +++ b/src/server/scripts/Northrend/Nexus/Oculus/boss_varos.cpp @@ -20,7 +20,6 @@ #include "SpellScript.h" #include "SpellAuraEffects.h" #include "oculus.h" -#include "MapManager.h" enum Says { @@ -121,7 +120,7 @@ public: coreEnergizeOrientation = me->GetOrientation(); firstCoreEnergize = true; } else - coreEnergizeOrientation = MapManager::NormalizeOrientation(coreEnergizeOrientation - 2.0f); + coreEnergizeOrientation = Position::NormalizeOrientation(coreEnergizeOrientation - 2.0f); DoCast(me, SPELL_ENERGIZE_CORES_VISUAL); events.ScheduleEvent(EVENT_ENERGIZE_CORES_VISUAL, 5000); diff --git a/src/server/shared/CMakeLists.txt b/src/server/shared/CMakeLists.txt index 01ccf648b31..447819b0431 100644 --- a/src/server/shared/CMakeLists.txt +++ b/src/server/shared/CMakeLists.txt @@ -16,6 +16,7 @@ file(GLOB_RECURSE sources_Configuration Configuration/*.cpp Configuration/*.h) file(GLOB_RECURSE sources_Cryptography Cryptography/*.cpp Cryptography/*.h) file(GLOB_RECURSE sources_Database Database/*.cpp Database/*.h) file(GLOB_RECURSE sources_DataStores DataStores/*.cpp DataStores/*.h) +file(GLOB_RECURSE sources_Debugging Debugging/*.cpp Debugging/*.h) file(GLOB_RECURSE sources_Dynamic Dynamic/*.cpp Dynamic/*.h) file(GLOB_RECURSE sources_Logging Logging/*.cpp Logging/*.h) file(GLOB_RECURSE sources_Packets Packets/*.cpp Packets/*.h) @@ -39,13 +40,13 @@ set(shared_STAT_SRCS ${sources_Cryptography} ${sources_Database} ${sources_DataStores} + ${sources_Debugging} ${sources_Dynamic} ${sources_Logging} ${sources_Packets} ${sources_Threading} ${sources_Utilities} ${sources_localdir} - Debugging/Errors.h ) include_directories( diff --git a/src/server/shared/Containers.h b/src/server/shared/Containers.h index 83c691a99e2..b33954d7ea4 100644 --- a/src/server/shared/Containers.h +++ b/src/server/shared/Containers.h @@ -18,6 +18,7 @@ #ifndef TRINITY_CONTAINERS_H #define TRINITY_CONTAINERS_H +#include "Define.h" #include <list> //! Because circular includes are bad diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp index 0f68fcb6c37..003c09e4589 100644 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.cpp @@ -20,15 +20,10 @@ #include "Cryptography/HMACSHA1.h" #include "Cryptography/BigNumber.h" -AuthCrypt::AuthCrypt() : _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH) - , _initialized(false) -{ -} - -AuthCrypt::~AuthCrypt() -{ - -} +AuthCrypt::AuthCrypt() : + _clientDecrypt(SHA_DIGEST_LENGTH), _serverEncrypt(SHA_DIGEST_LENGTH), + _initialized(false) +{ } void AuthCrypt::Init(BigNumber* K) { diff --git a/src/server/shared/Cryptography/Authentication/AuthCrypt.h b/src/server/shared/Cryptography/Authentication/AuthCrypt.h index 200681afd08..95e773b586e 100644 --- a/src/server/shared/Cryptography/Authentication/AuthCrypt.h +++ b/src/server/shared/Cryptography/Authentication/AuthCrypt.h @@ -27,7 +27,6 @@ class AuthCrypt { public: AuthCrypt(); - ~AuthCrypt(); void Init(BigNumber* K); void DecryptRecv(uint8 *, size_t); diff --git a/src/server/shared/Cryptography/BigNumber.cpp b/src/server/shared/Cryptography/BigNumber.cpp index 37778cceab8..06ea57b662e 100644 --- a/src/server/shared/Cryptography/BigNumber.cpp +++ b/src/server/shared/Cryptography/BigNumber.cpp @@ -24,18 +24,15 @@ #include <algorithm> BigNumber::BigNumber() - : _bn(BN_new()) - , _array(NULL) + : _bn(BN_new()), _array(NULL) { } BigNumber::BigNumber(BigNumber const& bn) - : _bn(BN_dup(bn._bn)) - , _array(NULL) + : _bn(BN_dup(bn._bn)), _array(NULL) { } BigNumber::BigNumber(uint32 val) - : _bn(BN_new()) - , _array(NULL) + : _bn(BN_new()), _array(NULL) { BN_set_word(_bn, val); } diff --git a/src/server/shared/Cryptography/HMACSHA1.cpp b/src/server/shared/Cryptography/HMACSHA1.cpp index ab50eb9981a..297b4e90316 100644 --- a/src/server/shared/Cryptography/HMACSHA1.cpp +++ b/src/server/shared/Cryptography/HMACSHA1.cpp @@ -40,7 +40,7 @@ void HmacHash::Finalize() { uint32 length = 0; HMAC_Final(&m_ctx, (uint8*)m_digest, &length); - ASSERT(length == SHA_DIGEST_LENGTH) + ASSERT(length == SHA_DIGEST_LENGTH); } uint8 *HmacHash::ComputeHash(BigNumber* bn) diff --git a/src/server/shared/Database/DatabaseWorkerPool.h b/src/server/shared/Database/DatabaseWorkerPool.h index 524a3de2628..a197610c6b5 100644 --- a/src/server/shared/Database/DatabaseWorkerPool.h +++ b/src/server/shared/Database/DatabaseWorkerPool.h @@ -55,8 +55,8 @@ class DatabaseWorkerPool memset(_connectionCount, 0, sizeof(_connectionCount)); _connections.resize(IDX_SIZE); - WPFatal (mysql_thread_safe(), "Used MySQL library isn't thread-safe."); - WPFatal (mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, "TrinityCore does not support MySQL versions below 5.1"); + WPFatal(mysql_thread_safe(), "Used MySQL library isn't thread-safe."); + WPFatal(mysql_get_client_version() >= MIN_MYSQL_CLIENT_VERSION, "TrinityCore does not support MySQL versions below 5.1"); } ~DatabaseWorkerPool() diff --git a/src/server/shared/Debugging/Errors.cpp b/src/server/shared/Debugging/Errors.cpp new file mode 100644 index 00000000000..bd299906de0 --- /dev/null +++ b/src/server/shared/Debugging/Errors.cpp @@ -0,0 +1,38 @@ +#include "Errors.h" +#include "Log.h" + +#include <ace/Stack_Trace.h> +#include <ace/OS_NS_unistd.h> + +namespace Trinity { + +void Assert(char const *file, int line, char const *function, char const *message) +{ + ACE_Stack_Trace st; + fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n%s\n", + file, line, function, message, st.c_str()); + *((volatile int*)NULL) = 0; +} + +void Fatal(char const *file, int line, char const *function, char const *message) +{ + sLog->outError(LOG_FILTER_GENERAL, "\n%s:%i in %s FATAL ERROR:\n %s\n", + file, line, function, message); + ACE_OS::sleep(10); + *((volatile int*)NULL) = 0; +} + +void Error(char const *file, int line, char const *function, char const *message) +{ + sLog->outError(LOG_FILTER_GENERAL, "\n%s:%i in %s ERROR:\n %s\n", + file, line, function, message); + *((volatile int*)NULL) = 0; +} + +void Warning(char const *file, int line, char const *function, char const *message) +{ + sLog->outError(LOG_FILTER_GENERAL, "\n%s:%i in %s WARNING:\n %s\n", + file, line, function, message); +} + +} // namespace Trinity diff --git a/src/server/shared/Debugging/Errors.h b/src/server/shared/Debugging/Errors.h index 10e94634e9a..554b20c3648 100644 --- a/src/server/shared/Debugging/Errors.h +++ b/src/server/shared/Debugging/Errors.h @@ -19,15 +19,23 @@ #ifndef TRINITYCORE_ERRORS_H #define TRINITYCORE_ERRORS_H -#include "Common.h" -#include "Log.h" -#include <ace/Stack_Trace.h> -#include <ace/OS_NS_unistd.h> +namespace Trinity { -#define WPAssert(assertion) { if (!(assertion)) { ACE_Stack_Trace st; fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n%s\n", __FILE__, __LINE__, __FUNCTION__, #assertion, st.c_str()); *((volatile int*)NULL) = 0; } } -#define WPError(assertion, errmsg) { if (!(assertion)) { sLog->outError(LOG_FILTER_GENERAL, "%\n%s:%i in %s ERROR:\n %s\n", __FILE__, __LINE__, __FUNCTION__, (char *)errmsg); *((volatile int*)NULL) = 0; } } -#define WPWarning(assertion, errmsg) { if (!(assertion)) { sLog->outError(LOG_FILTER_GENERAL, "\n%s:%i in %s WARNING:\n %s\n", __FILE__, __LINE__, __FUNCTION__, (char *)errmsg); } } -#define WPFatal(assertion, errmsg) { if (!(assertion)) { sLog->outError(LOG_FILTER_GENERAL, "\n%s:%i in %s FATAL ERROR:\n %s\n", __FILE__, __LINE__, __FUNCTION__, (char *)errmsg); ACE_OS::sleep(10); *((volatile int*)NULL) = 0; } } +void Assert(char const *file, int line, char const *function, char const *message); + +void Fatal(char const *file, int line, char const *function, char const *message); + +void Error(char const *file, int line, char const *function, char const *message); + +void Warning(char const *file, int line, char const *function, char const *message); + +} // namespace Trinity + +#define WPAssert(cond) do { if (!(cond)) Trinity::Assert(__FILE__, __LINE__, __FUNCTION__, #cond); } while(0) +#define WPFatal(cond, msg) do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) +#define WPError(cond, msg) do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) +#define WPWarning(cond, msg) do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) #define ASSERT WPAssert + #endif diff --git a/src/server/shared/Debugging/WheatyExceptionReport.cpp b/src/server/shared/Debugging/WheatyExceptionReport.cpp index d07e579ab5d..d4bd630ca25 100644 --- a/src/server/shared/Debugging/WheatyExceptionReport.cpp +++ b/src/server/shared/Debugging/WheatyExceptionReport.cpp @@ -3,6 +3,8 @@ // MSDN Magazine, 2002 // FILE: WheatyExceptionReport.CPP //========================================== +#include "CompilerDefs.h" + #if PLATFORM == PLATFORM_WINDOWS && !defined(__MINGW32__) #define WIN32_LEAN_AND_MEAN #pragma warning(disable:4996) diff --git a/src/server/shared/Logging/Appender.cpp b/src/server/shared/Logging/Appender.cpp index efb141d1060..cde94fe3a7c 100644 --- a/src/server/shared/Logging/Appender.cpp +++ b/src/server/shared/Logging/Appender.cpp @@ -218,6 +218,8 @@ char const* Appender::getLogFilterTypeString(LogFilterType type) return "SOAP"; case LOG_FILTER_RBAC: return "RBAC"; + case LOG_FILTER_CHEAT: + return "CHEAT"; default: break; } diff --git a/src/server/shared/Logging/Appender.h b/src/server/shared/Logging/Appender.h index e11bc40c42f..983f6a5ddbe 100644 --- a/src/server/shared/Logging/Appender.h +++ b/src/server/shared/Logging/Appender.h @@ -68,10 +68,11 @@ enum LogFilterType LOG_FILTER_SERVER_LOADING = 40, LOG_FILTER_OPCODES = 41, LOG_FILTER_SOAP = 42, - LOG_FILTER_RBAC = 43 + LOG_FILTER_RBAC = 43, + LOG_FILTER_CHEAT = 44 }; -const uint8 MaxLogFilter = 43; +const uint8 MaxLogFilter = 45; // Values assigned have their equivalent in enum ACE_Log_Priority enum LogLevel @@ -108,12 +109,8 @@ enum AppenderFlags struct LogMessage { LogMessage(LogLevel _level, LogFilterType _type, std::string _text) - : level(_level) - , type(_type) - , text(_text) - { - mtime = time(NULL); - } + : level(_level), type(_type), text(_text), mtime(time(NULL)) + { } static std::string getTimeStr(time_t time); std::string getTimeStr(); diff --git a/src/server/shared/Logging/LogOperation.h b/src/server/shared/Logging/LogOperation.h index 0a0dde3bb61..40017cb87f4 100644 --- a/src/server/shared/Logging/LogOperation.h +++ b/src/server/shared/Logging/LogOperation.h @@ -25,8 +25,7 @@ class LogOperation { public: LogOperation(Logger* _logger, LogMessage* _msg) - : logger(_logger) - , msg(_msg) + : logger(_logger), msg(_msg) { } ~LogOperation(); diff --git a/src/server/shared/Packets/ByteBuffer.cpp b/src/server/shared/Packets/ByteBuffer.cpp new file mode 100644 index 00000000000..a14cf3477af --- /dev/null +++ b/src/server/shared/Packets/ByteBuffer.cpp @@ -0,0 +1,95 @@ +#include "ByteBuffer.h" +#include "Log.h" + +#include <ace/Stack_Trace.h> +#include <sstream> + +ByteBufferPositionException::ByteBufferPositionException(bool add, size_t pos, + size_t size, size_t valueSize) +{ + std::ostringstream ss; + ACE_Stack_Trace trace; + + ss << "Attempted to " << (add ? "put" : "get") << " value with size: " + << valueSize << " in ByteBuffer (pos: " << pos << " size: " << size + << ")\n\n" << trace.c_str(); + + message().assign(ss.str()); +} + +ByteBufferSourceException::ByteBufferSourceException(size_t pos, size_t size, + size_t valueSize) +{ + std::ostringstream ss; + ACE_Stack_Trace trace; + + ss << "Attempted to put a " + << (valueSize > 0 ? "NULL-pointer" : "zero-sized value") + << " in ByteBuffer (pos: " << pos << " size: " << size << ")\n\n" + << trace.c_str(); + + message().assign(ss.str()); +} + +void ByteBuffer::print_storage() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + for (uint32 i = 0; i < size(); ++i) + o << read<uint8>(i) << " - "; + o << " "; + + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} + +void ByteBuffer::textlike() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + for (uint32 i = 0; i < size(); ++i) + { + char buf[1]; + snprintf(buf, 1, "%c", read<uint8>(i)); + o << buf; + } + o << " "; + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} + +void ByteBuffer::hexlike() const +{ + if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled trace output + return; + + uint32 j = 1, k = 1; + + std::ostringstream o; + o << "STORAGE_SIZE: " << size(); + + for (uint32 i = 0; i < size(); ++i) + { + char buf[3]; + snprintf(buf, 1, "%2X ", read<uint8>(i)); + if ((i == (j * 8)) && ((i != (k * 16)))) + { + o << "| "; + ++j; + } + else if (i == (k * 16)) + { + o << "\n"; + ++k; + ++j; + } + + o << buf; + } + o << " "; + sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); +} diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index ceab4ca442e..9b16c2e9c0b 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -19,64 +19,47 @@ #ifndef _BYTEBUFFER_H #define _BYTEBUFFER_H -#include "Common.h" +#include "Define.h" #include "Debugging/Errors.h" -#include "Logging/Log.h" #include "Utilities/ByteConverter.h" -class ByteBufferException +#include <exception> +#include <list> +#include <map> +#include <string> +#include <vector> + +#include <cstring> + +// Root of ByteBuffer exception hierarchy +class ByteBufferException : public std::exception { - public: - ByteBufferException(size_t pos, size_t size, size_t valueSize) - : Pos(pos), Size(size), ValueSize(valueSize) - { - } +public: + ~ByteBufferException() throw() { } - protected: - size_t Pos; - size_t Size; - size_t ValueSize; + char const * what() const throw() { return msg_.c_str(); } + +protected: + std::string & message() throw() { return msg_; } + +private: + std::string msg_; }; class ByteBufferPositionException : public ByteBufferException { - public: - ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize) - : ByteBufferException(pos, size, valueSize), _add(add) - { - PrintError(); - } - - protected: - void PrintError() const - { - ACE_Stack_Trace trace; - - sLog->outError(LOG_FILTER_NETWORKIO, "Attempted to %s value with size: "SIZEFMTD" in ByteBuffer (pos: " SIZEFMTD " size: "SIZEFMTD")\n[Stacktrace: %s]", - (_add ? "put" : "get"), ValueSize, Pos, Size, trace.c_str()); - } +public: + ByteBufferPositionException(bool add, size_t pos, size_t size, size_t valueSize); - private: - bool _add; + ~ByteBufferPositionException() throw() { } }; class ByteBufferSourceException : public ByteBufferException { - public: - ByteBufferSourceException(size_t pos, size_t size, size_t valueSize) - : ByteBufferException(pos, size, valueSize) - { - PrintError(); - } +public: + ByteBufferSourceException(size_t pos, size_t size, size_t valueSize); - protected: - void PrintError() const - { - ACE_Stack_Trace trace; - - sLog->outError(LOG_FILTER_NETWORKIO, "Attempted to put a %s in ByteBuffer (pos: "SIZEFMTD" size: "SIZEFMTD")\n[Stacktrace: %s]", - (ValueSize > 0 ? "NULL-pointer" : "zero-sized value"), Pos, Size, trace.c_str()); - } + ~ByteBufferSourceException() throw() { } }; class ByteBuffer @@ -85,19 +68,21 @@ class ByteBuffer const static size_t DEFAULT_SIZE = 0x1000; // constructor - ByteBuffer(): _rpos(0), _wpos(0) + ByteBuffer() : _rpos(0), _wpos(0) { _storage.reserve(DEFAULT_SIZE); } - // constructor - ByteBuffer(size_t res): _rpos(0), _wpos(0) + ByteBuffer(size_t reserve) : _rpos(0), _wpos(0) { - _storage.reserve(res); + _storage.reserve(reserve); } // copy constructor - ByteBuffer(const ByteBuffer &buf): _rpos(buf._rpos), _wpos(buf._wpos), _storage(buf._storage) { } + ByteBuffer(const ByteBuffer &buf) : _rpos(buf._rpos), _wpos(buf._wpos), + _storage(buf._storage) + { + } void clear() { @@ -275,9 +260,18 @@ class ByteBuffer return *this; } - uint8 operator[](size_t pos) const + uint8& operator[](size_t const pos) { - return read<uint8>(pos); + if (pos >= size()) + throw ByteBufferPositionException(false, pos, 1, size()); + return _storage[pos]; + } + + uint8 const& operator[](size_t const pos) const + { + if (pos >= size()) + throw ByteBufferPositionException(false, pos, 1, size()); + return _storage[pos]; } size_t rpos() const { return _rpos; } @@ -331,7 +325,7 @@ class ByteBuffer { if (_rpos + len > size()) throw ByteBufferPositionException(false, _rpos, len, size()); - memcpy(dest, &_storage[_rpos], len); + std::memcpy(dest, &_storage[_rpos], len); _rpos += len; } @@ -362,8 +356,7 @@ class ByteBuffer uint32 ReadPackedTime() { uint32 packedDate = read<uint32>(); - tm lt; - memset(<, 0, sizeof(lt)); + tm lt = tm(); lt.tm_min = packedDate & 0x3F; lt.tm_hour = (packedDate >> 6) & 0x1F; @@ -423,7 +416,7 @@ class ByteBuffer if (_storage.size() < _wpos + cnt) _storage.resize(_wpos + cnt); - memcpy(&_storage[_wpos], src, cnt); + std::memcpy(&_storage[_wpos], src, cnt); _wpos += cnt; } @@ -476,71 +469,14 @@ class ByteBuffer if (!src) throw ByteBufferSourceException(_wpos, size(), cnt); - memcpy(&_storage[pos], src, cnt); + std::memcpy(&_storage[pos], src, cnt); } - void print_storage() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; + void print_storage() const; - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - for (uint32 i = 0; i < size(); ++i) - o << read<uint8>(i) << " - "; - o << " "; + void textlike() const; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } - - void textlike() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; - - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - for (uint32 i = 0; i < size(); ++i) - { - char buf[1]; - snprintf(buf, 1, "%c", read<uint8>(i)); - o << buf; - } - o << " "; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } - - void hexlike() const - { - if (!sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE)) // optimize disabled debug output - return; - - uint32 j = 1, k = 1; - - std::ostringstream o; - o << "STORAGE_SIZE: " << size(); - - for (uint32 i = 0; i < size(); ++i) - { - char buf[3]; - snprintf(buf, 1, "%2X ", read<uint8>(i)); - if ((i == (j * 8)) && ((i != (k * 16)))) - { - o << "| "; - ++j; - } - else if (i == (k * 16)) - { - o << "\n"; - ++k; - ++j; - } - - o << buf; - } - o << " "; - sLog->outTrace(LOG_FILTER_NETWORKIO, "%s", o.str().c_str()); - } + void hexlike() const; protected: size_t _rpos, _wpos; @@ -652,5 +588,6 @@ inline void ByteBuffer::read_skip<std::string>() { read_skip<char*>(); } + #endif diff --git a/src/server/worldserver/worldserver.conf.dist b/src/server/worldserver/worldserver.conf.dist index 0802aca43ce..bf19240407f 100644 --- a/src/server/worldserver/worldserver.conf.dist +++ b/src/server/worldserver/worldserver.conf.dist @@ -1123,7 +1123,7 @@ AccountInstancesPerHour = 5 # RBAC.DefaultGroups # Description: Comma separated list of groups to be added to any account # Check auth.rbac_groups for correct ids -# Default: "" (No group) +# Default: "" (No group) RBAC.DefaultGroups = "" @@ -2712,6 +2712,7 @@ Appenders=Console Server GM DBErrors Char RA Warden Chat # 41 - Opcodes (just id and name sent / received) # 42 - SOAP # 43 - RBAC (Role Based Access Control) +# 44 - Cheat (used to log cheat attempts) # # LogLevel # 0 - (Disabled) |