Skip to content

Commit e402036

Browse files
committed
BattleGround: Wave 1 of safeguards against race conditions
BattleGround handler and BattleGround class still need to be massively reworked but this makes it a little bette
1 parent b29fd6e commit e402036

15 files changed

+151
-41
lines changed

src/game/BattleGround/BattleGround.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ Team BattleGround::GetPrematureWinner()
14771477
*/
14781478
void BattleGround::OnObjectDBLoad(Creature* creature)
14791479
{
1480-
const BattleGroundEventIdx eventId = sBattleGroundMgr.GetCreatureEventIndex(creature->GetDbGuid());
1480+
const BattleGroundEventIdx eventId = GetBgMap()->GetMapDataContainer().GetCreatureEventIndex(creature->GetDbGuid());
14811481
if (eventId.event1 == BG_EVENT_NONE)
14821482
return;
14831483

@@ -1525,7 +1525,7 @@ uint32 BattleGround::GetSingleGameObjectGuid(uint8 event1, uint8 event2)
15251525
*/
15261526
void BattleGround::OnObjectDBLoad(GameObject* obj)
15271527
{
1528-
const BattleGroundEventIdx eventId = sBattleGroundMgr.GetGameObjectEventIndex(obj->GetDbGuid());
1528+
const BattleGroundEventIdx eventId = GetBgMap()->GetMapDataContainer().GetGameObjectEventIndex(obj->GetDbGuid());
15291529
if (eventId.event1 == BG_EVENT_NONE)
15301530
return;
15311531

src/game/BattleGround/BattleGround.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ class BattleGround
541541
// returns the other team index
542542
static PvpTeamIndex GetOtherTeamIndex(PvpTeamIndex teamIdx) { return teamIdx == TEAM_INDEX_ALLIANCE ? TEAM_INDEX_HORDE : TEAM_INDEX_ALLIANCE; }
543543

544-
// checke if player is inside battleground
544+
// check if player is inside battleground
545545
bool IsPlayerInBattleGround(ObjectGuid /*playerGuid*/);
546546

547547
// Handle script condition fulfillment

src/game/BattleGround/BattleGroundAB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ void BattleGroundAB::HandlePlayerClickedOnFlag(Player* player, GameObject* go)
268268
uint32 factionStrig = 0;
269269

270270
// process battleground event
271-
uint8 event = (sBattleGroundMgr.GetGameObjectEventIndex(go->GetDbGuid())).event1;
271+
uint8 event = (GetBgMap()->GetMapDataContainer().GetGameObjectEventIndex(go->GetDbGuid())).event1;
272272
if (event >= BG_AB_MAX_NODES) // not a node
273273
return;
274274

src/game/BattleGround/BattleGroundAV.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,12 +616,12 @@ void BattleGroundAV::HandlePlayerClickedOnFlag(Player* player, GameObject* go)
616616

617617
DEBUG_LOG("BattleGroundAV: Player from team %u clicked on gameobject entry %u", player->GetTeam(), go->GetEntry());
618618

619-
uint8 event = (sBattleGroundMgr.GetGameObjectEventIndex(go->GetDbGuid())).event1;
619+
uint8 event = (GetBgMap()->GetMapDataContainer().GetGameObjectEventIndex(go->GetDbGuid())).event1;
620620
if (event >= BG_AV_MAX_NODES) // not a node
621621
return;
622622
AVNodeIds node = AVNodeIds(event);
623623

624-
switch ((sBattleGroundMgr.GetGameObjectEventIndex(go->GetDbGuid())).event2 % BG_AV_MAX_STATES)
624+
switch ((GetBgMap()->GetMapDataContainer().GetGameObjectEventIndex(go->GetDbGuid())).event2 % BG_AV_MAX_STATES)
625625
{
626626
case POINT_CONTROLLED:
627627
ProcessPlayerAssaultsPoint(player, node);

src/game/BattleGround/BattleGroundHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void WorldSession::HandleBattlemasterHelloOpcode(WorldPacket& recv_data)
5252
if (uint32 pauseTimer = pCreature->GetInteractionPauseTimer())
5353
pCreature->GetMotionMaster()->PauseWaypoints(pauseTimer);
5454

55-
BattleGroundTypeId bgTypeId = sBattleGroundMgr.GetBattleMasterBG(pCreature->GetEntry());
55+
BattleGroundTypeId bgTypeId = GetPlayer()->GetMap()->GetMapDataContainer().GetBattleMasterBG(pCreature->GetEntry());
5656

5757
if (bgTypeId == BATTLEGROUND_TYPE_NONE)
5858
return;

src/game/BattleGround/BattleGroundMgr.cpp

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void BattleGroundMgr::DeleteAllBattleGrounds()
6969
*/
7070
void BattleGroundMgr::Update(uint32 /*diff*/)
7171
{
72-
72+
m_messager.Execute(this);
7373
}
7474

7575
/**
@@ -623,9 +623,9 @@ uint32 BattleGroundMgr::GetPrematureFinishTime() const
623623
/**
624624
Method that loads battlemaster entries from DB
625625
*/
626-
void BattleGroundMgr::LoadBattleMastersEntry()
626+
void BattleGroundMgr::LoadBattleMastersEntry(bool reload)
627627
{
628-
m_battleMastersMap.clear(); // need for reload case
628+
std::shared_ptr<BattleMastersMap> newBattleMastersMap = std::make_shared<BattleMastersMap>();
629629

630630
auto queryResult = WorldDatabase.Query("SELECT entry,bg_template FROM battlemaster_entry");
631631

@@ -657,10 +657,23 @@ void BattleGroundMgr::LoadBattleMastersEntry()
657657
continue;
658658
}
659659

660-
m_battleMastersMap[entry] = BattleGroundTypeId(bgTypeId);
660+
(*newBattleMastersMap)[entry] = BattleGroundTypeId(bgTypeId);
661661
}
662662
while (queryResult->NextRow());
663663

664+
m_battleMastersMap = newBattleMastersMap;
665+
666+
if (reload)
667+
{
668+
sMapMgr.DoForAllMaps([battleMasters = newBattleMastersMap](Map* map)
669+
{
670+
map->GetMessager().AddMessage([battleMasters](Map* map)
671+
{
672+
map->GetMapDataContainer().SetBattleMastersMap(battleMasters);
673+
});
674+
});
675+
}
676+
664677
sLog.outString(">> Loaded %u battlemaster entries", count);
665678
sLog.outString();
666679
}
@@ -710,15 +723,15 @@ bool BattleGroundMgr::IsBgWeekend(BattleGroundTypeId bgTypeId)
710723
/**
711724
Method that loads battleground events used in battleground scripts
712725
*/
713-
void BattleGroundMgr::LoadBattleEventIndexes()
726+
void BattleGroundMgr::LoadBattleEventIndexes(bool reload)
714727
{
715728
BattleGroundEventIdx events;
716729
events.event1 = BG_EVENT_NONE;
717730
events.event2 = BG_EVENT_NONE;
718-
m_gameObjectBattleEventIndexMap.clear(); // need for reload case
719-
m_gameObjectBattleEventIndexMap[static_cast<uint32>(-1)] = events;
720-
m_creatureBattleEventIndexMap.clear(); // need for reload case
721-
m_creatureBattleEventIndexMap[static_cast<uint32>(-1)] = events;
731+
std::shared_ptr<GameObjectBattleEventIndexesMap> newGameObjectIndexes = std::make_shared<GameObjectBattleEventIndexesMap>();
732+
(*newGameObjectIndexes)[static_cast<uint32>(-1)] = events;
733+
std::shared_ptr<CreatureBattleEventIndexesMap> newCreatureIndexes = std::make_shared<CreatureBattleEventIndexesMap>();
734+
(*newCreatureIndexes)[static_cast<uint32>(-1)] = events;
722735

723736
uint32 count = 0;
724737

@@ -807,14 +820,29 @@ void BattleGroundMgr::LoadBattleEventIndexes()
807820
}
808821

809822
if (gameobject)
810-
m_gameObjectBattleEventIndexMap[dbTableGuidLow] = events;
823+
(*newGameObjectIndexes)[dbTableGuidLow] = events;
811824
else
812-
m_creatureBattleEventIndexMap[dbTableGuidLow] = events;
825+
(*newCreatureIndexes)[dbTableGuidLow] = events;
813826

814827
++count;
815828
}
816829
while (queryResult->NextRow());
817830

