aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/game')
-rw-r--r--src/server/game/AI/CoreAI/UnitAI.cpp4
-rw-r--r--src/server/game/AI/CreatureAI.cpp6
-rw-r--r--src/server/game/AI/CreatureAIFactory.h2
-rw-r--r--src/server/game/AI/CreatureAISelector.cpp6
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedEscortAI.h2
-rw-r--r--src/server/game/AI/ScriptedAI/ScriptedFollowerAI.h2
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.cpp38
-rw-r--r--src/server/game/AI/SmartScripts/SmartScript.h2
-rw-r--r--src/server/game/AI/SmartScripts/SmartScriptMgr.h28
-rw-r--r--src/server/game/Accounts/AccountMgr.h11
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp15
-rw-r--r--src/server/game/Achievements/AchievementMgr.h10
-rw-r--r--src/server/game/AuctionHouse/AuctionHouseMgr.h11
-rw-r--r--src/server/game/Battlefield/BattlefieldMgr.h17
-rw-r--r--src/server/game/Battlefield/Zones/BattlefieldWG.cpp2
-rw-r--r--src/server/game/Battlegrounds/Arena.cpp4
-rw-r--r--src/server/game/Battlegrounds/ArenaTeamMgr.h10
-rw-r--r--src/server/game/Battlegrounds/Battleground.h4
-rw-r--r--src/server/game/Battlegrounds/BattlegroundMgr.cpp6
-rw-r--r--src/server/game/Battlegrounds/BattlegroundMgr.h11
-rw-r--r--src/server/game/Battlegrounds/BattlegroundQueue.cpp1
-rw-r--r--src/server/game/Battlegrounds/Zones/BattlegroundRV.cpp2
-rw-r--r--src/server/game/CMakeLists.txt1
-rw-r--r--src/server/game/Calendar/CalendarMgr.h15
-rw-r--r--src/server/game/Chat/Channels/Channel.h14
-rw-r--r--src/server/game/Chat/Channels/ChannelMgr.cpp6
-rw-r--r--src/server/game/Chat/Channels/ChannelMgr.h14
-rw-r--r--src/server/game/Combat/UnitEvents.h2
-rw-r--r--src/server/game/Conditions/ConditionMgr.cpp12
-rw-r--r--src/server/game/Conditions/ConditionMgr.h12
-rw-r--r--src/server/game/Conditions/DisableMgr.cpp12
-rw-r--r--src/server/game/DataStores/DBCStructure.h10
-rw-r--r--src/server/game/DungeonFinding/LFGMgr.cpp2
-rw-r--r--src/server/game/DungeonFinding/LFGMgr.h13
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp2
-rw-r--r--src/server/game/Entities/Creature/Creature.h14
-rw-r--r--src/server/game/Entities/Creature/CreatureGroups.h13
-rw-r--r--src/server/game/Entities/GameObject/GameObject.h26
-rw-r--r--src/server/game/Entities/Item/Item.cpp4
-rw-r--r--src/server/game/Entities/Item/ItemPrototype.h2
-rw-r--r--src/server/game/Entities/Object/Object.h12
-rw-r--r--src/server/game/Entities/Pet/Pet.cpp2
-rw-r--r--src/server/game/Entities/Player/Player.cpp8
-rw-r--r--src/server/game/Entities/Player/Player.h12
-rw-r--r--src/server/game/Entities/Player/SocialMgr.cpp2
-rw-r--r--src/server/game/Entities/Player/SocialMgr.h11
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp10
-rw-r--r--src/server/game/Entities/Unit/Unit.h14
-rw-r--r--src/server/game/Entities/Vehicle/VehicleDefines.h2
-rw-r--r--src/server/game/Events/GameEventMgr.cpp16
-rw-r--r--src/server/game/Events/GameEventMgr.h11
-rw-r--r--src/server/game/Globals/ObjectAccessor.cpp23
-rw-r--r--src/server/game/Globals/ObjectAccessor.h53
-rw-r--r--src/server/game/Globals/ObjectMgr.cpp4
-rw-r--r--src/server/game/Globals/ObjectMgr.h12
-rw-r--r--src/server/game/Groups/Group.cpp6
-rw-r--r--src/server/game/Groups/GroupMgr.cpp2
-rw-r--r--src/server/game/Groups/GroupMgr.h9
-rw-r--r--src/server/game/Guilds/Guild.cpp2
-rw-r--r--src/server/game/Guilds/GuildMgr.h10
-rw-r--r--src/server/game/Handlers/AddonHandler.cpp4
-rw-r--r--src/server/game/Handlers/AddonHandler.h19
-rw-r--r--src/server/game/Handlers/CharacterHandler.cpp8
-rw-r--r--src/server/game/Handlers/GroupHandler.cpp2
-rw-r--r--src/server/game/Handlers/GuildHandler.cpp2
-rw-r--r--src/server/game/Handlers/MiscHandler.cpp3
-rw-r--r--src/server/game/Handlers/NPCHandler.cpp4
-rw-r--r--src/server/game/Handlers/PetHandler.cpp6
-rw-r--r--src/server/game/Instances/InstanceSaveMgr.h28
-rw-r--r--src/server/game/Maps/Map.cpp14
-rw-r--r--src/server/game/Maps/Map.h6
-rw-r--r--src/server/game/Maps/MapInstanced.cpp4
-rw-r--r--src/server/game/Maps/MapManager.cpp10
-rw-r--r--src/server/game/Maps/MapManager.h16
-rw-r--r--src/server/game/Maps/MapUpdater.cpp104
-rw-r--r--src/server/game/Maps/MapUpdater.h48
-rw-r--r--src/server/game/Maps/TransportMgr.h10
-rwxr-xr-xsrc/server/game/Movement/MovementGenerator.h2
-rw-r--r--src/server/game/Movement/PathGenerator.cpp4
-rw-r--r--src/server/game/Movement/Spline/MoveSplineFlag.h4
-rw-r--r--src/server/game/Movement/Waypoints/WaypointManager.h13
-rw-r--r--src/server/game/OutdoorPvP/OutdoorPvPMgr.h11
-rw-r--r--src/server/game/Pools/PoolMgr.h11
-rw-r--r--src/server/game/PrecompiledHeaders/gamePCH.h3
-rw-r--r--src/server/game/Quests/QuestDef.cpp4
-rw-r--r--src/server/game/Quests/QuestDef.h10
-rw-r--r--src/server/game/Reputation/ReputationMgr.cpp2
-rw-r--r--src/server/game/Scripting/MapScripts.cpp2
-rw-r--r--src/server/game/Scripting/ScriptMgr.cpp16
-rw-r--r--src/server/game/Scripting/ScriptMgr.h37
-rw-r--r--src/server/game/Scripting/ScriptSystem.h11
-rw-r--r--src/server/game/Server/Protocol/PacketLog.h11
-rw-r--r--src/server/game/Server/Protocol/ServerPktHeader.h59
-rw-r--r--src/server/game/Server/WorldSession.cpp48
-rw-r--r--src/server/game/Server/WorldSession.h15
-rw-r--r--src/server/game/Server/WorldSocket.cpp977
-rw-r--r--src/server/game/Server/WorldSocket.h258
-rw-r--r--src/server/game/Server/WorldSocketAcceptor.h67
-rw-r--r--src/server/game/Server/WorldSocketMgr.cpp360
-rw-r--r--src/server/game/Server/WorldSocketMgr.h74
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.cpp2
-rw-r--r--src/server/game/Spells/Auras/SpellAuras.h6
-rw-r--r--src/server/game/Spells/Spell.cpp12
-rw-r--r--src/server/game/Spells/Spell.h6
-rw-r--r--src/server/game/Spells/SpellEffects.cpp2
-rw-r--r--src/server/game/Spells/SpellInfo.cpp14
-rw-r--r--src/server/game/Spells/SpellMgr.h12
-rw-r--r--src/server/game/Spells/SpellScript.cpp2
-rw-r--r--src/server/game/Spells/SpellScript.h4
-rw-r--r--src/server/game/Texts/CreatureTextMgr.h14
-rw-r--r--src/server/game/Tickets/TicketMgr.h13
-rw-r--r--src/server/game/Tools/CharacterDatabaseCleaner.cpp6
-rw-r--r--src/server/game/Warden/WardenCheckMgr.cpp2
-rw-r--r--src/server/game/Warden/WardenCheckMgr.h18
-rw-r--r--src/server/game/Warden/WardenWin.cpp4
-rw-r--r--src/server/game/Weather/Weather.cpp2
-rw-r--r--src/server/game/Weather/WeatherMgr.cpp3
-rw-r--r--src/server/game/World/World.cpp44
-rw-r--r--src/server/game/World/World.h28
119 files changed, 1046 insertions, 2024 deletions
diff --git a/src/server/game/AI/CoreAI/UnitAI.cpp b/src/server/game/AI/CoreAI/UnitAI.cpp
index cb32740e068..90bd3e8627a 100644
--- a/src/server/game/AI/CoreAI/UnitAI.cpp
+++ b/src/server/game/AI/CoreAI/UnitAI.cpp
@@ -141,7 +141,7 @@ void UnitAI::DoCast(uint32 spellId)
{
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
{
- bool playerOnly = spellInfo->AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_PLAYERS;
+ bool playerOnly = (spellInfo->AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_PLAYERS) != 0;
target = SelectTarget(SELECT_TARGET_RANDOM, 0, spellInfo->GetMaxRange(false), playerOnly);
}
break;
@@ -156,7 +156,7 @@ void UnitAI::DoCast(uint32 spellId)
{
if (SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId))
{
- bool playerOnly = spellInfo->AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_PLAYERS;
+ bool playerOnly = (spellInfo->AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_PLAYERS) != 0;
float range = spellInfo->GetMaxRange(false);
DefaultTargetSelector targetSelector(me, range, playerOnly, -(int32)spellId);
diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp
index ac9de00cd10..7a79bb722a0 100644
--- a/src/server/game/AI/CreatureAI.cpp
+++ b/src/server/game/AI/CreatureAI.cpp
@@ -204,7 +204,8 @@ bool CreatureAI::UpdateVictimWithGaze()
if (Unit* victim = me->SelectVictim())
AttackStart(victim);
- return me->GetVictim();
+
+ return me->GetVictim() != nullptr;
}
bool CreatureAI::UpdateVictim()
@@ -216,7 +217,8 @@ bool CreatureAI::UpdateVictim()
{
if (Unit* victim = me->SelectVictim())
AttackStart(victim);
- return me->GetVictim();
+
+ return me->GetVictim() != nullptr;
}
else if (me->getThreatManager().isThreatListEmpty())
{
diff --git a/src/server/game/AI/CreatureAIFactory.h b/src/server/game/AI/CreatureAIFactory.h
index fc2d009e673..f2854f1a9ce 100644
--- a/src/server/game/AI/CreatureAIFactory.h
+++ b/src/server/game/AI/CreatureAIFactory.h
@@ -49,7 +49,6 @@ CreatureAIFactory<REAL_AI>::Create(void* data) const
typedef FactoryHolder<CreatureAI> CreatureAICreator;
typedef FactoryHolder<CreatureAI>::FactoryHolderRegistry CreatureAIRegistry;
-typedef FactoryHolder<CreatureAI>::FactoryHolderRepository CreatureAIRepository;
//GO
struct SelectableGameObjectAI : public FactoryHolder<GameObjectAI>, public Permissible<GameObject>
@@ -77,5 +76,4 @@ GameObjectAIFactory<REAL_GO_AI>::Create(void* data) const
typedef FactoryHolder<GameObjectAI> GameObjectAICreator;
typedef FactoryHolder<GameObjectAI>::FactoryHolderRegistry GameObjectAIRegistry;
-typedef FactoryHolder<GameObjectAI>::FactoryHolderRepository GameObjectAIRepository;
#endif
diff --git a/src/server/game/AI/CreatureAISelector.cpp b/src/server/game/AI/CreatureAISelector.cpp
index 473af0d787e..afbd306c184 100644
--- a/src/server/game/AI/CreatureAISelector.cpp
+++ b/src/server/game/AI/CreatureAISelector.cpp
@@ -31,7 +31,7 @@ namespace FactorySelector
CreatureAI* selectAI(Creature* creature)
{
const CreatureAICreator* ai_factory = NULL;
- CreatureAIRegistry& ai_registry(*CreatureAIRepository::instance());
+ CreatureAIRegistry& ai_registry(*CreatureAIRegistry::instance());
if (creature->IsPet())
ai_factory = ai_registry.GetRegistryItem("PetAI");
@@ -101,7 +101,7 @@ namespace FactorySelector
MovementGenerator* selectMovementGenerator(Creature* creature)
{
- MovementGeneratorRegistry& mv_registry(*MovementGeneratorRepository::instance());
+ MovementGeneratorRegistry& mv_registry(*MovementGeneratorRegistry::instance());
ASSERT(creature->GetCreatureTemplate());
const MovementGeneratorCreator* mv_factory = mv_registry.GetRegistryItem(creature->GetDefaultMovementType());
@@ -130,7 +130,7 @@ namespace FactorySelector
GameObjectAI* SelectGameObjectAI(GameObject* go)
{
const GameObjectAICreator* ai_factory = NULL;
- GameObjectAIRegistry& ai_registry(*GameObjectAIRepository::instance());
+ GameObjectAIRegistry& ai_registry(*GameObjectAIRegistry::instance());
// scriptname in db
if (GameObjectAI* scriptedAI = sScriptMgr->GetGameObjectAI(go))
diff --git a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
index 4aa00d74e4e..177810bbbfd 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedEscortAI.h
@@ -93,7 +93,7 @@ struct npc_escortAI : public ScriptedAI
void SetRun(bool on = true);
void SetEscortPaused(bool on);
- bool HasEscortState(uint32 escortState) { return (m_uiEscortState & escortState); }
+ bool HasEscortState(uint32 escortState) { return (m_uiEscortState & escortState) != 0; }
virtual bool IsEscorted() { return (m_uiEscortState & STATE_ESCORT_ESCORTING); }
void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; }
diff --git a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.h b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.h
index df435fa5c9a..af7508441b9 100644
--- a/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.h
+++ b/src/server/game/AI/ScriptedAI/ScriptedFollowerAI.h
@@ -60,7 +60,7 @@ class FollowerAI : public ScriptedAI
void SetFollowPaused(bool bPaused); //if special event require follow mode to hold/resume during the follow
void SetFollowComplete(bool bWithEndEvent = false);
- bool HasFollowState(uint32 uiFollowState) { return (m_uiFollowState & uiFollowState); }
+ bool HasFollowState(uint32 uiFollowState) { return (m_uiFollowState & uiFollowState) != 0; }
protected:
Player* GetLeaderForFollower();
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp
index 140bb5507b4..d4b41f529a9 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.cpp
+++ b/src/server/game/AI/SmartScripts/SmartScript.cpp
@@ -522,10 +522,10 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
CAST_AI(SmartAI, me->AI())->SetCombatMove(_allowMove);
}
- me->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
+ me->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
}
else if (go)
- go->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
+ go->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_CAST:: %s: %u casts spell %u on target %u with castflags %u",
GetLogNameForGuid(me ? me->GetGUID() : go->GetGUID()), me ? me->GetGUIDLow() : go->GetGUIDLow(), e.action.cast.spell, (*itr)->GetGUIDLow(), e.action.cast.flags);
@@ -557,7 +557,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (e.action.cast.flags & SMARTCAST_INTERRUPT_PREVIOUS)
tempLastInvoker->InterruptNonMeleeSpells(false);
- tempLastInvoker->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
+ tempLastInvoker->CastSpell((*itr)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_INVOKER_CAST: Invoker %u casts spell %u on target %u with castflags %u",
tempLastInvoker->GetGUIDLow(), e.action.cast.spell, (*itr)->GetGUIDLow(), e.action.cast.flags);
}
@@ -707,7 +707,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- CAST_AI(SmartAI, me->AI())->SetAutoAttack(e.action.autoAttack.attack);
+ CAST_AI(SmartAI, me->AI())->SetAutoAttack(e.action.autoAttack.attack != 0);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_AUTO_ATTACK: Creature: %u bool on = %u",
me->GetGUIDLow(), e.action.autoAttack.attack);
break;
@@ -717,7 +717,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- bool move = e.action.combatMove.move;
+ bool move = e.action.combatMove.move != 0;
CAST_AI(SmartAI, me->AI())->SetCombatMove(move);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_ALLOW_COMBAT_MOVEMENT: Creature %u bool on = %u",
me->GetGUIDLow(), e.action.combatMove.move);
@@ -1149,13 +1149,13 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
case SMART_ACTION_SET_VISIBILITY:
{
if (me)
- me->SetVisible(e.action.visibility.state);
+ me->SetVisible(e.action.visibility.state != 0);
break;
}
case SMART_ACTION_SET_ACTIVE:
{
if (WorldObject* baseObj = GetBaseObject())
- baseObj->setActive(e.action.active.state);
+ baseObj->setActive(e.action.active.state != 0);
break;
}
@@ -1331,7 +1331,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- CAST_AI(SmartAI, me->AI())->SetFly(e.action.setFly.fly);
+ CAST_AI(SmartAI, me->AI())->SetFly(e.action.setFly.fly != 0);
break;
}
case SMART_ACTION_SET_RUN:
@@ -1339,7 +1339,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- CAST_AI(SmartAI, me->AI())->SetRun(e.action.setRun.run);
+ CAST_AI(SmartAI, me->AI())->SetRun(e.action.setRun.run != 0);
break;
}
case SMART_ACTION_SET_SWIM:
@@ -1347,7 +1347,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- CAST_AI(SmartAI, me->AI())->SetSwim(e.action.setSwim.swim);
+ CAST_AI(SmartAI, me->AI())->SetSwim(e.action.setSwim.swim != 0);
break;
}
case SMART_ACTION_WP_START:
@@ -1355,9 +1355,9 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
if (!IsSmart())
break;
- bool run = e.action.wpStart.run;
+ bool run = e.action.wpStart.run != 0;
uint32 entry = e.action.wpStart.pathID;
- bool repeat = e.action.wpStart.repeat;
+ bool repeat = e.action.wpStart.repeat != 0;
ObjectList* targets = GetTargets(e, unit);
StoreTargetList(targets, SMART_ESCORT_TARGETS);
me->SetReactState((ReactStates)e.action.wpStart.reactState);
@@ -1385,7 +1385,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
uint32 DespawnTime = e.action.wpStop.despawnTime;
uint32 quest = e.action.wpStop.quest;
- bool fail = e.action.wpStop.fail;
+ bool fail = e.action.wpStop.fail != 0;
CAST_AI(SmartAI, me->AI())->StopPath(DespawnTime, quest, fail);
break;
}
@@ -1739,7 +1739,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
interruptedSpell = true;
}
- unit->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED));
+ unit->CastSpell((*it)->ToUnit(), e.action.cast.spell, (e.action.cast.flags & SMARTCAST_TRIGGERED) != 0);
}
else
TC_LOG_DEBUG("scripts.ai", "Spell %u not cast because it has flag SMARTCAST_AURA_NOT_PRESENT and the target (Guid: " UI64FMTD " Entry: %u Type: %u) already has the aura", e.action.cast.spell, (*it)->GetGUID(), (*it)->GetEntry(), uint32((*it)->GetTypeId()));
@@ -1909,7 +1909,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsUnit(*itr))
- (*itr)->ToUnit()->InterruptNonMeleeSpells(e.action.interruptSpellCasting.withDelayed, e.action.interruptSpellCasting.spell_id, e.action.interruptSpellCasting.withInstant);
+ (*itr)->ToUnit()->InterruptNonMeleeSpells(e.action.interruptSpellCasting.withDelayed != 0, e.action.interruptSpellCasting.spell_id, e.action.interruptSpellCasting.withInstant != 0);
delete targets;
break;
@@ -2100,7 +2100,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsCreature(*itr))
- (*itr)->ToCreature()->setRegeneratingHealth(e.action.setHealthRegen.regenHealth);
+ (*itr)->ToCreature()->setRegeneratingHealth(e.action.setHealthRegen.regenHealth != 0);
delete targets;
break;
@@ -2113,7 +2113,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
for (ObjectList::const_iterator itr = targets->begin(); itr != targets->end(); ++itr)
if (IsCreature(*itr))
- (*itr)->ToCreature()->SetControlled(e.action.setRoot.root, UNIT_STATE_ROOT);
+ (*itr)->ToCreature()->SetControlled(e.action.setRoot.root != 0, UNIT_STATE_ROOT);
delete targets;
break;
@@ -2622,7 +2622,7 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
case SMART_TARGET_CLOSEST_ENEMY:
{
if (me)
- if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist, e.target.closestAttackable.playerOnly))
+ if (Unit* target = me->SelectNearestTarget(e.target.closestAttackable.maxDist, e.target.closestAttackable.playerOnly != 0))
l->push_back(target);
break;
@@ -2630,7 +2630,7 @@ ObjectList* SmartScript::GetTargets(SmartScriptHolder const& e, Unit* invoker /*
case SMART_TARGET_CLOSEST_FRIENDLY:
{
if (me)
- if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist, e.target.closestFriendly.playerOnly))
+ if (Unit* target = DoFindClosestFriendlyInRange(e.target.closestFriendly.maxDist, e.target.closestFriendly.playerOnly != 0))
l->push_back(target);
break;
diff --git a/src/server/game/AI/SmartScripts/SmartScript.h b/src/server/game/AI/SmartScripts/SmartScript.h
index b83222dc263..0931756a026 100644
--- a/src/server/game/AI/SmartScripts/SmartScript.h
+++ b/src/server/game/AI/SmartScripts/SmartScript.h
@@ -216,7 +216,7 @@ class SmartScript
}
void DecPhase(int32 p = 1) { mEventPhase -= (mEventPhase < (uint32)p ? (uint32)p - mEventPhase : (uint32)p); }
- bool IsInPhase(uint32 p) const { return (1 << (mEventPhase - 1)) & p; }
+ bool IsInPhase(uint32 p) const { return ((1 << (mEventPhase - 1)) & p) != 0; }
void SetPhase(uint32 p = 0) { mEventPhase = p; }
SmartAIEventList mEvents;
diff --git a/src/server/game/AI/SmartScripts/SmartScriptMgr.h b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
index f57fae507d0..f3106ed726b 100644
--- a/src/server/game/AI/SmartScripts/SmartScriptMgr.h
+++ b/src/server/game/AI/SmartScripts/SmartScriptMgr.h
@@ -1404,11 +1404,17 @@ typedef std::unordered_map<uint32, ObjectGuidList*> ObjectListMap;
class SmartWaypointMgr
{
- friend class ACE_Singleton<SmartWaypointMgr, ACE_Null_Mutex>;
- SmartWaypointMgr() { }
- public:
+ private:
+ SmartWaypointMgr() { }
~SmartWaypointMgr();
+ public:
+ static SmartWaypointMgr* instance()
+ {
+ static SmartWaypointMgr* instance = new SmartWaypointMgr();
+ return instance;
+ }
+
void LoadFromDB();
WPPath* GetPath(uint32 id)
@@ -1434,11 +1440,17 @@ typedef std::pair<CacheSpellContainer::const_iterator, CacheSpellContainer::cons
class SmartAIMgr
{
- friend class ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>;
- SmartAIMgr() { }
- public:
+ private:
+ SmartAIMgr() { }
~SmartAIMgr() { }
+ public:
+ static SmartAIMgr* instance()
+ {
+ static SmartAIMgr* instance = new SmartAIMgr();
+ return instance;
+ }
+
void LoadSmartAIFromDB();
SmartAIEventList GetScript(int32 entry, SmartScriptType type)
@@ -1606,6 +1618,6 @@ class SmartAIMgr
CacheSpellContainer KillCreditSpellStore;
};
-#define sSmartScriptMgr ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance()
-#define sSmartWaypointMgr ACE_Singleton<SmartWaypointMgr, ACE_Null_Mutex>::instance()
+#define sSmartScriptMgr SmartAIMgr::instance()
+#define sSmartWaypointMgr SmartWaypointMgr::instance()
#endif
diff --git a/src/server/game/Accounts/AccountMgr.h b/src/server/game/Accounts/AccountMgr.h
index f39873f0ebf..47801f3ce19 100644
--- a/src/server/game/Accounts/AccountMgr.h
+++ b/src/server/game/Accounts/AccountMgr.h
@@ -20,7 +20,6 @@
#define _ACCMGR_H
#include "RBAC.h"
-#include <ace/Singleton.h>
enum class AccountOpResult : uint8
{
@@ -52,13 +51,17 @@ typedef std::map<uint8, rbac::RBACPermissionContainer> RBACDefaultPermissionsCon
class AccountMgr
{
- friend class ACE_Singleton<AccountMgr, ACE_Null_Mutex>;
-
private:
AccountMgr();
~AccountMgr();
public:
+ static AccountMgr* instance()
+ {
+ static AccountMgr* instance = new AccountMgr();
+ return instance;
+ }
+
AccountOpResult CreateAccount(std::string username, std::string password, std::string email = "");
static AccountOpResult DeleteAccount(uint32 accountId);
static AccountOpResult ChangeUsername(uint32 accountId, std::string newUsername, std::string newPassword);
@@ -95,5 +98,5 @@ class AccountMgr
rbac::RBACDefaultPermissionsContainer _defaultPermissions;
};
-#define sAccountMgr ACE_Singleton<AccountMgr, ACE_Null_Mutex>::instance()
+#define sAccountMgr AccountMgr::instance()
#endif
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 09b0981c751..48724dfe53d 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -388,6 +388,21 @@ bool AchievementCriteriaData::Meets(uint32 criteria_id, Player const* source, Un
return false;
return pProto->ItemLevel >= equipped_item.item_level && pProto->Quality >= equipped_item.item_quality;
}
+ case ACHIEVEMENT_CRITERIA_DATA_TYPE_MAP_ID:
+ return source->GetMapId() == map_id.mapId;
+ case ACHIEVEMENT_CRITERIA_DATA_TYPE_NTH_BIRTHDAY:
+ {
+ time_t birthday_start = time_t(sWorld->getIntConfig(CONFIG_BIRTHDAY_TIME));
+ tm birthday_tm;
+ localtime_r(&birthday_start, &birthday_tm);
+
+ // exactly N birthday
+ birthday_tm.tm_year += birthday_login.nth_birthday;
+
+ time_t birthday = mktime(&birthday_tm);
+ time_t now = sWorld->GetGameTime();
+ return now <= birthday + DAY && now >= birthday;
+ }
case ACHIEVEMENT_CRITERIA_DATA_TYPE_S_KNOWN_TITLE:
{
if (CharTitlesEntry const* titleInfo = sCharTitlesStore.LookupEntry(known_title.title_id))
diff --git a/src/server/game/Achievements/AchievementMgr.h b/src/server/game/Achievements/AchievementMgr.h
index 2758c677c21..66c91ef728e 100644
--- a/src/server/game/Achievements/AchievementMgr.h
+++ b/src/server/game/Achievements/AchievementMgr.h
@@ -23,7 +23,6 @@
#include <string>
#include "Common.h"
-#include <ace/Singleton.h>
#include "DatabaseEnv.h"
#include "DBCEnums.h"
#include "DBCStores.h"
@@ -299,7 +298,6 @@ class AchievementMgr
class AchievementGlobalMgr
{
- friend class ACE_Singleton<AchievementGlobalMgr, ACE_Null_Mutex>;
AchievementGlobalMgr() { }
~AchievementGlobalMgr() { }
@@ -307,6 +305,12 @@ class AchievementGlobalMgr
static char const* GetCriteriaTypeString(AchievementCriteriaTypes type);
static char const* GetCriteriaTypeString(uint32 type);
+ static AchievementGlobalMgr* instance()
+ {
+ static AchievementGlobalMgr* instance = new AchievementGlobalMgr();
+ return instance;
+ }
+
AchievementCriteriaEntryList const& GetAchievementCriteriaByType(AchievementCriteriaTypes type, bool guild = false) const
{
return guild ? m_GuildAchievementCriteriasByType[type] : m_AchievementCriteriasByType[type];
@@ -405,6 +409,6 @@ class AchievementGlobalMgr
AchievementRewardLocales m_achievementRewardLocales;
};
-#define sAchievementMgr ACE_Singleton<AchievementGlobalMgr, ACE_Null_Mutex>::instance()
+#define sAchievementMgr AchievementGlobalMgr::instance()
#endif
diff --git a/src/server/game/AuctionHouse/AuctionHouseMgr.h b/src/server/game/AuctionHouse/AuctionHouseMgr.h
index 978e6869bac..3222d3bfa3c 100644
--- a/src/server/game/AuctionHouse/AuctionHouseMgr.h
+++ b/src/server/game/AuctionHouse/AuctionHouseMgr.h
@@ -19,8 +19,6 @@
#ifndef _AUCTION_HOUSE_MGR_H
#define _AUCTION_HOUSE_MGR_H
-#include <ace/Singleton.h>
-
#include "Common.h"
#include "DatabaseEnv.h"
#include "DBCStructure.h"
@@ -137,13 +135,16 @@ class AuctionHouseObject
class AuctionHouseMgr
{
- friend class ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>;
-
private:
AuctionHouseMgr();
~AuctionHouseMgr();
public:
+ static AuctionHouseMgr* instance()
+ {
+ static AuctionHouseMgr* instance = new AuctionHouseMgr();
+ return instance;
+ }
typedef std::unordered_map<uint32, Item*> ItemMap;
@@ -193,6 +194,6 @@ class AuctionHouseMgr
ItemMap mAitems;
};
-#define sAuctionMgr ACE_Singleton<AuctionHouseMgr, ACE_Null_Mutex>::instance()
+#define sAuctionMgr AuctionHouseMgr::instance()
#endif
diff --git a/src/server/game/Battlefield/BattlefieldMgr.h b/src/server/game/Battlefield/BattlefieldMgr.h
index 225fa380870..a3aad126479 100644
--- a/src/server/game/Battlefield/BattlefieldMgr.h
+++ b/src/server/game/Battlefield/BattlefieldMgr.h
@@ -19,7 +19,6 @@
#define BATTLEFIELD_MGR_H_
#include "Battlefield.h"
-#include <ace/Singleton.h>
class Player;
class ZoneScript;
@@ -28,11 +27,12 @@ class ZoneScript;
class BattlefieldMgr
{
public:
- // ctor
- BattlefieldMgr();
- // dtor
- ~BattlefieldMgr();
-
+ static BattlefieldMgr* instance()
+ {
+ static BattlefieldMgr* instance = new BattlefieldMgr();
+ return instance;
+ }
+
// create battlefield events
void InitBattlefield();
@@ -53,6 +53,9 @@ class BattlefieldMgr
void Update(uint32 diff);
private:
+ BattlefieldMgr();
+ ~BattlefieldMgr();
+
typedef std::vector<Battlefield*> BattlefieldSet;
typedef std::map<uint32 /*zoneId*/, Battlefield*> BattlefieldMap;
// contains all initiated battlefield events
@@ -65,6 +68,6 @@ class BattlefieldMgr
uint32 _updateTimer;
};
-#define sBattlefieldMgr ACE_Singleton<BattlefieldMgr, ACE_Null_Mutex>::instance()
+#define sBattlefieldMgr BattlefieldMgr::instance()
#endif // BATTLEFIELD_MGR_H_
diff --git a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp
index 3e603f4bb28..e05c918f501 100644
--- a/src/server/game/Battlefield/Zones/BattlefieldWG.cpp
+++ b/src/server/game/Battlefield/Zones/BattlefieldWG.cpp
@@ -84,7 +84,7 @@ bool BattlefieldWG::SetupBattlefield()
sWorld->setWorldState(ClockWorldState[0], uint64(m_NoWarBattleTime));
}
- m_isActive = bool(sWorld->getWorldState(BATTLEFIELD_WG_WORLD_STATE_ACTIVE));
+ m_isActive = sWorld->getWorldState(BATTLEFIELD_WG_WORLD_STATE_ACTIVE) != 0;
m_DefenderTeam = TeamId(sWorld->getWorldState(BATTLEFIELD_WG_WORLD_STATE_DEFENDER));
m_Timer = sWorld->getWorldState(ClockWorldState[0]);
diff --git a/src/server/game/Battlegrounds/Arena.cpp b/src/server/game/Battlegrounds/Arena.cpp
index 23d540adfb9..7a72afa2b12 100644
--- a/src/server/game/Battlegrounds/Arena.cpp
+++ b/src/server/game/Battlegrounds/Arena.cpp
@@ -110,7 +110,7 @@ void Arena::RemovePlayerAtLeave(uint64 guid, bool transport, bool sendPacket)
// left a rated match while the encounter was in progress, consider as loser
if (winnerArenaTeam && loserArenaTeam && winnerArenaTeam != loserArenaTeam)
{
- if (Player* player = _GetPlayer(itr->first, itr->second.OfflineRemoveTime, "Arena::RemovePlayerAtLeave"))
+ if (Player* player = _GetPlayer(itr->first, itr->second.OfflineRemoveTime != 0, "Arena::RemovePlayerAtLeave"))
loserArenaTeam->MemberLost(player, GetArenaMatchmakerRating(GetOtherTeam(team)));
else
loserArenaTeam->OfflineMemberLost(guid, GetArenaMatchmakerRating(GetOtherTeam(team)));
@@ -213,7 +213,7 @@ void Arena::EndBattleground(uint32 winner)
continue;
}
- Player* player = _GetPlayer(i.first, i.second.OfflineRemoveTime, "Arena::EndBattleground");
+ Player* player = _GetPlayer(i.first, i.second.OfflineRemoveTime != 0, "Arena::EndBattleground");
if (!player)
continue;
diff --git a/src/server/game/Battlegrounds/ArenaTeamMgr.h b/src/server/game/Battlegrounds/ArenaTeamMgr.h
index ca915e0db6f..17b9120c7f6 100644
--- a/src/server/game/Battlegrounds/ArenaTeamMgr.h
+++ b/src/server/game/Battlegrounds/ArenaTeamMgr.h
@@ -22,11 +22,17 @@
class ArenaTeamMgr
{
- friend class ACE_Singleton<ArenaTeamMgr, ACE_Null_Mutex>;
+private:
ArenaTeamMgr();
~ArenaTeamMgr();
public:
+ static ArenaTeamMgr* instance()
+ {
+ static ArenaTeamMgr* instance = new ArenaTeamMgr();
+ return instance;
+ }
+
typedef std::unordered_map<uint32, ArenaTeam*> ArenaTeamContainer;
ArenaTeam* GetArenaTeamById(uint32 arenaTeamId) const;
@@ -48,6 +54,6 @@ protected:
ArenaTeamContainer ArenaTeamStore;
};
-#define sArenaTeamMgr ACE_Singleton<ArenaTeamMgr, ACE_Null_Mutex>::instance()
+#define sArenaTeamMgr ArenaTeamMgr::instance()
#endif
diff --git a/src/server/game/Battlegrounds/Battleground.h b/src/server/game/Battlegrounds/Battleground.h
index a67be38be05..d04ff5171aa 100644
--- a/src/server/game/Battlegrounds/Battleground.h
+++ b/src/server/game/Battlegrounds/Battleground.h
@@ -481,8 +481,8 @@ class Battleground
void PlayerAddedToBGCheckIfBGIsRunning(Player* player);
Player* _GetPlayer(uint64 guid, bool offlineRemove, const char* context) const;
- Player* _GetPlayer(BattlegroundPlayerMap::iterator itr, const char* context) { return _GetPlayer(itr->first, itr->second.OfflineRemoveTime, context); }
- Player* _GetPlayer(BattlegroundPlayerMap::const_iterator itr, const char* context) const { return _GetPlayer(itr->first, itr->second.OfflineRemoveTime, context); }
+ Player* _GetPlayer(BattlegroundPlayerMap::iterator itr, const char* context) { return _GetPlayer(itr->first, itr->second.OfflineRemoveTime != 0, context); }
+ Player* _GetPlayer(BattlegroundPlayerMap::const_iterator itr, const char* context) const { return _GetPlayer(itr->first, itr->second.OfflineRemoveTime != 0, context); }
Player* _GetPlayerForTeam(uint32 teamId, BattlegroundPlayerMap::const_iterator itr, const char* context) const;
void _ProcessOfflineQueue();
diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.cpp b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
index 9a22052e17d..45111a80bc5 100644
--- a/src/server/game/Battlegrounds/BattlegroundMgr.cpp
+++ b/src/server/game/Battlegrounds/BattlegroundMgr.cpp
@@ -1077,12 +1077,8 @@ void BattlegroundMgr::ToggleArenaTesting()
void BattlegroundMgr::SetHolidayWeekends(uint32 mask)
{
for (uint32 bgtype = 1; bgtype < MAX_BATTLEGROUND_TYPE_ID; ++bgtype)
- {
if (Battleground* bg = GetBattlegroundTemplate(BattlegroundTypeId(bgtype)))
- {
- bg->SetHoliday(mask & (1 << bgtype));
- }
- }
+ bg->SetHoliday((mask & (1 << bgtype)) != 0);
}
void BattlegroundMgr::ScheduleQueueUpdate(uint32 arenaMatchmakerRating, uint8 arenaType, BattlegroundQueueTypeId bgQueueTypeId, BattlegroundTypeId bgTypeId, BattlegroundBracketId bracket_id)
diff --git a/src/server/game/Battlegrounds/BattlegroundMgr.h b/src/server/game/Battlegrounds/BattlegroundMgr.h
index fdef1b32993..ee7fd660851 100644
--- a/src/server/game/Battlegrounds/BattlegroundMgr.h
+++ b/src/server/game/Battlegrounds/BattlegroundMgr.h
@@ -23,7 +23,6 @@
#include "DBCEnums.h"
#include "Battleground.h"
#include "BattlegroundQueue.h"
-#include <ace/Singleton.h>
typedef std::map<uint32, Battleground*> BattlegroundContainer;
typedef std::set<uint32> BattlegroundClientIdsContainer;
@@ -57,13 +56,17 @@ struct BattlegroundTemplate
class BattlegroundMgr
{
- friend class ACE_Singleton<BattlegroundMgr, ACE_Null_Mutex>;
-
private:
BattlegroundMgr();
~BattlegroundMgr();
public:
+ static BattlegroundMgr* instance()
+ {
+ static BattlegroundMgr* instance = new BattlegroundMgr();
+ return instance;
+ }
+
void Update(uint32 diff);
/* Packet Building */
@@ -167,6 +170,6 @@ class BattlegroundMgr
BattlegroundMapTemplateContainer _battlegroundMapTemplates;
};
-#define sBattlegroundMgr ACE_Singleton<BattlegroundMgr, ACE_Null_Mutex>::instance()
+#define sBattlegroundMgr BattlegroundMgr::instance()
#endif // __BATTLEGROUNDMGR_H
diff --git a/src/server/game/Battlegrounds/BattlegroundQueue.cpp b/src/server/game/Battlegrounds/BattlegroundQueue.cpp
index 4b71f8f88b6..2b9713157c9 100644
--- a/src/server/game/Battlegrounds/BattlegroundQueue.cpp
+++ b/src/server/game/Battlegrounds/BattlegroundQueue.cpp
@@ -191,7 +191,6 @@ GroupQueueInfo* BattlegroundQueue::AddGroup(Player* leader, Group* grp, Battlegr
//add GroupInfo to m_QueuedGroups
{
- //ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_Lock);
m_QueuedGroups[bracketId][index].push_back(ginfo);
//announce to world, this code needs mutex
diff --git a/src/server/game/Battlegrounds/Zones/BattlegroundRV.cpp b/src/server/game/Battlegrounds/Zones/BattlegroundRV.cpp
index 9609009d610..284b05a8960 100644
--- a/src/server/game/Battlegrounds/Zones/BattlegroundRV.cpp
+++ b/src/server/game/Battlegrounds/Zones/BattlegroundRV.cpp
@@ -158,7 +158,7 @@ void BattlegroundRV::TogglePillarCollision()
{
if (i >= BG_RV_OBJECT_PILAR_COLLISION_1)
{
- GOState state = (bool(go->GetGOInfo()->door.startOpen) == _pillarCollision) ? GO_STATE_ACTIVE : GO_STATE_READY;
+ GOState state = ((go->GetGOInfo()->door.startOpen != 0) == _pillarCollision) ? GO_STATE_ACTIVE : GO_STATE_READY;
go->SetGoState(state);
}
diff --git a/src/server/game/CMakeLists.txt b/src/server/game/CMakeLists.txt
index 932b792c3bf..8e4ae9b5498 100644
--- a/src/server/game/CMakeLists.txt
+++ b/src/server/game/CMakeLists.txt
@@ -198,7 +198,6 @@ include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/Weather
${CMAKE_CURRENT_SOURCE_DIR}/World
${CMAKE_SOURCE_DIR}/src/server/scripts/PrecompiledHeaders
- ${ACE_INCLUDE_DIR}
${MYSQL_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
)
diff --git a/src/server/game/Calendar/CalendarMgr.h b/src/server/game/Calendar/CalendarMgr.h
index eceeda62581..8d744988a76 100644
--- a/src/server/game/Calendar/CalendarMgr.h
+++ b/src/server/game/Calendar/CalendarMgr.h
@@ -18,7 +18,6 @@
#ifndef TRINITY_CALENDARMGR_H
#define TRINITY_CALENDARMGR_H
-#include <ace/Singleton.h>
#include "Common.h"
#include "DatabaseEnv.h"
#include "WorldPacket.h"
@@ -245,8 +244,8 @@ struct CalendarEvent
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; }
+ bool IsGuildEvent() const { return (_flags & CALENDAR_FLAG_GUILD_EVENT) != 0; }
+ bool IsGuildAnnouncement() const { return (_flags & CALENDAR_FLAG_WITHOUT_INVITES) != 0; }
std::string BuildCalendarMailSubject(uint64 remover) const;
std::string BuildCalendarMailBody() const;
@@ -269,8 +268,6 @@ typedef std::map<uint64 /* eventId */, CalendarInviteStore > CalendarEventInvite
class CalendarMgr
{
- friend class ACE_Singleton<CalendarMgr, ACE_Null_Mutex>;
-
private:
CalendarMgr();
~CalendarMgr();
@@ -284,6 +281,12 @@ class CalendarMgr
uint64 _maxInviteId;
public:
+ static CalendarMgr* instance()
+ {
+ static CalendarMgr* instance = new CalendarMgr();
+ return instance;
+ }
+
void LoadFromDB();
CalendarEvent* GetEvent(uint64 eventId) const;
@@ -330,6 +333,6 @@ class CalendarMgr
void SendPacketToAllEventRelatives(WorldPacket packet, CalendarEvent const& calendarEvent);
};
-#define sCalendarMgr ACE_Singleton<CalendarMgr, ACE_Null_Mutex>::instance()
+#define sCalendarMgr CalendarMgr::instance()
#endif
diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h
index 115e340762e..877c1e826c9 100644
--- a/src/server/game/Chat/Channels/Channel.h
+++ b/src/server/game/Chat/Channels/Channel.h
@@ -125,21 +125,21 @@ class Channel
uint64 player;
uint8 flags;
- bool HasFlag(uint8 flag) const { return flags & flag; }
- void SetFlag(uint8 flag) { if (!HasFlag(flag)) flags |= flag; }
- bool IsOwner() const { return flags & MEMBER_FLAG_OWNER; }
+ bool HasFlag(uint8 flag) const { return (flags & flag) != 0; }
+ void SetFlag(uint8 flag) { flags |= flag; }
+ bool IsOwner() const { return (flags & MEMBER_FLAG_OWNER) != 0; }
void SetOwner(bool state)
{
if (state) flags |= MEMBER_FLAG_OWNER;
else flags &= ~MEMBER_FLAG_OWNER;
}
- bool IsModerator() const { return flags & MEMBER_FLAG_MODERATOR; }
+ bool IsModerator() const { return (flags & MEMBER_FLAG_MODERATOR) != 0; }
void SetModerator(bool state)
{
if (state) flags |= MEMBER_FLAG_MODERATOR;
else flags &= ~MEMBER_FLAG_MODERATOR;
}
- bool IsMuted() const { return flags & MEMBER_FLAG_MUTED; }
+ bool IsMuted() const { return (flags & MEMBER_FLAG_MUTED) != 0; }
void SetMuted(bool state)
{
if (state) flags |= MEMBER_FLAG_MUTED;
@@ -153,13 +153,13 @@ class Channel
uint32 GetChannelId() const { return _channelId; }
bool IsConstant() const { return _channelId != 0; }
bool IsAnnounce() const { return _announce; }
- bool IsLFG() const { return GetFlags() & CHANNEL_FLAG_LFG; }
+ bool IsLFG() const { return (GetFlags() & CHANNEL_FLAG_LFG) != 0; }
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; }
+ bool HasFlag(uint8 flag) const { return (_flags & flag) != 0; }
void JoinChannel(Player* player, std::string const& pass);
void LeaveChannel(Player* player, bool send = true);
diff --git a/src/server/game/Chat/Channels/ChannelMgr.cpp b/src/server/game/Chat/Channels/ChannelMgr.cpp
index 5926d67cbd5..366b0eee59f 100644
--- a/src/server/game/Chat/Channels/ChannelMgr.cpp
+++ b/src/server/game/Chat/Channels/ChannelMgr.cpp
@@ -30,13 +30,13 @@ ChannelMgr::~ChannelMgr()
ChannelMgr* ChannelMgr::forTeam(uint32 team)
{
if (sWorld->getBoolConfig(CONFIG_ALLOW_TWO_SIDE_INTERACTION_CHANNEL))
- return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance(); // cross-faction
+ return AllianceChannelMgr::instance(); // cross-faction
if (team == ALLIANCE)
- return ACE_Singleton<AllianceChannelMgr, ACE_Null_Mutex>::instance();
+ return AllianceChannelMgr::instance();
if (team == HORDE)
- return ACE_Singleton<HordeChannelMgr, ACE_Null_Mutex>::instance();
+ return HordeChannelMgr::instance();
return NULL;
}
diff --git a/src/server/game/Chat/Channels/ChannelMgr.h b/src/server/game/Chat/Channels/ChannelMgr.h
index 603eb52f589..0fd5cdbfe24 100644
--- a/src/server/game/Chat/Channels/ChannelMgr.h
+++ b/src/server/game/Chat/Channels/ChannelMgr.h
@@ -20,7 +20,6 @@
#include "Common.h"
#include "Channel.h"
-#include <ace/Singleton.h>
#include <map>
#include <string>
@@ -31,12 +30,17 @@ class ChannelMgr
{
typedef std::map<std::wstring, Channel*> ChannelMap;
- public:
- ChannelMgr() : team(0)
- { }
-
+ protected:
+ ChannelMgr() : team(0) { }
~ChannelMgr();
+ public:
+ static ChannelMgr* instance()
+ {
+ static ChannelMgr* instance = new ChannelMgr();
+ return instance;
+ }
+
static ChannelMgr * forTeam(uint32 team);
void setTeam(uint32 newTeam) { team = newTeam; }
diff --git a/src/server/game/Combat/UnitEvents.h b/src/server/game/Combat/UnitEvents.h
index 50d4c3ad322..3377097a12e 100644
--- a/src/server/game/Combat/UnitEvents.h
+++ b/src/server/game/Combat/UnitEvents.h
@@ -74,7 +74,7 @@ class UnitBaseEvent
public:
UnitBaseEvent(uint32 pType) { iType = pType; }
uint32 getType() const { return iType; }
- bool matchesTypeMask(uint32 pMask) const { return iType & pMask; }
+ bool matchesTypeMask(uint32 pMask) const { return (iType & pMask) != 0; }
void setType(uint32 pType) { iType = pType; }
};
diff --git a/src/server/game/Conditions/ConditionMgr.cpp b/src/server/game/Conditions/ConditionMgr.cpp
index 0217363862e..04ceaefb0d5 100644
--- a/src/server/game/Conditions/ConditionMgr.cpp
+++ b/src/server/game/Conditions/ConditionMgr.cpp
@@ -78,7 +78,7 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
if (Player* player = object->ToPlayer())
{
if (FactionEntry const* faction = sFactionStore.LookupEntry(ConditionValue1))
- condMeets = (ConditionValue2 & (1 << player->GetReputationMgr().GetRank(faction)));
+ condMeets = (ConditionValue2 & (1 << player->GetReputationMgr().GetRank(faction))) != 0;
}
break;
}
@@ -97,13 +97,13 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
case CONDITION_CLASS:
{
if (Unit* unit = object->ToUnit())
- condMeets = unit->getClassMask() & ConditionValue1;
+ condMeets = (unit->getClassMask() & ConditionValue1) != 0;
break;
}
case CONDITION_RACE:
{
if (Unit* unit = object->ToUnit())
- condMeets = unit->getRaceMask() & ConditionValue1;
+ condMeets = (unit->getRaceMask() & ConditionValue1) != 0;
break;
}
case CONDITION_GENDER:
@@ -262,7 +262,7 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
Unit* toUnit = toObject->ToUnit();
Unit* unit = object->ToUnit();
if (toUnit && unit)
- condMeets = (1 << unit->GetReactionTo(toUnit)) & ConditionValue2;
+ condMeets = ((1 << unit->GetReactionTo(toUnit)) & ConditionValue2) != 0;
}
break;
}
@@ -308,7 +308,7 @@ bool Condition::Meets(ConditionSourceInfo& sourceInfo)
}
case CONDITION_SPAWNMASK:
{
- condMeets = ((1 << object->GetMap()->GetSpawnMode()) & ConditionValue1);
+ condMeets = ((1 << object->GetMap()->GetSpawnMode()) & ConditionValue1) != 0;
break;
}
case CONDITION_UNIT_STATE:
@@ -828,7 +828,7 @@ void ConditionMgr::LoadConditions(bool isReload)
cond->ConditionValue1 = fields[7].GetUInt32();
cond->ConditionValue2 = fields[8].GetUInt32();
cond->ConditionValue3 = fields[9].GetUInt32();
- cond->NegativeCondition = fields[10].GetUInt8();
+ cond->NegativeCondition = fields[10].GetBool();
cond->ErrorType = fields[11].GetUInt32();
cond->ErrorTextId = fields[12].GetUInt32();
cond->ScriptId = sObjectMgr->GetScriptId(fields[13].GetCString());
diff --git a/src/server/game/Conditions/ConditionMgr.h b/src/server/game/Conditions/ConditionMgr.h
index 35aa60772bd..f4130a3a619 100644
--- a/src/server/game/Conditions/ConditionMgr.h
+++ b/src/server/game/Conditions/ConditionMgr.h
@@ -21,7 +21,6 @@
#include "Define.h"
#include "Errors.h"
-#include <ace/Singleton.h>
#include <list>
#include <map>
@@ -224,13 +223,18 @@ typedef std::map<uint32, ConditionList> ConditionReferenceContainer;//only used
class ConditionMgr
{
- friend class ACE_Singleton<ConditionMgr, ACE_Null_Mutex>;
-
private:
ConditionMgr();
~ConditionMgr();
public:
+
+ static ConditionMgr* instance()
+ {
+ static ConditionMgr* instance = new ConditionMgr();
+ return instance;
+ }
+
void LoadConditions(bool isReload = false);
bool isConditionTypeValid(Condition* cond);
ConditionList GetConditionReferences(uint32 refId);
@@ -268,6 +272,6 @@ class ConditionMgr
PhaseDefinitionConditionContainer PhaseDefinitionsConditionStore;
};
-#define sConditionMgr ACE_Singleton<ConditionMgr, ACE_Null_Mutex>::instance()
+#define sConditionMgr ConditionMgr::instance()
#endif
diff --git a/src/server/game/Conditions/DisableMgr.cpp b/src/server/game/Conditions/DisableMgr.cpp
index b29959cac50..3f325be1e83 100644
--- a/src/server/game/Conditions/DisableMgr.cpp
+++ b/src/server/game/Conditions/DisableMgr.cpp
@@ -339,7 +339,7 @@ bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags
else if (spellFlags & SPELL_DISABLE_DEPRECATED_SPELL) // call not from spellcast
return true;
else if (flags & SPELL_DISABLE_LOS)
- return spellFlags & SPELL_DISABLE_LOS;
+ return (spellFlags & SPELL_DISABLE_LOS) != 0;
break;
}
@@ -355,13 +355,13 @@ bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags
switch (targetDifficulty)
{
case DUNGEON_DIFFICULTY_NORMAL:
- return disabledModes & DUNGEON_STATUSFLAG_NORMAL;
+ return (disabledModes & DUNGEON_STATUSFLAG_NORMAL) != 0;
case DUNGEON_DIFFICULTY_HEROIC:
- return disabledModes & DUNGEON_STATUSFLAG_HEROIC;
+ return (disabledModes & DUNGEON_STATUSFLAG_HEROIC) != 0;
case RAID_DIFFICULTY_10MAN_HEROIC:
- return disabledModes & RAID_STATUSFLAG_10MAN_HEROIC;
+ return (disabledModes & RAID_STATUSFLAG_10MAN_HEROIC) != 0;
case RAID_DIFFICULTY_25MAN_HEROIC:
- return disabledModes & RAID_STATUSFLAG_25MAN_HEROIC;
+ return (disabledModes & RAID_STATUSFLAG_25MAN_HEROIC) != 0;
}
}
else if (mapEntry->map_type == MAP_COMMON)
@@ -381,7 +381,7 @@ bool IsDisabledFor(DisableType type, uint32 entry, Unit const* unit, uint8 flags
case DISABLE_TYPE_MMAP:
return true;
case DISABLE_TYPE_VMAP:
- return flags & itr->second.flags;
+ return (flags & itr->second.flags) != 0;
}
return false;
diff --git a/src/server/game/DataStores/DBCStructure.h b/src/server/game/DataStores/DBCStructure.h
index cc1cc20d3ce..001392aee4c 100644
--- a/src/server/game/DataStores/DBCStructure.h
+++ b/src/server/game/DataStores/DBCStructure.h
@@ -563,7 +563,7 @@ struct AreaTableEntry
{
if (mapid == 609)
return true;
- return (flags & AREA_FLAG_SANCTUARY);
+ return (flags & AREA_FLAG_SANCTUARY) != 0;
}
};
@@ -1534,7 +1534,7 @@ struct MapEntry
return MapID == 0 || MapID == 1 || MapID == 530 || MapID == 571;
}
- bool IsDynamicDifficultyMap() const { return Flags & MAP_FLAG_DYNAMIC_DIFFICULTY; }
+ bool IsDynamicDifficultyMap() const { return (Flags & MAP_FLAG_DYNAMIC_DIFFICULTY) != 0; }
};
struct MapDifficultyEntry
@@ -2356,12 +2356,12 @@ struct VehicleSeatEntry
uint32 m_flagsB; // 45
// 46-57 added in 3.1, floats mostly
- bool CanEnterOrExit() const { return m_flags & VEHICLE_SEAT_FLAG_CAN_ENTER_OR_EXIT; }
- bool CanSwitchFromSeat() const { return m_flags & VEHICLE_SEAT_FLAG_CAN_SWITCH; }
+ bool CanEnterOrExit() const { return (m_flags & VEHICLE_SEAT_FLAG_CAN_ENTER_OR_EXIT) != 0; }
+ bool CanSwitchFromSeat() const { return (m_flags & VEHICLE_SEAT_FLAG_CAN_SWITCH) != 0; }
bool IsUsableByOverride() const { return (m_flags & (VEHICLE_SEAT_FLAG_UNCONTROLLED | VEHICLE_SEAT_FLAG_UNK18)
|| (m_flagsB & (VEHICLE_SEAT_FLAG_B_USABLE_FORCED | VEHICLE_SEAT_FLAG_B_USABLE_FORCED_2 |
VEHICLE_SEAT_FLAG_B_USABLE_FORCED_3 | VEHICLE_SEAT_FLAG_B_USABLE_FORCED_4))); }
- bool IsEjectable() const { return m_flagsB & VEHICLE_SEAT_FLAG_B_EJECTABLE; }
+ bool IsEjectable() const { return (m_flagsB & VEHICLE_SEAT_FLAG_B_EJECTABLE) != 0; }
};
struct WMOAreaTableEntry
diff --git a/src/server/game/DungeonFinding/LFGMgr.cpp b/src/server/game/DungeonFinding/LFGMgr.cpp
index e0adbb6c6a2..0efc7fd6230 100644
--- a/src/server/game/DungeonFinding/LFGMgr.cpp
+++ b/src/server/game/DungeonFinding/LFGMgr.cpp
@@ -1879,7 +1879,7 @@ void LFGMgr::Clean()
bool LFGMgr::isOptionEnabled(uint32 option)
{
- return m_options & option;
+ return (m_options & option) != 0;
}
uint32 LFGMgr::GetOptions()
diff --git a/src/server/game/DungeonFinding/LFGMgr.h b/src/server/game/DungeonFinding/LFGMgr.h
index bca19a6b627..c42777c494c 100644
--- a/src/server/game/DungeonFinding/LFGMgr.h
+++ b/src/server/game/DungeonFinding/LFGMgr.h
@@ -18,7 +18,6 @@
#ifndef _LFGMGR_H
#define _LFGMGR_H
-#include <ace/Singleton.h>
#include "DBCStructure.h"
#include "Field.h"
#include "LFG.h"
@@ -275,7 +274,7 @@ struct LFGDungeonData
LFGDungeonData(LFGDungeonEntry const* dbc): id(dbc->ID), name(dbc->name), map(dbc->map),
type(dbc->type), expansion(dbc->expansion), group(dbc->grouptype),
minlevel(dbc->minlevel), maxlevel(dbc->maxlevel), difficulty(Difficulty(dbc->difficulty)),
- seasonal(dbc->flags & LFG_FLAG_SEASONAL), x(0.0f), y(0.0f), z(0.0f), o(0.0f),
+ seasonal((dbc->flags & LFG_FLAG_SEASONAL) != 0), x(0.0f), y(0.0f), z(0.0f), o(0.0f),
requiredItemLevel(0)
{ }
@@ -298,13 +297,17 @@ struct LFGDungeonData
class LFGMgr
{
- friend class ACE_Singleton<LFGMgr, ACE_Null_Mutex>;
-
private:
LFGMgr();
~LFGMgr();
public:
+ static LFGMgr* instance()
+ {
+ static LFGMgr* instance = new LFGMgr();
+ return instance;
+ }
+
// Functions used outside lfg namespace
void Update(uint32 diff);
@@ -476,5 +479,5 @@ class LFGMgr
} // namespace lfg
-#define sLFGMgr ACE_Singleton<lfg::LFGMgr, ACE_Null_Mutex>::instance()
+#define sLFGMgr lfg::LFGMgr::instance()
#endif
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 020727970ff..992894a1a3c 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1658,7 +1658,7 @@ bool Creature::isWorldBoss() const
if (IsPet())
return false;
- return GetCreatureTemplate()->type_flags & CREATURE_TYPEFLAGS_BOSS;
+ return (GetCreatureTemplate()->type_flags & CREATURE_TYPEFLAGS_BOSS) != 0;
}
SpellInfo const* Creature::reachWithSpellAttack(Unit* victim)
diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h
index 991f37d604d..f5a0abfc469 100644
--- a/src/server/game/Entities/Creature/Creature.h
+++ b/src/server/game/Entities/Creature/Creature.h
@@ -457,12 +457,12 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject
void SetCorpseDelay(uint32 delay) { m_corpseDelay = delay; }
uint32 GetCorpseDelay() const { return m_corpseDelay; }
bool IsRacialLeader() const { return GetCreatureTemplate()->RacialLeader; }
- bool IsCivilian() const { return GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN; }
- bool IsTrigger() const { return GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER; }
- bool IsGuard() const { return GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD; }
- bool CanWalk() const { return GetCreatureTemplate()->InhabitType & INHABIT_GROUND; }
- bool CanSwim() const { return GetCreatureTemplate()->InhabitType & INHABIT_WATER || IsPet(); }
- bool CanFly() const { return GetCreatureTemplate()->InhabitType & INHABIT_AIR; }
+ bool IsCivilian() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_CIVILIAN) != 0; }
+ bool IsTrigger() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER) != 0; }
+ bool IsGuard() const { return (GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_GUARD) != 0; }
+ bool CanWalk() const { return (GetCreatureTemplate()->InhabitType & INHABIT_GROUND) != 0; }
+ bool CanSwim() const { return (GetCreatureTemplate()->InhabitType & INHABIT_WATER) != 0 || IsPet(); }
+ bool CanFly() const { return (GetCreatureTemplate()->InhabitType & INHABIT_AIR) != 0; }
void SetReactState(ReactStates st) { m_reactState = st; }
ReactStates GetReactState() { return m_reactState; }
@@ -562,7 +562,7 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject
void AllLootRemovedFromCorpse();
uint16 GetLootMode() { return m_LootMode; }
- bool HasLootMode(uint16 lootMode) { return m_LootMode & lootMode; }
+ bool HasLootMode(uint16 lootMode) { return (m_LootMode & lootMode) != 0; }
void SetLootMode(uint16 lootMode) { m_LootMode = lootMode; }
void AddLootMode(uint16 lootMode) { m_LootMode |= lootMode; }
void RemoveLootMode(uint16 lootMode) { m_LootMode &= ~lootMode; }
diff --git a/src/server/game/Entities/Creature/CreatureGroups.h b/src/server/game/Entities/Creature/CreatureGroups.h
index b790853f5e1..29832e4ff76 100644
--- a/src/server/game/Entities/Creature/CreatureGroups.h
+++ b/src/server/game/Entities/Creature/CreatureGroups.h
@@ -40,10 +40,17 @@ typedef std::unordered_map<uint32/*memberDBGUID*/, FormationInfo*> CreatureGro
class FormationMgr
{
- friend class ACE_Singleton<FormationMgr, ACE_Null_Mutex>;
- public:
+ private:
FormationMgr() { }
~FormationMgr();
+
+ public:
+ static FormationMgr* instance()
+ {
+ static FormationMgr* instance = new FormationMgr();
+ return instance;
+ }
+
void AddCreatureToGroup(uint32 group_id, Creature* creature);
void RemoveCreatureFromGroup(CreatureGroup* group, Creature* creature);
void LoadCreatureFormations();
@@ -78,6 +85,6 @@ class CreatureGroup
void MemberAttackStart(Creature* member, Unit* target);
};
-#define sFormationMgr ACE_Singleton<FormationMgr, ACE_Null_Mutex>::instance()
+#define sFormationMgr FormationMgr::instance()
#endif
diff --git a/src/server/game/Entities/GameObject/GameObject.h b/src/server/game/Entities/GameObject/GameObject.h
index 123c5e3bebe..09c84c71244 100644
--- a/src/server/game/Entities/GameObject/GameObject.h
+++ b/src/server/game/Entities/GameObject/GameObject.h
@@ -407,8 +407,8 @@ struct GameObjectTemplate
{
switch (type)
{
- case GAMEOBJECT_TYPE_CHEST: return chest.consumable;
- case GAMEOBJECT_TYPE_GOOBER: return goober.consumable;
+ case GAMEOBJECT_TYPE_CHEST: return chest.consumable != 0;
+ case GAMEOBJECT_TYPE_GOOBER: return goober.consumable != 0;
default: return false;
}
}
@@ -417,10 +417,10 @@ struct GameObjectTemplate
{
switch (type)
{
- case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.allowMounted;
- case GAMEOBJECT_TYPE_TEXT: return text.allowMounted;
- case GAMEOBJECT_TYPE_GOOBER: return goober.allowMounted;
- case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.allowMounted;
+ case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.allowMounted != 0;
+ case GAMEOBJECT_TYPE_TEXT: return text.allowMounted != 0;
+ case GAMEOBJECT_TYPE_GOOBER: return goober.allowMounted != 0;
+ case GAMEOBJECT_TYPE_SPELLCASTER: return spellcaster.allowMounted != 0;
default: return false;
}
}
@@ -448,12 +448,12 @@ struct GameObjectTemplate
{
switch (type)
{
- case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune;
- case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune;
- case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.noDamageImmune;
- case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune;
- case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune;
- case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune;
+ case GAMEOBJECT_TYPE_DOOR: return door.noDamageImmune != 0;
+ case GAMEOBJECT_TYPE_BUTTON: return button.noDamageImmune != 0;
+ case GAMEOBJECT_TYPE_QUESTGIVER: return questgiver.noDamageImmune != 0;
+ case GAMEOBJECT_TYPE_GOOBER: return goober.noDamageImmune != 0;
+ case GAMEOBJECT_TYPE_FLAGSTAND: return flagstand.noDamageImmune != 0;
+ case GAMEOBJECT_TYPE_FLAGDROP: return flagdrop.noDamageImmune != 0;
default: return true;
}
}
@@ -737,7 +737,7 @@ class GameObject : public WorldObject, public GridObject<GameObject>, public Map
void SetLootState(LootState s, Unit* unit = NULL);
uint16 GetLootMode() { return m_LootMode; }
- bool HasLootMode(uint16 lootMode) { return m_LootMode & lootMode; }
+ bool HasLootMode(uint16 lootMode) { return (m_LootMode & lootMode) != 0; }
void SetLootMode(uint16 lootMode) { m_LootMode = lootMode; }
void AddLootMode(uint16 lootMode) { m_LootMode |= lootMode; }
void RemoveLootMode(uint16 lootMode) { m_LootMode &= ~lootMode; }
diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp
index 2c12c82b80a..dcf534690db 100644
--- a/src/server/game/Entities/Item/Item.cpp
+++ b/src/server/game/Entities/Item/Item.cpp
@@ -315,7 +315,7 @@ void Item::UpdateDuration(Player* owner, uint32 diff)
void Item::SaveToDB(SQLTransaction& trans)
{
- bool isInTransaction = !(trans.null());
+ bool isInTransaction = bool(trans);
if (!isInTransaction)
trans = CharacterDatabase.BeginTransaction();
@@ -1110,7 +1110,7 @@ void Item::SaveRefundDataToDB()
void Item::DeleteRefundDataFromDB(SQLTransaction* trans)
{
- if (trans && !trans->null())
+ if (trans)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEM_REFUND_INSTANCE);
stmt->setUInt32(0, GetGUIDLow());
diff --git a/src/server/game/Entities/Item/ItemPrototype.h b/src/server/game/Entities/Item/ItemPrototype.h
index b4357d4a1a1..e470afac1ab 100644
--- a/src/server/game/Entities/Item/ItemPrototype.h
+++ b/src/server/game/Entities/Item/ItemPrototype.h
@@ -724,7 +724,7 @@ struct ItemTemplate
return false;
}
- bool IsCurrencyToken() const { return BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS; }
+ bool IsCurrencyToken() const { return (BagFamily & BAG_FAMILY_MASK_CURRENCY_TOKENS) != 0; }
uint32 GetMaxStackSize() const
{
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 2d7a6f12016..cefe482c585 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -198,7 +198,7 @@ class Object
virtual void SetObjectScale(float scale) { SetFloatValue(OBJECT_FIELD_SCALE_X, scale); }
TypeID GetTypeId() const { return m_objectTypeId; }
- bool isType(uint16 mask) const { return (mask & m_objectType); }
+ bool isType(uint16 mask) const { return (mask & m_objectType) != 0; }
virtual void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const;
void SendUpdateToPlayer(Player* player);
@@ -530,13 +530,13 @@ struct MovementInfo
void SetMovementFlags(uint32 flag) { flags = flag; }
void AddMovementFlag(uint32 flag) { flags |= flag; }
void RemoveMovementFlag(uint32 flag) { flags &= ~flag; }
- bool HasMovementFlag(uint32 flag) const { return flags & flag; }
+ bool HasMovementFlag(uint32 flag) const { return (flags & flag) != 0; }
uint16 GetExtraMovementFlags() const { return flags2; }
void SetExtraMovementFlags(uint16 flag) { flags2 = flag; }
void AddExtraMovementFlag(uint16 flag) { flags2 |= flag; }
void RemoveExtraMovementFlag(uint16 flag) { flags2 &= ~flag; }
- bool HasExtraMovementFlag(uint16 flag) const { return flags2 & flag; }
+ bool HasExtraMovementFlag(uint16 flag) const { return (flags2 & flag) != 0; }
void SetFallTime(uint32 time) { jump.fallTime = time; }
@@ -679,7 +679,7 @@ class WorldObject : public Object, public WorldLocation
virtual void SetInPhase(uint32 id, bool update, bool apply);
uint32 GetPhaseMask() const { return m_phaseMask; }
bool InSamePhase(WorldObject const* obj) const;
- bool InSamePhase(uint32 phasemask) const { return (GetPhaseMask() & phasemask); }
+ bool InSamePhase(uint32 phasemask) const { return (GetPhaseMask() & phasemask) != 0; }
bool IsInPhase(uint32 phase) const { return _phases.find(phase) != _phases.end(); }
bool IsInPhase(WorldObject const* obj) const;
std::set<uint32> const& GetPhases() const { return _phases; }
@@ -795,9 +795,9 @@ class WorldObject : public Object, public WorldLocation
//relocation and visibility system functions
void AddToNotify(uint16 f) { m_notifyflags |= f;}
- bool isNeedNotify(uint16 f) const { return m_notifyflags & f;}
+ bool isNeedNotify(uint16 f) const { return (m_notifyflags & f) != 0; }
uint16 GetNotifyFlags() const { return m_notifyflags; }
- bool NotifyExecuted(uint16 f) const { return m_executed_notifies & f;}
+ bool NotifyExecuted(uint16 f) const { return (m_executed_notifies & f) != 0; }
void SetNotified(uint16 f) { m_executed_notifies |= f;}
void ResetAllNotifies() { m_notifyflags = 0; m_executed_notifies = 0; }
diff --git a/src/server/game/Entities/Pet/Pet.cpp b/src/server/game/Entities/Pet/Pet.cpp
index 91c1aa52592..5c731c6f8f7 100644
--- a/src/server/game/Entities/Pet/Pet.cpp
+++ b/src/server/game/Entities/Pet/Pet.cpp
@@ -1050,7 +1050,7 @@ bool Pet::HaveInDiet(ItemTemplate const* item) const
uint32 diet = cFamily->petFoodMask;
uint32 FoodMask = 1 << (item->FoodType-1);
- return diet & FoodMask;
+ return (diet & FoodMask) != 0;
}
uint32 Pet::GetCurrentFoodBenefitLevel(uint32 itemlevel) const
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index 35d3267605a..241bc452706 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -3851,7 +3851,7 @@ bool Player::AddSpell(uint32 spellId, bool active, bool learning, bool dependent
if (spellInfo->IsPrimaryProfessionFirstRank())
SetFreePrimaryProfessions(freeProfs-1);
}
-
+
SkillLineAbilityMapBounds skill_bounds = sSpellMgr->GetSkillLineAbilityMapBounds(spellId);
// add dependent skills if this spell is not learned from adding skill already
@@ -20004,7 +20004,7 @@ void Player::_SaveMail(SQLTransaction& trans)
void Player::_SaveQuestStatus(SQLTransaction& trans)
{
- bool isTransaction = !trans.null();
+ bool isTransaction = bool(trans);
if (!isTransaction)
trans = CharacterDatabase.BeginTransaction();
@@ -24663,7 +24663,7 @@ uint32 Player::GetCorpseReclaimDelay(bool pvp) const
void Player::UpdateCorpseReclaimDelay()
{
- bool pvp = m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH;
+ bool pvp = (m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH) != 0;
if ((pvp && !sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVP)) ||
(!pvp && !sWorld->getBoolConfig(CONFIG_DEATH_CORPSE_RECLAIM_DELAY_PVE)))
@@ -24692,7 +24692,7 @@ int32 Player::CalculateCorpseReclaimDelay(bool load)
if (load && !corpse)
return -1;
- bool pvp = corpse ? corpse->GetType() == CORPSE_RESURRECTABLE_PVP : m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH;
+ bool pvp = corpse ? corpse->GetType() == CORPSE_RESURRECTABLE_PVP : (m_ExtraFlags & PLAYER_EXTRA_PVP_DEATH) != 0;
uint32 delay;
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index d54b9aa9a65..9d1dbcc9215 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1290,13 +1290,13 @@ class Player : public Unit, public GridObject<Player>
void CleanupAfterTaxiFlight();
void ContinueTaxiFlight();
// mount_id can be used in scripting calls
- bool isAcceptWhispers() const { return m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS; }
+ bool isAcceptWhispers() const { return (m_ExtraFlags & PLAYER_EXTRA_ACCEPT_WHISPERS) != 0; }
void SetAcceptWhispers(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_ACCEPT_WHISPERS; else m_ExtraFlags &= ~PLAYER_EXTRA_ACCEPT_WHISPERS; }
- bool IsGameMaster() const { return m_ExtraFlags & PLAYER_EXTRA_GM_ON; }
+ bool IsGameMaster() const { return (m_ExtraFlags & PLAYER_EXTRA_GM_ON) != 0; }
void SetGameMaster(bool on);
- bool isGMChat() const { return m_ExtraFlags & PLAYER_EXTRA_GM_CHAT; }
+ bool isGMChat() const { return (m_ExtraFlags & PLAYER_EXTRA_GM_CHAT) != 0; }
void SetGMChat(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_GM_CHAT; else m_ExtraFlags &= ~PLAYER_EXTRA_GM_CHAT; }
- bool isTaxiCheater() const { return m_ExtraFlags & PLAYER_EXTRA_TAXICHEAT; }
+ bool isTaxiCheater() const { return (m_ExtraFlags & PLAYER_EXTRA_TAXICHEAT) != 0; }
void SetTaxiCheater(bool on) { if (on) m_ExtraFlags |= PLAYER_EXTRA_TAXICHEAT; else m_ExtraFlags &= ~PLAYER_EXTRA_TAXICHEAT; }
bool isGMVisible() const { return !(m_ExtraFlags & PLAYER_EXTRA_GM_INVISIBLE); }
void SetGMVisible(bool on);
@@ -1308,7 +1308,7 @@ class Player : public Unit, public GridObject<Player>
void InitStatsForLevel(bool reapplyMods = false);
// .cheat command related
- bool GetCommandStatus(uint32 command) const { return _activeCheats & command; }
+ bool GetCommandStatus(uint32 command) const { return (_activeCheats & command) != 0; }
void SetCommandStatusOn(uint32 command) { _activeCheats |= command; }
void SetCommandStatusOff(uint32 command) { _activeCheats &= ~command; }
@@ -2377,7 +2377,7 @@ class Player : public Unit, public GridObject<Player>
uint8 m_forced_speed_changes[MAX_MOVE_TYPE];
- bool HasAtLoginFlag(AtLoginFlags f) const { return m_atLoginFlags & f; }
+ bool HasAtLoginFlag(AtLoginFlags f) const { return (m_atLoginFlags & f) != 0; }
void SetAtLoginFlag(AtLoginFlags f) { m_atLoginFlags |= f; }
void RemoveAtLoginFlag(AtLoginFlags flags, bool persist = false);
diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp
index 6e593951f2c..c351aeac482 100644
--- a/src/server/game/Entities/Player/SocialMgr.cpp
+++ b/src/server/game/Entities/Player/SocialMgr.cpp
@@ -188,7 +188,7 @@ bool PlayerSocial::HasIgnore(uint32 ignore_guid)
{
PlayerSocialMap::const_iterator itr = m_playerSocialMap.find(ignore_guid);
if (itr != m_playerSocialMap.end())
- return itr->second.Flags & SOCIAL_FLAG_IGNORED;
+ return (itr->second.Flags & SOCIAL_FLAG_IGNORED) != 0;
return false;
}
diff --git a/src/server/game/Entities/Player/SocialMgr.h b/src/server/game/Entities/Player/SocialMgr.h
index 910c9164738..68c25fbf648 100644
--- a/src/server/game/Entities/Player/SocialMgr.h
+++ b/src/server/game/Entities/Player/SocialMgr.h
@@ -19,7 +19,6 @@
#ifndef __TRINITY_SOCIALMGR_H
#define __TRINITY_SOCIALMGR_H
-#include <ace/Singleton.h>
#include "DatabaseEnv.h"
#include "Common.h"
@@ -123,13 +122,17 @@ class PlayerSocial
class SocialMgr
{
- friend class ACE_Singleton<SocialMgr, ACE_Null_Mutex>;
-
private:
SocialMgr();
~SocialMgr();
public:
+ static SocialMgr* instance()
+ {
+ static SocialMgr* instance = new SocialMgr();
+ return instance;
+ }
+
// Misc
void RemovePlayerSocial(uint32 guid) { m_socialMap.erase(guid); }
@@ -144,5 +147,5 @@ class SocialMgr
SocialMap m_socialMap;
};
-#define sSocialMgr ACE_Singleton<SocialMgr, ACE_Null_Mutex>::instance()
+#define sSocialMgr SocialMgr::instance()
#endif
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index da721cfc575..8a32f629513 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -363,7 +363,7 @@ void Unit::Update(uint32 p_time)
bool Unit::haveOffhandWeapon() const
{
if (Player const* player = ToPlayer())
- return player->GetWeaponForAttack(OFF_ATTACK, true);
+ return player->GetWeaponForAttack(OFF_ATTACK, true) != nullptr;
return CanDualWield();
}
@@ -2236,7 +2236,7 @@ SpellMissInfo Unit::MeleeSpellHitResult(Unit* victim, SpellInfo const* spellInfo
bool canDodge = true;
bool canParry = true;
- bool canBlock = spellInfo->AttributesEx3 & SPELL_ATTR3_BLOCKABLE_SPELL;
+ bool canBlock = (spellInfo->AttributesEx3 & SPELL_ATTR3_BLOCKABLE_SPELL) != 0;
// Same spells cannot be parry/dodge
if (spellInfo->Attributes & SPELL_ATTR0_IMPOSSIBLE_DODGE_PARRY_BLOCK)
@@ -3553,7 +3553,7 @@ void Unit::RemoveAurasDueToSpellBySteal(uint32 spellId, uint64 casterGUID, Unit*
}
}
- bool stealCharge = aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES;
+ bool stealCharge = (aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES) != 0;
// Cast duration to unsigned to prevent permanent aura's such as Righteous Fury being permanently added to caster
uint32 dur = std::min(2u * MINUTE * IN_MILLISECONDS, uint32(aura->GetDuration()));
@@ -4075,7 +4075,7 @@ void Unit::GetDispellableAuraList(Unit* caster, uint32 dispelMask, DispelCharges
// The charges / stack amounts don't count towards the total number of auras that can be dispelled.
// Ie: A dispel on a target with 5 stacks of Winters Chill and a Polymorph has 1 / (1 + 1) -> 50% chance to dispell
// Polymorph instead of 1 / (5 + 1) -> 16%.
- bool dispel_charges = aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES;
+ bool dispel_charges = (aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES) != 0;
uint8 charges = dispel_charges ? aura->GetCharges() : aura->GetStackAmount();
if (charges > 0)
dispelList.push_back(std::make_pair(aura, charges));
@@ -13614,7 +13614,7 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
if (group)
{
- group->BroadcastPacket(&data, group->GetMemberGroup(player->GetGUID()));
+ group->BroadcastPacket(&data, group->GetMemberGroup(player->GetGUID()) != 0);
if (creature)
{
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index eb0882e3b64..035c3a6aa0e 100644
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -1360,18 +1360,18 @@ class Unit : public WorldObject
void SendMeleeAttackStart(Unit* victim);
void AddUnitState(uint32 f) { m_state |= f; }
- bool HasUnitState(const uint32 f) const { return (m_state & f); }
+ bool HasUnitState(const uint32 f) const { return (m_state & f) != 0; }
void ClearUnitState(uint32 f) { m_state &= ~f; }
bool CanFreeMove() const;
uint32 HasUnitTypeMask(uint32 mask) const { return mask & m_unitTypeMask; }
void AddUnitTypeMask(uint32 mask) { m_unitTypeMask |= mask; }
- bool IsSummon() const { return m_unitTypeMask & UNIT_MASK_SUMMON; }
- bool IsGuardian() const { return m_unitTypeMask & UNIT_MASK_GUARDIAN; }
- bool IsPet() const { return m_unitTypeMask & UNIT_MASK_PET; }
- bool IsHunterPet() const{ return m_unitTypeMask & UNIT_MASK_HUNTER_PET; }
- bool IsTotem() const { return m_unitTypeMask & UNIT_MASK_TOTEM; }
- bool IsVehicle() const { return m_unitTypeMask & UNIT_MASK_VEHICLE; }
+ bool IsSummon() const { return (m_unitTypeMask & UNIT_MASK_SUMMON) != 0; }
+ bool IsGuardian() const { return (m_unitTypeMask & UNIT_MASK_GUARDIAN) != 0; }
+ bool IsPet() const { return (m_unitTypeMask & UNIT_MASK_PET) != 0; }
+ bool IsHunterPet() const{ return (m_unitTypeMask & UNIT_MASK_HUNTER_PET) != 0; }
+ bool IsTotem() const { return (m_unitTypeMask & UNIT_MASK_TOTEM) != 0; }
+ bool IsVehicle() const { return (m_unitTypeMask & UNIT_MASK_VEHICLE) != 0; }
uint8 getLevel() const { return uint8(GetUInt32Value(UNIT_FIELD_LEVEL)); }
uint8 getLevelForTarget(WorldObject const* /*target*/) const { return getLevel(); }
diff --git a/src/server/game/Entities/Vehicle/VehicleDefines.h b/src/server/game/Entities/Vehicle/VehicleDefines.h
index 2c466255dc0..2a800008e8b 100644
--- a/src/server/game/Entities/Vehicle/VehicleDefines.h
+++ b/src/server/game/Entities/Vehicle/VehicleDefines.h
@@ -105,7 +105,7 @@ struct VehicleAccessory
VehicleAccessory(uint32 entry, int8 seatId, bool isMinion, uint8 summonType, uint32 summonTime) :
AccessoryEntry(entry), IsMinion(isMinion), SummonTime(summonTime), SeatId(seatId), SummonedType(summonType) { }
uint32 AccessoryEntry;
- uint32 IsMinion;
+ bool IsMinion;
uint32 SummonTime;
int8 SeatId;
uint8 SummonedType;
diff --git a/src/server/game/Events/GameEventMgr.cpp b/src/server/game/Events/GameEventMgr.cpp
index 175524d7208..217919ff574 100644
--- a/src/server/game/Events/GameEventMgr.cpp
+++ b/src/server/game/Events/GameEventMgr.cpp
@@ -1164,7 +1164,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: %zu)",
internal_event_id, mGameEventCreatureGuids.size());
return;
}
@@ -1191,7 +1191,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: %zu)",
internal_event_id, mGameEventGameobjectGuids.size());
return;
}
@@ -1224,7 +1224,7 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %u (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %u (size: %zu)",
internal_event_id, mGameEventPoolIds.size());
return;
}
@@ -1239,7 +1239,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventCreatureGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element %i (size: %zu)",
internal_event_id, mGameEventCreatureGuids.size());
return;
}
@@ -1261,7 +1261,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventGameobjectGuids.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element %i (size: %zu)",
internal_event_id, mGameEventGameobjectGuids.size());
return;
}
@@ -1282,7 +1282,7 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
}
if (internal_event_id < 0 || internal_event_id >= int32(mGameEventPoolIds.size()))
{
- TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %u (size: " SIZEFMTD ")", internal_event_id, mGameEventPoolIds.size());
+ TC_LOG_ERROR("gameevent", "GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %u (size: %zu)", internal_event_id, mGameEventPoolIds.size());
return;
}
@@ -1601,14 +1601,14 @@ void GameEventMgr::RunSmartAIScripts(uint16 event_id, bool activate)
//! Iterate over every supported source type (creature and gameobject)
//! Not entirely sure how this will affect units in non-loaded grids.
{
- TRINITY_READ_GUARD(HashMapHolder<Creature>::LockType, *HashMapHolder<Creature>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Creature>::GetLock());
HashMapHolder<Creature>::MapType const& m = ObjectAccessor::GetCreatures();
for (HashMapHolder<Creature>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld())
iter->second->AI()->sOnGameEvent(activate, event_id);
}
{
- TRINITY_READ_GUARD(HashMapHolder<GameObject>::LockType, *HashMapHolder<GameObject>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<GameObject>::GetLock());
HashMapHolder<GameObject>::MapType const& m = ObjectAccessor::GetGameObjects();
for (HashMapHolder<GameObject>::MapType::const_iterator iter = m.begin(); iter != m.end(); ++iter)
if (iter->second->IsInWorld())
diff --git a/src/server/game/Events/GameEventMgr.h b/src/server/game/Events/GameEventMgr.h
index 4b63402caa8..99b94357a63 100644
--- a/src/server/game/Events/GameEventMgr.h
+++ b/src/server/game/Events/GameEventMgr.h
@@ -22,7 +22,6 @@
#include "Common.h"
#include "SharedDefines.h"
#include "Define.h"
-#include <ace/Singleton.h>
#define max_ge_check_delay DAY // 1 day in seconds
@@ -96,13 +95,17 @@ class Quest;
class GameEventMgr
{
- friend class ACE_Singleton<GameEventMgr, ACE_Null_Mutex>;
-
private:
GameEventMgr();
~GameEventMgr() { };
public:
+ static GameEventMgr* instance()
+ {
+ static GameEventMgr* instance = new GameEventMgr();
+ return instance;
+ }
+
typedef std::set<uint16> ActiveEvents;
typedef std::vector<GameEventData> GameEventDataMap;
ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; }
@@ -181,7 +184,7 @@ class GameEventMgr
GameEventGuidMap mGameEventGameobjectGuids;
};
-#define sGameEventMgr ACE_Singleton<GameEventMgr, ACE_Null_Mutex>::instance()
+#define sGameEventMgr GameEventMgr::instance()
bool IsHolidayActive(HolidayIds id);
bool IsEventActive(uint16 event_id);
diff --git a/src/server/game/Globals/ObjectAccessor.cpp b/src/server/game/Globals/ObjectAccessor.cpp
index 13609f8e949..d2426effa8e 100644
--- a/src/server/game/Globals/ObjectAccessor.cpp
+++ b/src/server/game/Globals/ObjectAccessor.cpp
@@ -16,6 +16,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <boost/thread/shared_mutex.hpp>
+#include <boost/thread/locks.hpp>
+
#include "ObjectAccessor.h"
#include "CellImpl.h"
#include "Corpse.h"
@@ -214,7 +217,8 @@ Unit* ObjectAccessor::FindUnit(uint64 guid)
Player* ObjectAccessor::FindPlayerByName(std::string const& name)
{
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
std::string nameStr = name;
std::transform(nameStr.begin(), nameStr.end(), nameStr.begin(), ::tolower);
HashMapHolder<Player>::MapType const& m = GetPlayers();
@@ -233,7 +237,8 @@ Player* ObjectAccessor::FindPlayerByName(std::string const& name)
void ObjectAccessor::SaveAllPlayers()
{
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
HashMapHolder<Player>::MapType const& m = GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
itr->second->SaveToDB();
@@ -241,7 +246,7 @@ void ObjectAccessor::SaveAllPlayers()
Corpse* ObjectAccessor::GetCorpseForPlayerGUID(uint64 guid)
{
- TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
Player2CorpsesMapType::iterator iter = i_player2corpse.find(guid);
if (iter == i_player2corpse.end())
@@ -256,6 +261,8 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
{
ASSERT(corpse && corpse->GetType() != CORPSE_BONES);
+ boost::upgrade_lock<boost::shared_mutex> lock(_corpseLock);
+
/// @todo more works need to be done for corpse and other world object
if (Map* map = corpse->FindMap())
{
@@ -274,7 +281,7 @@ void ObjectAccessor::RemoveCorpse(Corpse* corpse)
// Critical section
{
- TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::upgrade_to_unique_lock<boost::shared_mutex> uniqueLock(lock);
Player2CorpsesMapType::iterator iter = i_player2corpse.find(corpse->GetOwnerGUID());
if (iter == i_player2corpse.end()) /// @todo Fix this
@@ -294,7 +301,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
// Critical section
{
- TRINITY_WRITE_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::unique_lock<boost::shared_mutex> lock(_corpseLock);
ASSERT(i_player2corpse.find(corpse->GetOwnerGUID()) == i_player2corpse.end());
i_player2corpse[corpse->GetOwnerGUID()] = corpse;
@@ -307,7 +314,7 @@ void ObjectAccessor::AddCorpse(Corpse* corpse)
void ObjectAccessor::AddCorpsesToGrid(GridCoord const& gridpair, GridType& grid, Map* map)
{
- TRINITY_READ_GUARD(ACE_RW_Thread_Mutex, i_corpseLock);
+ boost::shared_lock<boost::shared_mutex> lock(_corpseLock);
for (Player2CorpsesMapType::iterator iter = i_player2corpse.begin(); iter != i_player2corpse.end(); ++iter)
{
@@ -439,8 +446,8 @@ void ObjectAccessor::UnloadAll()
/// Define the static members of HashMapHolder
-template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::m_objectMap;
-template <class T> typename HashMapHolder<T>::LockType HashMapHolder<T>::i_lock;
+template <class T> std::unordered_map< uint64, T* > HashMapHolder<T>::_objectMap;
+template <class T> boost::shared_mutex HashMapHolder<T>::_lock;
/// Global definitions for the hashmap storage
diff --git a/src/server/game/Globals/ObjectAccessor.h b/src/server/game/Globals/ObjectAccessor.h
index f65486850ac..dff783f4276 100644
--- a/src/server/game/Globals/ObjectAccessor.h
+++ b/src/server/game/Globals/ObjectAccessor.h
@@ -19,17 +19,17 @@
#ifndef TRINITY_OBJECTACCESSOR_H
#define TRINITY_OBJECTACCESSOR_H
-#include "Define.h"
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
+#include <mutex>
+#include <set>
#include <unordered_map>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
-#include "UpdateData.h"
-
+#include "Define.h"
#include "GridDefines.h"
+#include "UpdateData.h"
#include "Object.h"
-#include <set>
class Creature;
class Corpse;
@@ -48,42 +48,41 @@ class HashMapHolder
public:
typedef std::unordered_map<uint64, T*> MapType;
- typedef ACE_RW_Thread_Mutex LockType;
static void Insert(T* o)
{
- TRINITY_WRITE_GUARD(LockType, i_lock);
- m_objectMap[o->GetGUID()] = o;
+ boost::shared_lock<boost::shared_mutex> lock(_lock);
+
+ _objectMap[o->GetGUID()] = o;
}
static void Remove(T* o)
{
- TRINITY_WRITE_GUARD(LockType, i_lock);
- m_objectMap.erase(o->GetGUID());
+ boost::unique_lock<boost::shared_mutex> lock(_lock);
+ _objectMap.erase(o->GetGUID());
}
static T* Find(uint64 guid)
{
- TRINITY_READ_GUARD(LockType, i_lock);
- typename MapType::iterator itr = m_objectMap.find(guid);
- return (itr != m_objectMap.end()) ? itr->second : NULL;
+ boost::shared_lock<boost::shared_mutex> lock(_lock);
+ typename MapType::iterator itr = _objectMap.find(guid);
+ return (itr != _objectMap.end()) ? itr->second : NULL;
}
- static MapType& GetContainer() { return m_objectMap; }
+ static MapType& GetContainer() { return _objectMap; }
- static LockType* GetLock() { return &i_lock; }
+ static boost::shared_mutex* GetLock() { return &_lock; }
private:
//Non instanceable only static
HashMapHolder() { }
- static LockType i_lock;
- static MapType m_objectMap;
+ static boost::shared_mutex _lock;
+ static MapType _objectMap;
};
class ObjectAccessor
{
- friend class ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>;
private:
ObjectAccessor();
~ObjectAccessor();
@@ -93,6 +92,12 @@ class ObjectAccessor
public:
/// @todo: Override these template functions for each holder type and add assertions
+ static ObjectAccessor* instance()
+ {
+ static ObjectAccessor *instance = new ObjectAccessor();
+ return instance;
+ }
+
template<class T> static T* GetObjectInOrOutOfWorld(uint64 guid, T* /*typeSpecifier*/)
{
return HashMapHolder<T>::Find(guid);
@@ -196,13 +201,13 @@ class ObjectAccessor
//non-static functions
void AddUpdateObject(Object* obj)
{
- TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
+ std::lock_guard<std::mutex> lock(_objectLock);
i_objects.insert(obj);
}
void RemoveUpdateObject(Object* obj)
{
- TRINITY_GUARD(ACE_Thread_Mutex, i_objectLock);
+ std::lock_guard<std::mutex> lock(_objectLock);
i_objects.erase(obj);
}
@@ -229,9 +234,9 @@ class ObjectAccessor
std::set<Object*> i_objects;
Player2CorpsesMapType i_player2corpse;
- ACE_Thread_Mutex i_objectLock;
- ACE_RW_Thread_Mutex i_corpseLock;
+ std::mutex _objectLock;
+ boost::shared_mutex _corpseLock;
};
-#define sObjectAccessor ACE_Singleton<ObjectAccessor, ACE_Null_Mutex>::instance()
+#define sObjectAccessor ObjectAccessor::instance()
#endif
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index ec151d4d58b..93c06146c06 100644
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -5486,7 +5486,7 @@ void ObjectMgr::ReturnOrDeleteOldMails(bool serverUp)
time_t curTime = time(NULL);
tm lt;
- ACE_OS::localtime_r(&curTime, &lt);
+ localtime_r(&curTime, &lt);
uint64 basetime(curTime);
TC_LOG_INFO("misc", "Returning mails current time: hour: %d, minute: %d, second: %d ", lt.tm_hour, lt.tm_min, lt.tm_sec);
@@ -7047,7 +7047,7 @@ void ObjectMgr::LoadReputationOnKill()
repOnKill.IsTeamAward2 = fields[6].GetBool();
repOnKill.ReputationMaxCap2 = fields[7].GetUInt8();
repOnKill.RepValue2 = fields[8].GetInt32();
- repOnKill.TeamDependent = fields[9].GetUInt8();
+ repOnKill.TeamDependent = fields[9].GetBool();
if (!GetCreatureTemplate(creature_id))
{
diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index a6e2ce9b067..46561fd7773 100644
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -35,7 +35,6 @@
#include "Map.h"
#include "ObjectAccessor.h"
#include "ObjectDefines.h"
-#include <ace/Singleton.h>
#include "VehicleDefines.h"
#include <string>
#include <map>
@@ -723,13 +722,18 @@ class PlayerDumpReader;
class ObjectMgr
{
friend class PlayerDumpReader;
- friend class ACE_Singleton<ObjectMgr, ACE_Null_Mutex>;
private:
ObjectMgr();
~ObjectMgr();
public:
+ static ObjectMgr* instance()
+ {
+ static ObjectMgr* instance = new ObjectMgr();
+ return instance;
+ }
+
typedef std::unordered_map<uint32, Item*> ItemMap;
typedef std::unordered_map<uint32, Quest*> QuestMap;
@@ -1326,7 +1330,7 @@ class ObjectMgr
void LoadFactionChangeSpells();
void LoadFactionChangeTitles();
- bool IsTransportMap(uint32 mapId) const { return _transportMaps.count(mapId); }
+ bool IsTransportMap(uint32 mapId) const { return _transportMaps.count(mapId) != 0; }
void LoadHotfixData();
HotfixData const& GetHotfixData() const { return _hotfixData; }
@@ -1494,6 +1498,6 @@ class ObjectMgr
std::set<uint32> _transportMaps; // Helper container storing map ids that are for transports only, loaded from gameobject_template
};
-#define sObjectMgr ACE_Singleton<ObjectMgr, ACE_Null_Mutex>::instance()
+#define sObjectMgr ObjectMgr::instance()
#endif
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp
index e9ebfb1eff6..e6f0b0f459a 100644
--- a/src/server/game/Groups/Group.cpp
+++ b/src/server/game/Groups/Group.cpp
@@ -523,7 +523,7 @@ bool Group::RemoveMember(uint64 guid, const RemoveMethod& method /*= GROUP_REMOV
// LFG group vote kick handled in scripts
if (isLFGGroup() && method == GROUP_REMOVEMETHOD_KICK)
- return m_memberSlots.size();
+ return !m_memberSlots.empty();
// remove member and change leader (if need) only if strong more 2 members _before_ member remove (BG/BF allow 1 member group)
if (GetMembersCount() > ((isBGGroup() || isLFGGroup() || isBFGroup()) ? 1u : 2u))
@@ -2218,12 +2218,12 @@ bool Group::IsFull() const
bool Group::isLFGGroup() const
{
- return m_groupType & GROUPTYPE_LFG;
+ return (m_groupType & GROUPTYPE_LFG) != 0;
}
bool Group::isRaidGroup() const
{
- return m_groupType & GROUPTYPE_RAID;
+ return (m_groupType & GROUPTYPE_RAID) != 0;
}
bool Group::isBGGroup() const
diff --git a/src/server/game/Groups/GroupMgr.cpp b/src/server/game/Groups/GroupMgr.cpp
index 39735f5dce3..23b6998d688 100644
--- a/src/server/game/Groups/GroupMgr.cpp
+++ b/src/server/game/Groups/GroupMgr.cpp
@@ -226,7 +226,7 @@ void GroupMgr::LoadGroups()
diff = 0; // default for both difficaly types
}
- InstanceSave* save = sInstanceSaveMgr->AddInstanceSave(mapEntry->MapID, fields[2].GetUInt32(), Difficulty(diff), time_t(fields[5].GetUInt32()), (bool)fields[6].GetUInt64(), true);
+ InstanceSave* save = sInstanceSaveMgr->AddInstanceSave(mapEntry->MapID, fields[2].GetUInt32(), Difficulty(diff), time_t(fields[5].GetUInt32()), fields[6].GetUInt64() != 0, true);
group->BindToInstance(save, fields[3].GetBool(), true);
++count;
}
diff --git a/src/server/game/Groups/GroupMgr.h b/src/server/game/Groups/GroupMgr.h
index a805b7514da..4bf440c881e 100644
--- a/src/server/game/Groups/GroupMgr.h
+++ b/src/server/game/Groups/GroupMgr.h
@@ -22,12 +22,17 @@
class GroupMgr
{
- friend class ACE_Singleton<GroupMgr, ACE_Null_Mutex>;
private:
GroupMgr();
~GroupMgr();
public:
+ static GroupMgr* instance()
+ {
+ static GroupMgr* instance = new GroupMgr();
+ return instance;
+ }
+
typedef std::map<uint32, Group*> GroupContainer;
typedef std::vector<Group*> GroupDbContainer;
@@ -53,6 +58,6 @@ protected:
GroupDbContainer GroupDbStore;
};
-#define sGroupMgr ACE_Singleton<GroupMgr, ACE_Null_Mutex>::instance()
+#define sGroupMgr GroupMgr::instance()
#endif
diff --git a/src/server/game/Guilds/Guild.cpp b/src/server/game/Guilds/Guild.cpp
index 2df57099c99..9e86039e4af 100644
--- a/src/server/game/Guilds/Guild.cpp
+++ b/src/server/game/Guilds/Guild.cpp
@@ -3191,7 +3191,7 @@ bool Guild::_DoItemsMove(MoveItemData* pSrc, MoveItemData* pDest, bool sendError
Item* pDestItem = pDest->GetItem();
bool swap = (pDestItem != NULL);
- Item* pSrcItem = pSrc->GetItem(splitedAmount);
+ Item* pSrcItem = pSrc->GetItem(splitedAmount != 0);
// 1. Can store source item in destination
if (!pDest->CanStore(pSrcItem, swap, sendError))
return false;
diff --git a/src/server/game/Guilds/GuildMgr.h b/src/server/game/Guilds/GuildMgr.h
index 2dcc0202993..318445fe844 100644
--- a/src/server/game/Guilds/GuildMgr.h
+++ b/src/server/game/Guilds/GuildMgr.h
@@ -22,13 +22,17 @@
class GuildMgr
{
- friend class ACE_Singleton<GuildMgr, ACE_Null_Mutex>;
-
private:
GuildMgr();
~GuildMgr();
public:
+ static GuildMgr* instance()
+ {
+ static GuildMgr* instance = new GuildMgr();
+ return instance;
+ }
+
Guild* GetGuildByLeader(uint64 guid) const;
Guild* GetGuildById(uint32 guildId) const;
Guild* GetGuildByGuid(uint64 guid) const;
@@ -61,6 +65,6 @@ protected:
std::vector<GuildReward> GuildRewards;
};
-#define sGuildMgr ACE_Singleton<GuildMgr, ACE_Null_Mutex>::instance()
+#define sGuildMgr GuildMgr::instance()
#endif
diff --git a/src/server/game/Handlers/AddonHandler.cpp b/src/server/game/Handlers/AddonHandler.cpp
index 806cbd1c7fc..8a00ddc22f4 100644
--- a/src/server/game/Handlers/AddonHandler.cpp
+++ b/src/server/game/Handlers/AddonHandler.cpp
@@ -22,10 +22,6 @@
#include "Opcodes.h"
#include "Log.h"
-AddonHandler::AddonHandler() { }
-
-AddonHandler::~AddonHandler() { }
-
bool AddonHandler::BuildAddonPacket(WorldPacket* source, WorldPacket* target)
{
ByteBuffer AddOnPacked;
diff --git a/src/server/game/Handlers/AddonHandler.h b/src/server/game/Handlers/AddonHandler.h
index 97a541753d0..31bbfa01900 100644
--- a/src/server/game/Handlers/AddonHandler.h
+++ b/src/server/game/Handlers/AddonHandler.h
@@ -21,20 +21,23 @@
#include "Common.h"
#include "Config.h"
-#include <ace/Singleton.h>
#include "WorldPacket.h"
class AddonHandler
{
- /* Construction */
- friend class ACE_Singleton<AddonHandler, ACE_Null_Mutex>;
- AddonHandler();
-
public:
- ~AddonHandler();
- //build addon packet
+ static AddonHandler* instance()
+ {
+ static AddonHandler* instance = new AddonHandler();
+ return instance;
+ }
+
bool BuildAddonPacket(WorldPacket* Source, WorldPacket* Target);
+
+ private:
+ AddonHandler() { }
+ ~AddonHandler() { }
};
-#define sAddOnHandler ACE_Singleton<AddonHandler, ACE_Null_Mutex>::instance()
+#define sAddOnHandler AddonHandler::instance()
#endif
diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp
index dd4d9c9bc9f..422e5ce206b 100644
--- a/src/server/game/Handlers/CharacterHandler.cpp
+++ b/src/server/game/Handlers/CharacterHandler.cpp
@@ -312,10 +312,10 @@ void WorldSession::HandleCharCreateOpcode(WorldPacket& recvData)
switch (team)
{
case ALLIANCE:
- disabled = mask & (1 << 0);
+ disabled = (mask & (1 << 0)) != 0;
break;
case HORDE:
- disabled = mask & (1 << 1);
+ disabled = (mask & (1 << 1)) != 0;
break;
}
@@ -1152,7 +1152,7 @@ void WorldSession::HandleSetFactionAtWar(WorldPacket& recvData)
recvData >> repListID;
recvData >> flag;
- GetPlayer()->GetReputationMgr().SetAtWar(repListID, flag);
+ GetPlayer()->GetReputationMgr().SetAtWar(repListID, flag != 0);
}
//I think this function is never used :/ I dunno, but i guess this opcode not exists
@@ -1205,7 +1205,7 @@ void WorldSession::HandleSetFactionInactiveOpcode(WorldPacket& recvData)
uint8 inactive;
recvData >> replistid >> inactive;
- _player->GetReputationMgr().SetInactive(replistid, inactive);
+ _player->GetReputationMgr().SetInactive(replistid, inactive != 0);
}
void WorldSession::HandleShowingHelmOpcode(WorldPacket& recvData)
diff --git a/src/server/game/Handlers/GroupHandler.cpp b/src/server/game/Handlers/GroupHandler.cpp
index 8565da90f40..d74aebaaa1f 100644
--- a/src/server/game/Handlers/GroupHandler.cpp
+++ b/src/server/game/Handlers/GroupHandler.cpp
@@ -1377,5 +1377,5 @@ void WorldSession::HandleOptOutOfLootOpcode(WorldPacket& recvData)
return;
}
- GetPlayer()->SetPassOnGroupLoot(passOnLoot);
+ GetPlayer()->SetPassOnGroupLoot(passOnLoot != 0);
}
diff --git a/src/server/game/Handlers/GuildHandler.cpp b/src/server/game/Handlers/GuildHandler.cpp
index d40f2102c77..97d5ea8310e 100644
--- a/src/server/game/Handlers/GuildHandler.cpp
+++ b/src/server/game/Handlers/GuildHandler.cpp
@@ -538,7 +538,7 @@ void WorldSession::HandleGuildBankSwapItems(WorldPacket& recvPacket)
if (!Player::IsInventoryPos(playerBag, playerSlotId) && !(playerBag == NULL_BAG && playerSlotId == NULL_SLOT))
GetPlayer()->SendEquipError(EQUIP_ERR_INTERNAL_BAG_ERROR, NULL);
else
- guild->SwapItemsWithInventory(GetPlayer(), toChar, tabId, slotId, playerBag, playerSlotId, splitedAmount);
+ guild->SwapItemsWithInventory(GetPlayer(), toChar != 0, tabId, slotId, playerBag, playerSlotId, splitedAmount);
}
}
diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp
index 26f27ad817d..c9891de3c16 100644
--- a/src/server/game/Handlers/MiscHandler.cpp
+++ b/src/server/game/Handlers/MiscHandler.cpp
@@ -256,7 +256,8 @@ void WorldSession::HandleWhoOpcode(WorldPacket& recvData)
data << uint32(matchcount); // placeholder, count of players matching criteria
data << uint32(displaycount); // placeholder, count of players displayed
- TRINITY_READ_GUARD(HashMapHolder<Player>::LockType, *HashMapHolder<Player>::GetLock());
+ boost::shared_lock<boost::shared_mutex> lock(*HashMapHolder<Player>::GetLock());
+
HashMapHolder<Player>::MapType const& m = sObjectAccessor->GetPlayers();
for (HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
{
diff --git a/src/server/game/Handlers/NPCHandler.cpp b/src/server/game/Handlers/NPCHandler.cpp
index 1ce1197c3db..02651a1af09 100644
--- a/src/server/game/Handlers/NPCHandler.cpp
+++ b/src/server/game/Handlers/NPCHandler.cpp
@@ -907,12 +907,12 @@ void WorldSession::HandleRepairItemOpcode(WorldPacket& recvData)
Item* item = _player->GetItemByGuid(itemGUID);
if (item)
- _player->DurabilityRepair(item->GetPos(), true, discountMod, guildBank);
+ _player->DurabilityRepair(item->GetPos(), true, discountMod, guildBank != 0);
}
else
{
TC_LOG_DEBUG("network", "ITEM: Repair all items, npcGUID = %u", GUID_LOPART(npcGUID));
- _player->DurabilityRepairAll(true, discountMod, guildBank);
+ _player->DurabilityRepairAll(true, discountMod, guildBank != 0);
}
}
diff --git a/src/server/game/Handlers/PetHandler.cpp b/src/server/game/Handlers/PetHandler.cpp
index 39d18178a01..f3dc24a8c01 100644
--- a/src/server/game/Handlers/PetHandler.cpp
+++ b/src/server/game/Handlers/PetHandler.cpp
@@ -744,11 +744,11 @@ void WorldSession::HandlePetSpellAutocastOpcode(WorldPacket& recvPacket)
}
if (pet->IsPet())
- ((Pet*)pet)->ToggleAutocast(spellInfo, state);
+ ((Pet*)pet)->ToggleAutocast(spellInfo, state != 0);
else
- pet->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, state);
+ pet->GetCharmInfo()->ToggleCreatureAutocast(spellInfo, state != 0);
- charmInfo->SetSpellAutocast(spellInfo, state);
+ charmInfo->SetSpellAutocast(spellInfo, state != 0);
}
void WorldSession::HandlePetCastSpellOpcode(WorldPacket& recvPacket)
diff --git a/src/server/game/Instances/InstanceSaveMgr.h b/src/server/game/Instances/InstanceSaveMgr.h
index cf852b7c952..de8a0e0fc8e 100644
--- a/src/server/game/Instances/InstanceSaveMgr.h
+++ b/src/server/game/Instances/InstanceSaveMgr.h
@@ -19,12 +19,12 @@
#ifndef _INSTANCESAVEMGR_H
#define _INSTANCESAVEMGR_H
-#include "Define.h"
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
#include <list>
#include <map>
+#include <mutex>
#include <unordered_map>
+
+#include "Define.h"
#include "DatabaseEnv.h"
#include "DBCEnums.h"
#include "ObjectDefines.h"
@@ -80,13 +80,18 @@ class InstanceSave
/* online players bound to the instance (perm/solo)
does not include the members of the group unless they have permanent saves */
- void AddPlayer(Player* player) { TRINITY_GUARD(ACE_Thread_Mutex, _lock); m_playerList.push_back(player); }
+ void AddPlayer(Player* player)
+ {
+ std::lock_guard<std::mutex> lock(_playerListLock);
+ m_playerList.push_back(player);
+ }
+
bool RemovePlayer(Player* player)
{
- _lock.acquire();
+ _playerListLock.lock();
m_playerList.remove(player);
bool isStillValid = UnloadIfEmpty();
- _lock.release();
+ _playerListLock.unlock();
//delete here if needed, after releasing the lock
if (m_toDelete)
@@ -137,14 +142,13 @@ class InstanceSave
bool m_canReset;
bool m_toDelete;
- ACE_Thread_Mutex _lock;
+ std::mutex _playerListLock;
};
typedef std::unordered_map<uint32 /*PAIR32(map, difficulty)*/, time_t /*resetTime*/> ResetTimeByMapDifficultyMap;
class InstanceSaveManager
{
- friend class ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>;
friend class InstanceSave;
private:
@@ -154,6 +158,12 @@ class InstanceSaveManager
public:
typedef std::unordered_map<uint32 /*InstanceId*/, InstanceSave*> InstanceSaveHashMap;
+ static InstanceSaveManager* instance()
+ {
+ static InstanceSaveManager *instance = new InstanceSaveManager();
+ return instance;
+ }
+
/* resetTime is a global propery of each (raid/heroic) map
all instances of that map reset at the same time */
struct InstResetEvent
@@ -221,5 +231,5 @@ class InstanceSaveManager
ResetTimeQueue m_resetTimeQueue;
};
-#define sInstanceSaveMgr ACE_Singleton<InstanceSaveManager, ACE_Thread_Mutex>::instance()
+#define sInstanceSaveMgr InstanceSaveManager::instance()
#endif
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 21572858b2b..c69f7863ef6 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -387,7 +387,7 @@ void Map::DeleteFromWorld(Player* player)
void Map::EnsureGridCreated(const GridCoord &p)
{
- TRINITY_GUARD(ACE_Thread_Mutex, GridLock);
+ std::lock_guard<std::mutex> lock(_gridLock);
EnsureGridCreated_i(p);
}
@@ -2195,13 +2195,13 @@ inline bool IsOutdoorWMO(uint32 mogpFlags, int32 /*adtId*/, int32 /*rootId*/, in
return false;
}
- outdoor = mogpFlags&0x8;
+ outdoor = (mogpFlags & 0x8) != 0;
if (wmoEntry)
{
if (wmoEntry->Flags & 4)
return true;
- if ((wmoEntry->Flags & 2)!=0)
+ if (wmoEntry->Flags & 2)
outdoor = false;
}
return outdoor;
@@ -2442,12 +2442,12 @@ bool Map::IsInWater(float x, float y, float pZ, LiquidData* data) const
{
LiquidData liquid_status;
LiquidData* liquid_ptr = data ? data : &liquid_status;
- return getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, liquid_ptr) & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER);
+ return (getLiquidStatus(x, y, pZ, MAP_ALL_LIQUIDS, liquid_ptr) & (LIQUID_MAP_IN_WATER | LIQUID_MAP_UNDER_WATER)) != 0;
}
bool Map::IsUnderWater(float x, float y, float z) const
{
- return getLiquidStatus(x, y, z, MAP_LIQUID_TYPE_WATER|MAP_LIQUID_TYPE_OCEAN) & LIQUID_MAP_UNDER_WATER;
+ return (getLiquidStatus(x, y, z, MAP_LIQUID_TYPE_WATER | MAP_LIQUID_TYPE_OCEAN) & LIQUID_MAP_UNDER_WATER) != 0;
}
bool Map::CheckGridIntegrity(Creature* c, bool moved) const
@@ -2924,7 +2924,7 @@ bool InstanceMap::AddPlayerToMap(Player* player)
// Is it needed?
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
// Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
//if (!CanEnter(player))
//return false;
@@ -3266,7 +3266,7 @@ bool BattlegroundMap::CanEnter(Player* player)
bool BattlegroundMap::AddPlayerToMap(Player* player)
{
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
//Check moved to void WorldSession::HandleMoveWorldportAckOpcode()
//if (!CanEnter(player))
//return false;
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index 3b66fd0fed5..c676a5c5ce0 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -20,8 +20,6 @@
#define TRINITY_MAP_H
#include "Define.h"
-#include <ace/RW_Thread_Mutex.h>
-#include <ace/Thread_Mutex.h>
#include "DBCStructure.h"
#include "GridDefines.h"
@@ -576,8 +574,8 @@ class Map : public GridRefManager<NGridType>
protected:
void SetUnloadReferenceLock(const GridCoord &p, bool on) { getNGrid(p.x_coord, p.y_coord)->setUnloadReferenceLock(on); }
- ACE_Thread_Mutex Lock;
- ACE_Thread_Mutex GridLock;
+ std::mutex _mapLock;
+ std::mutex _gridLock;
MapEntry const* i_mapEntry;
uint8 i_spawnMode;
diff --git a/src/server/game/Maps/MapInstanced.cpp b/src/server/game/Maps/MapInstanced.cpp
index e914a5c3eee..498c669ba01 100644
--- a/src/server/game/Maps/MapInstanced.cpp
+++ b/src/server/game/Maps/MapInstanced.cpp
@@ -187,7 +187,7 @@ Map* MapInstanced::CreateInstanceForPlayer(const uint32 mapId, Player* player)
InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save, Difficulty difficulty)
{
// load/create a map
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
// make sure we have a valid map id
const MapEntry* entry = sMapStore.LookupEntry(GetId());
@@ -223,7 +223,7 @@ InstanceMap* MapInstanced::CreateInstance(uint32 InstanceId, InstanceSave* save,
BattlegroundMap* MapInstanced::CreateBattleground(uint32 InstanceId, Battleground* bg)
{
// load/create a map
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapLock);
TC_LOG_DEBUG("maps", "MapInstanced::CreateBattleground: map bg %d for %d created.", InstanceId, GetId());
diff --git a/src/server/game/Maps/MapManager.cpp b/src/server/game/Maps/MapManager.cpp
index d6c849f4387..cc408988428 100644
--- a/src/server/game/Maps/MapManager.cpp
+++ b/src/server/game/Maps/MapManager.cpp
@@ -52,8 +52,8 @@ void MapManager::Initialize()
int num_threads(sWorld->getIntConfig(CONFIG_NUMTHREADS));
// Start mtmaps if needed.
- if (num_threads > 0 && m_updater.activate(num_threads) == -1)
- abort();
+ if (num_threads > 0)
+ m_updater.activate(num_threads);
}
void MapManager::InitializeVisibilityDistanceInfo()
@@ -68,7 +68,7 @@ Map* MapManager::CreateBaseMap(uint32 id)
if (map == NULL)
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
MapEntry const* entry = sMapStore.LookupEntry(id);
ASSERT(entry);
@@ -296,7 +296,7 @@ void MapManager::UnloadAll()
uint32 MapManager::GetNumInstances()
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
@@ -313,7 +313,7 @@ uint32 MapManager::GetNumInstances()
uint32 MapManager::GetNumPlayersInInstances()
{
- TRINITY_GUARD(ACE_Thread_Mutex, Lock);
+ std::lock_guard<std::mutex> lock(_mapsLock);
uint32 ret = 0;
for (MapMapType::iterator itr = i_maps.begin(); itr != i_maps.end(); ++itr)
diff --git a/src/server/game/Maps/MapManager.h b/src/server/game/Maps/MapManager.h
index b7fb0617a46..990d5e80c1a 100644
--- a/src/server/game/Maps/MapManager.h
+++ b/src/server/game/Maps/MapManager.h
@@ -24,18 +24,18 @@
#include "GridStates.h"
#include "MapUpdater.h"
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
-
-
class Transport;
struct TransportCreatureProto;
class MapManager
{
- friend class ACE_Singleton<MapManager, ACE_Thread_Mutex>;
-
public:
+ static MapManager* instance()
+ {
+ static MapManager* instance = new MapManager();
+ return instance;
+ }
+
Map* CreateBaseMap(uint32 mapId);
Map* FindBaseNonInstanceMap(uint32 mapId) const;
Map* CreateMap(uint32 mapId, Player* player);
@@ -141,7 +141,7 @@ class MapManager
MapManager(const MapManager &);
MapManager& operator=(const MapManager &);
- ACE_Thread_Mutex Lock;
+ std::mutex _mapsLock;
uint32 i_gridCleanUpDelay;
MapMapType i_maps;
IntervalTimer i_timer;
@@ -150,5 +150,5 @@ class MapManager
uint32 _nextInstanceId;
MapUpdater m_updater;
};
-#define sMapMgr ACE_Singleton<MapManager, ACE_Thread_Mutex>::instance()
+#define sMapMgr MapManager::instance()
#endif
diff --git a/src/server/game/Maps/MapUpdater.cpp b/src/server/game/Maps/MapUpdater.cpp
index dd697719d54..c456f57bd20 100644
--- a/src/server/game/Maps/MapUpdater.cpp
+++ b/src/server/game/Maps/MapUpdater.cpp
@@ -1,97 +1,125 @@
+/*
+* Copyright (C) 2008-2014 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 <mutex>
+#include <condition_variable>
+
#include "MapUpdater.h"
-#include "DelayExecutor.h"
#include "Map.h"
-#include "DatabaseEnv.h"
-#include <ace/Guard_T.h>
-#include <ace/Method_Request.h>
-class MapUpdateRequest : public ACE_Method_Request
+class MapUpdateRequest
{
private:
Map& m_map;
MapUpdater& m_updater;
- ACE_UINT32 m_diff;
+ uint32 m_diff;
public:
- MapUpdateRequest(Map& m, MapUpdater& u, ACE_UINT32 d)
+ MapUpdateRequest(Map& m, MapUpdater& u, uint32 d)
: m_map(m), m_updater(u), m_diff(d)
{
}
- virtual int call()
+ void call()
{
m_map.Update (m_diff);
m_updater.update_finished();
- return 0;
}
};
-MapUpdater::MapUpdater():
-m_executor(), m_mutex(), m_condition(m_mutex), pending_requests(0) { }
+MapUpdater::MapUpdater() : _cancelationToken(false), pending_requests(0) {}
MapUpdater::~MapUpdater()
{
deactivate();
}
-int MapUpdater::activate(size_t num_threads)
+void MapUpdater::activate(size_t num_threads)
{
- return m_executor.start((int)num_threads);
+ for (size_t i = 0; i < num_threads; ++i)
+ {
+ _workerThreads.push_back(std::thread(&MapUpdater::WorkerThread, this));
+ }
}
-int MapUpdater::deactivate()
+void MapUpdater::deactivate()
{
+ _cancelationToken = true;
+
wait();
- return m_executor.deactivate();
+ _queue.Cancel();
+
+ for (auto& thread : _workerThreads)
+ {
+ thread.join();
+ }
}
-int MapUpdater::wait()
+void MapUpdater::wait()
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::unique_lock<std::mutex> lock(_lock);
while (pending_requests > 0)
- m_condition.wait();
+ _condition.wait(lock);
- return 0;
+ lock.unlock();
}
-int MapUpdater::schedule_update(Map& map, ACE_UINT32 diff)
+void MapUpdater::schedule_update(Map& map, uint32 diff)
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::lock_guard<std::mutex> lock(_lock);
++pending_requests;
- if (m_executor.execute(new MapUpdateRequest(map, *this, diff)) == -1)
- {
- ACE_DEBUG((LM_ERROR, ACE_TEXT("(%t) \n"), ACE_TEXT("Failed to schedule Map Update")));
-
- --pending_requests;
- return -1;
- }
-
- return 0;
+ _queue.Push(new MapUpdateRequest(map, *this, diff));
}
bool MapUpdater::activated()
{
- return m_executor.activated();
+ return _workerThreads.size() > 0;
}
void MapUpdater::update_finished()
{
- TRINITY_GUARD(ACE_Thread_Mutex, m_mutex);
+ std::lock_guard<std::mutex> lock(_lock);
- if (pending_requests == 0)
+ --pending_requests;
+
+ _condition.notify_all();
+}
+
+void MapUpdater::WorkerThread()
+{
+ while (1)
{
- ACE_ERROR((LM_ERROR, ACE_TEXT("(%t)\n"), ACE_TEXT("MapUpdater::update_finished BUG, report to devs")));
- return;
- }
+ MapUpdateRequest* request = nullptr;
- --pending_requests;
+ _queue.WaitAndPop(request);
+
+ if (_cancelationToken)
+ return;
- m_condition.broadcast();
+ request->call();
+
+ delete request;
+ }
}
diff --git a/src/server/game/Maps/MapUpdater.h b/src/server/game/Maps/MapUpdater.h
index 89798026339..c499110173e 100644
--- a/src/server/game/Maps/MapUpdater.h
+++ b/src/server/game/Maps/MapUpdater.h
@@ -1,11 +1,31 @@
+/*
+* Copyright (C) 2008-2014 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 _MAP_UPDATER_H_INCLUDED
#define _MAP_UPDATER_H_INCLUDED
-#include <ace/Thread_Mutex.h>
-#include <ace/Condition_Thread_Mutex.h>
-
-#include "DelayExecutor.h"
+#include "Define.h"
+#include <mutex>
+#include <thread>
+#include <condition_variable>
+#include "ProducerConsumerQueue.h"
+class MapUpdateRequest;
class Map;
class MapUpdater
@@ -17,24 +37,30 @@ class MapUpdater
friend class MapUpdateRequest;
- int schedule_update(Map& map, ACE_UINT32 diff);
+ void schedule_update(Map& map, uint32 diff);
- int wait();
+ void wait();
- int activate(size_t num_threads);
+ void activate(size_t num_threads);
- int deactivate();
+ void deactivate();
bool activated();
private:
- DelayExecutor m_executor;
- ACE_Thread_Mutex m_mutex;
- ACE_Condition_Thread_Mutex m_condition;
+ ProducerConsumerQueue<MapUpdateRequest*> _queue;
+
+ std::vector<std::thread> _workerThreads;
+ std::atomic<bool> _cancelationToken;
+
+ std::mutex _lock;
+ std::condition_variable _condition;
size_t pending_requests;
void update_finished();
+
+ void WorkerThread();
};
#endif //_MAP_UPDATER_H_INCLUDED
diff --git a/src/server/game/Maps/TransportMgr.h b/src/server/game/Maps/TransportMgr.h
index 759b761c3f1..e023c8be4ee 100644
--- a/src/server/game/Maps/TransportMgr.h
+++ b/src/server/game/Maps/TransportMgr.h
@@ -18,7 +18,6 @@
#ifndef TRANSPORTMGR_H
#define TRANSPORTMGR_H
-#include <ace/Singleton.h>
#include <G3D/Quat.h>
#include "Spline.h"
#include "DBCStores.h"
@@ -96,10 +95,15 @@ typedef std::map<uint32, TransportAnimation> TransportAnimationContainer;
class TransportMgr
{
- friend class ACE_Singleton<TransportMgr, ACE_Thread_Mutex>;
friend void LoadDBCStores(std::string const&);
public:
+ static TransportMgr* instance()
+ {
+ static TransportMgr* instance = new TransportMgr();
+ return instance;
+ }
+
void Unload();
void LoadTransportTemplates();
@@ -155,6 +159,6 @@ class TransportMgr
TransportAnimationContainer _transportAnimations;
};
-#define sTransportMgr ACE_Singleton<TransportMgr, ACE_Thread_Mutex>::instance()
+#define sTransportMgr TransportMgr::instance()
#endif // TRANSPORTMGR_H
diff --git a/src/server/game/Movement/MovementGenerator.h b/src/server/game/Movement/MovementGenerator.h
index f545f9fd314..12116b5505d 100755
--- a/src/server/game/Movement/MovementGenerator.h
+++ b/src/server/game/Movement/MovementGenerator.h
@@ -20,7 +20,6 @@
#define TRINITY_MOVEMENTGENERATOR_H
#include "Define.h"
-#include <ace/Singleton.h>
#include "ObjectRegistry.h"
#include "FactoryHolder.h"
#include "Common.h"
@@ -92,5 +91,4 @@ struct MovementGeneratorFactory : public SelectableMovement
typedef FactoryHolder<MovementGenerator, MovementGeneratorType> MovementGeneratorCreator;
typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRegistry MovementGeneratorRegistry;
-typedef FactoryHolder<MovementGenerator, MovementGeneratorType>::FactoryHolderRepository MovementGeneratorRepository;
#endif
diff --git a/src/server/game/Movement/PathGenerator.cpp b/src/server/game/Movement/PathGenerator.cpp
index d9b9b88d3dd..6acee7f7a9c 100644
--- a/src/server/game/Movement/PathGenerator.cpp
+++ b/src/server/game/Movement/PathGenerator.cpp
@@ -795,8 +795,8 @@ dtStatus PathGenerator::FindSmoothPath(float const* startPos, float const* endPo
if (!GetSteerTarget(iterPos, targetPos, SMOOTH_PATH_SLOP, polys, npolys, steerPos, steerPosFlag, steerPosRef))
break;
- bool endOfPath = (steerPosFlag & DT_STRAIGHTPATH_END);
- bool offMeshConnection = (steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION);
+ bool endOfPath = (steerPosFlag & DT_STRAIGHTPATH_END) != 0;
+ bool offMeshConnection = (steerPosFlag & DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0;
// Find movement delta.
float delta[VERTEX_SIZE];
diff --git a/src/server/game/Movement/Spline/MoveSplineFlag.h b/src/server/game/Movement/Spline/MoveSplineFlag.h
index f86ce6431ed..f9151c53fc2 100644
--- a/src/server/game/Movement/Spline/MoveSplineFlag.h
+++ b/src/server/game/Movement/Spline/MoveSplineFlag.h
@@ -86,9 +86,9 @@ namespace Movement
// Constant interface
- bool isSmooth() const { return raw() & Catmullrom; }
+ bool isSmooth() const { return (raw() & Catmullrom) != 0; }
bool isLinear() const { return !isSmooth(); }
- bool isFacing() const { return raw() & Mask_Final_Facing; }
+ bool isFacing() const { return (raw() & Mask_Final_Facing) != 0; }
uint8 getAnimationId() const { return animId; }
bool hasAllFlags(uint32 f) const { return (raw() & f) == f; }
diff --git a/src/server/game/Movement/Waypoints/WaypointManager.h b/src/server/game/Movement/Waypoints/WaypointManager.h
index bafc6322e71..b12396293aa 100644
--- a/src/server/game/Movement/Waypoints/WaypointManager.h
+++ b/src/server/game/Movement/Waypoints/WaypointManager.h
@@ -19,8 +19,6 @@
#ifndef TRINITY_WAYPOINTMANAGER_H
#define TRINITY_WAYPOINTMANAGER_H
-#include <ace/Singleton.h>
-#include <ace/Null_Mutex.h>
#include <vector>
struct WaypointData
@@ -38,9 +36,13 @@ typedef std::unordered_map<uint32, WaypointPath> WaypointPathContainer;
class WaypointMgr
{
- friend class ACE_Singleton<WaypointMgr, ACE_Null_Mutex>;
-
public:
+ static WaypointMgr* instance()
+ {
+ static WaypointMgr* instance = new WaypointMgr();
+ return instance;
+ }
+
// Attempts to reload a single path from database
void ReloadPath(uint32 id);
@@ -58,13 +60,12 @@ class WaypointMgr
}
private:
- // Only allow instantiation from ACE_Singleton
WaypointMgr();
~WaypointMgr();
WaypointPathContainer _waypointStore;
};
-#define sWaypointMgr ACE_Singleton<WaypointMgr, ACE_Null_Mutex>::instance()
+#define sWaypointMgr WaypointMgr::instance()
#endif
diff --git a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h
index 54ea2f3ba1d..ab1908e273d 100644
--- a/src/server/game/OutdoorPvP/OutdoorPvPMgr.h
+++ b/src/server/game/OutdoorPvP/OutdoorPvPMgr.h
@@ -21,7 +21,6 @@
#define OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL 1000
#include "OutdoorPvP.h"
-#include <ace/Singleton.h>
class Player;
class GameObject;
@@ -38,13 +37,17 @@ struct OutdoorPvPData
// class to handle player enter / leave / areatrigger / GO use events
class OutdoorPvPMgr
{
- friend class ACE_Singleton<OutdoorPvPMgr, ACE_Null_Mutex>;
-
private:
OutdoorPvPMgr();
~OutdoorPvPMgr() { };
public:
+ static OutdoorPvPMgr* instance()
+ {
+ static OutdoorPvPMgr* instance = new OutdoorPvPMgr();
+ return instance;
+ }
+
// create outdoor pvp events
void InitOutdoorPvP();
@@ -101,6 +104,6 @@ class OutdoorPvPMgr
uint32 m_UpdateTimer;
};
-#define sOutdoorPvPMgr ACE_Singleton<OutdoorPvPMgr, ACE_Null_Mutex>::instance()
+#define sOutdoorPvPMgr OutdoorPvPMgr::instance()
#endif /*OUTDOOR_PVP_MGR_H_*/
diff --git a/src/server/game/Pools/PoolMgr.h b/src/server/game/Pools/PoolMgr.h
index 2bc404b3a36..0a3f52b55f6 100644
--- a/src/server/game/Pools/PoolMgr.h
+++ b/src/server/game/Pools/PoolMgr.h
@@ -20,7 +20,6 @@
#define TRINITY_POOLHANDLER_H
#include "Define.h"
-#include <ace/Singleton.h>
#include "Creature.h"
#include "GameObject.h"
#include "QuestDef.h"
@@ -104,13 +103,17 @@ typedef std::pair<PooledQuestRelation::iterator, PooledQuestRelation::iterator>
class PoolMgr
{
- friend class ACE_Singleton<PoolMgr, ACE_Null_Mutex>;
-
private:
PoolMgr();
~PoolMgr() { };
public:
+ static PoolMgr* instance()
+ {
+ static PoolMgr* instance = new PoolMgr();
+ return instance;
+ }
+
void LoadFromDB();
void LoadQuestPools();
void SaveQuestsToDB();
@@ -164,7 +167,7 @@ class PoolMgr
ActivePoolData mSpawnedData;
};
-#define sPoolMgr ACE_Singleton<PoolMgr, ACE_Null_Mutex>::instance()
+#define sPoolMgr PoolMgr::instance()
// Method that tell if the creature is part of a pool and return the pool id if yes
template<>
diff --git a/src/server/game/PrecompiledHeaders/gamePCH.h b/src/server/game/PrecompiledHeaders/gamePCH.h
index 68f628430c4..c7c6ca5d2d6 100644
--- a/src/server/game/PrecompiledHeaders/gamePCH.h
+++ b/src/server/game/PrecompiledHeaders/gamePCH.h
@@ -1,9 +1,6 @@
//add here most rarely modified headers to speed up debug build compilation
-#include "WorldSocket.h" // must be first to make ACE happy with ACE includes in it
-
#include "Common.h"
-
#include "MapManager.h"
#include "Log.h"
#include "ObjectAccessor.h"
diff --git a/src/server/game/Quests/QuestDef.cpp b/src/server/game/Quests/QuestDef.cpp
index 5f811714f3a..7c089eee07b 100644
--- a/src/server/game/Quests/QuestDef.cpp
+++ b/src/server/game/Quests/QuestDef.cpp
@@ -321,12 +321,12 @@ uint32 Quest::GetRewMoneyMaxLevel() const
bool Quest::IsAutoAccept() const
{
- return sWorld->getBoolConfig(CONFIG_QUEST_IGNORE_AUTO_ACCEPT) ? false : (Flags & QUEST_FLAGS_AUTO_ACCEPT);
+ return !sWorld->getBoolConfig(CONFIG_QUEST_IGNORE_AUTO_ACCEPT) && HasFlag(QUEST_FLAGS_AUTO_ACCEPT);
}
bool Quest::IsAutoComplete() const
{
- return sWorld->getBoolConfig(CONFIG_QUEST_IGNORE_AUTO_COMPLETE) || (Method == 0);
+ return !sWorld->getBoolConfig(CONFIG_QUEST_IGNORE_AUTO_COMPLETE) && Method == 0;
}
bool Quest::IsRaidQuest(Difficulty difficulty) const
diff --git a/src/server/game/Quests/QuestDef.h b/src/server/game/Quests/QuestDef.h
index 9f84795f488..79b7a4b428e 100644
--- a/src/server/game/Quests/QuestDef.h
+++ b/src/server/game/Quests/QuestDef.h
@@ -288,14 +288,14 @@ class Quest
uint32 GetRewardReputationMask() const { return RewardReputationMask; }
uint32 GetQuestGiverPortrait() const { return QuestGiverPortrait; }
uint32 GetQuestTurnInPortrait() const { return QuestTurnInPortrait; }
- bool IsDaily() const { return Flags & QUEST_FLAGS_DAILY; }
- bool IsWeekly() const { return Flags & QUEST_FLAGS_WEEKLY; }
- bool IsMonthly() const { return SpecialFlags & QUEST_SPECIAL_FLAGS_MONTHLY; }
+ bool IsDaily() const { return (Flags & QUEST_FLAGS_DAILY) != 0; }
+ bool IsWeekly() const { return (Flags & QUEST_FLAGS_WEEKLY) != 0; }
+ bool IsMonthly() const { return (SpecialFlags & QUEST_SPECIAL_FLAGS_MONTHLY) != 0; }
bool IsSeasonal() const { return (ZoneOrSort == -QUEST_SORT_SEASONAL || ZoneOrSort == -QUEST_SORT_SPECIAL || ZoneOrSort == -QUEST_SORT_LUNAR_FESTIVAL || ZoneOrSort == -QUEST_SORT_MIDSUMMER || ZoneOrSort == -QUEST_SORT_BREWFEST || ZoneOrSort == -QUEST_SORT_LOVE_IS_IN_THE_AIR || ZoneOrSort == -QUEST_SORT_NOBLEGARDEN) && !IsRepeatable(); }
- bool IsDailyOrWeekly() const { return Flags & (QUEST_FLAGS_DAILY | QUEST_FLAGS_WEEKLY); }
+ bool IsDailyOrWeekly() const { return (Flags & (QUEST_FLAGS_DAILY | QUEST_FLAGS_WEEKLY)) != 0; }
bool IsRaidQuest(Difficulty difficulty) const;
bool IsAllowedInRaid(Difficulty difficulty) const;
- bool IsDFQuest() const { return SpecialFlags & QUEST_SPECIAL_FLAGS_DF_QUEST; }
+ bool IsDFQuest() const { return (SpecialFlags & QUEST_SPECIAL_FLAGS_DF_QUEST) != 0; }
uint32 CalculateHonorGain(uint8 level) const;
// multiple values
diff --git a/src/server/game/Reputation/ReputationMgr.cpp b/src/server/game/Reputation/ReputationMgr.cpp
index df6497f2513..b136e6893cd 100644
--- a/src/server/game/Reputation/ReputationMgr.cpp
+++ b/src/server/game/Reputation/ReputationMgr.cpp
@@ -60,7 +60,7 @@ bool ReputationMgr::IsAtWar(FactionEntry const* factionEntry) const
return false;
if (FactionState const* factionState = GetState(factionEntry))
- return (factionState->Flags & FACTION_FLAG_AT_WAR);
+ return (factionState->Flags & FACTION_FLAG_AT_WAR) != 0;
return false;
}
diff --git a/src/server/game/Scripting/MapScripts.cpp b/src/server/game/Scripting/MapScripts.cpp
index 58ad725d570..7c82b806cf8 100644
--- a/src/server/game/Scripting/MapScripts.cpp
+++ b/src/server/game/Scripting/MapScripts.cpp
@@ -806,7 +806,7 @@ void Map::ScriptsProcess()
if (!sWaypointMgr->GetPath(step.script->LoadPath.PathID))
TC_LOG_ERROR("scripts", "%s source object has an invalid path (%u), skipping.", step.script->GetDebugInfo().c_str(), step.script->LoadPath.PathID);
else
- unit->GetMotionMaster()->MovePath(step.script->LoadPath.PathID, step.script->LoadPath.IsRepeatable);
+ unit->GetMotionMaster()->MovePath(step.script->LoadPath.PathID, step.script->LoadPath.IsRepeatable != 0);
}
break;
diff --git a/src/server/game/Scripting/ScriptMgr.cpp b/src/server/game/Scripting/ScriptMgr.cpp
index ee0cb11983e..e437875d57a 100644
--- a/src/server/game/Scripting/ScriptMgr.cpp
+++ b/src/server/game/Scripting/ScriptMgr.cpp
@@ -175,8 +175,10 @@ struct TSpellSummary
uint8 Effects; // set of enum SelectEffect
} *SpellSummary;
-ScriptMgr::ScriptMgr()
- : _scriptCount(0), _scheduledScripts(0) { }
+ScriptMgr::ScriptMgr() : _scriptCount(0)
+{
+ _scheduledScripts = 0;
+}
ScriptMgr::~ScriptMgr() { }
@@ -398,35 +400,35 @@ void ScriptMgr::OnNetworkStop()
FOREACH_SCRIPT(ServerScript)->OnNetworkStop();
}
-void ScriptMgr::OnSocketOpen(WorldSocket* socket)
+void ScriptMgr::OnSocketOpen(std::shared_ptr<WorldSocket> socket)
{
ASSERT(socket);
FOREACH_SCRIPT(ServerScript)->OnSocketOpen(socket);
}
-void ScriptMgr::OnSocketClose(WorldSocket* socket, bool wasNew)
+void ScriptMgr::OnSocketClose(std::shared_ptr<WorldSocket> socket, bool wasNew)
{
ASSERT(socket);
FOREACH_SCRIPT(ServerScript)->OnSocketClose(socket, wasNew);
}
-void ScriptMgr::OnPacketReceive(WorldSocket* socket, WorldPacket packet)
+void ScriptMgr::OnPacketReceive(std::shared_ptr<WorldSocket> socket, WorldPacket packet)
{
ASSERT(socket);
FOREACH_SCRIPT(ServerScript)->OnPacketReceive(socket, packet);
}
-void ScriptMgr::OnPacketSend(WorldSocket* socket, WorldPacket packet)
+void ScriptMgr::OnPacketSend(std::shared_ptr<WorldSocket> socket, WorldPacket packet)
{
ASSERT(socket);
FOREACH_SCRIPT(ServerScript)->OnPacketSend(socket, packet);
}
-void ScriptMgr::OnUnknownPacketReceive(WorldSocket* socket, WorldPacket packet)
+void ScriptMgr::OnUnknownPacketReceive(std::shared_ptr<WorldSocket> socket, WorldPacket packet)
{
ASSERT(socket);
diff --git a/src/server/game/Scripting/ScriptMgr.h b/src/server/game/Scripting/ScriptMgr.h
index 00060bea90c..fc06dca6355 100644
--- a/src/server/game/Scripting/ScriptMgr.h
+++ b/src/server/game/Scripting/ScriptMgr.h
@@ -19,10 +19,8 @@
#ifndef SC_SCRIPTMGR_H
#define SC_SCRIPTMGR_H
+#include <atomic>
#include "Common.h"
-#include <ace/Singleton.h>
-#include <ace/Atomic_Op.h>
-
#include "DBCStores.h"
#include "QuestDef.h"
#include "SharedDefines.h"
@@ -215,30 +213,30 @@ class ServerScript : public ScriptObject
public:
- // Called when reactive socket I/O is started (WorldSocketMgr).
+ // Called when reactive socket I/O is started (WorldTcpSessionMgr).
virtual void OnNetworkStart() { }
// Called when reactive I/O is stopped.
virtual void OnNetworkStop() { }
// Called when a remote socket establishes a connection to the server. Do not store the socket object.
- virtual void OnSocketOpen(WorldSocket* /*socket*/) { }
+ virtual void OnSocketOpen(std::shared_ptr<WorldSocket> /*socket*/) { }
// Called when a socket is closed. Do not store the socket object, and do not rely on the connection
// being open; it is not.
- virtual void OnSocketClose(WorldSocket* /*socket*/, bool /*wasNew*/) { }
+ virtual void OnSocketClose(std::shared_ptr<WorldSocket> /*socket*/, bool /*wasNew*/) { }
// Called when a packet is sent to a client. The packet object is a copy of the original packet, so reading
// and modifying it is safe.
- virtual void OnPacketSend(WorldSocket* /*socket*/, WorldPacket& /*packet*/) { }
+ virtual void OnPacketSend(std::shared_ptr<WorldSocket> /*socket*/, WorldPacket& /*packet*/) { }
// Called when a (valid) packet is received by a client. The packet object is a copy of the original packet, so
// reading and modifying it is safe.
- virtual void OnPacketReceive(WorldSocket* /*socket*/, WorldPacket& /*packet*/) { }
+ virtual void OnPacketReceive(std::shared_ptr<WorldSocket> /*socket*/, WorldPacket& /*packet*/) { }
// Called when an invalid (unknown opcode) packet is received by a client. The packet is a reference to the orignal
// packet; not a copy. This allows you to actually handle unknown packets (for whatever purpose).
- virtual void OnUnknownPacketReceive(WorldSocket* /*socket*/, WorldPacket& /*packet*/) { }
+ virtual void OnUnknownPacketReceive(std::shared_ptr<WorldSocket> /*socket*/, WorldPacket& /*packet*/) { }
};
class WorldScript : public ScriptObject
@@ -868,20 +866,23 @@ class GroupScript : public ScriptObject
};
// Placed here due to ScriptRegistry::AddScript dependency.
-#define sScriptMgr ACE_Singleton<ScriptMgr, ACE_Null_Mutex>::instance()
+#define sScriptMgr ScriptMgr::instance()
// Manages registration, loading, and execution of scripts.
class ScriptMgr
{
- friend class ACE_Singleton<ScriptMgr, ACE_Null_Mutex>;
friend class ScriptObject;
private:
-
ScriptMgr();
virtual ~ScriptMgr();
public: /* Initialization */
+ static ScriptMgr* instance()
+ {
+ static ScriptMgr* instance = new ScriptMgr();
+ return instance;
+ }
void Initialize();
void LoadDatabase();
@@ -906,11 +907,11 @@ class ScriptMgr
void OnNetworkStart();
void OnNetworkStop();
- void OnSocketOpen(WorldSocket* socket);
- void OnSocketClose(WorldSocket* socket, bool wasNew);
- void OnPacketReceive(WorldSocket* socket, WorldPacket packet);
- void OnPacketSend(WorldSocket* socket, WorldPacket packet);
- void OnUnknownPacketReceive(WorldSocket* socket, WorldPacket packet);
+ void OnSocketOpen(std::shared_ptr<WorldSocket> socket);
+ void OnSocketClose(std::shared_ptr<WorldSocket> socket, bool wasNew);
+ void OnPacketReceive(std::shared_ptr<WorldSocket> socket, WorldPacket packet);
+ void OnPacketSend(std::shared_ptr<WorldSocket> socket, WorldPacket packet);
+ void OnUnknownPacketReceive(std::shared_ptr<WorldSocket> socket, WorldPacket packet);
public: /* WorldScript */
@@ -1125,7 +1126,7 @@ class ScriptMgr
uint32 _scriptCount;
//atomic op counter for active scripts amount
- ACE_Atomic_Op<ACE_Thread_Mutex, long> _scheduledScripts;
+ std::atomic_long _scheduledScripts;
};
#endif
diff --git a/src/server/game/Scripting/ScriptSystem.h b/src/server/game/Scripting/ScriptSystem.h
index 11120f3031b..636343838c1 100644
--- a/src/server/game/Scripting/ScriptSystem.h
+++ b/src/server/game/Scripting/ScriptSystem.h
@@ -6,7 +6,6 @@
#define SC_SYSTEM_H
#include "ScriptMgr.h"
-#include <ace/Singleton.h>
#define TEXT_SOURCE_RANGE -1000000 //the amount of entries each text source has available
@@ -48,11 +47,17 @@ typedef std::vector<ScriptPointMove> ScriptPointVector;
class SystemMgr
{
- friend class ACE_Singleton<SystemMgr, ACE_Null_Mutex>;
+ private:
SystemMgr() { }
~SystemMgr() { }
public:
+ static SystemMgr* instance()
+ {
+ static SystemMgr* instance = new SystemMgr();
+ return instance;
+ }
+
typedef std::unordered_map<uint32, ScriptPointVector> PointMoveMap;
//Database
@@ -75,6 +80,6 @@ class SystemMgr
static ScriptPointVector const _empty;
};
-#define sScriptSystemMgr ACE_Singleton<SystemMgr, ACE_Null_Mutex>::instance()
+#define sScriptSystemMgr SystemMgr::instance()
#endif
diff --git a/src/server/game/Server/Protocol/PacketLog.h b/src/server/game/Server/Protocol/PacketLog.h
index 9c60655e627..71d87bf45ae 100644
--- a/src/server/game/Server/Protocol/PacketLog.h
+++ b/src/server/game/Server/Protocol/PacketLog.h
@@ -19,7 +19,6 @@
#define TRINITY_PACKETLOG_H
#include "Common.h"
-#include <ace/Singleton.h>
enum Direction
{
@@ -31,13 +30,17 @@ class WorldPacket;
class PacketLog
{
- friend class ACE_Singleton<PacketLog, ACE_Thread_Mutex>;
-
private:
PacketLog();
~PacketLog();
public:
+ static PacketLog* instance()
+ {
+ static PacketLog* instance = new PacketLog();
+ return instance;
+ }
+
void Initialize();
bool CanLogPacket() const { return (_file != NULL); }
void LogPacket(WorldPacket const& packet, Direction direction);
@@ -46,5 +49,5 @@ class PacketLog
FILE* _file;
};
-#define sPacketLog ACE_Singleton<PacketLog, ACE_Thread_Mutex>::instance()
+#define sPacketLog PacketLog::instance()
#endif
diff --git a/src/server/game/Server/Protocol/ServerPktHeader.h b/src/server/game/Server/Protocol/ServerPktHeader.h
new file mode 100644
index 00000000000..4b0dae9f0f3
--- /dev/null
+++ b/src/server/game/Server/Protocol/ServerPktHeader.h
@@ -0,0 +1,59 @@
+/*
+* Copyright (C) 2008-2014 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 __SERVERPKTHDR_H__
+#define __SERVERPKTHDR_H__
+
+#include "Log.h"
+
+struct ServerPktHeader
+{
+ /**
+ * size is the length of the payload _plus_ the length of the opcode
+ */
+ ServerPktHeader(uint32 size, uint16 cmd) : size(size)
+ {
+ uint8 headerIndex=0;
+ if (isLargePacket())
+ {
+ TC_LOG_DEBUG("network", "initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
+ header[headerIndex++] = 0x80 | (0xFF & (size >> 16));
+ }
+ header[headerIndex++] = 0xFF &(size >> 8);
+ header[headerIndex++] = 0xFF & size;
+
+ header[headerIndex++] = 0xFF & cmd;
+ header[headerIndex++] = 0xFF & (cmd >> 8);
+ }
+
+ uint8 getHeaderLength()
+ {
+ // cmd = 2 bytes, size= 2||3bytes
+ return 2 + (isLargePacket() ? 3 : 2);
+ }
+
+ bool isLargePacket() const
+ {
+ return size > 0x7FFF;
+ }
+
+ const uint32 size;
+ uint8 header[5];
+};
+
+#endif
diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp
index 2ece2942a56..cabb0ef0494 100644
--- a/src/server/game/Server/WorldSession.cpp
+++ b/src/server/game/Server/WorldSession.cpp
@@ -20,7 +20,7 @@
\ingroup u2w
*/
-#include "WorldSocket.h" // must be first to make ACE happy with ACE includes in it
+#include "WorldSocket.h"
#include <zlib.h>
#include "Config.h"
#include "Common.h"
@@ -99,7 +99,7 @@ bool WorldSessionFilter::Process(WorldPacket* packet)
}
/// WorldSession constructor
-WorldSession::WorldSession(uint32 id, uint32 battlenetAccountId, WorldSocket* sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter):
+WorldSession::WorldSession(uint32 id, uint32 battlenetAccountId, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter):
m_muteTime(mute_time),
m_timeOutTime(0),
AntiDOS(this),
@@ -134,8 +134,7 @@ WorldSession::WorldSession(uint32 id, uint32 battlenetAccountId, WorldSocket* so
if (sock)
{
- m_Address = sock->GetRemoteAddress();
- sock->AddReference();
+ m_Address = sock->GetRemoteIpAddress();
ResetTimeOutTime();
LoginDatabase.PExecute("UPDATE account SET online = 1 WHERE id = %u;", GetAccountId()); // One-time query
}
@@ -164,8 +163,7 @@ WorldSession::~WorldSession()
if (m_Socket)
{
m_Socket->CloseSocket();
- m_Socket->RemoveReference();
- m_Socket = NULL;
+ m_Socket = nullptr;
}
delete _warden;
@@ -268,8 +266,7 @@ void WorldSession::SendPacket(WorldPacket const* packet, bool forced /*= false*/
}
#endif // !TRINITY_DEBUG
- if (m_Socket->SendPacket(*packet) == -1)
- m_Socket->CloseSocket();
+ m_Socket->AsyncWrite(*packet);
}
/// Add an incoming packet to the queue
@@ -322,9 +319,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
uint32 processedPackets = 0;
time_t currentTime = time(NULL);
- while (m_Socket && !m_Socket->IsClosed() &&
- !_recvQueue.empty() && _recvQueue.peek(true) != firstDelayedPacket &&
- _recvQueue.next(packet, updater))
+ while (m_Socket && !_recvQueue.empty() && _recvQueue.peek(true) != firstDelayedPacket && _recvQueue.next(packet, updater))
{
if (!AntiDOS.EvaluateOpcode(*packet, currentTime))
KickPlayer();
@@ -433,7 +428,7 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
break;
}
- if (m_Socket && !m_Socket->IsClosed() && _warden)
+ if (m_Socket && m_Socket->IsOpen() && _warden)
_warden->Update();
ProcessQueryCallbacks();
@@ -451,13 +446,12 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
_warden->Update();
///- Cleanup socket pointer if need
- if (m_Socket && m_Socket->IsClosed())
+ if (m_Socket && !m_Socket->IsOpen())
{
expireTime -= expireTime > diff ? diff : expireTime;
if (expireTime < diff || forceExit)
{
- m_Socket->RemoveReference();
- m_Socket = NULL;
+ m_Socket = nullptr;
}
}
@@ -823,7 +817,7 @@ void WorldSession::SaveTutorialsData(SQLTransaction &trans)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_HAS_TUTORIALS);
stmt->setUInt32(0, GetAccountId());
- bool hasTutorials = !CharacterDatabase.Query(stmt).null();
+ bool hasTutorials = bool(CharacterDatabase.Query(stmt));
// Modify data in DB
stmt = CharacterDatabase.GetPreparedStatement(hasTutorials ? CHAR_UPD_TUTORIALS : CHAR_INS_TUTORIALS);
for (uint8 i = 0; i < MAX_ACCOUNT_TUTORIAL_VALUES; ++i)
@@ -1046,27 +1040,23 @@ void WorldSession::ProcessQueryCallbacks()
PreparedQueryResult result;
//! HandleCharEnumOpcode
- if (_charEnumCallback.ready())
+ if (_charEnumCallback.valid() && _charEnumCallback.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
- _charEnumCallback.get(result);
+ result = _charEnumCallback.get();
HandleCharEnum(result);
- _charEnumCallback.cancel();
}
if (_charCreateCallback.IsReady())
{
_charCreateCallback.GetResult(result);
HandleCharCreateCallback(result, _charCreateCallback.GetParam());
- // Don't call FreeResult() here, the callback handler will do that depending on the events in the callback chain
}
//! HandlePlayerLoginOpcode
- if (_charLoginCallback.ready())
+ if (_charLoginCallback.valid() && _charLoginCallback.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
- SQLQueryHolder* param;
- _charLoginCallback.get(param);
+ SQLQueryHolder* param = _charLoginCallback.get();
HandlePlayerLogin((LoginQueryHolder*)param);
- _charLoginCallback.cancel();
}
//! HandleAddFriendOpcode
@@ -1088,11 +1078,10 @@ void WorldSession::ProcessQueryCallbacks()
}
//- HandleCharAddIgnoreOpcode
- if (_addIgnoreCallback.ready())
+ if (_addIgnoreCallback.valid() && _addIgnoreCallback.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
- _addIgnoreCallback.get(result);
+ result = _addIgnoreCallback.get();
HandleAddIgnoreOpcodeCallBack(result);
- _addIgnoreCallback.cancel();
}
//- SendStabledPet
@@ -1105,11 +1094,10 @@ void WorldSession::ProcessQueryCallbacks()
}
//- HandleStablePet
- if (_stablePetCallback.ready())
+ if (_stablePetCallback.valid() && _stablePetCallback.wait_for(std::chrono::seconds(0)) == std::future_status::ready)
{
- _stablePetCallback.get(result);
+ result = _stablePetCallback.get();
HandleStablePetCallback(result);
- _stablePetCallback.cancel();
}
//- HandleUnstablePet
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index 96f7d3d2535..96a66bf2421 100644
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -215,7 +215,7 @@ struct PacketCounter
class WorldSession
{
public:
- WorldSession(uint32 id, uint32 battlenetAccountId, WorldSocket* sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter);
+ WorldSession(uint32 id, uint32 battlenetAccountId, std::shared_ptr<WorldSocket> sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale, uint32 recruiter, bool isARecruiter);
~WorldSession();
bool PlayerLoading() const { return m_playerLoading; }
@@ -379,10 +379,11 @@ class WorldSession
void SetLatency(uint32 latency) { m_latency = latency; }
void ResetClientTimeDelay() { m_clientTimeDelay = 0; }
- ACE_Atomic_Op<ACE_Thread_Mutex, time_t> m_timeOutTime;
+ std::atomic<time_t> m_timeOutTime;
+
void UpdateTimeOutTime(uint32 diff)
{
- if (time_t(diff) > m_timeOutTime.value())
+ if (time_t(diff) > m_timeOutTime)
m_timeOutTime = 0;
else
m_timeOutTime -= diff;
@@ -1038,7 +1039,7 @@ class WorldSession
uint32 m_GUIDLow; // set logined or recently logout player (while m_playerRecentlyLogout set)
Player* _player;
- WorldSocket* m_Socket;
+ std::shared_ptr<WorldSocket> m_Socket;
std::string m_Address; // Current Remote Address
// std::string m_LAddress; // Last Attempted Remote Adress - we can not set attempted ip for a non-existing session!
@@ -1060,8 +1061,8 @@ class WorldSession
bool m_playerSave;
LocaleConstant m_sessionDbcLocale;
LocaleConstant m_sessionDbLocaleIndex;
- uint32 m_latency;
- uint32 m_clientTimeDelay;
+ std::atomic<uint32> m_latency;
+ std::atomic<uint32> m_clientTimeDelay;
AccountData m_accountData[NUM_ACCOUNT_DATA_TYPES];
uint32 m_Tutorials[MAX_ACCOUNT_TUTORIAL_VALUES];
bool m_TutorialsChanged;
@@ -1070,7 +1071,7 @@ class WorldSession
bool _filterAddonMessages;
uint32 recruiterId;
bool isRecruiter;
- ACE_Based::LockedQueue<WorldPacket*, ACE_Thread_Mutex> _recvQueue;
+ LockedQueue<WorldPacket*> _recvQueue;
z_stream_s* _compressionStream;
rbac::RBACData* _RBACData;
uint32 expireTime;
diff --git a/src/server/game/Server/WorldSocket.cpp b/src/server/game/Server/WorldSocket.cpp
index d06d680aea5..2aa24e10d9d 100644
--- a/src/server/game/Server/WorldSocket.cpp
+++ b/src/server/game/Server/WorldSocket.cpp
@@ -16,782 +16,205 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <ace/Message_Block.h>
-#include <ace/OS_NS_string.h>
-#include <ace/OS_NS_unistd.h>
-#include <ace/os_include/arpa/os_inet.h>
-#include <ace/os_include/netinet/os_tcp.h>
-#include <ace/os_include/sys/os_types.h>
-#include <ace/os_include/sys/os_socket.h>
-#include <ace/OS_NS_string.h>
-#include <ace/Reactor.h>
-#include <ace/Auto_Ptr.h>
-
+#include <boost/asio/write.hpp>
+#include <boost/asio/read_until.hpp>
+#include <memory>
#include "WorldSocket.h"
-#include "Common.h"
-#include "Player.h"
-#include "Util.h"
-#include "World.h"
-#include "WorldPacket.h"
-#include "SharedDefines.h"
-#include "ByteBuffer.h"
-#include "Opcodes.h"
-#include "DatabaseEnv.h"
+#include "ServerPktHeader.h"
#include "BigNumber.h"
-#include "SHA1.h"
-#include "WorldSession.h"
-#include "WorldSocketMgr.h"
-#include "Log.h"
-#include "PacketLog.h"
+#include "Opcodes.h"
#include "ScriptMgr.h"
-#include "AccountMgr.h"
+#include "SHA1.h"
#include "BattlenetAccountMgr.h"
-#if defined(__GNUC__)
-#pragma pack(1)
-#else
-#pragma pack(push, 1)
-#endif
-
-struct ServerPktHeader
-{
- /**
- * size is the length of the payload _plus_ the length of the opcode
- */
- ServerPktHeader(uint32 size, uint16 cmd) : size(size)
- {
- uint8 headerIndex=0;
- if (isLargePacket())
- {
- TC_LOG_DEBUG("network", "initializing large server to client packet. Size: %u, cmd: %u", size, cmd);
- header[headerIndex++] = 0x80 | (0xFF & (size >> 16));
- }
- header[headerIndex++] = 0xFF &(size >> 8);
- header[headerIndex++] = 0xFF & size;
-
- header[headerIndex++] = 0xFF & cmd;
- header[headerIndex++] = 0xFF & (cmd >> 8);
- }
-
- uint8 getHeaderLength()
- {
- // cmd = 2 bytes, size= 2||3bytes
- return 2 + (isLargePacket() ? 3 : 2);
- }
-
- bool isLargePacket() const
- {
- return size > 0x7FFF;
- }
-
- const uint32 size;
- uint8 header[5];
-};
-
-struct ClientPktHeader
-{
- uint16 size;
- uint32 cmd;
-};
-
-#if defined(__GNUC__)
-#pragma pack()
-#else
-#pragma pack(pop)
-#endif
-
-WorldSocket::WorldSocket (void): WorldHandler(),
-m_LastPingTime(ACE_Time_Value::zero), m_OverSpeedPings(0), m_Session(0),
-m_RecvWPct(0), m_RecvPct(), m_Header(sizeof (ClientPktHeader)),
-m_OutBuffer(0), m_OutBufferSize(65536), m_OutActive(false),
-m_Seed(static_cast<uint32> (rand32()))
-{
- reference_counting_policy().value (ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
-
- msg_queue()->high_water_mark(8 * 1024 * 1024);
- msg_queue()->low_water_mark(8 * 1024 * 1024);
-}
-
-WorldSocket::~WorldSocket (void)
-{
- delete m_RecvWPct;
-
- if (m_OutBuffer)
- m_OutBuffer->release();
-
- closing_ = true;
-
- peer().close();
-}
-
-bool WorldSocket::IsClosed (void) const
-{
- return closing_;
-}
-
-void WorldSocket::CloseSocket (void)
-{
- {
- ACE_GUARD (LockType, Guard, m_OutBufferLock);
-
- if (closing_)
- return;
-
- closing_ = true;
- peer().close_writer();
- }
-
- {
- ACE_GUARD (LockType, Guard, m_SessionLock);
-
- m_Session = NULL;
- }
-}
-
-const std::string& WorldSocket::GetRemoteAddress (void) const
-{
- return m_Address;
-}
-
-int WorldSocket::SendPacket(WorldPacket const& pct)
-{
- ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
-
- if (closing_)
- return -1;
-
- // Dump outgoing packet
- if (sPacketLog->CanLogPacket())
- sPacketLog->LogPacket(pct, SERVER_TO_CLIENT);
-
- WorldPacket const* pkt = &pct;
-
- // Empty buffer used in case packet should be compressed
- WorldPacket buff;
- if (m_Session && pkt->size() > 0x400)
- {
- buff.Compress(m_Session->GetCompressionStream(), pkt);
- pkt = &buff;
- }
-
- if (m_Session)
- TC_LOG_TRACE("network.opcode", "S->C: %s %s", m_Session->GetPlayerInfo().c_str(), GetOpcodeNameForLogging(pkt->GetOpcode()).c_str());
+using boost::asio::ip::tcp;
+using boost::asio::streambuf;
- sScriptMgr->OnPacketSend(this, *pkt);
-
- ServerPktHeader header(pkt->size()+2, pkt->GetOpcode());
- m_Crypt.EncryptSend ((uint8*)header.header, header.getHeaderLength());
-
- if (m_OutBuffer->space() >= pkt->size() + header.getHeaderLength() && msg_queue()->is_empty())
- {
- // Put the packet on the buffer.
- if (m_OutBuffer->copy((char*) header.header, header.getHeaderLength()) == -1)
- ACE_ASSERT (false);
-
- if (!pkt->empty())
- if (m_OutBuffer->copy((char*) pkt->contents(), pkt->size()) == -1)
- ACE_ASSERT (false);
- }
- else
- {
- // Enqueue the packet.
- ACE_Message_Block* mb;
-
- ACE_NEW_RETURN(mb, ACE_Message_Block(pkt->size() + header.getHeaderLength()), -1);
-
- mb->copy((char*) header.header, header.getHeaderLength());
-
- if (!pkt->empty())
- mb->copy((const char*)pkt->contents(), pkt->size());
-
- if (msg_queue()->enqueue_tail(mb, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
- {
- TC_LOG_ERROR("network", "WorldSocket::SendPacket enqueue_tail failed");
- mb->release();
- return -1;
- }
- }
-
- return 0;
-}
-
-long WorldSocket::AddReference (void)
+WorldSocket::WorldSocket(tcp::socket&& socket)
+ : _socket(std::move(socket)), _authSeed(static_cast<uint32>(rand32())), _OverSpeedPings(0), _worldSession(nullptr)
{
- return static_cast<long> (add_reference());
}
-long WorldSocket::RemoveReference (void)
+void WorldSocket::Start()
{
- return static_cast<long> (remove_reference());
-}
-
-int WorldSocket::open (void *a)
-{
- ACE_UNUSED_ARG (a);
-
- // Prevent double call to this func.
- if (m_OutBuffer)
- return -1;
-
- // This will also prevent the socket from being Updated
- // while we are initializing it.
- m_OutActive = true;
-
- // Hook for the manager.
- if (sWorldSocketMgr->OnSocketOpen(this) == -1)
- return -1;
-
- // Allocate the buffer.
- ACE_NEW_RETURN (m_OutBuffer, ACE_Message_Block (m_OutBufferSize), -1);
-
- // Store peer address.
- ACE_INET_Addr remote_addr;
-
- if (peer().get_remote_addr(remote_addr) == -1)
- {
- TC_LOG_ERROR("network", "WorldSocket::open: peer().get_remote_addr errno = %s", ACE_OS::strerror (errno));
- return -1;
- }
-
- m_Address = remote_addr.get_host_addr();
+ AsyncReadHeader();
// not an opcode. this packet sends raw string WORLD OF WARCRAFT CONNECTION - SERVER TO CLIENT"
- // because of our implementation, bytes "WO" become the opcode
+ // because of our implementation of WorldPacket sending, bytes "WO" become the opcode
WorldPacket packet(MSG_VERIFY_CONNECTIVITY);
packet << "RLD OF WARCRAFT CONNECTION - SERVER TO CLIENT";
-
- if (SendPacket(packet) == -1)
- return -1;
-
- // Register with ACE Reactor
- if (reactor()->register_handler(this, ACE_Event_Handler::READ_MASK | ACE_Event_Handler::WRITE_MASK) == -1)
- {
- TC_LOG_ERROR("network", "WorldSocket::open: unable to register client handler errno = %s", ACE_OS::strerror (errno));
- return -1;
- }
-
- // reactor takes care of the socket from now on
- remove_reference();
-
- return 0;
+ AsyncWrite(packet);
}
-int WorldSocket::close(u_long)
+void WorldSocket::HandleSendAuthSession()
{
- shutdown();
-
- closing_ = true;
+ WorldPacket packet(SMSG_AUTH_CHALLENGE, 37);
+ BigNumber seed1;
+ seed1.SetRand(16 * 8);
+ packet.append(seed1.AsByteArray(16).get(), 16); // new encryption seeds
- remove_reference();
+ BigNumber seed2;
+ seed2.SetRand(16 * 8);
+ packet.append(seed2.AsByteArray(16).get(), 16); // new encryption seeds
- return 0;
+ packet << uint32(_authSeed);
+ packet << uint8(1);
+ AsyncWrite(packet);
}
-int WorldSocket::handle_input(ACE_HANDLE)
+void WorldSocket::AsyncReadHeader()
{
- if (closing_)
- return -1;
-
- switch (handle_input_missing_data())
+ auto self(shared_from_this());
+ _socket.async_read_some(boost::asio::buffer(_readBuffer, sizeof(ClientPktHeader)), [this, self](boost::system::error_code error, size_t transferedBytes)
{
- case -1 :
+ if (!error && transferedBytes == sizeof(ClientPktHeader))
{
- if ((errno == EWOULDBLOCK) ||
- (errno == EAGAIN))
- {
- return Update(); // interesting line, isn't it ?
- }
+ ClientPktHeader* header = (ClientPktHeader*)&_readBuffer;
- TC_LOG_DEBUG("network", "WorldSocket::handle_input: Peer error closing connection errno = %s", ACE_OS::strerror (errno));
+ if (_worldSession)
+ _authCrypt.DecryptRecv((uint8*)header, sizeof(ClientPktHeader));
- errno = ECONNRESET;
- return -1;
- }
- case 0:
- {
- TC_LOG_DEBUG("network", "WorldSocket::handle_input: Peer has closed connection");
+ EndianConvertReverse(header->size);
+ EndianConvert(header->cmd);
- errno = ECONNRESET;
- return -1;
+ AsyncReadData(header->size - sizeof(header->cmd));
}
- case 1:
- return 1;
- default:
- return Update(); // another interesting line ;)
- }
-
- ACE_NOTREACHED(return -1);
-}
-
-int WorldSocket::handle_output(ACE_HANDLE)
-{
- ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
-
- if (closing_)
- return -1;
-
- size_t send_len = m_OutBuffer->length();
-
- if (send_len == 0)
- return handle_output_queue(Guard);
-
-#ifdef MSG_NOSIGNAL
- ssize_t n = peer().send (m_OutBuffer->rd_ptr(), send_len, MSG_NOSIGNAL);
-#else
- ssize_t n = peer().send (m_OutBuffer->rd_ptr(), send_len);
-#endif // MSG_NOSIGNAL
-
- if (n == 0)
- return -1;
- else if (n == -1)
- {
- if (errno == EWOULDBLOCK || errno == EAGAIN)
- return schedule_wakeup_output (Guard);
-
- return -1;
- }
- else if (n < (ssize_t)send_len) //now n > 0
- {
- m_OutBuffer->rd_ptr (static_cast<size_t> (n));
-
- // move the data to the base of the buffer
- m_OutBuffer->crunch();
-
- return schedule_wakeup_output (Guard);
- }
- else //now n == send_len
- {
- m_OutBuffer->reset();
-
- return handle_output_queue (Guard);
- }
-
- ACE_NOTREACHED (return 0);
-}
-
-int WorldSocket::handle_output_queue(GuardType& g)
-{
- if (msg_queue()->is_empty())
- return cancel_wakeup_output(g);
-
- ACE_Message_Block* mblk;
-
- if (msg_queue()->dequeue_head(mblk, (ACE_Time_Value*)&ACE_Time_Value::zero) == -1)
- {
- TC_LOG_ERROR("network", "WorldSocket::handle_output_queue dequeue_head");
- return -1;
- }
-
- const size_t send_len = mblk->length();
-
-#ifdef MSG_NOSIGNAL
- ssize_t n = peer().send(mblk->rd_ptr(), send_len, MSG_NOSIGNAL);
-#else
- ssize_t n = peer().send(mblk->rd_ptr(), send_len);
-#endif // MSG_NOSIGNAL
-
- if (n == 0)
- {
- mblk->release();
-
- return -1;
- }
- else if (n == -1)
- {
- if (errno == EWOULDBLOCK || errno == EAGAIN)
- {
- msg_queue()->enqueue_head(mblk, (ACE_Time_Value*) &ACE_Time_Value::zero);
- return schedule_wakeup_output (g);
- }
-
- mblk->release();
- return -1;
- }
- else if (n < (ssize_t)send_len) //now n > 0
- {
- mblk->rd_ptr(static_cast<size_t> (n));
-
- if (msg_queue()->enqueue_head(mblk, (ACE_Time_Value*) &ACE_Time_Value::zero) == -1)
+ else
{
- TC_LOG_ERROR("network", "WorldSocket::handle_output_queue enqueue_head");
- mblk->release();
- return -1;
+ _socket.close();
}
-
- return schedule_wakeup_output (g);
- }
- else //now n == send_len
- {
- mblk->release();
-
- return msg_queue()->is_empty() ? cancel_wakeup_output(g) : ACE_Event_Handler::WRITE_MASK;
- }
-
- ACE_NOTREACHED(return -1);
-}
-
-int WorldSocket::handle_close(ACE_HANDLE h, ACE_Reactor_Mask)
-{
- // Critical section
- {
- ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, -1);
-
- closing_ = true;
-
- if (h == ACE_INVALID_HANDLE)
- peer().close_writer();
- }
-
- // Critical section
- {
- ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
-
- m_Session = NULL;
- }
-
- reactor()->remove_handler(this, ACE_Event_Handler::DONT_CALL | ACE_Event_Handler::ALL_EVENTS_MASK);
- return 0;
-}
-
-int WorldSocket::Update (void)
-{
- if (closing_)
- return -1;
-
- if (m_OutActive)
- return 0;
-
- {
- ACE_GUARD_RETURN (LockType, Guard, m_OutBufferLock, 0);
- if (m_OutBuffer->length() == 0 && msg_queue()->is_empty())
- return 0;
- }
-
- int ret;
- do
- ret = handle_output(get_handle());
- while (ret > 0);
-
- return ret;
+ });
}
-int WorldSocket::handle_input_header (void)
+void WorldSocket::AsyncReadData(size_t dataSize)
{
- ACE_ASSERT(m_RecvWPct == NULL);
-
- ACE_ASSERT(m_Header.length() == sizeof(ClientPktHeader));
-
- m_Crypt.DecryptRecv ((uint8*)m_Header.rd_ptr(), sizeof(ClientPktHeader));
-
- ClientPktHeader& header = *((ClientPktHeader*)m_Header.rd_ptr());
-
- EndianConvertReverse(header.size);
- EndianConvert(header.cmd);
-
- if ((header.size < 4) || (header.size > 10240) || (header.cmd > 0xFFFF && (header.cmd >> 16) != 0x4C52)) // LR (from MSG_VERIFY_CONNECTIVITY)
+ auto self(shared_from_this());
+ _socket.async_read_some(boost::asio::buffer(&_readBuffer[sizeof(ClientPktHeader)], dataSize), [this, dataSize, self](boost::system::error_code error, size_t transferedBytes)
{
- Player* _player = m_Session ? m_Session->GetPlayer() : NULL;
- TC_LOG_ERROR("network", "WorldSocket::handle_input_header(): client (account: %u, char [GUID: %u, name: %s]) sent malformed packet (size: %d, cmd: %d)",
- m_Session ? m_Session->GetAccountId() : 0,
- _player ? _player->GetGUIDLow() : 0,
- _player ? _player->GetName().c_str() : "<none>",
- header.size, header.cmd);
-
- errno = EINVAL;
- return -1;
- }
-
- header.size -= 4;
-
- ACE_NEW_RETURN(m_RecvWPct, WorldPacket (PacketFilter::DropHighBytes(Opcodes(header.cmd)), header.size), -1);
-
- if (header.size > 0)
- {
- m_RecvWPct->resize(header.size);
- m_RecvPct.base ((char*) m_RecvWPct->contents(), m_RecvWPct->size());
- }
- else
- {
- ACE_ASSERT(m_RecvPct.space() == 0);
- }
-
- return 0;
-}
-
-int WorldSocket::handle_input_payload (void)
-{
- // set errno properly here on error !!!
- // now have a header and payload
-
- ACE_ASSERT (m_RecvPct.space() == 0);
- ACE_ASSERT (m_Header.space() == 0);
- ACE_ASSERT (m_RecvWPct != NULL);
-
- const int ret = ProcessIncoming (m_RecvWPct);
-
- m_RecvPct.base (NULL, 0);
- m_RecvPct.reset();
- m_RecvWPct = NULL;
-
- m_Header.reset();
-
- if (ret == -1)
- errno = EINVAL;
-
- return ret;
-}
-
-int WorldSocket::handle_input_missing_data (void)
-{
- char buf [4096];
-
- ACE_Data_Block db (sizeof (buf),
- ACE_Message_Block::MB_DATA,
- buf,
- 0,
- 0,
- ACE_Message_Block::DONT_DELETE,
- 0);
-
- ACE_Message_Block message_block(&db,
- ACE_Message_Block::DONT_DELETE,
- 0);
-
- const size_t recv_size = message_block.space();
+ if (!error && transferedBytes == dataSize)
+ {
+ ClientPktHeader* header = (ClientPktHeader*)&_readBuffer;
- const ssize_t n = peer().recv (message_block.wr_ptr(),
- recv_size);
+ header->size -= sizeof(header->cmd);
- if (n <= 0)
- return int(n);
+ Opcodes opcode = PacketFilter::DropHighBytes(Opcodes(header->cmd));
- message_block.wr_ptr (n);
+ std::string opcodeName = GetOpcodeNameForLogging(opcode);
- while (message_block.length() > 0)
- {
- if (m_Header.space() > 0)
- {
- //need to receive the header
- const size_t to_header = (message_block.length() > m_Header.space() ? m_Header.space() : message_block.length());
- m_Header.copy (message_block.rd_ptr(), to_header);
- message_block.rd_ptr (to_header);
+ WorldPacket packet(opcode, header->size);
- if (m_Header.space() > 0)
+ if (header->size > 0)
{
- // Couldn't receive the whole header this time.
- ACE_ASSERT (message_block.length() == 0);
- errno = EWOULDBLOCK;
- return -1;
- }
+ packet.resize(header->size);
- // We just received nice new header
- if (handle_input_header() == -1)
- {
- ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
- return -1;
+ std::memcpy(packet.contents(), &_readBuffer[sizeof(ClientPktHeader)], header->size);
}
- }
- // Its possible on some error situations that this happens
- // for example on closing when epoll receives more chunked data and stuff
- // hope this is not hack, as proper m_RecvWPct is asserted around
- if (!m_RecvWPct)
- {
- TC_LOG_ERROR("network", "Forcing close on input m_RecvWPct = NULL");
- errno = EINVAL;
- return -1;
- }
-
- // We have full read header, now check the data payload
- if (m_RecvPct.space() > 0)
- {
- //need more data in the payload
- const size_t to_data = (message_block.length() > m_RecvPct.space() ? m_RecvPct.space() : message_block.length());
- m_RecvPct.copy (message_block.rd_ptr(), to_data);
- message_block.rd_ptr (to_data);
-
- if (m_RecvPct.space() > 0)
+ switch (opcode)
{
- // Couldn't receive the whole data this time.
- ACE_ASSERT (message_block.length() == 0);
- errno = EWOULDBLOCK;
- return -1;
+ case CMSG_PING:
+ HandlePing(packet);
+ break;
+ case CMSG_AUTH_SESSION:
+ if (_worldSession)
+ {
+ TC_LOG_ERROR("network", "WorldSocket::ProcessIncoming: received duplicate CMSG_AUTH_SESSION from %s", _worldSession->GetPlayerInfo().c_str());
+ break;
+ }
+
+ sScriptMgr->OnPacketReceive(shared_from_this(), packet);
+ HandleAuthSession(packet);
+ break;
+ case CMSG_KEEP_ALIVE:
+ TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
+ sScriptMgr->OnPacketReceive(shared_from_this(), packet);
+ break;
+ case CMSG_LOG_DISCONNECT:
+ packet.rfinish(); // contains uint32 disconnectReason;
+ TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
+ sScriptMgr->OnPacketReceive(shared_from_this(), packet);
+ return;
+ // not an opcode, client sends string "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER" without opcode
+ // first 4 bytes become the opcode (2 dropped)
+ case MSG_VERIFY_CONNECTIVITY:
+ {
+ TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
+ sScriptMgr->OnPacketReceive(shared_from_this(), packet);
+ std::string str;
+ packet >> str;
+ if (str != "D OF WARCRAFT CONNECTION - CLIENT TO SERVER")
+ {
+ _socket.close();
+ break;
+ }
+
+ HandleSendAuthSession();
+ break;
+ }
+ case CMSG_ENABLE_NAGLE:
+ {
+ TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
+ sScriptMgr->OnPacketReceive(shared_from_this(), packet);
+ if (_worldSession)
+ _worldSession->HandleEnableNagleAlgorithm();
+ break;
+ }
+ default:
+ {
+ if (!_worldSession)
+ {
+ TC_LOG_ERROR("network.opcode", "ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
+ break;
+ }
+
+ // Our Idle timer will reset on any non PING opcodes.
+ // Catches people idling on the login screen and any lingering ingame connections.
+ _worldSession->ResetTimeOutTime();
+
+ // Copy the packet to the heap before enqueuing
+ _worldSession->QueuePacket(new WorldPacket(packet));
+ break;
+ }
}
- }
- //just received fresh new payload
- if (handle_input_payload() == -1)
+ AsyncReadHeader();
+ }
+ else
{
- ACE_ASSERT ((errno != EWOULDBLOCK) && (errno != EAGAIN));
- return -1;
+ _socket.close();
}
- }
-
- return size_t(n) == recv_size ? 1 : 2;
-}
-
-int WorldSocket::cancel_wakeup_output(GuardType& g)
-{
- if (!m_OutActive)
- return 0;
-
- m_OutActive = false;
-
- g.release();
-
- if (reactor()->cancel_wakeup
- (this, ACE_Event_Handler::WRITE_MASK) == -1)
- {
- // would be good to store errno from reactor with errno guard
- TC_LOG_ERROR("network", "WorldSocket::cancel_wakeup_output");
- return -1;
- }
-
- return 0;
+ });
}
-int WorldSocket::schedule_wakeup_output(GuardType& g)
+void WorldSocket::AsyncWrite(WorldPacket const& packet)
{
- if (m_OutActive)
- return 0;
+ ServerPktHeader header(packet.size() + 2, packet.GetOpcode());
+ _authCrypt.EncryptSend((uint8*)header.header, header.getHeaderLength());
- m_OutActive = true;
+ auto data = new char[header.getHeaderLength() + packet.size()];
+ std::memcpy(data, (char*)header.header, header.getHeaderLength());
- g.release();
+ if (!packet.empty())
+ std::memcpy(data + header.getHeaderLength(), (char const*)packet.contents(), packet.size());
- if (reactor()->schedule_wakeup
- (this, ACE_Event_Handler::WRITE_MASK) == -1)
+ // Use a shared_ptr here to prevent leaking memory after the async operation has completed
+ std::shared_ptr<char> buffer(data, [=](char* _b)
{
- TC_LOG_ERROR("network", "WorldSocket::schedule_wakeup_output");
- return -1;
- }
-
- return 0;
-}
-
-int WorldSocket::ProcessIncoming(WorldPacket* new_pct)
-{
- ACE_ASSERT (new_pct);
-
- // manage memory ;)
- ACE_Auto_Ptr<WorldPacket> aptr(new_pct);
-
- Opcodes opcode = PacketFilter::DropHighBytes(new_pct->GetOpcode());
-
- if (closing_)
- return -1;
-
- // Dump received packet.
- if (sPacketLog->CanLogPacket())
- sPacketLog->LogPacket(*new_pct, CLIENT_TO_SERVER);
+ delete[] _b; // Ensure that the data is deleted as an array
+ });
- std::string opcodeName = GetOpcodeNameForLogging(opcode);
- if (m_Session)
- TC_LOG_TRACE("network.opcode", "C->S: %s %s", m_Session->GetPlayerInfo().c_str(), opcodeName.c_str());
+ auto self(shared_from_this());
- try
+ boost::asio::async_write(_socket, boost::asio::buffer(buffer.get(), header.getHeaderLength() + packet.size()), [this, self, buffer](boost::system::error_code error, std::size_t /*length*/)
{
- switch (opcode)
+ if (error)
{
- case CMSG_PING:
- return HandlePing(*new_pct);
- case CMSG_AUTH_SESSION:
- if (m_Session)
- {
- TC_LOG_ERROR("network", "WorldSocket::ProcessIncoming: received duplicate CMSG_AUTH_SESSION from %s", m_Session->GetPlayerInfo().c_str());
- return -1;
- }
-
- sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
- return HandleAuthSession(*new_pct);
- case CMSG_KEEP_ALIVE:
- TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
- sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
- return 0;
- case CMSG_LOG_DISCONNECT:
- new_pct->rfinish(); // contains uint32 disconnectReason;
- TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
- sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
- return 0;
- // not an opcode, client sends string "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER" without opcode
- // first 4 bytes become the opcode (2 dropped)
- case MSG_VERIFY_CONNECTIVITY:
- {
- TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
- sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
- std::string str;
- *new_pct >> str;
- if (str != "D OF WARCRAFT CONNECTION - CLIENT TO SERVER")
- return -1;
- return HandleSendAuthSession();
- }
- case CMSG_ENABLE_NAGLE:
- {
- TC_LOG_DEBUG("network", "%s", opcodeName.c_str());
- sScriptMgr->OnPacketReceive(this, WorldPacket(*new_pct));
- return m_Session ? m_Session->HandleEnableNagleAlgorithm() : -1;
- }
- default:
- {
- ACE_GUARD_RETURN(LockType, Guard, m_SessionLock, -1);
- if (!m_Session)
- {
- TC_LOG_ERROR("network.opcode", "ProcessIncoming: Client not authed opcode = %u", uint32(opcode));
- return -1;
- }
-
- // prevent invalid memory access/crash with custom opcodes
- if (opcode >= NUM_OPCODE_HANDLERS)
- return 0;
-
- OpcodeHandler const* handler = opcodeTable[opcode];
- if (!handler || handler->Status == STATUS_UNHANDLED)
- {
- TC_LOG_ERROR("network.opcode", "No defined handler for opcode %s sent by %s", GetOpcodeNameForLogging(new_pct->GetOpcode()).c_str(), m_Session->GetPlayerInfo().c_str());
- return 0;
- }
-
- // Our Idle timer will reset on any non PING opcodes.
- // Catches people idling on the login screen and any lingering ingame connections.
- m_Session->ResetTimeOutTime();
-
- // OK, give the packet to WorldSession
- aptr.release();
- // WARNING here we call it with locks held.
- // Its possible to cause deadlock if QueuePacket calls back
- m_Session->QueuePacket(new_pct);
- return 0;
- }
+ _socket.close();
}
- }
- catch (ByteBufferException &)
- {
- TC_LOG_ERROR("network", "WorldSocket::ProcessIncoming ByteBufferException occured while parsing an instant handled packet %s from client %s, accountid=%i. Disconnected client.",
- opcodeName.c_str(), GetRemoteAddress().c_str(), m_Session ? int32(m_Session->GetAccountId()) : -1);
- new_pct->hexlike();
- return -1;
- }
-
- ACE_NOTREACHED (return 0);
+ });
}
-int WorldSocket::HandleSendAuthSession()
-{
- WorldPacket packet(SMSG_AUTH_CHALLENGE, 37);
- BigNumber seed1;
- seed1.SetRand(16 * 8);
- packet.append(seed1.AsByteArray(16).get(), 16); // new encryption seeds
-
- BigNumber seed2;
- seed2.SetRand(16 * 8);
- packet.append(seed2.AsByteArray(16).get(), 16); // new encryption seeds
-
- packet << m_Seed;
- packet << uint8(1);
- return SendPacket(packet);
-}
-
-int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
+void WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
uint8 digest[20];
uint32 clientSeed;
@@ -851,8 +274,8 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
if (sWorld->IsClosed())
{
SendAuthResponseError(AUTH_REJECT);
- TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: World closed, denying client (%s).", GetRemoteAddress().c_str());
- return -1;
+ TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: World closed, denying client (%s).", GetRemoteIpAddress().c_str());
+ return;
}
// Get the account information from the realmd database
@@ -881,7 +304,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
// We can not log here, as we do not know the account. Thus, no accountId.
SendAuthResponseError(AUTH_UNKNOWN_ACCOUNT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (unknown account).");
- return -1;
+ return;
}
Field* fields = result->Fetch();
@@ -892,7 +315,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
expansion = world_expansion;
// For hook purposes, we get Remoteaddress at this point.
- std::string address = GetRemoteAddress();
+ std::string address = GetRemoteIpAddress();
// As we don't know if attempted login process by ip works, we update last_attempt_ip right away
stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LAST_ATTEMPT_IP);
@@ -909,13 +332,13 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
///- Re-check ip locking (same check as in realmd).
if (fields[3].GetUInt8() == 1) // if ip is locked
{
- if (strcmp (fields[2].GetCString(), address.c_str()))
+ if (strcmp(fields[2].GetCString(), address.c_str()))
{
SendAuthResponseError(AUTH_FAILED);
TC_LOG_DEBUG("network", "WorldSocket::HandleAuthSession: Sent Auth Response (Account IP differs. Original IP: %s, new IP: %s).", fields[2].GetCString(), address.c_str());
// We could log on hook only instead of an additional db log, however action logger is config based. Better keep DB logging as well
sScriptMgr->OnFailedAccountLogin(id);
- return -1;
+ return;
}
}
@@ -935,7 +358,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
LoginDatabase.Execute(stmt);
}
- locale = LocaleConstant (fields[6].GetUInt8());
+ locale = LocaleConstant(fields[6].GetUInt8());
if (locale >= TOTAL_LOCALES)
locale = LOCALE_enUS;
@@ -947,7 +370,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
SendAuthResponseError(AUTH_REJECT);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Client %s attempted to log in using invalid client OS (%s).", address.c_str(), os.c_str());
- return -1;
+ return;
}
// Checks gmlevel per Realm
@@ -979,7 +402,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendAuthResponseError(AUTH_BANNED);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Sent Auth Response (Account banned).");
sScriptMgr->OnFailedAccountLogin(id);
- return -1;
+ return;
}
// Check locked state for server
@@ -990,17 +413,16 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
SendAuthResponseError(AUTH_UNAVAILABLE);
TC_LOG_INFO("network", "WorldSocket::HandleAuthSession: User tries to login but his security level is not enough");
sScriptMgr->OnFailedAccountLogin(id);
- return -1;
+ return;
}
// Check that Key and account name are the same on client and server
uint32 t = 0;
- uint32 seed = m_Seed;
sha.UpdateData(account);
sha.UpdateData((uint8*)&t, 4);
sha.UpdateData((uint8*)&clientSeed, 4);
- sha.UpdateData((uint8*)&seed, 4);
+ sha.UpdateData((uint8*)&_authSeed, 4);
sha.UpdateBigNumbers(&k, NULL);
sha.Finalize();
@@ -1008,7 +430,7 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
{
SendAuthResponseError(AUTH_FAILED);
TC_LOG_ERROR("network", "WorldSocket::HandleAuthSession: Authentication failed for account: %u ('%s') address: %s", id, account.c_str(), address.c_str());
- return -1;
+ return;
}
TC_LOG_DEBUG("network", "WorldSocket::HandleAuthSession: Client '%s' authenticated successfully from %s.",
@@ -1035,31 +457,36 @@ int WorldSocket::HandleAuthSession(WorldPacket& recvPacket)
LoginDatabase.Execute(stmt);
// NOTE ATM the socket is single-threaded, have this in mind ...
- ACE_NEW_RETURN(m_Session, WorldSession(id, battlenetAccountId, this, AccountTypes(security), expansion, mutetime, locale, recruiter, isRecruiter), -1);
+ _worldSession = new WorldSession(id, battlenetAccountId, shared_from_this(), AccountTypes(security), expansion, mutetime, locale, recruiter, isRecruiter);
- m_Crypt.Init(&k);
+ _authCrypt.Init(&k);
- m_Session->LoadGlobalAccountData();
- m_Session->LoadTutorialsData();
- m_Session->ReadAddonsInfo(addonsData);
- m_Session->LoadPermissions();
+ _worldSession->LoadGlobalAccountData();
+ _worldSession->LoadTutorialsData();
+ _worldSession->ReadAddonsInfo(recvPacket);
+ _worldSession->LoadPermissions();
// At this point, we can safely hook a successful login
sScriptMgr->OnAccountLogin(id);
// Initialize Warden system only if it is enabled by config
if (wardenActive)
- m_Session->InitWarden(&k, os);
+ _worldSession->InitWarden(&k, os);
- // Sleep this Network thread for
- uint32 sleepTime = sWorld->getIntConfig(CONFIG_SESSION_ADD_DELAY);
- ACE_OS::sleep(ACE_Time_Value(0, sleepTime));
+ sWorld->AddSession(_worldSession);
+}
- sWorld->AddSession(m_Session);
- return 0;
+void WorldSocket::SendAuthResponseError(uint8 code)
+{
+ WorldPacket packet(SMSG_AUTH_RESPONSE, 1);
+ packet.WriteBit(0); // has queue info
+ packet.WriteBit(0); // has account info
+ packet << uint8(code);
+
+ AsyncWrite(packet);
}
-int WorldSocket::HandlePing(WorldPacket& recvPacket)
+void WorldSocket::HandlePing(WorldPacket& recvPacket)
{
uint32 ping;
uint32 latency;
@@ -1068,67 +495,55 @@ int WorldSocket::HandlePing(WorldPacket& recvPacket)
recvPacket >> latency;
recvPacket >> ping;
- if (m_LastPingTime == ACE_Time_Value::zero)
- m_LastPingTime = ACE_OS::gettimeofday(); // for 1st ping
+ if (_LastPingTime == steady_clock::time_point())
+ {
+ _LastPingTime = steady_clock::now();
+ }
else
{
- ACE_Time_Value cur_time = ACE_OS::gettimeofday();
- ACE_Time_Value diff_time (cur_time);
- diff_time -= m_LastPingTime;
- m_LastPingTime = cur_time;
+ steady_clock::time_point now = steady_clock::now();
+
+ steady_clock::duration diff = now - _LastPingTime;
+
+ _LastPingTime = now;
- if (diff_time < ACE_Time_Value (27))
+ if (diff < seconds(27))
{
- ++m_OverSpeedPings;
+ ++_OverSpeedPings;
- uint32 max_count = sWorld->getIntConfig (CONFIG_MAX_OVERSPEED_PINGS);
+ uint32 maxAllowed = sWorld->getIntConfig(CONFIG_MAX_OVERSPEED_PINGS);
- if (max_count && m_OverSpeedPings > max_count)
+ if (maxAllowed && _OverSpeedPings > maxAllowed)
{
- ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
-
- if (m_Session && !m_Session->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_OVERSPEED_PING))
+ if (_worldSession && !_worldSession->HasPermission(rbac::RBAC_PERM_SKIP_CHECK_OVERSPEED_PING))
{
TC_LOG_ERROR("network", "WorldSocket::HandlePing: %s kicked for over-speed pings (address: %s)",
- m_Session->GetPlayerInfo().c_str(), GetRemoteAddress().c_str());
+ _worldSession->GetPlayerInfo().c_str(), GetRemoteIpAddress().c_str());
- return -1;
+ _socket.close();
+ return;
}
}
}
else
- m_OverSpeedPings = 0;
+ _OverSpeedPings = 0;
}
- // critical section
+ if (_worldSession)
+ {
+ _worldSession->SetLatency(latency);
+ _worldSession->ResetClientTimeDelay();
+ }
+ else
{
- ACE_GUARD_RETURN (LockType, Guard, m_SessionLock, -1);
+ TC_LOG_ERROR("network", "WorldSocket::HandlePing: peer sent CMSG_PING, but is not authenticated or got recently kicked, address = %s",
+ GetRemoteIpAddress().c_str());
- if (m_Session)
- {
- m_Session->SetLatency (latency);
- m_Session->ResetClientTimeDelay();
- }
- else
- {
- TC_LOG_ERROR("network", "WorldSocket::HandlePing: peer sent CMSG_PING, "
- "but is not authenticated or got recently kicked, "
- " address = %s",
- GetRemoteAddress().c_str());
- return -1;
- }
+ _socket.close();
+ return;
}
WorldPacket packet(SMSG_PONG, 4);
packet << ping;
- return SendPacket(packet);
-}
-
-void WorldSocket::SendAuthResponseError(uint8 code)
-{
- WorldPacket packet(SMSG_AUTH_RESPONSE, 1);
- packet.WriteBit(0); // has queue info
- packet.WriteBit(0); // has account info
- packet << uint8(code);
- SendPacket(packet);
+ return AsyncWrite(packet);
}
diff --git a/src/server/game/Server/WorldSocket.h b/src/server/game/Server/WorldSocket.h
index 306a50c083a..e46c6b3fe5c 100644
--- a/src/server/game/Server/WorldSocket.h
+++ b/src/server/game/Server/WorldSocket.h
@@ -1,219 +1,85 @@
/*
- * Copyright (C) 2008-2014 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/>.
- */
-
-/** \addtogroup u2w User to World Communication
- * @{
- * \file WorldSocket.h
- * \author Derex <derex101@gmail.com>
- */
-
-#ifndef _WORLDSOCKET_H
-#define _WORLDSOCKET_H
-
-#include <ace/Basic_Types.h>
-#include <ace/Synch_Traits.h>
-#include <ace/Svc_Handler.h>
-#include <ace/SOCK_Stream.h>
-#include <ace/Thread_Mutex.h>
-#include <ace/Guard_T.h>
-#include <ace/Unbounded_Queue.h>
-#include <ace/Message_Block.h>
-
-#if !defined (ACE_LACKS_PRAGMA_ONCE)
-#pragma once
-#endif /* ACE_LACKS_PRAGMA_ONCE */
-
+* Copyright (C) 2008-2014 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 __WORLDSOCKET_H__
+#define __WORLDSOCKET_H__
+
+#include <memory>
+#include <chrono>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/streambuf.hpp>
#include "Common.h"
#include "WorldPacketCrypt.h"
+#include "Util.h"
+#include "WorldPacket.h"
+#include "WorldSession.h"
-class ACE_Message_Block;
-class WorldPacket;
-class WorldSession;
-
-/// Handler that can communicate over stream sockets.
-typedef ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> WorldHandler;
-
-/**
- * WorldSocket.
- *
- * This class is responsible for the communication with
- * remote clients.
- * Most methods return -1 on failure.
- * The class uses reference counting.
- *
- * For output the class uses one buffer (64K usually) and
- * a queue where it stores packet if there is no place on
- * the queue. The reason this is done, is because the server
- * does really a lot of small-size writes to it, and it doesn't
- * scale well to allocate memory for every. When something is
- * written to the output buffer the socket is not immediately
- * activated for output (again for the same reason), there
- * is 10ms celling (thats why there is Update() method).
- * This concept is similar to TCP_CORK, but TCP_CORK
- * uses 200ms celling. As result overhead generated by
- * sending packets from "producer" threads is minimal,
- * and doing a lot of writes with small size is tolerated.
- *
- * The calls to Update() method are managed by WorldSocketMgr
- * and ReactorRunnable.
- *
- * For input, the class uses one 4096 bytes buffer on stack
- * to which it does recv() calls. And then received data is
- * distributed where its needed. 4096 matches pretty well the
- * traffic generated by client for now.
- *
- * The input/output do speculative reads/writes (AKA it tryes
- * to read all data available in the kernel buffer or tryes to
- * write everything available in userspace buffer),
- * which is ok for using with Level and Edge Triggered IO
- * notification.
- *
- */
-class WorldSocket : public WorldHandler
-{
- public:
- WorldSocket (void);
- virtual ~WorldSocket (void);
-
- friend class WorldSocketMgr;
-
- /// Mutex type used for various synchronizations.
- typedef ACE_Thread_Mutex LockType;
- typedef ACE_Guard<LockType> GuardType;
-
- /// Check if socket is closed.
- bool IsClosed(void) const;
-
- /// Close the socket.
- void CloseSocket(void);
-
- /// Get address of connected peer.
- const std::string& GetRemoteAddress(void) const;
-
- /// Send A packet on the socket, this function is reentrant.
- /// @param pct packet to send
- /// @return -1 of failure
- int SendPacket(const WorldPacket& pct);
-
- /// Add reference to this object.
- long AddReference(void);
-
- /// Remove reference to this object.
- long RemoveReference(void);
-
- /// things called by ACE framework.
-
- /// Called on open, the void* is the acceptor.
- virtual int open(void *);
-
- /// Called on failures inside of the acceptor, don't call from your code.
- virtual int close(u_long);
-
- /// Called when we can read from the socket.
- virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE);
+using boost::asio::ip::tcp;
- /// Called when the socket can write.
- virtual int handle_output(ACE_HANDLE = ACE_INVALID_HANDLE);
+#pragma pack(push, 1)
- /// Called when connection is closed or error happens.
- virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE,
- ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK);
-
- /// Called by WorldSocketMgr/ReactorRunnable.
- int Update(void);
-
- private:
- /// Helper functions for processing incoming data.
- int handle_input_header(void);
- int handle_input_payload(void);
- int handle_input_missing_data(void);
-
- /// Help functions to mark/unmark the socket for output.
- /// @param g the guard is for m_OutBufferLock, the function will release it
- int cancel_wakeup_output(GuardType& g);
- int schedule_wakeup_output(GuardType& g);
-
- /// Drain the queue if its not empty.
- int handle_output_queue(GuardType& g);
-
- /// process one incoming packet.
- /// @param new_pct received packet, note that you need to delete it.
- int ProcessIncoming(WorldPacket* new_pct);
-
- /// Called by ProcessIncoming() on CMSG_AUTH_SESSION.
- int HandleAuthSession(WorldPacket& recvPacket);
-
- /// Called by ProcessIncoming() on CMSG_PING.
- int HandlePing(WorldPacket& recvPacket);
-
- /// Called by CMSG_VERIFY_CONNECTIVITY_RESPONSE
- int HandleSendAuthSession();
+struct ClientPktHeader
+{
+ uint16 size;
+ uint32 cmd;
+};
- private:
- void SendAuthResponseError(uint8);
- /// Time in which the last ping was received
- ACE_Time_Value m_LastPingTime;
+#pragma pack(pop)
- /// Keep track of over-speed pings, to prevent ping flood.
- uint32 m_OverSpeedPings;
+class WorldSocket : public std::enable_shared_from_this<WorldSocket>
+{
+public:
+ WorldSocket(tcp::socket&& socket);
- /// Address of the remote peer
- std::string m_Address;
+ WorldSocket(WorldSocket const& right) = delete;
+ WorldSocket& operator=(WorldSocket const& right) = delete;
- /// Class used for managing encryption of the headers
- WorldPacketCrypt m_Crypt;
+ void Start();
- /// Mutex lock to protect m_Session
- LockType m_SessionLock;
+ const std::string GetRemoteIpAddress() const { return _socket.remote_endpoint().address().to_string(); };
+ unsigned short GetRemotePort() const { return _socket.remote_endpoint().port(); }
- /// Session to which received packets are routed
- WorldSession* m_Session;
+ void CloseSocket() { _socket.close(); };
+ bool IsOpen() { return _socket.is_open(); };
- /// here are stored the fragments of the received data
- WorldPacket* m_RecvWPct;
+ void AsyncWrite(WorldPacket const& packet);
- /// This block actually refers to m_RecvWPct contents,
- /// which allows easy and safe writing to it.
- /// It wont free memory when its deleted. m_RecvWPct takes care of freeing.
- ACE_Message_Block m_RecvPct;
+private:
+ void HandleSendAuthSession();
+ void HandleAuthSession(WorldPacket& recvPacket);
+ void SendAuthResponseError(uint8 code);
- /// Fragment of the received header.
- ACE_Message_Block m_Header;
+ void HandlePing(WorldPacket& recvPacket);
- /// Mutex for protecting output related data.
- LockType m_OutBufferLock;
+ void AsyncReadHeader();
+ void AsyncReadData(size_t dataSize);
- /// Buffer used for writing output.
- ACE_Message_Block* m_OutBuffer;
+ tcp::socket _socket;
- /// Size of the m_OutBuffer.
- size_t m_OutBufferSize;
+ char _readBuffer[4096];
- /// True if the socket is registered with the reactor for output
- bool m_OutActive;
+ uint32 _authSeed;
+ AuthCrypt _authCrypt;
- uint32 m_Seed;
+ std::chrono::steady_clock::time_point _LastPingTime;
+ uint32 _OverSpeedPings;
- WorldSocket(WorldSocket const& right) = delete;
- WorldSocket& operator=(WorldSocket const& right) = delete;
+ WorldSession* _worldSession;
};
-#endif /* _WORLDSOCKET_H */
-
-/// @}
-
+#endif
diff --git a/src/server/game/Server/WorldSocketAcceptor.h b/src/server/game/Server/WorldSocketAcceptor.h
deleted file mode 100644
index 0b07196a0cd..00000000000
--- a/src/server/game/Server/WorldSocketAcceptor.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- *
- * 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/>.
- */
-
-/** \addtogroup u2w User to World Communication
- * @{
- * \file WorldSocketMgr.h
- */
-
-#ifndef __WORLDSOCKETACCEPTOR_H_
-#define __WORLDSOCKETACCEPTOR_H_
-
-#include "Common.h"
-
-#include <ace/Acceptor.h>
-#include <ace/SOCK_Acceptor.h>
-
-#include "WorldSocket.h"
-
-class WorldSocketAcceptor : public ACE_Acceptor<WorldSocket, ACE_SOCK_Acceptor>
-{
-public:
- WorldSocketAcceptor(void) { }
- virtual ~WorldSocketAcceptor(void)
- {
- if (reactor())
- reactor()->cancel_timer(this, 1);
- }
-
-protected:
-
- virtual int handle_timeout(const ACE_Time_Value& /*current_time*/, const void* /*act = 0*/)
- {
- TC_LOG_DEBUG("misc", "Resuming acceptor");
- reactor()->cancel_timer(this, 1);
- return reactor()->register_handler(this, ACE_Event_Handler::ACCEPT_MASK);
- }
-
- virtual int handle_accept_error(void)
- {
-#if defined(ENFILE) && defined(EMFILE)
- if (errno == ENFILE || errno == EMFILE)
- {
- TC_LOG_ERROR("misc", "Out of file descriptors, suspending incoming connections for 10 seconds");
- reactor()->remove_handler(this, ACE_Event_Handler::ACCEPT_MASK | ACE_Event_Handler::DONT_CALL);
- reactor()->schedule_timer(this, NULL, ACE_Time_Value(10));
- }
-#endif
- return 0;
- }
-};
-
-#endif /* __WORLDSOCKETACCEPTOR_H_ */
-/// @}
diff --git a/src/server/game/Server/WorldSocketMgr.cpp b/src/server/game/Server/WorldSocketMgr.cpp
deleted file mode 100644
index 7880552ffa1..00000000000
--- a/src/server/game/Server/WorldSocketMgr.cpp
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Copyright (C) 2008-2014 TrinityCore <http://www.trinitycore.org/>
- * Copyright (C) 2005-2008 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/>.
- */
-
-/** \file WorldSocketMgr.cpp
-* \ingroup u2w
-* \author Derex <derex101@gmail.com>
-*/
-
-#include "WorldSocketMgr.h"
-
-#include <ace/ACE.h>
-#include <ace/Log_Msg.h>
-#include <ace/Reactor.h>
-#include <ace/Reactor_Impl.h>
-#include <ace/TP_Reactor.h>
-#include <ace/Dev_Poll_Reactor.h>
-#include <ace/Guard_T.h>
-#include <ace/Atomic_Op.h>
-#include <ace/os_include/arpa/os_inet.h>
-#include <ace/os_include/netinet/os_tcp.h>
-#include <ace/os_include/sys/os_types.h>
-#include <ace/os_include/sys/os_socket.h>
-
-#include <set>
-
-#include "Log.h"
-#include "Common.h"
-#include "Config.h"
-#include "DatabaseEnv.h"
-#include "WorldSocket.h"
-#include "WorldSocketAcceptor.h"
-#include "ScriptMgr.h"
-
-/**
-* This is a helper class to WorldSocketMgr, that manages
-* network threads, and assigning connections from acceptor thread
-* to other network threads
-*/
-class ReactorRunnable : protected ACE_Task_Base
-{
- public:
-
- ReactorRunnable() :
- m_Reactor(0),
- m_Connections(0),
- m_ThreadId(-1)
- {
- ACE_Reactor_Impl* imp;
-
- #if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL)
-
- imp = new ACE_Dev_Poll_Reactor();
-
- imp->max_notify_iterations (128);
- imp->restart (1);
-
- #else
-
- imp = new ACE_TP_Reactor();
- imp->max_notify_iterations (128);
-
- #endif
-
- m_Reactor = new ACE_Reactor (imp, 1);
- }
-
- virtual ~ReactorRunnable()
- {
- Stop();
- Wait();
-
- delete m_Reactor;
- }
-
- void Stop()
- {
- m_Reactor->end_reactor_event_loop();
- }
-
- int Start()
- {
- if (m_ThreadId != -1)
- return -1;
-
- return (m_ThreadId = activate());
- }
-
- void Wait() { ACE_Task_Base::wait(); }
-
- long Connections()
- {
- return static_cast<long> (m_Connections.value());
- }
-
- int AddSocket (WorldSocket* sock)
- {
- TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
-
- ++m_Connections;
- sock->AddReference();
- sock->reactor (m_Reactor);
- m_NewSockets.insert (sock);
-
- sScriptMgr->OnSocketOpen(sock);
-
- return 0;
- }
-
- ACE_Reactor* GetReactor()
- {
- return m_Reactor;
- }
-
- protected:
-
- void AddNewSockets()
- {
- TRINITY_GUARD(ACE_Thread_Mutex, m_NewSockets_Lock);
-
- if (m_NewSockets.empty())
- return;
-
- for (SocketSet::const_iterator i = m_NewSockets.begin(); i != m_NewSockets.end(); ++i)
- {
- WorldSocket* sock = (*i);
-
- if (sock->IsClosed())
- {
- sScriptMgr->OnSocketClose(sock, true);
-
- sock->RemoveReference();
- --m_Connections;
- }
- else
- m_Sockets.insert (sock);
- }
-
- m_NewSockets.clear();
- }
-
- virtual int svc()
- {
- TC_LOG_DEBUG("misc", "Network Thread Starting");
-
- ACE_ASSERT (m_Reactor);
-
- SocketSet::iterator i, t;
-
- while (!m_Reactor->reactor_event_loop_done())
- {
- // dont be too smart to move this outside the loop
- // the run_reactor_event_loop will modify interval
- ACE_Time_Value interval (0, 10000);
-
- if (m_Reactor->run_reactor_event_loop (interval) == -1)
- break;
-
- AddNewSockets();
-
- for (i = m_Sockets.begin(); i != m_Sockets.end();)
- {
- if ((*i)->Update() == -1)
- {
- t = i;
- ++i;
-
- (*t)->CloseSocket();
-
- sScriptMgr->OnSocketClose((*t), false);
-
- (*t)->RemoveReference();
- --m_Connections;
- m_Sockets.erase (t);
- }
- else
- ++i;
- }
- }
-
- TC_LOG_DEBUG("misc", "Network Thread exits");
-
- return 0;
- }
-
- private:
- typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt;
- typedef std::set<WorldSocket*> SocketSet;
-
- ACE_Reactor* m_Reactor;
- AtomicInt m_Connections;
- int m_ThreadId;
-
- SocketSet m_Sockets;
-
- SocketSet m_NewSockets;
- ACE_Thread_Mutex m_NewSockets_Lock;
-};
-
-WorldSocketMgr::WorldSocketMgr() :
- m_NetThreads(0),
- m_NetThreadsCount(0),
- m_SockOutKBuff(-1),
- m_SockOutUBuff(65536),
- m_UseNoDelay(true),
- m_Acceptor (0) { }
-
-WorldSocketMgr::~WorldSocketMgr()
-{
- delete [] m_NetThreads;
- delete m_Acceptor;
-}
-
-int
-WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address)
-{
- m_UseNoDelay = sConfigMgr->GetBoolDefault ("Network.TcpNodelay", true);
-
- int num_threads = sConfigMgr->GetIntDefault ("Network.Threads", 1);
-
- if (num_threads <= 0)
- {
- TC_LOG_ERROR("misc", "Network.Threads is wrong in your config file");
- return -1;
- }
-
- m_NetThreadsCount = static_cast<size_t> (num_threads + 1);
-
- m_NetThreads = new ReactorRunnable[m_NetThreadsCount];
-
- TC_LOG_DEBUG("misc", "Max allowed socket connections %d", ACE::max_handles());
-
- // -1 means use default
- m_SockOutKBuff = sConfigMgr->GetIntDefault ("Network.OutKBuff", -1);
-
- m_SockOutUBuff = sConfigMgr->GetIntDefault ("Network.OutUBuff", 65536);
-
- if (m_SockOutUBuff <= 0)
- {
- TC_LOG_ERROR("misc", "Network.OutUBuff is wrong in your config file");
- return -1;
- }
-
- m_Acceptor = new WorldSocketAcceptor;
-
- ACE_INET_Addr listen_addr (port, address);
-
- if (m_Acceptor->open(listen_addr, m_NetThreads[0].GetReactor(), ACE_NONBLOCK) == -1)
- {
- TC_LOG_ERROR("misc", "Failed to open acceptor, check if the port is free");
- return -1;
- }
-
- for (size_t i = 0; i < m_NetThreadsCount; ++i)
- m_NetThreads[i].Start();
-
- return 0;
-}
-
-int
-WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address)
-{
- if (!sLog->ShouldLog("misc", LOG_LEVEL_DEBUG))
- ACE_Log_Msg::instance()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS);
-
- if (StartReactiveIO(port, address) == -1)
- return -1;
-
- sScriptMgr->OnNetworkStart();
-
- return 0;
-}
-
-void
-WorldSocketMgr::StopNetwork()
-{
- if (m_Acceptor)
- {
- m_Acceptor->close();
- }
-
- if (m_NetThreadsCount != 0)
- {
- for (size_t i = 0; i < m_NetThreadsCount; ++i)
- m_NetThreads[i].Stop();
- }
-
- Wait();
-
- sScriptMgr->OnNetworkStop();
-}
-
-void
-WorldSocketMgr::Wait()
-{
- if (m_NetThreadsCount != 0)
- {
- for (size_t i = 0; i < m_NetThreadsCount; ++i)
- m_NetThreads[i].Wait();
- }
-}
-
-int
-WorldSocketMgr::OnSocketOpen (WorldSocket* sock)
-{
- // set some options here
- if (m_SockOutKBuff >= 0)
- {
- if (sock->peer().set_option (SOL_SOCKET,
- SO_SNDBUF,
- (void*) & m_SockOutKBuff,
- sizeof (int)) == -1 && errno != ENOTSUP)
- {
- TC_LOG_ERROR("misc", "WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF");
- return -1;
- }
- }
-
- static const int ndoption = 1;
-
- // Set TCP_NODELAY.
- if (m_UseNoDelay)
- {
- if (sock->peer().set_option (ACE_IPPROTO_TCP,
- TCP_NODELAY,
- (void*)&ndoption,
- sizeof (int)) == -1)
- {
- TC_LOG_ERROR("misc", "WorldSocketMgr::OnSocketOpen: peer().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno));
- return -1;
- }
- }
-
- sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff);
-
- // we skip the Acceptor Thread
- size_t min = 1;
-
- ACE_ASSERT (m_NetThreadsCount >= 1);
-
- for (size_t i = 1; i < m_NetThreadsCount; ++i)
- if (m_NetThreads[i].Connections() < m_NetThreads[min].Connections())
- min = i;
-
- return m_NetThreads[min].AddSocket (sock);
-}
diff --git a/src/server/game/Server/WorldSocketMgr.h b/src/server/game/Server/WorldSocketMgr.h
deleted file mode 100644
index fb8ddb42b9e..00000000000
--- a/src/server/game/Server/WorldSocketMgr.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2008-2014 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/>.
- */
-
-/** \addtogroup u2w User to World Communication
- * @{
- * \file WorldSocketMgr.h
- * \author Derex <derex101@gmail.com>
- */
-
-#ifndef __WORLDSOCKETMGR_H
-#define __WORLDSOCKETMGR_H
-
-#include <ace/Basic_Types.h>
-#include <ace/Singleton.h>
-#include <ace/Thread_Mutex.h>
-
-class WorldSocket;
-class ReactorRunnable;
-class ACE_Event_Handler;
-
-/// Manages all sockets connected to peers and network threads
-class WorldSocketMgr
-{
-public:
- friend class WorldSocket;
- friend class ACE_Singleton<WorldSocketMgr, ACE_Thread_Mutex>;
-
- /// Start network, listen at address:port .
- int StartNetwork(ACE_UINT16 port, const char* address);
-
- /// Stops all network threads, It will wait for all running threads .
- void StopNetwork();
-
- /// Wait untill all network threads have "joined" .
- void Wait();
-
-private:
- int OnSocketOpen(WorldSocket* sock);
-
- int StartReactiveIO(ACE_UINT16 port, const char* address);
-
-private:
- WorldSocketMgr();
- virtual ~WorldSocketMgr();
-
- ReactorRunnable* m_NetThreads;
- size_t m_NetThreadsCount;
-
- int m_SockOutKBuff;
- int m_SockOutUBuff;
- bool m_UseNoDelay;
-
- class WorldSocketAcceptor* m_Acceptor;
-};
-
-#define sWorldSocketMgr ACE_Singleton<WorldSocketMgr, ACE_Thread_Mutex>::instance()
-
-#endif
-/// @}
diff --git a/src/server/game/Spells/Auras/SpellAuras.cpp b/src/server/game/Spells/Auras/SpellAuras.cpp
index ab7f0eac759..e38dc8fdf4a 100644
--- a/src/server/game/Spells/Auras/SpellAuras.cpp
+++ b/src/server/game/Spells/Auras/SpellAuras.cpp
@@ -1065,7 +1065,7 @@ void Aura::SetLoadedState(int32 maxduration, int32 duration, int32 charges, uint
if (m_effects[i])
{
m_effects[i]->SetAmount(amount[i]);
- m_effects[i]->SetCanBeRecalculated(recalculateMask & (1<<i));
+ m_effects[i]->SetCanBeRecalculated((recalculateMask & (1 << i)) != 0);
m_effects[i]->CalculatePeriodic(caster, false, true);
m_effects[i]->CalculateSpellMod();
m_effects[i]->RecalculateAmount(caster);
diff --git a/src/server/game/Spells/Auras/SpellAuras.h b/src/server/game/Spells/Auras/SpellAuras.h
index 8c426ea2175..19c77c2ac7e 100644
--- a/src/server/game/Spells/Auras/SpellAuras.h
+++ b/src/server/game/Spells/Auras/SpellAuras.h
@@ -67,9 +67,9 @@ class AuraApplication
uint8 GetSlot() const { return _slot; }
uint8 GetFlags() const { return _flags; }
uint8 GetEffectMask() const { return _flags & (AFLAG_EFF_INDEX_0 | AFLAG_EFF_INDEX_1 | AFLAG_EFF_INDEX_2); }
- bool HasEffect(uint8 effect) const { ASSERT(effect < MAX_SPELL_EFFECTS); return _flags & (1<<effect); }
- bool IsPositive() const { return _flags & AFLAG_POSITIVE; }
- bool IsSelfcast() const { return _flags & AFLAG_CASTER; }
+ bool HasEffect(uint8 effect) const { ASSERT(effect < MAX_SPELL_EFFECTS); return (_flags & (1 << effect)) != 0; }
+ bool IsPositive() const { return (_flags & AFLAG_POSITIVE) != 0; }
+ bool IsSelfcast() const { return (_flags & AFLAG_CASTER) != 0; }
uint8 GetEffectsToApply() const { return _effectsToApply; }
void SetRemoveMode(AuraRemoveMode mode) { _removeMode = mode; }
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 6a2d54910f5..411f3c7343e 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -1755,8 +1755,8 @@ void Spell::SearchTargets(SEARCHER& searcher, uint32 containerMask, Unit* refere
return;
// search world and grid for possible targets
- bool searchInGrid = containerMask & (GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_GAMEOBJECT);
- bool searchInWorld = containerMask & (GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER | GRID_MAP_TYPE_MASK_CORPSE);
+ bool searchInGrid = (containerMask & (GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_GAMEOBJECT)) != 0;
+ bool searchInWorld = (containerMask & (GRID_MAP_TYPE_MASK_CREATURE | GRID_MAP_TYPE_MASK_PLAYER | GRID_MAP_TYPE_MASK_CORPSE)) != 0;
if (searchInGrid || searchInWorld)
{
float x, y;
@@ -2527,7 +2527,7 @@ SpellMissInfo Spell::DoSpellHitOnUnit(Unit* unit, uint32 effectMask, bool scaleA
aura_effmask |= 1 << i;
// Get Data Needed for Diminishing Returns, some effects may have multiple auras, so this must be done on spell hit, not aura add
- m_diminishGroup = GetDiminishingReturnsGroupForSpell(m_spellInfo, m_triggeredByAuraSpell);
+ m_diminishGroup = GetDiminishingReturnsGroupForSpell(m_spellInfo, m_triggeredByAuraSpell != nullptr);
if (m_diminishGroup && aura_effmask)
{
m_diminishLevel = unit->GetDiminishing(m_diminishGroup);
@@ -5579,7 +5579,7 @@ SpellCastResult Spell::CheckCasterAuras() const
mechanic_immune = IMMUNE_TO_MOVEMENT_IMPAIRMENT_AND_LOSS_CONTROL_MASK;
}
- bool usableInStun = m_spellInfo->AttributesEx5 & SPELL_ATTR5_USABLE_WHILE_STUNNED;
+ bool usableInStun = (m_spellInfo->AttributesEx5 & SPELL_ATTR5_USABLE_WHILE_STUNNED) != 0;
// Glyph of Pain Suppression
// Allow Pain Suppression and Guardian Spirit to be cast while stunned
@@ -6508,7 +6508,7 @@ bool Spell::CheckEffectTarget(Unit const* target, uint32 eff) const
bool Spell::IsNextMeleeSwingSpell() const
{
- return m_spellInfo->Attributes & SPELL_ATTR0_ON_NEXT_SWING;
+ return (m_spellInfo->Attributes & SPELL_ATTR0_ON_NEXT_SWING) != 0;
}
bool Spell::IsAutoActionResetSpell() const
@@ -6687,7 +6687,7 @@ void Spell::HandleLaunchPhase()
if (m_applyMultiplierMask & (1 << i))
multiplier[i] = m_spellInfo->Effects[i].CalcDamageMultiplier(m_originalCaster, this);
- bool usesAmmo = m_spellInfo->AttributesCu & SPELL_ATTR0_CU_DIRECT_DAMAGE;
+ bool usesAmmo = (m_spellInfo->AttributesCu & SPELL_ATTR0_CU_DIRECT_DAMAGE) != 0;
for (std::list<TargetInfo>::iterator ihit= m_UniqueTargetInfo.begin(); ihit != m_UniqueTargetInfo.end(); ++ihit)
{
diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h
index ae5bba9ed1a..5b976ced426 100644
--- a/src/server/game/Spells/Spell.h
+++ b/src/server/game/Spells/Spell.h
@@ -150,8 +150,8 @@ class SpellCastTargets
void ModDst(SpellDestination const& spellDest);
void RemoveDst();
- bool HasSrc() const { return GetTargetMask() & TARGET_FLAG_SOURCE_LOCATION; }
- bool HasDst() const { return GetTargetMask() & TARGET_FLAG_DEST_LOCATION; }
+ bool HasSrc() const { return (GetTargetMask() & TARGET_FLAG_SOURCE_LOCATION) != 0; }
+ bool HasDst() const { return (GetTargetMask() & TARGET_FLAG_DEST_LOCATION) != 0; }
bool HasTraj() const { return m_speed != 0; }
float GetElevation() const { return m_elevation; }
@@ -471,7 +471,7 @@ class Spell
void SetAutoRepeat(bool rep) { m_autoRepeat = rep; }
void ReSetTimer() { m_timer = m_casttime > 0 ? m_casttime : 0; }
bool IsNextMeleeSwingSpell() const;
- bool IsTriggered() const { return _triggeredCastFlags & TRIGGERED_FULL_MASK; }
+ bool IsTriggered() const { return (_triggeredCastFlags & TRIGGERED_FULL_MASK) != 0; }
bool IsChannelActive() const { return m_caster->GetUInt32Value(UNIT_CHANNEL_SPELL) != 0; }
bool IsAutoActionResetSpell() const;
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 301f33646dd..daef0208678 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -5072,7 +5072,7 @@ void Spell::EffectStealBeneficialBuff(SpellEffIndex effIndex)
// The charges / stack amounts don't count towards the total number of auras that can be dispelled.
// Ie: A dispel on a target with 5 stacks of Winters Chill and a Polymorph has 1 / (1 + 1) -> 50% chance to dispell
// Polymorph instead of 1 / (5 + 1) -> 16%.
- bool dispel_charges = aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES;
+ bool dispel_charges = (aura->GetSpellInfo()->AttributesEx7 & SPELL_ATTR7_DISPEL_CHARGES) != 0;
uint8 charges = dispel_charges ? aura->GetCharges() : aura->GetStackAmount();
if (charges > 0)
steal_list.push_back(std::make_pair(aura, charges));
diff --git a/src/server/game/Spells/SpellInfo.cpp b/src/server/game/Spells/SpellInfo.cpp
index cc10569f28f..e2c66dc6b3a 100644
--- a/src/server/game/Spells/SpellInfo.cpp
+++ b/src/server/game/Spells/SpellInfo.cpp
@@ -1170,7 +1170,7 @@ bool SpellInfo::IsTargetingArea() const
bool SpellInfo::NeedsExplicitUnitTarget() const
{
- return GetExplicitTargetMask() & TARGET_FLAG_UNIT_MASK;
+ return (GetExplicitTargetMask() & TARGET_FLAG_UNIT_MASK) != 0;
}
bool SpellInfo::NeedsToBeTriggeredByCaster(SpellInfo const* triggeringSpell) const
@@ -1211,7 +1211,7 @@ bool SpellInfo::NeedsToBeTriggeredByCaster(SpellInfo const* triggeringSpell) con
bool SpellInfo::IsPassive() const
{
- return Attributes & SPELL_ATTR0_PASSIVE;
+ return (Attributes & SPELL_ATTR0_PASSIVE) != 0;
}
bool SpellInfo::IsAutocastable() const
@@ -1279,12 +1279,12 @@ bool SpellInfo::IsCooldownStartedOnEvent() const
bool SpellInfo::IsDeathPersistent() const
{
- return AttributesEx3 & SPELL_ATTR3_DEATH_PERSISTENT;
+ return (AttributesEx3 & SPELL_ATTR3_DEATH_PERSISTENT) != 0;
}
bool SpellInfo::IsRequiringDeadTarget() const
{
- return AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_GHOSTS;
+ return (AttributesEx3 & SPELL_ATTR3_ONLY_TARGET_GHOSTS) != 0;
}
bool SpellInfo::IsAllowingDeadTarget() const
@@ -1318,12 +1318,12 @@ bool SpellInfo::IsPositiveEffect(uint8 effIndex) const
bool SpellInfo::IsChanneled() const
{
- return (AttributesEx & (SPELL_ATTR1_CHANNELED_1 | SPELL_ATTR1_CHANNELED_2));
+ return (AttributesEx & (SPELL_ATTR1_CHANNELED_1 | SPELL_ATTR1_CHANNELED_2)) != 0;
}
bool SpellInfo::NeedsComboPoints() const
{
- return (AttributesEx & (SPELL_ATTR1_REQ_COMBO_POINTS1 | SPELL_ATTR1_REQ_COMBO_POINTS2));
+ return (AttributesEx & (SPELL_ATTR1_REQ_COMBO_POINTS1 | SPELL_ATTR1_REQ_COMBO_POINTS2)) != 0;
}
bool SpellInfo::IsBreakingStealth() const
@@ -1339,7 +1339,7 @@ bool SpellInfo::IsRangedWeaponSpell() const
bool SpellInfo::IsAutoRepeatRangedSpell() const
{
- return AttributesEx2 & SPELL_ATTR2_AUTOREPEAT_FLAG;
+ return (AttributesEx2 & SPELL_ATTR2_AUTOREPEAT_FLAG) != 0;
}
bool SpellInfo::IsAffectedBySpellMods() const
diff --git a/src/server/game/Spells/SpellMgr.h b/src/server/game/Spells/SpellMgr.h
index 4f6364cf036..775d3f0c36d 100644
--- a/src/server/game/Spells/SpellMgr.h
+++ b/src/server/game/Spells/SpellMgr.h
@@ -21,8 +21,6 @@
// For static or at-server-startup loaded spell data
-#include <ace/Singleton.h>
-
#include "Define.h"
#include "DBCStructure.h"
#include "SharedDefines.h"
@@ -603,7 +601,6 @@ bool IsDiminishingReturnsGroupDurationLimited(DiminishingGroup group);
class SpellMgr
{
- friend class ACE_Singleton<SpellMgr, ACE_Null_Mutex>;
// Constructors
private:
SpellMgr();
@@ -611,6 +608,13 @@ class SpellMgr
// Accessors (const or static functions)
public:
+ static SpellMgr* instance()
+ {
+ static SpellMgr* instance = new SpellMgr();
+
+ return instance;
+ }
+
// Spell correctness for client using
static bool IsSpellValid(SpellInfo const* spellInfo, Player* player = NULL, bool msg = true);
@@ -766,6 +770,6 @@ class SpellMgr
SpellInfoMap mSpellInfoMap;
};
-#define sSpellMgr ACE_Singleton<SpellMgr, ACE_Null_Mutex>::instance()
+#define sSpellMgr SpellMgr::instance()
#endif
diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp
index c0bcd477e5b..7132e0583e8 100644
--- a/src/server/game/Spells/SpellScript.cpp
+++ b/src/server/game/Spells/SpellScript.cpp
@@ -87,7 +87,7 @@ uint8 _SpellScript::EffectHook::GetAffectedEffectsMask(SpellInfo const* spellEnt
bool _SpellScript::EffectHook::IsEffectAffected(SpellInfo const* spellEntry, uint8 effIndex)
{
- return GetAffectedEffectsMask(spellEntry) & 1<<effIndex;
+ return (GetAffectedEffectsMask(spellEntry) & 1 << effIndex) != 0;
}
std::string _SpellScript::EffectHook::EffIndexToString()
diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h
index 32b8781fb89..43d8a577fa3 100644
--- a/src/server/game/Spells/SpellScript.h
+++ b/src/server/game/Spells/SpellScript.h
@@ -256,8 +256,8 @@ class SpellScript : public _SpellScript
bool _Validate(SpellInfo const* entry);
bool _Load(Spell* spell);
void _InitHit();
- bool _IsEffectPrevented(SpellEffIndex effIndex) { return m_hitPreventEffectMask & (1<<effIndex); }
- bool _IsDefaultEffectPrevented(SpellEffIndex effIndex) { return m_hitPreventDefaultEffectMask & (1<<effIndex); }
+ bool _IsEffectPrevented(SpellEffIndex effIndex) { return (m_hitPreventEffectMask & (1 << effIndex)) != 0; }
+ bool _IsDefaultEffectPrevented(SpellEffIndex effIndex) { return (m_hitPreventDefaultEffectMask & (1 << effIndex)) != 0; }
void _PrepareScriptCall(SpellScriptHookType hookType);
void _FinishScriptCall();
bool IsInCheckCastHook() const;
diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h
index 28722ae70f4..d1db202ca68 100644
--- a/src/server/game/Texts/CreatureTextMgr.h
+++ b/src/server/game/Texts/CreatureTextMgr.h
@@ -82,11 +82,17 @@ typedef std::unordered_map<uint64, CreatureTextRepeatGroup> CreatureTextRepeatMa
class CreatureTextMgr
{
- friend class ACE_Singleton<CreatureTextMgr, ACE_Null_Mutex>;
- CreatureTextMgr() { };
+ private:
+ CreatureTextMgr() { };
+ ~CreatureTextMgr() { };
public:
- ~CreatureTextMgr() { };
+ static CreatureTextMgr* instance()
+ {
+ static CreatureTextMgr* instance = new CreatureTextMgr();
+ return instance;
+ }
+
void LoadCreatureTexts();
void LoadCreatureTextLocales();
CreatureTextMap const& GetTextMap() const { return mTextMap; }
@@ -113,7 +119,7 @@ class CreatureTextMgr
LocaleCreatureTextMap mLocaleTextMap;
};
-#define sCreatureTextMgr ACE_Singleton<CreatureTextMgr, ACE_Null_Mutex>::instance()
+#define sCreatureTextMgr CreatureTextMgr::instance()
template<class Builder>
class CreatureTextLocalizer
diff --git a/src/server/game/Tickets/TicketMgr.h b/src/server/game/Tickets/TicketMgr.h
index 5bfe78abbba..00b4e228fab 100644
--- a/src/server/game/Tickets/TicketMgr.h
+++ b/src/server/game/Tickets/TicketMgr.h
@@ -19,7 +19,6 @@
#define _TICKETMGR_H
#include <string>
-#include <ace/Singleton.h>
#include "ObjectMgr.h"
@@ -85,7 +84,7 @@ public:
GmTicket(Player* player);
~GmTicket();
- bool IsClosed() const { return _closedBy; }
+ bool IsClosed() const { return _closedBy != 0; }
bool IsCompleted() const { return _completed; }
bool IsFromPlayer(uint64 guid) const { return guid == _playerGuid; }
bool IsAssigned() const { return _assignedTo != 0; }
@@ -174,13 +173,17 @@ typedef std::map<uint32, GmTicket*> GmTicketList;
class TicketMgr
{
- friend class ACE_Singleton<TicketMgr, ACE_Null_Mutex>;
-
private:
TicketMgr();
~TicketMgr();
public:
+ static TicketMgr* instance()
+ {
+ static TicketMgr* instance = new TicketMgr();
+ return instance;
+ }
+
void LoadTickets();
void LoadSurveys();
@@ -246,6 +249,6 @@ protected:
uint64 _lastChange;
};
-#define sTicketMgr ACE_Singleton<TicketMgr, ACE_Null_Mutex>::instance()
+#define sTicketMgr TicketMgr::instance()
#endif // _TICKETMGR_H
diff --git a/src/server/game/Tools/CharacterDatabaseCleaner.cpp b/src/server/game/Tools/CharacterDatabaseCleaner.cpp
index 758c78b685d..11ed54bfa81 100644
--- a/src/server/game/Tools/CharacterDatabaseCleaner.cpp
+++ b/src/server/game/Tools/CharacterDatabaseCleaner.cpp
@@ -108,7 +108,7 @@ void CharacterDatabaseCleaner::CheckUnique(const char* column, const char* table
bool CharacterDatabaseCleaner::AchievementProgressCheck(uint32 criteria)
{
- return sAchievementMgr->GetAchievementCriteria(criteria);
+ return sAchievementMgr->GetAchievementCriteria(criteria) != nullptr;
}
void CharacterDatabaseCleaner::CleanCharacterAchievementProgress()
@@ -118,7 +118,7 @@ void CharacterDatabaseCleaner::CleanCharacterAchievementProgress()
bool CharacterDatabaseCleaner::SkillCheck(uint32 skill)
{
- return sSkillLineStore.LookupEntry(skill);
+ return sSkillLineStore.LookupEntry(skill) != nullptr;
}
void CharacterDatabaseCleaner::CleanCharacterSkills()
@@ -142,7 +142,7 @@ bool CharacterDatabaseCleaner::TalentCheck(uint32 talent_id)
if (!talentInfo)
return false;
- return sTalentTabStore.LookupEntry(talentInfo->TalentTab);
+ return sTalentTabStore.LookupEntry(talentInfo->TalentTab) != nullptr;
}
void CharacterDatabaseCleaner::CleanCharacterTalent()
diff --git a/src/server/game/Warden/WardenCheckMgr.cpp b/src/server/game/Warden/WardenCheckMgr.cpp
index 44bab1d31b3..98ed381a2b1 100644
--- a/src/server/game/Warden/WardenCheckMgr.cpp
+++ b/src/server/game/Warden/WardenCheckMgr.cpp
@@ -164,7 +164,7 @@ void WardenCheckMgr::LoadWardenOverrides()
uint32 count = 0;
- ACE_WRITE_GUARD(ACE_RW_Mutex, g, _checkStoreLock);
+ boost::unique_lock<boost::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
do
{
diff --git a/src/server/game/Warden/WardenCheckMgr.h b/src/server/game/Warden/WardenCheckMgr.h
index 8f2fa37400d..c9e26283060 100644
--- a/src/server/game/Warden/WardenCheckMgr.h
+++ b/src/server/game/Warden/WardenCheckMgr.h
@@ -20,6 +20,8 @@
#define _WARDENCHECKMGR_H
#include <map>
+#include <boost/thread/locks.hpp>
+#include <boost/thread/shared_mutex.hpp>
#include "Cryptography/BigNumber.h"
enum WardenActions
@@ -48,11 +50,17 @@ struct WardenCheckResult
class WardenCheckMgr
{
- friend class ACE_Singleton<WardenCheckMgr, ACE_Null_Mutex>;
- WardenCheckMgr();
- ~WardenCheckMgr();
+ private:
+ WardenCheckMgr();
+ ~WardenCheckMgr();
public:
+ static WardenCheckMgr* instance()
+ {
+ static WardenCheckMgr* instance = new WardenCheckMgr();
+ return instance;
+ }
+
// We have a linear key without any gaps, so we use vector for fast access
typedef std::vector<WardenCheck*> CheckContainer;
typedef std::map<uint32, WardenCheckResult*> CheckResultContainer;
@@ -66,13 +74,13 @@ class WardenCheckMgr
void LoadWardenChecks();
void LoadWardenOverrides();
- ACE_RW_Mutex _checkStoreLock;
+ boost::shared_mutex _checkStoreLock;
private:
CheckContainer CheckStore;
CheckResultContainer CheckResultStore;
};
-#define sWardenCheckMgr ACE_Singleton<WardenCheckMgr, ACE_Null_Mutex>::instance()
+#define sWardenCheckMgr WardenCheckMgr::instance()
#endif
diff --git a/src/server/game/Warden/WardenWin.cpp b/src/server/game/Warden/WardenWin.cpp
index 3428708ed69..9de4ff0958e 100644
--- a/src/server/game/Warden/WardenWin.cpp
+++ b/src/server/game/Warden/WardenWin.cpp
@@ -206,7 +206,7 @@ void WardenWin::RequestData()
ByteBuffer buff;
buff << uint8(WARDEN_SMSG_CHEAT_CHECKS_REQUEST);
- ACE_READ_GUARD(ACE_RW_Mutex, g, sWardenCheckMgr->_checkStoreLock);
+ boost::shared_lock<boost::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
for (uint32 i = 0; i < sWorld->getIntConfig(CONFIG_WARDEN_NUM_OTHER_CHECKS); ++i)
{
@@ -369,7 +369,7 @@ void WardenWin::HandleData(ByteBuffer &buff)
uint8 type;
uint16 checkFailed = 0;
- ACE_READ_GUARD(ACE_RW_Mutex, g, sWardenCheckMgr->_checkStoreLock);
+ boost::shared_lock<boost::shared_mutex> lock(sWardenCheckMgr->_checkStoreLock);
for (std::list<uint16>::iterator itr = _currentChecks.begin(); itr != _currentChecks.end(); ++itr)
{
diff --git a/src/server/game/Weather/Weather.cpp b/src/server/game/Weather/Weather.cpp
index 79b4fbd8c69..cab232931b9 100644
--- a/src/server/game/Weather/Weather.cpp
+++ b/src/server/game/Weather/Weather.cpp
@@ -95,7 +95,7 @@ bool Weather::ReGenerate()
// season source http://aa.usno.navy.mil/data/docs/EarthSeasons.html
time_t gtime = sWorld->GetGameTime();
struct tm ltime;
- ACE_OS::localtime_r(&gtime, &ltime);
+ localtime_r(&gtime, &ltime);
uint32 season = ((ltime.tm_yday - 78 + 365)/91)%4;
static char const* seasonName[WEATHER_SEASONS] = { "spring", "summer", "fall", "winter" };
diff --git a/src/server/game/Weather/WeatherMgr.cpp b/src/server/game/Weather/WeatherMgr.cpp
index 7a48d935a21..f18809b107a 100644
--- a/src/server/game/Weather/WeatherMgr.cpp
+++ b/src/server/game/Weather/WeatherMgr.cpp
@@ -24,7 +24,6 @@
#include "Weather.h"
#include "Log.h"
#include "ObjectMgr.h"
-#include "AutoPtr.h"
#include "Player.h"
#include "WorldPacket.h"
#include "Opcodes.h"
@@ -35,7 +34,7 @@ namespace WeatherMgr
namespace
{
- typedef std::unordered_map<uint32, Trinity::AutoPtr<Weather, ACE_Null_Mutex> > WeatherMap;
+ typedef std::unordered_map<uint32, std::shared_ptr<Weather> > WeatherMap;
typedef std::unordered_map<uint32, WeatherData> WeatherZoneMap;
WeatherMap m_weathers;
diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp
index 1bc22317d11..e5dc9ba1a4c 100644
--- a/src/server/game/World/World.cpp
+++ b/src/server/game/World/World.cpp
@@ -20,6 +20,7 @@
\ingroup world
*/
+#include <atomic>
#include "Common.h"
#include "Memory.h"
#include "DatabaseEnv.h"
@@ -83,9 +84,10 @@
#include "BattlefieldMgr.h"
#include "TransportMgr.h"
-ACE_Atomic_Op<ACE_Thread_Mutex, bool> World::m_stopEvent = false;
+
+std::atomic<bool> World::m_stopEvent(false);
uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
-ACE_Atomic_Op<ACE_Thread_Mutex, uint32> World::m_worldLoopCounter = 0;
+std::atomic<uint32> World::m_worldLoopCounter(0);
float World::m_MaxVisibleDistanceOnContinents = DEFAULT_VISIBILITY_DISTANCE;
float World::m_MaxVisibleDistanceInInstances = DEFAULT_VISIBILITY_INSTANCE;
@@ -681,7 +683,7 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GROUP] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Group", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_GUILD] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Guild", false);
m_bool_configs[CONFIG_ALLOW_TWO_SIDE_INTERACTION_AUCTION] = sConfigMgr->GetBoolDefault("AllowTwoSide.Interaction.Auction", false);
- m_bool_configs[CONFIG_ALLOW_TWO_SIDE_TRADE] = sConfigMgr->GetBoolDefault("AllowTwoSide.trade", false);
+ m_bool_configs[CONFIG_ALLOW_TWO_SIDE_TRADE] = sConfigMgr->GetBoolDefault("AllowTwoSide.Trade", false);
m_int_configs[CONFIG_STRICT_PLAYER_NAMES] = sConfigMgr->GetIntDefault ("StrictPlayerNames", 0);
m_int_configs[CONFIG_STRICT_CHARTER_NAMES] = sConfigMgr->GetIntDefault ("StrictCharterNames", 0);
m_int_configs[CONFIG_STRICT_PET_NAMES] = sConfigMgr->GetIntDefault ("StrictPetNames", 0);
@@ -990,7 +992,7 @@ void World::LoadConfigSettings(bool reload)
m_int_configs[CONFIG_CHATFLOOD_MESSAGE_DELAY] = sConfigMgr->GetIntDefault("ChatFlood.MessageDelay", 1);
m_int_configs[CONFIG_CHATFLOOD_MUTE_TIME] = sConfigMgr->GetIntDefault("ChatFlood.MuteTime", 10);
- m_bool_configs[CONFIG_EVENT_ANNOUNCE] = sConfigMgr->GetIntDefault("Event.Announce", false);
+ m_bool_configs[CONFIG_EVENT_ANNOUNCE] = sConfigMgr->GetBoolDefault("Event.Announce", false);
m_float_configs[CONFIG_CREATURE_FAMILY_FLEE_ASSISTANCE_RADIUS] = sConfigMgr->GetFloatDefault("CreatureFamilyFleeAssistanceRadius", 30.0f);
m_float_configs[CONFIG_CREATURE_FAMILY_ASSISTANCE_RADIUS] = sConfigMgr->GetFloatDefault("CreatureFamilyAssistanceRadius", 10.0f);
@@ -1301,8 +1303,6 @@ void World::LoadConfigSettings(bool reload)
m_bool_configs[CONFIG_IP_BASED_ACTION_LOGGING] = sConfigMgr->GetBoolDefault("Allow.IP.Based.Action.Logging", false);
- m_bool_configs[CONFIG_IP_BASED_LOGIN_LOGGING] = sConfigMgr->GetBoolDefault("Wrong.Password.Login.Logging", false);
-
// call ScriptMgr if we're reloading the configuration
if (reload)
sScriptMgr->OnConfigLoad(reload);
@@ -1816,7 +1816,7 @@ void World::SetInitialWorldSettings()
//one second is 1000 -(tested on win system)
/// @todo Get rid of magic numbers
tm localTm;
- ACE_OS::localtime_r(&m_gameTime, &localTm);
+ localtime_r(&m_gameTime, &localTm);
mail_timer = ((((localTm.tm_hour + 20) % 24)* HOUR * IN_MILLISECONDS) / m_timers[WUPDATE_AUCTIONS].GetInterval());
//1440
mail_timer_expires = ((DAY * IN_MILLISECONDS) / (m_timers[WUPDATE_AUCTIONS].GetInterval()));
@@ -2636,7 +2636,7 @@ void World::ShutdownMsg(bool show, Player* player)
void World::ShutdownCancel()
{
// nothing cancel or too later
- if (!m_ShutdownTimer || m_stopEvent.value())
+ if (!m_ShutdownTimer || m_stopEvent)
return;
ServerMessageType msgid = (m_ShutdownMask & SHUTDOWN_MASK_RESTART) ? SERVER_MSG_RESTART_CANCELLED : SERVER_MSG_SHUTDOWN_CANCELLED;
@@ -2779,7 +2779,7 @@ void World::UpdateRealmCharCount(uint32 accountId)
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_COUNT);
stmt->setUInt32(0, accountId);
PreparedQueryResultFuture result = CharacterDatabase.AsyncQuery(stmt);
- m_realmCharCallbacks.insert(result);
+ m_realmCharCallbacks.push_back(std::move(result));
}
void World::_UpdateRealmCharCount(PreparedQueryResult resultCharCount)
@@ -2827,7 +2827,7 @@ void World::InitDailyQuestResetTime()
// FIX ME: client not show day start time
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = 6;
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2861,7 +2861,7 @@ void World::InitRandomBGResetTime()
// generate time by config
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = getIntConfig(CONFIG_RANDOM_BG_RESET_HOUR);
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -2889,7 +2889,7 @@ void World::InitGuildResetTime()
// generate time by config
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
localTm.tm_hour = getIntConfig(CONFIG_GUILD_RESET_HOUR);
localTm.tm_min = 0;
localTm.tm_sec = 0;
@@ -3015,7 +3015,7 @@ void World::ResetMonthlyQuests()
// generate time
time_t curTime = time(NULL);
tm localTm;
- ACE_OS::localtime_r(&curTime, &localTm);
+ localtime_r(&curTime, &localTm);
int month = localTm.tm_mon;
int year = localTm.tm_year;
@@ -3180,19 +3180,17 @@ void World::ProcessQueryCallbacks()
{
PreparedQueryResult result;
- while (!m_realmCharCallbacks.is_empty())
+ for (std::deque<std::future<PreparedQueryResult>>::iterator itr = m_realmCharCallbacks.begin(); itr != m_realmCharCallbacks.end(); )
{
- ACE_Future<PreparedQueryResult> lResult;
- ACE_Time_Value timeout = ACE_Time_Value::zero;
- if (m_realmCharCallbacks.next_readable(lResult, &timeout) != 1)
- break;
-
- if (lResult.ready())
+ if ((*itr).wait_for(std::chrono::seconds(0)) != std::future_status::ready)
{
- lResult.get(result);
- _UpdateRealmCharCount(result);
- lResult.cancel();
+ ++itr;
+ continue;
}
+
+ result = (*itr).get();
+ _UpdateRealmCharCount(result);
+ itr = m_realmCharCallbacks.erase(itr);
}
}
diff --git a/src/server/game/World/World.h b/src/server/game/World/World.h
index 8a371bd75c2..557a0e62965 100644
--- a/src/server/game/World/World.h
+++ b/src/server/game/World/World.h
@@ -25,12 +25,11 @@
#include "Common.h"
#include "Timer.h"
-#include <ace/Singleton.h>
-#include <ace/Atomic_Op.h>
#include "SharedDefines.h"
#include "QueryResult.h"
#include "Callback.h"
+#include <atomic>
#include <map>
#include <set>
#include <list>
@@ -163,7 +162,6 @@ enum WorldBoolConfigs
CONFIG_STATS_LIMITS_ENABLE,
CONFIG_INSTANCES_RESET_ANNOUNCE,
CONFIG_IP_BASED_ACTION_LOGGING,
- CONFIG_IP_BASED_LOGIN_LOGGING,
BOOL_CONFIG_VALUE_COUNT
};
@@ -539,10 +537,13 @@ struct CharacterNameData
class World
{
public:
- static ACE_Atomic_Op<ACE_Thread_Mutex, uint32> m_worldLoopCounter;
+ static World* instance()
+ {
+ static World* instance = new World();
+ return instance;
+ }
- World();
- ~World();
+ static std::atomic<uint32> m_worldLoopCounter;
WorldSession* FindSession(uint32 id) const;
void AddSession(WorldSession* s);
@@ -655,7 +656,7 @@ class World
void ShutdownMsg(bool show = false, Player* player = NULL);
static uint8 GetExitCode() { return m_ExitCode; }
static void StopNow(uint8 exitcode) { m_stopEvent = true; m_ExitCode = exitcode; }
- static bool IsStopped() { return m_stopEvent.value(); }
+ static bool IsStopped() { return m_stopEvent; }
void Update(uint32 diff);
@@ -780,7 +781,10 @@ class World
void ResetGuildCap();
void ResetCurrencyWeekCap();
private:
- static ACE_Atomic_Op<ACE_Thread_Mutex, bool> m_stopEvent;
+ World();
+ ~World();
+
+ static std::atomic<bool> m_stopEvent;
static uint8 m_ExitCode;
uint32 m_ShutdownTimer;
uint32 m_ShutdownMask;
@@ -832,7 +836,7 @@ class World
static int32 m_visibility_notify_periodInBGArenas;
// CLI command holder to be thread safe
- ACE_Based::LockedQueue<CliCommandHolder*, ACE_Thread_Mutex> cliCmdQueue;
+ LockedQueue<CliCommandHolder*> cliCmdQueue;
// scheduled reset times
time_t m_NextDailyQuestReset;
@@ -847,7 +851,7 @@ class World
// sessions that are added async
void AddSession_(WorldSession* s);
- ACE_Based::LockedQueue<WorldSession*, ACE_Thread_Mutex> addSessQueue;
+ LockedQueue<WorldSession*> addSessQueue;
// used versions
std::string m_DBVersion;
@@ -862,11 +866,11 @@ class World
void LoadCharacterNameData();
void ProcessQueryCallbacks();
- ACE_Future_Set<PreparedQueryResult> m_realmCharCallbacks;
+ std::deque<std::future<PreparedQueryResult>> m_realmCharCallbacks;
};
extern uint32 realmID;
-#define sWorld ACE_Singleton<World, ACE_Null_Mutex>::instance()
+#define sWorld World::instance()
#endif
/// @}