diff options
| author | Nay <dnpd.dd@gmail.com> | 2012-11-23 23:39:03 +0000 |
|---|---|---|
| committer | Nay <dnpd.dd@gmail.com> | 2012-11-23 23:39:03 +0000 |
| commit | 24cd72c8e1d6d1745b58de11ae8a03043dbfa394 (patch) | |
| tree | 6d6a05d15cf0ebb4fc40d065d4b596a4a167b063 /src/server/game | |
| parent | ef7f6b7c1eb7866c57e5a31a386f5a8d55c8fd22 (diff) | |
| parent | eb10226b02ec3cf0370840ebed00315fed566262 (diff) | |
Merge remote-tracking branch 'origin/master' into mmaps
Conflicts:
src/server/game/Maps/Map.cpp
src/server/game/Movement/MovementGenerator.h
src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.h
src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.h
src/server/game/Movement/MovementGenerators/HomeMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/HomeMovementGenerator.h
src/server/game/Movement/MovementGenerators/PointMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/PointMovementGenerator.h
src/server/game/Movement/MovementGenerators/RandomMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/RandomMovementGenerator.h
src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.h
src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.cpp
src/server/game/Movement/MovementGenerators/WaypointMovementGenerator.h
src/server/game/Spells/SpellEffects.cpp
Diffstat (limited to 'src/server/game')
150 files changed, 3638 insertions, 3661 deletions
diff --git a/src/server/game/AI/CoreAI/CombatAI.cpp b/src/server/game/AI/CoreAI/CombatAI.cpp index 5ab5f99310a..d9d19c2f009 100755 --- a/src/server/game/AI/CoreAI/CombatAI.cpp +++ b/src/server/game/AI/CoreAI/CombatAI.cpp @@ -21,6 +21,7 @@ #include "SpellInfo.h" #include "Vehicle.h" #include "ObjectAccessor.h" +#include "Player.h" int AggressorAI::Permissible(const Creature* creature) { diff --git a/src/server/game/AI/CoreAI/GameObjectAI.h b/src/server/game/AI/CoreAI/GameObjectAI.h index 6dfea9ac158..4561aa92741 100644 --- a/src/server/game/AI/CoreAI/GameObjectAI.h +++ b/src/server/game/AI/CoreAI/GameObjectAI.h @@ -37,12 +37,12 @@ class GameObjectAI virtual void InitializeAI() { Reset(); } - virtual void Reset() {}; + virtual void Reset() { } // Pass parameters between AI virtual void DoAction(const int32 /*param = 0 */) {} - virtual void SetGUID(const uint64& /*guid*/, int32 /*id = 0 */) {} - virtual uint64 GetGUID(int32 /*id = 0 */) { return 0; } + virtual void SetGUID(uint64 /*guid*/, int32 /*id = 0 */) {} + virtual uint64 GetGUID(int32 /*id = 0 */) const { return 0; } static int Permissible(GameObject const* go); @@ -53,9 +53,9 @@ class GameObjectAI virtual bool QuestReward(Player* /*player*/, Quest const* /*quest*/, uint32 /*opt*/) { return false; } virtual uint32 GetDialogStatus(Player* /*player*/) { return 100; } virtual void Destroyed(Player* /*player*/, uint32 /*eventId*/) {} - virtual uint32 GetData(uint32 /*id*/) { return 0; } + virtual uint32 GetData(uint32 /*id*/) const { return 0; } virtual void SetData64(uint32 /*id*/, uint64 /*value*/) {} - virtual uint64 GetData64(uint32 /*id*/) { return 0; } + virtual uint64 GetData64(uint32 /*id*/) const { return 0; } virtual void SetData(uint32 /*id*/, uint32 /*value*/) {} virtual void OnGameEvent(bool /*start*/, uint16 /*eventId*/) {} virtual void OnStateChanged(uint32 /*state*/, Unit* /*unit*/) {} diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index 6802c109401..1de5417b820 100755 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -90,8 +90,6 @@ void PetAI::UpdateAI(const uint32 diff) else m_updateAlliesTimer -= diff; - // me->getVictim() can't be used for check in case stop fighting, me->getVictim() clear at Unit death etc. - // Must also check if victim is alive if (me->getVictim() && me->getVictim()->isAlive()) { // is only necessary to stop casting, the pet must not exit combat @@ -108,7 +106,9 @@ void PetAI::UpdateAI(const uint32 diff) return; } - DoMeleeAttackIfReady(); + // Check before attacking to prevent pets from leaving stay position + if (CanAttack(me->getVictim())) + DoMeleeAttackIfReady(); } else if (owner && me->GetCharmInfo()) //no victim { @@ -335,7 +335,8 @@ void PetAI::AttackStart(Unit* target) if (Unit* owner = me->GetOwner()) owner->SetInCombatWith(target); - DoAttack(target, true); + // Only chase if not commanded to stay or if stay but commanded to attack + DoAttack(target, (!me->GetCharmInfo()->HasCommandState(COMMAND_STAY) || me->GetCharmInfo()->IsCommandAttack())); } void PetAI::OwnerDamagedBy(Unit* attacker) @@ -382,31 +383,42 @@ void PetAI::OwnerAttacked(Unit* target) Unit* PetAI::SelectNextTarget() { // Provides next target selection after current target death + // Targets are not evaluated here for being valid attack targets // Passive pets don't do next target selection if (me->HasReactState(REACT_PASSIVE)) return NULL; - Unit* target = me->getAttackerForHelper(); + // Check pet attackers first so we don't drag a bunch of targets to the owner + if (Unit* myAttacker = me->getAttackerForHelper()) + if (!myAttacker->HasBreakableByDamageCrowdControlAura()) + return myAttacker; - // Check pet's attackers first to prevent dragging mobs back to owner - if (target && !target->HasBreakableByDamageCrowdControlAura()) - return target; - - if (me->GetCharmerOrOwner()) - { - // Check owner's attackers if pet didn't have any - target = me->GetCharmerOrOwner()->getAttackerForHelper(); - if (target && !target->HasBreakableByDamageCrowdControlAura()) - return target; - - // 3.0.2 - Pets now start attacking their owners target in defensive mode as soon as the hunter does - target = me->GetCharmerOrOwner()->getVictim(); - if (target && !target->HasBreakableByDamageCrowdControlAura()) - return target; - } + // Not sure why we wouldn't have an owner but just in case... + if (!me->GetCharmerOrOwner()) + return NULL; - // Default + // Check owner attackers + if (Unit* ownerAttacker = me->GetCharmerOrOwner()->getAttackerForHelper()) + if (!ownerAttacker->HasBreakableByDamageCrowdControlAura()) + return ownerAttacker; + + // Check owner victim + // 3.0.2 - Pets now start attacking their owners victim in defensive mode as soon as the hunter does + if (Unit* ownerVictim = me->GetCharmerOrOwner()->getVictim()) + if (!ownerVictim->HasBreakableByDamageCrowdControlAura()) + return ownerVictim; + + // Neither pet or owner had a target and aggressive pets can pick any target + // Note: Creature::SelectNearestTarget() If no distance is supplied it uses MAX_VISIBILITY_DISTANCE + // We also want to lock this to LOS so pet doesn't go running through walls and stuff + if (me->HasReactState(REACT_AGGRESSIVE)) + if (Unit* nearTarget = me->ToCreature()->SelectNearestTarget()) + if (nearTarget->IsHostileTo(me) && !nearTarget->HasBreakableByDamageCrowdControlAura()) + if (nearTarget->IsWithinLOS(me->GetPositionX(), me->GetPositionY(), me->GetPositionZ())) + return nearTarget; + + // Default - no valid targets return NULL; } @@ -518,6 +530,10 @@ bool PetAI::CanAttack(Unit* target) // Evaluates wether a pet can attack a specific // target based on CommandState, ReactState and other flags + // Can't attack dead targets... + if (!target->isAlive()) + return false; + // Returning - check first since pets returning ignore attacks if (me->GetCharmInfo()->IsReturning()) return false; @@ -526,19 +542,17 @@ bool PetAI::CanAttack(Unit* target) if (me->HasReactState(REACT_PASSIVE)) return me->GetCharmInfo()->IsCommandAttack(); - // Pets commanded to attack should not stop their approach if attacked by another creature - if (me->getVictim() && (me->getVictim() != target)) - return !me->GetCharmInfo()->IsCommandAttack(); - - // From this point on, pet will always be either aggressive or defensive + // Follow + if (me->GetCharmInfo()->HasCommandState(COMMAND_FOLLOW)) + return true; // Stay - can attack if target is within range or commanded to if (me->GetCharmInfo()->HasCommandState(COMMAND_STAY)) - return (me->IsWithinMeleeRange(target, MELEE_RANGE) || me->GetCharmInfo()->IsCommandAttack()); + return (me->IsWithinMeleeRange(target) || me->GetCharmInfo()->IsCommandAttack()); - // Follow - if (me->GetCharmInfo()->HasCommandState(COMMAND_FOLLOW)) - return true; + // Pets commanded to attack should not stop their approach if attacked by another creature + if (me->getVictim() && (me->getVictim() != target)) + return !me->GetCharmInfo()->IsCommandAttack(); // default, though we shouldn't ever get here return false; diff --git a/src/server/game/AI/CoreAI/UnitAI.h b/src/server/game/AI/CoreAI/UnitAI.h index b07c766ae0b..2eab0e89fcd 100755 --- a/src/server/game/AI/CoreAI/UnitAI.h +++ b/src/server/game/AI/CoreAI/UnitAI.h @@ -24,8 +24,9 @@ #include "Containers.h" #include <list> -class Unit; class Player; +class Quest; +class Unit; struct AISpellInfoType; // Default script texts @@ -146,10 +147,10 @@ class UnitAI // Pass parameters between AI virtual void DoAction(int32 const /*param*/) {} - virtual uint32 GetData(uint32 /*id = 0*/) { return 0; } + virtual uint32 GetData(uint32 /*id = 0*/) const { return 0; } virtual void SetData(uint32 /*id*/, uint32 /*value*/) {} virtual void SetGUID(uint64 /*guid*/, int32 /*id*/ = 0) {} - virtual uint64 GetGUID(int32 /*id*/ = 0) { return 0; } + virtual uint64 GetGUID(int32 /*id*/ = 0) const { return 0; } Unit* SelectTarget(SelectAggroTarget targetType, uint32 position = 0, float dist = 0.0f, bool playerOnly = false, int32 aura = 0); // Select the targets satifying the predicate. diff --git a/src/server/game/AI/EventAI/CreatureEventAI.cpp b/src/server/game/AI/EventAI/CreatureEventAI.cpp index 78a84eb7ae4..84e44109e58 100755 --- a/src/server/game/AI/EventAI/CreatureEventAI.cpp +++ b/src/server/game/AI/EventAI/CreatureEventAI.cpp @@ -497,23 +497,6 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 } break; } - case ACTION_T_SUMMON: - { - Unit* target = GetTargetByType(action.summon.target, actionInvoker); - - Creature* creature = NULL; - - if (action.summon.duration) - creature = me->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, action.summon.duration); - else - creature = me->SummonCreature(action.summon.creatureId, 0.0f, 0.0f, 0.0f, 0.0f, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0); - - if (!creature) - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: failed to spawn creature %u. Spawn event %d is on creature %d", action.summon.creatureId, eventId, me->GetEntry()); - else if (action.summon.target != TARGET_T_SELF && target) - creature->AI()->AttackStart(target); - break; - } case ACTION_T_THREAT_SINGLE_PCT: if (Unit* target = GetTargetByType(action.threat_single_pct.target, actionInvoker)) me->getThreatManager().modifyThreatPercent(target, action.threat_single_pct.percent); @@ -663,30 +646,6 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 else sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: ACTION_T_RANDOM_PHASE_RANGE cannot have Param2 < Param1. Event = %d. CreatureEntry = %d", eventId, me->GetEntry()); break; - case ACTION_T_SUMMON_ID: - { - Unit* target = GetTargetByType(action.summon_id.target, actionInvoker); - - CreatureEventAI_Summon_Map::const_iterator i = sEventAIMgr->GetCreatureEventAISummonMap().find(action.summon_id.spawnId); - if (i == sEventAIMgr->GetCreatureEventAISummonMap().end()) - { - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: failed to spawn creature %u. Summon map index %u does not exist. EventID %d. CreatureID %d", action.summon_id.creatureId, action.summon_id.spawnId, eventId, me->GetEntry()); - return; - } - - Creature* creature = NULL; - if ((*i).second.SpawnTimeSecs) - creature = me->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, (*i).second.SpawnTimeSecs); - else - creature = me->SummonCreature(action.summon_id.creatureId, (*i).second.position_x, (*i).second.position_y, (*i).second.position_z, (*i).second.orientation, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 0); - - if (!creature) - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: failed to spawn creature %u. EventId %d.Creature %d", action.summon_id.creatureId, eventId, me->GetEntry()); - else if (action.summon_id.target != TARGET_T_SELF && target) - creature->AI()->AttackStart(target); - - break; - } case ACTION_T_KILLED_MONSTER: //first attempt player who tapped creature if (Player* player = me->GetLootRecipient()) @@ -798,7 +757,6 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32 } break; } - case ACTION_T_SET_SHEATH: { me->SetSheath(SheathState(action.set_sheath.sheath)); diff --git a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp index 2d973d9eb8f..f3df332c1e9 100755 --- a/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp +++ b/src/server/game/AI/EventAI/CreatureEventAIMgr.cpp @@ -26,6 +26,7 @@ #include "ConditionMgr.h" #include "SpellMgr.h" #include "SpellInfo.h" +#include "Player.h" // ------------------- void CreatureEventAIMgr::LoadCreatureEventAI_Texts() @@ -100,52 +101,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Texts() sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u additional CreatureEventAI Texts data in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } -void CreatureEventAIMgr::LoadCreatureEventAI_Summons() -{ - uint32 oldMSTime = getMSTime(); - - //Drop Existing EventSummon Map - m_CreatureEventAI_Summon_Map.clear(); - - // Gather additional data for EventAI - QueryResult result = WorldDatabase.Query("SELECT id, position_x, position_y, position_z, orientation, spawntimesecs FROM creature_ai_summons"); - - if (!result) - { - sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 CreatureEventAI Summon definitions. DB table `creature_ai_summons` is empty."); - return; - } - - uint32 count = 0; - - do - { - Field* fields = result->Fetch(); - - CreatureEventAI_Summon temp; - - uint32 i = fields[0].GetUInt32(); - temp.position_x = fields[1].GetFloat(); - temp.position_y = fields[2].GetFloat(); - temp.position_z = fields[3].GetFloat(); - temp.orientation = fields[4].GetFloat(); - temp.SpawnTimeSecs = fields[5].GetUInt32(); - - if (!Trinity::IsValidMapCoord(temp.position_x, temp.position_y, temp.position_z, temp.orientation)) - { - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: Summon id %u have wrong coordinates (%f, %f, %f, %f), skipping.", i, temp.position_x, temp.position_y, temp.position_z, temp.orientation); - continue; - } - - //Add to map - m_CreatureEventAI_Summon_Map[i] = temp; - ++count; - } - while (result->NextRow()); - - sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u CreatureEventAI summon definitions in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); -} - void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() { uint32 oldMSTime = getMSTime(); @@ -622,14 +577,6 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts() // equal case processed at call } break; - case ACTION_T_SUMMON_ID: - if (!sObjectMgr->GetCreatureTemplate(action.summon_id.creatureId)) - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: Event %u Action %u uses non-existant creature entry %u.", i, j+1, action.summon_id.creatureId); - if (action.summon_id.target >= TARGET_T_END) - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: Event %u Action %u uses incorrect Target type", i, j+1); - if (m_CreatureEventAI_Summon_Map.find(action.summon_id.spawnId) == m_CreatureEventAI_Summon_Map.end()) - sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: Event %u Action %u summons missing CreatureEventAI_Summon %u", i, j+1, action.summon_id.spawnId); - break; case ACTION_T_KILLED_MONSTER: if (!sObjectMgr->GetCreatureTemplate(action.killed_monster.creatureId)) sLog->outError(LOG_FILTER_SQL, "CreatureEventAI: Event %u Action %u uses non-existant creature entry %u.", i, j+1, action.killed_monster.creatureId); diff --git a/src/server/game/AI/EventAI/CreatureEventAIMgr.h b/src/server/game/AI/EventAI/CreatureEventAIMgr.h index 93e953681b6..75e24266fb5 100755 --- a/src/server/game/AI/EventAI/CreatureEventAIMgr.h +++ b/src/server/game/AI/EventAI/CreatureEventAIMgr.h @@ -32,16 +32,13 @@ class CreatureEventAIMgr public: void LoadCreatureEventAI_Texts(); - void LoadCreatureEventAI_Summons(); void LoadCreatureEventAI_Scripts(); CreatureEventAI_Event_Map const& GetCreatureEventAIMap() const { return m_CreatureEventAI_Event_Map; } - CreatureEventAI_Summon_Map const& GetCreatureEventAISummonMap() const { return m_CreatureEventAI_Summon_Map; } CreatureEventAI_TextMap const& GetCreatureEventAITextMap() const { return m_CreatureEventAI_TextMap; } private: CreatureEventAI_Event_Map m_CreatureEventAI_Event_Map; - CreatureEventAI_Summon_Map m_CreatureEventAI_Summon_Map; CreatureEventAI_TextMap m_CreatureEventAI_TextMap; }; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp index f8025a32b7f..67cabc6ccb1 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.cpp @@ -77,17 +77,13 @@ void SummonList::RemoveNotExisting() } } -bool SummonList::HasEntry(uint32 entry) +bool SummonList::HasEntry(uint32 entry) const { - for (iterator i = begin(); i != end();) + for (const_iterator i = begin(); i != end(); ++i) { Creature* summon = Unit::GetCreature(*me, *i); - if (!summon) - erase(i++); - else if (summon->GetEntry() == entry) + if (summon && summon->GetEntry() == entry) return true; - else - ++i; } return false; diff --git a/src/server/game/AI/ScriptedAI/ScriptedCreature.h b/src/server/game/AI/ScriptedAI/ScriptedCreature.h index aa46d555b7d..2a221d04404 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedCreature.h +++ b/src/server/game/AI/ScriptedAI/ScriptedCreature.h @@ -54,7 +54,7 @@ class SummonList : public std::list<uint64> void DoZoneInCombat(uint32 entry = 0); void RemoveNotExisting(); - bool HasEntry(uint32 entry); + bool HasEntry(uint32 entry) const; private: Creature* me; }; diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp index 9c666e7de32..3f5952a210d 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.cpp @@ -12,6 +12,7 @@ EndScriptData */ #include "ScriptedCreature.h" #include "ScriptedEscortAI.h" #include "Group.h" +#include "Player.h" enum ePoints { diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp index ebb734156b4..96209084240 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp +++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.cpp @@ -12,6 +12,7 @@ EndScriptData */ #include "ScriptedCreature.h" #include "ScriptedFollowerAI.h" #include "Group.h" +#include "Player.h" const float MAX_PLAYER_DISTANCE = 100.0f; diff --git a/src/server/game/AI/ScriptedAI/ScriptedGossip.h b/src/server/game/AI/ScriptedAI/ScriptedGossip.h index 34300ff406c..ae1b5fcc12d 100644 --- a/src/server/game/AI/ScriptedAI/ScriptedGossip.h +++ b/src/server/game/AI/ScriptedAI/ScriptedGossip.h @@ -8,7 +8,6 @@ #ifndef SC_GOSSIP_H #define SC_GOSSIP_H -#include "Player.h" #include "GossipDef.h" #include "QuestDef.h" diff --git a/src/server/game/AI/SmartScripts/SmartAI.cpp b/src/server/game/AI/SmartScripts/SmartAI.cpp index 7dd4053b82f..6aebcbb2d8a 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.cpp +++ b/src/server/game/AI/SmartScripts/SmartAI.cpp @@ -698,7 +698,7 @@ void SmartAI::DoAction(const int32 param) GetScript()->ProcessEventsFor(SMART_EVENT_ACTION_DONE, NULL, param); } -uint32 SmartAI::GetData(uint32 /*id*/) +uint32 SmartAI::GetData(uint32 /*id*/) const { return 0; } @@ -712,7 +712,7 @@ void SmartAI::SetGUID(uint64 /*guid*/, int32 /*id*/) { } -uint64 SmartAI::GetGUID(int32 /*id*/) +uint64 SmartAI::GetGUID(int32 /*id*/) const { return 0; } diff --git a/src/server/game/AI/SmartScripts/SmartAI.h b/src/server/game/AI/SmartScripts/SmartAI.h index f81d6e86850..6f748f9dee2 100644 --- a/src/server/game/AI/SmartScripts/SmartAI.h +++ b/src/server/game/AI/SmartScripts/SmartAI.h @@ -22,7 +22,6 @@ #include "Creature.h" #include "CreatureAI.h" #include "Unit.h" -#include "ConditionMgr.h" #include "Spell.h" #include "SmartScript.h" @@ -151,7 +150,7 @@ class SmartAI : public CreatureAI void DoAction(const int32 param = 0); // Used in scripts to share variables - uint32 GetData(uint32 id = 0); + uint32 GetData(uint32 id = 0) const; // Used in scripts to share variables void SetData(uint32 id, uint32 value); @@ -160,7 +159,7 @@ class SmartAI : public CreatureAI void SetGUID(uint64 guid, int32 id = 0); // Used in scripts to share variables - uint64 GetGUID(int32 id = 0); + uint64 GetGUID(int32 id = 0) const; //core related static int Permissible(const Creature*); diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index a1fb2147cc2..2cd65c42f74 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -15,25 +15,25 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "Cell.h" +#include "CellImpl.h" +#include "CreatureTextMgr.h" #include "DatabaseEnv.h" -#include "ObjectMgr.h" -#include "ObjectDefines.h" +#include "GossipDef.h" #include "GridDefines.h" #include "GridNotifiers.h" -#include "SpellMgr.h" #include "GridNotifiersImpl.h" -#include "Cell.h" -#include "CellImpl.h" +#include "Group.h" #include "InstanceScript.h" +#include "Language.h" +#include "ObjectDefines.h" +#include "ObjectMgr.h" #include "ScriptedCreature.h" -#include "GossipDef.h" -#include "ScriptedCreature.h" -#include "SmartScript.h" +#include "ScriptedGossip.h" #include "SmartAI.h" -#include "Group.h" +#include "SmartScript.h" +#include "SpellMgr.h" #include "Vehicle.h" -#include "ScriptedGossip.h" -#include "CreatureTextMgr.h" class TrinityStringTextBuilder { @@ -472,6 +472,13 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr) { + // Special handling for vehicles + if (IsUnit(*itr)) + if (Vehicle* vehicle = (*itr)->ToUnit()->GetVehicleKit()) + for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it) + if (Player* player = ObjectAccessor::FindPlayer(it->second.Passenger)) + player->AreaExploredOrEventHappens(e.action.quest.quest); + if (IsPlayer(*itr)) { (*itr)->ToPlayer()->AreaExploredOrEventHappens(e.action.quest.quest); @@ -746,12 +753,21 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u } case SMART_ACTION_CALL_GROUPEVENTHAPPENS: { + if (!unit) + break; + if (IsPlayer(unit) && GetBaseObject()) { unit->ToPlayer()->GroupEventHappens(e.action.quest.quest, GetBaseObject()); sLog->outDebug(LOG_FILTER_DATABASE_AI, "SmartScript::ProcessAction: SMART_ACTION_CALL_GROUPEVENTHAPPENS: Player %u, group credit for quest %u", unit->GetGUIDLow(), e.action.quest.quest); } + + // Special handling for vehicles + if (Vehicle* vehicle = unit->GetVehicleKit()) + for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it) + if (Player* player = ObjectAccessor::FindPlayer(it->second.Passenger)) + player->GroupEventHappens(e.action.quest.quest, GetBaseObject()); break; } case SMART_ACTION_CALL_CASTEDCREATUREORGO: @@ -878,6 +894,13 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr) { + // Special handling for vehicles + if (IsUnit(*itr)) + if (Vehicle* vehicle = (*itr)->ToUnit()->GetVehicleKit()) + for (SeatMap::iterator it = vehicle->Seats.begin(); it != vehicle->Seats.end(); ++it) + if (Player* player = ObjectAccessor::FindPlayer(it->second.Passenger)) + player->RewardPlayerAndGroupAtEvent(e.action.killedMonster.creature, player); + if (!IsPlayer(*itr)) continue; diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h index 2a0eceb574a..61e22b25d17 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.h +++ b/src/server/game/AI/SmartScripts/SmartScript.h @@ -22,7 +22,6 @@ #include "Creature.h" #include "CreatureAI.h" #include "Unit.h" -#include "ConditionMgr.h" #include "Spell.h" #include "GridNotifiers.h" diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 2b67acfd6d0..a82de501ea6 100755 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -22,6 +22,7 @@ #include "Player.h" #include "Util.h" #include "SHA1.h" +#include "WorldSession.h" namespace AccountMgr { diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp index 0ee133edce9..91437ae3bb5 100755 --- a/src/server/game/Achievements/AchievementMgr.cpp +++ b/src/server/game/Achievements/AchievementMgr.cpp @@ -16,30 +16,32 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Common.h" -#include "DBCEnums.h" -#include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "GuildMgr.h" -#include "World.h" -#include "WorldPacket.h" -#include "DatabaseEnv.h" #include "AchievementMgr.h" #include "ArenaTeam.h" +#include "ArenaTeamMgr.h" +#include "BattlegroundAB.h" +#include "Battleground.h" #include "CellImpl.h" +#include "Common.h" +#include "DatabaseEnv.h" +#include "DBCEnums.h" +#include "DisableMgr.h" #include "GameEventMgr.h" #include "GridNotifiersImpl.h" #include "Guild.h" +#include "GuildMgr.h" +#include "InstanceScript.h" #include "Language.h" +#include "Map.h" +#include "MapManager.h" +#include "ObjectMgr.h" #include "Player.h" -#include "SpellMgr.h" -#include "DisableMgr.h" +#include "ReputationMgr.h" #include "ScriptMgr.h" -#include "MapManager.h" -#include "Battleground.h" -#include "BattlegroundAB.h" -#include "Map.h" -#include "InstanceScript.h" +#include "SpellMgr.h" +#include "World.h" +#include "WorldPacket.h" + namespace Trinity { @@ -355,7 +357,7 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un return false; return target->getGender() == gender.gender; case ACHIEVEMENT_CRITERIA_DATA_TYPE_SCRIPT: - return sScriptMgr->OnCriteriaCheck(this, const_cast<Player*>(source), const_cast<Unit*>(target)); + return sScriptMgr->OnCriteriaCheck(ScriptId, const_cast<Player*>(source), const_cast<Unit*>(target)); case ACHIEVEMENT_CRITERIA_DATA_TYPE_MAP_DIFFICULTY: if (source->GetMap()->IsRaid()) if (source->GetMap()->Is25ManRaid() != ((difficulty.difficulty & RAID_DIFFICULTY_MASK_25MAN) != 0)) @@ -1617,7 +1619,6 @@ void AchievementMgr::UpdateAchievementCriteria(AchievementCriteriaTypes type, ui case ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK: case ACHIEVEMENT_CRITERIA_TYPE_EARNED_PVP_TITLE: case ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE: - case ACHIEVEMENT_CRITERIA_TYPE_TOTAL: break; // Not implemented yet :( } @@ -2405,7 +2406,7 @@ void AchievementGlobalMgr::LoadCompletedAchievements() if (!result) { - sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 completed achievements. DB table `character_achievement` is empty."); + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded 0 realm first completed achievements. DB table `character_achievement` is empty."); return; } @@ -2432,7 +2433,7 @@ void AchievementGlobalMgr::LoadCompletedAchievements() m_allCompletedAchievements.insert(achievementId); } while (result->NextRow()); - sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %lu completed achievements in %u ms", (unsigned long)m_allCompletedAchievements.size(), GetMSTimeDiffToNow(oldMSTime)); + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %lu realm first completed achievements in %u ms", (unsigned long)m_allCompletedAchievements.size(), GetMSTimeDiffToNow(oldMSTime)); } void AchievementGlobalMgr::LoadRewards() diff --git a/src/server/game/Battlefield/Battlefield.cpp b/src/server/game/Battlefield/Battlefield.cpp index b3f5c7bf704..7e3b3cc0f1a 100644 --- a/src/server/game/Battlefield/Battlefield.cpp +++ b/src/server/game/Battlefield/Battlefield.cpp @@ -587,12 +587,12 @@ bool Battlefield::AddOrSetPlayerToCorrectBfGroup(Player* player) //-------------------- //-Battlefield Method- //-------------------- -BfGraveyard* Battlefield::GetGraveyardById(uint32 id) +BfGraveyard* Battlefield::GetGraveyardById(uint32 id) const { if (id < m_GraveyardList.size()) { - if (m_GraveyardList[id]) - return m_GraveyardList[id]; + if (BfGraveyard* graveyard = m_GraveyardList.at(id)) + return graveyard; else sLog->outError(LOG_FILTER_BATTLEFIELD, "Battlefield::GetGraveyardById Id:%u not existed", id); } diff --git a/src/server/game/Battlefield/Battlefield.h b/src/server/game/Battlefield/Battlefield.h index 0752fa88fc1..4533c666869 100644 --- a/src/server/game/Battlefield/Battlefield.h +++ b/src/server/game/Battlefield/Battlefield.h @@ -79,6 +79,8 @@ class BfCapturePoint public: BfCapturePoint(Battlefield* bf); + virtual ~BfCapturePoint() { } + virtual void FillInitialWorldStates(WorldPacket& /*data*/) {} // Send world state update to all players present @@ -145,7 +147,7 @@ class BfGraveyard // Method to changing who controls the graveyard void GiveControlTo(TeamId team); - TeamId GetControlTeamId() { return m_ControlTeam; } + TeamId GetControlTeamId() const { return m_ControlTeam; } // Find the nearest graveyard to a player float GetDistance(Player* player); @@ -185,7 +187,7 @@ class BfGraveyard bool HasPlayer(uint64 guid) { return m_ResurrectQueue.find(guid) != m_ResurrectQueue.end(); } // Get the graveyard's ID. - uint32 GetGraveyardId() { return m_GraveyardId; } + uint32 GetGraveyardId() const { return m_GraveyardId; } protected: TeamId m_ControlTeam; @@ -258,11 +260,11 @@ class Battlefield : public ZoneScript void HandlePlayerLeaveZone(Player* player, uint32 zone); // All-purpose data storage 64 bit - virtual uint64 GetData64(uint32 dataId) { return m_Data64[dataId]; } + virtual uint64 GetData64(uint32 dataId) const { return m_Data64[dataId]; } virtual void SetData64(uint32 dataId, uint64 value) { m_Data64[dataId] = value; } // All-purpose data storage 32 bit - virtual uint32 GetData(uint32 dataId) { return m_Data32[dataId]; } + virtual uint32 GetData(uint32 dataId) const { return m_Data32[dataId]; } virtual void SetData(uint32 dataId, uint32 value) { m_Data32[dataId] = value; } virtual void UpdateData(uint32 index, int32 pad) { m_Data32[index] += pad; } @@ -290,7 +292,7 @@ class Battlefield : public ZoneScript virtual void AddPlayerToResurrectQueue(uint64 npc_guid, uint64 player_guid); void RemovePlayerFromResurrectQueue(uint64 player_guid); void SetGraveyardNumber(uint32 number) { m_GraveyardList.resize(number); } - BfGraveyard* GetGraveyardById(uint32 id); + BfGraveyard* GetGraveyardById(uint32 id) const; // Misc methods Creature* SpawnCreature(uint32 entry, float x, float y, float z, float o, TeamId team); diff --git a/src/server/game/Battlefield/BattlefieldHandler.cpp b/src/server/game/Battlefield/BattlefieldHandler.cpp index 1ebeb664fb3..a2d8cec3936 100644 --- a/src/server/game/Battlefield/BattlefieldHandler.cpp +++ b/src/server/game/Battlefield/BattlefieldHandler.cpp @@ -25,6 +25,7 @@ #include "Battlefield.h" #include "BattlefieldMgr.h" #include "Opcodes.h" +#include "Player.h" //This send to player windows for invite player to join the war //Param1:(BattleId) the BattleId of Bf diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp index 59dc6761583..0ea4266cc22 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp @@ -20,10 +20,14 @@ // TODO: Use spell victory/defeat in wg instead of RewardMarkOfHonor() && RewardHonor // TODO: Add proper implement of achievement -#include "ObjectMgr.h" #include "BattlefieldWG.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "Player.h" #include "SpellAuras.h" +#include "TemporarySummon.h" #include "Vehicle.h" +#include "WorldSession.h" enum WGVehicles { @@ -453,7 +457,7 @@ void BattlefieldWG::OnStartGrouping() SendWarningToAllInZone(BATTLEFIELD_WG_TEXT_WILL_START); } -uint8 BattlefieldWG::GetSpiritGraveyardId(uint32 areaId) +uint8 BattlefieldWG::GetSpiritGraveyardId(uint32 areaId) const { switch (areaId) { @@ -801,7 +805,7 @@ void BattlefieldWG::OnPlayerEnterZone(Player* player) SendInitWorldStatesTo(player); } -uint32 BattlefieldWG::GetData(uint32 data) +uint32 BattlefieldWG::GetData(uint32 data) const { switch (data) { @@ -812,8 +816,8 @@ uint32 BattlefieldWG::GetData(uint32 data) case AREA_WESTPARK_WORKSHOP: case AREA_EASTPARK_WORKSHOP: // Graveyards and Workshops are controlled by the same team. - if (m_GraveyardList[GetSpiritGraveyardId(data)]) - return m_GraveyardList[GetSpiritGraveyardId(data)]->GetControlTeamId(); + if (BfGraveyard const* graveyard = GetGraveyardById(GetSpiritGraveyardId(data))) + return graveyard->GetControlTeamId(); } return Battlefield::GetData(data); diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.h b/src/server/game/Battlefield/Zones/BattlefieldWG.h index 49ea25a5e04..bd616167e8b 100644 --- a/src/server/game/Battlefield/Zones/BattlefieldWG.h +++ b/src/server/game/Battlefield/Zones/BattlefieldWG.h @@ -21,11 +21,10 @@ #include "ObjectAccessor.h" #include "WorldPacket.h" -#include "World.h" -#include "Group.h" -#include "GroupMgr.h" #include "Battlefield.h" +#include "World.h" +class Group; class BattlefieldWG; class WintergraspCapturePoint; @@ -153,10 +152,10 @@ class BfGraveyardWG : public BfGraveyard public: BfGraveyardWG(BattlefieldWG* Bf); - void SetTextId(uint32 textid) { m_GossipTextId = textid; } - uint32 GetTextId() { return m_GossipTextId; } + void SetTextId(int32 textid) { m_GossipTextId = textid; } + int32 GetTextId() { return m_GossipTextId; } protected: - uint32 m_GossipTextId; + int32 m_GossipTextId; }; enum WGGraveyardId @@ -227,7 +226,7 @@ struct BfWGCoordGY float o; uint32 gyid; uint8 type; - uint32 textid; // for gossip menu + int32 textid; // for gossip menu TeamId startcontrol; }; @@ -412,9 +411,9 @@ class BattlefieldWG : public Battlefield bool FindAndRemoveVehicleFromList(Unit* vehicle); // returns the graveyardId in the specified area. - uint8 GetSpiritGraveyardId(uint32 areaId); + uint8 GetSpiritGraveyardId(uint32 areaId) const; - uint32 GetData(uint32 data); + uint32 GetData(uint32 data) const; protected: bool m_isRelicInteractible; diff --git a/src/server/game/Battlegrounds/ArenaTeam.cpp b/src/server/game/Battlegrounds/ArenaTeam.cpp index d763b29bbc1..fd58765b056 100755 --- a/src/server/game/Battlegrounds/ArenaTeam.cpp +++ b/src/server/game/Battlegrounds/ArenaTeam.cpp @@ -22,6 +22,9 @@ #include "World.h" #include "Group.h" #include "ArenaTeamMgr.h" +#include "Player.h" +#include "WorldSession.h" +#include "Opcodes.h" ArenaTeam::ArenaTeam() : TeamId(0), Type(0), TeamName(), CaptainGuid(0), BackgroundColor(0), EmblemStyle(0), EmblemColor(0), @@ -510,6 +513,23 @@ void ArenaTeam::BroadcastEvent(ArenaTeamEvents event, uint64 guid, uint8 strCoun sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Sent SMSG_ARENA_TEAM_EVENT"); } +void ArenaTeam::MassInviteToEvent(WorldSession* session) +{ + WorldPacket data(SMSG_CALENDAR_ARENA_TEAM, (Members.size() - 1) * (4 + 8 + 1)); + data << uint32(Members.size() - 1); + + for (MemberList::const_iterator itr = Members.begin(); itr != Members.end(); ++itr) + { + if (itr->Guid != session->GetPlayer()->GetGUID()) + { + data.appendPackGUID(itr->Guid); + data << uint8(0); // unk + } + } + + session->SendPacket(&data); +} + uint8 ArenaTeam::GetSlotByType(uint32 type) { switch (type) diff --git a/src/server/game/Battlegrounds/ArenaTeam.h b/src/server/game/Battlegrounds/ArenaTeam.h index 7d2d680cddc..137ac93d3c0 100755 --- a/src/server/game/Battlegrounds/ArenaTeam.h +++ b/src/server/game/Battlegrounds/ArenaTeam.h @@ -162,6 +162,8 @@ class ArenaTeam void BroadcastEvent(ArenaTeamEvents event, uint64 guid, uint8 strCount, std::string const& str1, std::string const& str2, std::string const& str3); void NotifyStatsChanged(); + void MassInviteToEvent(WorldSession* session); + void Roster(WorldSession* session); void Query(WorldSession* session); void SendStats(WorldSession* session); diff --git a/src/server/game/Battlegrounds/ArenaTeamMgr.cpp b/src/server/game/Battlegrounds/ArenaTeamMgr.cpp index 55de445345b..8a2dcecd209 100644 --- a/src/server/game/Battlegrounds/ArenaTeamMgr.cpp +++ b/src/server/game/Battlegrounds/ArenaTeamMgr.cpp @@ -22,6 +22,7 @@ #include "DatabaseEnv.h" #include "Language.h" #include "ObjectAccessor.h" +#include "Player.h" ArenaTeamMgr::ArenaTeamMgr() { diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index 50f8554d5db..40a74a49b69 100755 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -16,24 +16,24 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Player.h" -#include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "World.h" -#include "WorldPacket.h" #include "ArenaTeam.h" +#include "ArenaTeamMgr.h" #include "Battleground.h" #include "BattlegroundMgr.h" #include "Creature.h" #include "Formulas.h" #include "GridNotifiersImpl.h" #include "Group.h" -#include "Language.h" #include "MapManager.h" #include "Object.h" -#include "SpellAuras.h" +#include "ObjectMgr.h" +#include "Player.h" +#include "ReputationMgr.h" #include "SpellAuraEffects.h" +#include "SpellAuras.h" #include "Util.h" +#include "World.h" +#include "WorldPacket.h" namespace Trinity { @@ -404,6 +404,17 @@ inline void Battleground::_ProcessRessurect(uint32 diff) } } +uint32 Battleground::GetPrematureWinner() +{ + uint32 winner = 0; + if (GetPlayersCountByTeam(ALLIANCE) >= GetMinPlayersPerTeam()) + winner = ALLIANCE; + else if (GetPlayersCountByTeam(HORDE) >= GetMinPlayersPerTeam()) + winner = HORDE; + + return winner; +} + inline void Battleground::_ProcessProgress(uint32 diff) { // ********************************************************* @@ -418,13 +429,7 @@ inline void Battleground::_ProcessProgress(uint32 diff) else if (m_PrematureCountDownTimer < diff) { // time's up! - uint32 winner = 0; - if (GetPlayersCountByTeam(ALLIANCE) >= GetMinPlayersPerTeam()) - winner = ALLIANCE; - else if (GetPlayersCountByTeam(HORDE) >= GetMinPlayersPerTeam()) - winner = HORDE; - - EndBattleground(winner); + EndBattleground(GetPrematureWinner()); m_PrematureCountDown = false; } else if (!sBattlegroundMgr->isTesting()) @@ -642,7 +647,12 @@ void Battleground::SendPacketToTeam(uint32 TeamID, WorldPacket* packet, Player* for (BattlegroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr) if (Player* player = _GetPlayerForTeam(TeamID, itr, "SendPacketToTeam")) if (self || sender != player) - player->GetSession()->SendPacket(packet); + { + WorldSession* session = player->GetSession(); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "%s %s - SendPacketToTeam %u, Player: %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str(), + session->GetPlayerInfo().c_str(), TeamID, sender ? sender->GetName().c_str() : "null"); + session->SendPacket(packet); + } } void Battleground::PlaySoundToAll(uint32 SoundID) @@ -1064,7 +1074,7 @@ void Battleground::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac if (Transport) player->TeleportToBGEntryPoint(); - sLog->outInfo(LOG_FILTER_BATTLEGROUND, "BATTLEGROUND: Removed player %s from Battleground.", player->GetName().c_str()); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Removed player %s from Battleground.", player->GetName().c_str()); } //battleground object will be deleted next Battleground::Update() call @@ -1078,9 +1088,6 @@ void Battleground::Reset() SetStartTime(0); SetEndTime(0); SetLastResurrectTime(0); - SetArenaType(0); - SetRated(false); - m_Events = 0; if (m_InvitedAlliance > 0 || m_InvitedHorde > 0) @@ -1177,10 +1184,9 @@ void Battleground::AddPlayer(Player* player) player->ResetAllPowers(); } - WorldPacket teammate; - teammate.Initialize(SMSG_ARENA_OPPONENT_UPDATE, 8); - teammate << uint64(player->GetGUID()); - SendPacketToTeam(team, &teammate, player, false); + WorldPacket data(SMSG_ARENA_OPPONENT_UPDATE, 8); + data << uint64(player->GetGUID()); + SendPacketToTeam(team, &data, player, false); } else { @@ -1203,9 +1209,6 @@ void Battleground::AddPlayer(Player* player) // setup BG group membership PlayerAddedToBGCheckIfBGIsRunning(player); AddOrSetPlayerToCorrectBgGroup(player, team); - - // Log - sLog->outInfo(LOG_FILTER_BATTLEGROUND, "BATTLEGROUND: Player %s joined the battle.", player->GetName().c_str()); } // this method adds player to his team's bg group, or sets his correct group if player is already in bg group diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h index 6d188d1367a..71dbd097b0a 100755 --- a/src/server/game/Battlegrounds/Battleground.h +++ b/src/server/game/Battlegrounds/Battleground.h @@ -168,23 +168,6 @@ struct BattlegroundObjectInfo uint32 spellid; }; -// handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time -enum BattlegroundQueueTypeId -{ - BATTLEGROUND_QUEUE_NONE = 0, - BATTLEGROUND_QUEUE_AV = 1, - BATTLEGROUND_QUEUE_WS = 2, - BATTLEGROUND_QUEUE_AB = 3, - BATTLEGROUND_QUEUE_EY = 4, - BATTLEGROUND_QUEUE_SA = 5, - BATTLEGROUND_QUEUE_IC = 6, - BATTLEGROUND_QUEUE_RB = 7, - BATTLEGROUND_QUEUE_2v2 = 8, - BATTLEGROUND_QUEUE_3v3 = 9, - BATTLEGROUND_QUEUE_5v5 = 10, - MAX_BATTLEGROUND_QUEUE_TYPES -}; - enum ScoreType { SCORE_KILLING_BLOWS = 1, @@ -253,27 +236,6 @@ enum BattlegroundStartingEventsIds }; #define BG_STARTING_EVENT_COUNT 4 -enum GroupJoinBattlegroundResult -{ - // positive values are indexes in BattlemasterList.dbc - ERR_GROUP_JOIN_BATTLEGROUND_FAIL = 0, // Your group has joined a battleground queue, but you are not eligible (showed for non existing BattlemasterList.dbc indexes) - ERR_BATTLEGROUND_NONE = -1, // not show anything - ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS = -2, // You cannot join the battleground yet because you or one of your party members is flagged as a Deserter. - ERR_ARENA_TEAM_PARTY_SIZE = -3, // Incorrect party size for this arena. - ERR_BATTLEGROUND_TOO_MANY_QUEUES = -4, // You can only be queued for 2 battles at once - ERR_BATTLEGROUND_CANNOT_QUEUE_FOR_RATED = -5, // You cannot queue for a rated match while queued for other battles - ERR_BATTLEDGROUND_QUEUED_FOR_RATED = -6, // You cannot queue for another battle while queued for a rated arena match - ERR_BATTLEGROUND_TEAM_LEFT_QUEUE = -7, // Your team has left the arena queue - ERR_BATTLEGROUND_NOT_IN_BATTLEGROUND = -8, // You can't do that in a battleground. - ERR_BATTLEGROUND_JOIN_XP_GAIN = -9, // wtf, doesn't exist in client... - ERR_BATTLEGROUND_JOIN_RANGE_INDEX = -10, // Cannot join the queue unless all members of your party are in the same battleground level range. - ERR_BATTLEGROUND_JOIN_TIMED_OUT = -11, // %s was unavailable to join the queue. (uint64 guid exist in client cache) - ERR_BATTLEGROUND_JOIN_FAILED = -12, // Join as a group failed (uint64 guid doesn't exist in client cache) - ERR_LFG_CANT_USE_BATTLEGROUND = -13, // You cannot queue for a battleground or arena while using the dungeon system. - ERR_IN_RANDOM_BG = -14, // Can't do that while in a Random Battleground queue. - ERR_IN_NON_RANDOM_BG = -15 // Can't queue for Random Battleground while in another Battleground queue. -}; - struct BattlegroundScore { BattlegroundScore() : KillingBlows(0), Deaths(0), HonorableKills(0), BonusHonor(0), @@ -566,6 +528,8 @@ class Battleground virtual uint64 GetFlagPickerGUID(int32 /*team*/ = -1) const { return 0; } virtual void SetDroppedFlagGUID(uint64 /*guid*/, int32 /*team*/ = -1) {} uint32 GetTeamScore(uint32 TeamID) const; + + virtual uint32 GetPrematureWinner(); protected: // this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends Battleground diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp index bfa3b955427..a0f95e1eaef 100755 --- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp +++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp @@ -44,6 +44,7 @@ #include "SharedDefines.h" #include "Formulas.h" #include "DisableMgr.h" +#include "Opcodes.h" /*********************************************************/ /*** BATTLEGROUND MANAGER ***/ @@ -131,7 +132,7 @@ void BattlegroundMgr::Update(uint32 diff) if (m_NextRatedArenaUpdate < diff) { // forced update for rated arenas (scan all, but skipped non rated) - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "BattlegroundMgr: UPDATING ARENA QUEUES"); + sLog->outTrace(LOG_FILTER_ARENAS, "BattlegroundMgr: UPDATING ARENA QUEUES"); for (int qtype = BATTLEGROUND_QUEUE_2v2; qtype <= BATTLEGROUND_QUEUE_5v5; ++qtype) for (int bracket = BG_BRACKET_ID_FIRST; bracket < MAX_BATTLEGROUND_BRACKETS; ++bracket) m_BattlegroundQueues[qtype].BattlegroundQueueUpdate(diff, @@ -699,8 +700,8 @@ void BattlegroundMgr::CreateInitialBattlegrounds() data.MaxPlayersPerTeam = fields[2].GetUInt16(); data.LevelMin = fields[3].GetUInt8(); data.LevelMax = fields[4].GetUInt8(); - uint8 spawn = fields[9].GetUInt8(); - data.StartMaxDist = float(spawn * spawn); + float dist = fields[9].GetFloat(); + data.StartMaxDist = dist * dist; data.scriptId = sObjectMgr->GetScriptId(fields[11].GetCString()); data.BattlegroundName = bl->name[sWorld->GetDefaultDbcLocale()]; @@ -904,25 +905,25 @@ BattlegroundQueueTypeId BattlegroundMgr::BGQueueTypeId(BattlegroundTypeId bgType { switch (bgTypeId) { - case BATTLEGROUND_WS: - return BATTLEGROUND_QUEUE_WS; case BATTLEGROUND_AB: return BATTLEGROUND_QUEUE_AB; case BATTLEGROUND_AV: return BATTLEGROUND_QUEUE_AV; case BATTLEGROUND_EY: return BATTLEGROUND_QUEUE_EY; - case BATTLEGROUND_SA: - return BATTLEGROUND_QUEUE_SA; case BATTLEGROUND_IC: return BATTLEGROUND_QUEUE_IC; case BATTLEGROUND_RB: return BATTLEGROUND_QUEUE_RB; + case BATTLEGROUND_SA: + return BATTLEGROUND_QUEUE_SA; + case BATTLEGROUND_WS: + return BATTLEGROUND_QUEUE_WS; case BATTLEGROUND_AA: - case BATTLEGROUND_NA: - case BATTLEGROUND_RL: case BATTLEGROUND_BE: case BATTLEGROUND_DS: + case BATTLEGROUND_NA: + case BATTLEGROUND_RL: case BATTLEGROUND_RV: switch (arenaType) { diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp index 922cccb9186..c610cafa1b1 100755 --- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp +++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp @@ -16,14 +16,16 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "BattlegroundQueue.h" #include "ArenaTeam.h" +#include "ArenaTeamMgr.h" #include "BattlegroundMgr.h" +#include "BattlegroundQueue.h" #include "Chat.h" -#include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "Log.h" #include "Group.h" +#include "Log.h" +#include "Language.h" +#include "ObjectMgr.h" +#include "Player.h" /*********************************************************/ /*** BATTLEGROUND QUEUE SYSTEM ***/ @@ -216,7 +218,7 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr // Show queue status to player only (when joining queue) if (sWorld->getBoolConfig(CONFIG_BATTLEGROUND_QUEUE_ANNOUNCER_PLAYERONLY)) { - ChatHandler(leader).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, bgName, q_min_level, q_max_level, + ChatHandler(leader->GetSession()).PSendSysMessage(LANG_BG_QUEUE_ANNOUNCE_SELF, bgName, q_min_level, q_max_level, qAlliance, (MinPlayers > qAlliance) ? MinPlayers - qAlliance : (uint32)0, qHorde, (MinPlayers > qHorde) ? MinPlayers - qHorde : (uint32)0); } // System message @@ -475,7 +477,7 @@ bool BattlegroundQueue::InviteGroupToBG(GroupQueueInfo* ginfo, Battleground* bg, uint32 queueSlot = player->GetBattlegroundQueueIndex(bgQueueTypeId); - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: invited player %s (%u) to BG instance %u queueindex %u bgtype %u, I can't help it if they don't press the enter battle button.", + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: invited player %s (%u) to BG instance %u queueindex %u bgtype %u", player->GetName().c_str(), player->GetGUIDLow(), bg->GetInstanceID(), queueSlot, bg->GetTypeID()); // send status packet diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp index 5a887c647b1..47320db27cf 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAB.cpp @@ -26,6 +26,7 @@ #include "Object.h" #include "Player.h" #include "Util.h" +#include "WorldSession.h" BattlegroundAB::BattlegroundAB() { @@ -548,6 +549,25 @@ void BattlegroundAB::EventPlayerClickedOnFlag(Player* source, GameObject* /*targ PlaySoundToAll(sound); } +uint32 BattlegroundAB::GetPrematureWinner() +{ + // How many bases each team owns + uint8 ally = 0, horde = 0; + for (uint8 i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i) + if (m_Nodes[i] == BG_AB_NODE_STATUS_ALLY_OCCUPIED) + ++ally; + else if (m_Nodes[i] == BG_AB_NODE_STATUS_HORDE_OCCUPIED) + ++horde; + + if (ally > horde) + return ALLIANCE; + else if (horde > ally) + return HORDE; + + // If the values are equal, fall back to the original result (based on number of players on each team) + return Battleground::GetPrematureWinner(); +} + bool BattlegroundAB::SetupBattleground() { for (int i = 0; i < BG_AB_DYNAMIC_NODES_COUNT; ++i) diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAB.h b/src/server/game/Battlegrounds/Zones/BattlegroundAB.h index 63c89717c8f..b80e216a216 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAB.h +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAB.h @@ -272,6 +272,8 @@ class BattlegroundAB : public Battleground /* achievement req. */ bool IsAllNodesConrolledByTeam(uint32 team) const; // overwrited bool IsTeamScores500Disadvantage(uint32 team) const { return m_TeamScores500Disadvantage[GetTeamIndexByTeamId(team)]; } + + uint32 GetPrematureWinner(); private: void PostUpdateImpl(uint32 diff); /* Gameobject spawning/despawning */ diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp index a348ec69b8a..918cef4d261 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAV.cpp @@ -21,11 +21,12 @@ #include "ObjectMgr.h" #include "WorldPacket.h" -#include "Miscellaneous/Formulas.h" +#include "Formulas.h" #include "GameObject.h" -#include "Miscellaneous/Language.h" +#include "Language.h" #include "Player.h" #include "SpellAuras.h" +#include "WorldSession.h" BattlegroundAV::BattlegroundAV() { @@ -1695,3 +1696,16 @@ bool BattlegroundAV::IsAllTowersControlledAndCaptainAlive(uint32 team) const return false; } + +uint32 BattlegroundAV::GetPrematureWinner() +{ + uint32 allianceScore = m_Team_Scores[GetTeamIndexByTeamId(ALLIANCE)]; + uint32 hordeScore = m_Team_Scores[GetTeamIndexByTeamId(HORDE)]; + + if (allianceScore > hordeScore) + return ALLIANCE; + else if (hordeScore > allianceScore) + return HORDE; + + return Battleground::GetPrematureWinner(); +} diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundAV.h b/src/server/game/Battlegrounds/Zones/BattlegroundAV.h index dab67fe3258..bedd946a78c 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundAV.h +++ b/src/server/game/Battlegrounds/Zones/BattlegroundAV.h @@ -1556,7 +1556,7 @@ class BattlegroundAV : public Battleground /*general stuff*/ void UpdateScore(uint16 team, int16 points); - void UpdatePlayerScore(Player* Source, uint32 type, uint32 value, bool doAddHonor = true); + void UpdatePlayerScore(Player* Source, uint32 type, uint32 value, bool doAddHonor = true); /*handlestuff*/ //these are functions which get called from extern void EventPlayerClickedOnFlag(Player* source, GameObject* target_obj); @@ -1572,6 +1572,8 @@ class BattlegroundAV : public Battleground /* achievement req. */ bool IsBothMinesControlledByTeam(uint32 team) const; bool IsAllTowersControlledAndCaptainAlive(uint32 team) const; + + uint32 GetPrematureWinner(); private: void PostUpdateImpl(uint32 diff); diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundDS.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundDS.cpp index a64184261c7..02c5167c9ec 100644 --- a/src/server/game/Battlegrounds/Zones/BattlegroundDS.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundDS.cpp @@ -17,11 +17,12 @@ */ #include "BattlegroundDS.h" -#include "ObjectAccessor.h" +#include "Creature.h" +#include "GameObject.h" #include "Language.h" +#include "ObjectAccessor.h" #include "Player.h" #include "WorldPacket.h" -#include "GameObject.h" BattlegroundDS::BattlegroundDS() { diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp index e900bc9b1d3..458e86729e7 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundEY.cpp @@ -937,3 +937,13 @@ bool BattlegroundEY::IsAllNodesConrolledByTeam(uint32 team) const return count == EY_POINTS_MAX; } + +uint32 BattlegroundEY::GetPrematureWinner() +{ + if (GetTeamScore(TEAM_ALLIANCE) > GetTeamScore(TEAM_HORDE)) + return ALLIANCE; + else if (GetTeamScore(TEAM_HORDE) > GetTeamScore(TEAM_ALLIANCE)) + return HORDE; + + return Battleground::GetPrematureWinner(); +}
\ No newline at end of file diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundEY.h b/src/server/game/Battlegrounds/Zones/BattlegroundEY.h index 61ee5b16c1c..2cfd4ca7e0f 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundEY.h +++ b/src/server/game/Battlegrounds/Zones/BattlegroundEY.h @@ -369,6 +369,8 @@ class BattlegroundEY : public Battleground /* achievement req. */ bool IsAllNodesConrolledByTeam(uint32 team) const; + + uint32 GetPrematureWinner(); private: void PostUpdateImpl(uint32 diff); diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp index 90c0dae9f5e..dbffc318c78 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundIC.cpp @@ -25,6 +25,7 @@ #include "ObjectMgr.h" #include "Vehicle.h" #include "Transport.h" +#include "WorldSession.h" BattlegroundIC::BattlegroundIC() { diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundIC.h b/src/server/game/Battlegrounds/Zones/BattlegroundIC.h index 1386af13186..9e58a93fd2d 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundIC.h +++ b/src/server/game/Battlegrounds/Zones/BattlegroundIC.h @@ -20,6 +20,8 @@ #define __BATTLEGROUNDIC_H #include "Battleground.h" +#include "Language.h" +#include "Object.h" const uint32 BG_IC_Factions[2] = { diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp index 7dba811c1a1..ab479eeff2d 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundSA.cpp @@ -22,6 +22,7 @@ #include "GameObject.h" #include "ObjectMgr.h" #include "WorldPacket.h" +#include "WorldSession.h" BattlegroundSA::BattlegroundSA() { diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp index 5fd6e43c029..965045c5293 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp +++ b/src/server/game/Battlegrounds/Zones/BattlegroundWS.cpp @@ -858,3 +858,12 @@ void BattlegroundWS::FillInitialWorldStates(WorldPacket& data) data << uint32(BG_WS_FLAG_STATE_ALLIANCE) << uint32(1); } +uint32 BattlegroundWS::GetPrematureWinner() +{ + if (GetTeamScore(TEAM_ALLIANCE) > GetTeamScore(TEAM_HORDE)) + return ALLIANCE; + else if (GetTeamScore(TEAM_HORDE) > GetTeamScore(TEAM_ALLIANCE)) + return HORDE; + + return Battleground::GetPrematureWinner(); +}
\ No newline at end of file diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundWS.h b/src/server/game/Battlegrounds/Zones/BattlegroundWS.h index ec9f4ab1506..5b72de43b32 100755 --- a/src/server/game/Battlegrounds/Zones/BattlegroundWS.h +++ b/src/server/game/Battlegrounds/Zones/BattlegroundWS.h @@ -211,6 +211,8 @@ class BattlegroundWS : public Battleground void AddPoint(uint32 TeamID, uint32 Points = 1) { m_TeamScores[GetTeamIndexByTeamId(TeamID)] += Points; } void SetTeamPoint(uint32 TeamID, uint32 Points = 0) { m_TeamScores[GetTeamIndexByTeamId(TeamID)] = Points; } void RemovePoint(uint32 TeamID, uint32 Points = 1) { m_TeamScores[GetTeamIndexByTeamId(TeamID)] -= Points; } + + uint32 GetPrematureWinner(); private: uint64 m_FlagKeepers[2]; // 0 - alliance, 1 - horde uint64 m_DroppedFlagGUID[2]; diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt index 0f8bec7f0e5..15eb61b8477 100644 --- a/src/server/game/CMakeLists.txt +++ b/src/server/game/CMakeLists.txt @@ -8,10 +8,6 @@ # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -if( USE_COREPCH ) - include_directories(${CMAKE_CURRENT_BINARY_DIR}) -endif() - file(GLOB_RECURSE sources_Accounts Accounts/*.cpp Accounts/*.h) file(GLOB_RECURSE sources_Achievements Achievements/*.cpp Achievements/*.h) file(GLOB_RECURSE sources_Addons Addons/*.cpp Addons/*.h) @@ -55,12 +51,10 @@ file(GLOB_RECURSE sources_World World/*.cpp World/*.h) # Create game-libary -if( USE_COREPCH AND MSVC ) - set(game_STAT_SRCS - PrecompiledHeaders/gamePCH.cpp - PrecompiledHeaders/gamePCH.h - ) -endif() +if (USE_COREPCH) + set(game_STAT_PCH_HDR PrecompiledHeaders/gamePCH.h) + set(game_STAT_PCH_SRC PrecompiledHeaders/gamePCH.cpp) +endif () set(game_STAT_SRCS ${game_STAT_SRCS} @@ -207,15 +201,14 @@ include_directories( ${OPENSSL_INCLUDE_DIR} ) -add_library(game STATIC ${game_STAT_SRCS}) +add_library(game STATIC + ${game_STAT_SRCS} + ${game_STAT_PCH_SRC} +) add_dependencies(game revision.h) # Generate precompiled header -if( USE_COREPCH ) - if(CMAKE_COMPILER_IS_GNUCXX) - add_precompiled_header(game ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders/gamePCH.h) - elseif(MSVC) - add_native_precompiled_header(game ${CMAKE_CURRENT_SOURCE_DIR}/PrecompiledHeaders/gamePCH) - endif() -endif() +if (USE_COREPCH) + add_cxx_pch(game ${game_STAT_PCH_HDR} ${game_STAT_PCH_SRC}) +endif () diff --git a/src/server/game/Calendar/Calendar.cpp b/src/server/game/Calendar/Calendar.cpp deleted file mode 100755 index 139e63614cc..00000000000 --- a/src/server/game/Calendar/Calendar.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/> - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#include "Player.h" -#include "Calendar.h" - -std::string CalendarInvite::GetDebugString() const -{ - std::ostringstream data; - - data << "CalendarInvite::" - << " inviteId: " << _inviteId - << " EventId: " << _eventId - << " Status: " << uint32(_status) - << " Invitee: " << _invitee - << " Sender: " << _senderGUID - << " Rank: " << uint32(_rank) - << " Text: " << _text; - - return data.str(); -} - -void CalendarInvite::Init() -{ - _eventId = 0; - _invitee = 0; - _senderGUID = 0; - _statusTime = 0; - _status = CALENDAR_STATUS_INVITED; // default (0)? - _rank = CALENDAR_RANK_PLAYER; - _text = ""; -} - -std::string CalendarEvent::GetDebugString() const -{ - std::ostringstream data; - - data << "CalendarEvent::" - << " EventId: " << _eventId - << " Title: " << _title - << " Description" << _description - << " Type: " << uint32(_type) - << " Max Invites: " << _maxInvites - << " Creator: " << _creatorGUID - << " Flags: " << _flags - << " Guild: " << _guildId - << " Time: " << _eventTime - << " Time2: " << _timezoneTime - << " Repeatable: " << uint32(_repeatable) - << " DungeonId: " << _dungeonId; - - return data.str(); -} - -void CalendarEvent::Init() -{ - _creatorGUID = 0; - _guildId = 0; - _type = CALENDAR_TYPE_OTHER; - _dungeonId = -1; - _maxInvites = 0; - _eventTime = 0; - _flags = 0; - _repeatable = false; - _timezoneTime = 0; - _title = ""; - _description = ""; - -} - -std::string CalendarAction::GetDebugString() const -{ - std::ostringstream data; - - data << "CalendarAction::" - << " Action: " << GetAction() - << " Guid: " << GetPlayer()->GetGUID() - << " Invite Id: " << GetInviteId() - << " Extra data: " << GetExtraData() - << " Event: " << Event.GetDebugString() - << " Invite: " << Invite.GetDebugString(); - - return data.str(); -} diff --git a/src/server/game/Calendar/Calendar.h b/src/server/game/Calendar/Calendar.h deleted file mode 100755 index 273db4c3854..00000000000 --- a/src/server/game/Calendar/Calendar.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/> - * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; either version 2 of the License, or (at your - * option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef TRINITY_CALENDAR_H -#define TRINITY_CALENDAR_H - -#include "Errors.h" -#include "SharedDefines.h" -#include <map> - -class CalendarInvite -{ - public: - CalendarInvite() : _inviteId(0) { Init(); } - explicit CalendarInvite(uint64 inviteId) : _inviteId(inviteId) { Init(); } - - ~CalendarInvite() { } - - void SetInviteId(uint64 inviteId) { _inviteId = inviteId; } - uint64 GetInviteId() const { return _inviteId; } - - void SetEventId(uint64 eventId) { _eventId = eventId; } - uint64 GetEventId() const { return _eventId; } - - void SetSenderGUID(uint64 guid) { _senderGUID = guid; } - uint64 GetSenderGUID() const { return _senderGUID; } - - void SetInvitee(uint64 guid) { _invitee = guid; } - uint64 GetInvitee() const { return _invitee; } - - void SetStatusTime(uint32 statusTime) { _statusTime = statusTime; } - uint32 GetStatusTime() const { return _statusTime; } - - void SetText(std::string const& text) { _text = text; } - std::string const& GetText() const { return _text; } - - void SetStatus(CalendarInviteStatus status) { _status = status; } - CalendarInviteStatus GetStatus() const { return _status; } - - void SetRank(CalendarModerationRank rank) { _rank = rank; } - CalendarModerationRank GetRank() const { return _rank; } - - std::string GetDebugString() const; - - private: - void Init(); - - uint64 _inviteId; - uint64 _eventId; - uint64 _invitee; - uint64 _senderGUID; - uint32 _statusTime; - CalendarInviteStatus _status; - CalendarModerationRank _rank; - std::string _text; -}; - -typedef std::set<uint64> CalendarInviteIdList; - -class CalendarEvent -{ - public: - CalendarEvent() : _eventId(0) { Init(); } - explicit CalendarEvent(uint64 eventId) : _eventId(eventId) { Init(); } - - ~CalendarEvent() { } - - void SetEventId(uint64 eventId) { _eventId = eventId; } - uint64 GetEventId() const { return _eventId; } - - void SetCreatorGUID(uint64 guid) { _creatorGUID = guid; } - uint64 GetCreatorGUID() const { return _creatorGUID; } - - void SetGuildId(uint32 guildId) { _guildId = guildId; } - uint32 GetGuildId() const { return _guildId; } - - void SetTitle(std::string const& title) { _title = title; } - std::string const& GetTitle() const { return _title; } - - void SetDescription(std::string const& description) { _description = description; } - std::string const& GetDescription() const { return _description; } - - void SetType(CalendarEventType type) { _type = type; } - CalendarEventType GetType() const { return _type; } - - void SetMaxInvites(uint32 limit) { _maxInvites = limit; } - uint32 GetMaxInvites() const { return _maxInvites; } - - void SetDungeonId(int32 dungeonId) { _dungeonId = dungeonId; } - int32 GetDungeonId() const { return _dungeonId; } - - void SetTime(uint32 eventTime) { _eventTime = eventTime; } - uint32 GetTime() const { return _eventTime; } - - void SetFlags(uint32 flags) { _flags = flags; } - uint32 GetFlags() const { return _flags; } - - void SetRepeatable(bool repeatable) { _repeatable = repeatable; } - bool GetRepeatable() const { return _repeatable; } - - void SetTimeZoneTime(uint32 timezoneTime) { _timezoneTime = timezoneTime; } - uint32 GetTimeZoneTime() const { return _timezoneTime; } - - void AddInvite(uint64 inviteId) - { - if (inviteId) - _invites.insert(inviteId); - } - - void RemoveInvite(uint64 inviteId) { _invites.erase(inviteId); } - bool HasInvite(uint64 inviteId) const { return _invites.find(inviteId) != _invites.end(); } - CalendarInviteIdList const& GetInviteIdList() const { return _invites; } - void SetInviteIdList(CalendarInviteIdList const& list) { _invites = list; } - void ClearInviteIdList() { _invites.clear(); } - - std::string GetDebugString() const; - - private: - void Init(); - - uint64 _eventId; - uint64 _creatorGUID; - uint32 _guildId; - CalendarEventType _type; - int32 _dungeonId; - uint32 _maxInvites; - uint32 _eventTime; - uint32 _flags; - bool _repeatable; - uint32 _timezoneTime; - std::string _title; - std::string _description; - CalendarInviteIdList _invites; -}; - -typedef std::set<uint64> CalendarEventIdList; -typedef std::map<uint64, CalendarInviteIdList> CalendarPlayerInviteIdMap; -typedef std::map<uint64, CalendarEventIdList> CalendarPlayerEventIdMap; -typedef std::map<uint64, CalendarInvite> CalendarInviteMap; -typedef std::map<uint64, CalendarEvent> CalendarEventMap; - -class Player; - -struct CalendarAction -{ - CalendarAction(): _action(CALENDAR_ACTION_NONE), _player(NULL), _inviteId(0), _data(0) - { - } - - void SetAction(CalendarActionData data) { _action = data; } - CalendarActionData GetAction() const { return _action; } - - void SetPlayer(Player* player) { ASSERT(player); _player = player; } - Player* GetPlayer() const { return _player; } - - void SetInviteId(uint64 id) { _inviteId = id; } - uint64 GetInviteId() const { return _inviteId; } - - void SetExtraData(uint32 data) { _data = data; } - uint32 GetExtraData() const { return _data; } - - CalendarEvent Event; - CalendarInvite Invite; - - std::string GetDebugString() const; - - private: - CalendarActionData _action; - Player* _player; - uint64 _inviteId; - uint32 _data; -}; - -#endif diff --git a/src/server/game/Calendar/CalendarMgr.cpp b/src/server/game/Calendar/CalendarMgr.cpp index 80de42c0ce2..9f4816d6c7c 100644 --- a/src/server/game/Calendar/CalendarMgr.cpp +++ b/src/server/game/Calendar/CalendarMgr.cpp @@ -15,579 +15,621 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* - -DROP TABLE IF EXISTS `calendar_events`; -CREATE TABLE IF NOT EXISTS `calendar_events` ( - `id` int(11) unsigned NOT NULL DEFAULT '0', - `creator` int(11) unsigned NOT NULL DEFAULT '0', - `title` varchar(255) NOT NULL DEFAULT '', - `description` varchar(255) NOT NULL DEFAULT '', - `type` tinyint(1) unsigned NOT NULL DEFAULT '4', - `dungeon` tinyint(3) NOT NULL DEFAULT '-1', - `eventtime` int(10) unsigned NOT NULL DEFAULT '0', - `flags` int(10) unsigned NOT NULL DEFAULT '0', - `repeatable` tinyint(1) unsigned NOT NULL DEFAULT '0', - `time2` int(10) unsigned NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -); - -DROP TABLE IF EXISTS `calendar_invites`; -CREATE TABLE IF NOT EXISTS `calendar_invites` ( - `id` int(11) unsigned NOT NULL DEFAULT '0', - `event` int(11) unsigned NOT NULL DEFAULT '0', - `invitee` int(11) unsigned NOT NULL DEFAULT '0', - `sender` int(11) unsigned NOT NULL DEFAULT '0', - `status` tinyint(1) unsigned NOT NULL DEFAULT '0', - `statustime` int(10) unsigned NOT NULL DEFAULT '0', - `rank` tinyint(1) unsigned NOT NULL DEFAULT '0', - `text` varchar(255) NOT NULL DEFAULT '', - PRIMARY KEY (`id`) -); -*/ - #include "CalendarMgr.h" #include "QueryResult.h" #include "DatabaseEnv.h" #include "Log.h" #include "Player.h" +#include "GuildMgr.h" #include "ObjectAccessor.h" +#include "Opcodes.h" -CalendarMgr::CalendarMgr() : - _eventNum(0), _inviteNum(0) +CalendarInvite::~CalendarInvite() { + sCalendarMgr->FreeInviteId(_inviteId); } -CalendarMgr::~CalendarMgr() +CalendarEvent::~CalendarEvent() { + sCalendarMgr->FreeEventId(_eventId); } -uint32 CalendarMgr::GetPlayerNumPending(uint64 guid) +CalendarMgr::CalendarMgr() { - if (!guid) - return 0; - - CalendarPlayerInviteIdMap::const_iterator itr = _playerInvites.find(guid); - if (itr == _playerInvites.end()) - return 0; - - uint32 pendingNum = 0; - for (CalendarInviteIdList::const_iterator it = itr->second.begin(); it != itr->second.end(); ++it) - if (CalendarInvite* invite = GetInvite(*it)) - if (invite->GetRank() != CALENDAR_RANK_OWNER - && invite->GetStatus() != CALENDAR_STATUS_CONFIRMED - && invite->GetStatus() != CALENDAR_STATUS_8 - && invite->GetStatus() != CALENDAR_STATUS_9) // FIXME Check the proper value - ++pendingNum; - - return pendingNum; } -CalendarInviteIdList const& CalendarMgr::GetPlayerInvites(uint64 guid) +CalendarMgr::~CalendarMgr() { - return _playerInvites[guid]; } -CalendarEventIdList const& CalendarMgr::GetPlayerEvents(uint64 guid) +void CalendarMgr::LoadFromDB() { - return _playerEvents[guid]; -} + uint32 count = 0; + _maxEventId = 0; + _maxInviteId = 0; -CalendarInvite* CalendarMgr::GetInvite(uint64 inviteId) -{ - CalendarInviteMap::iterator itr = _invites.find(inviteId); - if (itr != _invites.end()) - return &(itr->second); + // 0 1 2 3 4 5 6 7 8 + if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags, time2 FROM calendar_events")) + do + { + Field* fields = result->Fetch(); - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::GetInvite: [" UI64FMTD "] not found!", inviteId); - return NULL; -} + uint64 eventId = fields[0].GetUInt64(); + uint64 creatorGUID = MAKE_NEW_GUID(fields[1].GetUInt32(), 0, HIGHGUID_PLAYER); + std::string title = fields[2].GetString(); + std::string description = fields[3].GetString(); + CalendarEventType type = CalendarEventType(fields[4].GetUInt8()); + int32 dungeonId = fields[5].GetInt32(); + uint32 eventTime = fields[6].GetUInt32(); + uint32 flags = fields[7].GetUInt32(); + uint32 timezoneTime = fields[8].GetUInt32(); + uint32 guildId = 0; -CalendarEvent* CalendarMgr::GetEvent(uint64 eventId) -{ - CalendarEventMap::iterator itr = _events.find(eventId); - if (itr != _events.end()) - return &(itr->second); + if (flags & CALENDAR_FLAG_GUILD_EVENT || flags & CALENDAR_FLAG_WITHOUT_INVITES) + guildId = Player::GetGuildIdFromDB(creatorGUID); - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::GetEvent: [" UI64FMTD "] not found!", eventId); - return NULL; -} + CalendarEvent* calendarEvent = new CalendarEvent(eventId, creatorGUID , guildId, type, dungeonId, time_t(eventTime), flags, time_t(timezoneTime), title, description); + _events.insert(calendarEvent); -uint64 CalendarMgr::GetFreeEventId() -{ - return ++_eventNum; -} -uint64 CalendarMgr::GetFreeInviteId() -{ - return ++_inviteNum; -} + _maxEventId = std::max(_maxEventId, eventId); -void CalendarMgr::LoadFromDB() -{ - /* - uint32 count = 0; - // 0 1 2 3 4 5 6 7 8 9 - if (QueryResult result = CharacterDatabase.Query("SELECT id, creator, title, description, type, dungeon, eventtime, flags, repeatable, time2 FROM calendar_events")) - do - { - Field * fields = result->Fetch(); - - uint64 eventId = fields[0].GetUInt64(); - CalendarEvent& calendarEvent = _events[eventId]; - - calendarEvent.SetEventId(eventId); - calendarEvent.SetCreatorGUID(fields[1].GetUInt64()); - calendarEvent.SetTitle(fields[2].GetString()); - calendarEvent.SetDescription(fields[3].GetString()); - calendarEvent.SetType(fields[4].GetUInt8()); - calendarEvent.SetDungeonId(fields[5].GetInt32()); - calendarEvent.SetTime(fields[6].GetUInt32()); - calendarEvent.SetFlags(fields[7].GetUInt32()); - calendarEvent.SetRepeatable(fields[8].GetBool()); - calendarEvent.SetTimeZoneTime(fields[9].GetUInt32()); ++count; } while (result->NextRow()); - sLog->outInfo(LOG_FILTER_CALENDAR, ">> Loaded %u calendar events", count); + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u calendar events", count); count = 0; // 0 1 2 3 4 5 6 7 if (QueryResult result = CharacterDatabase.Query("SELECT id, event, invitee, sender, status, statustime, rank, text FROM calendar_invites")) do { - Field * fields = result->Fetch(); + Field* fields = result->Fetch(); - uint64 inviteId = fields[0].GetUInt64(); - uint64 eventId = fields[1].GetUInt64(); + uint64 inviteId = fields[0].GetUInt64(); + uint64 eventId = fields[1].GetUInt64(); + uint64 invitee = MAKE_NEW_GUID(fields[2].GetUInt32(), 0, HIGHGUID_PLAYER); + uint64 senderGUID = MAKE_NEW_GUID(fields[3].GetUInt32(), 0, HIGHGUID_PLAYER); + CalendarInviteStatus status = CalendarInviteStatus(fields[4].GetUInt8()); + uint32 statusTime = fields[5].GetUInt32(); + CalendarModerationRank rank = CalendarModerationRank(fields[6].GetUInt8()); + std::string text = fields[7].GetString(); - CalendarInvite& invite = _invites[inviteId]; + CalendarInvite* invite = new CalendarInvite(inviteId, eventId, invitee, senderGUID, time_t(statusTime), status, rank, text); + _invites[eventId].push_back(invite); - invite.SetEventId(eventId); - invite.SetInvitee(fields[2].GetUInt64()); - invite.SetSenderGUID(fields[3].GetUInt64()); - invite.SetStatus(fields[4].GetUInt8()); - invite.SetStatusTime(fields[5].GetUInt32()); - invite.SetRank(fields[6].GetUInt8()); - invite.SetText(fields[7].GetString()); + _maxInviteId = std::max(_maxInviteId, inviteId); - CalendarEvent& calendarEvent = _events[eventId]; - calendarEvent.AddInvite(inviteId); + ++count; } while (result->NextRow()); - sLog->outInfo(LOG_FILTER_CALENDAR, ">> Loaded %u calendar Invites", count); - */ + sLog->outInfo(LOG_FILTER_SERVER_LOADING, ">> Loaded %u calendar invites", count); + + for (uint64 i = 1; i < _maxEventId; ++i) + if (!GetEvent(i)) + _freeEventIds.push_back(i); + + for (uint64 i = 1; i < _maxInviteId; ++i) + if (!GetInvite(i)) + _freeInviteIds.push_back(i); } -CalendarEvent* CalendarMgr::CheckPermisions(uint64 eventId, Player* player, uint64 inviteId, CalendarModerationRank minRank) +void CalendarMgr::AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType) { - if (!player) - return NULL; // CALENDAR_ERROR_INTERNAL + _events.insert(calendarEvent); + UpdateEvent(calendarEvent); + SendCalendarEvent(calendarEvent->GetCreatorGUID(), *calendarEvent, sendType); +} - CalendarEvent* calendarEvent = GetEvent(eventId); - if (!calendarEvent) - { - player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_EVENT_INVALID); - return NULL; - } +void CalendarMgr::AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite) +{ + if (!calendarEvent->IsGuildAnnouncement()) + SendCalendarEventInvite(*invite); - CalendarInvite* invite = GetInvite(inviteId); - if (!invite) - { - player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NO_INVITE); - return NULL; - } + if (!calendarEvent->IsGuildEvent() || invite->GetInviteeGUID() == calendarEvent->GetCreatorGUID()) + SendCalendarEventInviteAlert(*calendarEvent, *invite); - if (!calendarEvent->HasInvite(inviteId)) + if (!calendarEvent->IsGuildAnnouncement()) { - player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_NOT_INVITED); - return NULL; + _invites[invite->GetEventId()].push_back(invite); + UpdateInvite(invite); } +} + +void CalendarMgr::RemoveEvent(uint64 eventId, uint64 remover) +{ + CalendarEvent* calendarEvent = GetEvent(eventId); - if (invite->GetEventId() != calendarEvent->GetEventId() || invite->GetInvitee() != player->GetGUID()) + if (!calendarEvent) { - player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_INTERNAL); - return NULL; + SendCalendarCommandResult(remover, CALENDAR_ERROR_EVENT_INVALID); + return; } - if (invite->GetRank() < minRank) + SendCalendarEventRemovedAlert(*calendarEvent); + + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + PreparedStatement* stmt; + MailDraft mail(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody()); + + std::vector<CalendarInvite*>::iterator itr = _invites[eventId].begin(); + while (itr != _invites[eventId].end()) { - player->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_PERMISSIONS); - return NULL; + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_INVITE); + stmt->setUInt64(0, (*itr)->GetInviteId()); + trans->Append(stmt); + + // guild events only? check invite status here? + // When an event is deleted, all invited (accepted/declined? - verify) guildies are notified via in-game mail. (wowwiki) + if (remover && (*itr)->GetInviteeGUID() != remover) + mail.SendMailTo(trans, MailReceiver((*itr)->GetInviteeGUID()), calendarEvent, MAIL_CHECK_MASK_COPIED); + + delete *itr; + _invites[eventId].erase(itr); } - return calendarEvent; + _invites.erase(eventId); + + stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_EVENT); + stmt->setUInt64(0, eventId); + trans->Append(stmt); + CharacterDatabase.CommitTransaction(trans); + + delete calendarEvent; + _events.erase(calendarEvent); } -void CalendarMgr::AddAction(CalendarAction const& action) +void CalendarMgr::RemoveInvite(uint64 inviteId, uint64 eventId, uint64 /*remover*/) { - switch (action.GetAction()) - { - case CALENDAR_ACTION_ADD_EVENT: - { - if (AddEvent(action.Event) && AddInvite(action.Invite)) - { - SendCalendarEventInviteAlert(action.Event, action.Invite); - SendCalendarEvent(action.Event, CALENDAR_SENDTYPE_ADD); - } - break; - } - case CALENDAR_ACTION_MODIFY_EVENT: - { - uint64 eventId = action.Event.GetEventId(); - CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); - if (!calendarEvent) - return; - - calendarEvent->SetEventId(action.Event.GetEventId()); - calendarEvent->SetType(action.Event.GetType()); - calendarEvent->SetFlags(action.Event.GetFlags()); - calendarEvent->SetTime(action.Event.GetTime()); - calendarEvent->SetTimeZoneTime(action.Event.GetTimeZoneTime()); - calendarEvent->SetRepeatable(action.Event.GetRepeatable()); - calendarEvent->SetDungeonId(action.Event.GetDungeonId()); - calendarEvent->SetTitle(action.Event.GetTitle()); - calendarEvent->SetDescription(action.Event.GetDescription()); - calendarEvent->SetMaxInvites(action.Event.GetMaxInvites()); - - CalendarInviteIdList const& invites = calendarEvent->GetInviteIdList(); - for (CalendarInviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) - if (CalendarInvite* invite = GetInvite(*itr)) - SendCalendarEventUpdateAlert(invite->GetInvitee(), *calendarEvent, CALENDAR_SENDTYPE_ADD); + CalendarEvent* calendarEvent = GetEvent(eventId); - break; - } - case CALENDAR_ACTION_COPY_EVENT: - { - CalendarEvent* calendarEvent = CheckPermisions(action.Event.GetEventId(), action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER); - - if (!calendarEvent) - return; - - uint64 eventId = GetFreeEventId(); - CalendarEvent newEvent(eventId); - newEvent.SetType(calendarEvent->GetType()); - newEvent.SetFlags(calendarEvent->GetFlags()); - newEvent.SetTime(action.Event.GetTime()); - newEvent.SetTimeZoneTime(calendarEvent->GetTimeZoneTime()); - newEvent.SetRepeatable(calendarEvent->GetRepeatable()); - newEvent.SetDungeonId(calendarEvent->GetDungeonId()); - newEvent.SetTitle(calendarEvent->GetTitle()); - newEvent.SetDescription(calendarEvent->GetDescription()); - newEvent.SetMaxInvites(calendarEvent->GetMaxInvites()); - newEvent.SetCreatorGUID(calendarEvent->GetCreatorGUID()); - newEvent.SetGuildId(calendarEvent->GetGuildId()); - - CalendarInviteIdList const invites = calendarEvent->GetInviteIdList(); - for (CalendarInviteIdList::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) - { - if (CalendarInvite* invite = GetInvite(*itr)) - { - uint64 inviteId = GetFreeInviteId(); - CalendarInvite newInvite(inviteId); - newInvite.SetEventId(eventId); - newInvite.SetSenderGUID(action.GetPlayer()->GetGUID()); - newInvite.SetInvitee(invite->GetInvitee()); - newInvite.SetStatus(invite->GetStatus()); - newInvite.SetStatusTime(invite->GetStatusTime()); - newInvite.SetText(invite->GetText()); - newInvite.SetRank(invite->GetRank()); - if (AddInvite(newInvite)) - { - SendCalendarEventInviteAlert(newEvent, newInvite); - newEvent.AddInvite(inviteId); - } - } - } - - if (AddEvent(newEvent)) - SendCalendarEvent(newEvent, CALENDAR_SENDTYPE_COPY); + if (!calendarEvent) + return; + std::vector<CalendarInvite*>::iterator itr = _invites[eventId].begin(); + for (; itr != _invites[eventId].end(); ++itr) + if ((*itr)->GetInviteId() == inviteId) break; - } - case CALENDAR_ACTION_REMOVE_EVENT: - { - uint64 eventId = action.Event.GetEventId(); - //uint32 flags = action.Event.GetFlags(); - // FIXME - Use of Flags here! - CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER); - if (!calendarEvent) - return; + if (itr == _invites[eventId].end()) + return; - RemoveEvent(eventId); - break; - } - case CALENDAR_ACTION_ADD_EVENT_INVITE: - { - uint64 eventId = action.Invite.GetEventId(); - CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); - if (!calendarEvent) - return; - - if (AddInvite(action.Invite)) - { - calendarEvent->AddInvite(action.Invite.GetInviteId()); - SendCalendarEventInvite(action.Invite, (!(calendarEvent->GetFlags() & CALENDAR_FLAG_INVITES_LOCKED) && - !action.Invite.GetStatusTime())); - SendCalendarEventInviteAlert(*calendarEvent, action.Invite); - } + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_CALENDAR_INVITE); + stmt->setUInt64(0, (*itr)->GetInviteId()); + trans->Append(stmt); + CharacterDatabase.CommitTransaction(trans); - break; - } - case CALENDAR_ACTION_SIGNUP_TO_EVENT: - { - uint64 eventId = action.Event.GetEventId(); - CalendarEvent* calendarEvent = GetEvent(eventId); - CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); + if (!calendarEvent->IsGuildEvent()) + SendCalendarEventInviteRemoveAlert((*itr)->GetInviteeGUID(), *calendarEvent, CALENDAR_STATUS_REMOVED); - if (!calendarEvent || !(calendarEvent->GetFlags() & CALENDAR_FLAG_GUILD_ONLY) - || !calendarEvent->GetGuildId() || calendarEvent->GetGuildId() != action.GetExtraData()) - return; + SendCalendarEventInviteRemove(*calendarEvent, **itr, calendarEvent->GetFlags()); - CalendarInviteStatus status = action.Invite.GetStatus(); + // we need to find out how to use CALENDAR_INVITE_REMOVED_MAIL_SUBJECT to force client to display different mail + //if ((*itr)->GetInviteeGUID() != remover) + // MailDraft(calendarEvent->BuildCalendarMailSubject(remover), calendarEvent->BuildCalendarMailBody()) + // .SendMailTo(trans, MailReceiver((*itr)->GetInvitee()), calendarEvent, MAIL_CHECK_MASK_COPIED); - if (status == CALENDAR_STATUS_INVITED) - status = CALENDAR_STATUS_CONFIRMED; - else if (status == CALENDAR_STATUS_ACCEPTED) - status = CALENDAR_STATUS_8; + delete *itr; + _invites[eventId].erase(itr); +} - CalendarInvite newInvite(GetFreeInviteId()); - newInvite.SetStatus(status); - newInvite.SetStatusTime(uint32(time(NULL))); - newInvite.SetEventId(eventId); - newInvite.SetInvitee(action.GetPlayer()->GetGUID()); - newInvite.SetSenderGUID(action.GetPlayer()->GetGUID()); +void CalendarMgr::UpdateEvent(CalendarEvent* calendarEvent) +{ + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_EVENT); + stmt->setUInt64(0, calendarEvent->GetEventId()); + stmt->setUInt32(1, GUID_LOPART(calendarEvent->GetCreatorGUID())); + stmt->setString(2, calendarEvent->GetTitle()); + stmt->setString(3, calendarEvent->GetDescription()); + stmt->setUInt8(4, calendarEvent->GetType()); + stmt->setInt32(5, calendarEvent->GetDungeonId()); + stmt->setUInt32(6, uint32(calendarEvent->GetEventTime())); + stmt->setUInt32(7, calendarEvent->GetFlags()); + stmt->setUInt32(8, calendarEvent->GetTimeZoneTime()); // correct? + trans->Append(stmt); + CharacterDatabase.CommitTransaction(trans); +} - if (AddInvite(newInvite)) - SendCalendarEventInvite(newInvite, false); +void CalendarMgr::UpdateInvite(CalendarInvite* invite) +{ + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_CALENDAR_INVITE); + stmt->setUInt64(0, invite->GetInviteId()); + stmt->setUInt64(1, invite->GetEventId()); + stmt->setUInt32(2, GUID_LOPART(invite->GetInviteeGUID())); + stmt->setUInt32(3, GUID_LOPART(invite->GetSenderGUID())); + stmt->setUInt8(4, invite->GetStatus()); + stmt->setUInt32(5, uint32(invite->GetStatusTime())); + stmt->setUInt8(6, invite->GetRank()); + stmt->setString(7, invite->GetText()); + trans->Append(stmt); + CharacterDatabase.CommitTransaction(trans); +} - break; - } - case CALENDAR_ACTION_MODIFY_EVENT_INVITE: - { - uint64 eventId = action.Invite.GetEventId(); - uint64 inviteId = action.Invite.GetInviteId(); +void CalendarMgr::RemoveAllPlayerEventsAndInvites(uint64 guid) +{ + for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr) + if ((*itr)->GetCreatorGUID() == guid) + RemoveEvent((*itr)->GetEventId(), 0); // don't send mail if removing a character - CalendarEvent* calendarEvent = NULL; - if (action.GetInviteId() != action.Invite.GetInviteId()) - calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); - else - calendarEvent = GetEvent(eventId); + std::vector<CalendarInvite*> playerInvites = GetPlayerInvites(guid); + for (std::vector<CalendarInvite*>::const_iterator itr = playerInvites.begin(); itr != playerInvites.end(); ++itr) + RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid); +} - CalendarInvite* invite = GetInvite(inviteId); +void CalendarMgr::RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId) +{ + for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr) + if ((*itr)->GetCreatorGUID() == guid && ((*itr)->IsGuildEvent() || (*itr)->IsGuildAnnouncement())) + RemoveEvent((*itr)->GetEventId(), guid); + + std::vector<CalendarInvite*> playerInvites = GetPlayerInvites(guid); + for (std::vector<CalendarInvite*>::const_iterator itr = playerInvites.begin(); itr != playerInvites.end(); ++itr) + if (CalendarEvent* calendarEvent = GetEvent((*itr)->GetEventId())) + if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == guildId) + RemoveInvite((*itr)->GetInviteId(), (*itr)->GetEventId(), guid); +} - if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId)) - return; +CalendarEvent* CalendarMgr::GetEvent(uint64 eventId) +{ + for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr) + if ((*itr)->GetEventId() == eventId) + return *itr; - invite->SetStatus(action.Invite.GetStatus()); - SendCalendarEventStatus(invite->GetSenderGUID(), *calendarEvent, *invite); - break; - } - case CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE: - { - uint64 eventId = action.Invite.GetEventId(); - uint64 inviteId = action.Invite.GetInviteId(); + sLog->outDebug(LOG_FILTER_CALENDAR, "CalendarMgr::GetEvent: [" UI64FMTD "] not found!", eventId); + return NULL; +} - CalendarEvent* calendarEvent = NULL; - if (action.GetInviteId() != action.Invite.GetInviteId()) - calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_OWNER); - else - calendarEvent = GetEvent(eventId); +CalendarInvite* CalendarMgr::GetInvite(uint64 inviteId) +{ + for (CalendarInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr) + for (std::vector<CalendarInvite*>::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2) + if ((*itr2)->GetInviteId() == inviteId) + return *itr2; - CalendarInvite* invite = GetInvite(inviteId); + sLog->outDebug(LOG_FILTER_CALENDAR, "CalendarMgr::GetInvite: [" UI64FMTD "] not found!", inviteId); + return NULL; +} - if (!calendarEvent || !invite || !calendarEvent->HasInvite(inviteId)) - return; +void CalendarMgr::FreeEventId(uint64 id) +{ + if (id == _maxEventId) + --_maxEventId; + else + _freeEventIds.push_back(id); +} - invite->SetStatus(action.Invite.GetStatus()); - SendCalendarEventModeratorStatusAlert(*invite); - break; - } - case CALENDAR_ACTION_REMOVE_EVENT_INVITE: - { - uint64 eventId = action.Invite.GetEventId(); - uint64 inviteId = action.Invite.GetInviteId(); - CalendarEvent* calendarEvent = CheckPermisions(eventId, action.GetPlayer(), action.GetInviteId(), CALENDAR_RANK_MODERATOR); - if (!calendarEvent) - return; - - // already checked in CheckPermisions - CalendarInvite* invite = GetInvite(inviteId); - if (!invite) - return; - - if (calendarEvent->GetCreatorGUID() == invite->GetInvitee()) - { - action.GetPlayer()->GetSession()->SendCalendarCommandResult(CALENDAR_ERROR_DELETE_CREATOR_FAILED); - return; - } - - if (uint64 invitee = RemoveInvite(inviteId)) - { - SendCalendarEventInviteRemoveAlert(invitee, *calendarEvent, CALENDAR_STATUS_9); - SendCalendarEventInviteRemove(action.GetPlayer()->GetGUID(), action.Invite, calendarEvent->GetFlags()); - } - break; - } - default: - break; +uint64 CalendarMgr::GetFreeEventId() +{ + if (_freeEventIds.empty()) + return ++_maxEventId; + else + { + uint64 eventId = _freeEventIds.front(); + _freeEventIds.pop_front(); + return eventId; } +} +void CalendarMgr::FreeInviteId(uint64 id) +{ + if (id == _maxInviteId) + --_maxInviteId; + else + _freeInviteIds.push_back(id); } -bool CalendarMgr::AddEvent(CalendarEvent const& newEvent) +uint64 CalendarMgr::GetFreeInviteId() { - uint64 eventId = newEvent.GetEventId(); - if (_events.find(eventId) != _events.end()) + if (_freeInviteIds.empty()) + return ++_maxInviteId; + else { - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::AddEvent: Event [" UI64FMTD "] exists", eventId); - return false; + uint64 inviteId = _freeInviteIds.front(); + _freeInviteIds.pop_front(); + return inviteId; } +} + +CalendarEventStore CalendarMgr::GetPlayerEvents(uint64 guid) +{ + CalendarEventStore events; + + for (CalendarInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr) + for (std::vector<CalendarInvite*>::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2) + if ((*itr2)->GetInviteeGUID() == guid) + events.insert(GetEvent(itr->first)); - _events[eventId] = newEvent; - return true; + if (Player* player = ObjectAccessor::FindPlayer(guid)) + for (CalendarEventStore::const_iterator itr = _events.begin(); itr != _events.end(); ++itr) + if ((*itr)->GetGuildId() == player->GetGuildId()) + events.insert(*itr); + + return events; } -bool CalendarMgr::RemoveEvent(uint64 eventId) +std::vector<CalendarInvite*> CalendarMgr::GetEventInvites(uint64 eventId) { - CalendarEventMap::iterator itr = _events.find(eventId); - if (itr == _events.end()) - { - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::RemoveEvent: Event [" UI64FMTD "] does not exist", eventId); - return false; - } + return _invites[eventId]; +} - bool val = true; +std::vector<CalendarInvite*> CalendarMgr::GetPlayerInvites(uint64 guid) +{ + std::vector<CalendarInvite*> invites; - CalendarInviteIdList const& invites = itr->second.GetInviteIdList(); - for (CalendarInviteIdList::const_iterator itrInvites = invites.begin(); itrInvites != invites.end(); ++itrInvites) - { - CalendarInvite* invite = GetInvite(*itrInvites); - if (!invite || !RemovePlayerEvent(invite->GetInvitee(), eventId)) - val = false; + for (CalendarInviteStore::const_iterator itr = _invites.begin(); itr != _invites.end(); ++itr) + for (std::vector<CalendarInvite*>::const_iterator itr2 = itr->second.begin(); itr2 != itr->second.end(); ++itr2) + if ((*itr2)->GetInviteeGUID() == guid) + invites.push_back(*itr2); - if (uint64 invitee = RemoveInvite(*itrInvites)) - SendCalendarEventRemovedAlert(invitee, itr->second); - } + return invites; +} + +uint32 CalendarMgr::GetPlayerNumPending(uint64 guid) +{ + std::vector<CalendarInvite*> const& invites = GetPlayerInvites(guid); - _events.erase(itr); + uint32 pendingNum = 0; + for (std::vector<CalendarInvite*>::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) + // correct? + if ((*itr)->GetStatus() == CALENDAR_STATUS_INVITED || (*itr)->GetStatus() == CALENDAR_STATUS_TENTATIVE || (*itr)->GetStatus() == CALENDAR_STATUS_NOT_SIGNED_UP) + ++pendingNum; - return val; + return pendingNum; } -bool CalendarMgr::AddPlayerEvent(uint64 guid, uint64 eventId) +std::string CalendarEvent::BuildCalendarMailSubject(uint64 remover) const { - _playerEvents[guid].insert(eventId); - return true; + std::ostringstream strm; + strm << remover << ':' << _title; + return strm.str(); } -bool CalendarMgr::RemovePlayerEvent(uint64 guid, uint64 eventId) +std::string CalendarEvent::BuildCalendarMailBody() const { - _playerEvents[guid].erase(eventId); - return true; + WorldPacket data; + uint32 time; + std::ostringstream strm; + + // we are supposed to send PackedTime so i used WorldPacket to pack it + data.AppendPackedTime(_eventTime); + data >> time; + strm << time; + return strm.str(); } -bool CalendarMgr::AddInvite(CalendarInvite const& newInvite) +void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite) { - uint64 inviteId = newInvite.GetInviteId(); - if (!inviteId) + CalendarEvent* calendarEvent = GetEvent(invite.GetEventId()); + time_t statusTime = invite.GetStatusTime(); + bool hasStatusTime = statusTime != 946684800; // 01/01/2000 00:00:00 + + uint64 invitee = invite.GetInviteeGUID(); + Player* player = ObjectAccessor::FindPlayer(invitee); + + uint8 level = player ? player->getLevel() : Player::GetLevelFromDB(invitee); + + WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (statusTime ? 4 : 0) + 1); + data.appendPackGUID(invitee); + data << uint64(invite.GetEventId()); + data << uint64(invite.GetInviteId()); + data << uint8(level); + data << uint8(invite.GetStatus()); + data << uint8(hasStatusTime); + if (hasStatusTime) + data.AppendPackedTime(statusTime); + data << uint8(invite.GetSenderGUID() != invite.GetInviteeGUID()); // false only if the invite is sign-up + + if (!calendarEvent) // Pre-invite { - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::AddInvite: Cant add Invite 0"); - return false; + if (Player* player = ObjectAccessor::FindPlayer(invite.GetSenderGUID())) + player->SendDirectMessage(&data); } - - if (_invites.find(inviteId) != _invites.end()) + else { - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::AddInvite: Invite [" UI64FMTD "] exists", inviteId); - return false; + if (calendarEvent->GetCreatorGUID() != invite.GetInviteeGUID()) // correct? + SendPacketToAllEventRelatives(data, *calendarEvent); } - - _invites[inviteId] = newInvite; - uint64 guid = newInvite.GetInvitee(); - bool inviteAdded = AddPlayerInvite(guid, inviteId); - bool eventAdded = AddPlayerEvent(guid, newInvite.GetEventId()); - return eventAdded && inviteAdded; } -uint64 CalendarMgr::RemoveInvite(uint64 inviteId) +void CalendarMgr::SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t oldEventTime) { - CalendarInviteMap::iterator itr = _invites.find(inviteId); - if (itr == _invites.end()) - { - sLog->outError(LOG_FILTER_CALENDAR, "CalendarMgr::RemoveInvite: Invite [" UI64FMTD "] does not exist", inviteId); - return 0; - } - - uint64 invitee = itr->second.GetInvitee(); - _invites.erase(itr); - - return RemovePlayerInvite(invitee, inviteId) ? invitee : 0; + WorldPacket data(SMSG_CALENDAR_EVENT_UPDATED_ALERT, 1 + 8 + 4 + 4 + 4 + 1 + 4 + + calendarEvent.GetTitle().size() + calendarEvent.GetDescription().size() + 1 + 4 + 4); + data << uint8(1); // unk + data << uint64(calendarEvent.GetEventId()); + data.AppendPackedTime(oldEventTime); + data << uint32(calendarEvent.GetFlags()); + data.AppendPackedTime(calendarEvent.GetEventTime()); + data << uint8(calendarEvent.GetType()); + data << int32(calendarEvent.GetDungeonId()); + data << calendarEvent.GetTitle(); + data << calendarEvent.GetDescription(); + data << uint8(CALENDAR_REPEAT_NEVER); // repeatable + data << uint32(CALENDAR_MAX_INVITES); + data << uint32(0); // unk + + SendPacketToAllEventRelatives(data, calendarEvent); } -bool CalendarMgr::AddPlayerInvite(uint64 guid, uint64 inviteId) +void CalendarMgr::SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { - _playerInvites[guid].insert(inviteId); - return true; + WorldPacket data(SMSG_CALENDAR_EVENT_STATUS, 8 + 8 + 4 + 4 + 1 + 1 + 4); + data.appendPackGUID(invite.GetInviteeGUID()); + data << uint64(calendarEvent.GetEventId()); + data.AppendPackedTime(calendarEvent.GetEventTime()); + data << uint32(calendarEvent.GetFlags()); + data << uint8(invite.GetStatus()); + data << uint8(invite.GetRank()); + data.AppendPackedTime(invite.GetStatusTime()); + + SendPacketToAllEventRelatives(data, calendarEvent); } -bool CalendarMgr::RemovePlayerInvite(uint64 guid, uint64 inviteId) +void CalendarMgr::SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent) { - _playerInvites[guid].erase(inviteId); - return true; + WorldPacket data(SMSG_CALENDAR_EVENT_REMOVED_ALERT, 1 + 8 + 1); + data << uint8(1); // FIXME: If true does not SignalEvent(EVENT_CALENDAR_ACTION_PENDING) + data << uint64(calendarEvent.GetEventId()); + data.AppendPackedTime(calendarEvent.GetEventTime()); + + SendPacketToAllEventRelatives(data, calendarEvent); } -void CalendarMgr::SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType type) +void CalendarMgr::SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags) { - if (Player* player = ObjectAccessor::FindPlayer(calendarEvent.GetCreatorGUID())) - player->GetSession()->SendCalendarEvent(calendarEvent, type); + WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED, 8 + 4 + 4 + 1); + data.appendPackGUID(invite.GetInviteeGUID()); + data << uint64(invite.GetEventId()); + data << uint32(flags); + data << uint8(1); // FIXME + + SendPacketToAllEventRelatives(data, calendarEvent); } -void CalendarMgr::SendCalendarEventInvite(CalendarInvite const& invite, bool pending) +void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { - if (Player* player = ObjectAccessor::FindPlayer(invite.GetSenderGUID())) - player->GetSession()->SendCalendarEventInvite(invite, pending); + WorldPacket data(SMSG_CALENDAR_EVENT_MODERATOR_STATUS_ALERT, 8 + 8 + 1 + 1); + data.appendPackGUID(invite.GetInviteeGUID()); + data << uint64(invite.GetEventId()); + data << uint8(invite.GetRank()); + data << uint8(1); // Unk boolean - Display to client? + + SendPacketToAllEventRelatives(data, calendarEvent); } void CalendarMgr::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) { - if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee())) - player->GetSession()->SendCalendarEventInviteAlert(calendarEvent, invite); + WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_ALERT); + data << uint64(calendarEvent.GetEventId()); + data << calendarEvent.GetTitle(); + data.AppendPackedTime(calendarEvent.GetEventTime()); + data << uint32(calendarEvent.GetFlags()); + data << uint32(calendarEvent.GetType()); + data << int32(calendarEvent.GetDungeonId()); + data << uint64(invite.GetInviteId()); + data << uint8(invite.GetStatus()); + data << uint8(invite.GetRank()); + data.appendPackGUID(calendarEvent.GetCreatorGUID()); + data.appendPackGUID(invite.GetSenderGUID()); + + if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) + { + if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId())) + guild->BroadcastPacket(&data); + } + else + if (Player* player = ObjectAccessor::FindPlayer(invite.GetInviteeGUID())) + player->SendDirectMessage(&data); } -void CalendarMgr::SendCalendarEventUpdateAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType type) +void CalendarMgr::SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType) { - if (Player* player = ObjectAccessor::FindPlayer(guid)) - player->GetSession()->SendCalendarEventUpdateAlert(calendarEvent, type); -} + Player* player = ObjectAccessor::FindPlayer(guid); + if (!player) + return; + + std::vector<CalendarInvite*> const& eventInviteeList = _invites[calendarEvent.GetEventId()]; + + WorldPacket data(SMSG_CALENDAR_SEND_EVENT, 60 + eventInviteeList.size() * 32); + data << uint8(sendType); + data.appendPackGUID(calendarEvent.GetCreatorGUID()); + data << uint64(calendarEvent.GetEventId()); + data << calendarEvent.GetTitle(); + data << calendarEvent.GetDescription(); + data << uint8(calendarEvent.GetType()); + data << uint8(CALENDAR_REPEAT_NEVER); // repeatable + data << uint32(CALENDAR_MAX_INVITES); + data << int32(calendarEvent.GetDungeonId()); + data << uint32(calendarEvent.GetFlags()); + data.AppendPackedTime(calendarEvent.GetEventTime()); + data.AppendPackedTime(calendarEvent.GetTimeZoneTime()); + data << uint32(calendarEvent.GetGuildId()); + + data << uint32(eventInviteeList.size()); + for (std::vector<CalendarInvite*>::const_iterator itr = eventInviteeList.begin(); itr != eventInviteeList.end(); ++itr) + { + CalendarInvite const* calendarInvite = (*itr); + uint64 inviteeGuid = calendarInvite->GetInviteeGUID(); + Player* invitee = ObjectAccessor::FindPlayer(inviteeGuid); + + uint8 inviteeLevel = invitee ? invitee->getLevel() : Player::GetLevelFromDB(inviteeGuid); + uint32 inviteeGuildId = invitee ? invitee->GetGuildId() : Player::GetGuildIdFromDB(inviteeGuid); + + data.appendPackGUID(inviteeGuid); + data << uint8(inviteeLevel); + data << uint8(calendarInvite->GetStatus()); + data << uint8(calendarInvite->GetRank()); + data << uint8(calendarEvent.IsGuildEvent() && calendarEvent.GetGuildId() == inviteeGuildId); + data << uint64(calendarInvite->GetInviteId()); + data.AppendPackedTime(calendarInvite->GetStatusTime()); + data << calendarInvite->GetText(); + } -void CalendarMgr::SendCalendarEventStatus(uint64 guid, CalendarEvent const& calendarEvent, CalendarInvite const& invite) -{ - if (Player* player = ObjectAccessor::FindPlayer(guid)) - player->GetSession()->SendCalendarEventStatus(calendarEvent, invite); + player->SendDirectMessage(&data); } -void CalendarMgr::SendCalendarEventRemovedAlert(uint64 guid, CalendarEvent const& calendarEvent) +void CalendarMgr::SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status) { if (Player* player = ObjectAccessor::FindPlayer(guid)) - player->GetSession()->SendCalendarEventRemovedAlert(calendarEvent); + { + WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED_ALERT, 8 + 4 + 4 + 1); + data << uint64(calendarEvent.GetEventId()); + data.AppendPackedTime(calendarEvent.GetEventTime()); + data << uint32(calendarEvent.GetFlags()); + data << uint8(status); + + player->SendDirectMessage(&data); + } } -void CalendarMgr::SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status) +void CalendarMgr::SendCalendarClearPendingAction(uint64 guid) { if (Player* player = ObjectAccessor::FindPlayer(guid)) - player->GetSession()->SendCalendarEventInviteRemoveAlert(calendarEvent, status); + { + WorldPacket data(SMSG_CALENDAR_CLEAR_PENDING_ACTION, 0); + player->SendDirectMessage(&data); + } } -void CalendarMgr::SendCalendarEventInviteRemove(uint64 guid, CalendarInvite const& invite, uint32 flags) +void CalendarMgr::SendCalendarCommandResult(uint64 guid, CalendarError err, char const* param /*= NULL*/) { if (Player* player = ObjectAccessor::FindPlayer(guid)) - player->GetSession()->SendCalendarEventInviteRemove(invite, flags); + { + WorldPacket data(SMSG_CALENDAR_COMMAND_RESULT, 0); + data << uint32(0); + data << uint8(0); + switch (err) + { + case CALENDAR_ERROR_OTHER_INVITES_EXCEEDED: + case CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S: + case CALENDAR_ERROR_IGNORING_YOU_S: + data << param; + break; + default: + data << uint8(0); + break; + } + + data << uint32(err); + + player->SendDirectMessage(&data); + } } -void CalendarMgr::SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite) +void CalendarMgr::SendPacketToAllEventRelatives(WorldPacket packet, CalendarEvent const& calendarEvent) { - if (Player* player = ObjectAccessor::FindPlayer(invite.GetInvitee())) - player->GetSession()->SendCalendarEventModeratorStatusAlert(invite); + // Send packet to all guild members + if (calendarEvent.IsGuildEvent() || calendarEvent.IsGuildAnnouncement()) + if (Guild* guild = sGuildMgr->GetGuildById(calendarEvent.GetGuildId())) + guild->BroadcastPacket(&packet); + + // Send packet to all invitees if event is non-guild, in other case only to non-guild invitees (packet was broadcasted for them) + std::vector<CalendarInvite*> invites = _invites[calendarEvent.GetEventId()]; + for (std::vector<CalendarInvite*>::iterator itr = invites.begin(); itr != invites.end(); ++itr) + if (Player* player = ObjectAccessor::FindPlayer((*itr)->GetInviteeGUID())) + if (!calendarEvent.IsGuildEvent() || (calendarEvent.IsGuildEvent() && player->GetGuildId() != calendarEvent.GetGuildId())) + player->SendDirectMessage(&packet); } diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h index a8749778cb3..db6acb667ec 100644 --- a/src/server/game/Calendar/CalendarMgr.h +++ b/src/server/game/Calendar/CalendarMgr.h @@ -19,60 +19,311 @@ #define TRINITY_CALENDARMGR_H #include <ace/Singleton.h> -#include "Calendar.h" +#include "Common.h" +#include "WorldPacket.h" + +enum CalendarMailAnswers +{ + // else + CALENDAR_EVENT_REMOVED_MAIL_SUBJECT = 0, + // if ( *(_DWORD *)(a1 + 8292) & 0x100 ) + CALENDAR_INVITE_REMOVED_MAIL_SUBJECT = 0x100 +}; + +enum CalendarFlags +{ + CALENDAR_FLAG_ALL_ALLOWED = 0x001, + CALENDAR_FLAG_INVITES_LOCKED = 0x010, + CALENDAR_FLAG_WITHOUT_INVITES = 0x040, + CALENDAR_FLAG_GUILD_EVENT = 0x400 +}; + +enum CalendarModerationRank +{ + CALENDAR_RANK_PLAYER = 0, + CALENDAR_RANK_MODERATOR = 1, + CALENDAR_RANK_OWNER = 2 +}; + +enum CalendarSendEventType +{ + CALENDAR_SENDTYPE_GET = 0, + CALENDAR_SENDTYPE_ADD = 1, + CALENDAR_SENDTYPE_COPY = 2 +}; + +enum CalendarEventType +{ + CALENDAR_TYPE_RAID = 0, + CALENDAR_TYPE_DUNGEON = 1, + CALENDAR_TYPE_PVP = 2, + CALENDAR_TYPE_MEETING = 3, + CALENDAR_TYPE_OTHER = 4 +}; + +enum CalendarRepeatType +{ + CALENDAR_REPEAT_NEVER = 0, + CALENDAR_REPEAT_WEEKLY = 1, + CALENDAR_REPEAT_BIWEEKLY = 2, + CALENDAR_REPEAT_MONTHLY = 3 +}; + +enum CalendarInviteStatus +{ + CALENDAR_STATUS_INVITED = 0, + CALENDAR_STATUS_ACCEPTED = 1, + CALENDAR_STATUS_DECLINED = 2, + CALENDAR_STATUS_CONFIRMED = 3, + CALENDAR_STATUS_OUT = 4, + CALENDAR_STATUS_STANDBY = 5, + CALENDAR_STATUS_SIGNED_UP = 6, + CALENDAR_STATUS_NOT_SIGNED_UP = 7, + CALENDAR_STATUS_TENTATIVE = 8, + CALENDAR_STATUS_REMOVED = 9 // correct name? +}; + +enum CalendarError +{ + CALENDAR_OK = 0, + CALENDAR_ERROR_GUILD_EVENTS_EXCEEDED = 1, + CALENDAR_ERROR_EVENTS_EXCEEDED = 2, + CALENDAR_ERROR_SELF_INVITES_EXCEEDED = 3, + CALENDAR_ERROR_OTHER_INVITES_EXCEEDED = 4, + CALENDAR_ERROR_PERMISSIONS = 5, + CALENDAR_ERROR_EVENT_INVALID = 6, + CALENDAR_ERROR_NOT_INVITED = 7, + CALENDAR_ERROR_INTERNAL = 8, + CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD = 9, + CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S = 10, + CALENDAR_ERROR_PLAYER_NOT_FOUND = 11, + CALENDAR_ERROR_NOT_ALLIED = 12, + CALENDAR_ERROR_IGNORING_YOU_S = 13, + CALENDAR_ERROR_INVITES_EXCEEDED = 14, + CALENDAR_ERROR_INVALID_DATE = 16, + CALENDAR_ERROR_INVALID_TIME = 17, + + CALENDAR_ERROR_NEEDS_TITLE = 19, + CALENDAR_ERROR_EVENT_PASSED = 20, + CALENDAR_ERROR_EVENT_LOCKED = 21, + CALENDAR_ERROR_DELETE_CREATOR_FAILED = 22, + CALENDAR_ERROR_SYSTEM_DISABLED = 24, + CALENDAR_ERROR_RESTRICTED_ACCOUNT = 25, + CALENDAR_ERROR_ARENA_EVENTS_EXCEEDED = 26, + CALENDAR_ERROR_RESTRICTED_LEVEL = 27, + CALENDAR_ERROR_USER_SQUELCHED = 28, + CALENDAR_ERROR_NO_INVITE = 29, + + CALENDAR_ERROR_EVENT_WRONG_SERVER = 36, + CALENDAR_ERROR_INVITE_WRONG_SERVER = 37, + CALENDAR_ERROR_NO_GUILD_INVITES = 38, + CALENDAR_ERROR_INVALID_SIGNUP = 39, + CALENDAR_ERROR_NO_MODERATOR = 40 +}; + +#define CALENDAR_MAX_EVENTS 30 +#define CALENDAR_MAX_GUILD_EVENTS 100 +#define CALENDAR_MAX_INVITES 100 + +struct CalendarInvite +{ + public: + CalendarInvite(CalendarInvite const& calendarInvite, uint64 inviteId, uint64 eventId) + { + _inviteId = inviteId; + _eventId = eventId; + _invitee = calendarInvite.GetInviteeGUID(); + _senderGUID = calendarInvite.GetSenderGUID(); + _statusTime = calendarInvite.GetStatusTime(); + _status = calendarInvite.GetStatus(); + _rank = calendarInvite.GetRank(); + _text = calendarInvite.GetText(); + } + + CalendarInvite() : _inviteId(1), _eventId(0), _invitee(0), _senderGUID(0), _statusTime(time(NULL)), + _status(CALENDAR_STATUS_INVITED), _rank(CALENDAR_RANK_PLAYER), _text("") { } + + CalendarInvite(uint64 inviteId, uint64 eventId, uint64 invitee, uint64 senderGUID, time_t statusTime, + CalendarInviteStatus status, CalendarModerationRank rank, std::string text) : + _inviteId(inviteId), _eventId(eventId), _invitee(invitee), _senderGUID(senderGUID), _statusTime(statusTime), + _status(status), _rank(rank), _text(text) { } + + ~CalendarInvite(); + + void SetInviteId(uint64 inviteId) { _inviteId = inviteId; } + uint64 GetInviteId() const { return _inviteId; } + + void SetEventId(uint64 eventId) { _eventId = eventId; } + uint64 GetEventId() const { return _eventId; } + + void SetSenderGUID(uint64 guid) { _senderGUID = guid; } + uint64 GetSenderGUID() const { return _senderGUID; } + + void SetInvitee(uint64 guid) { _invitee = guid; } + uint64 GetInviteeGUID() const { return _invitee; } + + void SetStatusTime(time_t statusTime) { _statusTime = statusTime; } + time_t GetStatusTime() const { return _statusTime; } + + void SetText(std::string text) { _text = text; } + std::string GetText() const { return _text; } + + void SetStatus(CalendarInviteStatus status) { _status = status; } + CalendarInviteStatus GetStatus() const { return _status; } + + void SetRank(CalendarModerationRank rank) { _rank = rank; } + CalendarModerationRank GetRank() const { return _rank; } + + private: + uint64 _inviteId; + uint64 _eventId; + uint64 _invitee; + uint64 _senderGUID; + time_t _statusTime; + CalendarInviteStatus _status; + CalendarModerationRank _rank; + std::string _text; +}; + +struct CalendarEvent +{ + public: + CalendarEvent(CalendarEvent const& calendarEvent, uint64 eventId) + { + _eventId = eventId; + _creatorGUID = calendarEvent.GetCreatorGUID(); + _guildId = calendarEvent.GetGuildId(); + _type = calendarEvent.GetType(); + _dungeonId = calendarEvent.GetDungeonId(); + _eventTime = calendarEvent.GetEventTime(); + _flags = calendarEvent.GetFlags(); + _timezoneTime = calendarEvent.GetTimeZoneTime(); + _title = calendarEvent.GetTitle(); + _description = calendarEvent.GetDescription(); + } + + CalendarEvent(uint64 eventId, uint64 creatorGUID, uint32 guildId, CalendarEventType type, int32 dungeonId, + time_t eventTime, uint32 flags, time_t timezoneTime, std::string title, std::string description) : + _eventId(eventId), _creatorGUID(creatorGUID), _guildId(guildId), _type(type), _dungeonId(dungeonId), + _eventTime(eventTime), _flags(flags), _timezoneTime(timezoneTime), _title(title), + _description(description) { } + + CalendarEvent() : _eventId(1), _creatorGUID(0), _guildId(0), _type(CALENDAR_TYPE_OTHER), _dungeonId(-1), _eventTime(0), + _flags(0), _timezoneTime(0), _title(""), _description("") { } + + ~CalendarEvent(); + + void SetEventId(uint64 eventId) { _eventId = eventId; } + uint64 GetEventId() const { return _eventId; } + + void SetCreatorGUID(uint64 guid) { _creatorGUID = guid; } + uint64 GetCreatorGUID() const { return _creatorGUID; } + + void SetGuildId(uint32 guildId) { _guildId = guildId; } + uint32 GetGuildId() const { return _guildId; } + + void SetTitle(std::string title) { _title = title; } + std::string GetTitle() const { return _title; } + + void SetDescription(std::string description) { _description = description; } + std::string GetDescription() const { return _description; } + + void SetType(CalendarEventType type) { _type = type; } + CalendarEventType GetType() const { return _type; } + + void SetDungeonId(int32 dungeonId) { _dungeonId = dungeonId; } + int32 GetDungeonId() const { return _dungeonId; } + + void SetEventTime(time_t eventTime) { _eventTime = eventTime; } + time_t GetEventTime() const { return _eventTime; } + + void SetFlags(uint32 flags) { _flags = flags; } + uint32 GetFlags() const { return _flags; } + + void SetTimeZoneTime(time_t timezoneTime) { _timezoneTime = timezoneTime; } + time_t GetTimeZoneTime() const { return _timezoneTime; } + + bool IsGuildEvent() const { return _flags & CALENDAR_FLAG_GUILD_EVENT; } + bool IsGuildAnnouncement() const { return _flags & CALENDAR_FLAG_WITHOUT_INVITES; } + + std::string BuildCalendarMailSubject(uint64 remover) const; + std::string BuildCalendarMailBody() const; + + private: + uint64 _eventId; + uint64 _creatorGUID; + uint32 _guildId; + CalendarEventType _type; + int32 _dungeonId; + time_t _eventTime; + uint32 _flags; + time_t _timezoneTime; + std::string _title; + std::string _description; +}; + +typedef std::set<CalendarEvent*> CalendarEventStore; +typedef std::map<uint64 /* eventId */, std::vector<CalendarInvite*> > CalendarInviteStore; class CalendarMgr { - friend class ACE_Singleton<CalendarMgr, ACE_Null_Mutex>; + friend class ACE_Singleton<CalendarMgr, ACE_Null_Mutex>; + private: CalendarMgr(); ~CalendarMgr(); + CalendarEventStore _events; + CalendarInviteStore _invites; + + std::deque<uint64> _freeEventIds; + std::deque<uint64> _freeInviteIds; + uint64 _maxEventId; + uint64 _maxInviteId; + public: void LoadFromDB(); - CalendarInvite* GetInvite(uint64 inviteId); CalendarEvent* GetEvent(uint64 eventId); + CalendarEventStore const& GetEvents() const { return _events; } + CalendarEventStore GetPlayerEvents(uint64 guid); - CalendarInviteIdList const& GetPlayerInvites(uint64 guid); - CalendarEventIdList const& GetPlayerEvents(uint64 guid); + CalendarInvite* GetInvite(uint64 inviteId); + CalendarInviteStore const& GetInvites() const { return _invites; } + std::vector<CalendarInvite*> GetEventInvites(uint64 eventId); + std::vector<CalendarInvite*> GetPlayerInvites(uint64 guid); - uint32 GetPlayerNumPending(uint64 guid); + void FreeEventId(uint64 id); uint64 GetFreeEventId(); + void FreeInviteId(uint64 id); uint64 GetFreeInviteId(); - void AddAction(CalendarAction const& action); - - void SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType type); - void SendCalendarEventInvite(CalendarInvite const& invite, bool pending); - void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite); - void SendCalendarEventInviteRemove(uint64 guid, CalendarInvite const& invite, uint32 flags); - void SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status); - void SendCalendarEventUpdateAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType type); - void SendCalendarEventStatus(uint64 guid, CalendarEvent const& calendarEvent, CalendarInvite const& invite); - void SendCalendarEventRemovedAlert(uint64 guid, CalendarEvent const& calendarEvent); - void SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite); + uint32 GetPlayerNumPending(uint64 guid); - private: - CalendarEvent* CheckPermisions(uint64 eventId, Player* player, uint64 inviteId, CalendarModerationRank minRank); + void AddEvent(CalendarEvent* calendarEvent, CalendarSendEventType sendType); + void RemoveEvent(uint64 eventId, uint64 remover); + void UpdateEvent(CalendarEvent* calendarEvent); - bool AddEvent(CalendarEvent const& calendarEvent); - bool RemoveEvent(uint64 eventId); - bool AddPlayerEvent(uint64 guid, uint64 eventId); - bool RemovePlayerEvent(uint64 guid, uint64 eventId); + void AddInvite(CalendarEvent* calendarEvent, CalendarInvite* invite); + void RemoveInvite(uint64 inviteId, uint64 eventId, uint64 remover); + void UpdateInvite(CalendarInvite* invite); - bool AddInvite(CalendarInvite const& invite); - uint64 RemoveInvite(uint64 inviteId); - bool AddPlayerInvite(uint64 guid, uint64 inviteId); - bool RemovePlayerInvite(uint64 guid, uint64 inviteId); + void RemoveAllPlayerEventsAndInvites(uint64 guid); + void RemovePlayerGuildEventsAndSignups(uint64 guid, uint32 guildId); - CalendarEventMap _events; - CalendarInviteMap _invites; - CalendarPlayerInviteIdMap _playerInvites; - CalendarPlayerEventIdMap _playerEvents; + void SendCalendarEvent(uint64 guid, CalendarEvent const& calendarEvent, CalendarSendEventType sendType); + void SendCalendarEventInvite(CalendarInvite const& invite); + void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite); + void SendCalendarEventInviteRemove(CalendarEvent const& calendarEvent, CalendarInvite const& invite, uint32 flags); + void SendCalendarEventInviteRemoveAlert(uint64 guid, CalendarEvent const& calendarEvent, CalendarInviteStatus status); + void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, time_t oldEventTime); + void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite); + void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent); + void SendCalendarEventModeratorStatusAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite); + void SendCalendarClearPendingAction(uint64 guid); + void SendCalendarCommandResult(uint64 guid, CalendarError err, char const* param = NULL); - uint64 _eventNum; - uint64 _inviteNum; + void SendPacketToAllEventRelatives(WorldPacket packet, CalendarEvent const& calendarEvent); }; #define sCalendarMgr ACE_Singleton<CalendarMgr, ACE_Null_Mutex>::instance() diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index 66f964fb4cf..cba38a3ebf1 100755 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -23,49 +23,56 @@ #include "World.h" #include "DatabaseEnv.h" #include "AccountMgr.h" - -Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) : m_announce(true), - m_ownership(true), m_name(name), m_password(""), m_flags(0), m_channelId(channel_id), - m_ownerGUID(0), m_Team(Team) +#include "Player.h" + +Channel::Channel(std::string const& name, uint32 channelId, uint32 team): + _announce(true), + _ownership(true), + _IsSaved(false), + _flags(0), + _channelId(channelId), + _Team(team), + _ownerGUID(0), + _name(name), + _password("") { - m_IsSaved = false; // set special flags if built-in channel - if (ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(channel_id)) // check whether it's a built-in channel + if (ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(channelId)) // check whether it's a built-in channel { - m_announce = false; // no join/leave announces - m_ownership = false; // no ownership handout + _announce = false; // no join/leave announces + _ownership = false; // no ownership handout - m_flags |= CHANNEL_FLAG_GENERAL; // for all built-in channels + _flags |= CHANNEL_FLAG_GENERAL; // for all built-in channels if (ch->flags & CHANNEL_DBC_FLAG_TRADE) // for trade channel - m_flags |= CHANNEL_FLAG_TRADE; + _flags |= CHANNEL_FLAG_TRADE; if (ch->flags & CHANNEL_DBC_FLAG_CITY_ONLY2) // for city only channels - m_flags |= CHANNEL_FLAG_CITY; + _flags |= CHANNEL_FLAG_CITY; if (ch->flags & CHANNEL_DBC_FLAG_LFG) // for LFG channel - m_flags |= CHANNEL_FLAG_LFG; + _flags |= CHANNEL_FLAG_LFG; else // for all other channels - m_flags |= CHANNEL_FLAG_NOT_LFG; + _flags |= CHANNEL_FLAG_NOT_LFG; } else // it's custom channel { - m_flags |= CHANNEL_FLAG_CUSTOM; + _flags |= CHANNEL_FLAG_CUSTOM; // If storing custom channels in the db is enabled either load or save the channel if (sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS)) { PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHANNEL); stmt->setString(0, name); - stmt->setUInt32(1, m_Team); + stmt->setUInt32(1, _Team); PreparedQueryResult result = CharacterDatabase.Query(stmt); if (result) //load { Field* fields = result->Fetch(); - m_announce = fields[0].GetBool(); - m_ownership = fields[1].GetBool(); - m_password = fields[2].GetString(); + _announce = fields[0].GetBool(); + _ownership = fields[1].GetBool(); + _password = fields[2].GetString(); const char* db_BannedList = fields[3].GetCString(); if (db_BannedList) @@ -76,8 +83,8 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) : m_an uint64 banned_guid = atol(*i); if (banned_guid) { - sLog->outDebug(LOG_FILTER_CHATSYS, "Channel(%s) loaded banned guid:" UI64FMTD "", name.c_str(), banned_guid); - banned.insert(banned_guid); + sLog->outDebug(LOG_FILTER_CHATSYS, "Channel(%s) loaded bannedStore guid:" UI64FMTD "", name.c_str(), banned_guid); + bannedStore.insert(banned_guid); } } } @@ -86,45 +93,45 @@ Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team) : m_an { stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_CHANNEL); stmt->setString(0, name); - stmt->setUInt32(1, m_Team); + stmt->setUInt32(1, _Team); CharacterDatabase.Execute(stmt); sLog->outDebug(LOG_FILTER_CHATSYS, "Channel(%s) saved in database", name.c_str()); } - m_IsSaved = true; + _IsSaved = true; } } } void Channel::UpdateChannelInDB() const { - if (m_IsSaved) + if (_IsSaved) { std::ostringstream banlist; - BannedList::const_iterator iter; - for (iter = banned.begin(); iter != banned.end(); ++iter) + BannedContainer::const_iterator iter; + for (iter = bannedStore.begin(); iter != bannedStore.end(); ++iter) banlist << (*iter) << ' '; std::string banListStr = banlist.str(); PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL); - stmt->setBool(0, m_announce); - stmt->setBool(1, m_ownership); - stmt->setString(2, m_password); + stmt->setBool(0, _announce); + stmt->setBool(1, _ownership); + stmt->setString(2, _password); stmt->setString(3, banListStr); - stmt->setString(4, m_name); - stmt->setUInt32(5, m_Team); + stmt->setString(4, _name); + stmt->setUInt32(5, _Team); CharacterDatabase.Execute(stmt); - sLog->outDebug(LOG_FILTER_CHATSYS, "Channel(%s) updated in database", m_name.c_str()); + sLog->outDebug(LOG_FILTER_CHATSYS, "Channel(%s) updated in database", _name.c_str()); } } void Channel::UpdateChannelUseageInDB() const { PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_CHANNEL_USAGE); - stmt->setString(0, m_name); - stmt->setUInt32(1, m_Team); + stmt->setString(0, _name); + stmt->setUInt32(1, _Team); CharacterDatabase.Execute(stmt); } @@ -140,531 +147,507 @@ void Channel::CleanOldChannelsInDB() } } -void Channel::Join(uint64 p, const char *pass) +void Channel::JoinChannel(Player* player, std::string const& pass) { - WorldPacket data; - if (IsOn(p)) + uint64 guid = player->GetGUID(); + if (IsOn(guid)) { - if (!IsConstant()) // non send error message for built-in channels + // Do not send error message for built-in channels + if (!IsConstant()) { - MakePlayerAlreadyMember(&data, p); - SendToOne(&data, p); + WorldPacket data; + MakePlayerAlreadyMember(&data, guid); + SendToOne(&data, guid); } return; } - if (IsBanned(p)) + if (IsBanned(guid)) { + WorldPacket data; MakeBanned(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - if (m_password.length() > 0 && strcmp(pass, m_password.c_str())) + if (!_password.empty() && pass != _password) { + WorldPacket data; MakeWrongPassword(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - Player* player = ObjectAccessor::FindPlayer(p); - - if (player) + if (HasFlag(CHANNEL_FLAG_LFG) && + sWorld->getBoolConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && + AccountMgr::IsPlayerAccount(player->GetSession()->GetSecurity()) && + player->GetGroup()) { - if (HasFlag(CHANNEL_FLAG_LFG) && - sWorld->getBoolConfig(CONFIG_RESTRICTED_LFG_CHANNEL) && AccountMgr::IsPlayerAccount(player->GetSession()->GetSecurity()) && player->GetGroup()) - { - MakeNotInLfg(&data); - SendToOne(&data, p); - return; - } - - player->JoinedChannel(this); + WorldPacket data; + MakeNotInLfg(&data); + SendToOne(&data, guid); + return; } - if (m_announce && (!player || !AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || !sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL))) + player->JoinedChannel(this); + + if (_announce && (!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || + !sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL))) { - MakeJoined(&data, p); + WorldPacket data; + MakeJoined(&data, guid); SendToAll(&data); } - data.clear(); - PlayerInfo pinfo; - pinfo.player = p; + pinfo.player = guid; pinfo.flags = MEMBER_FLAG_NONE; - players[p] = pinfo; + playersStore[guid] = pinfo; + WorldPacket data; MakeYouJoined(&data); - SendToOne(&data, p); + SendToOne(&data, guid); - JoinNotify(p); + JoinNotify(guid); // Custom channel handling if (!IsConstant()) { // Update last_used timestamp in db - if (!players.empty()) + if (!playersStore.empty()) UpdateChannelUseageInDB(); // If the channel has no owner yet and ownership is allowed, set the new owner. - if (!m_ownerGUID && m_ownership) + if (!_ownerGUID && _ownership) { - SetOwner(p, (players.size() > 1 ? true : false)); - players[p].SetModerator(true); + SetOwner(guid, playersStore.size() > 1); + playersStore[guid].SetModerator(true); } } } -void Channel::Leave(uint64 p, bool send) +void Channel::LeaveChannel(Player* player, bool send) { - if (!IsOn(p)) + uint64 guid = player->GetGUID(); + if (!IsOn(guid)) { if (send) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); } + return; } - else + + if (send) { - Player* player = ObjectAccessor::FindPlayer(p); + WorldPacket data; + MakeYouLeft(&data); + SendToOne(&data, guid); + player->LeftChannel(this); + data.clear(); + } - if (send) - { - WorldPacket data; - MakeYouLeft(&data); - SendToOne(&data, p); - if (player) - player->LeftChannel(this); - data.clear(); - } + bool changeowner = playersStore[guid].IsOwner(); - bool changeowner = players[p].IsOwner(); + playersStore.erase(guid); + if (_announce && (!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || + !sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL))) + { + WorldPacket data; + MakeLeft(&data, guid); + SendToAll(&data); + } - players.erase(p); - if (m_announce && (!player || !AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || !sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL))) - { - WorldPacket data; - MakeLeft(&data, p); - SendToAll(&data); - } + LeaveNotify(guid); - LeaveNotify(p); + if (!IsConstant()) + { + // Update last_used timestamp in db + UpdateChannelUseageInDB(); - if (!IsConstant()) + // If the channel owner left and there are still playersStore inside, pick a new owner + if (changeowner && _ownership && !playersStore.empty()) { - // Update last_used timestamp in db - UpdateChannelUseageInDB(); - - // If the channel owner left and there are still players inside, pick a new owner - if (changeowner && m_ownership && !players.empty()) - { - uint64 newowner = players.begin()->second.player; - players[newowner].SetModerator(true); - SetOwner(newowner); - } + uint64 newowner = playersStore.begin()->second.player; + playersStore[newowner].SetModerator(true); + SetOwner(newowner); } } } -void Channel::KickOrBan(uint64 good, const char *badname, bool ban) +void Channel::KickOrBan(Player const* player, std::string const& badname, bool ban) { - AccountTypes sec = SEC_PLAYER; - Player* gplr = ObjectAccessor::FindPlayer(good); - if (gplr) - sec = gplr->GetSession()->GetSecurity(); + AccountTypes sec = player->GetSession()->GetSecurity(); + uint64 good = player->GetGUID(); if (!IsOn(good)) { WorldPacket data; MakeNotMember(&data); SendToOne(&data, good); + return; } - else if (!players[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) + + if (!playersStore[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) { WorldPacket data; MakeNotModerator(&data); SendToOne(&data, good); + return; } - else + + Player* bad = sObjectAccessor->FindPlayerByName(badname); + uint64 victim = bad ? bad->GetGUID() : 0; + if (!victim || !IsOn(victim)) { - Player* bad = sObjectAccessor->FindPlayerByName(badname); - if (bad == NULL || !IsOn(bad->GetGUID())) - { - WorldPacket data; - MakePlayerNotFound(&data, badname); - SendToOne(&data, good); - } - else if (!AccountMgr::IsGMAccount(sec) && bad->GetGUID() == m_ownerGUID && good != m_ownerGUID) - { - WorldPacket data; - MakeNotOwner(&data); - SendToOne(&data, good); - } - else - { - bool changeowner = (m_ownerGUID == bad->GetGUID()); - - WorldPacket data; - bool notify = !(AccountMgr::IsGMAccount(sec) && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL)); + WorldPacket data; + MakePlayerNotFound(&data, badname); + SendToOne(&data, good); + return; + } - if (ban && !IsBanned(bad->GetGUID())) - { - banned.insert(bad->GetGUID()); - UpdateChannelInDB(); + bool changeowner = _ownerGUID == victim; - if (notify) - MakePlayerBanned(&data, bad->GetGUID(), good); - } - else if (notify) - MakePlayerKicked(&data, bad->GetGUID(), good); + if (!AccountMgr::IsGMAccount(sec) && changeowner && good != _ownerGUID) + { + WorldPacket data; + MakeNotOwner(&data); + SendToOne(&data, good); + return; + } - if (notify) - SendToAll(&data); + bool notify = !(AccountMgr::IsGMAccount(sec) && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL)); - players.erase(bad->GetGUID()); - bad->LeftChannel(this); + if (ban && !IsBanned(victim)) + { + bannedStore.insert(victim); + UpdateChannelInDB(); - if (changeowner && m_ownership && !players.empty()) - { - uint64 newowner = good; - players[newowner].SetModerator(true); - SetOwner(newowner); - } + if (notify) + { + WorldPacket data; + MakePlayerBanned(&data, victim, good); + SendToAll(&data); } } + else if (notify) + { + WorldPacket data; + MakePlayerKicked(&data, victim, good); + SendToAll(&data); + } + + playersStore.erase(victim); + bad->LeftChannel(this); + + if (changeowner && _ownership && !playersStore.empty()) + { + uint64 newowner = good; + playersStore[newowner].SetModerator(true); + SetOwner(newowner); + } } -void Channel::UnBan(uint64 good, const char *badname) +void Channel::UnBan(Player const* player, std::string const& badname) { - uint32 sec = 0; - Player* gplr = ObjectAccessor::FindPlayer(good); - if (gplr) - sec = gplr->GetSession()->GetSecurity(); + uint32 sec = player->GetSession()->GetSecurity(); + uint64 good = player->GetGUID(); if (!IsOn(good)) { WorldPacket data; MakeNotMember(&data); SendToOne(&data, good); + return; } - else if (!players[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) + + if (!playersStore[good].IsModerator() && !AccountMgr::IsGMAccount(sec)) { WorldPacket data; MakeNotModerator(&data); SendToOne(&data, good); + return; } - else - { - Player* bad = sObjectAccessor->FindPlayerByName(badname); - if (bad == NULL || !IsBanned(bad->GetGUID())) - { - WorldPacket data; - MakePlayerNotFound(&data, badname); - SendToOne(&data, good); - } - else - { - banned.erase(bad->GetGUID()); - WorldPacket data; - MakePlayerUnbanned(&data, bad->GetGUID(), good); - SendToAll(&data); + Player* bad = sObjectAccessor->FindPlayerByName(badname); + uint64 victim = bad ? bad->GetGUID(): 0; - UpdateChannelInDB(); - } + if (!victim || !IsBanned(victim)) + { + WorldPacket data; + MakePlayerNotFound(&data, badname); + SendToOne(&data, good); + return; } + + bannedStore.erase(victim); + + WorldPacket data; + MakePlayerUnbanned(&data, victim, good); + SendToAll(&data); + + UpdateChannelInDB(); } -void Channel::Password(uint64 p, const char *pass) +void Channel::Password(Player const* player, std::string const& pass) { - uint32 sec = 0; - Player* player = ObjectAccessor::FindPlayer(p); - if (player) - sec = player->GetSession()->GetSecurity(); - - ChatHandler chat(player); + uint64 guid = player->GetGUID(); - if (!IsOn(p)) + ChatHandler chat(player->GetSession()); + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else if (!players[p].IsModerator() && !AccountMgr::IsGMAccount(sec)) + + if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(player->GetSession()->GetSecurity())) { WorldPacket data; MakeNotModerator(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else - { - m_password = pass; - WorldPacket data; - MakePasswordChanged(&data, p); - SendToAll(&data); + _password = pass; - UpdateChannelInDB(); - } + WorldPacket data; + MakePasswordChanged(&data, guid); + SendToAll(&data); + + UpdateChannelInDB(); } -void Channel::SetMode(uint64 p, const char *p2n, bool mod, bool set) +void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bool set) { - Player* player = ObjectAccessor::FindPlayer(p); - if (!player) - return; - + uint64 guid = player->GetGUID(); uint32 sec = player->GetSession()->GetSecurity(); - if (!IsOn(p)) + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else if (!players[p].IsModerator() && !AccountMgr::IsGMAccount(sec)) + + if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(sec)) { WorldPacket data; MakeNotModerator(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else - { - Player* newp = sObjectAccessor->FindPlayerByName(p2n); - if (!newp) - { - WorldPacket data; - MakePlayerNotFound(&data, p2n); - SendToOne(&data, p); - return; - } - if (p == m_ownerGUID && newp->GetGUID() == m_ownerGUID && mod) - return; + if (guid == _ownerGUID && std::string(p2n) == player->GetName() && mod) + return; - if (!IsOn(newp->GetGUID())) - { - WorldPacket data; - MakePlayerNotFound(&data, p2n); - SendToOne(&data, p); - return; - } + Player* newp = sObjectAccessor->FindPlayerByName(p2n); + uint64 victim = newp ? newp->GetGUID() : 0; + if (!victim || !IsOn(victim) || // allow make moderator from another team only if both is GMs // at this moment this only way to show channel post for GM from another team - if ((!AccountMgr::IsGMAccount(player->GetSession()->GetSecurity()) || !AccountMgr::IsGMAccount(newp->GetSession()->GetSecurity())) && - player->GetTeam() != newp->GetTeam() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) - { - WorldPacket data; - MakePlayerNotFound(&data, p2n); - SendToOne(&data, p); - return; - } - - if (m_ownerGUID == newp->GetGUID() && m_ownerGUID != p) - { - WorldPacket data; - MakeNotOwner(&data); - SendToOne(&data, p); - return; - } + ((!AccountMgr::IsGMAccount(sec) || !AccountMgr::IsGMAccount(newp->GetSession()->GetSecurity())) && + player->GetTeam() != newp->GetTeam() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))) + { + WorldPacket data; + MakePlayerNotFound(&data, p2n); + SendToOne(&data, guid); + return; + } - if (mod) - SetModerator(newp->GetGUID(), set); - else - SetMute(newp->GetGUID(), set); + if (_ownerGUID == victim && _ownerGUID != guid) + { + WorldPacket data; + MakeNotOwner(&data); + SendToOne(&data, guid); + return; } + + if (mod) + SetModerator(newp->GetGUID(), set); + else + SetMute(newp->GetGUID(), set); } -void Channel::SetOwner(uint64 p, const char *newname) +void Channel::SetOwner(Player const* player, std::string const& newname) { - Player* player = ObjectAccessor::FindPlayer(p); - if (!player) - return; - + uint64 guid = player->GetGUID(); uint32 sec = player->GetSession()->GetSecurity(); - if (!IsOn(p)) + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - if (!AccountMgr::IsGMAccount(sec) && p != m_ownerGUID) + if (!AccountMgr::IsGMAccount(sec) && guid != _ownerGUID) { WorldPacket data; MakeNotOwner(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } Player* newp = sObjectAccessor->FindPlayerByName(newname); - if (newp == NULL || !IsOn(newp->GetGUID())) + uint64 victim = newp ? newp->GetGUID() : 0; + + if (!victim || !IsOn(victim) || + (newp->GetTeam() != player->GetTeam() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))) { WorldPacket data; MakePlayerNotFound(&data, newname); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - if (newp->GetTeam() != player->GetTeam() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) - { - WorldPacket data; - MakePlayerNotFound(&data, newname); - SendToOne(&data, p); - return; - } - - players[newp->GetGUID()].SetModerator(true); - SetOwner(newp->GetGUID()); + playersStore[victim].SetModerator(true); + SetOwner(victim); } -void Channel::SendWhoOwner(uint64 p) +void Channel::SendWhoOwner(uint64 guid) { - if (!IsOn(p)) - { - WorldPacket data; - MakeNotMember(&data); - SendToOne(&data, p); - } - else - { - WorldPacket data; + WorldPacket data; + if (IsOn(guid)) MakeChannelOwner(&data); - SendToOne(&data, p); - } + else + MakeNotMember(&data); + SendToOne(&data, guid); } -void Channel::List(Player* player) +void Channel::List(Player const* player) { - uint64 p = player->GetGUID(); + uint64 guid = player->GetGUID(); - if (!IsOn(p)) + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else - { - WorldPacket data(SMSG_CHANNEL_LIST, 1+(GetName().size()+1)+1+4+players.size()*(8+1)); - data << uint8(1); // channel type? - data << GetName(); // channel name - data << uint8(GetFlags()); // channel flags? - size_t pos = data.wpos(); - data << uint32(0); // size of list, placeholder + sLog->outDebug(LOG_FILTER_CHATSYS, "SMSG_CHANNEL_LIST %s Channel: %s", + player->GetSession()->GetPlayerInfo().c_str(), GetName().c_str()); - uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST); + WorldPacket data(SMSG_CHANNEL_LIST, 1+(GetName().size()+1)+1+4+playersStore.size()*(8+1)); + data << uint8(1); // channel type? + data << GetName(); // channel name + data << uint8(GetFlags()); // channel flags? - uint32 count = 0; - for (PlayerList::const_iterator i = players.begin(); i != players.end(); ++i) - { - Player* member = ObjectAccessor::FindPlayer(i->first); + size_t pos = data.wpos(); + data << uint32(0); // size of list, placeholder - // PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters - // MODERATOR, GAME MASTER, ADMINISTRATOR can see all - if (member && (!AccountMgr::IsPlayerAccount(player->GetSession()->GetSecurity()) || member->GetSession()->GetSecurity() <= AccountTypes(gmLevelInWhoList)) && - member->IsVisibleGloballyFor(player)) - { - data << uint64(i->first); - data << uint8(i->second.flags); // flags seems to be changed... - ++count; - } - } + uint32 gmLevelInWhoList = sWorld->getIntConfig(CONFIG_GM_LEVEL_IN_WHO_LIST); - data.put<uint32>(pos, count); + uint32 count = 0; + for (PlayerContainer::const_iterator i = playersStore.begin(); i != playersStore.end(); ++i) + { + Player* member = ObjectAccessor::FindPlayer(i->first); - SendToOne(&data, p); + // PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters + // MODERATOR, GAME MASTER, ADMINISTRATOR can see all + if (member && (!AccountMgr::IsPlayerAccount(player->GetSession()->GetSecurity()) || member->GetSession()->GetSecurity() <= AccountTypes(gmLevelInWhoList)) && + member->IsVisibleGloballyFor(player)) + { + data << uint64(i->first); + data << uint8(i->second.flags); // flags seems to be changed... + ++count; + } } + + data.put<uint32>(pos, count); + + SendToOne(&data, guid); } -void Channel::Announce(uint64 p) +void Channel::Announce(Player const* player) { - uint32 sec = 0; - Player* player = ObjectAccessor::FindPlayer(p); - if (player) - sec = player->GetSession()->GetSecurity(); + uint64 guid = player->GetGUID(); + uint32 sec = player->GetSession()->GetSecurity(); - if (!IsOn(p)) + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else if (!players[p].IsModerator() && !AccountMgr::IsGMAccount(sec)) + + if (!playersStore[guid].IsModerator() && !AccountMgr::IsGMAccount(sec)) { WorldPacket data; MakeNotModerator(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else - { - m_announce = !m_announce; - WorldPacket data; - if (m_announce) - MakeAnnouncementsOn(&data, p); - else - MakeAnnouncementsOff(&data, p); - SendToAll(&data); + _announce = !_announce; - UpdateChannelInDB(); - } + WorldPacket data; + if (_announce) + MakeAnnouncementsOn(&data, guid); + else + MakeAnnouncementsOff(&data, guid); + SendToAll(&data); + + UpdateChannelInDB(); } -void Channel::Say(uint64 p, const char *what, uint32 lang) +void Channel::Say(uint64 guid, std::string const& what, uint32 lang) { - if (!what) + if (what.empty()) return; + if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) lang = LANG_UNIVERSAL; - Player* player = ObjectAccessor::FindPlayer(p); - - if (!IsOn(p)) + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); + return; } - else if (players[p].IsMuted()) + + if (playersStore[guid].IsMuted()) { WorldPacket data; MakeMuted(&data); - SendToOne(&data, p); - } - else - { - uint32 messageLength = strlen(what) + 1; - - WorldPacket data(SMSG_MESSAGECHAT, 1+4+8+4+m_name.size()+1+8+4+messageLength+1); - data << (uint8)CHAT_MSG_CHANNEL; - data << (uint32)lang; - data << p; // 2.1.0 - data << uint32(0); // 2.1.0 - data << m_name; - data << p; - data << messageLength; - data << what; - data << uint8(player ? player->GetChatTag() : 0); - - SendToAll(&data, !players[p].IsModerator() ? p : false); + SendToOne(&data, guid); + return; } + + WorldPacket data(SMSG_MESSAGECHAT, 1 + 4 + 8 + 4 + _name.size() + 8 + 4 + what.size() + 1); + data << uint8(CHAT_MSG_CHANNEL); + data << uint32(lang); + data << uint64(guid); + data << uint32(0); + data << _name; + data << uint64(guid); + data << uint32(what.size() + 1); + data << what; + Player* player = ObjectAccessor::FindPlayer(guid); + data << uint8(player ? player->GetChatTag() : 0); + + SendToAll(&data, !playersStore[guid].IsModerator() ? guid : false); } -void Channel::Invite(uint64 p, const char *newname) +void Channel::Invite(Player const* player, std::string const& newname) { - if (!IsOn(p)) + uint64 guid = player->GetGUID(); + + if (!IsOn(guid)) { WorldPacket data; MakeNotMember(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } @@ -673,7 +656,7 @@ void Channel::Invite(uint64 p, const char *newname) { WorldPacket data; MakePlayerNotFound(&data, newname); - SendToOne(&data, p); + SendToOne(&data, guid); return; } @@ -681,19 +664,15 @@ void Channel::Invite(uint64 p, const char *newname) { WorldPacket data; MakePlayerInviteBanned(&data, newname); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - Player* player = ObjectAccessor::FindPlayer(p); - if (!player) - return; - if (newp->GetTeam() != player->GetTeam() && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL)) { WorldPacket data; MakeInviteWrongFaction(&data); - SendToOne(&data, p); + SendToOne(&data, guid); return; } @@ -701,45 +680,47 @@ void Channel::Invite(uint64 p, const char *newname) { WorldPacket data; MakePlayerAlreadyMember(&data, newp->GetGUID()); - SendToOne(&data, p); + SendToOne(&data, guid); return; } - WorldPacket data; - if (!newp->GetSocial()->HasIgnore(GUID_LOPART(p))) + if (!newp->GetSocial()->HasIgnore(GUID_LOPART(guid))) { - MakeInvite(&data, p); + WorldPacket data; + MakeInvite(&data, guid); SendToOne(&data, newp->GetGUID()); data.clear(); } + + WorldPacket data; MakePlayerInvited(&data, newp->GetName()); - SendToOne(&data, p); + SendToOne(&data, guid); } void Channel::SetOwner(uint64 guid, bool exclaim) { - if (m_ownerGUID) + if (_ownerGUID) { // [] will re-add player after it possible removed - PlayerList::iterator p_itr = players.find(m_ownerGUID); - if (p_itr != players.end()) + PlayerContainer::iterator p_itr = playersStore.find(_ownerGUID); + if (p_itr != playersStore.end()) p_itr->second.SetOwner(false); } - m_ownerGUID = guid; - if (m_ownerGUID) + _ownerGUID = guid; + if (_ownerGUID) { - uint8 oldFlag = GetPlayerFlags(m_ownerGUID); - players[m_ownerGUID].SetModerator(true); - players[m_ownerGUID].SetOwner(true); + uint8 oldFlag = GetPlayerFlags(_ownerGUID); + playersStore[_ownerGUID].SetModerator(true); + playersStore[_ownerGUID].SetOwner(true); WorldPacket data; - MakeModeChange(&data, m_ownerGUID, oldFlag); + MakeModeChange(&data, _ownerGUID, oldFlag); SendToAll(&data); if (exclaim) { - MakeOwnerChanged(&data, m_ownerGUID); + MakeOwnerChanged(&data, _ownerGUID); SendToAll(&data); } @@ -747,36 +728,25 @@ void Channel::SetOwner(uint64 guid, bool exclaim) } } -void Channel::SendToAll(WorldPacket* data, uint64 p) +void Channel::SendToAll(WorldPacket* data, uint64 guid) { - for (PlayerList::const_iterator i = players.begin(); i != players.end(); ++i) - { - Player* player = ObjectAccessor::FindPlayer(i->first); - if (player) - { - if (!p || !player->GetSocial()->HasIgnore(GUID_LOPART(p))) + for (PlayerContainer::const_iterator i = playersStore.begin(); i != playersStore.end(); ++i) + if (Player* player = ObjectAccessor::FindPlayer(i->first)) + if (!guid || !player->GetSocial()->HasIgnore(GUID_LOPART(guid))) player->GetSession()->SendPacket(data); - } - } } void Channel::SendToAllButOne(WorldPacket* data, uint64 who) { - for (PlayerList::const_iterator i = players.begin(); i != players.end(); ++i) - { + for (PlayerContainer::const_iterator i = playersStore.begin(); i != playersStore.end(); ++i) if (i->first != who) - { - Player* player = ObjectAccessor::FindPlayer(i->first); - if (player) + if (Player* player = ObjectAccessor::FindPlayer(i->first)) player->GetSession()->SendPacket(data); - } - } } void Channel::SendToOne(WorldPacket* data, uint64 who) { - Player* player = ObjectAccessor::FindPlayer(who); - if (player) + if (Player* player = ObjectAccessor::FindPlayer(who)) player->GetSession()->SendPacket(data); } @@ -790,29 +760,25 @@ void Channel::DeVoice(uint64 /*guid1*/, uint64 /*guid2*/) } -// done void Channel::MakeNotifyPacket(WorldPacket* data, uint8 notify_type) { - data->Initialize(SMSG_CHANNEL_NOTIFY, 1+m_name.size()+1); + data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + _name.size()); *data << uint8(notify_type); - *data << m_name; + *data << _name; } -// done 0x00 void Channel::MakeJoined(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_JOINED_NOTICE); *data << uint64(guid); } -// done 0x01 void Channel::MakeLeft(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_LEFT_NOTICE); *data << uint64(guid); } -// done 0x02 void Channel::MakeYouJoined(WorldPacket* data) { MakeNotifyPacket(data, CHAT_YOU_JOINED_NOTICE); @@ -821,7 +787,6 @@ void Channel::MakeYouJoined(WorldPacket* data) *data << uint32(0); } -// done 0x03 void Channel::MakeYouLeft(WorldPacket* data) { MakeNotifyPacket(data, CHAT_YOU_LEFT_NOTICE); @@ -829,64 +794,55 @@ void Channel::MakeYouLeft(WorldPacket* data) *data << uint8(IsConstant()); } -// done 0x04 void Channel::MakeWrongPassword(WorldPacket* data) { MakeNotifyPacket(data, CHAT_WRONG_PASSWORD_NOTICE); } -// done 0x05 void Channel::MakeNotMember(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_MEMBER_NOTICE); } -// done 0x06 void Channel::MakeNotModerator(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_MODERATOR_NOTICE); } -// done 0x07 void Channel::MakePasswordChanged(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_PASSWORD_CHANGED_NOTICE); *data << uint64(guid); } -// done 0x08 void Channel::MakeOwnerChanged(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_OWNER_CHANGED_NOTICE); *data << uint64(guid); } -// done 0x09 -void Channel::MakePlayerNotFound(WorldPacket* data, const std::string& name) +void Channel::MakePlayerNotFound(WorldPacket* data, std::string const& name) { MakeNotifyPacket(data, CHAT_PLAYER_NOT_FOUND_NOTICE); *data << name; } -// done 0x0A void Channel::MakeNotOwner(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_OWNER_NOTICE); } -// done 0x0B void Channel::MakeChannelOwner(WorldPacket* data) { std::string name = ""; - if (!sObjectMgr->GetPlayerNameByGUID(m_ownerGUID, name) || name.empty()) + if (!sObjectMgr->GetPlayerNameByGUID(_ownerGUID, name) || name.empty()) name = "PLAYER_NOT_FOUND"; MakeNotifyPacket(data, CHAT_CHANNEL_OWNER_NOTICE); - *data << ((IsConstant() || !m_ownerGUID) ? "Nobody" : name); + *data << ((IsConstant() || !_ownerGUID) ? "Nobody" : name); } -// done 0x0C void Channel::MakeModeChange(WorldPacket* data, uint64 guid, uint8 oldflags) { MakeNotifyPacket(data, CHAT_MODE_CHANGE_NOTICE); @@ -895,27 +851,23 @@ void Channel::MakeModeChange(WorldPacket* data, uint64 guid, uint8 oldflags) *data << uint8(GetPlayerFlags(guid)); } -// done 0x0D void Channel::MakeAnnouncementsOn(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_ANNOUNCEMENTS_ON_NOTICE); *data << uint64(guid); } -// done 0x0E void Channel::MakeAnnouncementsOff(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_ANNOUNCEMENTS_OFF_NOTICE); *data << uint64(guid); } -// done 0x11 void Channel::MakeMuted(WorldPacket* data) { MakeNotifyPacket(data, CHAT_MUTED_NOTICE); } -// done 0x12 void Channel::MakePlayerKicked(WorldPacket* data, uint64 bad, uint64 good) { MakeNotifyPacket(data, CHAT_PLAYER_KICKED_NOTICE); @@ -923,13 +875,11 @@ void Channel::MakePlayerKicked(WorldPacket* data, uint64 bad, uint64 good) *data << uint64(good); } -// done 0x13 void Channel::MakeBanned(WorldPacket* data) { MakeNotifyPacket(data, CHAT_BANNED_NOTICE); } -// done 0x14 void Channel::MakePlayerBanned(WorldPacket* data, uint64 bad, uint64 good) { MakeNotifyPacket(data, CHAT_PLAYER_BANNED_NOTICE); @@ -937,7 +887,6 @@ void Channel::MakePlayerBanned(WorldPacket* data, uint64 bad, uint64 good) *data << uint64(good); } -// done 0x15 void Channel::MakePlayerUnbanned(WorldPacket* data, uint64 bad, uint64 good) { MakeNotifyPacket(data, CHAT_PLAYER_UNBANNED_NOTICE); @@ -945,91 +894,77 @@ void Channel::MakePlayerUnbanned(WorldPacket* data, uint64 bad, uint64 good) *data << uint64(good); } -// done 0x16 void Channel::MakePlayerNotBanned(WorldPacket* data, const std::string &name) { MakeNotifyPacket(data, CHAT_PLAYER_NOT_BANNED_NOTICE); *data << name; } -// done 0x17 void Channel::MakePlayerAlreadyMember(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_PLAYER_ALREADY_MEMBER_NOTICE); *data << uint64(guid); } -// done 0x18 void Channel::MakeInvite(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_INVITE_NOTICE); *data << uint64(guid); } -// done 0x19 void Channel::MakeInviteWrongFaction(WorldPacket* data) { MakeNotifyPacket(data, CHAT_INVITE_WRONG_FACTION_NOTICE); } -// done 0x1A void Channel::MakeWrongFaction(WorldPacket* data) { MakeNotifyPacket(data, CHAT_WRONG_FACTION_NOTICE); } -// done 0x1B void Channel::MakeInvalidName(WorldPacket* data) { MakeNotifyPacket(data, CHAT_INVALID_NAME_NOTICE); } -// done 0x1C void Channel::MakeNotModerated(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_MODERATED_NOTICE); } -// done 0x1D void Channel::MakePlayerInvited(WorldPacket* data, const std::string& name) { MakeNotifyPacket(data, CHAT_PLAYER_INVITED_NOTICE); *data << name; } -// done 0x1E void Channel::MakePlayerInviteBanned(WorldPacket* data, const std::string& name) { MakeNotifyPacket(data, CHAT_PLAYER_INVITE_BANNED_NOTICE); *data << name; } -// done 0x1F void Channel::MakeThrottled(WorldPacket* data) { MakeNotifyPacket(data, CHAT_THROTTLED_NOTICE); } -// done 0x20 void Channel::MakeNotInArea(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_IN_AREA_NOTICE); } -// done 0x21 void Channel::MakeNotInLfg(WorldPacket* data) { MakeNotifyPacket(data, CHAT_NOT_IN_LFG_NOTICE); } -// done 0x22 void Channel::MakeVoiceOn(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_VOICE_ON_NOTICE); *data << uint64(guid); } -// done 0x23 void Channel::MakeVoiceOff(WorldPacket* data, uint64 guid) { MakeNotifyPacket(data, CHAT_VOICE_OFF_NOTICE); @@ -1038,13 +973,7 @@ void Channel::MakeVoiceOff(WorldPacket* data, uint64 guid) void Channel::JoinNotify(uint64 guid) { - WorldPacket data; - - if (IsConstant()) - data.Initialize(SMSG_USERLIST_ADD, 8+1+1+4+GetName().size()+1); - else - data.Initialize(SMSG_USERLIST_UPDATE, 8+1+1+4+GetName().size()+1); - + WorldPacket data(IsConstant() ? SMSG_USERLIST_ADD : SMSG_USERLIST_UPDATE, 8 + 1 + 1 + 4 + GetName().size()); data << uint64(guid); data << uint8(GetPlayerFlags(guid)); data << uint8(GetFlags()); @@ -1059,7 +988,7 @@ void Channel::JoinNotify(uint64 guid) void Channel::LeaveNotify(uint64 guid) { - WorldPacket data(SMSG_USERLIST_REMOVE, 8+1+4+GetName().size()+1); + WorldPacket data(SMSG_USERLIST_REMOVE, 8 + 1 + 4 + GetName().size()); data << uint64(guid); data << uint8(GetFlags()); data << uint32(GetNumPlayers()); diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h index bdb5112c7ef..c816cd91257 100755 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -26,7 +26,6 @@ #include "Common.h" #include "Opcodes.h" -#include "Player.h" #include "WorldPacket.h" enum ChatNotify @@ -52,10 +51,10 @@ enum ChatNotify // CHAT_MODERATION_OFF_NOTICE = 0x10, //+ "[%s] Channel moderation disabled by %s."; CHAT_MUTED_NOTICE = 0x11, //+ "[%s] You do not have permission to speak."; CHAT_PLAYER_KICKED_NOTICE = 0x12, //? "[%s] Player %s kicked by %s."; - CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are banned from that channel."; - CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s banned by %s."; + CHAT_BANNED_NOTICE = 0x13, //+ "[%s] You are bannedStore from that channel."; + CHAT_PLAYER_BANNED_NOTICE = 0x14, //? "[%s] Player %s bannedStore by %s."; CHAT_PLAYER_UNBANNED_NOTICE = 0x15, //? "[%s] Player %s unbanned by %s."; - CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not banned."; + CHAT_PLAYER_NOT_BANNED_NOTICE = 0x16, //+ "[%s] Player %s is not bannedStore."; CHAT_PLAYER_ALREADY_MEMBER_NOTICE = 0x17, //+ "[%s] Player %s is already on the channel."; CHAT_INVITE_NOTICE = 0x18, //+ "%2$s has invited you to join the channel '%1$s'."; CHAT_INVITE_WRONG_FACTION_NOTICE = 0x19, //+ "Target is in the wrong alliance for %s."; @@ -63,7 +62,7 @@ enum ChatNotify CHAT_INVALID_NAME_NOTICE = 0x1B, //+ "Invalid channel name"; CHAT_NOT_MODERATED_NOTICE = 0x1C, //+ "%s is not moderated"; CHAT_PLAYER_INVITED_NOTICE = 0x1D, //+ "[%s] You invited %s to join the channel"; - CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been banned."; + CHAT_PLAYER_INVITE_BANNED_NOTICE = 0x1E, //+ "[%s] %s has been bannedStore."; CHAT_THROTTLED_NOTICE = 0x1F, //+ "[%s] The number of messages that can be sent to this channel is limited, please wait to send another message."; CHAT_NOT_IN_AREA_NOTICE = 0x20, //+ "[%s] You are not in the correct area for this channel."; -- The user is trying to send a chat to a zone specific channel, and they're not physically in that zone. CHAT_NOT_IN_LFG_NOTICE = 0x21, //+ "[%s] You must be queued in looking for group before joining this channel."; -- The user must be in the looking for group system to join LFG chat channels. @@ -146,18 +145,45 @@ class Channel } }; - typedef std::map<uint64, PlayerInfo> PlayerList; - PlayerList players; - typedef std::set<uint64> BannedList; - BannedList banned; - bool m_announce; - bool m_ownership; - std::string m_name; - std::string m_password; - uint8 m_flags; - uint32 m_channelId; - uint64 m_ownerGUID; - bool m_IsSaved; + public: + Channel(std::string const& name, uint32 channel_id, uint32 Team = 0); + std::string const& GetName() const { return _name; } + uint32 GetChannelId() const { return _channelId; } + bool IsConstant() const { return _channelId != 0; } + bool IsAnnounce() const { return _announce; } + bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; } + std::string const& GetPassword() const { return _password; } + void SetPassword(std::string const& npassword) { _password = npassword; } + void SetAnnounce(bool nannounce) { _announce = nannounce; } + uint32 GetNumPlayers() const { return playersStore.size(); } + uint8 GetFlags() const { return _flags; } + bool HasFlag(uint8 flag) const { return _flags & flag; } + + void JoinChannel(Player* player, std::string const& pass); + void LeaveChannel(Player* player, bool send = true); + void KickOrBan(Player const* player, std::string const& badname, bool ban); + void Kick(Player const* player, std::string const& badname) { KickOrBan(player, badname, false); } + void Ban(Player const* player, std::string const& badname) { KickOrBan(player, badname, true); } + void UnBan(Player const* player, std::string const& badname); + void Password(Player const* player, std::string const& pass); + void SetMode(Player const* player, std::string const& p2n, bool mod, bool set); + void SetOwner(uint64 guid, bool exclaim = true); + void SetOwner(Player const* player, std::string const& name); + void SendWhoOwner(uint64 guid); + void SetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, true); } + void UnsetModerator(Player const* player, std::string const& newname) { SetMode(player, newname, true, false); } + void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); } + void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); } + void List(Player const* player); + void Announce(Player const* player); + void Say(uint64 guid, std::string const& what, uint32 lang); + void Invite(Player const* player, std::string const& newp); + void Voice(uint64 guid1, uint64 guid2); + void DeVoice(uint64 guid1, uint64 guid2); + void JoinNotify(uint64 guid); // invisible notify + void LeaveNotify(uint64 guid); // invisible notify + void SetOwnership(bool ownership) { _ownership = ownership; }; + static void CleanOldChannelsInDB(); private: // initial packet data (notify type and channel name) @@ -198,91 +224,62 @@ class Channel void MakeVoiceOn(WorldPacket* data, uint64 guid); //+ 0x22 void MakeVoiceOff(WorldPacket* data, uint64 guid); //+ 0x23 - void SendToAll(WorldPacket* data, uint64 p = 0); + void SendToAll(WorldPacket* data, uint64 guid = 0); void SendToAllButOne(WorldPacket* data, uint64 who); void SendToOne(WorldPacket* data, uint64 who); - bool IsOn(uint64 who) const { return players.find(who) != players.end(); } - bool IsBanned(uint64 guid) const { return banned.find(guid) != banned.end(); } + bool IsOn(uint64 who) const { return playersStore.find(who) != playersStore.end(); } + bool IsBanned(uint64 guid) const { return bannedStore.find(guid) != bannedStore.end(); } void UpdateChannelInDB() const; void UpdateChannelUseageInDB() const; - uint8 GetPlayerFlags(uint64 p) const + uint8 GetPlayerFlags(uint64 guid) const { - PlayerList::const_iterator p_itr = players.find(p); - if (p_itr == players.end()) - return 0; - - return p_itr->second.flags; + PlayerContainer::const_iterator itr = playersStore.find(guid); + return itr != playersStore.end() ? itr->second.flags : 0; } - void SetModerator(uint64 p, bool set) + void SetModerator(uint64 guid, bool set) { - if (players[p].IsModerator() != set) + if (playersStore[guid].IsModerator() != set) { - uint8 oldFlag = GetPlayerFlags(p); - players[p].SetModerator(set); + uint8 oldFlag = GetPlayerFlags(guid); + playersStore[guid].SetModerator(set); WorldPacket data; - MakeModeChange(&data, p, oldFlag); + MakeModeChange(&data, guid, oldFlag); SendToAll(&data); } } - void SetMute(uint64 p, bool set) + void SetMute(uint64 guid, bool set) { - if (players[p].IsMuted() != set) + if (playersStore[guid].IsMuted() != set) { - uint8 oldFlag = GetPlayerFlags(p); - players[p].SetMuted(set); + uint8 oldFlag = GetPlayerFlags(guid); + playersStore[guid].SetMuted(set); WorldPacket data; - MakeModeChange(&data, p, oldFlag); + MakeModeChange(&data, guid, oldFlag); SendToAll(&data); } } - public: - uint32 m_Team; - Channel(std::string const& name, uint32 channel_id, uint32 Team = 0); - std::string const& GetName() const { return m_name; } - uint32 GetChannelId() const { return m_channelId; } - bool IsConstant() const { return m_channelId != 0; } - bool IsAnnounce() const { return m_announce; } - bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; } - std::string const& GetPassword() const { return m_password; } - void SetPassword(std::string const& npassword) { m_password = npassword; } - void SetAnnounce(bool nannounce) { m_announce = nannounce; } - uint32 GetNumPlayers() const { return players.size(); } - uint8 GetFlags() const { return m_flags; } - bool HasFlag(uint8 flag) const { return m_flags & flag; } + typedef std::map<uint64, PlayerInfo> PlayerContainer; + typedef std::set<uint64> BannedContainer; - void Join(uint64 p, const char *pass); - void Leave(uint64 p, bool send = true); - void KickOrBan(uint64 good, const char *badname, bool ban); - void Kick(uint64 good, const char *badname) { KickOrBan(good, badname, false); } - void Ban(uint64 good, const char *badname) { KickOrBan(good, badname, true); } - void UnBan(uint64 good, const char *badname); - void Password(uint64 p, const char *pass); - void SetMode(uint64 p, const char *p2n, bool mod, bool set); - void SetOwner(uint64 p, bool exclaim = true); - void SetOwner(uint64 p, const char *newname); - void SendWhoOwner(uint64 p); - void SetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, true); } - void UnsetModerator(uint64 p, const char *newname) { SetMode(p, newname, true, false); } - void SetMute(uint64 p, const char *newname) { SetMode(p, newname, false, true); } - void UnsetMute(uint64 p, const char *newname) { SetMode(p, newname, false, false); } - void List(Player* p); - void Announce(uint64 p); - void Say(uint64 p, const char *what, uint32 lang); - void Invite(uint64 p, const char *newp); - void Voice(uint64 guid1, uint64 guid2); - void DeVoice(uint64 guid1, uint64 guid2); - void JoinNotify(uint64 guid); // invisible notify - void LeaveNotify(uint64 guid); // invisible notify - void SetOwnership(bool ownership) { m_ownership = ownership; }; - static void CleanOldChannelsInDB(); + bool _announce; + bool _ownership; + bool _IsSaved; + uint8 _flags; + uint32 _channelId; + uint32 _Team; + uint64 _ownerGUID; + std::string _name; + std::string _password; + PlayerContainer playersStore; + BannedContainer bannedStore; }; #endif diff --git a/src/server/game/Chat/Channels/ChannelMgr.cpp b/src/server/game/Chat/Channels/ChannelMgr.cpp index 78b71744e0e..acd85f11ed8 100755 --- a/src/server/game/Chat/Channels/ChannelMgr.cpp +++ b/src/server/game/Chat/Channels/ChannelMgr.cpp @@ -17,7 +17,7 @@ */ #include "ChannelMgr.h" - +#include "Player.h" #include "World.h" ChannelMgr::~ChannelMgr() @@ -35,13 +35,14 @@ ChannelMgr* ChannelMgr::forTeam(uint32 team) if (team == ALLIANCE) return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance(); + if (team == HORDE) return ACE_Singleton<HordeChannelMgr, ACE_Null_Mutex>::instance(); return NULL; } -Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channel_id) +Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channelId) { std::wstring wname; Utf8toWStr(name, wname); @@ -51,7 +52,7 @@ Channel* ChannelMgr::GetJoinChannel(std::string const& name, uint32 channel_id) if (i == channels.end()) { - Channel* nchan = new Channel(name, channel_id, team); + Channel* nchan = new Channel(name, channelId, team); channels[wname] = nchan; return nchan; } @@ -78,8 +79,8 @@ Channel* ChannelMgr::GetChannel(std::string const& name, Player* player, bool pk return NULL; } - else - return i->second; + + return i->second; } void ChannelMgr::LeftChannel(std::string const& name) @@ -95,7 +96,7 @@ void ChannelMgr::LeftChannel(std::string const& name) Channel* channel = i->second; - if (channel->GetNumPlayers() == 0 && !channel->IsConstant()) + if (!channel->GetNumPlayers() && !channel->IsConstant()) { channels.erase(wname); delete channel; @@ -104,6 +105,6 @@ void ChannelMgr::LeftChannel(std::string const& name) void ChannelMgr::MakeNotOnPacket(WorldPacket* data, std::string const& name) { - data->Initialize(SMSG_CHANNEL_NOTIFY, (1+10)); // we guess size - (*data) << (uint8)0x05 << name; + data->Initialize(SMSG_CHANNEL_NOTIFY, 1 + name.size()); + (*data) << uint8(5) << name; } diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 7faf05a577c..c1ea96b0db1 100755 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -1169,6 +1169,11 @@ int ChatHandler::GetSessionDbLocaleIndex() const return m_session->GetSessionDbLocaleIndex(); } +std::string ChatHandler::GetNameLink(Player* chr) const +{ + return playerLink(chr->GetName()); +} + const char *CliHandler::GetTrinityString(int32 entry) const { return sObjectMgr->GetTrinityStringForDBCLocale(entry); diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 0c1b22182e1..3b08fd9aa76 100755 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -20,16 +20,18 @@ #define TRINITYCORE_CHAT_H #include "SharedDefines.h" -#include "Player.h" +#include "WorldSession.h" #include <vector> class ChatHandler; -class WorldSession; -class WorldObject; class Creature; +class Group; class Player; class Unit; +class WorldSession; +class WorldObject; + struct GameTele; class ChatCommand @@ -48,7 +50,6 @@ class ChatHandler public: WorldSession* GetSession() { return m_session; } explicit ChatHandler(WorldSession* session) : m_session(session), sentErrorMessage(false) {} - explicit ChatHandler(Player* player) : m_session(player->GetSession()), sentErrorMessage(false) {} virtual ~ChatHandler() {} static void FillMessageData(WorldPacket* data, WorldSession* session, uint8 type, uint32 language, const char *channelName, uint64 target_guid, const char *message, Unit* speaker); @@ -115,7 +116,7 @@ class ChatHandler bool extractPlayerTarget(char* args, Player** player, uint64* player_guid = NULL, std::string* player_name = NULL); std::string playerLink(std::string const& name) const { return m_session ? "|cffffffff|Hplayer:"+name+"|h["+name+"]|h|r" : name; } - std::string GetNameLink(Player* chr) const { return playerLink(chr->GetName()); } + std::string GetNameLink(Player* chr) const; GameObject* GetNearbyGameObject(); GameObject* GetObjectGlobalyWithGuidOrNearWithDbGuid(uint32 lowguid, uint32 entry); diff --git a/src/server/game/Chat/ChatLink.cpp b/src/server/game/Chat/ChatLink.cpp index d26f937c43d..a9c72e1112e 100644 --- a/src/server/game/Chat/ChatLink.cpp +++ b/src/server/game/Chat/ChatLink.cpp @@ -19,6 +19,7 @@ #include "SpellMgr.h" #include "ObjectMgr.h" #include "SpellInfo.h" +#include "DBCStores.h" // Supported shift-links (client generated and server side) // |color|Hachievement:achievement_id:player_guid:0:0:0:0:0:0:0:0|h[name]|h|r @@ -74,7 +75,7 @@ inline bool CheckDelimiter(std::istringstream& iss, char delimiter, const char* char c = iss.peek(); if (c != delimiter) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid %s link structure ('%c' expected, '%c' found)", iss.str().c_str(), context, delimiter, c); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid %s link structure ('%c' expected, '%c' found)", iss.str().c_str(), context, delimiter, c); return false; } iss.ignore(1); @@ -108,20 +109,20 @@ bool ItemChatLink::Initialize(std::istringstream& iss) uint32 itemEntry = 0; if (!ReadUInt32(iss, itemEntry)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item entry", iss.str().c_str()); return false; } // Validate item _item = sObjectMgr->GetItemTemplate(itemEntry); if (!_item) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid itemEntry %u in |item command", iss.str().c_str(), itemEntry); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid itemEntry %u in |item command", iss.str().c_str(), itemEntry); return false; } // Validate item's color if (_color != ItemQualityColors[_item->Quality]) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked item has color %u, but user claims %u", iss.str().c_str(), ItemQualityColors[_item->Quality], _color); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked item has color %u, but user claims %u", iss.str().c_str(), ItemQualityColors[_item->Quality], _color); return false; } // Number of various item properties after item entry @@ -135,7 +136,7 @@ bool ItemChatLink::Initialize(std::istringstream& iss) int32 id = 0; if (!ReadInt32(iss, id)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item property (%u)", iss.str().c_str(), index); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading item property (%u)", iss.str().c_str(), index); return false; } if (id && (index == randomPropertyPosition)) @@ -146,7 +147,7 @@ bool ItemChatLink::Initialize(std::istringstream& iss) _property = sItemRandomPropertiesStore.LookupEntry(id); if (!_property) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid item property id %u in |item command", iss.str().c_str(), id); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid item property id %u in |item command", iss.str().c_str(), id); return false; } } @@ -155,7 +156,7 @@ bool ItemChatLink::Initialize(std::istringstream& iss) _suffix = sItemRandomSuffixStore.LookupEntry(-id); if (!_suffix) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid item suffix id %u in |item command", iss.str().c_str(), -id); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid item suffix id %u in |item command", iss.str().c_str(), -id); return false; } } @@ -197,7 +198,7 @@ bool ItemChatLink::ValidateName(char* buffer, const char* context) } } if (!res) - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked item (id: %u) name wasn't found in any localization", context, _item->ItemId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked item (id: %u) name wasn't found in any localization", context, _item->ItemId); return res; } @@ -209,14 +210,14 @@ bool QuestChatLink::Initialize(std::istringstream& iss) uint32 questId = 0; if (!ReadUInt32(iss, questId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading quest entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading quest entry", iss.str().c_str()); return false; } // Validate quest _quest = sObjectMgr->GetQuestTemplate(questId); if (!_quest) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): quest template %u not found", iss.str().c_str(), questId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): quest template %u not found", iss.str().c_str(), questId); return false; } // Check delimiter @@ -225,13 +226,13 @@ bool QuestChatLink::Initialize(std::istringstream& iss) // Read quest level if (!ReadInt32(iss, _questLevel)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading quest level", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading quest level", iss.str().c_str()); return false; } // Validate quest level if (_questLevel >= STRONG_MAX_LEVEL) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): quest level %d is too big", iss.str().c_str(), _questLevel); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): quest level %d is too big", iss.str().c_str(), _questLevel); return false; } return true; @@ -251,7 +252,7 @@ bool QuestChatLink::ValidateName(char* buffer, const char* context) break; } if (!res) - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked quest (id: %u) title wasn't found in any localization", context, _quest->GetQuestId()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked quest (id: %u) title wasn't found in any localization", context, _quest->GetQuestId()); return res; } @@ -265,14 +266,14 @@ bool SpellChatLink::Initialize(std::istringstream& iss) uint32 spellId = 0; if (!ReadUInt32(iss, spellId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading spell entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading spell entry", iss.str().c_str()); return false; } // Validate spell _spell = sSpellMgr->GetSpellInfo(spellId); if (!_spell) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |spell command", iss.str().c_str(), spellId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |spell command", iss.str().c_str(), spellId); return false; } return true; @@ -288,19 +289,19 @@ bool SpellChatLink::ValidateName(char* buffer, const char* context) SkillLineAbilityMapBounds bounds = sSpellMgr->GetSkillLineAbilityMapBounds(_spell->Id); if (bounds.first == bounds.second) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line not found for spell %u", context, _spell->Id); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line not found for spell %u", context, _spell->Id); return false; } SkillLineAbilityEntry const* skillInfo = bounds.first->second; if (!skillInfo) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line ability not found for spell %u", context, _spell->Id); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line ability not found for spell %u", context, _spell->Id); return false; } SkillLineEntry const* skillLine = sSkillLineStore.LookupEntry(skillInfo->skillId); if (!skillLine) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line not found for skill %u", context, skillInfo->skillId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): skill line not found for skill %u", context, skillInfo->skillId); return false; } @@ -326,7 +327,7 @@ bool SpellChatLink::ValidateName(char* buffer, const char* context) } if (!res) - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked spell (id: %u) name wasn't found in any localization", context, _spell->Id); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked spell (id: %u) name wasn't found in any localization", context, _spell->Id); return res; } @@ -340,14 +341,14 @@ bool AchievementChatLink::Initialize(std::istringstream& iss) uint32 achievementId = 0; if (!ReadUInt32(iss, achievementId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement entry", iss.str().c_str()); return false; } // Validate achievement _achievement = sAchievementStore.LookupEntry(achievementId); if (!_achievement) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid achivement id %u in |achievement command", iss.str().c_str(), achievementId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid achivement id %u in |achievement command", iss.str().c_str(), achievementId); return false; } // Check delimiter @@ -356,7 +357,7 @@ bool AchievementChatLink::Initialize(std::istringstream& iss) // Read HEX if (!ReadHex(iss, _guid, 0)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid hexadecimal number while reading char's guid", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid hexadecimal number while reading char's guid", iss.str().c_str()); return false; } // Skip progress @@ -368,7 +369,7 @@ bool AchievementChatLink::Initialize(std::istringstream& iss) if (!ReadUInt32(iss, _data[index])) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement property (%u)", iss.str().c_str(), index); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement property (%u)", iss.str().c_str(), index); return false; } } @@ -388,7 +389,7 @@ bool AchievementChatLink::ValidateName(char* buffer, const char* context) } if (!res) - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked achievement (id: %u) name wasn't found in any localization", context, _achievement->ID); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): linked achievement (id: %u) name wasn't found in any localization", context, _achievement->ID); return res; } @@ -402,14 +403,14 @@ bool TradeChatLink::Initialize(std::istringstream& iss) uint32 spellId = 0; if (!ReadUInt32(iss, spellId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement entry", iss.str().c_str()); return false; } // Validate spell _spell = sSpellMgr->GetSpellInfo(spellId); if (!_spell) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |trade command", iss.str().c_str(), spellId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |trade command", iss.str().c_str(), spellId); return false; } // Check delimiter @@ -418,7 +419,7 @@ bool TradeChatLink::Initialize(std::istringstream& iss) // Minimum talent level if (!ReadInt32(iss, _minSkillLevel)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading minimum talent level", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading minimum talent level", iss.str().c_str()); return false; } // Check delimiter @@ -427,7 +428,7 @@ bool TradeChatLink::Initialize(std::istringstream& iss) // Maximum talent level if (!ReadInt32(iss, _maxSkillLevel)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading maximum talent level", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading maximum talent level", iss.str().c_str()); return false; } // Check delimiter @@ -436,7 +437,7 @@ bool TradeChatLink::Initialize(std::istringstream& iss) // Something hexadecimal if (!ReadHex(iss, _guid, 0)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement's owner guid", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading achievement's owner guid", iss.str().c_str()); return false; } // Skip base64 encoded stuff @@ -453,21 +454,21 @@ bool TalentChatLink::Initialize(std::istringstream& iss) // Read talent entry if (!ReadUInt32(iss, _talentId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading talent entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading talent entry", iss.str().c_str()); return false; } // Validate talent TalentEntry const* talentInfo = sTalentStore.LookupEntry(_talentId); if (!talentInfo) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid talent id %u in |talent command", iss.str().c_str(), _talentId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid talent id %u in |talent command", iss.str().c_str(), _talentId); return false; } // Validate talent's spell _spell = sSpellMgr->GetSpellInfo(talentInfo->RankID[0]); if (!_spell) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |trade command", iss.str().c_str(), talentInfo->RankID[0]); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |trade command", iss.str().c_str(), talentInfo->RankID[0]); return false; } // Delimiter @@ -476,7 +477,7 @@ bool TalentChatLink::Initialize(std::istringstream& iss) // Rank if (!ReadInt32(iss, _rankId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading talent rank", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading talent rank", iss.str().c_str()); return false; } return true; @@ -492,14 +493,14 @@ bool EnchantmentChatLink::Initialize(std::istringstream& iss) uint32 spellId = 0; if (!ReadUInt32(iss, spellId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading enchantment spell entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading enchantment spell entry", iss.str().c_str()); return false; } // Validate spell _spell = sSpellMgr->GetSpellInfo(spellId); if (!_spell) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |enchant command", iss.str().c_str(), spellId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |enchant command", iss.str().c_str(), spellId); return false; } return true; @@ -514,7 +515,7 @@ bool GlyphChatLink::Initialize(std::istringstream& iss) // Slot if (!ReadUInt32(iss, _slotId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading slot id", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading slot id", iss.str().c_str()); return false; } // Check delimiter @@ -524,21 +525,21 @@ bool GlyphChatLink::Initialize(std::istringstream& iss) uint32 glyphId = 0; if (!ReadUInt32(iss, glyphId)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading glyph entry", iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly while reading glyph entry", iss.str().c_str()); return false; } // Validate glyph _glyph = sGlyphPropertiesStore.LookupEntry(glyphId); if (!_glyph) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid glyph id %u in |glyph command", iss.str().c_str(), glyphId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid glyph id %u in |glyph command", iss.str().c_str(), glyphId); return false; } // Validate glyph's spell _spell = sSpellMgr->GetSpellInfo(_glyph->SpellId); if (!_spell) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |glyph command", iss.str().c_str(), _glyph->SpellId); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid spell id %u in |glyph command", iss.str().c_str(), _glyph->SpellId); return false; } return true; @@ -576,14 +577,14 @@ bool LinkExtractor::IsValidMessage() } else if (_iss.get() != PIPE_CHAR) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence aborted unexpectedly", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence aborted unexpectedly", _iss.str().c_str()); return false; } // pipe has always to be followed by at least one char if (_iss.peek() == '\0') { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): pipe followed by '\\0'", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): pipe followed by '\\0'", _iss.str().c_str()); return false; } @@ -606,14 +607,14 @@ bool LinkExtractor::IsValidMessage() } else { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid sequence, expected '%c' but got '%c'", _iss.str().c_str(), *validSequenceIterator, commandChar); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid sequence, expected '%c' but got '%c'", _iss.str().c_str(), *validSequenceIterator, commandChar); return false; } } else if (validSequence != validSequenceIterator) { // no escaped pipes in sequences - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got escaped pipe in sequence", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got escaped pipe in sequence", _iss.str().c_str()); return false; } @@ -622,7 +623,7 @@ bool LinkExtractor::IsValidMessage() case 'c': if (!ReadHex(_iss, color, 8)) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid hexadecimal number while reading color", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): invalid hexadecimal number while reading color", _iss.str().c_str()); return false; } break; @@ -631,7 +632,7 @@ bool LinkExtractor::IsValidMessage() _iss.getline(buffer, 256, DELIMITER); if (_iss.eof()) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly", _iss.str().c_str()); return false; } @@ -653,7 +654,7 @@ bool LinkExtractor::IsValidMessage() link = new GlyphChatLink(); else { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): user sent unsupported link type '%s'", _iss.str().c_str(), buffer); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): user sent unsupported link type '%s'", _iss.str().c_str(), buffer); return false; } _links.push_back(link); @@ -668,13 +669,13 @@ bool LinkExtractor::IsValidMessage() // links start with '[' if (_iss.get() != '[') { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): link caption doesn't start with '['", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): link caption doesn't start with '['", _iss.str().c_str()); return false; } _iss.getline(buffer, 256, ']'); if (_iss.eof()) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): sequence finished unexpectedly", _iss.str().c_str()); return false; } @@ -692,7 +693,7 @@ bool LinkExtractor::IsValidMessage() // no further payload break; default: - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid command |%c", _iss.str().c_str(), commandChar); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): got invalid command |%c", _iss.str().c_str(), commandChar); return false; } } @@ -700,7 +701,7 @@ bool LinkExtractor::IsValidMessage() // check if every opened sequence was also closed properly if (validSequence != validSequenceIterator) { - sLog->outDebug(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): EOF in active sequence", _iss.str().c_str()); + sLog->outTrace(LOG_FILTER_CHATSYS, "ChatHandler::isValidChatMessage('%s'): EOF in active sequence", _iss.str().c_str()); return false; } diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp index 72f00406c69..2f3cb0fbaaf 100755 --- a/src/server/game/Conditions/ConditionMgr.cpp +++ b/src/server/game/Conditions/ConditionMgr.cpp @@ -16,15 +16,16 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Player.h" -#include "SpellAuras.h" -#include "SpellMgr.h" +#include "ConditionMgr.h" #include "GameEventMgr.h" -#include "ObjectMgr.h" #include "InstanceScript.h" -#include "ConditionMgr.h" -#include "ScriptMgr.h" +#include "ObjectMgr.h" +#include "Player.h" +#include "ReputationMgr.h" #include "ScriptedCreature.h" +#include "ScriptMgr.h" +#include "SpellAuras.h" +#include "SpellMgr.h" #include "Spell.h" // Checks if object meets the condition diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h index 57af0562dcd..7b0dc1f20bf 100755 --- a/src/server/game/Conditions/ConditionMgr.h +++ b/src/server/game/Conditions/ConditionMgr.h @@ -19,8 +19,11 @@ #ifndef TRINITY_CONDITIONMGR_H #define TRINITY_CONDITIONMGR_H -#include "LootMgr.h" +#include "Define.h" +#include "Errors.h" #include <ace/Singleton.h> +#include <list> +#include <map> class Player; class Unit; diff --git a/src/server/game/Conditions/DisableMgr.cpp b/src/server/game/Conditions/DisableMgr.cpp index a209d9b6cf6..cc23036c534 100755 --- a/src/server/game/Conditions/DisableMgr.cpp +++ b/src/server/game/Conditions/DisableMgr.cpp @@ -21,6 +21,7 @@ #include "OutdoorPvP.h" #include "SpellMgr.h" #include "VMapManager2.h" +#include "Player.h" namespace DisableMgr { diff --git a/src/server/game/DataStores/DBCEnums.h b/src/server/game/DataStores/DBCEnums.h index 12ec7206141..4fa2e3e748e 100755 --- a/src/server/game/DataStores/DBCEnums.h +++ b/src/server/game/DataStores/DBCEnums.h @@ -19,18 +19,21 @@ #ifndef DBCENUMS_H #define DBCENUMS_H -// Client expected level limitation, like as used in DBC item max levels for "until max player level" -// use as default max player level, must be fit max level for used client -// also see MAX_LEVEL and STRONG_MAX_LEVEL define -#define DEFAULT_MAX_LEVEL 80 - -// client supported max level for player/pets/etc. Avoid overflow or client stability affected. -// also see GT_MAX_LEVEL define -#define MAX_LEVEL 100 - -// Server side limitation. Base at used code requirements. -// also see MAX_LEVEL and GT_MAX_LEVEL define -#define STRONG_MAX_LEVEL 255 +enum LevelLimit +{ + // Client expected level limitation, like as used in DBC item max levels for "until max player level" + // use as default max player level, must be fit max level for used client + // also see MAX_LEVEL and STRONG_MAX_LEVEL define + DEFAULT_MAX_LEVEL = 80, + + // client supported max level for player/pets/etc. Avoid overflow or client stability affected. + // also see GT_MAX_LEVEL define + MAX_LEVEL = 100, + + // Server side limitation. Base at used code requirements. + // also see MAX_LEVEL and GT_MAX_LEVEL define + STRONG_MAX_LEVEL = 255, +}; enum BattlegroundBracketId // bracketId for level ranges { @@ -58,16 +61,16 @@ enum AchievementFaction enum AchievementFlags { - ACHIEVEMENT_FLAG_COUNTER = 0x00000001, // Just count statistic (never stop and complete) - ACHIEVEMENT_FLAG_HIDDEN = 0x00000002, // Not sent to client - internal use only - ACHIEVEMENT_FLAG_STORE_MAX_VALUE = 0x00000004, // Store only max value? used only in "Reach level xx" - ACHIEVEMENT_FLAG_SUMM = 0x00000008, // Use summ criteria value from all reqirements (and calculate max value) - ACHIEVEMENT_FLAG_MAX_USED = 0x00000010, // Show max criteria (and calculate max value ??) - ACHIEVEMENT_FLAG_REQ_COUNT = 0x00000020, // Use not zero req count (and calculate max value) - ACHIEVEMENT_FLAG_AVERAGE = 0x00000040, // Show as average value (value / time_in_days) depend from other flag (by def use last criteria value) - ACHIEVEMENT_FLAG_BAR = 0x00000080, // Show as progress bar (value / max vale) depend from other flag (by def use last criteria value) - ACHIEVEMENT_FLAG_REALM_FIRST_REACH = 0x00000100, // - ACHIEVEMENT_FLAG_REALM_FIRST_KILL = 0x00000200 // + ACHIEVEMENT_FLAG_COUNTER = 0x00000001, // Just count statistic (never stop and complete) + ACHIEVEMENT_FLAG_HIDDEN = 0x00000002, // Not sent to client - internal use only + ACHIEVEMENT_FLAG_STORE_MAX_VALUE = 0x00000004, // Store only max value? used only in "Reach level xx" + ACHIEVEMENT_FLAG_SUMM = 0x00000008, // Use summ criteria value from all requirements (and calculate max value) + ACHIEVEMENT_FLAG_MAX_USED = 0x00000010, // Show max criteria (and calculate max value ??) + ACHIEVEMENT_FLAG_REQ_COUNT = 0x00000020, // Use not zero req count (and calculate max value) + ACHIEVEMENT_FLAG_AVERAGE = 0x00000040, // Show as average value (value / time_in_days) depend from other flag (by def use last criteria value) + ACHIEVEMENT_FLAG_BAR = 0x00000080, // Show as progress bar (value / max vale) depend from other flag (by def use last criteria value) + ACHIEVEMENT_FLAG_REALM_FIRST_REACH = 0x00000100, // + ACHIEVEMENT_FLAG_REALM_FIRST_KILL = 0x00000200 // }; #define MAX_CRITERIA_REQUIREMENTS 2 @@ -108,124 +111,117 @@ enum AchievementCriteriaTimedTypes enum AchievementCriteriaTypes { - ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE = 0, - ACHIEVEMENT_CRITERIA_TYPE_WIN_BG = 1, - ACHIEVEMENT_CRITERIA_TYPE_REACH_LEVEL = 5, - ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL = 7, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT = 8, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT = 9, - // you have to complete a daily quest x times in a row - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST_DAILY = 10, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE = 11, - ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE = 13, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST = 14, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND= 15, - ACHIEVEMENT_CRITERIA_TYPE_DEATH_AT_MAP= 16, - ACHIEVEMENT_CRITERIA_TYPE_DEATH= 17, - ACHIEVEMENT_CRITERIA_TYPE_DEATH_IN_DUNGEON = 18, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_RAID = 19, - ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE = 20, - ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER = 23, - ACHIEVEMENT_CRITERIA_TYPE_FALL_WITHOUT_DYING = 24, - ACHIEVEMENT_CRITERIA_TYPE_DEATHS_FROM = 26, - ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST = 27, - ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET = 28, - ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL= 29, - ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE = 30, - ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA = 31, - ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA = 32, - ACHIEVEMENT_CRITERIA_TYPE_PLAY_ARENA = 33, - ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL = 34, - ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL = 35, - ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM = 36, - // TODO: the archievements 1162 and 1163 requires a special rating which can't be found in the dbc - ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA = 37, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING = 38, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_PERSONAL_RATING = 39, - ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL = 40, - ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM = 41, - ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM= 42, - ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA = 43, - ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK= 44, - ACHIEVEMENT_CRITERIA_TYPE_BUY_BANK_SLOT= 45, - ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION= 46, - ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION= 47, - // noted: rewarded as soon as the player payed, not at taking place at the seat - ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP= 48, - ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM = 49, - // TODO: itemlevel is mentioned in text but not present in dbc - ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT = 50, - ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT= 51, - ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS = 52, - ACHIEVEMENT_CRITERIA_TYPE_HK_RACE = 53, - ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE = 54, - ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE = 55, - // TODO: in some cases map not present, and in some cases need do without die - ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS = 56, - ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM = 57, - ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_VENDORS = 59, - ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TALENTS = 60, - ACHIEVEMENT_CRITERIA_TYPE_NUMBER_OF_TALENT_RESETS = 61, - ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_QUEST_REWARD = 62, - ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING = 63, - ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_AT_BARBER = 65, - ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_MAIL = 66, - ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY = 67, - ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT = 68, - ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2= 69, - ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL= 70, - ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT = 72, - // TODO: title id is not mentioned in dbc - ACHIEVEMENT_CRITERIA_TYPE_EARNED_PVP_TITLE = 74, - ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS= 75, - ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL = 76, - ACHIEVEMENT_CRITERIA_TYPE_LOSE_DUEL = 77, - // TODO: creature type (demon, undead etc.) is not stored in dbc - ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE = 78, - ACHIEVEMENT_CRITERIA_TYPE_GOLD_EARNED_BY_AUCTIONS= 80, - ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION= 82, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID= 83, - ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS= 84, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD = 85, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_GOLD_VALUE_OWNED = 86, - ACHIEVEMENT_CRITERIA_TYPE_GAIN_REVERED_REPUTATION = 87, - ACHIEVEMENT_CRITERIA_TYPE_GAIN_HONORED_REPUTATION = 88, - ACHIEVEMENT_CRITERIA_TYPE_KNOWN_FACTIONS = 89, - ACHIEVEMENT_CRITERIA_TYPE_LOOT_EPIC_ITEM = 90, - ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM = 91, - ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED = 93, - ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED = 94, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALTH = 95, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_POWER = 96, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_STAT = 97, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_SPELLPOWER = 98, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_ARMOR = 99, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_RATING = 100, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT = 101, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED = 102, - ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED = 103, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED = 104, - ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED = 105, - ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED = 106, - ACHIEVEMENT_CRITERIA_TYPE_QUEST_ABANDONED = 107, - ACHIEVEMENT_CRITERIA_TYPE_FLIGHT_PATHS_TAKEN = 108, - ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE = 109, - // TODO: target entry is missing - ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2 = 110, - ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE= 112, - ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL = 113, - ACHIEVEMENT_CRITERIA_TYPE_ACCEPTED_SUMMONINGS = 114, - // 0..115 => 116 criteria types total - ACHIEVEMENT_CRITERIA_TYPE_EARN_ACHIEVEMENT_POINTS = 115, + ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE = 0, + ACHIEVEMENT_CRITERIA_TYPE_WIN_BG = 1, + ACHIEVEMENT_CRITERIA_TYPE_REACH_LEVEL = 5, + ACHIEVEMENT_CRITERIA_TYPE_REACH_SKILL_LEVEL = 7, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_ACHIEVEMENT = 8, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST_COUNT = 9, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST_DAILY = 10, // you have to complete a daily quest x times in a row + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUESTS_IN_ZONE = 11, + ACHIEVEMENT_CRITERIA_TYPE_DAMAGE_DONE = 13, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_DAILY_QUEST = 14, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_BATTLEGROUND = 15, + ACHIEVEMENT_CRITERIA_TYPE_DEATH_AT_MAP = 16, + ACHIEVEMENT_CRITERIA_TYPE_DEATH = 17, + ACHIEVEMENT_CRITERIA_TYPE_DEATH_IN_DUNGEON = 18, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_RAID = 19, + ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_CREATURE = 20, + ACHIEVEMENT_CRITERIA_TYPE_KILLED_BY_PLAYER = 23, + ACHIEVEMENT_CRITERIA_TYPE_FALL_WITHOUT_DYING = 24, + ACHIEVEMENT_CRITERIA_TYPE_DEATHS_FROM = 26, + ACHIEVEMENT_CRITERIA_TYPE_COMPLETE_QUEST = 27, + ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET = 28, + ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL = 29, + ACHIEVEMENT_CRITERIA_TYPE_BG_OBJECTIVE_CAPTURE = 30, + ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL_AT_AREA = 31, + ACHIEVEMENT_CRITERIA_TYPE_WIN_ARENA = 32, + ACHIEVEMENT_CRITERIA_TYPE_PLAY_ARENA = 33, + ACHIEVEMENT_CRITERIA_TYPE_LEARN_SPELL = 34, + ACHIEVEMENT_CRITERIA_TYPE_HONORABLE_KILL = 35, + ACHIEVEMENT_CRITERIA_TYPE_OWN_ITEM = 36, + ACHIEVEMENT_CRITERIA_TYPE_WIN_RATED_ARENA = 37, // TODO: the archievements 1162 and 1163 requires a special rating which can't be found in the dbc + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_TEAM_RATING = 38, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_PERSONAL_RATING = 39, + ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LEVEL = 40, + ACHIEVEMENT_CRITERIA_TYPE_USE_ITEM = 41, + ACHIEVEMENT_CRITERIA_TYPE_LOOT_ITEM = 42, + ACHIEVEMENT_CRITERIA_TYPE_EXPLORE_AREA = 43, + ACHIEVEMENT_CRITERIA_TYPE_OWN_RANK = 44, + ACHIEVEMENT_CRITERIA_TYPE_BUY_BANK_SLOT = 45, + ACHIEVEMENT_CRITERIA_TYPE_GAIN_REPUTATION = 46, + ACHIEVEMENT_CRITERIA_TYPE_GAIN_EXALTED_REPUTATION = 47, + ACHIEVEMENT_CRITERIA_TYPE_VISIT_BARBER_SHOP = 48, + ACHIEVEMENT_CRITERIA_TYPE_EQUIP_EPIC_ITEM = 49, + ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED_ON_LOOT = 50, // TODO: itemlevel is mentioned in text but not present in dbc + ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED_ON_LOOT = 51, + ACHIEVEMENT_CRITERIA_TYPE_HK_CLASS = 52, + ACHIEVEMENT_CRITERIA_TYPE_HK_RACE = 53, + ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE = 54, + ACHIEVEMENT_CRITERIA_TYPE_HEALING_DONE = 55, + ACHIEVEMENT_CRITERIA_TYPE_GET_KILLING_BLOWS = 56, // TODO: in some cases map not present, and in some cases need do without die + ACHIEVEMENT_CRITERIA_TYPE_EQUIP_ITEM = 57, + ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_VENDORS = 59, + ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TALENTS = 60, + ACHIEVEMENT_CRITERIA_TYPE_NUMBER_OF_TALENT_RESETS = 61, + ACHIEVEMENT_CRITERIA_TYPE_MONEY_FROM_QUEST_REWARD = 62, + ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_TRAVELLING = 63, + ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_AT_BARBER = 65, + ACHIEVEMENT_CRITERIA_TYPE_GOLD_SPENT_FOR_MAIL = 66, + ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY = 67, + ACHIEVEMENT_CRITERIA_TYPE_USE_GAMEOBJECT = 68, + ACHIEVEMENT_CRITERIA_TYPE_BE_SPELL_TARGET2 = 69, + ACHIEVEMENT_CRITERIA_TYPE_SPECIAL_PVP_KILL = 70, + ACHIEVEMENT_CRITERIA_TYPE_FISH_IN_GAMEOBJECT = 72, + // TODO 73: Achievements 1515, 1241, 1103 (Name: Mal'Ganis) + ACHIEVEMENT_CRITERIA_TYPE_EARNED_PVP_TITLE = 74, // TODO: title id is not mentioned in dbc + ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILLLINE_SPELLS = 75, + ACHIEVEMENT_CRITERIA_TYPE_WIN_DUEL = 76, + ACHIEVEMENT_CRITERIA_TYPE_LOSE_DUEL = 77, + ACHIEVEMENT_CRITERIA_TYPE_KILL_CREATURE_TYPE = 78, + ACHIEVEMENT_CRITERIA_TYPE_GOLD_EARNED_BY_AUCTIONS = 80, + ACHIEVEMENT_CRITERIA_TYPE_CREATE_AUCTION = 82, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_BID = 83, + ACHIEVEMENT_CRITERIA_TYPE_WON_AUCTIONS = 84, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_AUCTION_SOLD = 85, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_GOLD_VALUE_OWNED = 86, + ACHIEVEMENT_CRITERIA_TYPE_GAIN_REVERED_REPUTATION = 87, + ACHIEVEMENT_CRITERIA_TYPE_GAIN_HONORED_REPUTATION = 88, + ACHIEVEMENT_CRITERIA_TYPE_KNOWN_FACTIONS = 89, + ACHIEVEMENT_CRITERIA_TYPE_LOOT_EPIC_ITEM = 90, + ACHIEVEMENT_CRITERIA_TYPE_RECEIVE_EPIC_ITEM = 91, + ACHIEVEMENT_CRITERIA_TYPE_ROLL_NEED = 93, + ACHIEVEMENT_CRITERIA_TYPE_ROLL_GREED = 94, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALTH = 95, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_POWER = 96, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_STAT = 97, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_SPELLPOWER = 98, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_ARMOR = 99, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_RATING = 100, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_DEALT = 101, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HIT_RECEIVED = 102, + ACHIEVEMENT_CRITERIA_TYPE_TOTAL_DAMAGE_RECEIVED = 103, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEAL_CASTED = 104, + ACHIEVEMENT_CRITERIA_TYPE_TOTAL_HEALING_RECEIVED = 105, + ACHIEVEMENT_CRITERIA_TYPE_HIGHEST_HEALING_RECEIVED = 106, + ACHIEVEMENT_CRITERIA_TYPE_QUEST_ABANDONED = 107, + ACHIEVEMENT_CRITERIA_TYPE_FLIGHT_PATHS_TAKEN = 108, + ACHIEVEMENT_CRITERIA_TYPE_LOOT_TYPE = 109, + ACHIEVEMENT_CRITERIA_TYPE_CAST_SPELL2 = 110, // TODO: target entry is missing + ACHIEVEMENT_CRITERIA_TYPE_LEARN_SKILL_LINE = 112, + ACHIEVEMENT_CRITERIA_TYPE_EARN_HONORABLE_KILL = 113, + ACHIEVEMENT_CRITERIA_TYPE_ACCEPTED_SUMMONINGS = 114, + ACHIEVEMENT_CRITERIA_TYPE_EARN_ACHIEVEMENT_POINTS = 115, ACHIEVEMENT_CRITERIA_TYPE_USE_LFD_TO_GROUP_WITH_PLAYERS = 119, // 120 // 121 // 122 // 123 // 0..123 => 124 criteria types total - ACHIEVEMENT_CRITERIA_TYPE_TOTAL = 124 }; +#define ACHIEVEMENT_CRITERIA_TYPE_TOTAL 124 + enum AchievementCategory { CATEGORY_CHILDRENS_WEEK = 163 @@ -286,7 +282,7 @@ enum Difficulty enum SpawnMask { - SPAWNMASK_CONTINENT = (1 << REGULAR_DIFFICULTY), // any any maps without spawn modes + SPAWNMASK_CONTINENT = (1 << REGULAR_DIFFICULTY), // any maps without spawn modes SPAWNMASK_DUNGEON_NORMAL = (1 << DUNGEON_DIFFICULTY_NORMAL), SPAWNMASK_DUNGEON_HEROIC = (1 << DUNGEON_DIFFICULTY_HEROIC), @@ -349,19 +345,19 @@ enum ItemEnchantmentType enum ItemLimitCategoryMode { - ITEM_LIMIT_CATEGORY_MODE_HAVE = 0, // limit applied to amount items in inventory/bank - ITEM_LIMIT_CATEGORY_MODE_EQUIP = 1 // limit applied to amount equipped items (including used gems) + ITEM_LIMIT_CATEGORY_MODE_HAVE = 0, // limit applied to amount items in inventory/bank + ITEM_LIMIT_CATEGORY_MODE_EQUIP = 1 // limit applied to amount equipped items (including used gems) }; enum TotemCategoryType { - TOTEM_CATEGORY_TYPE_KNIFE = 1, - TOTEM_CATEGORY_TYPE_TOTEM = 2, - TOTEM_CATEGORY_TYPE_ROD = 3, - TOTEM_CATEGORY_TYPE_PICK = 21, - TOTEM_CATEGORY_TYPE_STONE = 22, - TOTEM_CATEGORY_TYPE_HAMMER = 23, - TOTEM_CATEGORY_TYPE_SPANNER = 24 + TOTEM_CATEGORY_TYPE_KNIFE = 1, + TOTEM_CATEGORY_TYPE_TOTEM = 2, + TOTEM_CATEGORY_TYPE_ROD = 3, + TOTEM_CATEGORY_TYPE_PICK = 21, + TOTEM_CATEGORY_TYPE_STONE = 22, + TOTEM_CATEGORY_TYPE_HAMMER = 23, + TOTEM_CATEGORY_TYPE_SPANNER = 24 }; // SummonProperties.dbc, col 1 diff --git a/src/server/game/DungeonFinding/LFG.h b/src/server/game/DungeonFinding/LFG.h index 6ad30547670..8477002279c 100755 --- a/src/server/game/DungeonFinding/LFG.h +++ b/src/server/game/DungeonFinding/LFG.h @@ -41,7 +41,7 @@ enum LfgUpdateType LFG_UPDATETYPE_DEFAULT = 0, // Internal Use LFG_UPDATETYPE_LEADER_UNK1 = 1, // FIXME: At group leave LFG_UPDATETYPE_ROLECHECK_ABORTED = 4, - LFG_UPDATETYPE_JOIN_PROPOSAL = 5, + LFG_UPDATETYPE_JOIN_QUEUE = 5, LFG_UPDATETYPE_ROLECHECK_FAILED = 6, LFG_UPDATETYPE_REMOVED_FROM_QUEUE = 7, LFG_UPDATETYPE_PROPOSAL_FAILED = 8, diff --git a/src/server/game/DungeonFinding/LFGGroupData.cpp b/src/server/game/DungeonFinding/LFGGroupData.cpp index a4ee230b5eb..c7cf6f23ce9 100644 --- a/src/server/game/DungeonFinding/LFGGroupData.cpp +++ b/src/server/game/DungeonFinding/LFGGroupData.cpp @@ -37,7 +37,7 @@ void LfgGroupData::SetState(LfgState state) case LFG_STATE_FINISHED_DUNGEON: case LFG_STATE_NONE: case LFG_STATE_DUNGEON: - m_OldState = state; + m_OldState = m_State; // No break on purpose default: m_State = state; diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp index c91be00080e..da279016255 100755 --- a/src/server/game/DungeonFinding/LFGMgr.cpp +++ b/src/server/game/DungeonFinding/LFGMgr.cpp @@ -21,6 +21,7 @@ #include "DisableMgr.h" #include "ObjectMgr.h" #include "SocialMgr.h" +#include "Language.h" #include "LFGMgr.h" #include "LFGScripts.h" #include "LFGGroupData.h" @@ -30,6 +31,7 @@ #include "Player.h" #include "GroupMgr.h" #include "GameEventMgr.h" +#include "WorldSession.h" LFGMgr::LFGMgr(): m_QueueTimer(0), m_lfgProposalId(1), m_options(sWorld->getIntConfig(CONFIG_LFG_OPTIONSMASK)) @@ -551,14 +553,17 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const LfgDungeonSet const& playerDungeons = GetSelectedDungeons(guid); if (playerDungeons == dungeons) // Joining the same dungeons -- Send OK { - LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ADDED_TO_QUEUE, dungeons, comment); player->GetSession()->SendLfgJoinResult(joinData); // Default value of joinData.result = LFG_JOIN_OK if (grp) { + LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_ADDED_TO_QUEUE, dungeons, comment); for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) if (itr->getSource() && itr->getSource()->GetSession()) itr->getSource()->GetSession()->SendLfgUpdateParty(updateData); } + else + player->GetSession()->SendLfgUpdatePlayer(LfgUpdateData(LFG_UPDATETYPE_JOIN_QUEUE, dungeons, comment)); + return; } else // Remove from queue and rejoin @@ -689,7 +694,7 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const SetState(gguid, LFG_STATE_ROLECHECK); // Send update to player - LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_JOIN_PROPOSAL, dungeons, comment); + LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_JOIN_QUEUE, dungeons, comment); for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next()) { if (Player* plrg = itr->getSource()) @@ -726,7 +731,7 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const } // Send update to player player->GetSession()->SendLfgJoinResult(joinData); - player->GetSession()->SendLfgUpdatePlayer(LfgUpdateData(LFG_UPDATETYPE_JOIN_PROPOSAL, dungeons, comment)); + player->GetSession()->SendLfgUpdatePlayer(LfgUpdateData(LFG_UPDATETYPE_JOIN_QUEUE, dungeons, comment)); SetState(gguid, LFG_STATE_QUEUED); SetRoles(guid, roles); debugNames.append(player->GetName()); @@ -749,10 +754,10 @@ void LFGMgr::JoinLfg(Player* player, uint8 roles, LfgDungeonSet& dungeons, const */ void LFGMgr::LeaveLfg(uint64 guid) { - LfgState state = GetState(guid); - uint64 gguid = IS_GROUP(guid) ? guid : GetGroup(guid); - sLog->outDebug(LOG_FILTER_LFG, "LFGMgr::Leave: [" UI64FMTD "]", guid); + + uint64 gguid = IS_GROUP(guid) ? guid : GetGroup(guid); + LfgState state = GetState(guid); switch (state) { case LFG_STATE_QUEUED: @@ -1962,11 +1967,10 @@ void LFGMgr::SetOptions(uint32 options) m_options = options; } -LfgState LFGMgr::GetLfgStatus(uint64 guid, LfgUpdateData& data) +LfgUpdateData LFGMgr::GetLfgStatus(uint64 guid) { LfgPlayerData& playerData = PlayersStore[guid]; - data.dungeons = playerData.GetSelectedDungeons(); - return playerData.GetState(); + return LfgUpdateData(LFG_UPDATETYPE_UPDATE_STATUS, playerData.GetState(), playerData.GetSelectedDungeons()); } bool LFGMgr::IsSeasonActive(uint32 dungeonId) diff --git a/src/server/game/DungeonFinding/LFGMgr.h b/src/server/game/DungeonFinding/LFGMgr.h index ba1cc251278..9c023d1daf8 100755 --- a/src/server/game/DungeonFinding/LFGMgr.h +++ b/src/server/game/DungeonFinding/LFGMgr.h @@ -18,8 +18,9 @@ #ifndef _LFGMGR_H #define _LFGMGR_H -#include "Common.h" #include <ace/Singleton.h> +#include "DBCStructure.h" +#include "Field.h" #include "LFG.h" #include "LFGQueue.h" #include "LFGGroupData.h" @@ -155,11 +156,14 @@ struct LfgJoinResultData // Data needed by SMSG_LFG_UPDATE_PARTY and SMSG_LFG_UPDATE_PLAYER struct LfgUpdateData { - LfgUpdateData(LfgUpdateType _type = LFG_UPDATETYPE_DEFAULT): updateType(_type), comment("") {} + LfgUpdateData(LfgUpdateType _type = LFG_UPDATETYPE_DEFAULT): updateType(_type), state(LFG_STATE_NONE), comment("") { } LfgUpdateData(LfgUpdateType _type, LfgDungeonSet const& _dungeons, std::string const& _comment): - updateType(_type), dungeons(_dungeons), comment(_comment) {} + updateType(_type), state(LFG_STATE_NONE), dungeons(_dungeons), comment(_comment) { } + LfgUpdateData(LfgUpdateType _type, LfgState _state, LfgDungeonSet const& _dungeons, std::string const& _comment = ""): + updateType(_type), state(_state), dungeons(_dungeons), comment(_comment) { } LfgUpdateType updateType; + LfgState state; LfgDungeonSet dungeons; std::string comment; }; @@ -361,7 +365,7 @@ class LFGMgr bool isOptionEnabled(uint32 option); uint32 GetOptions(); void SetOptions(uint32 options); - LfgState GetLfgStatus(uint64 guid, LfgUpdateData& data); + LfgUpdateData GetLfgStatus(uint64 guid); bool IsSeasonActive(uint32 dungeonId); std::string DumpQueueInfo(bool full = false); diff --git a/src/server/game/DungeonFinding/LFGPlayerData.cpp b/src/server/game/DungeonFinding/LFGPlayerData.cpp index e5645f0f0aa..f1281875598 100644 --- a/src/server/game/DungeonFinding/LFGPlayerData.cpp +++ b/src/server/game/DungeonFinding/LFGPlayerData.cpp @@ -35,7 +35,7 @@ void LfgPlayerData::SetState(LfgState state) m_SelectedDungeons.clear(); // No break on purpose case LFG_STATE_DUNGEON: - m_OldState = state; + m_OldState = m_State; // No break on purpose default: m_State = state; diff --git a/src/server/game/DungeonFinding/LFGQueue.cpp b/src/server/game/DungeonFinding/LFGQueue.cpp index cf600b0645f..3bcd1ee5643 100644 --- a/src/server/game/DungeonFinding/LFGQueue.cpp +++ b/src/server/game/DungeonFinding/LFGQueue.cpp @@ -639,7 +639,7 @@ void LFGQueue::FindBestCompatibleInQueue(LfgQueueDataContainer::iterator itrQueu std::string sguid = o.str(); for (LfgCompatibleContainer::const_iterator itr = CompatibleMapStore.begin(); itr != CompatibleMapStore.end(); ++itr) - if (itr->second.compatibility == LFG_COMPATIBLES_WITH_LESS_PLAYERS && + if (itr->second.compatibility == LFG_COMPATIBLES_WITH_LESS_PLAYERS && std::string::npos != itr->first.find(sguid)) { UpdateBestCompatibleInQueue(itrQueue, itr->first, itr->second.roles); @@ -650,7 +650,7 @@ void LFGQueue::UpdateBestCompatibleInQueue(LfgQueueDataContainer::iterator itrQu { LfgQueueData& queueData = itrQueue->second; - uint8 storedSize = queueData.bestCompatible.empty() ? 0 : + uint8 storedSize = queueData.bestCompatible.empty() ? 0 : std::count(queueData.bestCompatible.begin(), queueData.bestCompatible.end(), '|') + 1; uint8 size = std::count(key.begin(), key.end(), '|') + 1; diff --git a/src/server/game/DungeonFinding/LFGQueue.h b/src/server/game/DungeonFinding/LFGQueue.h index f937ac0d21a..e6ba038a9e6 100644 --- a/src/server/game/DungeonFinding/LFGQueue.h +++ b/src/server/game/DungeonFinding/LFGQueue.h @@ -42,7 +42,7 @@ struct LfgCompatibilityData compatibility(_compatibility), roles(_roles) { } LfgCompatibility compatibility; - LfgRolesMap roles; + LfgRolesMap roles; }; /// Stores player or group queue info diff --git a/src/server/game/DungeonFinding/LFGScripts.cpp b/src/server/game/DungeonFinding/LFGScripts.cpp index 91314e64285..f9e3c02fe98 100644 --- a/src/server/game/DungeonFinding/LFGScripts.cpp +++ b/src/server/game/DungeonFinding/LFGScripts.cpp @@ -27,6 +27,7 @@ #include "LFGMgr.h" #include "ScriptMgr.h" #include "ObjectAccessor.h" +#include "WorldSession.h" LFGPlayerScript::LFGPlayerScript() : PlayerScript("LFGPlayerScript") { @@ -45,14 +46,11 @@ void LFGPlayerScript::OnLogout(Player* player) if (!sLFGMgr->isOptionEnabled(LFG_OPTION_ENABLE_DUNGEON_FINDER | LFG_OPTION_ENABLE_RAID_BROWSER)) return; - uint64 guid = player->GetGUID(); - sLFGMgr->LeaveLfg(guid); - LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_REMOVED_FROM_QUEUE); - player->GetSession()->SendLfgUpdateParty(updateData); - player->GetSession()->SendLfgUpdatePlayer(updateData); - player->GetSession()->SendLfgLfrList(false); - // TODO - Do not remove, add timer before deleting - sLFGMgr->RemovePlayerData(guid); + if (!player->GetGroup()) + { + player->GetSession()->SendLfgLfrList(false); + sLFGMgr->LeaveLfg(player->GetGUID()); + } } void LFGPlayerScript::OnLogin(Player* player) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 9bcd4d9c1e2..911ccd25728 100755 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -16,40 +16,42 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "BattlegroundMgr.h" +#include "CellImpl.h" #include "Common.h" -#include "DatabaseEnv.h" -#include "WorldPacket.h" -#include "World.h" -#include "ObjectMgr.h" -#include "GroupMgr.h" -#include "SpellMgr.h" -#include "Creature.h" -#include "QuestDef.h" -#include "GossipDef.h" -#include "Player.h" -#include "PoolMgr.h" -#include "Opcodes.h" -#include "Log.h" -#include "LootMgr.h" -#include "MapManager.h" #include "CreatureAI.h" #include "CreatureAISelector.h" +#include "CreatureGroups.h" +#include "Creature.h" +#include "DatabaseEnv.h" #include "Formulas.h" -#include "WaypointMovementGenerator.h" -#include "InstanceScript.h" -#include "BattlegroundMgr.h" -#include "Util.h" +#include "GameEventMgr.h" +#include "GossipDef.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" -#include "CellImpl.h" -#include "OutdoorPvPMgr.h" -#include "GameEventMgr.h" -#include "CreatureGroups.h" -#include "Vehicle.h" -#include "SpellAuraEffects.h" #include "Group.h" -#include "MoveSplineInit.h" +#include "GroupMgr.h" +#include "InstanceScript.h" +#include "Log.h" +#include "LootMgr.h" +#include "MapManager.h" #include "MoveSpline.h" +#include "MoveSplineInit.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "OutdoorPvPMgr.h" +#include "Player.h" +#include "PoolMgr.h" +#include "QuestDef.h" +#include "SpellAuraEffects.h" +#include "SpellMgr.h" +#include "TemporarySummon.h" +#include "Util.h" +#include "Vehicle.h" +#include "WaypointMovementGenerator.h" +#include "World.h" +#include "WorldPacket.h" + // apply implementation of the singletons TrainerSpell const* TrainerSpellData::Find(uint32 spell_id) const @@ -953,30 +955,6 @@ bool Creature::isCanTrainingAndResetTalentsOf(Player* player) const && player->getClass() == GetCreatureTemplate()->trainer_class; } -void Creature::AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 /*MovementFlags*/, uint8 /*type*/) -{ - /* uint32 timeElap = getMSTime(); - if ((timeElap - m_startMove) < m_moveTime) - { - oX = (dX - oX) * ((timeElap - m_startMove) / m_moveTime); - oY = (dY - oY) * ((timeElap - m_startMove) / m_moveTime); - } - else - { - oX = dX; - oY = dY; - } - - dX = x; - dY = y; - m_orientation = atan2((oY - dY), (oX - dX)); - - m_startMove = getMSTime(); - m_moveTime = time;*/ - float speed = GetDistance(x, y, z) / ((float)time * 0.001f); - MonsterMoveWithSpeed(x, y, z, speed); -} - Player* Creature::GetLootRecipient() const { if (!m_lootRecipient) diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index c0703196075..228485d001e 100755 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -520,7 +520,6 @@ class Creature : public Unit, public GridObject<Creature>, public MapCreature bool AIM_Initialize(CreatureAI* ai = NULL); void Motion_Initialize(); - void AI_SendMoveToPacket(float x, float y, float z, uint32 time, uint32 MovementFlags, uint8 type); CreatureAI* AI() const { return (CreatureAI*)i_AI; } bool SetWalk(bool enable); diff --git a/src/server/game/Entities/Creature/TemporarySummon.cpp b/src/server/game/Entities/Creature/TemporarySummon.cpp index 43b29c600d6..a6b51a4d395 100755 --- a/src/server/game/Entities/Creature/TemporarySummon.cpp +++ b/src/server/game/Entities/Creature/TemporarySummon.cpp @@ -21,6 +21,8 @@ #include "CreatureAI.h" #include "ObjectMgr.h" #include "TemporarySummon.h" +#include "Pet.h" +#include "Player.h" TempSummon::TempSummon(SummonPropertiesEntry const* properties, Unit* owner, bool isWorldObject) : Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN), diff --git a/src/server/game/Entities/Item/Container/Bag.cpp b/src/server/game/Entities/Item/Container/Bag.cpp index db563c712cd..73b38c1da83 100755 --- a/src/server/game/Entities/Item/Container/Bag.cpp +++ b/src/server/game/Entities/Item/Container/Bag.cpp @@ -23,6 +23,7 @@ #include "Bag.h" #include "Log.h" #include "UpdateData.h" +#include "Player.h" Bag::Bag(): Item() { diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp index f1a7d646fe4..a1ff6cf2ce8 100755 --- a/src/server/game/Entities/Item/Item.cpp +++ b/src/server/game/Entities/Item/Item.cpp @@ -26,6 +26,8 @@ #include "SpellInfo.h" #include "ScriptMgr.h" #include "ConditionMgr.h" +#include "Player.h" +#include "Opcodes.h" void AddItemsSetItem(Player* player, Item* item) { diff --git a/src/server/game/Entities/Item/ItemEnchantmentMgr.cpp b/src/server/game/Entities/Item/ItemEnchantmentMgr.cpp index f85bf80e145..cfb8c880479 100755 --- a/src/server/game/Entities/Item/ItemEnchantmentMgr.cpp +++ b/src/server/game/Entities/Item/ItemEnchantmentMgr.cpp @@ -25,6 +25,7 @@ #include <list> #include <vector> #include "Util.h" +#include "DBCStores.h" struct EnchStoreItem { diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp index d7e87cedbf8..ca32fd377e9 100755 --- a/src/server/game/Entities/Object/Object.cpp +++ b/src/server/game/Entities/Object/Object.cpp @@ -1844,7 +1844,7 @@ bool WorldObject::CanDetect(WorldObject const* obj, bool ignoreStealth) const if (obj->IsAlwaysDetectableFor(seer)) return true; - if (!seer->CanDetectInvisibilityOf(obj)) + if (!ignoreStealth && !seer->CanDetectInvisibilityOf(obj)) return false; if (!ignoreStealth && !seer->CanDetectStealthOf(obj)) @@ -2360,119 +2360,6 @@ TempSummon* WorldObject::SummonCreature(uint32 entry, const Position &pos, TempS return NULL; } -Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, uint32 duration) -{ - Pet* pet = new Pet(this, petType); - - if (petType == SUMMON_PET && pet->LoadPetFromDB(this, entry)) - { - // Remove Demonic Sacrifice auras (known pet) - Unit::AuraEffectList const& auraClassScripts = GetAuraEffectsByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for (Unit::AuraEffectList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();) - { - if ((*itr)->GetMiscValue() == 2228) - { - RemoveAurasDueToSpell((*itr)->GetId()); - itr = auraClassScripts.begin(); - } - else - ++itr; - } - - if (duration > 0) - pet->SetDuration(duration); - - return NULL; - } - - // petentry == 0 for hunter "call pet" (current pet summoned if any) - if (!entry) - { - delete pet; - return NULL; - } - - pet->Relocate(x, y, z, ang); - if (!pet->IsPositionValid()) - { - sLog->outError(LOG_FILTER_GENERAL, "Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)", pet->GetGUIDLow(), pet->GetEntry(), pet->GetPositionX(), pet->GetPositionY()); - delete pet; - return NULL; - } - - Map* map = GetMap(); - uint32 pet_number = sObjectMgr->GeneratePetNumber(); - if (!pet->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PET), map, GetPhaseMask(), entry, pet_number)) - { - sLog->outError(LOG_FILTER_GENERAL, "no such creature entry %u", entry); - delete pet; - return NULL; - } - - pet->SetCreatorGUID(GetGUID()); - pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction()); - - pet->setPowerType(POWER_MANA); - pet->SetUInt32Value(UNIT_NPC_FLAGS, 0); - pet->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); - pet->InitStatsForLevel(getLevel()); - - SetMinion(pet, true); - - switch (petType) - { - case SUMMON_PET: - // this enables pet details window (Shift+P) - pet->GetCharmInfo()->SetPetNumber(pet_number, true); - pet->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048); - pet->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0); - pet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000); - pet->SetFullHealth(); - pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA)); - pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped in this case - break; - default: - break; - } - - map->AddToMap(pet->ToCreature()); - - switch (petType) - { - case SUMMON_PET: - pet->InitPetCreateSpells(); - pet->InitTalentForLevel(); - pet->SavePetToDB(PET_SAVE_AS_CURRENT); - PetSpellInitialize(); - break; - default: - break; - } - - if (petType == SUMMON_PET) - { - // Remove Demonic Sacrifice auras (known pet) - Unit::AuraEffectList const& auraClassScripts = GetAuraEffectsByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); - for (Unit::AuraEffectList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();) - { - if ((*itr)->GetMiscValue() == 2228) - { - RemoveAurasDueToSpell((*itr)->GetId()); - itr = auraClassScripts.begin(); - } - else - ++itr; - } - } - - if (duration > 0) - pet->SetDuration(duration); - - //ObjectAccessor::UpdateObjectVisibility(pet); - - return pet; -} - GameObject* WorldObject::SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime) { if (!IsInWorld()) diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp index d2d9bdac4b3..b6417681f4a 100755 --- a/src/server/game/Entities/Pet/Pet.cpp +++ b/src/server/game/Entities/Pet/Pet.cpp @@ -30,6 +30,7 @@ #include "Unit.h" #include "Util.h" #include "Group.h" +#include "Opcodes.h" #define PET_XP_FACTOR 0.05f @@ -1077,7 +1078,7 @@ bool Pet::HaveInDiet(ItemTemplate const* item) const return diet & FoodMask; } -uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) +uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) const { // -5 or greater food level if (getLevel() <= itemlevel + 5) //possible to feed level 60 pet with level 55 level food for full effect @@ -1881,7 +1882,7 @@ void Pet::ToggleAutocast(SpellInfo const* spellInfo, bool apply) } } -bool Pet::IsPermanentPetFor(Player* owner) +bool Pet::IsPermanentPetFor(Player* owner) const { switch (getPetType()) { diff --git a/src/server/game/Entities/Pet/Pet.h b/src/server/game/Entities/Pet/Pet.h index f55d03ce081..a1dd57a26cc 100755 --- a/src/server/game/Entities/Pet/Pet.h +++ b/src/server/game/Entities/Pet/Pet.h @@ -19,50 +19,11 @@ #ifndef TRINITYCORE_PET_H #define TRINITYCORE_PET_H -#include "ObjectDefines.h" -#include "Unit.h" +#include "PetDefines.h" #include "TemporarySummon.h" -enum PetType -{ - SUMMON_PET = 0, - HUNTER_PET = 1, - MAX_PET_TYPE = 4 -}; - -#define MAX_PET_STABLES 4 - -// stored in character_pet.slot -enum PetSaveMode -{ - PET_SAVE_AS_DELETED = -1, // not saved in fact - PET_SAVE_AS_CURRENT = 0, // in current slot (with player) - PET_SAVE_FIRST_STABLE_SLOT = 1, - PET_SAVE_LAST_STABLE_SLOT = MAX_PET_STABLES, // last in DB stable slot index (including), all higher have same meaning as PET_SAVE_NOT_IN_SLOT - PET_SAVE_NOT_IN_SLOT = 100 // for avoid conflict with stable size grow will use 100 -}; - -enum HappinessState -{ - UNHAPPY = 1, - CONTENT = 2, - HAPPY = 3 -}; - -enum PetSpellState -{ - PETSPELL_UNCHANGED = 0, - PETSPELL_CHANGED = 1, - PETSPELL_NEW = 2, - PETSPELL_REMOVED = 3 -}; - -enum PetSpellType -{ - PETSPELL_NORMAL = 0, - PETSPELL_FAMILY = 1, - PETSPELL_TALENT = 2 -}; +#define PET_FOCUS_REGEN_INTERVAL 4 * IN_MILLISECONDS +#define HAPPINESS_LEVEL_SIZE 333000 struct PetSpell { @@ -71,51 +32,9 @@ struct PetSpell PetSpellType type; }; -enum ActionFeedback -{ - FEEDBACK_NONE = 0, - FEEDBACK_PET_DEAD = 1, - FEEDBACK_NOTHING_TO_ATT = 2, - FEEDBACK_CANT_ATT_TARGET = 3 -}; - -enum PetTalk -{ - PET_TALK_SPECIAL_SPELL = 0, - PET_TALK_ATTACK = 1 -}; - -enum PetNameInvalidReason -{ - // custom, not send - PET_NAME_SUCCESS = 0, - - PET_NAME_INVALID = 1, - PET_NAME_NO_NAME = 2, - PET_NAME_TOO_SHORT = 3, - PET_NAME_TOO_LONG = 4, - PET_NAME_MIXED_LANGUAGES = 6, - PET_NAME_PROFANE = 7, - PET_NAME_RESERVED = 8, - PET_NAME_THREE_CONSECUTIVE = 11, - PET_NAME_INVALID_SPACE = 12, - PET_NAME_CONSECUTIVE_SPACES = 13, - PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, - PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, - PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 -}; - typedef UNORDERED_MAP<uint32, PetSpell> PetSpellMap; typedef std::vector<uint32> AutoSpellList; -#define HAPPINESS_LEVEL_SIZE 333000 - -#define ACTIVE_SPELLS_MAX 4 - -#define PET_FOLLOW_DIST 1.0f -#define PET_FOLLOW_ANGLE (M_PI/2) -#define PET_FOCUS_REGEN_INTERVAL 4 * IN_MILLISECONDS - class Player; class Pet : public Guardian @@ -132,9 +51,9 @@ class Pet : public Guardian bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; } bool isTemporarySummoned() const { return m_duration > 0; } - bool IsPermanentPetFor(Player* owner); // pet have tab in character windows and set UNIT_FIELD_PETNUMBER + bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PETNUMBER - bool Create (uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number); + bool Create(uint32 guidlow, Map* map, uint32 phaseMask, uint32 Entry, uint32 pet_number); bool CreateBaseAtCreature(Creature* creature); bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner); bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phaseMask); @@ -162,9 +81,9 @@ class Pet : public Guardian void GivePetLevel(uint8 level); void SynchronizeLevelWithOwner(); bool HaveInDiet(ItemTemplate const* item) const; - uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel); + uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel) const; void SetDuration(int32 dur) { m_duration = dur; } - int32 GetDuration() { return m_duration; } + int32 GetDuration() const { return m_duration; } /* bool UpdateStats(Stats stat); diff --git a/src/server/game/Entities/Pet/PetDefines.h b/src/server/game/Entities/Pet/PetDefines.h new file mode 100644 index 00000000000..76de2647c8c --- /dev/null +++ b/src/server/game/Entities/Pet/PetDefines.h @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef TRINITYCORE_PET_DEFINES_H +#define TRINITYCORE_PET_DEFINES_H + +enum PetType +{ + SUMMON_PET = 0, + HUNTER_PET = 1, + MAX_PET_TYPE = 4 +}; + +#define MAX_PET_STABLES 4 + +// stored in character_pet.slot +enum PetSaveMode +{ + PET_SAVE_AS_DELETED = -1, // not saved in fact + PET_SAVE_AS_CURRENT = 0, // in current slot (with player) + PET_SAVE_FIRST_STABLE_SLOT = 1, + PET_SAVE_LAST_STABLE_SLOT = MAX_PET_STABLES, // last in DB stable slot index (including), all higher have same meaning as PET_SAVE_NOT_IN_SLOT + PET_SAVE_NOT_IN_SLOT = 100 // for avoid conflict with stable size grow will use 100 +}; + +enum HappinessState +{ + UNHAPPY = 1, + CONTENT = 2, + HAPPY = 3 +}; + +enum PetSpellState +{ + PETSPELL_UNCHANGED = 0, + PETSPELL_CHANGED = 1, + PETSPELL_NEW = 2, + PETSPELL_REMOVED = 3 +}; + +enum PetSpellType +{ + PETSPELL_NORMAL = 0, + PETSPELL_FAMILY = 1, + PETSPELL_TALENT = 2 +}; + +enum ActionFeedback +{ + FEEDBACK_NONE = 0, + FEEDBACK_PET_DEAD = 1, + FEEDBACK_NOTHING_TO_ATT = 2, + FEEDBACK_CANT_ATT_TARGET = 3 +}; + +enum PetTalk +{ + PET_TALK_SPECIAL_SPELL = 0, + PET_TALK_ATTACK = 1 +}; + +#define PET_FOLLOW_DIST 1.0f +#define PET_FOLLOW_ANGLE (M_PI/2) + +#endif diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 46110a2cc11..dd9907d8c07 100755 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -16,67 +16,68 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Common.h" -#include "Language.h" -#include "DatabaseEnv.h" -#include "Log.h" -#include "Opcodes.h" -#include "SpellMgr.h" -#include "World.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "UpdateMask.h" #include "Player.h" -#include "Vehicle.h" -#include "SkillDiscovery.h" -#include "QuestDef.h" -#include "GossipDef.h" -#include "UpdateData.h" +#include "AccountMgr.h" +#include "AchievementMgr.h" +#include "ArenaTeam.h" +#include "ArenaTeamMgr.h" +#include "Battlefield.h" +#include "BattlefieldMgr.h" +#include "BattlefieldWG.h" +#include "BattlegroundAV.h" +#include "Battleground.h" +#include "BattlegroundMgr.h" +#include "CellImpl.h" #include "Channel.h" #include "ChannelMgr.h" -#include "MapManager.h" -#include "MapInstanced.h" -#include "InstanceSaveMgr.h" -#include "GridNotifiers.h" -#include "GridNotifiersImpl.h" -#include "CellImpl.h" -#include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "GuildMgr.h" -#include "GroupMgr.h" -#include "ObjectAccessor.h" +#include "CharacterDatabaseCleaner.h" +#include "Chat.h" +#include <cmath> +#include "Common.h" +#include "ConditionMgr.h" #include "CreatureAI.h" +#include "DatabaseEnv.h" +#include "DisableMgr.h" #include "Formulas.h" +#include "GameEventMgr.h" +#include "GossipDef.h" +#include "GridNotifiers.h" +#include "GridNotifiersImpl.h" #include "Group.h" +#include "GroupMgr.h" #include "Guild.h" -#include "Pet.h" -#include "Util.h" -#include "Transport.h" -#include "Weather.h" -#include "Battleground.h" -#include "BattlegroundAV.h" -#include "BattlegroundMgr.h" +#include "GuildMgr.h" +#include "InstanceSaveMgr.h" +#include "InstanceScript.h" +#include "Language.h" +#include "LFGMgr.h" +#include "Log.h" +#include "MapInstanced.h" +#include "MapManager.h" +#include "ObjectAccessor.h" +#include "ObjectMgr.h" +#include "Opcodes.h" #include "OutdoorPvP.h" #include "OutdoorPvPMgr.h" -#include "ArenaTeam.h" -#include "Chat.h" -#include "Spell.h" +#include "ReputationMgr.h" +#include "Pet.h" +#include "QuestDef.h" +#include "SkillDiscovery.h" #include "SocialMgr.h" -#include "GameEventMgr.h" -#include "AchievementMgr.h" -#include "SpellAuras.h" #include "SpellAuraEffects.h" -#include "ConditionMgr.h" -#include "DisableMgr.h" +#include "SpellAuras.h" +#include "Spell.h" +#include "SpellMgr.h" +#include "Transport.h" +#include "UpdateData.h" +#include "UpdateMask.h" +#include "Util.h" +#include "Vehicle.h" +#include "Weather.h" #include "WeatherMgr.h" -#include "LFGMgr.h" -#include "CharacterDatabaseCleaner.h" -#include "InstanceScript.h" -#include <cmath> -#include "AccountMgr.h" -#include "Battlefield.h" -#include "BattlefieldMgr.h" -#include "BattlefieldWG.h" +#include "World.h" +#include "WorldPacket.h" +#include "WorldSession.h" #define ZONE_UPDATE_INTERVAL (1*IN_MILLISECONDS) @@ -643,7 +644,7 @@ void KillRewarder::Reward() #ifdef _MSC_VER #pragma warning(disable:4355) #endif -Player::Player(WorldSession* session): Unit(true), m_achievementMgr(this), m_reputationMgr(this) +Player::Player(WorldSession* session): Unit(true) { #ifdef _MSC_VER #pragma warning(default:4355) @@ -869,6 +870,8 @@ Player::Player(WorldSession* session): Unit(true), m_achievementMgr(this), m_rep SetPendingBind(0, 0); _activeCheats = CHEAT_NONE; + m_achievementMgr = new AchievementMgr(this); + m_reputationMgr = new ReputationMgr(this); } Player::~Player() @@ -904,6 +907,8 @@ Player::~Player() delete m_declinedname; delete m_runes; + delete m_achievementMgr; + delete m_reputationMgr; sWorld->DecreasePlayerCount(); } @@ -1609,7 +1614,7 @@ void Player::Update(uint32 p_time) } } - m_achievementMgr.UpdateTimedAchievements(p_time); + m_achievementMgr->UpdateTimedAchievements(p_time); if (HasUnitState(UNIT_STATE_MELEE_ATTACKING) && !HasUnitState(UNIT_STATE_CASTING)) { @@ -5580,11 +5585,11 @@ void Player::CleanupChannels() { Channel* ch = *m_channels.begin(); m_channels.erase(m_channels.begin()); // remove from player's channel list - ch->Leave(GetGUID(), false); // not send to client, not remove from player's channel list + ch->LeaveChannel(this, false); // not send to client, not remove from player's channel list if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetTeam())) cMgr->LeftChannel(ch->GetName()); // deleted channel if empty } - sLog->outDebug(LOG_FILTER_CHATSYS, "Player: channels cleaned up!"); + sLog->outDebug(LOG_FILTER_CHATSYS, "Player %s: channels cleaned up!", GetName().c_str()); } void Player::UpdateLocalChannels(uint32 newZone) @@ -5657,11 +5662,11 @@ void Player::UpdateLocalChannels(uint32 newZone) removeChannel = usedChannel; if (joinChannel) - joinChannel->Join(GetGUID(), ""); // Changed Channel: ... or Joined Channel: ... + joinChannel->JoinChannel(this, ""); // Changed Channel: ... or Joined Channel: ... if (removeChannel) { - removeChannel->Leave(GetGUID(), sendRemove); // Leave old channel + removeChannel->LeaveChannel(this, sendRemove); // Leave old channel std::string name = removeChannel->GetName(); // Store name, (*i)erase in LeftChannel LeftChannel(removeChannel); // Remove from player's channel list cMgr->LeftChannel(name); // Delete if empty @@ -5676,7 +5681,7 @@ void Player::LeaveLFGChannel() { if ((*i)->IsLFG()) { - (*i)->Leave(GetGUID()); + (*i)->LeaveChannel(this); break; } } @@ -5684,13 +5689,8 @@ void Player::LeaveLFGChannel() void Player::UpdateDefense() { - uint32 defense_skill_gain = sWorld->getIntConfig(CONFIG_SKILL_GAIN_DEFENSE); - - if (UpdateSkill(SKILL_DEFENSE, defense_skill_gain)) - { - // update dependent from defense skill part - UpdateDefenseBonusesMod(); - } + if (UpdateSkill(SKILL_DEFENSE, sWorld->getIntConfig(CONFIG_SKILL_GAIN_DEFENSE))) + UpdateDefenseBonusesMod(); // update dependent from defense skill part } void Player::HandleBaseModValue(BaseModGroup modGroup, BaseModType modType, float amount, bool apply) @@ -7259,7 +7259,7 @@ bool Player::RewardHonor(Unit* victim, uint32 groupsize, int32 honor, bool pvpto int32 count = sWorld->getIntConfig(CONFIG_PVP_TOKEN_COUNT); if (AddItem(itemId, count)) - ChatHandler(this).PSendSysMessage("You have been awarded a token for slaying another player."); + ChatHandler(GetSession()).PSendSysMessage("You have been awarded a token for slaying another player."); } } @@ -16648,6 +16648,11 @@ float Player::GetFloatValueFromArray(Tokenizer const& data, uint16 index) return result; } +bool Player::isBeingLoaded() const +{ + return GetSession()->PlayerLoading(); +} + bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) { //// 0 1 2 3 4 5 6 7 8 9 10 11 @@ -16732,7 +16737,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) SetFloatValue(UNIT_FIELD_HOVERHEIGHT, 1.0f); // load achievements before anything else to prevent multiple gains for the same achievement/criteria on every loading (as loading does call UpdateAchievementCriteria) - m_achievementMgr.LoadFromDB(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS), holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS)); + m_achievementMgr->LoadFromDB(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADACHIEVEMENTS), holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADCRITERIAPROGRESS)); uint32 money = fields[8].GetUInt32(); if (money > MAX_MONEY_AMOUNT) @@ -17176,7 +17181,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) learnDefaultSpells(); // must be before inventory (some items required reputation check) - m_reputationMgr.LoadFromDB(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADREPUTATION)); + m_reputationMgr->LoadFromDB(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADREPUTATION)); _LoadInventory(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADINVENTORY), time_diff); @@ -17284,7 +17289,7 @@ bool Player::LoadFromDB(uint32 guid, SQLQueryHolder *holder) _LoadDeclinedNames(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADDECLINEDNAMES)); - m_achievementMgr.CheckAllAchievementCriteria(); + m_achievementMgr->CheckAllAchievementCriteria(); _LoadEquipmentSets(holder->GetPreparedResult(PLAYER_LOGIN_QUERY_LOADEQUIPMENTSETS)); @@ -18509,6 +18514,14 @@ bool Player::CheckInstanceLoginValid() return sMapMgr->CanPlayerEnter(GetMap()->GetId(), this, true); } +bool Player::CheckInstanceCount(uint32 instanceId) const +{ + if (_instanceResetTimes.size() < sWorld->getIntConfig(CONFIG_MAX_INSTANCES_PER_HOUR)) + return true; + return _instanceResetTimes.find(instanceId) != _instanceResetTimes.end(); +} + + bool Player::_LoadHomeBind(PreparedQueryResult result) { PlayerInfo const* info = sObjectMgr->GetPlayerInfo(getRace(), getClass()); @@ -18828,8 +18841,8 @@ void Player::SaveToDB(bool create /*=false*/) _SaveActions(trans); _SaveAuras(trans); _SaveSkills(trans); - m_achievementMgr.SaveToDB(trans); - m_reputationMgr.SaveToDB(trans); + m_achievementMgr->SaveToDB(trans); + m_reputationMgr->SaveToDB(trans); _SaveEquipmentSets(trans); GetSession()->SaveTutorialsData(trans); // changed only while character in game _SaveGlyphs(trans); @@ -19967,7 +19980,7 @@ void Player::Whisper(const std::string& text, uint32 language, uint64 receiver) } else if (!isAddonMessage) // announce to player that player he is whispering to is dnd and cannot receive his message - ChatHandler(this).PSendSysMessage(LANG_PLAYER_DND, rPlayer->GetName().c_str(), rPlayer->dndMsg.c_str()); + ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_DND, rPlayer->GetName().c_str(), rPlayer->dndMsg.c_str()); // rest stuff shouldn't happen in case of addon message if (isAddonMessage) @@ -19976,12 +19989,12 @@ void Player::Whisper(const std::string& text, uint32 language, uint64 receiver) if (!isAcceptWhispers() && !isGameMaster() && !rPlayer->isGameMaster()) { SetAcceptWhispers(true); - ChatHandler(this).SendSysMessage(LANG_COMMAND_WHISPERON); + ChatHandler(GetSession()).SendSysMessage(LANG_COMMAND_WHISPERON); } // announce to player that player he is whispering to is afk if (rPlayer->isAFK()) - ChatHandler(this).PSendSysMessage(LANG_PLAYER_AFK, rPlayer->GetName().c_str(), rPlayer->afkMsg.c_str()); + ChatHandler(GetSession()).PSendSysMessage(LANG_PLAYER_AFK, rPlayer->GetName().c_str(), rPlayer->afkMsg.c_str()); // if player whisper someone, auto turn of dnd to be able to receive an answer if (isDND() && !rPlayer->isGameMaster()) @@ -21702,7 +21715,7 @@ bool Player::IsAlwaysDetectableFor(WorldObject const* seer) const return false; } -bool Player::IsVisibleGloballyFor(Player* u) const +bool Player::IsVisibleGloballyFor(Player const* u) const { if (!u) return false; @@ -22077,8 +22090,8 @@ void Player::SendInitialPacketsBeforeAddToMap() GetSession()->SendPacket(&data); SendInitialActionButtons(); - m_reputationMgr.SendInitialReputations(); - m_achievementMgr.SendAllAchievementData(); + m_reputationMgr->SendInitialReputations(); + m_achievementMgr->SendAllAchievementData(); SendEquipmentSetList(); @@ -24189,42 +24202,42 @@ void Player::HandleFall(MovementInfo const& movementInfo) void Player::ResetAchievements() { - m_achievementMgr.Reset(); + m_achievementMgr->Reset(); } void Player::SendRespondInspectAchievements(Player* player) const { - m_achievementMgr.SendRespondInspectAchievements(player); + m_achievementMgr->SendRespondInspectAchievements(player); } bool Player::HasAchieved(uint32 achievementId) const { - return m_achievementMgr.HasAchieved(achievementId); + return m_achievementMgr->HasAchieved(achievementId); } void Player::StartTimedAchievement(AchievementCriteriaTimedTypes type, uint32 entry, uint32 timeLost/* = 0*/) { - m_achievementMgr.StartTimedAchievement(type, entry, timeLost); + m_achievementMgr->StartTimedAchievement(type, entry, timeLost); } void Player::RemoveTimedAchievement(AchievementCriteriaTimedTypes type, uint32 entry) { - m_achievementMgr.RemoveTimedAchievement(type, entry); + m_achievementMgr->RemoveTimedAchievement(type, entry); } void Player::ResetAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1 /*= 0*/, uint32 miscValue2 /*= 0*/, bool evenIfCriteriaComplete /* = false*/) { - m_achievementMgr.ResetAchievementCriteria(type, miscValue1, miscValue2, evenIfCriteriaComplete); + m_achievementMgr->ResetAchievementCriteria(type, miscValue1, miscValue2, evenIfCriteriaComplete); } void Player::UpdateAchievementCriteria(AchievementCriteriaTypes type, uint32 miscValue1 /*= 0*/, uint32 miscValue2 /*= 0*/, Unit* unit /*= NULL*/) { - m_achievementMgr.UpdateAchievementCriteria(type, miscValue1, miscValue2, unit); + m_achievementMgr->UpdateAchievementCriteria(type, miscValue1, miscValue2, unit); } void Player::CompletedAchievement(AchievementEntry const* entry) { - m_achievementMgr.CompletedAchievement(entry); + m_achievementMgr->CompletedAchievement(entry); } void Player::LearnTalent(uint32 talentId, uint32 talentRank) @@ -25330,7 +25343,7 @@ bool Player::AddItem(uint32 itemId, uint32 count) if (count == 0 || dest.empty()) { // -- TODO: Send to mailbox if no space - ChatHandler(this).PSendSysMessage("You don't have any space in your bags."); + ChatHandler(GetSession()).PSendSysMessage("You don't have any space in your bags."); return false; } @@ -25594,3 +25607,116 @@ Guild* Player::GetGuild() uint32 guildId = GetGuildId(); return guildId ? sGuildMgr->GetGuildById(guildId) : NULL; } + +Pet* Player::SummonPet(uint32 entry, float x, float y, float z, float ang, PetType petType, uint32 duration) +{ + Pet* pet = new Pet(this, petType); + + if (petType == SUMMON_PET && pet->LoadPetFromDB(this, entry)) + { + // Remove Demonic Sacrifice auras (known pet) + Unit::AuraEffectList const& auraClassScripts = GetAuraEffectsByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for (Unit::AuraEffectList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();) + { + if ((*itr)->GetMiscValue() == 2228) + { + RemoveAurasDueToSpell((*itr)->GetId()); + itr = auraClassScripts.begin(); + } + else + ++itr; + } + + if (duration > 0) + pet->SetDuration(duration); + + return NULL; + } + + // petentry == 0 for hunter "call pet" (current pet summoned if any) + if (!entry) + { + delete pet; + return NULL; + } + + pet->Relocate(x, y, z, ang); + if (!pet->IsPositionValid()) + { + sLog->outError(LOG_FILTER_GENERAL, "Pet (guidlow %d, entry %d) not summoned. Suggested coordinates isn't valid (X: %f Y: %f)", pet->GetGUIDLow(), pet->GetEntry(), pet->GetPositionX(), pet->GetPositionY()); + delete pet; + return NULL; + } + + Map* map = GetMap(); + uint32 pet_number = sObjectMgr->GeneratePetNumber(); + if (!pet->Create(sObjectMgr->GenerateLowGuid(HIGHGUID_PET), map, GetPhaseMask(), entry, pet_number)) + { + sLog->outError(LOG_FILTER_GENERAL, "no such creature entry %u", entry); + delete pet; + return NULL; + } + + pet->SetCreatorGUID(GetGUID()); + pet->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, getFaction()); + + pet->setPowerType(POWER_MANA); + pet->SetUInt32Value(UNIT_NPC_FLAGS, 0); + pet->SetUInt32Value(UNIT_FIELD_BYTES_1, 0); + pet->InitStatsForLevel(getLevel()); + + SetMinion(pet, true); + + switch (petType) + { + case SUMMON_PET: + // this enables pet details window (Shift+P) + pet->GetCharmInfo()->SetPetNumber(pet_number, true); + pet->SetUInt32Value(UNIT_FIELD_BYTES_0, 2048); + pet->SetUInt32Value(UNIT_FIELD_PETEXPERIENCE, 0); + pet->SetUInt32Value(UNIT_FIELD_PETNEXTLEVELEXP, 1000); + pet->SetFullHealth(); + pet->SetPower(POWER_MANA, pet->GetMaxPower(POWER_MANA)); + pet->SetUInt32Value(UNIT_FIELD_PET_NAME_TIMESTAMP, uint32(time(NULL))); // cast can't be helped in this case + break; + default: + break; + } + + map->AddToMap(pet->ToCreature()); + + switch (petType) + { + case SUMMON_PET: + pet->InitPetCreateSpells(); + pet->InitTalentForLevel(); + pet->SavePetToDB(PET_SAVE_AS_CURRENT); + PetSpellInitialize(); + break; + default: + break; + } + + if (petType == SUMMON_PET) + { + // Remove Demonic Sacrifice auras (known pet) + Unit::AuraEffectList const& auraClassScripts = GetAuraEffectsByType(SPELL_AURA_OVERRIDE_CLASS_SCRIPTS); + for (Unit::AuraEffectList::const_iterator itr = auraClassScripts.begin(); itr != auraClassScripts.end();) + { + if ((*itr)->GetMiscValue() == 2228) + { + RemoveAurasDueToSpell((*itr)->GetId()); + itr = auraClassScripts.begin(); + } + else + ++itr; + } + } + + if (duration > 0) + pet->SetDuration(duration); + + //ObjectAccessor::UpdateObjectVisibility(pet); + + return pet; +} diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index fe1d1a5b798..3e4b3e8a971 100755 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -19,30 +19,28 @@ #ifndef _PLAYER_H #define _PLAYER_H -#include "AchievementMgr.h" -#include "Battleground.h" -#include "Bag.h" -#include "Common.h" -#include "DatabaseEnv.h" -#include "DBCEnums.h" +#include "DBCStores.h" #include "GroupReference.h" -#include "ItemPrototype.h" -#include "Item.h" #include "MapReference.h" -#include "NPCHandler.h" -#include "Pet.h" + +#include "Item.h" +#include "PetDefines.h" #include "QuestDef.h" -#include "ReputationMgr.h" -#include "Unit.h" -#include "Util.h" // for Tokens typedef -#include "WorldSession.h" #include "SpellMgr.h" +#include "Unit.h" -#include<string> -#include<vector> +#include <string> +#include <vector> +struct CreatureTemplate; struct Mail; +struct TrainerSpell; +struct VendorItem; + +class AchievementMgr; +class ReputationMgr; class Channel; +class CharacterCreateInfo; class Creature; class DynamicObject; class Group; @@ -242,9 +240,7 @@ typedef std::list<PlayerCreateInfoAction> PlayerCreateInfoActions; struct PlayerInfo { // existence checked by displayId != 0 - PlayerInfo() : displayId_m(0), displayId_f(0), levelInfo(NULL) - { - } + PlayerInfo() : displayId_m(0), displayId_f(0), levelInfo(NULL) { } uint32 mapId; uint32 areaId; @@ -725,13 +721,6 @@ enum RestType REST_TYPE_IN_CITY = 2 }; -enum DuelCompleteType -{ - DUEL_INTERRUPTED = 0, - DUEL_WON = 1, - DUEL_FLED = 2 -}; - enum TeleportToOptions { TELE_TO_GM_MODE = 0x01, @@ -834,17 +823,6 @@ struct InstancePlayerBind InstancePlayerBind() : save(NULL), perm(false) {} }; -enum DungeonStatusFlag -{ - DUNGEON_STATUSFLAG_NORMAL = 0x01, - DUNGEON_STATUSFLAG_HEROIC = 0x02, - - RAID_STATUSFLAG_10MAN_NORMAL = 0x01, - RAID_STATUSFLAG_25MAN_NORMAL = 0x02, - RAID_STATUSFLAG_10MAN_HEROIC = 0x04, - RAID_STATUSFLAG_25MAN_HEROIC = 0x08 -}; - struct AccessRequirement { uint8 levelMin; @@ -1513,7 +1491,7 @@ class Player : public Unit, public GridObject<Player> /*********************************************************/ bool LoadFromDB(uint32 guid, SQLQueryHolder *holder); - bool isBeingLoaded() const { return GetSession()->PlayerLoading();} + bool isBeingLoaded() const; void Initialize(uint32 guid); static uint32 GetUInt32ValueFromArray(Tokenizer const& data, uint16 index); @@ -2037,8 +2015,8 @@ class Player : public Unit, public GridObject<Player> uint8 GetGrantableLevels() { return m_grantableLevels; } void SetGrantableLevels(uint8 val) { m_grantableLevels = val; } - ReputationMgr& GetReputationMgr() { return m_reputationMgr; } - ReputationMgr const& GetReputationMgr() const { return m_reputationMgr; } + ReputationMgr& GetReputationMgr() { return *m_reputationMgr; } + ReputationMgr const& GetReputationMgr() const { return *m_reputationMgr; } ReputationRank GetReputationRank(uint32 faction_id) const; void RewardReputation(Unit* victim, float rate); void RewardReputation(Quest const* quest); @@ -2339,7 +2317,7 @@ class Player : public Unit, public GridObject<Player> bool IsNeverVisible() const; - bool IsVisibleGloballyFor(Player* player) const; + bool IsVisibleGloballyFor(Player const* player) const; void SendInitialVisiblePackets(Unit* target); void UpdateObjectVisibility(bool forced = true); @@ -2398,12 +2376,7 @@ class Player : public Unit, public GridObject<Player> static void ConvertInstancesToGroup(Player* player, Group* group, bool switchLeader); bool Satisfy(AccessRequirement const* ar, uint32 target_map, bool report = false); bool CheckInstanceLoginValid(); - bool CheckInstanceCount(uint32 instanceId) const - { - if (_instanceResetTimes.size() < sWorld->getIntConfig(CONFIG_MAX_INSTANCES_PER_HOUR)) - return true; - return _instanceResetTimes.find(instanceId) != _instanceResetTimes.end(); - } + bool CheckInstanceCount(uint32 instanceId) const; void AddInstanceEnterTime(uint32 instanceId, time_t enterTime) { @@ -2860,8 +2833,8 @@ class Player : public Unit, public GridObject<Player> uint32 m_temporaryUnsummonedPetNumber; uint32 m_oldpetspell; - AchievementMgr m_achievementMgr; - ReputationMgr m_reputationMgr; + AchievementMgr* m_achievementMgr; + ReputationMgr* m_reputationMgr; SpellCooldowns m_spellCooldowns; diff --git a/src/server/game/Entities/Totem/Totem.cpp b/src/server/game/Entities/Totem/Totem.cpp index d5d1bd99277..4d726181c4f 100755 --- a/src/server/game/Entities/Totem/Totem.cpp +++ b/src/server/game/Entities/Totem/Totem.cpp @@ -17,13 +17,14 @@ */ #include "Totem.h" -#include "WorldPacket.h" #include "Log.h" #include "Group.h" -#include "Player.h" #include "ObjectMgr.h" +#include "Opcodes.h" +#include "Player.h" #include "SpellMgr.h" #include "SpellInfo.h" +#include "WorldPacket.h" Totem::Totem(SummonPropertiesEntry const* properties, Unit* owner) : Minion(properties, owner, false) { diff --git a/src/server/game/Entities/Transport/Transport.cpp b/src/server/game/Entities/Transport/Transport.cpp index f52d0059a36..6de359c67dd 100755 --- a/src/server/game/Entities/Transport/Transport.cpp +++ b/src/server/game/Entities/Transport/Transport.cpp @@ -26,6 +26,7 @@ #include "DBCStores.h" #include "World.h" #include "GameObjectAI.h" +#include "Player.h" void MapManager::LoadTransports() { diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 29afc0c1b36..0b168a1615b 100755 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -16,49 +16,50 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "Unit.h" #include "Common.h" +#include "Battlefield.h" +#include "BattlefieldMgr.h" +#include "Battleground.h" +#include "CellImpl.h" +#include "ConditionMgr.h" +#include "CreatureAI.h" #include "CreatureAIImpl.h" -#include "Log.h" -#include "Opcodes.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "World.h" -#include "ObjectMgr.h" -#include "SpellMgr.h" -#include "Unit.h" -#include "QuestDef.h" -#include "Player.h" +#include "CreatureGroups.h" #include "Creature.h" -#include "Spell.h" +#include "Formulas.h" +#include "GridNotifiersImpl.h" #include "Group.h" -#include "SpellAuras.h" -#include "SpellAuraEffects.h" +#include "InstanceSaveMgr.h" +#include "InstanceScript.h" +#include "Log.h" #include "MapManager.h" +#include "MoveSpline.h" +#include "MoveSplineInit.h" #include "ObjectAccessor.h" -#include "CreatureAI.h" -#include "Formulas.h" -#include "Pet.h" -#include "Util.h" -#include "Totem.h" -#include "Battleground.h" +#include "ObjectMgr.h" +#include "Opcodes.h" #include "OutdoorPvP.h" -#include "InstanceSaveMgr.h" -#include "GridNotifiersImpl.h" -#include "CellImpl.h" -#include "CreatureGroups.h" -#include "PetAI.h" #include "PassiveAI.h" +#include "PetAI.h" +#include "Pet.h" +#include "Player.h" +#include "QuestDef.h" +#include "ReputationMgr.h" +#include "SpellAuraEffects.h" +#include "SpellAuras.h" +#include "Spell.h" +#include "SpellInfo.h" +#include "SpellMgr.h" #include "TemporarySummon.h" -#include "Vehicle.h" +#include "Totem.h" #include "Transport.h" -#include "InstanceScript.h" -#include "SpellInfo.h" -#include "MoveSplineInit.h" -#include "MoveSpline.h" -#include "ConditionMgr.h" #include "UpdateFieldFlags.h" -#include "Battlefield.h" -#include "BattlefieldMgr.h" +#include "Util.h" +#include "Vehicle.h" +#include "World.h" +#include "WorldPacket.h" +#include "WorldSession.h" #include <math.h> @@ -1328,7 +1329,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) // If this is a creature and it attacks from behind it has a probability to daze it's victim if ((damageInfo->hitOutCome == MELEE_HIT_CRIT || damageInfo->hitOutCome == MELEE_HIT_CRUSHING || damageInfo->hitOutCome == MELEE_HIT_NORMAL || damageInfo->hitOutCome == MELEE_HIT_GLANCING) && GetTypeId() != TYPEID_PLAYER && !ToCreature()->IsControlledByPlayer() && !victim->HasInArc(M_PI, this) - && (victim->GetTypeId() == TYPEID_PLAYER || !victim->ToCreature()->isWorldBoss())) + && (victim->GetTypeId() == TYPEID_PLAYER || !victim->ToCreature()->isWorldBoss())&& !victim->IsVehicle()) { // -probability is between 0% and 40% // 20% base chance @@ -1341,7 +1342,10 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss) uint32 VictimDefense=victim->GetDefenseSkillValue(); uint32 AttackerMeleeSkill=GetUnitMeleeSkill(); - Probability *= AttackerMeleeSkill/(float)VictimDefense; + Probability *= AttackerMeleeSkill/(float)VictimDefense*0.16; + + if (Probability < 0) + Probability = 0; if (Probability > 40.0f) Probability = 40.0f; diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h index ce329098bc6..08fefe4c420 100755 --- a/src/server/game/Entities/Unit/Unit.h +++ b/src/server/game/Entities/Unit/Unit.h @@ -19,24 +19,14 @@ #ifndef __UNIT_H #define __UNIT_H -#include "Common.h" -#include "Object.h" -#include "Opcodes.h" -#include "SpellAuraDefines.h" -#include "UpdateFields.h" -#include "SharedDefines.h" -#include "ThreatManager.h" -#include "HostileRefManager.h" +#include "EventProcessor.h" #include "FollowerReference.h" #include "FollowerRefManager.h" -#include "EventProcessor.h" +#include "HostileRefManager.h" #include "MotionMaster.h" -#include "DBCStructure.h" -#include "SpellInfo.h" -#include "Path.h" -#include "WorldPacket.h" -#include "Timer.h" -#include <list> +#include "Object.h" +#include "SpellAuraDefines.h" +#include "ThreatManager.h" #define WORLD_TRIGGER 12999 @@ -342,6 +332,7 @@ class Totem; class Transport; class Vehicle; class TransportBase; +class SpellCastTargets; typedef std::list<Unit*> UnitList; typedef std::list< std::pair<Aura*, uint8> > DispelChargesList; diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp index 84274a9692d..f8f7a1a1b72 100755 --- a/src/server/game/Entities/Vehicle/Vehicle.cpp +++ b/src/server/game/Entities/Vehicle/Vehicle.cpp @@ -29,6 +29,7 @@ #include "SpellMgr.h" #include "SpellInfo.h" #include "MoveSplineInit.h" +#include "TemporarySummon.h" Vehicle::Vehicle(Unit* unit, VehicleEntry const* vehInfo, uint32 creatureEntry) : _me(unit), _vehicleInfo(vehInfo), _usableSeatNum(0), _creatureEntry(creatureEntry) { diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp index b19abc778a9..cedb20eccf1 100755 --- a/src/server/game/Globals/ObjectAccessor.cpp +++ b/src/server/game/Globals/ObjectAccessor.cpp @@ -17,25 +17,25 @@ */ #include "ObjectAccessor.h" -#include "ObjectMgr.h" - -#include "Player.h" +#include "CellImpl.h" +#include "Corpse.h" #include "Creature.h" -#include "GameObject.h" #include "DynamicObject.h" -#include "Vehicle.h" -#include "WorldPacket.h" -#include "Item.h" -#include "Corpse.h" +#include "GameObject.h" #include "GridNotifiers.h" -#include "MapManager.h" -#include "Map.h" -#include "CellImpl.h" #include "GridNotifiersImpl.h" -#include "Opcodes.h" -#include "ObjectDefines.h" +#include "Item.h" +#include "Map.h" #include "MapInstanced.h" +#include "MapManager.h" +#include "ObjectDefines.h" +#include "ObjectMgr.h" +#include "Opcodes.h" +#include "Pet.h" +#include "Player.h" +#include "Vehicle.h" #include "World.h" +#include "WorldPacket.h" #include <cmath> @@ -47,6 +47,12 @@ ObjectAccessor::~ObjectAccessor() { } +Player* ObjectAccessor::GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/) +{ + Player* player = HashMapHolder<Player>::Find(guid); + return player && player->IsInWorld() ? player : NULL; +} + WorldObject* ObjectAccessor::GetWorldObject(WorldObject const& p, uint64 guid) { switch (GUID_HIPART(guid)) diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h index 41a7abc9a24..d2b532c9f94 100755 --- a/src/server/game/Globals/ObjectAccessor.h +++ b/src/server/game/Globals/ObjectAccessor.h @@ -28,7 +28,6 @@ #include "GridDefines.h" #include "Object.h" -#include "Player.h" #include <set> @@ -116,11 +115,7 @@ class ObjectAccessor } // Player may be not in world while in ObjectAccessor - static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/) - { - Player* player = HashMapHolder<Player>::Find(guid); - return player && player->IsInWorld() ? player : NULL; - } + static Player* GetObjectInWorld(uint64 guid, Player* /*typeSpecifier*/); static Unit* GetObjectInWorld(uint64 guid, Unit* /*typeSpecifier*/) { diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index db8a484ad76..ff734efe385 100755 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -16,36 +16,38 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "AccountMgr.h" +#include "AchievementMgr.h" +#include "ArenaTeam.h" +#include "ArenaTeamMgr.h" +#include "Chat.h" #include "Common.h" #include "DatabaseEnv.h" +#include "DisableMgr.h" +#include "GameEventMgr.h" +#include "GossipDef.h" +#include "GroupMgr.h" +#include "GuildMgr.h" +#include "InstanceSaveMgr.h" +#include "Language.h" +#include "LFGMgr.h" #include "Log.h" #include "MapManager.h" #include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "GuildMgr.h" -#include "GroupMgr.h" +#include "Pet.h" +#include "PoolMgr.h" +#include "ReputationMgr.h" +#include "ScriptMgr.h" +#include "SpellAuras.h" +#include "Spell.h" #include "SpellMgr.h" -#include "UpdateMask.h" -#include "World.h" -#include "ArenaTeam.h" +#include "SpellScript.h" #include "Transport.h" -#include "Language.h" -#include "GameEventMgr.h" -#include "Spell.h" -#include "Chat.h" -#include "AccountMgr.h" -#include "InstanceSaveMgr.h" -#include "SpellAuras.h" +#include "UpdateMask.h" #include "Util.h" -#include "WaypointManager.h" -#include "GossipDef.h" #include "Vehicle.h" -#include "AchievementMgr.h" -#include "DisableMgr.h" -#include "ScriptMgr.h" -#include "SpellScript.h" -#include "PoolMgr.h" -#include "LFGMgr.h" +#include "WaypointManager.h" +#include "World.h" ScriptMapMap sQuestEndScripts; ScriptMapMap sQuestStartScripts; @@ -227,11 +229,29 @@ bool SpellClickInfo::IsFitToRequirements(Unit const* clicker, Unit const* clicke return true; } -ObjectMgr::ObjectMgr(): _auctionId(1), _equipmentSetGuid(1), - _itemTextId(1), _mailId(1), _hiPetNumber(1), _hiCharGuid(1), - _hiCreatureGuid(1), _hiPetGuid(1), _hiVehicleGuid(1), _hiItemGuid(1), - _hiGoGuid(1), _hiDoGuid(1), _hiCorpseGuid(1), _hiMoTransGuid(1) -{} +ObjectMgr::ObjectMgr(): + _auctionId(1), + _equipmentSetGuid(1), + _itemTextId(1), + _mailId(1), + _hiPetNumber(1), + _hiCharGuid(1), + _hiCreatureGuid(1), + _hiPetGuid(1), + _hiVehicleGuid(1), + _hiItemGuid(1), + _hiGoGuid(1), + _hiDoGuid(1), + _hiCorpseGuid(1), + _hiMoTransGuid(1) +{ + for (uint8 i = 0; i < MAX_CLASSES; ++i) + { + _playerClassInfo[i] = NULL; + for (uint8 j = 0; j < MAX_RACES; ++j) + _playerInfo[j][i] = NULL; + } +} ObjectMgr::~ObjectMgr() { @@ -243,11 +263,21 @@ ObjectMgr::~ObjectMgr() // free only if loaded for (int class_ = 0; class_ < MAX_CLASSES; ++class_) - delete[] _playerClassInfo[class_].levelInfo; + { + if (_playerClassInfo[class_]) + delete[] _playerClassInfo[class_]->levelInfo; + delete _playerClassInfo[class_]; + } for (int race = 0; race < MAX_RACES; ++race) + { for (int class_ = 0; class_ < MAX_CLASSES; ++class_) - delete[] _playerInfo[race][class_].levelInfo; + { + if (_playerInfo[race][class_]) + delete[] _playerInfo[race][class_]->levelInfo; + delete _playerInfo[race][class_]; + } + } for (CacheVendorItemContainer::iterator itr = _cacheVendorItemStore.begin(); itr != _cacheVendorItemStore.end(); ++itr) itr->second.Clear(); @@ -257,6 +287,9 @@ ObjectMgr::~ObjectMgr() for (DungeonEncounterContainer::iterator itr =_dungeonEncounterStore.begin(); itr != _dungeonEncounterStore.end(); ++itr) for (DungeonEncounterList::iterator encounterItr = itr->second.begin(); encounterItr != itr->second.end(); ++encounterItr) delete *encounterItr; + + for (AccessRequirementContainer::iterator itr = _accessRequirementStore.begin(); itr != _accessRequirementStore.end(); ++itr) + delete itr->second; } void ObjectMgr::AddLocaleString(std::string const& s, LocaleConstant locale, StringVector& data) @@ -2923,8 +2956,11 @@ PetLevelInfo const* ObjectMgr::GetPetLevelInfo(uint32 creature_id, uint8 level) void ObjectMgr::PlayerCreateInfoAddItemHelper(uint32 race_, uint32 class_, uint32 itemId, int32 count) { + if (!_playerInfo[race_][class_]) + return; + if (count > 0) - _playerInfo[race_][class_].item.push_back(PlayerCreateInfoItem(itemId, count)); + _playerInfo[race_][class_]->item.push_back(PlayerCreateInfoItem(itemId, count)); else { if (count < -1) @@ -3031,17 +3067,16 @@ void ObjectMgr::LoadPlayerInfo() continue; } - PlayerInfo* pInfo = &_playerInfo[current_race][current_class]; - - pInfo->mapId = mapId; - pInfo->areaId = areaId; - pInfo->positionX = positionX; - pInfo->positionY = positionY; - pInfo->positionZ = positionZ; - pInfo->orientation = orientation; - - pInfo->displayId_m = rEntry->model_m; - pInfo->displayId_f = rEntry->model_f; + PlayerInfo* info = new PlayerInfo(); + info->mapId = mapId; + info->areaId = areaId; + info->positionX = positionX; + info->positionY = positionY; + info->positionZ = positionZ; + info->orientation = orientation; + info->displayId_m = rEntry->model_m; + info->displayId_f = rEntry->model_f; + _playerInfo[current_race][current_class] = info; ++count; } @@ -3164,10 +3199,16 @@ void ObjectMgr::LoadPlayerInfo() uint32 max_class = current_class ? current_class + 1 : MAX_CLASSES; for (uint32 r = min_race; r < max_race; ++r) for (uint32 c = min_class; c < max_class; ++c) - _playerInfo[r][c].spell.push_back(fields[2].GetUInt32()); + if (PlayerInfo * info = _playerInfo[r][c]) + info->spell.push_back(fields[2].GetUInt32()); } + else if (PlayerInfo * info = _playerInfo[current_race][current_class]) + info->spell.push_back(fields[2].GetUInt32()); else - _playerInfo[current_race][current_class].spell.push_back(fields[2].GetUInt32()); + { + sLog->outError(LOG_FILTER_SQL, "Wrong race: %u, class: %u combination in `playercreateinfo_spell` table, ignoring.", current_race, current_class); + continue; + } ++count; } @@ -3212,8 +3253,8 @@ void ObjectMgr::LoadPlayerInfo() continue; } - PlayerInfo* pInfo = &_playerInfo[current_race][current_class]; - pInfo->action.push_back(PlayerCreateInfoAction(fields[2].GetUInt16(), fields[3].GetUInt32(), fields[4].GetUInt16())); + if (PlayerInfo* info = _playerInfo[current_race][current_class]) + info->action.push_back(PlayerCreateInfoAction(fields[2].GetUInt16(), fields[3].GetUInt32(), fields[4].GetUInt16())); ++count; } @@ -3228,13 +3269,12 @@ void ObjectMgr::LoadPlayerInfo() { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 + // 0 1 2 3 QueryResult result = WorldDatabase.Query("SELECT class, level, basehp, basemana FROM player_classlevelstats"); if (!result) { sLog->outError(LOG_FILTER_SQL, ">> Loaded 0 level health/mana definitions. DB table `game_event_condition` is empty."); - exit(1); } @@ -3259,15 +3299,18 @@ void ObjectMgr::LoadPlayerInfo() continue; } - PlayerClassInfo* pClassInfo = &_playerClassInfo[current_class]; - - if (!pClassInfo->levelInfo) - pClassInfo->levelInfo = new PlayerClassLevelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)]; + PlayerClassInfo* info = _playerClassInfo[current_class]; + if (!info) + { + info = new PlayerClassInfo(); + info->levelInfo = new PlayerClassLevelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)]; + _playerClassInfo[current_class] = info; + } - PlayerClassLevelInfo* pClassLevelInfo = &pClassInfo->levelInfo[current_level-1]; + PlayerClassLevelInfo& levelInfo = info->levelInfo[current_level-1]; - pClassLevelInfo->basehealth = fields[2].GetUInt16(); - pClassLevelInfo->basemana = fields[3].GetUInt16(); + levelInfo.basehealth = fields[2].GetUInt16(); + levelInfo.basemana = fields[3].GetUInt16(); ++count; } @@ -3280,7 +3323,7 @@ void ObjectMgr::LoadPlayerInfo() if (!sChrClassesStore.LookupEntry(class_)) continue; - PlayerClassInfo* pClassInfo = &_playerClassInfo[class_]; + PlayerClassInfo* pClassInfo = _playerClassInfo[class_]; // fatal error if no level 1 data if (!pClassInfo->levelInfo || pClassInfo->levelInfo[0].basehealth == 0) @@ -3351,16 +3394,14 @@ void ObjectMgr::LoadPlayerInfo() continue; } - PlayerInfo* pInfo = &_playerInfo[current_race][current_class]; - - if (!pInfo->levelInfo) - pInfo->levelInfo = new PlayerLevelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)]; - - PlayerLevelInfo* pLevelInfo = &pInfo->levelInfo[current_level-1]; - - for (int i = 0; i < MAX_STATS; i++) + if (PlayerInfo* info = _playerInfo[current_race][current_class]) { - pLevelInfo->stats[i] = fields[i+3].GetUInt8(); + if (!info->levelInfo) + info->levelInfo = new PlayerLevelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)]; + + PlayerLevelInfo& levelInfo = info->levelInfo[current_level-1]; + for (int i = 0; i < MAX_STATS; i++) + levelInfo.stats[i] = fields[i+3].GetUInt8(); } ++count; @@ -3380,10 +3421,8 @@ void ObjectMgr::LoadPlayerInfo() if (!sChrClassesStore.LookupEntry(class_)) continue; - PlayerInfo* pInfo = &_playerInfo[race][class_]; - - // skip non loaded combinations - if (!pInfo->displayId_m || !pInfo->displayId_f) + PlayerInfo* info = _playerInfo[race][class_]; + if (!info) continue; // skip expansion races if not playing with expansion @@ -3395,7 +3434,7 @@ void ObjectMgr::LoadPlayerInfo() continue; // fatal error if no level 1 data - if (!pInfo->levelInfo || pInfo->levelInfo[0].stats[0] == 0) + if (!info->levelInfo || info->levelInfo[0].stats[0] == 0) { sLog->outError(LOG_FILTER_SQL, "Race %i Class %i Level 1 does not have stats data!", race, class_); exit(1); @@ -3404,10 +3443,10 @@ void ObjectMgr::LoadPlayerInfo() // fill level gaps for (uint8 level = 1; level < sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL); ++level) { - if (pInfo->levelInfo[level].stats[0] == 0) + if (info->levelInfo[level].stats[0] == 0) { sLog->outError(LOG_FILTER_SQL, "Race %i Class %i Level %i does not have stats data. Using stats data of level %i.", race, class_, level+1, level); - pInfo->levelInfo[level] = pInfo->levelInfo[level-1]; + info->levelInfo[level] = info->levelInfo[level-1]; } } } @@ -3480,7 +3519,7 @@ void ObjectMgr::GetPlayerClassLevelInfo(uint32 class_, uint8 level, PlayerClassL if (level < 1 || class_ >= MAX_CLASSES) return; - PlayerClassInfo const* pInfo = &_playerClassInfo[class_]; + PlayerClassInfo const* pInfo = _playerClassInfo[class_]; if (level > sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) level = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL); @@ -3493,8 +3532,8 @@ void ObjectMgr::GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, Play if (level < 1 || race >= MAX_RACES || class_ >= MAX_CLASSES) return; - PlayerInfo const* pInfo = &_playerInfo[race][class_]; - if (pInfo->displayId_m == 0 || pInfo->displayId_f == 0) + PlayerInfo const* pInfo = _playerInfo[race][class_]; + if (!pInfo) return; if (level <= sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)) @@ -3506,7 +3545,7 @@ void ObjectMgr::GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, Play void ObjectMgr::BuildPlayerLevelInfo(uint8 race, uint8 _class, uint8 level, PlayerLevelInfo* info) const { // base data (last known level) - *info = _playerInfo[race][_class].levelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)-1]; + *info = _playerInfo[race][_class]->levelInfo[sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)-1]; // if conversion from uint32 to uint8 causes unexpected behaviour, change lvl to uint32 for (uint8 lvl = sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL)-1; lvl < level; ++lvl) @@ -5898,7 +5937,13 @@ void ObjectMgr::LoadAccessRequirements() { uint32 oldMSTime = getMSTime(); - _accessRequirementStore.clear(); // need for reload case + if (!_accessRequirementStore.empty()) + { + for (AccessRequirementContainer::iterator itr = _accessRequirementStore.begin(); itr != _accessRequirementStore.end(); ++itr) + delete itr->second; + + _accessRequirementStore.clear(); // need for reload case + } // 0 1 2 3 4 5 6 7 8 9 QueryResult result = WorldDatabase.Query("SELECT mapid, difficulty, level_min, level_max, item, item2, quest_done_A, quest_done_H, completed_achievement, quest_failed_text FROM access_requirement"); @@ -5920,61 +5965,61 @@ void ObjectMgr::LoadAccessRequirements() uint8 difficulty = fields[1].GetUInt8(); uint32 requirement_ID = MAKE_PAIR32(mapid, difficulty); - AccessRequirement ar; + AccessRequirement* ar = new AccessRequirement(); - ar.levelMin = fields[2].GetUInt8(); - ar.levelMax = fields[3].GetUInt8(); - ar.item = fields[4].GetUInt32(); - ar.item2 = fields[5].GetUInt32(); - ar.quest_A = fields[6].GetUInt32(); - ar.quest_H = fields[7].GetUInt32(); - ar.achievement = fields[8].GetUInt32(); - ar.questFailedText = fields[9].GetString(); + ar->levelMin = fields[2].GetUInt8(); + ar->levelMax = fields[3].GetUInt8(); + ar->item = fields[4].GetUInt32(); + ar->item2 = fields[5].GetUInt32(); + ar->quest_A = fields[6].GetUInt32(); + ar->quest_H = fields[7].GetUInt32(); + ar->achievement = fields[8].GetUInt32(); + ar->questFailedText = fields[9].GetString(); - if (ar.item) + if (ar->item) { - ItemTemplate const* pProto = GetItemTemplate(ar.item); + ItemTemplate const* pProto = GetItemTemplate(ar->item); if (!pProto) { - sLog->outError(LOG_FILTER_GENERAL, "Key item %u does not exist for map %u difficulty %u, removing key requirement.", ar.item, mapid, difficulty); - ar.item = 0; + sLog->outError(LOG_FILTER_GENERAL, "Key item %u does not exist for map %u difficulty %u, removing key requirement.", ar->item, mapid, difficulty); + ar->item = 0; } } - if (ar.item2) + if (ar->item2) { - ItemTemplate const* pProto = GetItemTemplate(ar.item2); + ItemTemplate const* pProto = GetItemTemplate(ar->item2); if (!pProto) { - sLog->outError(LOG_FILTER_GENERAL, "Second item %u does not exist for map %u difficulty %u, removing key requirement.", ar.item2, mapid, difficulty); - ar.item2 = 0; + sLog->outError(LOG_FILTER_GENERAL, "Second item %u does not exist for map %u difficulty %u, removing key requirement.", ar->item2, mapid, difficulty); + ar->item2 = 0; } } - if (ar.quest_A) + if (ar->quest_A) { - if (!GetQuestTemplate(ar.quest_A)) + if (!GetQuestTemplate(ar->quest_A)) { - sLog->outError(LOG_FILTER_SQL, "Required Alliance Quest %u not exist for map %u difficulty %u, remove quest done requirement.", ar.quest_A, mapid, difficulty); - ar.quest_A = 0; + sLog->outError(LOG_FILTER_SQL, "Required Alliance Quest %u not exist for map %u difficulty %u, remove quest done requirement.", ar->quest_A, mapid, difficulty); + ar->quest_A = 0; } } - if (ar.quest_H) + if (ar->quest_H) { - if (!GetQuestTemplate(ar.quest_H)) + if (!GetQuestTemplate(ar->quest_H)) { - sLog->outError(LOG_FILTER_SQL, "Required Horde Quest %u not exist for map %u difficulty %u, remove quest done requirement.", ar.quest_H, mapid, difficulty); - ar.quest_H = 0; + sLog->outError(LOG_FILTER_SQL, "Required Horde Quest %u not exist for map %u difficulty %u, remove quest done requirement.", ar->quest_H, mapid, difficulty); + ar->quest_H = 0; } } - if (ar.achievement) + if (ar->achievement) { - if (!sAchievementStore.LookupEntry(ar.achievement)) + if (!sAchievementStore.LookupEntry(ar->achievement)) { - sLog->outError(LOG_FILTER_SQL, "Required Achievement %u not exist for map %u difficulty %u, remove quest done requirement.", ar.achievement, mapid, difficulty); - ar.achievement = 0; + sLog->outError(LOG_FILTER_SQL, "Required Achievement %u not exist for map %u difficulty %u, remove quest done requirement.", ar->achievement, mapid, difficulty); + ar->achievement = 0; } } @@ -8202,7 +8247,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (!cInfo) { if (player) - ChatHandler(player).SendSysMessage(LANG_COMMAND_VENDORSELECTION); + ChatHandler(player->GetSession()).SendSysMessage(LANG_COMMAND_VENDORSELECTION); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` have data for not existed creature template (Entry: %u), ignore", vendor_entry); return false; @@ -8213,7 +8258,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (!skip_vendors || skip_vendors->count(vendor_entry) == 0) { if (player) - ChatHandler(player).SendSysMessage(LANG_COMMAND_VENDORSELECTION); + ChatHandler(player->GetSession()).SendSysMessage(LANG_COMMAND_VENDORSELECTION); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` have data for not creature template (Entry: %u) without vendor flag, ignore", vendor_entry); @@ -8226,7 +8271,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (!sObjectMgr->GetItemTemplate(item_id)) { if (player) - ChatHandler(player).PSendSysMessage(LANG_ITEM_NOT_FOUND, item_id); + ChatHandler(player->GetSession()).PSendSysMessage(LANG_ITEM_NOT_FOUND, item_id); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` for Vendor (Entry: %u) have in item list non-existed item (%u), ignore", vendor_entry, item_id); return false; @@ -8235,7 +8280,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (ExtendedCost && !sItemExtendedCostStore.LookupEntry(ExtendedCost)) { if (player) - ChatHandler(player).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST, ExtendedCost); + ChatHandler(player->GetSession()).PSendSysMessage(LANG_EXTENDED_COST_NOT_EXIST, ExtendedCost); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` have Item (Entry: %u) with wrong ExtendedCost (%u) for vendor (%u), ignore", item_id, ExtendedCost, vendor_entry); return false; @@ -8244,7 +8289,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (maxcount > 0 && incrtime == 0) { if (player) - ChatHandler(player).PSendSysMessage("MaxCount != 0 (%u) but IncrTime == 0", maxcount); + ChatHandler(player->GetSession()).PSendSysMessage("MaxCount != 0 (%u) but IncrTime == 0", maxcount); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` has `maxcount` (%u) for item %u of vendor (Entry: %u) but `incrtime`=0, ignore", maxcount, item_id, vendor_entry); return false; @@ -8252,7 +8297,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max else if (maxcount == 0 && incrtime > 0) { if (player) - ChatHandler(player).PSendSysMessage("MaxCount == 0 but IncrTime<>= 0"); + ChatHandler(player->GetSession()).PSendSysMessage("MaxCount == 0 but IncrTime<>= 0"); else sLog->outError(LOG_FILTER_SQL, "Table `(game_event_)npc_vendor` has `maxcount`=0 for item %u of vendor (Entry: %u) but `incrtime`<>0, ignore", item_id, vendor_entry); return false; @@ -8265,7 +8310,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (vItems->FindItemCostPair(item_id, ExtendedCost)) { if (player) - ChatHandler(player).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST, item_id, ExtendedCost); + ChatHandler(player->GetSession()).PSendSysMessage(LANG_ITEM_ALREADY_IN_LIST, item_id, ExtendedCost); else sLog->outError(LOG_FILTER_SQL, "Table `npc_vendor` has duplicate items %u (with extended cost %u) for vendor (Entry: %u), ignoring", item_id, ExtendedCost, vendor_entry); return false; @@ -8274,7 +8319,7 @@ bool ObjectMgr::IsVendorItemValid(uint32 vendor_entry, uint32 item_id, int32 max if (vItems->GetItemCount() >= MAX_VENDOR_ITEMS) { if (player) - ChatHandler(player).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS); + ChatHandler(player->GetSession()).SendSysMessage(LANG_COMMAND_ADDVENDORITEMITEMS); else sLog->outError(LOG_FILTER_SQL, "Table `npc_vendor` has too many items (%u >= %i) for vendor (Entry: %u), ignore", vItems->GetItemCount(), MAX_VENDOR_ITEMS, vendor_entry); return false; @@ -8695,3 +8740,15 @@ VehicleAccessoryList const* ObjectMgr::GetVehicleAccessoryList(Vehicle* veh) con return &itr->second; return NULL; } + +PlayerInfo const* ObjectMgr::GetPlayerInfo(uint32 race, uint32 class_) const +{ + if (race >= MAX_RACES) + return NULL; + if (class_ >= MAX_CLASSES) + return NULL; + PlayerInfo const* info = _playerInfo[race][class_]; + if (!info) + return NULL; + return info; +} diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 29ca353bdd7..3dcab3df951 100755 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -23,7 +23,6 @@ #include "Object.h" #include "Bag.h" #include "Creature.h" -#include "Player.h" #include "DynamicObject.h" #include "GameObject.h" #include "Corpse.h" @@ -44,6 +43,11 @@ #include <functional> class Item; +struct AccessRequirement; +struct PlayerClassInfo; +struct PlayerClassLevelInfo; +struct PlayerInfo; +struct PlayerLevelInfo; // GCC have alternative #pragma pack(N) syntax and old gcc version not support pack(push, N), also any gcc version not support it at some platform #if defined(__GNUC__) @@ -65,6 +69,41 @@ struct PageText #pragma pack(pop) #endif +// DB scripting commands +enum ScriptCommands +{ + SCRIPT_COMMAND_TALK = 0, // source/target = Creature, target = any, datalong = talk type (0=say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text), datalong2 & 1 = player talk (instead of creature), dataint = string_id + SCRIPT_COMMAND_EMOTE = 1, // source/target = Creature, datalong = emote id, datalong2 = 0: set emote state; > 0: play emote state + SCRIPT_COMMAND_FIELD_SET = 2, // source/target = Creature, datalong = field id, datalog2 = value + SCRIPT_COMMAND_MOVE_TO = 3, // source/target = Creature, datalong2 = time to reach, x/y/z = destination + SCRIPT_COMMAND_FLAG_SET = 4, // source/target = Creature, datalong = field id, datalog2 = bitmask + SCRIPT_COMMAND_FLAG_REMOVE = 5, // source/target = Creature, datalong = field id, datalog2 = bitmask + SCRIPT_COMMAND_TELEPORT_TO = 6, // source/target = Creature/Player (see datalong2), datalong = map_id, datalong2 = 0: Player; 1: Creature, x/y/z = destination, o = orientation + SCRIPT_COMMAND_QUEST_EXPLORED = 7, // target/source = Player, target/source = GO/Creature, datalong = quest id, datalong2 = distance or 0 + SCRIPT_COMMAND_KILL_CREDIT = 8, // target/source = Player, datalong = creature entry, datalong2 = 0: personal credit, 1: group credit + SCRIPT_COMMAND_RESPAWN_GAMEOBJECT = 9, // source = WorldObject (summoner), datalong = GO guid, datalong2 = despawn delay + SCRIPT_COMMAND_TEMP_SUMMON_CREATURE = 10, // source = WorldObject (summoner), datalong = creature entry, datalong2 = despawn delay, x/y/z = summon position, o = orientation + SCRIPT_COMMAND_OPEN_DOOR = 11, // source = Unit, datalong = GO guid, datalong2 = reset delay (min 15) + SCRIPT_COMMAND_CLOSE_DOOR = 12, // source = Unit, datalong = GO guid, datalong2 = reset delay (min 15) + SCRIPT_COMMAND_ACTIVATE_OBJECT = 13, // source = Unit, target = GO + SCRIPT_COMMAND_REMOVE_AURA = 14, // source (datalong2 != 0) or target (datalong2 == 0) = Unit, datalong = spell id + SCRIPT_COMMAND_CAST_SPELL = 15, // source and/or target = Unit, datalong2 = cast direction (0: s->t 1: s->s 2: t->t 3: t->s 4: s->creature with dataint entry), dataint & 1 = triggered flag + SCRIPT_COMMAND_PLAY_SOUND = 16, // source = WorldObject, target = none/Player, datalong = sound id, datalong2 (bitmask: 0/1=anyone/player, 0/2=without/with distance dependency, so 1|2 = 3 is target with distance dependency) + SCRIPT_COMMAND_CREATE_ITEM = 17, // target/source = Player, datalong = item entry, datalong2 = amount + SCRIPT_COMMAND_DESPAWN_SELF = 18, // target/source = Creature, datalong = despawn delay + + SCRIPT_COMMAND_LOAD_PATH = 20, // source = Unit, datalong = path id, datalong2 = is repeatable + SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT = 21, // source = WorldObject (if present used as a search center), datalong = script id, datalong2 = unit lowguid, dataint = script table to use (see ScriptsType) + SCRIPT_COMMAND_KILL = 22, // source/target = Creature, dataint = remove corpse attribute + + // TrinityCore only + SCRIPT_COMMAND_ORIENTATION = 30, // source = Unit, target (datalong > 0) = Unit, datalong = > 0 turn source to face target, o = orientation + SCRIPT_COMMAND_EQUIP = 31, // soucre = Creature, datalong = equipment id + SCRIPT_COMMAND_MODEL = 32, // source = Creature, datalong = model id + SCRIPT_COMMAND_CLOSE_GOSSIP = 33, // source = Player + SCRIPT_COMMAND_PLAYMOVIE = 34 // source = Player, datalong = movie id +}; + // Benchmarked: Faster than UNORDERED_MAP (insert/find) typedef std::map<uint32, PageText> PageTextContainer; @@ -598,7 +637,7 @@ class ObjectMgr typedef UNORDERED_MAP<uint32, uint32> AreaTriggerScriptContainer; - typedef UNORDERED_MAP<uint32, AccessRequirement> AccessRequirementContainer; + typedef UNORDERED_MAP<uint32, AccessRequirement*> AccessRequirementContainer; typedef UNORDERED_MAP<uint32, RepRewardRate > RepRewardRateContainer; typedef UNORDERED_MAP<uint32, ReputationOnKillEntry> RepOnKillContainer; @@ -647,21 +686,11 @@ class ObjectMgr { if (class_ >= MAX_CLASSES) return NULL; - return &_playerClassInfo[class_]; + return _playerClassInfo[class_]; } void GetPlayerClassLevelInfo(uint32 class_, uint8 level, PlayerClassLevelInfo* info) const; - PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const - { - if (race >= MAX_RACES) - return NULL; - if (class_ >= MAX_CLASSES) - return NULL; - PlayerInfo const* info = &_playerInfo[race][class_]; - if (info->displayId_m == 0 || info->displayId_f == 0) - return NULL; - return info; - } + PlayerInfo const* GetPlayerInfo(uint32 race, uint32 class_) const; void GetPlayerLevelInfo(uint32 race, uint32 class_, uint8 level, PlayerLevelInfo* info) const; @@ -722,7 +751,7 @@ class ObjectMgr { AccessRequirementContainer::const_iterator itr = _accessRequirementStore.find(MAKE_PAIR32(mapid, difficulty)); if (itr != _accessRequirementStore.end()) - return &itr->second; + return itr->second; return NULL; } @@ -1233,11 +1262,11 @@ class ObjectMgr // PetLevelInfoContainer[creature_id][level] PetLevelInfoContainer _petInfoStore; // [creature_id][level] - PlayerClassInfo _playerClassInfo[MAX_CLASSES]; + PlayerClassInfo* _playerClassInfo[MAX_CLASSES]; void BuildPlayerLevelInfo(uint8 race, uint8 class_, uint8 level, PlayerLevelInfo* plinfo) const; - PlayerInfo _playerInfo[MAX_RACES][MAX_CLASSES]; + PlayerInfo* _playerInfo[MAX_RACES][MAX_CLASSES]; typedef std::vector<uint32> PlayerXPperLevel; // [level] PlayerXPperLevel _playerXPperLevel; diff --git a/src/server/game/Grids/Notifiers/GridNotifiers.h b/src/server/game/Grids/Notifiers/GridNotifiers.h index db4dc819557..752c6ec068e 100755 --- a/src/server/game/Grids/Notifiers/GridNotifiers.h +++ b/src/server/game/Grids/Notifiers/GridNotifiers.h @@ -31,6 +31,7 @@ #include "Unit.h" #include "CreatureAI.h" #include "Spell.h" +#include "WorldSession.h" class Player; //class Map; diff --git a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h index e3cda4dd76d..2d60678d4ff 100755 --- a/src/server/game/Grids/Notifiers/GridNotifiersImpl.h +++ b/src/server/game/Grids/Notifiers/GridNotifiersImpl.h @@ -26,6 +26,7 @@ #include "UpdateData.h" #include "CreatureAI.h" #include "SpellAuras.h" +#include "Opcodes.h" template<class T> inline void Trinity::VisibleNotifier::Visit(GridRefManager<T> &m) diff --git a/src/server/game/Groups/Group.h b/src/server/game/Groups/Group.h index a00b7e1ef3a..b20a1bd9dd4 100755 --- a/src/server/game/Groups/Group.h +++ b/src/server/game/Groups/Group.h @@ -19,16 +19,14 @@ #ifndef TRINITYCORE_GROUP_H #define TRINITYCORE_GROUP_H -#include "Battleground.h" #include "DBCEnums.h" #include "GroupRefManager.h" #include "LootMgr.h" #include "QueryResult.h" #include "SharedDefines.h" -#include "Player.h" -#include "Battlefield.h" -#include "BattlefieldMgr.h" +class Battlefield; +class Battleground; class Creature; class GroupReference; class InstanceSave; diff --git a/src/server/game/Groups/GroupMgr.cpp b/src/server/game/Groups/GroupMgr.cpp index 77b3a304f6b..8283075a226 100644 --- a/src/server/game/Groups/GroupMgr.cpp +++ b/src/server/game/Groups/GroupMgr.cpp @@ -18,6 +18,8 @@ #include "Common.h" #include "GroupMgr.h" #include "InstanceSaveMgr.h" +#include "World.h" +#include "DBCStores.h" GroupMgr::GroupMgr() { diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp index 8f7359d9d44..a03e94ff190 100755 --- a/src/server/game/Guilds/Guild.cpp +++ b/src/server/game/Guilds/Guild.cpp @@ -16,19 +16,72 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include "AccountMgr.h" +#include "CalendarMgr.h" +#include "Chat.h" +#include "Config.h" #include "DatabaseEnv.h" #include "Guild.h" #include "GuildMgr.h" +#include "Language.h" +#include "Log.h" #include "ScriptMgr.h" -#include "Chat.h" -#include "Config.h" #include "SocialMgr.h" -#include "Log.h" -#include "AccountMgr.h" +#include "Opcodes.h" #define MAX_GUILD_BANK_TAB_TEXT_LEN 500 #define EMBLEM_PRICE 10 * GOLD +std::string _GetGuildEventString(GuildEvents event) +{ + switch (event) + { + case GE_PROMOTION: + return "Member promotion"; + case GE_DEMOTION: + return "Member demotion"; + case GE_MOTD: + return "Guild MOTD"; + case GE_JOINED: + return "Member joined"; + case GE_LEFT: + return "Member left"; + case GE_REMOVED: + return "Member removed"; + case GE_LEADER_IS: + return "Leader is"; + case GE_LEADER_CHANGED: + return "Leader changed"; + case GE_DISBANDED: + return "Guild disbanded"; + case GE_TABARDCHANGE: + return "Tabard change"; + case GE_RANK_UPDATED: + return "Rank updated"; + case GE_RANK_DELETED: + return "Rank deleted"; + case GE_SIGNED_ON: + return "Member signed on"; + case GE_SIGNED_OFF: + return "Member signed off"; + case GE_GUILDBANKBAGSLOTS_CHANGED: + return "Bank bag slots changed"; + case GE_BANK_TAB_PURCHASED: + return "Bank tab purchased"; + case GE_BANK_TAB_UPDATED: + return "Bank tab updated"; + case GE_BANK_MONEY_SET: + return "Bank money set"; + case GE_BANK_MONEY_CHANGED: + return "Bank money changed"; + case GE_BANK_TEXT_CHANGED: + return "Bank tab text changed"; + default: + break; + } + return "<None>"; +} + inline uint32 _GetGuildBankTabPrice(uint8 tabId) { switch (tabId) @@ -240,9 +293,9 @@ void Guild::RankInfo::CreateMissingTabsIfNeeded(uint8 tabs, SQLTransaction& tran PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_INS_GUILD_BANK_RIGHT); stmt->setUInt32(0, m_guildId); - stmt->setUInt8 (1, i); - stmt->setUInt8 (2, m_rankId); - stmt->setUInt32(3, rightsAndSlots.GetRights()); + stmt->setUInt8(1, i); + stmt->setUInt8(2, m_rankId); + stmt->setUInt8(3, rightsAndSlots.GetRights()); stmt->setUInt32(4, rightsAndSlots.GetSlots()); trans->Append(stmt); } @@ -1428,24 +1481,21 @@ void Guild::HandleBuyBankTab(WorldSession* session, uint8 tabId) if (_GetPurchasedTabsSize() >= GUILD_BANK_MAX_TABS) return; - if (tabId != _GetPurchasedTabsSize()) - return; + if (tabId != _GetPurchasedTabsSize()) + return; - uint32 tabCost = _GetGuildBankTabPrice(tabId) * GOLD; - if (!tabCost) - return; + uint32 tabCost = _GetGuildBankTabPrice(tabId) * GOLD; + if (!tabCost) + return; - if (!player->HasEnoughMoney(tabCost)) // Should not happen, this is checked by client - return; + if (!player->HasEnoughMoney(tabCost)) // Should not happen, this is checked by client + return; - player->ModifyMoney(-int32(tabCost)); + player->ModifyMoney(-int32(tabCost)); - uint8 rankId = member->GetRankId(); _CreateNewBankTab(); - _SetRankBankMoneyPerDay(rankId, uint32(GUILD_WITHDRAW_MONEY_UNLIMITED)); - GuildBankRightsAndSlots rightsAndSlots(tabId); - _SetRankBankTabRightsAndSlots(rankId, rightsAndSlots); - SendBankTabsInfo(session); + _BroadcastEvent(GE_BANK_TAB_PURCHASED, 0); + SendPermissions(session); /// Hack to force client to update permissions } void Guild::HandleInviteMember(WorldSession* session, std::string const& name) @@ -1532,6 +1582,8 @@ void Guild::HandleLeaveMember(WorldSession* session) SendCommandResult(session, GUILD_COMMAND_QUIT, ERR_GUILD_COMMAND_SUCCESS, m_name); } + + sCalendarMgr->RemovePlayerGuildEventsAndSignups(player->GetGUID(), GetId()); } void Guild::HandleRemoveMember(WorldSession* session, std::string const& name) @@ -2091,6 +2143,39 @@ void Guild::BroadcastPacket(WorldPacket* packet) const player->GetSession()->SendPacket(packet); } +void Guild::MassInviteToEvent(WorldSession* session, uint32 minLevel, uint32 maxLevel, uint32 minRank) +{ + uint32 count = 0; + + WorldPacket data(SMSG_CALENDAR_FILTER_GUILD); + data << uint32(count); // count placeholder + + for (Members::const_iterator itr = m_members.begin(); itr != m_members.end(); ++itr) + { + // not sure if needed, maybe client checks it as well + if (count >= CALENDAR_MAX_INVITES) + { + if (Player* player = session->GetPlayer()) + sCalendarMgr->SendCalendarCommandResult(player->GetGUID(), CALENDAR_ERROR_INVITES_EXCEEDED); + return; + } + + Member* member = itr->second; + uint32 level = Player::GetLevelFromDB(member->GetGUID()); + + if (member->GetGUID() != session->GetPlayer()->GetGUID() && level >= minLevel && level <= maxLevel && member->IsRankNotLower(minRank)) + { + data.appendPackGUID(member->GetGUID()); + data << uint8(0); // unk + ++count; + } + } + + data.put<uint32>(0, count); + + session->SendPacket(&data); +} + // Members handling bool Guild::AddMember(uint64 guid, uint8 rankId) { @@ -2299,6 +2384,10 @@ void Guild::_CreateNewBankTab() stmt->setUInt8 (1, tabId); trans->Append(stmt); + ++tabId; + for (Ranks::iterator itr = m_ranks.begin(); itr != m_ranks.end(); ++itr) + (*itr).CreateMissingTabsIfNeeded(tabId, trans, false); + CharacterDatabase.CommitTransaction(trans); } @@ -2734,7 +2823,9 @@ void Guild::_BroadcastEvent(GuildEvents guildEvent, uint64 guid, const char* par data << uint64(guid); BroadcastPacket(&data); - sLog->outDebug(LOG_FILTER_GUILD, "SMSG_GUILD_EVENT [Broadcast] Event: %u", guildEvent); + + if (sLog->ShouldLog(LOG_FILTER_GUILD, LOG_LEVEL_DEBUG)) + sLog->outDebug(LOG_FILTER_GUILD, "SMSG_GUILD_EVENT [Broadcast] Event: %s (%u)", _GetGuildEventString(guildEvent).c_str(), guildEvent); } void Guild::_SendBankList(WorldSession* session /* = NULL*/, uint8 tabId /*= 0*/, bool sendAllSlots /*= false*/, SlotIds *slots /*= NULL*/) const diff --git a/src/server/game/Guilds/Guild.h b/src/server/game/Guilds/Guild.h index a8bf5dcdb62..2f43245159b 100755 --- a/src/server/game/Guilds/Guild.h +++ b/src/server/game/Guilds/Guild.h @@ -711,6 +711,8 @@ public: void BroadcastPacketToRank(WorldPacket* packet, uint8 rankId) const; void BroadcastPacket(WorldPacket* packet) const; + void MassInviteToEvent(WorldSession* session, uint32 minLevel, uint32 maxLevel, uint32 minRank); + template<class Do> void BroadcastWorker(Do& _do, Player* except = NULL) { diff --git a/src/server/game/Handlers/ArenaTeamHandler.cpp b/src/server/game/Handlers/ArenaTeamHandler.cpp index d3738883d6d..b8592fd846e 100755 --- a/src/server/game/Handlers/ArenaTeamHandler.cpp +++ b/src/server/game/Handlers/ArenaTeamHandler.cpp @@ -27,6 +27,7 @@ #include "ObjectMgr.h" #include "SocialMgr.h" #include "ArenaTeamMgr.h" +#include "Opcodes.h" void WorldSession::HandleInspectArenaTeamsOpcode(WorldPacket & recvData) { diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index 3c3a6978384..7e23429be2f 100755 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -24,6 +24,7 @@ #include "AuctionHouseMgr.h" #include "Log.h" +#include "Language.h" #include "Opcodes.h" #include "UpdateMask.h" #include "Util.h" diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp index 3a359704916..0a076dfaa34 100755 --- a/src/server/game/Handlers/BattleGroundHandler.cpp +++ b/src/server/game/Handlers/BattleGroundHandler.cpp @@ -342,8 +342,6 @@ void WorldSession::HandleBattlefieldListOpcode(WorldPacket &recvData) void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message"); - uint8 type; // arenatype if arena uint8 unk2; // unk, can be 0x0 (may be if was invited?) and 0x1 uint32 bgTypeId_; // type id from dbc @@ -351,16 +349,17 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData) uint8 action; // enter battle 0x1, leave queue 0x0 recvData >> type >> unk2 >> bgTypeId_ >> unk >> action; - if (!sBattlemasterListStore.LookupEntry(bgTypeId_)) { - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "BattlegroundHandler: invalid bgtype (%u) with player (Name: %s, GUID: %u) received.", bgTypeId_, _player->GetName().c_str(), _player->GetGUIDLow()); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u. Invalid BgType!", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action); return; } if (!_player->InBattlegroundQueue()) { - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "BattlegroundHandler: Invalid CMSG_BATTLEFIELD_PORT received from player (Name: %s, GUID: %u), he is not in bg_queue.", _player->GetName().c_str(), _player->GetGUIDLow()); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u. Player not in queue!", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action); return; } @@ -372,27 +371,39 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData) GroupQueueInfo ginfo; if (!bgQueue.GetPlayerGroupInfoData(_player->GetGUID(), &ginfo)) { - sLog->outError(LOG_FILTER_NETWORKIO, "BattlegroundHandler: itrplayerstatus not found."); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u. Player not in queue (No player Group Info)!", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action); return; } // if action == 1, then instanceId is required if (!ginfo.IsInvitedToBGInstanceGUID && action == 1) { - sLog->outError(LOG_FILTER_NETWORKIO, "BattlegroundHandler: instance not found."); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u. Player is not invited to any bg!", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action); return; } Battleground* bg = sBattlegroundMgr->GetBattleground(ginfo.IsInvitedToBGInstanceGUID, bgTypeId); - - // bg template might and must be used in case of leaving queue, when instance is not created yet - if (!bg && action == 0) - bg = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId); if (!bg) { - sLog->outError(LOG_FILTER_NETWORKIO, "BattlegroundHandler: bg_template not found for type id %u.", bgTypeId); - return; + if (action) + { + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u. Cant find BG with id %u!", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action, ginfo.IsInvitedToBGInstanceGUID); + return; + } + + bg = sBattlegroundMgr->GetBattlegroundTemplate(bgTypeId); + if (!bg) + { + sLog->outError(LOG_FILTER_NETWORKIO, "BattlegroundHandler: bg_template not found for type id %u.", bgTypeId); + return; + } } + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "CMSG_BATTLEFIELD_PORT %s ArenaType: %u, Unk: %u, BgType: %u, Action: %u.", + GetPlayerInfo().c_str(), type, unk2, bgTypeId_, action); + // expected bracket entry PvPDifficultyEntry const* bracketEntry = GetBattlegroundBracketByLevel(bg->GetMapId(), _player->getLevel()); if (!bracketEntry) @@ -409,86 +420,82 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket &recvData) sBattlegroundMgr->BuildGroupJoinedBattlegroundPacket(&data2, ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS); _player->GetSession()->SendPacket(&data2); action = 0; - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player %s (%u) has a deserter debuff, do not port him to battleground!", _player->GetName().c_str(), _player->GetGUIDLow()); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Player %s (%u) has a deserter debuff, do not port him to battleground!", _player->GetName().c_str(), _player->GetGUIDLow()); } //if player don't match battleground max level, then do not allow him to enter! (this might happen when player leveled up during his waiting in queue if (_player->getLevel() > bg->GetMaxLevel()) { - sLog->outError(LOG_FILTER_NETWORKIO, "Battleground: Player %s (%u) has level (%u) higher than maxlevel (%u) of battleground (%u)! Do not port him to battleground!", + sLog->outError(LOG_FILTER_NETWORKIO, "Player %s (%u) has level (%u) higher than maxlevel (%u) of battleground (%u)! Do not port him to battleground!", _player->GetName().c_str(), _player->GetGUIDLow(), _player->getLevel(), bg->GetMaxLevel(), bg->GetTypeID()); action = 0; } } uint32 queueSlot = _player->GetBattlegroundQueueIndex(bgQueueTypeId); WorldPacket data; - switch (action) + if (action) { - case 1: // port to battleground - if (!_player->IsInvitedForBattlegroundQueueType(bgQueueTypeId)) - return; // cheating? + if (!_player->IsInvitedForBattlegroundQueueType(bgQueueTypeId)) + return; // cheating? - if (!_player->InBattleground()) - _player->SetBattlegroundEntryPoint(); + if (!_player->InBattleground()) + _player->SetBattlegroundEntryPoint(); - // resurrect the player - if (!_player->isAlive()) - { - _player->ResurrectPlayer(1.0f); - _player->SpawnCorpseBones(); - } - // stop taxi flight at port - if (_player->isInFlight()) - { - _player->GetMotionMaster()->MovementExpired(); - _player->CleanupAfterTaxiFlight(); - } + // resurrect the player + if (!_player->isAlive()) + { + _player->ResurrectPlayer(1.0f); + _player->SpawnCorpseBones(); + } + // stop taxi flight at port + if (_player->isInFlight()) + { + _player->GetMotionMaster()->MovementExpired(); + _player->CleanupAfterTaxiFlight(); + } - sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime(), bg->GetArenaType()); - _player->GetSession()->SendPacket(&data); - // remove battleground queue status from BGmgr - bgQueue.RemovePlayer(_player->GetGUID(), false); - // this is still needed here if battleground "jumping" shouldn't add deserter debuff - // also this is required to prevent stuck at old battleground after SetBattlegroundId set to new - if (Battleground* currentBg = _player->GetBattleground()) - currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true); - - // set the destination instance id - _player->SetBattlegroundId(bg->GetInstanceID(), bgTypeId); - // set the destination team - _player->SetBGTeam(ginfo.Team); - // bg->HandleBeforeTeleportToBattleground(_player); - sBattlegroundMgr->SendToBattleground(_player, ginfo.IsInvitedToBGInstanceGUID, bgTypeId); - // add only in HandleMoveWorldPortAck() - // bg->AddPlayer(_player, team); - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u.", _player->GetName().c_str(), _player->GetGUIDLow(), bg->GetInstanceID(), bg->GetTypeID(), bgQueueTypeId); - break; - case 0: // leave queue - if (bg->isArena() && bg->GetStatus() > STATUS_WAIT_QUEUE) - return; + sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime(), bg->GetArenaType()); + _player->GetSession()->SendPacket(&data); + // remove battleground queue status from BGmgr + bgQueue.RemovePlayer(_player->GetGUID(), false); + // this is still needed here if battleground "jumping" shouldn't add deserter debuff + // also this is required to prevent stuck at old battleground after SetBattlegroundId set to new + if (Battleground* currentBg = _player->GetBattleground()) + currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true); + + // set the destination instance id + _player->SetBattlegroundId(bg->GetInstanceID(), bgTypeId); + // set the destination team + _player->SetBGTeam(ginfo.Team); + // bg->HandleBeforeTeleportToBattleground(_player); + sBattlegroundMgr->SendToBattleground(_player, ginfo.IsInvitedToBGInstanceGUID, bgTypeId); + // add only in HandleMoveWorldPortAck() + // bg->AddPlayer(_player, team); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u.", _player->GetName().c_str(), _player->GetGUIDLow(), bg->GetInstanceID(), bg->GetTypeID(), bgQueueTypeId); + } + else // leave queue + { + if (bg->isArena() && bg->GetStatus() > STATUS_WAIT_QUEUE) + return; - // if player leaves rated arena match before match start, it is counted as he played but he lost - if (ginfo.IsRated && ginfo.IsInvitedToBGInstanceGUID) + // if player leaves rated arena match before match start, it is counted as he played but he lost + if (ginfo.IsRated && ginfo.IsInvitedToBGInstanceGUID) + { + ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(ginfo.Team); + if (at) { - ArenaTeam* at = sArenaTeamMgr->GetArenaTeamById(ginfo.Team); - if (at) - { - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "UPDATING memberLost's personal arena rating for %u by opponents rating: %u, because he has left queue!", GUID_LOPART(_player->GetGUID()), ginfo.OpponentsTeamRating); - at->MemberLost(_player, ginfo.OpponentsMatchmakerRating); - at->SaveToDB(); - } + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "UPDATING memberLost's personal arena rating for %u by opponents rating: %u, because he has left queue!", GUID_LOPART(_player->GetGUID()), ginfo.OpponentsTeamRating); + at->MemberLost(_player, ginfo.OpponentsMatchmakerRating); + at->SaveToDB(); } - _player->RemoveBattlegroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs - sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_NONE, 0, 0, 0); - bgQueue.RemovePlayer(_player->GetGUID(), true); - // player left queue, we should update it - do not update Arena Queue - if (!ginfo.ArenaType) - sBattlegroundMgr->ScheduleQueueUpdate(ginfo.ArenaMatchmakerRating, ginfo.ArenaType, bgQueueTypeId, bgTypeId, bracketEntry->GetBracketId()); - SendPacket(&data); - sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player %s (%u) left queue for bgtype %u, queue type %u.", _player->GetName().c_str(), _player->GetGUIDLow(), bg->GetTypeID(), bgQueueTypeId); - break; - default: - sLog->outError(LOG_FILTER_NETWORKIO, "Battleground port: unknown action %u", action); - break; + } + _player->RemoveBattlegroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs + sBattlegroundMgr->BuildBattlegroundStatusPacket(&data, bg, queueSlot, STATUS_NONE, 0, 0, 0); + bgQueue.RemovePlayer(_player->GetGUID(), true); + // player left queue, we should update it - do not update Arena Queue + if (!ginfo.ArenaType) + sBattlegroundMgr->ScheduleQueueUpdate(ginfo.ArenaMatchmakerRating, ginfo.ArenaType, bgQueueTypeId, bgTypeId, bracketEntry->GetBracketId()); + SendPacket(&data); + sLog->outDebug(LOG_FILTER_BATTLEGROUND, "Battleground: player %s (%u) left queue for bgtype %u, queue type %u.", _player->GetName().c_str(), _player->GetGUIDLow(), bg->GetTypeID(), bgQueueTypeId); } } diff --git a/src/server/game/Handlers/CalendarHandler.cpp b/src/server/game/Handlers/CalendarHandler.cpp index 0cecd3d615a..876a0fc4463 100755 --- a/src/server/game/Handlers/CalendarHandler.cpp +++ b/src/server/game/Handlers/CalendarHandler.cpp @@ -19,131 +19,116 @@ /* ----- Opcodes Not Used yet ----- -SMSG_CALENDAR_CLEAR_PENDING_ACTION SendCalendarClearPendingAction() -SMSG_CALENDAR_RAID_LOCKOUT_UPDATED SendCalendarRaidLockoutUpdated(InstanceSave const* save) - ------ Opcodes without Sniffs ----- -SMSG_CALENDAR_FILTER_GUILD [ for (... uint32(count) { packguid(???), uint8(???) } ] -SMSG_CALENDAR_ARENA_TEAM [ for (... uint32(count) { packguid(???), uint8(???) } ] -CMSG_CALENDAR_EVENT_INVITE_NOTES [ packguid(Invitee), uint64(inviteId), string(Text), Boolean(Unk) ] -SMSG_CALENDAR_EVENT_INVITE_NOTES [ uint32(unk1), uint32(unk2), uint32(unk3), uint32(unk4), uint32(unk5) ] +SMSG_CALENDAR_EVENT_INVITE_NOTES [ packguid(Invitee), uint64(inviteId), string(Text), Boolean(Unk) ] +?CMSG_CALENDAR_EVENT_INVITE_NOTES [ uint32(unk1), uint32(unk2), uint32(unk3), uint32(unk4), uint32(unk5) ] SMSG_CALENDAR_EVENT_INVITE_NOTES_ALERT [ uint64(inviteId), string(Text) ] -SMSG_CALENDAR_EVENT_INVITE_STATUS_ALERT [ Structure unkown ] +SMSG_CALENDAR_EVENT_INVITE_STATUS_ALERT [ uint64(eventId), uint32(eventTime), uint32(unkFlag), uint8(deletePending) ] +SMSG_CALENDAR_RAID_LOCKOUT_UPDATED SendCalendarRaidLockoutUpdated(InstanceSave const* save) -*/ +----- TODO ----- -#include "Common.h" -#include "WorldPacket.h" -#include "WorldSession.h" +Finish complains' handling - what to do with received complains and how to respond? +Find out what to do with all "not used yet" opcodes +Correct errors sending (event/invite not found, invites exceeded, event already passed, permissions etc.) +Fix locked events to be displayed properly and response time shouldn't be shown for people that haven't respond yet +Copied events should probably have a new owner + +*/ #include "InstanceSaveMgr.h" #include "Log.h" #include "Opcodes.h" #include "Player.h" +#include "SocialMgr.h" #include "CalendarMgr.h" #include "ObjectMgr.h" #include "ObjectAccessor.h" #include "DatabaseEnv.h" +#include "GuildMgr.h" +#include "ArenaTeamMgr.h" +#include "WorldSession.h" void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) { uint64 guid = _player->GetGUID(); sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_CALENDAR [" UI64FMTD "]", guid); - time_t cur_time = time_t(time(NULL)); + time_t currTime = time(NULL); - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR [" UI64FMTD "]", guid); - WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Impossible to get the correct size without doing a double iteration of some elements + WorldPacket data(SMSG_CALENDAR_SEND_CALENDAR, 1000); // Average size if no instance - CalendarInviteIdList const& invites = sCalendarMgr->GetPlayerInvites(guid); + std::vector<CalendarInvite*> invites = sCalendarMgr->GetPlayerInvites(guid); data << uint32(invites.size()); - for (CalendarInviteIdList::const_iterator it = invites.begin(); it != invites.end(); ++it) + for (std::vector<CalendarInvite*>::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) { - CalendarInvite* invite = sCalendarMgr->GetInvite(*it); - CalendarEvent* calendarEvent = invite ? sCalendarMgr->GetEvent(invite->GetEventId()) : NULL; + data << uint64((*itr)->GetEventId()); + data << uint64((*itr)->GetInviteId()); + data << uint8((*itr)->GetStatus()); + data << uint8((*itr)->GetRank()); - if (calendarEvent) + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent((*itr)->GetEventId())) { - data << uint64(invite->GetEventId()); - data << uint64(invite->GetInviteId()); - data << uint8(invite->GetStatus()); - data << uint8(invite->GetRank()); - data << uint8(calendarEvent->GetGuildId() != 0); + data << uint8(calendarEvent->IsGuildEvent()); data.appendPackGUID(calendarEvent->GetCreatorGUID()); } else { - sLog->outError(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR: No Invite found with id [" UI64FMTD "]", *it); - data << uint64(0); - data << uint64(0); - data << uint8(0); data << uint8(0); - data << uint8(0); - data.appendPackGUID(0); + data.appendPackGUID((*itr)->GetSenderGUID()); } } - CalendarEventIdList const& events = sCalendarMgr->GetPlayerEvents(guid); - data << uint32(events.size()); - for (CalendarEventIdList::const_iterator it = events.begin(); it != events.end(); ++it) + CalendarEventStore playerEvents = sCalendarMgr->GetPlayerEvents(guid); + data << uint32(playerEvents.size()); + for (CalendarEventStore::const_iterator itr = playerEvents.begin(); itr != playerEvents.end(); ++itr) { - if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(*it)) - { - data << uint64(*it); - data << calendarEvent->GetTitle(); - data << uint32(calendarEvent->GetType()); - data.AppendPackedTime(calendarEvent->GetTime()); - data << uint32(calendarEvent->GetFlags()); - data << uint32(calendarEvent->GetDungeonId()); - data.appendPackGUID(calendarEvent->GetCreatorGUID()); - } - else - { - sLog->outError(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_CALENDAR: No Event found with id [" UI64FMTD "]", *it); - data << uint64(0); - data << uint8(0); - data << uint32(0); - data << uint32(0); - data << uint32(0); - data << uint32(0); - data.appendPackGUID(0); - } + CalendarEvent* calendarEvent = *itr; + + data << uint64(calendarEvent->GetEventId()); + data << calendarEvent->GetTitle(); + data << uint32(calendarEvent->GetType()); + data.AppendPackedTime(calendarEvent->GetEventTime()); + data << uint32(calendarEvent->GetFlags()); + data << int32(calendarEvent->GetDungeonId()); + data.appendPackGUID(calendarEvent->GetCreatorGUID()); } - data << uint32(cur_time); // server time - data.AppendPackedTime(cur_time); // server time - - uint32 counter = 0; - size_t p_counter = data.wpos(); - data << uint32(counter); // instance save count + data << uint32(currTime); // server time + data.AppendPackedTime(currTime); // zone time + ByteBuffer dataBuffer; + uint32 boundCounter = 0; for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) - for (Player::BoundInstancesMap::const_iterator itr = _player->m_boundInstances[i].begin(); itr != _player->m_boundInstances[i].end(); ++itr) + { + Player::BoundInstancesMap boundInstances = _player->GetBoundInstances(Difficulty(i)); + for (Player::BoundInstancesMap::const_iterator itr = boundInstances.begin(); itr != boundInstances.end(); ++itr) + { if (itr->second.perm) { InstanceSave const* save = itr->second.save; - data << uint32(save->GetMapId()); - data << uint32(save->GetDifficulty()); - data << uint32(save->GetResetTime() - cur_time); - data << uint64(save->GetInstanceId()); // instance save id as unique instance copy id - ++counter; + dataBuffer << uint32(save->GetMapId()); + dataBuffer << uint32(save->GetDifficulty()); + dataBuffer << uint32(save->GetResetTime() - currTime); + dataBuffer << uint64(save->GetInstanceId()); // instance save id as unique instance copy id + ++boundCounter; } + } + } - data.put<uint32>(p_counter, counter); - - data << uint32(1135753200); // unk (28.12.2005 07:00) + data << uint32(boundCounter); + data.append(dataBuffer); - counter = 0; - p_counter = data.wpos(); - data << uint32(counter); // raid reset count + data << uint32(1135753200); // Constant date, unk (28.12.2005 07:00) + // Reuse variables + boundCounter = 0; std::set<uint32> sentMaps; + dataBuffer.clear(); ResetTimeByMapDifficultyMap const& resets = sInstanceSaveMgr->GetResetTimeMap(); for (ResetTimeByMapDifficultyMap::const_iterator itr = resets.begin(); itr != resets.end(); ++itr) { uint32 mapId = PAIR32_LOPART(itr->first); - if (sentMaps.find(mapId) != sentMaps.end()) continue; @@ -153,12 +138,14 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) sentMaps.insert(mapId); - data << uint32(mapId); - data << uint32(itr->second - cur_time); - data << uint32(mapEntry->unk_time); - ++counter; + dataBuffer << int32(mapId); + dataBuffer << int32(itr->second - currTime); + dataBuffer << int32(0); // Never seen anything else in sniffs - still unknown + ++boundCounter; } - data.put<uint32>(p_counter, counter); + + data << uint32(boundCounter); + data.append(dataBuffer); // TODO: Fix this, how we do know how many and what holidays to send? uint32 holidayCount = 0; @@ -174,7 +161,7 @@ void WorldSession::HandleCalendarGetCalendar(WorldPacket& /*recvData*/) data << uint32(holiday->CalendarFilterType); // m_calendarFilterType for (uint8 j = 0; j < MAX_HOLIDAY_DATES; ++j) - data << uint32(holiday->Date[j]); // 26 * m_date + data << uint32(holiday->Date[j]); // 26 * m_date -- WritePackedTime ? for (uint8 j = 0; j < MAX_HOLIDAY_DURATIONS; ++j) data << uint32(holiday->Duration[j]); // 10 * m_duration @@ -193,133 +180,114 @@ void WorldSession::HandleCalendarGetEvent(WorldPacket& recvData) uint64 eventId; recvData >> eventId; - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_EVENT. Event: [" + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GET_EVENT. Player [" UI64FMTD "] Event [" UI64FMTD "]", _player->GetGUID(), eventId); if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) - SendCalendarEvent(*calendarEvent, CALENDAR_SENDTYPE_GET); + sCalendarMgr->SendCalendarEvent(_player->GetGUID(), *calendarEvent, CALENDAR_SENDTYPE_GET); + else + sCalendarMgr->SendCalendarCommandResult(_player->GetGUID(), CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarGuildFilter(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GUILD_FILTER [" UI64FMTD "]", _player->GetGUID()); - int32 unk1, unk2, unk3; - recvData >> unk1; - recvData >> unk2; - recvData >> unk3; + uint32 minLevel; + uint32 maxLevel; + uint32 minRank; + + recvData >> minLevel >> maxLevel >> minRank; + + if (Guild* guild = sGuildMgr->GetGuildById(_player->GetGuildId())) + guild->MassInviteToEvent(this, minLevel, maxLevel, minRank); - sLog->outDebug(LOG_FILTER_NETWORKIO, "Calendar: CMSG_CALENDAR_GUILD_FILTER - unk1: %d unk2: %d unk3: %d", unk1, unk2, unk3); + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_GUILD_FILTER: Min level [%d], Max level [%d], Min rank [%d]", minLevel, maxLevel, minRank); } void WorldSession::HandleCalendarArenaTeam(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_ARENA_TEAM [" UI64FMTD "]", _player->GetGUID()); - int32 unk1; - recvData >> unk1; + uint32 arenaTeamId; + recvData >> arenaTeamId; - sLog->outDebug(LOG_FILTER_NETWORKIO, "Calendar: CMSG_CALENDAR_ARENA_TEAM - unk1: %d", unk1); + if (ArenaTeam* team = sArenaTeamMgr->GetArenaTeamById(arenaTeamId)) + team->MassInviteToEvent(this); } void WorldSession::HandleCalendarAddEvent(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); + std::string title; std::string description; uint8 type; - bool repeatable; + uint8 repeatable; uint32 maxInvites; int32 dungeonId; uint32 eventPackedTime; uint32 unkPackedTime; uint32 flags; - uint64 inviteId = 0; - uint64 invitee = 0; - uint8 status; - uint8 rank; - recvData >> title >> description >> type >> repeatable >> maxInvites; - recvData >> dungeonId; + recvData >> title >> description >> type >> repeatable >> maxInvites >> dungeonId; recvData.ReadPackedTime(eventPackedTime); recvData.ReadPackedTime(unkPackedTime); recvData >> flags; - if (!(flags & CALENDAR_FLAG_WITHOUT_INVITES)) + CalendarEvent* calendarEvent = new CalendarEvent(sCalendarMgr->GetFreeEventId(), guid, 0, CalendarEventType(type), dungeonId, + time_t(eventPackedTime), flags, time_t(unkPackedTime), title, description); + + if (calendarEvent->IsGuildEvent() || calendarEvent->IsGuildAnnouncement()) + if (Player* creator = ObjectAccessor::FindPlayer(guid)) + calendarEvent->SetGuildId(creator->GetGuildId()); + + if (calendarEvent->IsGuildAnnouncement()) + { + // 946684800 is 01/01/2000 00:00:00 - default response time + CalendarInvite* invite = new CalendarInvite(0, calendarEvent->GetEventId(), 0, guid, 946684800, CALENDAR_STATUS_NOT_SIGNED_UP, CALENDAR_RANK_PLAYER, ""); + sCalendarMgr->AddInvite(calendarEvent, invite); + } + else { uint32 inviteCount; recvData >> inviteCount; - recvData.readPackGUID(invitee); - recvData >> status >> rank; - if (inviteCount != 1 || invitee != guid) + for (uint32 i = 0; i < inviteCount; ++i) { - sLog->outError(LOG_FILTER_NETWORKIO, "HandleCalendarAddEvent: [" UI64FMTD - "]: More than one invite (%d) or Invitee [" UI64FMTD - "] differs", guid, inviteCount, invitee); - return; + uint64 invitee = 0; + uint8 status = 0; + uint8 rank = 0; + recvData.readPackGUID(invitee); + recvData >> status >> rank; + + // 946684800 is 01/01/2000 00:00:00 - default response time + CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), calendarEvent->GetEventId(), invitee, guid, 946684800, CalendarInviteStatus(status), CalendarModerationRank(rank), ""); + sCalendarMgr->AddInvite(calendarEvent, invite); } - - inviteId = sCalendarMgr->GetFreeInviteId(); - } - else - { - inviteId = 0; - status = CALENDAR_STATUS_NO_OWNER; - rank = CALENDAR_RANK_PLAYER; } - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_ADD_EVENT: [" UI64FMTD "] " - "Title %s, Description %s, type %u, Repeatable %u, MaxInvites %u, " - "Dungeon ID %d, Time %u, Time2 %u, Flags %u, Invitee [" UI64FMTD "] " - "Status %d, Rank %d", guid, title.c_str(), description.c_str(), - type, repeatable, maxInvites, dungeonId, eventPackedTime, - unkPackedTime, flags, invitee, status, rank); - - CalendarAction action; - - action.SetAction(CALENDAR_ACTION_ADD_EVENT); - action.SetPlayer(_player); - action.Event.SetEventId(sCalendarMgr->GetFreeEventId()); - action.Event.SetCreatorGUID(guid); - action.Event.SetType((CalendarEventType) type); - action.Event.SetFlags(flags); - action.Event.SetTime(eventPackedTime); - action.Event.SetTimeZoneTime(unkPackedTime); - action.Event.SetRepeatable(repeatable); - action.Event.SetMaxInvites(maxInvites); - action.Event.SetDungeonId(dungeonId); - action.Event.SetGuildId((flags & CALENDAR_FLAG_GUILD_ONLY) ? GetPlayer()->GetGuildId() : 0); - action.Event.SetTitle(title); - action.Event.SetDescription(description); - action.Event.AddInvite(inviteId); - action.Invite.SetEventId(action.Event.GetEventId()); - action.Invite.SetInviteId(inviteId); - action.Invite.SetInvitee(invitee); - action.Invite.SetStatus((CalendarInviteStatus) status); - action.Invite.SetRank((CalendarModerationRank) rank); - action.Invite.SetSenderGUID(guid); - - sCalendarMgr->AddAction(action); + sCalendarMgr->AddEvent(calendarEvent, CALENDAR_SENDTYPE_ADD); } void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); + time_t oldEventTime; + uint64 eventId; uint64 inviteId; std::string title; std::string description; uint8 type; - bool repeatable; + uint8 repetitionType; uint32 maxInvites; int32 dungeonId; uint32 eventPackedTime; uint32 timeZoneTime; uint32 flags; - recvData >> eventId >> inviteId >> title >> description >> type; - recvData >> repeatable >> maxInvites >> dungeonId; + recvData >> eventId >> inviteId >> title >> description >> type >> repetitionType >> maxInvites >> dungeonId; recvData.ReadPackedTime(eventPackedTime); recvData.ReadPackedTime(timeZoneTime); recvData >> flags; @@ -328,46 +296,37 @@ void WorldSession::HandleCalendarUpdateEvent(WorldPacket& recvData) "], InviteId [" UI64FMTD "] Title %s, Description %s, type %u " "Repeatable %u, MaxInvites %u, Dungeon ID %d, Time %u " "Time2 %u, Flags %u", guid, eventId, inviteId, title.c_str(), - description.c_str(), type, repeatable, maxInvites, dungeonId, + description.c_str(), type, repetitionType, maxInvites, dungeonId, eventPackedTime, timeZoneTime, flags); - CalendarAction action; - action.SetAction(CALENDAR_ACTION_MODIFY_EVENT); - action.SetPlayer(_player); - action.SetInviteId(inviteId); - action.Event.SetEventId(eventId); - action.Event.SetType((CalendarEventType) type); - action.Event.SetFlags((CalendarFlags) flags); - action.Event.SetTime(eventPackedTime); - action.Event.SetTimeZoneTime(timeZoneTime); - action.Event.SetRepeatable(repeatable); - action.Event.SetDungeonId(dungeonId); - action.Event.SetTitle(title); - action.Event.SetDescription(description); - action.Event.SetMaxInvites(maxInvites); - - sCalendarMgr->AddAction(action); + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + oldEventTime = calendarEvent->GetEventTime(); + + calendarEvent->SetType(CalendarEventType(type)); + calendarEvent->SetFlags(flags); + calendarEvent->SetEventTime(time_t(eventPackedTime)); + calendarEvent->SetTimeZoneTime(time_t(timeZoneTime)); // Not sure, seems constant from the little sniffs we have + calendarEvent->SetDungeonId(dungeonId); + calendarEvent->SetTitle(title); + calendarEvent->SetDescription(description); + + sCalendarMgr->UpdateEvent(calendarEvent); + sCalendarMgr->SendCalendarEventUpdateAlert(*calendarEvent, oldEventTime); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarRemoveEvent(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); uint64 eventId; - uint64 inviteId; - uint32 flags; - recvData >> eventId >> inviteId >> flags; - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_REMOVE_EVENT [" UI64FMTD "], EventId [" UI64FMTD - "] inviteId [" UI64FMTD "] Flags?: %u", guid, eventId, inviteId, flags); - - CalendarAction action; - action.SetAction(CALENDAR_ACTION_REMOVE_EVENT); - action.SetPlayer(_player); - action.SetInviteId(inviteId); - action.Event.SetEventId(eventId); - action.Event.SetFlags((CalendarFlags) flags); + recvData >> eventId; + recvData.rfinish(); // Skip flags & invite ID, we don't use them - sCalendarMgr->AddAction(action); + sCalendarMgr->RemoveEvent(eventId, guid); } void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData) @@ -382,94 +341,140 @@ void WorldSession::HandleCalendarCopyEvent(WorldPacket& recvData) sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_COPY_EVENT [" UI64FMTD "], EventId [" UI64FMTD "] inviteId [" UI64FMTD "] Time: %u", guid, eventId, inviteId, time); - CalendarAction action; - action.SetAction(CALENDAR_ACTION_COPY_EVENT); - action.SetPlayer(_player); - action.SetInviteId(inviteId); - action.Event.SetEventId(eventId); - action.Event.SetTime(time); + if (CalendarEvent* oldEvent = sCalendarMgr->GetEvent(eventId)) + { + CalendarEvent* newEvent = new CalendarEvent(*oldEvent, sCalendarMgr->GetFreeEventId()); + newEvent->SetEventTime(time_t(time)); + sCalendarMgr->AddEvent(newEvent, CALENDAR_SENDTYPE_COPY); + + std::vector<CalendarInvite*> invites = sCalendarMgr->GetEventInvites(eventId); + + for (std::vector<CalendarInvite*>::const_iterator itr = invites.begin(); itr != invites.end(); ++itr) + sCalendarMgr->AddInvite(newEvent, new CalendarInvite(**itr, sCalendarMgr->GetFreeInviteId(), newEvent->GetEventId())); - sCalendarMgr->AddAction(action); + // should we change owner when somebody makes a copy of event owned by another person? + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarEventInvite(WorldPacket& recvData) { - uint64 guid = _player->GetGUID(); + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_INVITE"); + + uint64 playerGuid = _player->GetGUID(); + uint64 eventId; uint64 inviteId; std::string name; - uint8 status; - uint8 rank; - uint64 invitee = 0; - uint32 team = 0; + bool isPreInvite; + bool isGuildEvent; + + uint64 inviteeGuid = 0; + uint32 inviteeTeam = 0; + uint32 inviteeGuildId = 0; - recvData >> eventId >> inviteId >> name >> status >> rank; - if (Player* player = sObjectAccessor->FindPlayerByName(name)) + recvData >> eventId >> inviteId >> name >> isPreInvite >> isGuildEvent; + + if (Player* player = sObjectAccessor->FindPlayerByName(name.c_str())) { - invitee = player->GetGUID(); - team = player->GetTeam(); + // Invitee is online + inviteeGuid = player->GetGUID(); + inviteeTeam = player->GetTeam(); + inviteeGuildId = player->GetGuildId(); } else { + // Invitee offline, get data from database PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_GUID_RACE_ACC_BY_NAME); stmt->setString(0, name); if (PreparedQueryResult result = CharacterDatabase.Query(stmt)) { Field* fields = result->Fetch(); - invitee = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); - team = Player::TeamForRace(fields[1].GetUInt8()); + inviteeGuid = MAKE_NEW_GUID(fields[0].GetUInt32(), 0, HIGHGUID_PLAYER); + inviteeTeam = Player::TeamForRace(fields[1].GetUInt8()); + inviteeGuildId = Player::GetGuildIdFromDB(inviteeGuid); } } - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_INVITE [" UI64FMTD "], EventId [" - UI64FMTD "] InviteId [" UI64FMTD "] Name %s ([" UI64FMTD "]), status %u, " - "Rank %u", guid, eventId, inviteId, name.c_str(), invitee, status, rank); - - if (!invitee) + if (!inviteeGuid) { - SendCalendarCommandResult(CALENDAR_ERROR_PLAYER_NOT_FOUND); + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_PLAYER_NOT_FOUND); return; } - if (_player->GetTeam() != team && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR)) + if (_player->GetTeam() != inviteeTeam && !sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CALENDAR)) { - SendCalendarCommandResult(CALENDAR_ERROR_NOT_ALLIED); + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NOT_ALLIED); return; } - // TODO: Check ignore, even if offline (db query) + if (QueryResult result = CharacterDatabase.PQuery("SELECT flags FROM character_social WHERE guid = " UI64FMTD " AND friend = " UI64FMTD, inviteeGuid, playerGuid)) + { + Field* fields = result->Fetch(); + if (fields[0].GetUInt8() & SOCIAL_FLAG_IGNORED) + { + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_IGNORING_YOU_S, name.c_str()); + return; + } + } + + if (!isPreInvite) + { + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() == inviteeGuildId) + { + // we can't invite guild members to guild events + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NO_GUILD_INVITES); + return; + } - CalendarAction action; - action.SetAction(CALENDAR_ACTION_ADD_EVENT_INVITE); - action.SetPlayer(_player); - action.SetInviteId(inviteId); - action.Invite.SetEventId(eventId); - action.Invite.SetInviteId(sCalendarMgr->GetFreeInviteId()); - action.Invite.SetSenderGUID(_player->GetGUID()); - action.Invite.SetInvitee(invitee); - action.Invite.SetRank((CalendarModerationRank) rank); - action.Invite.SetStatus((CalendarInviteStatus) status); + // 946684800 is 01/01/2000 00:00:00 - default response time + CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, inviteeGuid, playerGuid, 946684800, CALENDAR_STATUS_INVITED, CALENDAR_RANK_PLAYER, ""); + sCalendarMgr->AddInvite(calendarEvent, invite); + } + else + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_EVENT_INVALID); + } + else + { + if (isGuildEvent && inviteeGuildId == _player->GetGuildId()) + { + sCalendarMgr->SendCalendarCommandResult(playerGuid, CALENDAR_ERROR_NO_GUILD_INVITES); + return; + } - sCalendarMgr->AddAction(action); + // 946684800 is 01/01/2000 00:00:00 - default response time + CalendarInvite* invite = new CalendarInvite(inviteId, 0, inviteeGuid, playerGuid, 946684800, CALENDAR_STATUS_INVITED, CALENDAR_RANK_PLAYER, ""); + sCalendarMgr->SendCalendarEventInvite(*invite); + } } void WorldSession::HandleCalendarEventSignup(WorldPacket& recvData) { uint64 guid = _player->GetGUID(); uint64 eventId; - uint8 status; + bool tentative; + + recvData >> eventId >> tentative; + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_SIGNUP [" UI64FMTD "] EventId [" UI64FMTD "] Tentative %u", guid, eventId, tentative); - recvData >> eventId >> status; - sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_SIGNUP [" UI64FMTD "] EventId [" - UI64FMTD "] Status %u", guid, eventId, status); - - CalendarAction action; - action.SetAction(CALENDAR_ACTION_SIGNUP_TO_EVENT); - action.SetPlayer(_player); - action.SetExtraData(GetPlayer()->GetGuildId()); - action.Event.SetEventId(eventId); - action.Invite.SetStatus((CalendarInviteStatus) status); - sCalendarMgr->AddAction(action); + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + if (calendarEvent->IsGuildEvent() && calendarEvent->GetGuildId() != _player->GetGuildId()) + { + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD); + return; + } + + CalendarInviteStatus status = tentative ? CALENDAR_STATUS_TENTATIVE : CALENDAR_STATUS_SIGNED_UP; + CalendarInvite* invite = new CalendarInvite(sCalendarMgr->GetFreeInviteId(), eventId, guid, guid, time(NULL), status, CALENDAR_RANK_PLAYER, ""); + sCalendarMgr->AddInvite(calendarEvent, invite); + sCalendarMgr->SendCalendarClearPendingAction(guid); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarEventRsvp(WorldPacket& recvData) @@ -477,22 +482,36 @@ void WorldSession::HandleCalendarEventRsvp(WorldPacket& recvData) uint64 guid = _player->GetGUID(); uint64 eventId; uint64 inviteId; - uint8 status; + uint32 status; recvData >> eventId >> inviteId >> status; sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_RSVP [" UI64FMTD"] EventId [" UI64FMTD "], InviteId [" UI64FMTD "], status %u", guid, eventId, inviteId, status); - CalendarAction action; - action.SetAction(CALENDAR_ACTION_MODIFY_EVENT_INVITE); - action.SetPlayer(_player); - action.SetInviteId(inviteId); - action.Invite.SetInviteId(inviteId); - action.Invite.SetEventId(eventId); - action.Invite.SetStatus((CalendarInviteStatus) status); + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + // i think we still should be able to remove self from locked events + if (status != CALENDAR_STATUS_REMOVED && calendarEvent->GetFlags() & CALENDAR_FLAG_INVITES_LOCKED) + { + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_LOCKED); + return; + } + + if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId)) + { + invite->SetStatus(CalendarInviteStatus(status)); + invite->SetStatusTime(time(NULL)); - sCalendarMgr->AddAction(action); + sCalendarMgr->UpdateInvite(invite); + sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite); + sCalendarMgr->SendCalendarClearPendingAction(guid); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct? + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recvData) @@ -500,26 +519,29 @@ void WorldSession::HandleCalendarEventRemoveInvite(WorldPacket& recvData) uint64 guid = _player->GetGUID(); uint64 invitee; uint64 eventId; - uint64 owninviteId; + uint64 ownerInviteId; // isn't it sender's inviteId? uint64 inviteId; recvData.readPackGUID(invitee); - recvData >> inviteId >> owninviteId >> eventId; + recvData >> inviteId >> ownerInviteId >> eventId; sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_REMOVE_INVITE [" - UI64FMTD "] EventId [" UI64FMTD "], OwnInviteId [" + UI64FMTD "] EventId [" UI64FMTD "], ownerInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: [" UI64FMTD "])", - guid, eventId, owninviteId, invitee, inviteId); + guid, eventId, ownerInviteId, invitee, inviteId); - CalendarAction action; - action.SetAction(CALENDAR_ACTION_REMOVE_EVENT_INVITE); - action.SetPlayer(_player); - action.SetInviteId(owninviteId); - action.Invite.SetInviteId(inviteId); - action.Invite.SetEventId(eventId); - action.Invite.SetInvitee(invitee); + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + if (calendarEvent->GetCreatorGUID() == invitee) + { + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_DELETE_CREATOR_FAILED); + return; + } - sCalendarMgr->AddAction(action); + sCalendarMgr->RemoveInvite(inviteId, eventId, guid); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); } void WorldSession::HandleCalendarEventStatus(WorldPacket& recvData) @@ -528,25 +550,32 @@ void WorldSession::HandleCalendarEventStatus(WorldPacket& recvData) uint64 invitee; uint64 eventId; uint64 inviteId; - uint64 owninviteId; + uint64 ownerInviteId; // isn't it sender's inviteId? uint8 status; recvData.readPackGUID(invitee); - recvData >> eventId >> inviteId >> owninviteId >> status; + recvData >> eventId >> inviteId >> ownerInviteId >> status; sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_STATUS [" UI64FMTD"] EventId [" - UI64FMTD "] OwnInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: [" - UI64FMTD "], status %u", guid, eventId, owninviteId, invitee, inviteId, status); - - CalendarAction action; - action.SetAction(CALENDAR_ACTION_MODIFY_EVENT_INVITE); - action.SetPlayer(_player); - action.SetInviteId(owninviteId); - action.Invite.SetInviteId(inviteId); - action.Invite.SetEventId(eventId); - action.Invite.SetInvitee(invitee); - action.Invite.SetStatus((CalendarInviteStatus) status); - - sCalendarMgr->AddAction(action); + UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: [" + UI64FMTD "], status %u", guid, eventId, ownerInviteId, invitee, inviteId, status); + + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId)) + { + invite->SetStatus((CalendarInviteStatus)status); + // not sure if we should set response time when moderator changes invite status + //invite->SetStatusTime(time(NULL)); + + sCalendarMgr->UpdateInvite(invite); + sCalendarMgr->SendCalendarEventStatus(*calendarEvent, *invite); + sCalendarMgr->SendCalendarClearPendingAction(invitee); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct? + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recvData) @@ -555,25 +584,28 @@ void WorldSession::HandleCalendarEventModeratorStatus(WorldPacket& recvData) uint64 invitee; uint64 eventId; uint64 inviteId; - uint64 owninviteId; - uint8 status; + uint64 ownerInviteId; // isn't it sender's inviteId? + uint8 rank; recvData.readPackGUID(invitee); - recvData >> eventId >> inviteId >> owninviteId >> status; + recvData >> eventId >> inviteId >> ownerInviteId >> rank; sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_EVENT_MODERATOR_STATUS [" UI64FMTD "] EventId [" - UI64FMTD "] OwnInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: [" - UI64FMTD "], status %u", guid, eventId, owninviteId, invitee, inviteId, status); - - CalendarAction action; - action.SetAction(CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE); - action.SetPlayer(_player); - action.SetInviteId(owninviteId); - action.Invite.SetInviteId(inviteId); - action.Invite.SetEventId(eventId); - action.Invite.SetInvitee(invitee); - action.Invite.SetStatus((CalendarInviteStatus) status); - - sCalendarMgr->AddAction(action); + UI64FMTD "] ownerInviteId [" UI64FMTD "], Invitee ([" UI64FMTD "] id: [" + UI64FMTD "], rank %u", guid, eventId, ownerInviteId, invitee, inviteId, rank); + + if (CalendarEvent* calendarEvent = sCalendarMgr->GetEvent(eventId)) + { + if (CalendarInvite* invite = sCalendarMgr->GetInvite(inviteId)) + { + invite->SetRank(CalendarModerationRank(rank)); + sCalendarMgr->UpdateInvite(invite); + sCalendarMgr->SendCalendarEventModeratorStatusAlert(*calendarEvent, *invite); + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_NO_INVITE); // correct? + } + else + sCalendarMgr->SendCalendarCommandResult(guid, CALENDAR_ERROR_EVENT_INVALID); } void WorldSession::HandleCalendarComplain(WorldPacket& recvData) @@ -585,6 +617,8 @@ void WorldSession::HandleCalendarComplain(WorldPacket& recvData) recvData >> eventId >> complainGUID; sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_CALENDAR_COMPLAIN [" UI64FMTD "] EventId [" UI64FMTD "] guid [" UI64FMTD "]", guid, eventId, complainGUID); + + // what to do with complains? } void WorldSession::HandleCalendarGetNumPending(WorldPacket& /*recvData*/) @@ -600,279 +634,25 @@ void WorldSession::HandleCalendarGetNumPending(WorldPacket& /*recvData*/) SendPacket(&data); } -// ----------------------------------- SEND ------------------------------------ - -void WorldSession::SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType sendEventType) -{ - uint64 eventId = calendarEvent.GetEventId(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_SEND_EVENT [" UI64FMTD "] EventId [" - UI64FMTD "] SendType %u", _player->GetGUID(), eventId, sendEventType); - - WorldPacket data(SMSG_CALENDAR_SEND_EVENT); - data << uint8(sendEventType); - data.appendPackGUID(calendarEvent.GetCreatorGUID()); - data << uint64(eventId); - data << calendarEvent.GetTitle(); - data << calendarEvent.GetDescription(); - data << uint8(calendarEvent.GetType()); - data << uint8(calendarEvent.GetRepeatable()); - data << uint32(calendarEvent.GetMaxInvites()); - data << int32(calendarEvent.GetDungeonId()); - data << uint32(calendarEvent.GetFlags()); - data.AppendPackedTime(calendarEvent.GetTime()); - data.AppendPackedTime(calendarEvent.GetTimeZoneTime()); - data << uint32(calendarEvent.GetGuildId()); - - CalendarInviteIdList const& invites = calendarEvent.GetInviteIdList(); - data << uint32(invites.size()); - for (CalendarInviteIdList::const_iterator it = invites.begin(); it != invites.end(); ++it) - { - if (CalendarInvite* invite = sCalendarMgr->GetInvite(*it)) - { - uint64 guid = invite->GetInvitee(); - Player* player = ObjectAccessor::FindPlayer(guid); - uint8 level = player ? player->getLevel() : Player::GetLevelFromDB(guid); - - data.appendPackGUID(guid); - data << uint8(level); - data << uint8(invite->GetStatus()); - data << uint8(invite->GetRank()); - data << uint8(calendarEvent.GetGuildId() != 0); - data << uint64(invite->GetInviteId()); - data << uint32(invite->GetStatusTime()); - data << invite->GetText(); - } - else - { - data.appendPackGUID(_player->GetGUID()); - data << uint8(0) << uint8(0) << uint8(0) << uint8(0) - << uint64(0) << uint32(0) << uint8(0); - - sLog->outError(LOG_FILTER_NETWORKIO, "SendCalendarEvent: No Invite found with id [" UI64FMTD "]", *it); - } - } - SendPacket(&data); -} - -void WorldSession::SendCalendarEventInvite(CalendarInvite const& invite, bool pending) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = invite.GetEventId(); - uint64 inviteId = invite.GetInviteId(); - uint64 invitee = invite.GetInvitee(); - uint8 status = invite.GetStatus(); - uint32 statusTime = invite.GetStatusTime(); - Player* player = ObjectAccessor::FindPlayer(invitee); - uint8 level = player ? player->getLevel() : Player::GetLevelFromDB(invitee); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_INVITE [" UI64FMTD "] EventId [" - UI64FMTD "] InviteId [" UI64FMTD "] Invitee [" UI64FMTD "] " - " Level %u, Status %u, StatusTime %u" , guid, eventId, inviteId, - invitee, level, status, statusTime); - - WorldPacket data(SMSG_CALENDAR_EVENT_INVITE, 8 + 8 + 8 + 1 + 1 + 1 + (statusTime ? 4 : 0) + 1); - data.appendPackGUID(invitee); - data << uint64(eventId); - data << uint64(inviteId); - data << uint8(level); - data << uint8(status); - if (statusTime) - data << uint8(1) << uint32(statusTime); - else - data << uint8(0); - data << uint8(pending); - - SendPacket(&data); -} - -void WorldSession::SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& invite) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = calendarEvent.GetEventId(); - uint64 inviteId = invite.GetInviteId(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_INVITE_ALERT [" UI64FMTD "] EventId [" - UI64FMTD "] InviteId [" UI64FMTD "]", guid, eventId, inviteId); - - WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_ALERT); - data << uint64(eventId); - data << calendarEvent.GetTitle().c_str(); - data.AppendPackedTime(calendarEvent.GetTime()); - data << uint32(calendarEvent.GetFlags()); - data << uint32(calendarEvent.GetType()); - data << uint32(calendarEvent.GetDungeonId()); - data << uint64(inviteId); - data << uint8(invite.GetStatus()); - data << uint8(invite.GetRank()); - data.appendPackGUID(calendarEvent.GetCreatorGUID()); - data.appendPackGUID(invite.GetSenderGUID()); - SendPacket(&data); -} - -void WorldSession::SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, CalendarSendEventType sendEventType) +void WorldSession::HandleSetSavedInstanceExtend(WorldPacket& recvData) { - uint64 guid = _player->GetGUID(); - uint64 eventId = calendarEvent.GetEventId(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_UPDATED_ALERT [" - UI64FMTD "] EventId [" UI64FMTD "]", guid, eventId); - - - WorldPacket data(SMSG_CALENDAR_EVENT_UPDATED_ALERT, 1 + 8 + 4 + 4 + 4 + 1 + 4 + - calendarEvent.GetTitle().size() + calendarEvent.GetDescription().size() + 1 + 4 + 4); - data << uint8(sendEventType); - data << uint64(eventId); - data.AppendPackedTime(calendarEvent.GetTime()); - data << uint32(calendarEvent.GetFlags()); - data.AppendPackedTime(calendarEvent.GetTime()); - data << uint8(calendarEvent.GetType()); - data << uint32(calendarEvent.GetDungeonId()); - data << calendarEvent.GetTitle().c_str(); - data << calendarEvent.GetDescription().c_str(); - data << uint8(calendarEvent.GetRepeatable()); - data << uint32(calendarEvent.GetMaxInvites()); - data << uint32(0); // FIXME - SendPacket(&data); -} - -void WorldSession::SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = calendarEvent.GetEventId(); - uint32 eventTime = calendarEvent.GetTime(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_REMOVED_ALERT [" UI64FMTD "] EventId [" - UI64FMTD "] Time %u", guid, eventId, eventTime); - - WorldPacket data(SMSG_CALENDAR_EVENT_REMOVED_ALERT, 1 + 8 + 1); - data << uint8(1); // FIXME: If true does not SignalEvent(EVENT_CALENDAR_ACTION_PENDING) - data << uint64(eventId); - data.AppendPackedTime(eventTime); - SendPacket(&data); -} - -void WorldSession::SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = calendarEvent.GetEventId(); - uint64 inviteId = invite.GetInviteId(); - uint64 invitee = invite.GetInvitee(); - uint32 eventTime = calendarEvent.GetTime(); - uint32 flags = calendarEvent.GetFlags(); - uint8 status = invite.GetStatus(); - uint8 rank = invite.GetRank(); - uint32 statusTime = invite.GetStatusTime(); - - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_STATUS [" UI64FMTD "] EventId [" - UI64FMTD "] InviteId [" UI64FMTD "] Invitee [" UI64FMTD "] Time %u " - "Flags %u, Status %u, Rank %u, StatusTime %u", - guid, eventId, inviteId, invitee, eventTime, flags, status, rank, - statusTime); - - WorldPacket data(SMSG_CALENDAR_EVENT_STATUS, 8 + 8 + 4 + 4 + 1 + 1 + 4); - data.appendPackGUID(invitee); - data << uint64(eventId); - data.AppendPackedTime(eventTime); - data << uint32(flags); - data << uint8(status); - data << uint8(rank); - data.AppendPackedTime(statusTime); - SendPacket(&data); -} - -void WorldSession::SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = invite.GetEventId(); - uint64 invitee = invite.GetInvitee(); - uint8 status = invite.GetStatus(); - - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_MODERATOR_STATUS_ALERT [" UI64FMTD - "] Invitee [" UI64FMTD "] EventId [" UI64FMTD "] Status %u ", guid, - invitee, eventId, status); - - - WorldPacket data(SMSG_CALENDAR_EVENT_MODERATOR_STATUS_ALERT, 8 + 8 + 1 + 1); - data.appendPackGUID(invitee); - data << uint64(eventId); - data << uint8(status); - data << uint8(1); // FIXME - SendPacket(&data); -} - -void WorldSession::SendCalendarEventInviteRemoveAlert(CalendarEvent const& calendarEvent, CalendarInviteStatus status) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = calendarEvent.GetEventId(); - uint32 eventTime = calendarEvent.GetTime(); - uint32 flags = calendarEvent.GetFlags(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_INVITE_REMOVED_ALERT [" - UI64FMTD "] EventId [" UI64FMTD "] Time %u, Flags %u, Status %u", - guid, eventId, eventTime, flags, status); - - WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED_ALERT, 8 + 4 + 4 + 1); - data << uint64(eventId); - data.AppendPackedTime(eventTime); - data << uint32(flags); - data << uint8(status); - SendPacket(&data); -} - -void WorldSession::SendCalendarEventInviteRemove(CalendarInvite const& invite, uint32 flags) -{ - uint64 guid = _player->GetGUID(); - uint64 eventId = invite.GetEventId(); - uint64 invitee = invite.GetInvitee(); - - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_EVENT_INVITE_REMOVED [" - UI64FMTD "] Invitee [" UI64FMTD "] EventId [" UI64FMTD - "] Flags %u", guid, invitee, eventId, flags); - - WorldPacket data(SMSG_CALENDAR_EVENT_INVITE_REMOVED, 8 + 4 + 4 + 1); - data.appendPackGUID(invitee); - data << uint32(eventId); - data << uint32(flags); - data << uint8(1); // FIXME - SendPacket(&data); -} - -void WorldSession::SendCalendarClearPendingAction() -{ - uint64 guid = _player->GetGUID(); - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_CLEAR_PENDING_ACTION [" UI64FMTD "]", guid); + uint32 mapId, difficulty; + uint8 toggleExtend; + recvData >> mapId >> difficulty>> toggleExtend; + sLog->outDebug(LOG_FILTER_NETWORKIO, "CMSG_SET_SAVED_INSTANCE_EXTEND - MapId: %u, Difficulty: %u, ToggleExtend: %s", mapId, difficulty, toggleExtend ? "On" : "Off"); + + /* + InstancePlayerBind* instanceBind = _player->GetBoundInstance(mapId, Difficulty(difficulty)); + if (!instanceBind || !instanceBind->save) + return; - WorldPacket data(SMSG_CALENDAR_CLEAR_PENDING_ACTION, 0); - SendPacket(&data); + InstanceSave* save = instanceBind->save; + // http://www.wowwiki.com/Instance_Lock_Extension + // SendCalendarRaidLockoutUpdated(save); + */ } -void WorldSession::SendCalendarCommandResult(CalendarError err, char const* param /*= NULL*/) -{ - uint64 guid = _player->GetGUID(); - sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_COMMAND_RESULT [" UI64FMTD "] Value: %u", guid, err); - - WorldPacket data(SMSG_CALENDAR_COMMAND_RESULT, 0); - data << uint32(0); - data << uint8(0); - switch (err) - { - case CALENDAR_ERROR_OTHER_INVITES_EXCEEDED: - case CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S: - case CALENDAR_ERROR_IGNORING_YOU_S: - data << param; - break; - default: - data << uint8(0); - break; - } - - data << uint32(err); - - SendPacket(&data); -} +// ----------------------------------- SEND ------------------------------------ void WorldSession::SendCalendarRaidLockout(InstanceSave const* save, bool add) { @@ -902,13 +682,13 @@ void WorldSession::SendCalendarRaidLockoutUpdated(InstanceSave const* save) sLog->outDebug(LOG_FILTER_NETWORKIO, "SMSG_CALENDAR_RAID_LOCKOUT_UPDATED [" UI64FMTD "] Map: %u, Difficulty %u", guid, save->GetMapId(), save->GetDifficulty()); - time_t cur_time = time_t(time(NULL)); + time_t currTime = time(NULL); WorldPacket data(SMSG_CALENDAR_RAID_LOCKOUT_UPDATED, 4 + 4 + 4 + 4 + 8); - data.AppendPackedTime(cur_time); + data.AppendPackedTime(currTime); data << uint32(save->GetMapId()); data << uint32(save->GetDifficulty()); data << uint32(0); // Amount of seconds that has changed to the reset time - data << uint32(save->GetResetTime() - cur_time); + data << uint32(save->GetResetTime() - currTime); SendPacket(&data); } diff --git a/src/server/game/Handlers/ChannelHandler.cpp b/src/server/game/Handlers/ChannelHandler.cpp index a65e3830a81..462bc7fff0b 100755 --- a/src/server/game/Handlers/ChannelHandler.cpp +++ b/src/server/game/Handlers/ChannelHandler.cpp @@ -18,252 +18,256 @@ #include "ObjectMgr.h" // for normalizePlayerName #include "ChannelMgr.h" +#include "Player.h" void WorldSession::HandleJoinChannel(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - - uint32 channel_id; + uint32 channelId; uint8 unknown1, unknown2; - std::string channelname, pass; + std::string channelName, password; + + recvPacket >> channelId >> unknown1 >> unknown2 >> channelName >> password; - recvPacket >> channel_id; - recvPacket >> unknown1 >> unknown2; - recvPacket >> channelname; - recvPacket >> pass; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_JOIN_CHANNEL %s Channel: %u, unk1: %u, unk2: %u, channel: %s, password: %s", + GetPlayerInfo().c_str(), channelId, unknown1, unknown2, channelName.c_str(), password.c_str()); - if (channel_id) + if (channelId) { - ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(channel_id); + ChatChannelsEntry const* channel = sChatChannelsStore.LookupEntry(channelId); if (!channel) return; - AreaTableEntry const* current_zone = GetAreaEntryByAreaID(_player->GetZoneId()); - if (!current_zone) - return; - - if (!_player->CanJoinConstantChannelInZone(channel, current_zone)) + AreaTableEntry const* zone = GetAreaEntryByAreaID(GetPlayer()->GetZoneId()); + if (!zone || !GetPlayer()->CanJoinConstantChannelInZone(channel, zone)) return; } - if (channelname.empty()) + if (channelName.empty()) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) { - cMgr->setTeam(_player->GetTeam()); - if (Channel* chn = cMgr->GetJoinChannel(channelname, channel_id)) - chn->Join(_player->GetGUID(), pass.c_str()); + cMgr->setTeam(GetPlayer()->GetTeam()); + if (Channel* channel = cMgr->GetJoinChannel(channelName, channelId)) + channel->JoinChannel(GetPlayer(), password); } } void WorldSession::HandleLeaveChannel(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - uint32 unk; - std::string channelname; - recvPacket >> unk; // channel id? - recvPacket >> channelname; + std::string channelName; + recvPacket >> unk >> channelName; - if (channelname.empty()) + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_LEAVE_CHANNEL %s Channel: %s, unk1: %u", + GetPlayerInfo().c_str(), channelName.c_str(), unk); + + if (channelName.empty()) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) { - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Leave(_player->GetGUID(), true); - cMgr->LeftChannel(channelname); + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->LeaveChannel(GetPlayer(), true); + cMgr->LeftChannel(channelName); } } void WorldSession::HandleChannelList(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname; - recvPacket >> channelname; + std::string channelName; + recvPacket >> channelName; + + sLog->outDebug(LOG_FILTER_CHATSYS, "%s %s Channel: %s", + recvPacket.GetOpcode() == CMSG_CHANNEL_DISPLAY_LIST ? "CMSG_CHANNEL_DISPLAY_LIST" : "CMSG_CHANNEL_LIST", + GetPlayerInfo().c_str(), channelName.c_str()); - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->List(_player); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->List(GetPlayer()); } void WorldSession::HandleChannelPassword(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, pass; - recvPacket >> channelname; + std::string channelName, password; + recvPacket >> channelName >> password; - recvPacket >> pass; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_PASSWORD %s Channel: %s, Password: %s", + GetPlayerInfo().c_str(), channelName.c_str(), password.c_str()); - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Password(_player->GetGUID(), pass.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->Password(GetPlayer(), password); } void WorldSession::HandleChannelSetOwner(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, newp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> newp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_SET_OWNER %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(newp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->SetOwner(_player->GetGUID(), newp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->SetOwner(GetPlayer(), targetName); } void WorldSession::HandleChannelOwner(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname; - recvPacket >> channelname; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->SendWhoOwner(_player->GetGUID()); + std::string channelName; + recvPacket >> channelName; + + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_OWNER %s Channel: %s", + GetPlayerInfo().c_str(), channelName.c_str()); + + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->SendWhoOwner(GetPlayer()->GetGUID()); } void WorldSession::HandleChannelModerator(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_MODERATOR %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->SetModerator(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->SetModerator(GetPlayer(), targetName); } void WorldSession::HandleChannelUnmoderator(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_UNMODERATOR %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->UnsetModerator(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->UnsetModerator(GetPlayer(), targetName); } void WorldSession::HandleChannelMute(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_MUTE %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->SetMute(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->SetMute(GetPlayer(), targetName); } void WorldSession::HandleChannelUnmute(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_UNMUTE %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->UnsetMute(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->UnsetMute(GetPlayer(), targetName); } void WorldSession::HandleChannelInvite(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_INVITE %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Invite(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->Invite(GetPlayer(), targetName); } void WorldSession::HandleChannelKick(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; - if (!normalizePlayerName(otp)) + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_KICK %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); + + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Kick(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->Kick(GetPlayer(), targetName); } void WorldSession::HandleChannelBan(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_BAN %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Ban(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->Ban(GetPlayer(), targetName); } void WorldSession::HandleChannelUnban(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - - std::string channelname, otp; - recvPacket >> channelname; + std::string channelName, targetName; + recvPacket >> channelName >> targetName; - recvPacket >> otp; + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_UNBAN %s Channel: %s, Target: %s", + GetPlayerInfo().c_str(), channelName.c_str(), targetName.c_str()); - if (!normalizePlayerName(otp)) + if (!normalizePlayerName(targetName)) return; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->UnBan(_player->GetGUID(), otp.c_str()); + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->UnBan(GetPlayer(), targetName); } void WorldSession::HandleChannelAnnouncements(WorldPacket& recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname; - recvPacket >> channelname; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->Announce(_player->GetGUID()); + std::string channelName; + recvPacket >> channelName; + + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_CHANNEL_ANNOUNCEMENTS %s Channel: %s", + GetPlayerInfo().c_str(), channelName.c_str()); + + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->Announce(GetPlayer()); } void WorldSession::HandleChannelDisplayListQuery(WorldPacket &recvPacket) @@ -274,17 +278,23 @@ void WorldSession::HandleChannelDisplayListQuery(WorldPacket &recvPacket) void WorldSession::HandleGetChannelMemberCount(WorldPacket &recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname; - recvPacket >> channelname; - if (ChannelMgr* cMgr = ChannelMgr::forTeam(_player->GetTeam())) + std::string channelName; + recvPacket >> channelName; + + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_GET_CHANNEL_MEMBER_COUNT %s Channel: %s", + GetPlayerInfo().c_str(), channelName.c_str()); + + if (ChannelMgr* cMgr = ChannelMgr::forTeam(GetPlayer()->GetTeam())) { - if (Channel* chn = cMgr->GetChannel(channelname, _player)) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) { - WorldPacket data(SMSG_CHANNEL_MEMBER_COUNT, chn->GetName().size()+1+1+4); - data << chn->GetName(); - data << uint8(chn->GetFlags()); - data << uint32(chn->GetNumPlayers()); + sLog->outDebug(LOG_FILTER_CHATSYS, "SMSG_CHANNEL_MEMBER_COUNT %s Channel: %s Count: %u", + GetPlayerInfo().c_str(), channelName.c_str(), channel->GetNumPlayers()); + + WorldPacket data(SMSG_CHANNEL_MEMBER_COUNT, channel->GetName().size() + 1 + 4); + data << channel->GetName(); + data << uint8(channel->GetFlags()); + data << uint32(channel->GetNumPlayers()); SendPacket(&data); } } @@ -292,10 +302,15 @@ void WorldSession::HandleGetChannelMemberCount(WorldPacket &recvPacket) void WorldSession::HandleSetChannelWatch(WorldPacket &recvPacket) { - sLog->outDebug(LOG_FILTER_NETWORKIO, "Opcode %u", recvPacket.GetOpcode()); - std::string channelname; - recvPacket >> channelname; - /*if (ChannelMgr* cMgr = channelMgr(_player->GetTeam())) - if (Channel* chn = cMgr->GetChannel(channelname, _player)) - chn->JoinNotify(_player->GetGUID());*/ + std::string channelName; + recvPacket >> channelName; + + sLog->outDebug(LOG_FILTER_CHATSYS, "CMSG_SET_CHANNEL_WATCH %s Channel: %s", + GetPlayerInfo().c_str(), channelName.c_str()); + + /* + if (ChannelMgr* cMgr = channelMgr(GetPlayer()->GetTeam())) + if (Channel* channel = cMgr->GetChannel(channelName, GetPlayer())) + channel->JoinNotify(GetPlayer()); + */ } diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 258878b1f87..0b01c796511 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -16,34 +16,37 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Common.h" -#include "ObjectAccessor.h" -#include "ObjectMgr.h" -#include "ArenaTeamMgr.h" -#include "GuildMgr.h" -#include "SystemConfig.h" -#include "World.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "DatabaseEnv.h" - +#include "AccountMgr.h" #include "ArenaTeam.h" +#include "ArenaTeamMgr.h" +#include "Battleground.h" +#include "CalendarMgr.h" #include "Chat.h" +#include "Common.h" +#include "DatabaseEnv.h" #include "Group.h" #include "Guild.h" +#include "GuildMgr.h" #include "Language.h" +#include "LFGMgr.h" #include "Log.h" +#include "ObjectAccessor.h" +#include "ObjectMgr.h" #include "Opcodes.h" -#include "Player.h" +#include "Pet.h" #include "PlayerDump.h" +#include "Player.h" +#include "ReputationMgr.h" +#include "ScriptMgr.h" #include "SharedDefines.h" #include "SocialMgr.h" +#include "SystemConfig.h" #include "UpdateMask.h" #include "Util.h" -#include "ScriptMgr.h" -#include "Battleground.h" -#include "AccountMgr.h" -#include "LFGMgr.h" +#include "World.h" +#include "WorldPacket.h" +#include "WorldSession.h" + class LoginQueryHolder : public SQLQueryHolder { @@ -726,6 +729,7 @@ void WorldSession::HandleCharDeleteOpcode(WorldPacket & recvData) sLog->outCharDump(dump.c_str(), GetAccountId(), GUID_LOPART(guid), name.c_str()); } + sCalendarMgr->RemoveAllPlayerEventsAndInvites(guid); Player::DeleteFromDB(guid, GetAccountId()); WorldPacket data(SMSG_CHAR_DELETE, 1); @@ -772,7 +776,7 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder* holder) Player* pCurrChar = new Player(this); // for send server info and strings (config) - ChatHandler chH = ChatHandler(pCurrChar); + ChatHandler chH = ChatHandler(pCurrChar->GetSession()); // "GetAccountId() == db stored account id" checked in LoadFromDB (prevent login not own character using cheating tools) if (!pCurrChar->LoadFromDB(GUID_LOPART(playerGuid), holder)) diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp index 8b7fc5542ab..e4989816998 100755 --- a/src/server/game/Handlers/ChatHandler.cpp +++ b/src/server/game/Handlers/ChatHandler.cpp @@ -114,7 +114,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) return; break; default: - sLog->outError(LOG_FILTER_NETWORKIO, "Player %s (GUID: %u) sent a chatmessage with an invalid language/message type combination", + sLog->outError(LOG_FILTER_NETWORKIO, "Player %s (GUID: %u) sent a chatmessage with an invalid language/message type combination", GetPlayer()->GetName().c_str(), GetPlayer()->GetGUIDLow()); recvData.rfinish(); @@ -561,8 +561,8 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData) // Only allow text-emotes for "dead" entities (feign death included) if (GetPlayer()->HasUnitState(UNIT_STATE_DIED)) break; - GetPlayer()->HandleEmoteCommand(emote_anim); - break; + GetPlayer()->HandleEmoteCommand(emote_anim); + break; } Unit* unit = ObjectAccessor::GetUnit(*_player, guid); diff --git a/src/server/game/Handlers/CombatHandler.cpp b/src/server/game/Handlers/CombatHandler.cpp index 1cd86afc6d2..d30164b2592 100755 --- a/src/server/game/Handlers/CombatHandler.cpp +++ b/src/server/game/Handlers/CombatHandler.cpp @@ -25,6 +25,8 @@ #include "ObjectDefines.h" #include "Vehicle.h" #include "VehicleDefines.h" +#include "Player.h" +#include "Opcodes.h" void WorldSession::HandleAttackSwingOpcode(WorldPacket& recvData) { diff --git a/src/server/game/Handlers/GroupHandler.cpp b/src/server/game/Handlers/GroupHandler.cpp index 223a5316c7a..8555b4a6a1f 100755 --- a/src/server/game/Handlers/GroupHandler.cpp +++ b/src/server/game/Handlers/GroupHandler.cpp @@ -18,19 +18,20 @@ #include "Common.h" #include "DatabaseEnv.h" -#include "Opcodes.h" +#include "Group.h" +#include "GroupMgr.h" #include "Log.h" -#include "WorldPacket.h" -#include "WorldSession.h" -#include "World.h" #include "ObjectMgr.h" -#include "GroupMgr.h" +#include "Opcodes.h" +#include "Pet.h" #include "Player.h" -#include "Group.h" #include "SocialMgr.h" -#include "Util.h" #include "SpellAuras.h" +#include "Util.h" #include "Vehicle.h" +#include "World.h" +#include "WorldPacket.h" +#include "WorldSession.h" class Aura; diff --git a/src/server/game/Handlers/LFGHandler.cpp b/src/server/game/Handlers/LFGHandler.cpp index 9926c75eb2a..3f33b60329b 100755 --- a/src/server/game/Handlers/LFGHandler.cpp +++ b/src/server/game/Handlers/LFGHandler.cpp @@ -15,14 +15,13 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "WorldSession.h" -#include "WorldPacket.h" -#include "DBCStores.h" -#include "Player.h" -#include "Group.h" #include "LFGMgr.h" #include "ObjectMgr.h" -#include "GroupMgr.h" +#include "Group.h" +#include "Player.h" +#include "Opcodes.h" +#include "WorldPacket.h" +#include "WorldSession.h" void BuildPlayerLockDungeonBlock(WorldPacket& data, const LfgLockMap& lock) { @@ -59,11 +58,11 @@ void WorldSession::HandleLfgJoinOpcode(WorldPacket& recvData) uint32 roles; recvData >> roles; - recvData.read_skip<uint16>(); // uint8 (always 0) - uint8 (always 0) + recvData.read_skip<uint16>(); // uint8 (always 0) - uint8 (always 0) recvData >> numDungeons; if (!numDungeons) { - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_JOIN [" UI64FMTD "] no dungeons selected", GetPlayer()->GetGUID()); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_JOIN %s no dungeons selected", GetPlayerInfo().c_str()); recvData.rfinish(); return; } @@ -72,14 +71,15 @@ void WorldSession::HandleLfgJoinOpcode(WorldPacket& recvData) for (int8 i = 0; i < numDungeons; ++i) { recvData >> dungeon; - newDungeons.insert((dungeon & 0x00FFFFFF)); // remove the type from the dungeon entry + newDungeons.insert((dungeon & 0x00FFFFFF)); // remove the type from the dungeon entry } - recvData.read_skip<uint32>(); // for 0..uint8 (always 3) { uint8 (always 0) } + recvData.read_skip<uint32>(); // for 0..uint8 (always 3) { uint8 (always 0) } std::string comment; recvData >> comment; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_JOIN [" UI64FMTD "] roles: %u, Dungeons: %u, Comment: %s", GetPlayer()->GetGUID(), roles, uint8(newDungeons.size()), comment.c_str()); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_JOIN %s roles: %u, Dungeons: %u, Comment: %s", + GetPlayerInfo().c_str(), roles, uint8(newDungeons.size()), comment.c_str()); sLFGMgr->JoinLfg(GetPlayer(), uint8(roles), newDungeons, comment); } @@ -89,7 +89,8 @@ void WorldSession::HandleLfgLeaveOpcode(WorldPacket& /*recvData*/) uint64 guid = GetPlayer()->GetGUID(); uint64 gguid = grp ? grp->GetGUID() : guid; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LEAVE [" UI64FMTD "] in group: %u", guid, grp ? 1 : 0); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LEAVE %s in group: %u", + GetPlayerInfo().c_str(), grp ? 1 : 0); // Check cheating - only leader can leave the queue if (!grp || grp->GetLeaderGUID() == GetPlayer()->GetGUID()) @@ -98,28 +99,31 @@ void WorldSession::HandleLfgLeaveOpcode(WorldPacket& /*recvData*/) void WorldSession::HandleLfgProposalResultOpcode(WorldPacket& recvData) { - uint32 lfgGroupID; // Internal lfgGroupID + uint32 lfgGroupID; // Internal lfgGroupID bool accept; // Accept to join? recvData >> lfgGroupID; recvData >> accept; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PROPOSAL_RESULT [" UI64FMTD "] proposal: %u accept: %u", GetPlayer()->GetGUID(), lfgGroupID, accept ? 1 : 0); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PROPOSAL_RESULT %s proposal: %u accept: %u", + GetPlayerInfo().c_str(), lfgGroupID, accept ? 1 : 0); sLFGMgr->UpdateProposal(lfgGroupID, GetPlayer()->GetGUID(), accept); } void WorldSession::HandleLfgSetRolesOpcode(WorldPacket& recvData) { uint8 roles; - recvData >> roles; // Player Group Roles + recvData >> roles; // Player Group Roles uint64 guid = GetPlayer()->GetGUID(); Group* grp = GetPlayer()->GetGroup(); if (!grp) { - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_ROLES [" UI64FMTD "] Not in group", guid); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_ROLES %s Not in group", + GetPlayerInfo().c_str()); return; } uint64 gguid = grp->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_ROLES: Group [" UI64FMTD "], Player [" UI64FMTD "], Roles: %u", gguid, guid, roles); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_ROLES: Group %u, Player %s, Roles: %u", + GUID_LOPART(gguid), GetPlayerInfo().c_str(), roles); sLFGMgr->UpdateRoleCheck(gguid, guid, roles); } @@ -128,7 +132,8 @@ void WorldSession::HandleLfgSetCommentOpcode(WorldPacket& recvData) std::string comment; recvData >> comment; uint64 guid = GetPlayer()->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_COMMENT [" UI64FMTD "] comment: %s", guid, comment.c_str()); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_COMMENT %s comment: %s", + GetPlayerInfo().c_str(), comment.c_str()); sLFGMgr->SetComment(guid, comment); } @@ -139,7 +144,8 @@ void WorldSession::HandleLfgSetBootVoteOpcode(WorldPacket& recvData) recvData >> agree; uint64 guid = GetPlayer()->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_BOOT_VOTE [" UI64FMTD "] agree: %u", guid, agree ? 1 : 0); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_SET_BOOT_VOTE %s agree: %u", + GetPlayerInfo().c_str(), agree ? 1 : 0); sLFGMgr->UpdateBoot(guid, agree); } @@ -148,14 +154,16 @@ void WorldSession::HandleLfgTeleportOpcode(WorldPacket& recvData) bool out; recvData >> out; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_TELEPORT [" UI64FMTD "] out: %u", GetPlayer()->GetGUID(), out ? 1 : 0); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_TELEPORT %s out: %u", + GetPlayerInfo().c_str(), out ? 1 : 0); sLFGMgr->TeleportPlayer(GetPlayer(), out, true); } void WorldSession::HandleLfgPlayerLockInfoRequestOpcode(WorldPacket& /*recvData*/) { uint64 guid = GetPlayer()->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PLAYER_LOCK_INFO_REQUEST [" UI64FMTD "]", guid); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PLAYER_LOCK_INFO_REQUEST %s", + GetPlayerInfo().c_str()); // Get Random dungeons that can be done at a certain level and expansion LfgDungeonSet randomDungeons; @@ -176,7 +184,7 @@ void WorldSession::HandleLfgPlayerLockInfoRequestOpcode(WorldPacket& /*recvData* uint32 rsize = uint32(randomDungeons.size()); uint32 lsize = uint32(lock.size()); - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PLAYER_INFO [" UI64FMTD "]", guid); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PLAYER_INFO %s", GetPlayerInfo().c_str()); WorldPacket data(SMSG_LFG_PLAYER_INFO, 1 + rsize * (4 + 1 + 4 + 4 + 4 + 4 + 1 + 4 + 4 + 4) + 4 + lsize * (1 + 4 + 4 + 4 + 4 + 1 + 4 + 4 + 4)); data << uint8(randomDungeons.size()); // Random Dungeon count @@ -234,7 +242,7 @@ void WorldSession::HandleLfgPlayerLockInfoRequestOpcode(WorldPacket& /*recvData* void WorldSession::HandleLfgPartyLockInfoRequestOpcode(WorldPacket& /*recvData*/) { uint64 guid = GetPlayer()->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PARTY_LOCK_INFO_REQUEST [" UI64FMTD "]", guid); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_PARTY_LOCK_INFO_REQUEST %s", GetPlayerInfo().c_str()); Group* grp = GetPlayer()->GetGroup(); if (!grp) @@ -259,7 +267,7 @@ void WorldSession::HandleLfgPartyLockInfoRequestOpcode(WorldPacket& /*recvData* for (LfgLockPartyMap::const_iterator it = lockMap.begin(); it != lockMap.end(); ++it) size += 8 + 4 + uint32(it->second.size()) * (4 + 4); - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PARTY_INFO [" UI64FMTD "]", guid); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PARTY_INFO %s", GetPlayerInfo().c_str()); WorldPacket data(SMSG_LFG_PARTY_INFO, 1 + size); BuildPartyLockDungeonBlock(data, lockMap); SendPacket(&data); @@ -269,7 +277,8 @@ void WorldSession::HandleLfrJoinOpcode(WorldPacket& recvData) { uint32 entry; // Raid id to search recvData >> entry; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LFR_JOIN [" UI64FMTD "] dungeon entry: %u", GetPlayer()->GetGUID(), entry); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LFR_JOIN %s dungeon entry: %u", + GetPlayerInfo().c_str(), entry); //SendLfrUpdateListOpcode(entry); } @@ -277,48 +286,64 @@ void WorldSession::HandleLfrLeaveOpcode(WorldPacket& recvData) { uint32 dungeonId; // Raid id queue to leave recvData >> dungeonId; - sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LFR_LEAVE [" UI64FMTD "] dungeonId: %u", GetPlayer()->GetGUID(), dungeonId); + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_LFR_LEAVE %s dungeonId: %u", + GetPlayerInfo().c_str(), dungeonId); //sLFGMgr->LeaveLfr(GetPlayer(), dungeonId); } +void WorldSession::HandleLfgGetStatus(WorldPacket& /*recvData*/) +{ + sLog->outDebug(LOG_FILTER_LFG, "CMSG_LFG_GET_STATUS %s", GetPlayerInfo().c_str()); + + uint64 guid = GetPlayer()->GetGUID(); + LfgUpdateData updateData = sLFGMgr->GetLfgStatus(guid); + + if (GetPlayer()->GetGroup()) + { + SendLfgUpdateParty(updateData); + updateData.dungeons.clear(); + SendLfgUpdatePlayer(updateData); + } + else + { + SendLfgUpdatePlayer(updateData); + updateData.dungeons.clear(); + SendLfgUpdateParty(updateData); + } +} + void WorldSession::SendLfgUpdatePlayer(const LfgUpdateData& updateData) { bool queued = false; - bool extrainfo = false; - uint64 guid = GetPlayer()->GetGUID(); uint8 size = uint8(updateData.dungeons.size()); switch (updateData.updateType) { - case LFG_UPDATETYPE_JOIN_PROPOSAL: + case LFG_UPDATETYPE_JOIN_QUEUE: case LFG_UPDATETYPE_ADDED_TO_QUEUE: queued = true; - extrainfo = true; break; case LFG_UPDATETYPE_UPDATE_STATUS: - extrainfo = size > 0; - break; - case LFG_UPDATETYPE_PROPOSAL_BEGIN: - extrainfo = true; + queued = updateData.state == LFG_STATE_QUEUED; break; default: break; } - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_UPDATE_PLAYER [" UI64FMTD "] updatetype: %u", guid, updateData.updateType); - WorldPacket data(SMSG_LFG_UPDATE_PLAYER, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + size * 4 + updateData.comment.length())); - data << uint8(updateData.updateType); // Lfg Update type - data << uint8(extrainfo); // Extra info - if (extrainfo) + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_UPDATE_PLAYER %s updatetype: %u", + GetPlayerInfo().c_str(), updateData.updateType); + WorldPacket data(SMSG_LFG_UPDATE_PLAYER, 1 + 1 + (size > 0 ? 1 : 0) * (1 + 1 + 1 + 1 + size * 4 + updateData.comment.length())); + data << uint8(updateData.updateType); // Lfg Update type + data << uint8(size > 0); // Extra info + if (size) { - data << uint8(queued); // Join the queue - data << uint8(0); // unk - Always 0 - data << uint8(0); // unk - Always 0 + data << uint8(queued); // Join the queue + data << uint8(0); // unk - Always 0 + data << uint8(0); // unk - Always 0 data << uint8(size); - if (size) - for (LfgDungeonSet::const_iterator it = updateData.dungeons.begin(); it != updateData.dungeons.end(); ++it) - data << uint32(*it); + for (LfgDungeonSet::const_iterator it = updateData.dungeons.begin(); it != updateData.dungeons.end(); ++it) + data << uint32(*it); data << updateData.comment; } SendPacket(&data); @@ -327,51 +352,42 @@ void WorldSession::SendLfgUpdatePlayer(const LfgUpdateData& updateData) void WorldSession::SendLfgUpdateParty(const LfgUpdateData& updateData) { bool join = false; - bool extrainfo = false; bool queued = false; - uint64 guid = GetPlayer()->GetGUID(); uint8 size = uint8(updateData.dungeons.size()); switch (updateData.updateType) { - case LFG_UPDATETYPE_JOIN_PROPOSAL: - extrainfo = true; - break; - case LFG_UPDATETYPE_ADDED_TO_QUEUE: - extrainfo = true; - join = true; + case LFG_UPDATETYPE_ADDED_TO_QUEUE: // Rolecheck Success queued = true; - break; - case LFG_UPDATETYPE_UPDATE_STATUS: - extrainfo = size > 0; - join = true; - queued = true; - break; + // no break on purpose case LFG_UPDATETYPE_PROPOSAL_BEGIN: - extrainfo = true; join = true; break; + case LFG_UPDATETYPE_UPDATE_STATUS: + join = updateData.state != LFG_STATE_ROLECHECK && updateData.state != LFG_STATE_NONE; + queued = updateData.state == LFG_STATE_QUEUED; + break; default: break; } - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_UPDATE_PARTY [" UI64FMTD "] updatetype: %u", guid, updateData.updateType); - WorldPacket data(SMSG_LFG_UPDATE_PARTY, 1 + 1 + (extrainfo ? 1 : 0) * (1 + 1 + 1 + 1 + 1 + size * 4 + updateData.comment.length())); - data << uint8(updateData.updateType); // Lfg Update type - data << uint8(extrainfo); // Extra info - if (extrainfo) + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_UPDATE_PARTY %s updatetype: %u", + GetPlayerInfo().c_str(), updateData.updateType); + WorldPacket data(SMSG_LFG_UPDATE_PARTY, 1 + 1 + (size > 0 ? 1 : 0) * (1 + 1 + 1 + 1 + 1 + size * 4 + updateData.comment.length())); + data << uint8(updateData.updateType); // Lfg Update type + data << uint8(size > 0); // Extra info + if (size) { - data << uint8(join); // LFG Join - data << uint8(queued); // Join the queue - data << uint8(0); // unk - Always 0 - data << uint8(0); // unk - Always 0 + data << uint8(join); // LFG Join + data << uint8(queued); // Join the queue + data << uint8(0); // unk - Always 0 + data << uint8(0); // unk - Always 0 for (uint8 i = 0; i < 3; ++i) - data << uint8(0); // unk - Always 0 + data << uint8(0); // unk - Always 0 data << uint8(size); - if (size) - for (LfgDungeonSet::const_iterator it = updateData.dungeons.begin(); it != updateData.dungeons.end(); ++it) - data << uint32(*it); + for (LfgDungeonSet::const_iterator it = updateData.dungeons.begin(); it != updateData.dungeons.end(); ++it) + data << uint32(*it); data << updateData.comment; } SendPacket(&data); @@ -379,7 +395,8 @@ void WorldSession::SendLfgUpdateParty(const LfgUpdateData& updateData) void WorldSession::SendLfgRoleChosen(uint64 guid, uint8 roles) { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_ROLE_CHOSEN [" UI64FMTD "] guid: [" UI64FMTD "] roles: %u", GetPlayer()->GetGUID(), guid, roles); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_ROLE_CHOSEN %s guid: %u roles: %u", + GetPlayerInfo().c_str(), GUID_LOPART(guid), roles); WorldPacket data(SMSG_LFG_ROLE_CHOSEN, 8 + 1 + 4); data << uint64(guid); // Guid @@ -396,7 +413,7 @@ void WorldSession::SendLfgRoleCheckUpdate(const LfgRoleCheck& roleCheck) else dungeons = roleCheck.dungeons; - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_ROLE_CHECK_UPDATE [" UI64FMTD "]", GetPlayer()->GetGUID()); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_ROLE_CHECK_UPDATE %s", GetPlayerInfo().c_str()); WorldPacket data(SMSG_LFG_ROLE_CHECK_UPDATE, 4 + 1 + 1 + dungeons.size() * 4 + 1 + roleCheck.roles.size() * (8 + 1 + 4 + 1)); data << uint32(roleCheck.state); // Check result @@ -421,7 +438,7 @@ void WorldSession::SendLfgRoleCheckUpdate(const LfgRoleCheck& roleCheck) data << uint8(roles > 0); // Ready data << uint32(roles); // Roles Player* player = ObjectAccessor::FindPlayer(guid); - data << uint8(player ? player->getLevel() : 0); // Level + data << uint8(player ? player->getLevel() : 0); // Level for (LfgRolesMap::const_iterator it = roleCheck.roles.begin(); it != roleCheck.roles.end(); ++it) { @@ -434,7 +451,7 @@ void WorldSession::SendLfgRoleCheckUpdate(const LfgRoleCheck& roleCheck) data << uint8(roles > 0); // Ready data << uint32(roles); // Roles player = ObjectAccessor::FindPlayer(guid); - data << uint8(player ? player->getLevel() : 0); // Level + data << uint8(player ? player->getLevel() : 0);// Level } } SendPacket(&data); @@ -446,7 +463,8 @@ void WorldSession::SendLfgJoinResult(const LfgJoinResultData& joinData) for (LfgLockPartyMap::const_iterator it = joinData.lockmap.begin(); it != joinData.lockmap.end(); ++it) size += 8 + 4 + uint32(it->second.size()) * (4 + 4); - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_JOIN_RESULT [" UI64FMTD "] checkResult: %u checkValue: %u", GetPlayer()->GetGUID(), joinData.result, joinData.state); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_JOIN_RESULT %s checkResult: %u checkValue: %u", + GetPlayerInfo().c_str(), joinData.result, joinData.state); WorldPacket data(SMSG_LFG_JOIN_RESULT, 4 + 4 + size); data << uint32(joinData.result); // Check Result data << uint32(joinData.state); // Check Value @@ -457,8 +475,8 @@ void WorldSession::SendLfgJoinResult(const LfgJoinResultData& joinData) void WorldSession::SendLfgQueueStatus(const LfgQueueStatusData& queueData) { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_QUEUE_STATUS [" UI64FMTD "] dungeon: %u - waitTime: %d - avgWaitTime: %d - waitTimeTanks: %d - waitTimeHealer: %d - waitTimeDps: %d - queuedTime: %u - tanks: %u - healers: %u - dps: %u", - GetPlayer()->GetGUID(), queueData.dungeonId, queueData.waitTime, queueData.waitTimeAvg, queueData.waitTimeTank, queueData.waitTimeHealer, queueData.waitTimeDps, queueData.queuedTime, queueData.tanks, queueData.healers, queueData.dps); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_QUEUE_STATUS %s dungeon: %u - waitTime: %d - avgWaitTime: %d - waitTimeTanks: %d - waitTimeHealer: %d - waitTimeDps: %d - queuedTime: %u - tanks: %u - healers: %u - dps: %u", + GetPlayerInfo().c_str(), queueData.dungeonId, queueData.waitTime, queueData.waitTimeAvg, queueData.waitTimeTank, queueData.waitTimeHealer, queueData.waitTimeDps, queueData.queuedTime, queueData.tanks, queueData.healers, queueData.dps); WorldPacket data(SMSG_LFG_QUEUE_STATUS, 4 + 4 + 4 + 4 + 4 +4 + 1 + 1 + 1 + 4); data << uint32(queueData.dungeonId); // Dungeon @@ -481,7 +499,8 @@ void WorldSession::SendLfgPlayerReward(uint32 rdungeonEntry, uint32 sdungeonEntr uint8 itemNum = uint8(quest ? quest->GetRewItemsCount() : 0); - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PLAYER_REWARD [" UI64FMTD "] rdungeonEntry: %u - sdungeonEntry: %u - done: %u", GetPlayer()->GetGUID(), rdungeonEntry, sdungeonEntry, done); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PLAYER_REWARD %s rdungeonEntry: %u - sdungeonEntry: %u - done: %u", + GetPlayerInfo().c_str(), rdungeonEntry, sdungeonEntry, done); WorldPacket data(SMSG_LFG_PLAYER_REWARD, 4 + 4 + 1 + 4 + 4 + 4 + 4 + 4 + 1 + itemNum * (4 + 4 + 4)); data << uint32(rdungeonEntry); // Random Dungeon Finished data << uint32(sdungeonEntry); // Dungeon Finished @@ -522,8 +541,12 @@ void WorldSession::SendLfgBootProposalUpdate(const LfgPlayerBoot& boot) ++agreeNum; } } - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_BOOT_PROPOSAL_UPDATE [" UI64FMTD "] inProgress: %u - didVote: %u - agree: %u - victim: [" UI64FMTD "] votes: %u - agrees: %u - left: %u - needed: %u - reason %s", - guid, uint8(boot.inProgress), uint8(playerVote != LFG_ANSWER_PENDING), uint8(playerVote == LFG_ANSWER_AGREE), boot.victim, votesNum, agreeNum, secsleft, LFG_GROUP_KICK_VOTES_NEEDED, boot.reason.c_str()); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_BOOT_PROPOSAL_UPDATE %s inProgress: %u - " + "didVote: %u - agree: %u - victim: %u votes: %u - agrees: %u - left: %u - " + "needed: %u - reason %s", + GetPlayerInfo().c_str(), uint8(boot.inProgress), uint8(playerVote != LFG_ANSWER_PENDING), + uint8(playerVote == LFG_ANSWER_AGREE), GUID_LOPART(boot.victim), votesNum, agreeNum, + secsleft, LFG_GROUP_KICK_VOTES_NEEDED, boot.reason.c_str()); WorldPacket data(SMSG_LFG_BOOT_PROPOSAL_UPDATE, 1 + 1 + 1 + 8 + 4 + 4 + 4 + 4 + boot.reason.length()); data << uint8(boot.inProgress); // Vote in progress data << uint8(playerVote != LFG_ANSWER_PENDING); // Did Vote @@ -544,7 +567,8 @@ void WorldSession::SendLfgUpdateProposal(uint32 proposalId, LfgProposal const& p bool silent = !proposal.isNew && gguid == proposal.group; uint32 dungeonEntry = proposal.dungeonId; - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PROPOSAL_UPDATE [" UI64FMTD "] state: %u", guid, proposal.state); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_PROPOSAL_UPDATE %s state: %u", + GetPlayerInfo().c_str(), proposal.state); WorldPacket data(SMSG_LFG_PROPOSAL_UPDATE, 4 + 1 + 4 + 4 + 1 + 1 + proposal.players.size() * (4 + 1 + 1 + 1 + 1 +1)); // show random dungeon if player selected random dungeon and it's not lfg group @@ -577,18 +601,19 @@ void WorldSession::SendLfgUpdateProposal(uint32 proposalId, LfgProposal const& p } else { - data << uint8(player.group == proposal.group); // In dungeon (silent) - data << uint8(player.group == gguid); // Same Group than player + data << uint8(player.group == proposal.group); // In dungeon (silent) + data << uint8(player.group == gguid); // Same Group than player } - data << uint8(player.accept != LFG_ANSWER_PENDING); // Answered - data << uint8(player.accept == LFG_ANSWER_AGREE); // Accepted + data << uint8(player.accept != LFG_ANSWER_PENDING);// Answered + data << uint8(player.accept == LFG_ANSWER_AGREE); // Accepted } SendPacket(&data); } void WorldSession::SendLfgLfrList(bool update) { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_LFR_LIST [" UI64FMTD "] update: %u", GetPlayer()->GetGUID(), update ? 1 : 0); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_LFR_LIST %s update: %u", + GetPlayerInfo().c_str(), update ? 1 : 0); WorldPacket data(SMSG_LFG_UPDATE_SEARCH, 1); data << uint8(update); // In Lfg Queue? SendPacket(&data); @@ -596,14 +621,15 @@ void WorldSession::SendLfgLfrList(bool update) void WorldSession::SendLfgDisabled() { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_DISABLED [" UI64FMTD "]", GetPlayer()->GetGUID()); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_DISABLED %s", GetPlayerInfo().c_str()); WorldPacket data(SMSG_LFG_DISABLED, 0); SendPacket(&data); } void WorldSession::SendLfgOfferContinue(uint32 dungeonEntry) { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_OFFER_CONTINUE [" UI64FMTD "] dungeon entry: %u", GetPlayer()->GetGUID(), dungeonEntry); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_OFFER_CONTINUE %s dungeon entry: %u", + GetPlayerInfo().c_str(), dungeonEntry); WorldPacket data(SMSG_LFG_OFFER_CONTINUE, 4); data << uint32(dungeonEntry); SendPacket(&data); @@ -611,48 +637,18 @@ void WorldSession::SendLfgOfferContinue(uint32 dungeonEntry) void WorldSession::SendLfgTeleportError(uint8 err) { - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_TELEPORT_DENIED [" UI64FMTD "] reason: %u", GetPlayer()->GetGUID(), err); + sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_TELEPORT_DENIED %s reason: %u", + GetPlayerInfo().c_str(), err); WorldPacket data(SMSG_LFG_TELEPORT_DENIED, 4); data << uint32(err); // Error SendPacket(&data); } -void WorldSession::HandleLfgGetStatus(WorldPacket& /*recvData*/) -{ - uint64 guid = GetPlayer()->GetGUID(); - sLog->outDebug(LOG_FILTER_LFG, "SMSG_LFG_GET_STATUS [" UI64FMTD "]", guid); - - LfgUpdateData updateData = LfgUpdateData(LFG_UPDATETYPE_UPDATE_STATUS); - LfgState state = sLFGMgr->GetLfgStatus(guid, updateData); - - if (state == LFG_STATE_NONE || updateData.dungeons.empty()) - { - SendLfgUpdatePlayer(updateData); - SendLfgUpdateParty(updateData); - return; - } - - if (state != LFG_STATE_QUEUED) - return; - - if (GetPlayer()->GetGroup()) - { - SendLfgUpdateParty(updateData); - updateData.dungeons.clear(); - SendLfgUpdatePlayer(updateData); - } - else - { - SendLfgUpdatePlayer(updateData); - updateData.dungeons.clear(); - SendLfgUpdateParty(updateData); - } -} - /* void WorldSession::SendLfrUpdateListOpcode(uint32 dungeonEntry) { - sLog->outDebug(LOG_FILTER_PACKETIO, "SMSG_LFG_UPDATE_LIST [" UI64FMTD "] dungeon entry: %u", GetPlayer()->GetGUID(), dungeonEntry); + sLog->outDebug(LOG_FILTER_PACKETIO, "SMSG_LFG_UPDATE_LIST %s dungeon entry: %u", + GetPlayerInfo().c_str(), dungeonEntry); WorldPacket data(SMSG_LFG_UPDATE_LIST); SendPacket(&data); } diff --git a/src/server/game/Handlers/LootHandler.cpp b/src/server/game/Handlers/LootHandler.cpp index 83deaaa1bc6..1c9719a210f 100755 --- a/src/server/game/Handlers/LootHandler.cpp +++ b/src/server/game/Handlers/LootHandler.cpp @@ -17,18 +17,19 @@ */ #include "Common.h" -#include "WorldPacket.h" #include "Log.h" #include "Corpse.h" +#include "Creature.h" #include "GameObject.h" -#include "Player.h" -#include "ObjectAccessor.h" -#include "WorldSession.h" +#include "Group.h" #include "LootMgr.h" +#include "ObjectAccessor.h" #include "Object.h" -#include "Group.h" +#include "Opcodes.h" +#include "Player.h" #include "World.h" -#include "Util.h" +#include "WorldPacket.h" +#include "WorldSession.h" void WorldSession::HandleAutostoreLootItemOpcode(WorldPacket & recvData) { diff --git a/src/server/game/Handlers/MailHandler.cpp b/src/server/game/Handlers/MailHandler.cpp index 5a7a3b52b56..cb3a6d920b8 100755 --- a/src/server/game/Handlers/MailHandler.cpp +++ b/src/server/game/Handlers/MailHandler.cpp @@ -607,10 +607,8 @@ void WorldSession::HandleGetMailList(WorldPacket & recvData) case MAIL_CREATURE: case MAIL_GAMEOBJECT: case MAIL_AUCTION: - data << uint32((*itr)->sender); // creature/gameobject entry, auction id - break; - case MAIL_ITEM: // item entry (?) sender = "Unknown", NYI - data << uint32(0); // item entry + case MAIL_CALENDAR: + data << uint32((*itr)->sender); // creature/gameobject entry, auction id, calendar event id? break; } diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index 8928a7c15a1..aa182a16d91 100755 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -888,7 +888,7 @@ void WorldSession::HandleAreaTriggerOpcode(WorldPacket& recvData) } if (player->isDebugAreaTriggers) - ChatHandler(player).PSendSysMessage(LANG_DEBUG_AREATRIGGER_REACHED, triggerId); + ChatHandler(player->GetSession()).PSendSysMessage(LANG_DEBUG_AREATRIGGER_REACHED, triggerId); if (sScriptMgr->OnAreaTrigger(player, atEntry)) return; @@ -1382,25 +1382,21 @@ void WorldSession::HandleFarSightOpcode(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_FAR_SIGHT"); - uint8 apply; + bool apply; recvData >> apply; - switch (apply) + if (apply) { - case 0: - sLog->outDebug(LOG_FILTER_NETWORKIO, "Player %u set vision to self", _player->GetGUIDLow()); - _player->SetSeer(_player); - break; - case 1: - sLog->outDebug(LOG_FILTER_NETWORKIO, "Added FarSight " UI64FMTD " to player %u", _player->GetUInt64Value(PLAYER_FARSIGHT), _player->GetGUIDLow()); - if (WorldObject* target = _player->GetViewpoint()) - _player->SetSeer(target); - else - sLog->outError(LOG_FILTER_NETWORKIO, "Player %s requests non-existing seer " UI64FMTD, _player->GetName().c_str(), _player->GetUInt64Value(PLAYER_FARSIGHT)); - break; - default: - sLog->outDebug(LOG_FILTER_NETWORKIO, "Unhandled mode in CMSG_FAR_SIGHT: %u", apply); - return; + sLog->outDebug(LOG_FILTER_NETWORKIO, "Added FarSight " UI64FMTD " to player %u", _player->GetUInt64Value(PLAYER_FARSIGHT), _player->GetGUIDLow()); + if (WorldObject* target = _player->GetViewpoint()) + _player->SetSeer(target); + else + sLog->outError(LOG_FILTER_NETWORKIO, "Player %s requests non-existing seer " UI64FMTD, _player->GetName().c_str(), _player->GetUInt64Value(PLAYER_FARSIGHT)); + } + else + { + sLog->outDebug(LOG_FILTER_NETWORKIO, "Player %u set vision to self", _player->GetGUIDLow()); + _player->SetSeer(_player); } GetPlayer()->UpdateVisibilityForPlayer(); @@ -1467,7 +1463,7 @@ void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPacket& recvData) if (mode >= MAX_DUNGEON_DIFFICULTY) { - sLog->outError(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode); + sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player %d sent an invalid instance mode %d!", _player->GetGUIDLow(), mode); return; } @@ -1478,7 +1474,7 @@ void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPacket& recvData) Map* map = _player->FindMap(); if (map && map->IsDungeon()) { - sLog->outError(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player (Name: %s, GUID: %u) tried to reset the instance while player is inside!", + sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player (Name: %s, GUID: %u) tried to reset the instance while player is inside!", _player->GetName().c_str(), _player->GetGUIDLow()); return; } @@ -1499,7 +1495,7 @@ void WorldSession::HandleSetDungeonDifficultyOpcode(WorldPacket& recvData) if (groupGuy->GetMap()->IsNonRaidDungeon()) { - sLog->outError(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player %d tried to reset the instance while group member (Name: %s, GUID: %u) is inside!", + sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetDungeonDifficultyOpcode: player %d tried to reset the instance while group member (Name: %s, GUID: %u) is inside!", _player->GetGUIDLow(), groupGuy->GetName().c_str(), groupGuy->GetGUIDLow()); return; } @@ -1534,7 +1530,7 @@ void WorldSession::HandleSetRaidDifficultyOpcode(WorldPacket& recvData) Map* map = _player->FindMap(); if (map && map->IsDungeon()) { - sLog->outError(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow()); + sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow()); return; } @@ -1557,7 +1553,7 @@ void WorldSession::HandleSetRaidDifficultyOpcode(WorldPacket& recvData) if (groupGuy->GetMap()->IsRaid()) { - sLog->outError(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow()); + sLog->outDebug(LOG_FILTER_NETWORKIO, "WorldSession::HandleSetRaidDifficultyOpcode: player %d tried to reset the instance while inside!", _player->GetGUIDLow()); return; } } diff --git a/src/server/game/Handlers/NPCHandler.cpp b/src/server/game/Handlers/NPCHandler.cpp index 0265d1e6f60..ef0f8e130b6 100755 --- a/src/server/game/Handlers/NPCHandler.cpp +++ b/src/server/game/Handlers/NPCHandler.cpp @@ -31,6 +31,7 @@ #include "ObjectAccessor.h" #include "Creature.h" #include "Pet.h" +#include "ReputationMgr.h" #include "BattlegroundMgr.h" #include "Battleground.h" #include "ScriptMgr.h" diff --git a/src/server/game/Handlers/PetHandler.cpp b/src/server/game/Handlers/PetHandler.cpp index 7ed5e3846ef..97a2765b4df 100755 --- a/src/server/game/Handlers/PetHandler.cpp +++ b/src/server/game/Handlers/PetHandler.cpp @@ -31,8 +31,9 @@ #include "World.h" #include "Group.h" #include "SpellInfo.h" +#include "Player.h" -void WorldSession::HandleDismissCritter(WorldPacket &recvData) +void WorldSession::HandleDismissCritter(WorldPacket& recvData) { uint64 guid; recvData >> guid; @@ -138,7 +139,7 @@ void WorldSession::HandlePetStopAttack(WorldPacket &recvData) pet->AttackStop(); } -void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid, uint16 flag, uint64 guid2) +void WorldSession::HandlePetActionHelper(Unit* pet, uint64 guid1, uint32 spellid, uint16 flag, uint64 guid2) { CharmInfo* charmInfo = pet->GetCharmInfo(); if (!charmInfo) @@ -848,15 +849,15 @@ void WorldSession::SendPetNameInvalid(uint32 error, const std::string& name, Dec SendPacket(&data); } -void WorldSession::HandlePetLearnTalent(WorldPacket & recvData) +void WorldSession::HandlePetLearnTalent(WorldPacket& recvData) { sLog->outDebug(LOG_FILTER_NETWORKIO, "WORLD: CMSG_PET_LEARN_TALENT"); uint64 guid; - uint32 talent_id, requested_rank; - recvData >> guid >> talent_id >> requested_rank; + uint32 talentId, requestedRank; + recvData >> guid >> talentId >> requestedRank; - _player->LearnPetTalent(guid, talent_id, requested_rank); + _player->LearnPetTalent(guid, talentId, requestedRank); _player->SendTalentsInfoData(true); } diff --git a/src/server/game/Handlers/SkillHandler.cpp b/src/server/game/Handlers/SkillHandler.cpp index 88ae01f59be..ec389142182 100755 --- a/src/server/game/Handlers/SkillHandler.cpp +++ b/src/server/game/Handlers/SkillHandler.cpp @@ -18,13 +18,14 @@ #include "Common.h" #include "DatabaseEnv.h" -#include "Opcodes.h" #include "Log.h" +#include "ObjectAccessor.h" +#include "Opcodes.h" #include "Player.h" +#include "Pet.h" +#include "UpdateMask.h" #include "WorldPacket.h" #include "WorldSession.h" -#include "ObjectAccessor.h" -#include "UpdateMask.h" void WorldSession::HandleLearnTalentOpcode(WorldPacket & recvData) { diff --git a/src/server/game/Handlers/SpellHandler.cpp b/src/server/game/Handlers/SpellHandler.cpp index 1c834b323ac..270980c8e7c 100755 --- a/src/server/game/Handlers/SpellHandler.cpp +++ b/src/server/game/Handlers/SpellHandler.cpp @@ -32,6 +32,7 @@ #include "ScriptMgr.h" #include "GameObjectAI.h" #include "SpellAuraEffects.h" +#include "Player.h" void WorldSession::HandleClientCastFlags(WorldPacket& recvPacket, uint8 castFlags, SpellCastTargets& targets) { diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 41e834d84e8..1571d857f41 100755 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -17,15 +17,16 @@ */ #include "zlib.h" -#include "Language.h" -#include "WorldPacket.h" #include "Common.h" +#include "Language.h" #include "ObjectMgr.h" -#include "TicketMgr.h" +#include "Opcodes.h" #include "Player.h" +#include "TicketMgr.h" +#include "Util.h" #include "World.h" +#include "WorldPacket.h" #include "WorldSession.h" -#include "Util.h" void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) { diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index f8df5862df0..a370cf25d97 100755 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -16,15 +16,18 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "InstanceScript.h" -#include "DatabaseEnv.h" -#include "Map.h" -#include "Player.h" -#include "GameObject.h" #include "Creature.h" #include "CreatureAI.h" -#include "Log.h" +#include "DatabaseEnv.h" +#include "GameObject.h" +#include "InstanceScript.h" #include "LFGMgr.h" +#include "Log.h" +#include "Map.h" +#include "Player.h" +#include "Pet.h" +#include "WorldSession.h" +#include "Opcodes.h" void InstanceScript::SaveToDB() { diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index fca8d78a3de..ef3d2b9fbd6 100755 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -25,6 +25,7 @@ #include "SpellMgr.h" #include "SpellInfo.h" #include "Group.h" +#include "Player.h" static Rates const qualityToRate[MAX_ITEM_QUALITY] = { diff --git a/src/server/game/Mails/Mail.cpp b/src/server/game/Mails/Mail.cpp index 929a1d81d57..108856d81b6 100755 --- a/src/server/game/Mails/Mail.cpp +++ b/src/server/game/Mails/Mail.cpp @@ -26,6 +26,7 @@ #include "BattlegroundMgr.h" #include "Item.h" #include "AuctionHouseMgr.h" +#include "CalendarMgr.h" MailSender::MailSender(Object* sender, MailStationery stationery) : m_stationery(stationery) { @@ -39,10 +40,10 @@ MailSender::MailSender(Object* sender, MailStationery stationery) : m_stationery m_messageType = MAIL_GAMEOBJECT; m_senderId = sender->GetEntry(); break; - case TYPEID_ITEM: + /*case TYPEID_ITEM: m_messageType = MAIL_ITEM; m_senderId = sender->GetEntry(); - break; + break;*/ case TYPEID_PLAYER: m_messageType = MAIL_NORMAL; m_senderId = sender->GetGUIDLow(); @@ -55,6 +56,11 @@ MailSender::MailSender(Object* sender, MailStationery stationery) : m_stationery } } +MailSender::MailSender(CalendarEvent* sender) + : m_messageType(MAIL_CALENDAR), m_senderId(sender->GetEventId()), m_stationery(MAIL_STATIONERY_DEFAULT) // what stationery we should use here? +{ +} + MailSender::MailSender(AuctionEntry* sender) : m_messageType(MAIL_AUCTION), m_senderId(sender->GetHouseId()), m_stationery(MAIL_STATIONERY_AUCTION) { diff --git a/src/server/game/Mails/Mail.h b/src/server/game/Mails/Mail.h index 7c12ac1a1c6..c2771f4b57c 100755 --- a/src/server/game/Mails/Mail.h +++ b/src/server/game/Mails/Mail.h @@ -23,6 +23,7 @@ #include <map> struct AuctionEntry; +struct CalendarEvent; class Item; class Object; class Player; @@ -36,7 +37,7 @@ enum MailMessageType MAIL_AUCTION = 2, MAIL_CREATURE = 3, // client send CMSG_CREATURE_QUERY on this mailmessagetype MAIL_GAMEOBJECT = 4, // client send CMSG_GAMEOBJECT_QUERY on this mailmessagetype - MAIL_ITEM = 5 // client send CMSG_ITEM_QUERY on this mailmessagetype + MAIL_CALENDAR = 5 }; enum MailCheckMask @@ -85,6 +86,7 @@ class MailSender { } MailSender(Object* sender, MailStationery stationery = MAIL_STATIONERY_DEFAULT); + MailSender(CalendarEvent* sender); MailSender(AuctionEntry* sender); MailSender(Player* sender); public: // Accessors diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index b1200252c54..1bb651831c7 100755 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -17,23 +17,25 @@ */ #include "Map.h" -#include "GridStates.h" -#include "ScriptMgr.h" -#include "VMapFactory.h" +#include "Battleground.h" #include "MMapFactory.h" -#include "MapInstanced.h" #include "CellImpl.h" +#include "DynamicTree.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" -#include "Transport.h" +#include "GridStates.h" +#include "Group.h" #include "InstanceScript.h" -#include "ObjectAccessor.h" +#include "LFGMgr.h" +#include "MapInstanced.h" #include "MapManager.h" +#include "ObjectAccessor.h" #include "ObjectMgr.h" -#include "Group.h" -#include "LFGMgr.h" -#include "DynamicTree.h" +#include "Pet.h" +#include "ScriptMgr.h" +#include "Transport.h" #include "Vehicle.h" +#include "VMapFactory.h" union u_map_magic { @@ -157,7 +159,7 @@ void Map::LoadMap(int gx, int gy, bool reload) // load grid map for base map if (!m_parentMap->GridMaps[gx][gy]) - m_parentMap->EnsureGridCreated(GridCoord(63-gx, 63-gy)); + m_parentMap->EnsureGridCreated_i(GridCoord(63-gx, 63-gy)); ((MapInstanced*)(m_parentMap))->AddGridMapReference(GridCoord(gx, gy)); GridMaps[gx][gy] = m_parentMap->GridMaps[gx][gy]; @@ -322,32 +324,34 @@ void Map::DeleteFromWorld(Player* player) delete player; } +void Map::EnsureGridCreated(const GridCoord &p) +{ + TRINITY_GUARD(ACE_Thread_Mutex, Lock); + EnsureGridCreated_i(p); +} + //Create NGrid so the object can be added to it //But object data is not loaded here -void Map::EnsureGridCreated(const GridCoord &p) +void Map::EnsureGridCreated_i(const GridCoord &p) { if (!getNGrid(p.x_coord, p.y_coord)) { - TRINITY_GUARD(ACE_Thread_Mutex, Lock); - if (!getNGrid(p.x_coord, p.y_coord)) - { - sLog->outDebug(LOG_FILTER_MAPS, "Creating grid[%u, %u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); + sLog->outDebug(LOG_FILTER_MAPS, "Creating grid[%u, %u] for map %u instance %u", p.x_coord, p.y_coord, GetId(), i_InstanceId); - setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD)), - p.x_coord, p.y_coord); + setNGrid(new NGridType(p.x_coord*MAX_NUMBER_OF_GRIDS + p.y_coord, p.x_coord, p.y_coord, i_gridExpiry, sWorld->getBoolConfig(CONFIG_GRID_UNLOAD)), + p.x_coord, p.y_coord); - // build a linkage between this map and NGridType - buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); + // build a linkage between this map and NGridType + buildNGridLinkage(getNGrid(p.x_coord, p.y_coord)); - getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); + getNGrid(p.x_coord, p.y_coord)->SetGridState(GRID_STATE_IDLE); - //z coord - int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord; - int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord; + //z coord + int gx = (MAX_NUMBER_OF_GRIDS - 1) - p.x_coord; + int gy = (MAX_NUMBER_OF_GRIDS - 1) - p.y_coord; - if (!GridMaps[gx][gy]) - LoadMapAndVMap(gx, gy); - } + if (!GridMaps[gx][gy]) + LoadMapAndVMap(gx, gy); } } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index 126d0855352..e35f430b638 100755 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -502,6 +502,7 @@ class Map : public GridRefManager<NGridType> bool IsGridLoaded(const GridCoord &) const; void EnsureGridCreated(const GridCoord &); + void EnsureGridCreated_i(const GridCoord &); bool EnsureGridLoaded(Cell const&); void EnsureGridLoadedForActiveObject(Cell const&, WorldObject* object); diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp index e0dbc19aff4..f45105c324a 100755 --- a/src/server/game/Maps/MapInstanced.cpp +++ b/src/server/game/Maps/MapInstanced.cpp @@ -25,6 +25,7 @@ #include "InstanceSaveMgr.h" #include "World.h" #include "Group.h" +#include "Player.h" MapInstanced::MapInstanced(uint32 id, time_t expiry) : Map(id, expiry, 0, DUNGEON_DIFFICULTY_NORMAL) { @@ -282,4 +283,4 @@ bool MapInstanced::CanEnter(Player* /*player*/) { //ASSERT(false); return true; -}
\ No newline at end of file +} diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp index f6aa6ff7dc3..96a2a44655d 100755 --- a/src/server/game/Maps/MapManager.cpp +++ b/src/server/game/Maps/MapManager.cpp @@ -33,6 +33,9 @@ #include "Language.h" #include "WorldPacket.h" #include "Group.h" +#include "Player.h" +#include "WorldSession.h" +#include "Opcodes.h" extern GridState* si_GridStates[]; // debugging code, should be deleted some day @@ -439,4 +442,4 @@ void MapManager::FreeInstanceId(uint32 instanceId) SetNextInstanceId(instanceId); _instanceIds[instanceId] = false; -}
\ No newline at end of file +} diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp index b747d065a14..5e5f520505c 100644 --- a/src/server/game/Maps/MapUpdater.cpp +++ b/src/server/game/Maps/MapUpdater.cpp @@ -69,7 +69,7 @@ MapUpdater::~MapUpdater() int MapUpdater::activate(size_t num_threads) { - return m_executor.activate((int)num_threads, new WDBThreadStartReq1, new WDBThreadEndReq1); + return m_executor.start((int)num_threads, new WDBThreadStartReq1, new WDBThreadEndReq1); } int MapUpdater::deactivate() diff --git a/src/server/game/Maps/ZoneScript.h b/src/server/game/Maps/ZoneScript.h index df6349a7664..7b20b0ee676 100755 --- a/src/server/game/Maps/ZoneScript.h +++ b/src/server/game/Maps/ZoneScript.h @@ -32,19 +32,20 @@ class ZoneScript virtual uint32 GetCreatureEntry(uint32 /*guidlow*/, CreatureData const* data) { return data->id; } virtual uint32 GetGameObjectEntry(uint32 /*guidlow*/, uint32 entry) { return entry; } - virtual void OnCreatureCreate(Creature* /*creature*/) {} - virtual void OnCreatureRemove(Creature* /*creature*/) {} - virtual void OnGameObjectCreate(GameObject* /*go*/) {} - virtual void OnGameObjectRemove(GameObject* /*go*/) {} + virtual void OnCreatureCreate(Creature *) { } + virtual void OnCreatureRemove(Creature *) { } - virtual void OnUnitDeath(Unit* /*unit*/) {} + virtual void OnGameObjectCreate(GameObject *) { } + virtual void OnGameObjectRemove(GameObject *) { } + + virtual void OnUnitDeath(Unit*) { } //All-purpose data storage 64 bit - virtual uint64 GetData64(uint32 /*DataId*/) { return 0; } + virtual uint64 GetData64(uint32 /*DataId*/) const { return 0; } virtual void SetData64(uint32 /*DataId*/, uint64 /*Value*/) {} //All-purpose data storage 32 bit - virtual uint32 GetData(uint32 /*DataId*/) { return 0; } + virtual uint32 GetData(uint32 /*DataId*/) const { return 0; } virtual void SetData(uint32 /*DataId*/, uint32 /*Value*/) {} virtual void ProcessEvent(WorldObject* /*obj*/, uint32 /*eventId*/) {} diff --git a/src/server/game/Miscellaneous/Formulas.h b/src/server/game/Miscellaneous/Formulas.h index dac5b1ef9a2..4f358d7a145 100755 --- a/src/server/game/Miscellaneous/Formulas.h +++ b/src/server/game/Miscellaneous/Formulas.h @@ -22,6 +22,7 @@ #include "World.h" #include "SharedDefines.h" #include "ScriptMgr.h" +#include "Player.h" namespace Trinity { diff --git a/src/server/game/Miscellaneous/Language.h b/src/server/game/Miscellaneous/Language.h index 07bfd284a7d..5321202b256 100755 --- a/src/server/game/Miscellaneous/Language.h +++ b/src/server/game/Miscellaneous/Language.h @@ -950,8 +950,8 @@ enum TrinityStrings LANG_BATTLEGROUND = 5015, LANG_ARENA = 5016, LANG_RAID = 5017, - LANG_HEROIC = 5018, - LANG_MOUNTABLE = 5019, + //= 5018, + //= 5019, LANG_NPCINFO_PHASEMASK = 5020, LANG_NPCINFO_ARMOR = 5021, LANG_CHANNEL_ENABLE_OWNERSHIP = 5022, diff --git a/src/server/game/Miscellaneous/SharedDefines.h b/src/server/game/Miscellaneous/SharedDefines.h index ae594f555e7..7d69753b287 100755 --- a/src/server/game/Miscellaneous/SharedDefines.h +++ b/src/server/game/Miscellaneous/SharedDefines.h @@ -3423,106 +3423,113 @@ enum ActivateTaxiReply ERR_TAXINOTSTANDING = 12 }; -// Calendar - start - -enum CalendarFlags -{ - CALENDAR_FLAG_ALL_ALLOWED = 0x001, - CALENDAR_FLAG_INVITES_LOCKED = 0x010, - CALENDAR_FLAG_WITHOUT_INVITES = 0x040, - CALENDAR_FLAG_GUILD_ONLY = 0x400 -}; - -enum CalendarActionData -{ - CALENDAR_ACTION_NONE, - CALENDAR_ACTION_ADD_EVENT, - CALENDAR_ACTION_MODIFY_EVENT, - CALENDAR_ACTION_REMOVE_EVENT, - CALENDAR_ACTION_COPY_EVENT, - CALENDAR_ACTION_ADD_EVENT_INVITE, - CALENDAR_ACTION_MODIFY_EVENT_INVITE, - CALENDAR_ACTION_MODIFY_MODERATOR_EVENT_INVITE, - CALENDAR_ACTION_REMOVE_EVENT_INVITE, - CALENDAR_ACTION_SIGNUP_TO_EVENT -}; - -enum CalendarModerationRank -{ - CALENDAR_RANK_PLAYER, - CALENDAR_RANK_MODERATOR, - CALENDAR_RANK_OWNER -}; - -enum CalendarSendEventType -{ - CALENDAR_SENDTYPE_GET, - CALENDAR_SENDTYPE_ADD, - CALENDAR_SENDTYPE_COPY -}; - -enum CalendarEventType -{ - CALENDAR_TYPE_RAID, - CALENDAR_TYPE_DUNGEON, - CALENDAR_TYPE_PVP, - CALENDAR_TYPE_MEETING, - CALENDAR_TYPE_OTHER -}; - -enum CalendarInviteStatus -{ - CALENDAR_STATUS_INVITED, - CALENDAR_STATUS_ACCEPTED, - CALENDAR_STATUS_DECLINED, - CALENDAR_STATUS_TENTATIVE, - CALENDAR_STATUS_OUT, - CALENDAR_STATUS_STANDBY, - CALENDAR_STATUS_CONFIRMED, - CALENDAR_STATUS_NO_OWNER, - CALENDAR_STATUS_8, - CALENDAR_STATUS_9 -}; - -enum CalendarError -{ - CALENDAR_OK = 0, - CALENDAR_ERROR_GUILD_EVENTS_EXCEEDED = 1, - CALENDAR_ERROR_EVENTS_EXCEEDED = 2, - CALENDAR_ERROR_SELF_INVITES_EXCEEDED = 3, - CALENDAR_ERROR_OTHER_INVITES_EXCEEDED = 4, - CALENDAR_ERROR_PERMISSIONS = 5, - CALENDAR_ERROR_EVENT_INVALID = 6, - CALENDAR_ERROR_NOT_INVITED = 7, - CALENDAR_ERROR_INTERNAL = 8, - CALENDAR_ERROR_GUILD_PLAYER_NOT_IN_GUILD = 9, - CALENDAR_ERROR_ALREADY_INVITED_TO_EVENT_S = 10, - CALENDAR_ERROR_PLAYER_NOT_FOUND = 11, - CALENDAR_ERROR_NOT_ALLIED = 12, - CALENDAR_ERROR_IGNORING_YOU_S = 13, - CALENDAR_ERROR_INVITES_EXCEEDED = 14, - CALENDAR_ERROR_INVALID_DATE = 16, - CALENDAR_ERROR_INVALID_TIME = 17, - - CALENDAR_ERROR_NEEDS_TITLE = 19, - CALENDAR_ERROR_EVENT_PASSED = 20, - CALENDAR_ERROR_EVENT_LOCKED = 21, - CALENDAR_ERROR_DELETE_CREATOR_FAILED = 22, - CALENDAR_ERROR_SYSTEM_DISABLED = 24, - CALENDAR_ERROR_RESTRICTED_ACCOUNT = 25, - CALENDAR_ERROR_ARENA_EVENTS_EXCEEDED = 26, - CALENDAR_ERROR_RESTRICTED_LEVEL = 27, - CALENDAR_ERROR_USER_SQUELCHED = 28, - CALENDAR_ERROR_NO_INVITE = 29, - - CALENDAR_ERROR_EVENT_WRONG_SERVER = 36, - CALENDAR_ERROR_INVITE_WRONG_SERVER = 37, - CALENDAR_ERROR_NO_GUILD_INVITES = 38, - CALENDAR_ERROR_INVALID_SIGNUP = 39, - CALENDAR_ERROR_NO_MODERATOR = 40 -}; - -// Calendar - end +enum DuelCompleteType +{ + DUEL_INTERRUPTED = 0, + DUEL_WON = 1, + DUEL_FLED = 2 +}; +// handle the queue types and bg types separately to enable joining queue for different sized arenas at the same time +enum BattlegroundQueueTypeId +{ + BATTLEGROUND_QUEUE_NONE = 0, + BATTLEGROUND_QUEUE_AV = 1, + BATTLEGROUND_QUEUE_WS = 2, + BATTLEGROUND_QUEUE_AB = 3, + BATTLEGROUND_QUEUE_EY = 4, + BATTLEGROUND_QUEUE_SA = 5, + BATTLEGROUND_QUEUE_IC = 6, + BATTLEGROUND_QUEUE_RB = 7, + BATTLEGROUND_QUEUE_2v2 = 8, + BATTLEGROUND_QUEUE_3v3 = 9, + BATTLEGROUND_QUEUE_5v5 = 10, + MAX_BATTLEGROUND_QUEUE_TYPES +}; + +enum GroupJoinBattlegroundResult +{ + // positive values are indexes in BattlemasterList.dbc + ERR_GROUP_JOIN_BATTLEGROUND_FAIL = 0, // Your group has joined a battleground queue, but you are not eligible (showed for non existing BattlemasterList.dbc indexes) + ERR_BATTLEGROUND_NONE = -1, // not show anything + ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS = -2, // You cannot join the battleground yet because you or one of your party members is flagged as a Deserter. + ERR_ARENA_TEAM_PARTY_SIZE = -3, // Incorrect party size for this arena. + ERR_BATTLEGROUND_TOO_MANY_QUEUES = -4, // You can only be queued for 2 battles at once + ERR_BATTLEGROUND_CANNOT_QUEUE_FOR_RATED = -5, // You cannot queue for a rated match while queued for other battles + ERR_BATTLEDGROUND_QUEUED_FOR_RATED = -6, // You cannot queue for another battle while queued for a rated arena match + ERR_BATTLEGROUND_TEAM_LEFT_QUEUE = -7, // Your team has left the arena queue + ERR_BATTLEGROUND_NOT_IN_BATTLEGROUND = -8, // You can't do that in a battleground. + ERR_BATTLEGROUND_JOIN_XP_GAIN = -9, // wtf, doesn't exist in client... + ERR_BATTLEGROUND_JOIN_RANGE_INDEX = -10, // Cannot join the queue unless all members of your party are in the same battleground level range. + ERR_BATTLEGROUND_JOIN_TIMED_OUT = -11, // %s was unavailable to join the queue. (uint64 guid exist in client cache) + ERR_BATTLEGROUND_JOIN_FAILED = -12, // Join as a group failed (uint64 guid doesn't exist in client cache) + ERR_LFG_CANT_USE_BATTLEGROUND = -13, // You cannot queue for a battleground or arena while using the dungeon system. + ERR_IN_RANDOM_BG = -14, // Can't do that while in a Random Battleground queue. + ERR_IN_NON_RANDOM_BG = -15 // Can't queue for Random Battleground while in another Battleground queue. +}; + +enum PetNameInvalidReason +{ + // custom, not send + PET_NAME_SUCCESS = 0, + + PET_NAME_INVALID = 1, + PET_NAME_NO_NAME = 2, + PET_NAME_TOO_SHORT = 3, + PET_NAME_TOO_LONG = 4, + PET_NAME_MIXED_LANGUAGES = 6, + PET_NAME_PROFANE = 7, + PET_NAME_RESERVED = 8, + PET_NAME_THREE_CONSECUTIVE = 11, + PET_NAME_INVALID_SPACE = 12, + PET_NAME_CONSECUTIVE_SPACES = 13, + PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14, + PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15, + PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16 +}; + +enum DungeonStatusFlag +{ + DUNGEON_STATUSFLAG_NORMAL = 0x01, + DUNGEON_STATUSFLAG_HEROIC = 0x02, + + RAID_STATUSFLAG_10MAN_NORMAL = 0x01, + RAID_STATUSFLAG_25MAN_NORMAL = 0x02, + RAID_STATUSFLAG_10MAN_HEROIC = 0x04, + RAID_STATUSFLAG_25MAN_HEROIC = 0x08 +}; + +enum PartyResult +{ + ERR_PARTY_RESULT_OK = 0, + ERR_BAD_PLAYER_NAME_S = 1, + ERR_TARGET_NOT_IN_GROUP_S = 2, + ERR_TARGET_NOT_IN_INSTANCE_S = 3, + ERR_GROUP_FULL = 4, + ERR_ALREADY_IN_GROUP_S = 5, + ERR_NOT_IN_GROUP = 6, + ERR_NOT_LEADER = 7, + ERR_PLAYER_WRONG_FACTION = 8, + ERR_IGNORING_YOU_S = 9, + ERR_LFG_PENDING = 12, + ERR_INVITE_RESTRICTED = 13, + ERR_GROUP_SWAP_FAILED = 14, // if (PartyOperation == PARTY_OP_SWAP) ERR_GROUP_SWAP_FAILED else ERR_INVITE_IN_COMBAT + ERR_INVITE_UNKNOWN_REALM = 15, + ERR_INVITE_NO_PARTY_SERVER = 16, + ERR_INVITE_PARTY_BUSY = 17, + ERR_PARTY_TARGET_AMBIGUOUS = 18, + ERR_PARTY_LFG_INVITE_RAID_LOCKED = 19, + ERR_PARTY_LFG_BOOT_LIMIT = 20, + ERR_PARTY_LFG_BOOT_COOLDOWN_S = 21, + ERR_PARTY_LFG_BOOT_IN_PROGRESS = 22, + ERR_PARTY_LFG_BOOT_TOO_FEW_PLAYERS = 23, + ERR_PARTY_LFG_BOOT_NOT_ELIGIBLE_S = 24, + ERR_RAID_DISALLOWED_BY_LEVEL = 25, + ERR_PARTY_LFG_BOOT_IN_COMBAT = 26, + ERR_VOTE_KICK_REASON_NEEDED = 27, + ERR_PARTY_LFG_BOOT_DUNGEON_COMPLETE = 28, + ERR_PARTY_LFG_BOOT_LOOT_ROLLS = 29, + ERR_PARTY_LFG_TELEPORT_IN_COMBAT = 30 +}; #define MMAP_MAGIC 0x4d4d4150 // 'MMAP' #define MMAP_VERSION 3 diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp index 578654ca162..3d75e384e93 100644 --- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp @@ -24,6 +24,7 @@ #include "ObjectAccessor.h" #include "MoveSplineInit.h" #include "MoveSpline.h" +#include "Player.h" #define MIN_QUIET_DISTANCE 28.0f #define MAX_QUIET_DISTANCE 43.0f diff --git a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp index dc6cc55b855..554e38d7efd 100755 --- a/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp +++ b/src/server/game/Movement/MovementGenerators/TargetedMovementGenerator.cpp @@ -49,8 +49,19 @@ void TargetedMovementGeneratorMedium<T,D>::_setTargetLocation(T* owner, bool upd } else { + float size; + + // Pets need special handling. + // We need to subtract GetObjectSize() because it gets added back further down the chain + // and that makes pets too far away. Subtracting it allows pets to properly + // be (GetCombatReach() + i_offset) away. + if (owner.isPet()) + size = i_target->GetCombatReach() - i_target->GetObjectSize(); + else + size = owner.GetObjectSize(); + // to at i_offset distance from target and i_angle from target facing - i_target->GetClosePoint(x, y, z, owner->GetObjectSize(), i_offset, i_angle); + i_target->GetClosePoint(x, y, z, size, i_offset, i_angle); } } else diff --git a/src/server/game/Movement/Spline/MoveSpline.cpp b/src/server/game/Movement/Spline/MoveSpline.cpp index 7160f64c0fb..1821a78d993 100644 --- a/src/server/game/Movement/Spline/MoveSpline.cpp +++ b/src/server/game/Movement/Spline/MoveSpline.cpp @@ -201,7 +201,7 @@ bool MoveSplineInitArgs::Validate(Unit* unit) const #define CHECK(exp) \ if (!(exp))\ {\ - sLog->outError(LOG_FILTER_GENERAL, "MoveSplineInitArgs::Validate: expression '%s' failed for GUID: %u", #exp, unit->GetTypeId() == TYPEID_PLAYER ? unit->GetGUIDLow() : unit->ToCreature()->GetDBTableGUIDLow());\ + sLog->outError(LOG_FILTER_GENERAL, "MoveSplineInitArgs::Validate: expression '%s' failed for GUID: %u Entry: %u", #exp, unit->GetTypeId() == TYPEID_PLAYER ? unit->GetGUIDLow() : unit->ToCreature()->GetDBTableGUIDLow(), unit->GetEntry());\ return false;\ } CHECK(path.size() > 1); diff --git a/src/server/game/Movement/Spline/MoveSplineInit.cpp b/src/server/game/Movement/Spline/MoveSplineInit.cpp index b6cd1391ca3..e2a18d21ff2 100644 --- a/src/server/game/Movement/Spline/MoveSplineInit.cpp +++ b/src/server/game/Movement/Spline/MoveSplineInit.cpp @@ -22,6 +22,8 @@ #include "Unit.h" #include "Transport.h" #include "Vehicle.h" +#include "WorldPacket.h" +#include "Opcodes.h" namespace Movement { diff --git a/src/server/game/Reputation/ReputationMgr.cpp b/src/server/game/Reputation/ReputationMgr.cpp index 356a70ba6a5..3a8dc7c5e63 100755 --- a/src/server/game/Reputation/ReputationMgr.cpp +++ b/src/server/game/Reputation/ReputationMgr.cpp @@ -24,6 +24,7 @@ #include "World.h" #include "ObjectMgr.h" #include "ScriptMgr.h" +#include "Opcodes.h" const int32 ReputationMgr::PointsInRank[MAX_REPUTATION_RANK] = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000}; diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp index 517ea6cb6bd..069ae71b7cb 100755 --- a/src/server/game/Scripting/MapScripts.cpp +++ b/src/server/game/Scripting/MapScripts.cpp @@ -16,19 +16,20 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "Map.h" -#include "World.h" #include "CellImpl.h" #include "GridNotifiers.h" #include "GridNotifiersImpl.h" -#include "Transport.h" -#include "ScriptedCreature.h" -#include "WaypointManager.h" #include "GossipDef.h" +#include "Map.h" #include "MapManager.h" -#include "ObjectMgr.h" #include "MapRefManager.h" +#include "ObjectMgr.h" +#include "Pet.h" +#include "ScriptedCreature.h" #include "ScriptMgr.h" +#include "Transport.h" +#include "WaypointManager.h" +#include "World.h" /// Put scripts in the execution queue void Map::ScriptsStart(ScriptMapMap const& scripts, uint32 id, Object* source, Object* target) diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp index 47ce6c17b28..6682d3c11e3 100755 --- a/src/server/game/Scripting/ScriptMgr.cpp +++ b/src/server/game/Scripting/ScriptMgr.cpp @@ -30,6 +30,8 @@ #include "SpellScript.h" #include "GossipDef.h" #include "CreatureAI.h" +#include "Player.h" +#include "WorldPacket.h" // This is the global static registry of scripts. template<class TScript> @@ -1186,12 +1188,12 @@ void ScriptMgr::OnShutdown() FOREACH_SCRIPT(WorldScript)->OnShutdown(); } -bool ScriptMgr::OnCriteriaCheck(AchievementCriteriaData const* data, Player* source, Unit* target) +bool ScriptMgr::OnCriteriaCheck(uint32 scriptId, Player* source, Unit* target) { ASSERT(source); // target can be NULL. - GET_SCRIPT_RET(AchievementCriteriaScript, data->ScriptId, tmpscript, false); + GET_SCRIPT_RET(AchievementCriteriaScript, scriptId, tmpscript, false); return tmpscript->OnCheck(source, target); } diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h index 270182509f9..947be2b73fe 100755 --- a/src/server/game/Scripting/ScriptMgr.h +++ b/src/server/game/Scripting/ScriptMgr.h @@ -24,7 +24,6 @@ #include <ace/Atomic_Op.h> #include "DBCStores.h" -#include "Player.h" #include "SharedDefines.h" #include "World.h" #include "Weather.h" @@ -980,7 +979,7 @@ class ScriptMgr public: /* AchievementCriteriaScript */ - bool OnCriteriaCheck(AchievementCriteriaData const* data, Player* source, Unit* target); + bool OnCriteriaCheck(uint32 scriptId, Player* source, Unit* target); public: /* PlayerScript */ diff --git a/src/server/game/Server/Protocol/Opcodes.cpp b/src/server/game/Server/Protocol/Opcodes.cpp index 9078f6720a0..0821be2abb9 100755 --- a/src/server/game/Server/Protocol/Opcodes.cpp +++ b/src/server/game/Server/Protocol/Opcodes.cpp @@ -684,7 +684,7 @@ OpcodeHandler opcodeTable[NUM_MSG_TYPES] = /*0x28F*/ { "CMSG_GROUP_ASSISTANT_LEADER", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleGroupAssistantLeaderOpcode}, /*0x290*/ { "CMSG_BUYBACK_ITEM", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleBuybackItem }, /*0x291*/ { "SMSG_SERVER_MESSAGE", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide }, - /*0x292*/ { "CMSG_SET_SAVED_INSTANCE_EXTEND", STATUS_UNHANDLED, PROCESS_INPLACE, &WorldSession::Handle_NULL }, + /*0x292*/ { "CMSG_SET_SAVED_INSTANCE_EXTEND", STATUS_LOGGEDIN, PROCESS_THREADUNSAFE, &WorldSession::HandleSetSavedInstanceExtend }, /*0x293*/ { "SMSG_LFG_OFFER_CONTINUE", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide }, /*0x294*/ { "CMSG_TEST_DROP_RATE", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_NULL }, /*0x295*/ { "SMSG_TEST_DROP_RATE_RESULT", STATUS_NEVER, PROCESS_INPLACE, &WorldSession::Handle_ServerSide }, diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index 18ff3b32d67..0185d4adc9f 100755 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -225,7 +225,10 @@ void WorldSession::LogUnexpectedOpcode(WorldPacket* packet, const char* status, /// Logging helper for unexpected opcodes void WorldSession::LogUnprocessedTail(WorldPacket* packet) { - sLog->outError(LOG_FILTER_OPCODES, "Unprocessed tail data (read stop at %u from %u) Opcode %s from %s", + if (!sLog->ShouldLog(LOG_FILTER_OPCODES, LOG_LEVEL_TRACE) || packet->rpos() >= packet->wpos()) + return; + + sLog->outTrace(LOG_FILTER_OPCODES, "Unprocessed tail data (read stop at %u from %u) Opcode %s from %s", uint32(packet->rpos()), uint32(packet->wpos()), GetOpcodeNameForLogging(packet->GetOpcode()).c_str(), GetPlayerInfo().c_str()); packet->print_storage(); } @@ -293,8 +296,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) { sScriptMgr->OnPacketReceive(m_Socket, WorldPacket(*packet)); (this->*opHandle.handler)(*packet); - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE) && packet->rpos() < packet->wpos()) - LogUnprocessedTail(packet); + LogUnprocessedTail(packet); } // lag can cause STATUS_LOGGEDIN opcodes to arrive after the player started a transfer break; @@ -307,8 +309,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) // not expected _player or must checked in packet handler sScriptMgr->OnPacketReceive(m_Socket, WorldPacket(*packet)); (this->*opHandle.handler)(*packet); - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE) && packet->rpos() < packet->wpos()) - LogUnprocessedTail(packet); + LogUnprocessedTail(packet); } break; case STATUS_TRANSFER: @@ -320,8 +321,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) { sScriptMgr->OnPacketReceive(m_Socket, WorldPacket(*packet)); (this->*opHandle.handler)(*packet); - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE) && packet->rpos() < packet->wpos()) - LogUnprocessedTail(packet); + LogUnprocessedTail(packet); } break; case STATUS_AUTHED: @@ -339,8 +339,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater) sScriptMgr->OnPacketReceive(m_Socket, WorldPacket(*packet)); (this->*opHandle.handler)(*packet); - if (sLog->ShouldLog(LOG_FILTER_NETWORKIO, LOG_LEVEL_TRACE) && packet->rpos() < packet->wpos()) - LogUnprocessedTail(packet); + LogUnprocessedTail(packet); break; case STATUS_NEVER: sLog->outError(LOG_FILTER_OPCODES, "Received not allowed opcode %s from %s", GetOpcodeNameForLogging(packet->GetOpcode()).c_str() diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 7d5dba847d4..a442bb45a69 100755 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -31,8 +31,6 @@ #include "WorldPacket.h" #include "Cryptography/BigNumber.h" -class CalendarEvent; -class CalendarInvite; class Creature; class GameObject; class InstanceSave; @@ -93,40 +91,6 @@ enum PartyOperation PARTY_OP_SWAP = 4 }; -enum PartyResult -{ - ERR_PARTY_RESULT_OK = 0, - ERR_BAD_PLAYER_NAME_S = 1, - ERR_TARGET_NOT_IN_GROUP_S = 2, - ERR_TARGET_NOT_IN_INSTANCE_S = 3, - ERR_GROUP_FULL = 4, - ERR_ALREADY_IN_GROUP_S = 5, - ERR_NOT_IN_GROUP = 6, - ERR_NOT_LEADER = 7, - ERR_PLAYER_WRONG_FACTION = 8, - ERR_IGNORING_YOU_S = 9, - ERR_LFG_PENDING = 12, - ERR_INVITE_RESTRICTED = 13, - ERR_GROUP_SWAP_FAILED = 14, // if (PartyOperation == PARTY_OP_SWAP) ERR_GROUP_SWAP_FAILED else ERR_INVITE_IN_COMBAT - ERR_INVITE_UNKNOWN_REALM = 15, - ERR_INVITE_NO_PARTY_SERVER = 16, - ERR_INVITE_PARTY_BUSY = 17, - ERR_PARTY_TARGET_AMBIGUOUS = 18, - ERR_PARTY_LFG_INVITE_RAID_LOCKED = 19, - ERR_PARTY_LFG_BOOT_LIMIT = 20, - ERR_PARTY_LFG_BOOT_COOLDOWN_S = 21, - ERR_PARTY_LFG_BOOT_IN_PROGRESS = 22, - ERR_PARTY_LFG_BOOT_TOO_FEW_PLAYERS = 23, - ERR_PARTY_LFG_BOOT_NOT_ELIGIBLE_S = 24, - ERR_RAID_DISALLOWED_BY_LEVEL = 25, - ERR_PARTY_LFG_BOOT_IN_COMBAT = 26, - ERR_VOTE_KICK_REASON_NEEDED = 27, - ERR_PARTY_LFG_BOOT_DUNGEON_COMPLETE = 28, - ERR_PARTY_LFG_BOOT_LOOT_ROLLS = 29, - ERR_PARTY_LFG_TELEPORT_IN_COMBAT = 30 -}; - - enum BFLeaveReason { BF_LEAVE_REASON_CLOSE = 0x00000001, @@ -750,7 +714,7 @@ class WorldSession //Pet void HandlePetAction(WorldPacket& recvData); void HandlePetStopAttack(WorldPacket& recvData); - void HandlePetActionHelper(Unit* pet, uint64 guid1, uint16 spellid, uint16 flag, uint64 guid2); + void HandlePetActionHelper(Unit* pet, uint64 guid1, uint32 spellid, uint16 flag, uint64 guid2); void HandlePetNameQuery(WorldPacket& recvData); void HandlePetSetAction(WorldPacket& recvData); void HandlePetAbandon(WorldPacket& recvData); @@ -904,19 +868,9 @@ class WorldSession void HandleCalendarGetNumPending(WorldPacket& recvData); void HandleCalendarEventSignup(WorldPacket& recvData); - void SendCalendarEvent(CalendarEvent const& calendarEvent, CalendarSendEventType sendEventType); - void SendCalendarEventInvite(CalendarInvite const& invite, bool pending); - void SendCalendarEventInviteAlert(CalendarEvent const& calendarEvent, CalendarInvite const& calendarInvite); - void SendCalendarEventInviteRemove(CalendarInvite const& invite, uint32 flags); - void SendCalendarEventInviteRemoveAlert(CalendarEvent const& calendarEvent, CalendarInviteStatus status); - void SendCalendarEventRemovedAlert(CalendarEvent const& calendarEvent); - void SendCalendarEventUpdateAlert(CalendarEvent const& calendarEvent, CalendarSendEventType sendEventType); - void SendCalendarEventStatus(CalendarEvent const& calendarEvent, CalendarInvite const& invite); - void SendCalendarEventModeratorStatusAlert(CalendarInvite const& invite); - void SendCalendarClearPendingAction(); void SendCalendarRaidLockout(InstanceSave const* save, bool add); void SendCalendarRaidLockoutUpdated(InstanceSave const* save); - void SendCalendarCommandResult(CalendarError err, char const* param = NULL); + void HandleSetSavedInstanceExtend(WorldPacket& recvData); void HandleSpellClick(WorldPacket& recvData); void HandleMirrorImageDataRequest(WorldPacket& recvData); diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp index ee54c8d662c..8b034299ad6 100755 --- a/src/server/game/Server/WorldSocket.cpp +++ b/src/server/game/Server/WorldSocket.cpp @@ -29,7 +29,7 @@ #include "WorldSocket.h" #include "Common.h" - +#include "Player.h" #include "Util.h" #include "World.h" #include "WorldPacket.h" @@ -163,6 +163,9 @@ int WorldSocket::SendPacket(WorldPacket const& pct) if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(pct, SERVER_TO_CLIENT); + if (m_Session) + sLog->outTrace(LOG_FILTER_OPCODES, "S->C %s %s", m_Session->GetPlayerInfo().c_str(), GetOpcodeNameForLogging(pct.GetOpcode()).c_str()); + // Create a copy of the original packet; this is to avoid issues if a hook modifies it. sScriptMgr->OnPacketSend(this, WorldPacket(pct)); @@ -674,6 +677,9 @@ int WorldSocket::ProcessIncoming(WorldPacket* new_pct) if (sPacketLog->CanLogPacket()) sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER); + if (m_Session) + sLog->outTrace(LOG_FILTER_OPCODES, "C->S %s %s", m_Session->GetPlayerInfo().c_str(), GetOpcodeNameForLogging(new_pct->GetOpcode()).c_str()); + try { switch (opcode) @@ -857,6 +863,17 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket) uint32 recruiter = fields[9].GetUInt32(); std::string os = fields[10].GetString(); + // Must be done before WorldSession is created + if (sWorld->getBoolConfig(CONFIG_WARDEN_ENABLED) && os != "Win" && os != "OSX") + { + packet.Initialize(SMSG_AUTH_RESPONSE, 1); + packet << uint8(AUTH_REJECT); + SendPacket(packet); + + sLog->outError(LOG_FILTER_NETWORKIO, "WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", GetRemoteAddress().c_str(), os.c_str()); + return -1; + } + // Checks gmlevel per Realm stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_GMLEVEL_BY_REALMID); diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp index 5e9e8cc090b..b29f1498152 100755 --- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp +++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp @@ -38,6 +38,8 @@ #include "Vehicle.h" #include "Battlefield.h" #include "BattlefieldMgr.h" +#include "Pet.h" +#include "ReputationMgr.h" class Aura; // diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 77adece17b4..97f0f350ab0 100755 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -5456,6 +5456,9 @@ SpellCastResult Spell::CheckCast(bool strict) if (target->GetCharmerGUID()) return SPELL_FAILED_CHARMED; + if (target->GetOwner() && target->GetOwner()->GetTypeId() == TYPEID_PLAYER) + return SPELL_FAILED_TARGET_IS_PLAYER_CONTROLLED; + int32 damage = CalculateDamage(i, target); if (damage && int32(target->getLevel()) > damage) return SPELL_FAILED_HIGHLEVEL; diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index cdb9490c10d..622f3e1517b 100755 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -64,6 +64,7 @@ #include "AccountMgr.h" #include "InstanceScript.h" #include "PathGenerator.h" +#include "ReputationMgr.h" pEffect SpellEffects[TOTAL_SPELL_EFFECTS]= { diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp index 27b4f22bbcf..be4c522956c 100644 --- a/src/server/game/Spells/SpellInfo.cpp +++ b/src/server/game/Spells/SpellInfo.cpp @@ -21,6 +21,8 @@ #include "Spell.h" #include "DBCStores.h" #include "ConditionMgr.h" +#include "Player.h" +#include "Battleground.h" uint32 GetTargetFlagMask(SpellTargetObjectTypes objType) { diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index 4ffbab6cb63..1edb8eab103 100755 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -32,6 +32,7 @@ #include "BattlegroundIC.h" #include "BattlefieldWG.h" #include "BattlefieldMgr.h" +#include "Player.h" bool IsPrimaryProfessionSkill(uint32 skill) { @@ -80,6 +81,9 @@ DiminishingGroup GetDiminishingReturnsGroupForSpell(SpellInfo const* spellproto, // Gnaw else if (spellproto->Id == 47481) return DIMINISHING_CONTROLLED_STUN; + // ToC Icehowl Arctic Breath + else if (spellproto->SpellVisual[0] == 14153) + return DIMINISHING_NONE; break; } // Event spells @@ -373,7 +377,7 @@ bool SpellMgr::IsSpellValid(SpellInfo const* spellInfo, Player* player, bool msg if (msg) { if (player) - ChatHandler(player).PSendSysMessage("Craft spell %u not have create item entry.", spellInfo->Id); + ChatHandler(player->GetSession()).PSendSysMessage("Craft spell %u not have create item entry.", spellInfo->Id); else sLog->outError(LOG_FILTER_SQL, "Craft spell %u not have create item entry.", spellInfo->Id); } @@ -387,7 +391,7 @@ bool SpellMgr::IsSpellValid(SpellInfo const* spellInfo, Player* player, bool msg if (msg) { if (player) - ChatHandler(player).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Effects[i].ItemType); + ChatHandler(player->GetSession()).PSendSysMessage("Craft spell %u create not-exist in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Effects[i].ItemType); else sLog->outError(LOG_FILTER_SQL, "Craft spell %u create not-exist in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Effects[i].ItemType); } @@ -405,7 +409,7 @@ bool SpellMgr::IsSpellValid(SpellInfo const* spellInfo, Player* player, bool msg if (msg) { if (player) - ChatHandler(player).PSendSysMessage("Spell %u learn to broken spell %u, and then...", spellInfo->Id, spellInfo->Effects[i].TriggerSpell); + ChatHandler(player->GetSession()).PSendSysMessage("Spell %u learn to broken spell %u, and then...", spellInfo->Id, spellInfo->Effects[i].TriggerSpell); else sLog->outError(LOG_FILTER_SQL, "Spell %u learn to invalid spell %u, and then...", spellInfo->Id, spellInfo->Effects[i].TriggerSpell); } @@ -425,7 +429,7 @@ bool SpellMgr::IsSpellValid(SpellInfo const* spellInfo, Player* player, bool msg if (msg) { if (player) - ChatHandler(player).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Reagent[j]); + ChatHandler(player->GetSession()).PSendSysMessage("Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Reagent[j]); else sLog->outError(LOG_FILTER_SQL, "Craft spell %u have not-exist reagent in DB item (Entry: %u) and then...", spellInfo->Id, spellInfo->Reagent[j]); } diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 5c2639175d2..89b75fd1695 100755 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -65,6 +65,47 @@ class CreatureTextBuilder uint64 _targetGUID; }; +class PlayerTextBuilder +{ + public: + PlayerTextBuilder(WorldObject* obj, WorldObject* speaker, ChatMsg msgtype, uint8 textGroup, uint32 id, uint32 language, uint64 targetGUID) + : _source(obj), _talker(speaker), _msgType(msgtype), _textGroup(textGroup), _textId(id), _language(language), _targetGUID(targetGUID) + { + } + + size_t operator()(WorldPacket* data, LocaleConstant locale) const + { + std::string const& text = sCreatureTextMgr->GetLocalizedChatString(_source->GetEntry(), _textGroup, _textId, locale); + + *data << uint8(_msgType); + *data << uint32(_language); + *data << uint64(_talker->GetGUID()); + *data << uint32(1); // 2.1.0 + *data << uint32(_talker->GetName().size() + 1); + *data << _talker->GetName(); + size_t whisperGUIDpos = data->wpos(); + *data << uint64(_targetGUID); // Unit Target + if (_targetGUID && !IS_PLAYER_GUID(_targetGUID)) + { + *data << uint32(1); // target name length + *data << uint8(0); // target name + } + *data << uint32(text.length() + 1); + *data << text; + *data << uint8(0); // ChatTag + + return whisperGUIDpos; + } + + WorldObject* _source; + WorldObject* _talker; + ChatMsg _msgType; + uint8 _textGroup; + uint32 _textId; + uint32 _language; + uint64 _targetGUID; +}; + void CreatureTextMgr::LoadCreatureTexts() { uint32 oldMSTime = getMSTime(); @@ -170,7 +211,7 @@ void CreatureTextMgr::LoadCreatureTextLocales() } -uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid /*= 0*/, ChatMsg msgType /*= CHAT_MSG_ADDON*/, Language language /*= LANG_ADDON*/, TextRange range /*= TEXT_RANGE_NORMAL*/, uint32 sound /*= 0*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, Player* srcPlr /*= NULL*/) +uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid /*= 0*/, ChatMsg msgType /*= CHAT_MSG_ADDON*/, Language language /*= LANG_ADDON*/, CreatureTextRange range /*= TEXT_RANGE_NORMAL*/, uint32 sound /*= 0*/, Team team /*= TEAM_OTHER*/, bool gmOnly /*= false*/, Player* srcPlr /*= NULL*/) { if (!source) return 0; @@ -261,8 +302,16 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisp if (iter->emote) SendEmote(finalSource, iter->emote); - CreatureTextBuilder builder(finalSource, finalType, iter->group, iter->id, finalLang, whisperGuid); - SendChatPacket(finalSource, builder, finalType, whisperGuid, range, team, gmOnly); + if (srcPlr) + { + PlayerTextBuilder builder(source, finalSource, finalType, iter->group, iter->id, finalLang, whisperGuid); + SendChatPacket(finalSource, builder, finalType, whisperGuid, range, team, gmOnly); + } + else + { + CreatureTextBuilder builder(finalSource, finalType, iter->group, iter->id, finalLang, whisperGuid); + SendChatPacket(finalSource, builder, finalType, whisperGuid, range, team, gmOnly); + } if (isEqualChanced || (!isEqualChanced && totalChance == 100.0f)) SetRepeatId(source, textGroup, iter->id); @@ -288,7 +337,7 @@ float CreatureTextMgr::GetRangeForChatType(ChatMsg msgType) const return dist; } -void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) +void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) { if (!sound || !source) return; @@ -298,7 +347,7 @@ void CreatureTextMgr::SendSound(Creature* source, uint32 sound, ChatMsg msgType, SendNonChatPacket(source, &data, msgType, whisperGuid, range, team, gmOnly); } -void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const +void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) const { float dist = GetRangeForChatType(msgType); diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h index 8ed0b01fcd5..df6dd7fe4f3 100755 --- a/src/server/game/Texts/CreatureTextMgr.h +++ b/src/server/game/Texts/CreatureTextMgr.h @@ -22,6 +22,7 @@ #include "GridNotifiers.h" #include "ObjectAccessor.h" #include "SharedDefines.h" +#include "Opcodes.h" struct CreatureTextEntry { @@ -37,7 +38,7 @@ struct CreatureTextEntry uint32 sound; }; -enum TextRange +enum CreatureTextRange { TEXT_RANGE_NORMAL = 0, TEXT_RANGE_AREA = 1, @@ -89,21 +90,21 @@ class CreatureTextMgr void LoadCreatureTextLocales(); CreatureTextMap const& GetTextMap() const { return mTextMap; } - void SendSound(Creature* source, uint32 sound, ChatMsg msgType, uint64 whisperGuid, TextRange range, Team team, bool gmOnly); + void SendSound(Creature* source, uint32 sound, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly); void SendEmote(Unit* source, uint32 emote); //if sent, returns the 'duration' of the text else 0 if error - uint32 SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid = 0, ChatMsg msgType = CHAT_MSG_ADDON, Language language = LANG_ADDON, TextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0, Team team = TEAM_OTHER, bool gmOnly = false, Player* srcPlr = NULL); + uint32 SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid = 0, ChatMsg msgType = CHAT_MSG_ADDON, Language language = LANG_ADDON, CreatureTextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0, Team team = TEAM_OTHER, bool gmOnly = false, Player* srcPlr = NULL); bool TextExist(uint32 sourceEntry, uint8 textGroup); std::string GetLocalizedChatString(uint32 entry, uint8 textGroup, uint32 id, LocaleConstant locale) const; template<class Builder> - void SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, uint64 whisperGuid = 0, TextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false) const; + void SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, uint64 whisperGuid = 0, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false) const; private: CreatureTextRepeatIds GetRepeatGroup(Creature* source, uint8 textGroup); void SetRepeatId(Creature* source, uint8 textGroup, uint8 id); - void SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const; + void SendNonChatPacket(WorldObject* source, WorldPacket* data, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) const; float GetRangeForChatType(ChatMsg msgType) const; CreatureTextMap mTextMap; @@ -172,7 +173,7 @@ class CreatureTextLocalizer }; template<class Builder> -void CreatureTextMgr::SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, uint64 whisperGuid, TextRange range, Team team, bool gmOnly) const +void CreatureTextMgr::SendChatPacket(WorldObject* source, Builder const& builder, ChatMsg msgType, uint64 whisperGuid, CreatureTextRange range, Team team, bool gmOnly) const { if (!source) return; diff --git a/src/server/game/Tickets/TicketMgr.cpp b/src/server/game/Tickets/TicketMgr.cpp index 51e17cb9076..3f0e608ec14 100755 --- a/src/server/game/Tickets/TicketMgr.cpp +++ b/src/server/game/Tickets/TicketMgr.cpp @@ -20,10 +20,13 @@ #include "TicketMgr.h" #include "DatabaseEnv.h" #include "Log.h" +#include "Language.h" #include "WorldPacket.h" #include "WorldSession.h" #include "Chat.h" #include "World.h" +#include "Player.h" +#include "Opcodes.h" inline float GetAge(uint64 t) { return float(time(NULL) - t) / DAY; } diff --git a/src/server/game/Tools/PlayerDump.cpp b/src/server/game/Tools/PlayerDump.cpp index ec7d2e08001..57986243879 100644 --- a/src/server/game/Tools/PlayerDump.cpp +++ b/src/server/game/Tools/PlayerDump.cpp @@ -22,6 +22,7 @@ #include "UpdateFields.h" #include "ObjectMgr.h" #include "AccountMgr.h" +#include "World.h" #define DUMP_TABLE_COUNT 27 struct DumpTable diff --git a/src/server/game/Warden/Warden.cpp b/src/server/game/Warden/Warden.cpp index ce64dbd1a94..06f8454fda7 100644 --- a/src/server/game/Warden/Warden.cpp +++ b/src/server/game/Warden/Warden.cpp @@ -151,13 +151,28 @@ bool Warden::IsValidCheckSum(uint32 checksum, const uint8* data, const uint16 le } } +struct keyData { + union + { + struct + { + uint8 bytes[20]; + } bytes; + + struct + { + uint32 ints[5]; + } ints; + }; +}; + uint32 Warden::BuildChecksum(const uint8* data, uint32 length) { - uint8 hash[20]; - SHA1(data, length, hash); + keyData hash; + SHA1(data, length, hash.bytes.bytes); uint32 checkSum = 0; for (uint8 i = 0; i < 5; ++i) - checkSum = checkSum ^ *(uint32*)(&hash[0] + i * 4); + checkSum = checkSum ^ hash.ints.ints[i]; return checkSum; } diff --git a/src/server/game/Warden/WardenMac.cpp b/src/server/game/Warden/WardenMac.cpp index e08d24ecbcd..c6ce33fe131 100644 --- a/src/server/game/Warden/WardenMac.cpp +++ b/src/server/game/Warden/WardenMac.cpp @@ -114,17 +114,32 @@ void WardenMac::RequestHash() _session->SendPacket(&pkt); } +struct keyData { + union + { + struct + { + uint8 bytes[16]; + } bytes; + + struct + { + int ints[4]; + } ints; + }; +}; + void WardenMac::HandleHashResult(ByteBuffer &buff) { // test int keyIn[4]; - uint8 mod_seed[16] = { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE }; + keyData mod_seed = { { { { 0x4D, 0x80, 0x8D, 0x2C, 0x77, 0xD9, 0x05, 0xC4, 0x1A, 0x63, 0x80, 0xEC, 0x08, 0x58, 0x6A, 0xFE } } } }; for (int i = 0; i < 4; ++i) { - keyIn[i] = *(int*)(&mod_seed[0] + i * 4); + keyIn[i] = mod_seed.ints.ints[i]; } int keyOut[4]; diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp index 896e7161606..e119ebf5f2e 100755 --- a/src/server/game/Weather/Weather.cpp +++ b/src/server/game/Weather/Weather.cpp @@ -28,6 +28,7 @@ #include "ObjectMgr.h" #include "Util.h" #include "ScriptMgr.h" +#include "Opcodes.h" /// Create the Weather object Weather::Weather(uint32 zone, WeatherData const* weatherChances) diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp index da62122d7a3..c96ec1742cf 100755 --- a/src/server/game/Weather/WeatherMgr.cpp +++ b/src/server/game/Weather/WeatherMgr.cpp @@ -25,6 +25,9 @@ #include "Log.h" #include "ObjectMgr.h" #include "AutoPtr.h" +#include "Player.h" +#include "WorldPacket.h" +#include "Opcodes.h" namespace WeatherMgr { diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index e19f0b56f4b..be5b005dc27 100755 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1668,9 +1668,6 @@ void World::SetInitialWorldSettings() sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading CreatureEventAI Texts..."); sEventAIMgr->LoadCreatureEventAI_Texts(); - sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading CreatureEventAI Summons..."); - sEventAIMgr->LoadCreatureEventAI_Summons(); - sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Loading CreatureEventAI Scripts..."); sEventAIMgr->LoadCreatureEventAI_Scripts(); diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h index 7342c76f619..37c35c58c29 100644 --- a/src/server/game/World/World.h +++ b/src/server/game/World/World.h @@ -474,41 +474,6 @@ enum WorldStates WS_GUILD_DAILY_RESET_TIME = 20006, // Next guild cap reset time }; -// DB scripting commands -enum ScriptCommands -{ - SCRIPT_COMMAND_TALK = 0, // source/target = Creature, target = any, datalong = talk type (0=say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text), datalong2 & 1 = player talk (instead of creature), dataint = string_id - SCRIPT_COMMAND_EMOTE = 1, // source/target = Creature, datalong = emote id, datalong2 = 0: set emote state; > 0: play emote state - SCRIPT_COMMAND_FIELD_SET = 2, // source/target = Creature, datalong = field id, datalog2 = value - SCRIPT_COMMAND_MOVE_TO = 3, // source/target = Creature, datalong2 = time to reach, x/y/z = destination - SCRIPT_COMMAND_FLAG_SET = 4, // source/target = Creature, datalong = field id, datalog2 = bitmask - SCRIPT_COMMAND_FLAG_REMOVE = 5, // source/target = Creature, datalong = field id, datalog2 = bitmask - SCRIPT_COMMAND_TELEPORT_TO = 6, // source/target = Creature/Player (see datalong2), datalong = map_id, datalong2 = 0: Player; 1: Creature, x/y/z = destination, o = orientation - SCRIPT_COMMAND_QUEST_EXPLORED = 7, // target/source = Player, target/source = GO/Creature, datalong = quest id, datalong2 = distance or 0 - SCRIPT_COMMAND_KILL_CREDIT = 8, // target/source = Player, datalong = creature entry, datalong2 = 0: personal credit, 1: group credit - SCRIPT_COMMAND_RESPAWN_GAMEOBJECT = 9, // source = WorldObject (summoner), datalong = GO guid, datalong2 = despawn delay - SCRIPT_COMMAND_TEMP_SUMMON_CREATURE = 10, // source = WorldObject (summoner), datalong = creature entry, datalong2 = despawn delay, x/y/z = summon position, o = orientation - SCRIPT_COMMAND_OPEN_DOOR = 11, // source = Unit, datalong = GO guid, datalong2 = reset delay (min 15) - SCRIPT_COMMAND_CLOSE_DOOR = 12, // source = Unit, datalong = GO guid, datalong2 = reset delay (min 15) - SCRIPT_COMMAND_ACTIVATE_OBJECT = 13, // source = Unit, target = GO - SCRIPT_COMMAND_REMOVE_AURA = 14, // source (datalong2 != 0) or target (datalong2 == 0) = Unit, datalong = spell id - SCRIPT_COMMAND_CAST_SPELL = 15, // source and/or target = Unit, datalong2 = cast direction (0: s->t 1: s->s 2: t->t 3: t->s 4: s->creature with dataint entry), dataint & 1 = triggered flag - SCRIPT_COMMAND_PLAY_SOUND = 16, // source = WorldObject, target = none/Player, datalong = sound id, datalong2 (bitmask: 0/1=anyone/player, 0/2=without/with distance dependency, so 1|2 = 3 is target with distance dependency) - SCRIPT_COMMAND_CREATE_ITEM = 17, // target/source = Player, datalong = item entry, datalong2 = amount - SCRIPT_COMMAND_DESPAWN_SELF = 18, // target/source = Creature, datalong = despawn delay - - SCRIPT_COMMAND_LOAD_PATH = 20, // source = Unit, datalong = path id, datalong2 = is repeatable - SCRIPT_COMMAND_CALLSCRIPT_TO_UNIT = 21, // source = WorldObject (if present used as a search center), datalong = script id, datalong2 = unit lowguid, dataint = script table to use (see ScriptsType) - SCRIPT_COMMAND_KILL = 22, // source/target = Creature, dataint = remove corpse attribute - - // TrinityCore only - SCRIPT_COMMAND_ORIENTATION = 30, // source = Unit, target (datalong > 0) = Unit, datalong = > 0 turn source to face target, o = orientation - SCRIPT_COMMAND_EQUIP = 31, // soucre = Creature, datalong = equipment id - SCRIPT_COMMAND_MODEL = 32, // source = Creature, datalong = model id - SCRIPT_COMMAND_CLOSE_GOSSIP = 33, // source = Player - SCRIPT_COMMAND_PLAYMOVIE = 34 // source = Player, datalong = movie id -}; - /// Storage class for commands issued for delayed execution struct CliCommandHolder { |