831+
m_gameObjectBattleEventIndexMap = newGameObjectIndexes;
832+
m_creatureBattleEventIndexMap = newCreatureIndexes;
833+
834+
if (reload)
835+
{
836+
sMapMgr.DoForAllMaps([gameobjects = newGameObjectIndexes, creatures = newCreatureIndexes](Map* map)
837+
{
838+
map->GetMessager().AddMessage([gameobjects, creatures](Map* map)
839+
{
840+
map->GetMapDataContainer().SetGameObjectEventIndexes(gameobjects);
841+
map->GetMapDataContainer().SetCreatureEventIndexes(creatures);
842+
});
843+
});
844+
}
845+
818846
sLog.outString(">> Loaded %u battleground eventindexes", count);
819847
sLog.outString();
820848
}

src/game/BattleGround/BattleGroundMgr.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,35 +73,40 @@ class BattleGroundMgr
7373

7474
void ToggleTesting();
7575

76-
void LoadBattleMastersEntry();
76+
void LoadBattleMastersEntry(bool reload);
7777
BattleGroundTypeId GetBattleMasterBG(uint32 entry) const
7878
{
79-
BattleMastersMap::const_iterator itr = m_battleMastersMap.find(entry);
80-
if (itr != m_battleMastersMap.end())
79+
BattleMastersMap::const_iterator itr = m_battleMastersMap->find(entry);
80+
if (itr != m_battleMastersMap->end())
8181
return itr->second;
8282

8383
return BATTLEGROUND_TYPE_NONE;
8484
}
85+
std::shared_ptr<BattleMastersMap> GetBattleMastersMap() const { return m_battleMastersMap; }
8586

86-
void LoadBattleEventIndexes();
87+
void LoadBattleEventIndexes(bool reload);
8788
const BattleGroundEventIdx GetCreatureEventIndex(uint32 dbGuid) const
8889
{
89-
CreatureBattleEventIndexesMap::const_iterator itr = m_creatureBattleEventIndexMap.find(dbGuid);
90-
if (itr != m_creatureBattleEventIndexMap.end())
90+
CreatureBattleEventIndexesMap::const_iterator itr = m_creatureBattleEventIndexMap->find(dbGuid);
91+
if (itr != m_creatureBattleEventIndexMap->end())
9192
return itr->second;
9293

93-
return m_creatureBattleEventIndexMap.find(static_cast<uint32>(-1))->second;
94+
return m_creatureBattleEventIndexMap->find(static_cast<uint32>(-1))->second;
9495
}
9596

97+
std::shared_ptr<CreatureBattleEventIndexesMap> GetCreatureEventIndexes() const { return m_creatureBattleEventIndexMap; }
98+
9699
const BattleGroundEventIdx GetGameObjectEventIndex(uint32 dbGuid) const
97100
{
98-
GameObjectBattleEventIndexesMap::const_iterator itr = m_gameObjectBattleEventIndexMap.find(dbGuid);
99-
if (itr != m_gameObjectBattleEventIndexMap.end())
101+
GameObjectBattleEventIndexesMap::const_iterator itr = m_gameObjectBattleEventIndexMap->find(dbGuid);
102+
if (itr != m_gameObjectBattleEventIndexMap->end())
100103
return itr->second;
101104

102-
return m_gameObjectBattleEventIndexMap.find(static_cast<uint32>(-1))->second;
105+
return m_gameObjectBattleEventIndexMap->find(static_cast<uint32>(-1))->second;
103106
}
104107

108+
std::shared_ptr<GameObjectBattleEventIndexesMap> GetGameObjectEventIndexes() const { return m_gameObjectBattleEventIndexMap; }
109+
105110
bool IsTesting() const { return m_testing; }
106111

107112
static BattleGroundQueueTypeId BgQueueTypeId(BattleGroundTypeId /*bgTypeId*/);
@@ -116,16 +121,20 @@ class BattleGroundMgr
116121
uint32 GetMinLevelForBattleGroundBracketId(BattleGroundBracketId bracket_id, BattleGroundTypeId bgTypeId) const;
117122
uint32 GetMaxLevelForBattleGroundBracketId(BattleGroundBracketId bracket_id, BattleGroundTypeId bgTypeId) const;
118123
BattleGroundBracketId GetBattleGroundBracketIdFromLevel(BattleGroundTypeId bgTypeId, uint32 playerLevel) const;
124+
125+
Messager<BattleGroundMgr>& GetMessager() { return m_messager; }
119126
private:
120127
std::mutex schedulerLock;
121-
BattleMastersMap m_battleMastersMap;
122-
CreatureBattleEventIndexesMap m_creatureBattleEventIndexMap;
123-
GameObjectBattleEventIndexesMap m_gameObjectBattleEventIndexMap;
128+
std::shared_ptr<BattleMastersMap> m_battleMastersMap;
129+
std::shared_ptr<CreatureBattleEventIndexesMap> m_creatureBattleEventIndexMap;
130+
std::shared_ptr<GameObjectBattleEventIndexesMap> m_gameObjectBattleEventIndexMap;
124131

125132
/* Battlegrounds */
126133
BattleGroundSet m_battleGrounds[MAX_BATTLEGROUND_TYPE_ID];
127134
bool m_testing;
128135
std::set<uint32> m_usedRefloot;
136+
137+
Messager<BattleGroundMgr> m_messager;
129138
};
130139

131140
#define sBattleGroundMgr MaNGOS::Singleton<BattleGroundMgr>::Instance()

src/game/Chat/Level3.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,10 @@ bool ChatHandler::HandleReloadItemRequiredTragetCommand(char* /*args*/)
763763
bool ChatHandler::HandleReloadBattleEventCommand(char* /*args*/)
764764
{
765765
sLog.outString("Re-Loading BattleGround Eventindexes...");
766-
sBattleGroundMgr.LoadBattleEventIndexes();
766+
sBattleGroundMgr.GetMessager().AddMessage([](BattleGroundMgr* mgr)
767+
{
768+
mgr->LoadBattleEventIndexes(true);
769+
});
767770
SendGlobalSysMessage("DB table `gameobject_battleground` and `creature_battleground` reloaded.");
768771
return true;
769772
}

src/game/Chat/debugcmds.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,10 @@ bool ChatHandler::HandleDebugGetItemStateCommand(char* args)
723723

724724
bool ChatHandler::HandleDebugBattlegroundCommand(char* /*args*/)
725725
{
726-
sBattleGroundMgr.ToggleTesting();
726+
sBattleGroundMgr.GetMessager().AddMessage([](BattleGroundMgr* mgr)
727+
{
728+
mgr->ToggleTesting();
729+
});
727730
return true;
728731
}
729732

src/game/Entities/Creature.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ bool Creature::CanInteractWithBattleMaster(Player* pPlayer, bool msg) const
10151015
if (!isBattleMaster())
10161016
return false;
10171017

1018-
BattleGroundTypeId bgTypeId = sBattleGroundMgr.GetBattleMasterBG(GetEntry());
1018+
BattleGroundTypeId bgTypeId = GetMap()->GetMapDataContainer().GetBattleMasterBG(GetEntry());
10191019
if (bgTypeId == BATTLEGROUND_TYPE_NONE)
10201020
return false;
10211021

0 commit comments

Comments
 (0)