Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [quote]From 19328e7d4f883ed6dff07efb287ed5c968e337b0 Mon Sep 17 00:00:00 2001
- From: Opterman <fasteruo@gmail.com>
- Date: Sun, 22 Nov 2009 13:57:40 +0100
- Subject: [PATCH] Map Updater v.07
- ---
- src/game/BattleGround.cpp | 16 +-
- src/game/BattleGround.h | 62 ++---
- src/game/BattleGroundBE.cpp | 6 +-
- src/game/BattleGroundDS.cpp | 42 +++-
- src/game/BattleGroundDS.h | 1 +
- src/game/BattleGroundHandler.cpp | 18 +-
- src/game/BattleGroundMgr.cpp | 398 +++++++++++++++++---------------
- src/game/BattleGroundMgr.h | 60 +++--
- src/game/BattleGroundNA.cpp | 6 +-
- src/game/BattleGroundRL.cpp | 5 +-
- src/game/BattleGroundRV.cpp | 33 +++-
- src/game/BattleGroundRV.h | 1 +
- src/game/CharacterHandler.cpp | 21 ++
- src/game/DBCStructure.h | 12 +-
- src/game/DBCfmt.h | 2 +-
- src/game/GameEventMgr.cpp | 363 +++++++++++++----------------
- src/game/GameEventMgr.h | 42 ++--
- src/game/GridDefines.h | 2 +-
- src/game/Group.cpp | 4 +-
- src/game/InstanceData.cpp | 10 +-
- src/game/Level2.cpp | 102 +++-----
- src/game/Map.cpp | 208 +++++++++++++++--
- src/game/Map.h | 23 ++-
- src/game/MapInstanced.cpp | 4 +-
- src/game/MapManager.cpp | 60 ++++--
- src/game/MapManager.h | 9 +-
- src/game/MovementHandler.cpp | 22 ++-
- src/game/Object.cpp | 5 +-
- src/game/ObjectMgr.cpp | 9 +-
- src/game/Player.cpp | 44 +++-
- src/game/Player.h | 4 +-
- src/game/Spell.cpp | 10 +
- src/game/Spell.h | 2 +-
- src/game/World.cpp | 38 ++--
- src/game/World.h | 6 +-
- src/game/WorldSession.cpp | 8 +-
- src/game/WorldSession.h | 14 ++
- src/mangosd/Master.cpp | 81 +++++--
- src/mangosd/WorldRunnable.cpp | 1 +
- src/mangosd/mangosd.conf.dist.in | 33 +++-
- src/shared/Database/Database.cpp | 10 +
- src/shared/Database/Database.h | 29 ++--
- src/shared/Database/DatabaseImpl.h | 64 +++---
- src/shared/Database/SqlDelayThread.cpp | 4 +-
- src/shared/Database/SqlDelayThread.h | 4 +-
- src/shared/Threading.cpp | 22 ++
- src/shared/Threading.h | 6 +-
- 47 files changed, 1195 insertions(+), 731 deletions(-)
- diff --git a/src/game/BattleGround.cpp b/src/game/BattleGround.cpp
- index 9034853..35eafcc 100644
- --- a/src/game/BattleGround.cpp
- +++ b/src/game/BattleGround.cpp
- @@ -212,7 +212,7 @@ BattleGround::BattleGround()
- m_Status = STATUS_NONE;
- m_ClientInstanceID = 0;
- m_EndTime = 0;
- - m_QueueId = QUEUE_ID_MAX_LEVEL_19;
- + m_QueueId = 0;
- m_InvitedAlliance = 0;
- m_InvitedHorde = 0;
- m_ArenaType = 0;
- @@ -304,7 +304,7 @@ BattleGround::~BattleGround()
- m_Map->SetUnload();
- // remove from bg free slot queue
- - this->RemoveFromBGFreeSlotQueue();
- + RemoveFromBGFreeSlotQueue();
- for(BattleGroundScoreMap::const_iterator itr = m_PlayerScores.begin(); itr != m_PlayerScores.end(); ++itr)
- delete itr->second;
- @@ -984,6 +984,14 @@ void BattleGround::BlockMovement(Player *plr)
- plr->SetClientControl(plr, 0); // movement disabled NOTE: the effect will be automatically removed by client when the player is teleported from the battleground, so no need to send with uint8(1) in RemovePlayerAtLeave()
- }
- +void BattleGround::RemovePlayer(Player * /*player */, uint64 /*guid*/)
- +{
- + if(!isArena() || GetStatus() != STATUS_WAIT_LEAVE)
- + return;
- +
- + CheckArenaWinConditions();
- +}
- +
- void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPacket)
- {
- uint32 team = GetPlayerTeam(guid);
- @@ -1114,7 +1122,7 @@ void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac
- // this method is called when no players remains in battleground
- void BattleGround::Reset()
- {
- - SetQueueId(QUEUE_ID_MAX_LEVEL_19);
- + SetQueueId(0);
- SetWinner(WINNER_NONE);
- SetStatus(STATUS_WAIT_QUEUE);
- SetStartTime(0);
- @@ -1742,6 +1750,8 @@ void BattleGround::HandleKillPlayer( Player *player, Player *killer )
- // to be able to remove insignia -- ONLY IN BattleGrounds
- if (!isArena())
- player->SetFlag( UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE );
- + else if(GetStatus() == STATUS_IN_PROGRESS && killer)
- + CheckArenaWinConditions();
- }
- // return the player's team based on battlegroundplayer info
- diff --git a/src/game/BattleGround.h b/src/game/BattleGround.h
- index d35e114..bd0d4b3 100644
- --- a/src/game/BattleGround.h
- +++ b/src/game/BattleGround.h
- @@ -165,19 +165,6 @@ enum BattleGroundQueueTypeId
- };
- #define MAX_BATTLEGROUND_QUEUE_TYPES 10
- -enum BGQueueIdBasedOnLevel // queue_id for level ranges
- -{
- - QUEUE_ID_MAX_LEVEL_19 = 0,
- - QUEUE_ID_MAX_LEVEL_29 = 1,
- - QUEUE_ID_MAX_LEVEL_39 = 2,
- - QUEUE_ID_MAX_LEVEL_49 = 3,
- - QUEUE_ID_MAX_LEVEL_59 = 4,
- - QUEUE_ID_MAX_LEVEL_69 = 5,
- - QUEUE_ID_MAX_LEVEL_79 = 6,
- - QUEUE_ID_MAX_LEVEL_80 = 7
- -};
- -#define MAX_BATTLEGROUND_QUEUES 8
- -
- enum ScoreType
- {
- SCORE_KILLING_BLOWS = 1,
- @@ -307,26 +294,26 @@ class BattleGround
- /* Battleground */
- // Get methods:
- - char const* GetName() const { return m_Name; }
- - BattleGroundTypeId GetTypeID() const { return m_TypeID; }
- - BGQueueIdBasedOnLevel GetQueueId() const { return m_QueueId; }
- - uint32 GetInstanceID() const { return m_InstanceID; }
- - BattleGroundStatus GetStatus() const { return m_Status; }
- - uint32 GetClientInstanceID() const { return m_ClientInstanceID; }
- - uint32 GetStartTime() const { return m_StartTime; }
- - uint32 GetEndTime() const { return m_EndTime; }
- - uint32 GetMaxPlayers() const { return m_MaxPlayers; }
- - uint32 GetMinPlayers() const { return m_MinPlayers; }
- -
- - uint32 GetMinLevel() const { return m_LevelMin; }
- - uint32 GetMaxLevel() const { return m_LevelMax; }
- -
- - uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayersPerTeam; }
- - uint32 GetMinPlayersPerTeam() const { return m_MinPlayersPerTeam; }
- -
- - int32 GetStartDelayTime() const { return m_StartDelayTime; }
- - uint8 GetArenaType() const { return m_ArenaType; }
- - uint8 GetWinner() const { return m_Winner; }
- + char const* GetName() const { return m_Name; }
- + BattleGroundTypeId GetTypeID() const { return m_TypeID; }
- + uint8 GetQueueId() const { return m_QueueId; }
- + uint32 GetInstanceID() const { return m_InstanceID; }
- + BattleGroundStatus GetStatus() const { return m_Status; }
- + uint32 GetClientInstanceID() const { return m_ClientInstanceID; }
- + uint32 GetStartTime() const { return m_StartTime; }
- + uint32 GetEndTime() const { return m_EndTime; }
- + uint32 GetMaxPlayers() const { return m_MaxPlayers; }
- + uint32 GetMinPlayers() const { return m_MinPlayers; }
- +
- + uint32 GetMinLevel() const { return m_LevelMin; }
- + uint32 GetMaxLevel() const { return m_LevelMax; }
- +
- + uint32 GetMaxPlayersPerTeam() const { return m_MaxPlayersPerTeam; }
- + uint32 GetMinPlayersPerTeam() const { return m_MinPlayersPerTeam; }
- +
- + int32 GetStartDelayTime() const { return m_StartDelayTime; }
- + uint8 GetArenaType() const { return m_ArenaType; }
- + uint8 GetWinner() const { return m_Winner; }
- uint32 GetBattlemasterEntry() const;
- uint32 GetBonusHonorFromKill(uint32 kills) const;
- @@ -334,11 +321,11 @@ class BattleGround
- void SetName(char const* Name) { m_Name = Name; }
- void SetTypeID(BattleGroundTypeId TypeID) { m_TypeID = TypeID; }
- //here we can count minlevel and maxlevel for players
- - void SetQueueId(BGQueueIdBasedOnLevel ID)
- + void SetQueueId(uint8 ID)
- {
- m_QueueId = ID;
- uint8 diff = (m_TypeID == BATTLEGROUND_AV) ? 1 : 0;
- - this->SetLevelRange((ID + 1) * 10 + diff, (ID + 2) * 10 - ((diff + 1) % 2));
- + SetLevelRange((ID + 1) * 10 + diff, (ID + 2) * 10 - ((diff + 1) % 2));
- }
- void SetInstanceID(uint32 InstanceID) { m_InstanceID = InstanceID; }
- void SetStatus(BattleGroundStatus Status) { m_Status = Status; }
- @@ -372,6 +359,7 @@ class BattleGround
- return m_InvitedHorde;
- }
- bool HasFreeSlots() const;
- + bool CanUnload(){ return m_SetDeleteThis; }
- uint32 GetFreeSlotsForTeam(uint32 Team) const;
- bool isArena() const { return m_IsArena; }
- @@ -561,7 +549,7 @@ class BattleGround
- BattleGroundScoreMap m_PlayerScores; // Player scores
- // must be implemented in BG subclass
- - virtual void RemovePlayer(Player * /*player*/, uint64 /*guid*/) {}
- + virtual void RemovePlayer(Player *player, uint64 guid);
- /* Player lists, those need to be accessible by inherited classes */
- BattleGroundPlayerMap m_Players;
- @@ -585,7 +573,7 @@ class BattleGround
- uint32 m_StartTime;
- bool m_ArenaBuffSpawned; // to cache if arenabuff event is started (cause bool is faster than checking IsActiveEvent)
- int32 m_EndTime; // it is set to 120000 when bg is ending and it decreases itself
- - BGQueueIdBasedOnLevel m_QueueId;
- + uint8 m_QueueId;
- uint8 m_ArenaType; // 2=2v2, 3=3v3, 5=5v5
- bool m_InBGFreeSlotQueue; // used to make sure that BG is only once inserted into the BattleGroundMgr.BGFreeSlotQueue[bgTypeId] deque
- bool m_SetDeleteThis; // used for safe deletion of the bg after end / all players leave
- diff --git a/src/game/BattleGroundBE.cpp b/src/game/BattleGroundBE.cpp
- index fddc8bc..50fa9ad 100644
- --- a/src/game/BattleGroundBE.cpp
- +++ b/src/game/BattleGroundBE.cpp
- @@ -73,7 +73,7 @@ void BattleGroundBE::AddPlayer(Player *plr)
- UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE));
- }
- -void BattleGroundBE::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- +void BattleGroundBE::RemovePlayer(Player* player, uint64 guid)
- {
- if (GetStatus() == STATUS_WAIT_LEAVE)
- return;
- @@ -81,7 +81,7 @@ void BattleGroundBE::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE));
- - CheckArenaWinConditions();
- + BattleGround::RemovePlayer(player, guid);
- }
- void BattleGroundBE::HandleKillPlayer(Player *player, Player *killer)
- @@ -99,8 +99,6 @@ void BattleGroundBE::HandleKillPlayer(Player *player, Player *killer)
- UpdateWorldState(0x9f1, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0x9f0, GetAlivePlayersCountByTeam(HORDE));
- -
- - CheckArenaWinConditions();
- }
- bool BattleGroundBE::HandlePlayerUnderMap(Player *player)
- diff --git a/src/game/BattleGroundDS.cpp b/src/game/BattleGroundDS.cpp
- index 78360b9..43c6f53 100644
- --- a/src/game/BattleGroundDS.cpp
- +++ b/src/game/BattleGroundDS.cpp
- @@ -19,6 +19,7 @@
- #include "Player.h"
- #include "BattleGround.h"
- #include "BattleGroundDS.h"
- +#include "WorldPacket.h"
- #include "Language.h"
- BattleGroundDS::BattleGroundDS()
- @@ -51,6 +52,7 @@ void BattleGroundDS::StartingEventCloseDoors()
- void BattleGroundDS::StartingEventOpenDoors()
- {
- + OpenDoorEvent(BG_EVENT_DOOR);
- }
- void BattleGroundDS::AddPlayer(Player *plr)
- @@ -60,21 +62,49 @@ void BattleGroundDS::AddPlayer(Player *plr)
- BattleGroundDSScore* sc = new BattleGroundDSScore;
- m_PlayerScores[plr->GetGUID()] = sc;
- -}
- -void BattleGroundDS::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
- -{
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- }
- -void BattleGroundDS::HandleKillPlayer(Player* player, Player* killer)
- -{
- +void BattleGroundDS::RemovePlayer(Player * player, uint64 guid)
- + {
- + if (GetStatus() == STATUS_WAIT_LEAVE)
- + return;
- +
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- +
- + BattleGround::RemovePlayer(player, guid);
- + }
- +
- + void BattleGroundDS::HandleKillPlayer(Player* player, Player* killer)
- + {
- + if (GetStatus() != STATUS_IN_PROGRESS)
- + return;
- +
- + if (!killer)
- + {
- + sLog.outError("BattleGroundDS: Killer player not found");
- + return;
- + }
- +
- BattleGround::HandleKillPlayer(player, killer);
- -}
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- + }
- void BattleGroundDS::HandleAreaTrigger(Player * /*Source*/, uint32 /*Trigger*/)
- {
- }
- +void BattleGroundDS::FillInitialWorldStates(WorldPacket &data)
- +{
- + data << uint32(0xe11) << uint32(GetAlivePlayersCountByTeam(ALLIANCE)); // 7
- + data << uint32(0xe10) << uint32(GetAlivePlayersCountByTeam(HORDE)); // 8
- + data << uint32(0xe1a) << uint32(1); // 9
- +}
- +
- bool BattleGroundDS::SetupBattleGround()
- {
- return true;
- diff --git a/src/game/BattleGroundDS.h b/src/game/BattleGroundDS.h
- index 44a6cfb..3097e4f 100644
- --- a/src/game/BattleGroundDS.h
- +++ b/src/game/BattleGroundDS.h
- @@ -45,6 +45,7 @@ class BattleGroundDS : public BattleGround
- void RemovePlayer(Player *plr, uint64 guid);
- void HandleAreaTrigger(Player *Source, uint32 Trigger);
- bool SetupBattleGround();
- + virtual void FillInitialWorldStates(WorldPacket &d);
- void HandleKillPlayer(Player* player, Player *killer);
- };
- #endif
- diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp
- index f6d3229..8f83701 100644
- --- a/src/game/BattleGroundHandler.cpp
- +++ b/src/game/BattleGroundHandler.cpp
- @@ -104,7 +104,7 @@ void WorldSession::HandleBattlemasterJoinOpcode( WorldPacket & recv_data )
- // get bg instance or bg template if instance not found
- BattleGround *bg = NULL;
- if (instanceId)
- - bg = sBattleGroundMgr.GetBattleGroundThroughClientInstance(instanceId, bgTypeId);
- + bg = sBattleGroundMgr.GetBattleGround(instanceId, bgTypeId, _player->GetBGLevelQueueId());
- if (!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId)))
- {
- @@ -153,7 +153,7 @@ void WorldSession::HandleBattlemasterJoinOpcode( WorldPacket & recv_data )
- {
- sLog.outDebug("Battleground: the following players are joining as group:");
- GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, grp, bgTypeId, 0, false, isPremade, 0);
- - uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundQueueIdFromLevel());
- + uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBGLevelQueueId());
- for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
- {
- Player *member = itr->getSource();
- @@ -174,7 +174,7 @@ void WorldSession::HandleBattlemasterJoinOpcode( WorldPacket & recv_data )
- else
- {
- GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, NULL, bgTypeId, 0, false, isPremade, 0);
- - uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundQueueIdFromLevel());
- + uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBGLevelQueueId());
- // already checked if queueSlot is valid, now just get it
- uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId);
- @@ -184,7 +184,7 @@ void WorldSession::HandleBattlemasterJoinOpcode( WorldPacket & recv_data )
- SendPacket(&data);
- sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName());
- }
- - sBattleGroundMgr.ScheduleQueueUpdate(0, 0, bgQueueTypeId, bgTypeId, _player->GetBattleGroundQueueIdFromLevel());
- + sBattleGroundMgr.ScheduleQueueUpdate(0, 0, bgQueueTypeId, bgTypeId, _player->GetBGLevelQueueId());
- }
- void WorldSession::HandleBattleGroundPlayerPositionsOpcode( WorldPacket & /*recv_data*/ )
- @@ -427,7 +427,7 @@ void WorldSession::HandleBattleFieldPortOpcode( WorldPacket &recv_data )
- bgQueue.RemovePlayer(_player->GetGUID(), true);
- // player left queue, we should update it - do not update Arena Queue
- if (!ginfo.ArenaType)
- - sBattleGroundMgr.ScheduleQueueUpdate(ginfo.ArenaTeamRating, ginfo.ArenaType, bgQueueTypeId, bgTypeId, _player->GetBattleGroundQueueIdFromLevel());
- + sBattleGroundMgr.ScheduleQueueUpdate(ginfo.ArenaTeamRating, ginfo.ArenaType, bgQueueTypeId, bgTypeId, _player->GetBGLevelQueueId());
- SendPacket(&data);
- sLog.outDebug("Battleground: player %s (%u) left queue for bgtype %u, queue type %u.", _player->GetName(), _player->GetGUIDLow(), bg->GetTypeID(), bgQueueTypeId);
- break;
- @@ -509,7 +509,7 @@ void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ )
- bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId);
- if (!bg)
- continue;
- - uint32 avgTime = bgQueue.GetAverageQueueWaitTime(&ginfo, _player->GetBattleGroundQueueIdFromLevel());
- + uint32 avgTime = bgQueue.GetAverageQueueWaitTime(&ginfo, _player->GetBGLevelQueueId());
- // send status in BattleGround Queue
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, i, STATUS_WAIT_QUEUE, avgTime, getMSTimeDiff(ginfo.JoinTime, getMSTime()), arenaType);
- SendPacket(&data);
- @@ -679,7 +679,7 @@ void WorldSession::HandleBattlemasterJoinArena( WorldPacket & recv_data )
- sLog.outDebug("Battleground: arena team id %u, leader %s queued with rating %u for type %u",_player->GetArenaTeamId(arenaslot),_player->GetName(),arenaRating,arenatype);
- GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, grp, bgTypeId, arenatype, isRated, false, arenaRating, ateamId);
- - uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundQueueIdFromLevel());
- + uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBGLevelQueueId());
- for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
- {
- Player *member = itr->getSource();
- @@ -701,7 +701,7 @@ void WorldSession::HandleBattlemasterJoinArena( WorldPacket & recv_data )
- else
- {
- GroupQueueInfo * ginfo = bgQueue.AddGroup(_player, NULL, bgTypeId, arenatype, isRated, false, arenaRating, ateamId);
- - uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBattleGroundQueueIdFromLevel());
- + uint32 avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, _player->GetBGLevelQueueId());
- uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId);
- WorldPacket data;
- @@ -710,7 +710,7 @@ void WorldSession::HandleBattlemasterJoinArena( WorldPacket & recv_data )
- SendPacket(&data);
- sLog.outDebug("Battleground: player joined queue for arena, skirmish, bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName());
- }
- - sBattleGroundMgr.ScheduleQueueUpdate(arenaRating, arenatype, bgQueueTypeId, bgTypeId, _player->GetBattleGroundQueueIdFromLevel());
- + sBattleGroundMgr.ScheduleQueueUpdate(arenaRating, arenatype, bgQueueTypeId, bgTypeId, _player->GetBGLevelQueueId());
- }
- void WorldSession::HandleReportPvPAFK( WorldPacket & recv_data )
- diff --git a/src/game/BattleGroundMgr.cpp b/src/game/BattleGroundMgr.cpp
- index 44014c4..66f16f3 100644
- --- a/src/game/BattleGroundMgr.cpp
- +++ b/src/game/BattleGroundMgr.cpp
- @@ -54,12 +54,19 @@ INSTANTIATE_SINGLETON_1( BattleGroundMgr );
- BattleGroundQueue::BattleGroundQueue()
- {
- + uint8 MaxQueueId = BattleGroundMgr::GetMaxQueueId();
- +
- + m_QueuedGroups.resize(MaxQueueId);
- + for(uint8 p = 0; p < MaxQueueId; p++)
- + m_QueuedGroups[p].resize(BG_QUEUE_GROUP_TYPES_COUNT);
- +
- for(uint32 i = 0; i < BG_TEAMS_COUNT; i++)
- {
- - for(uint32 j = 0; j < MAX_BATTLEGROUND_QUEUES; j++)
- + for(uint32 j = 0; j < MaxQueueId; j++)
- {
- m_SumOfWaitTimes[i][j] = 0;
- m_WaitTimeLastPlayer[i][j] = 0;
- + m_WaitTimes[i][j].resize(COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME);
- for(uint32 k = 0; k < COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME; k++)
- m_WaitTimes[i][j][k] = 0;
- }
- @@ -69,16 +76,20 @@ BattleGroundQueue::BattleGroundQueue()
- BattleGroundQueue::~BattleGroundQueue()
- {
- m_QueuedPlayers.clear();
- - for (int i = 0; i < MAX_BATTLEGROUND_QUEUES; i++)
- +
- + uint32 MaxQueueId = sBattleGroundMgr.GetMaxQueueId();
- + for (int i = 0; i < MaxQueueId; i++)
- {
- for(uint32 j = 0; j < BG_QUEUE_GROUP_TYPES_COUNT; j++)
- {
- - for(GroupsQueueType::iterator itr = m_QueuedGroups[i][j].begin(); itr!= m_QueuedGroups[i][j].end(); ++itr)
- + for(GroupQueueInfoList::iterator itr = m_QueuedGroups[i][j].begin(); itr!= m_QueuedGroups[i][j].end(); ++itr)
- delete (*itr);
- m_QueuedGroups[i][j].clear();
- }
- - }
- -}
- + m_QueuedGroups[i].clear();
- + }
- + m_QueuedGroups.clear();
- + }
- /*********************************************************/
- /*** BATTLEGROUND QUEUE SELECTION POOLS ***/
- @@ -99,8 +110,8 @@ bool BattleGroundQueue::SelectionPool::KickGroup(uint32 size)
- {
- //find maxgroup or LAST group with size == size and kick it
- bool found = false;
- - GroupsQueueType::iterator groupToKick = SelectedGroups.begin();
- - for (GroupsQueueType::iterator itr = groupToKick; itr != SelectedGroups.end(); ++itr)
- + GroupQueueInfoList::iterator groupToKick = SelectedGroups.begin();
- + for (GroupQueueInfoList::iterator itr = groupToKick; itr != SelectedGroups.end(); ++itr)
- {
- if (abs((int32)((*itr)->Players.size() - size)) <= 1)
- {
- @@ -150,7 +161,7 @@ bool BattleGroundQueue::SelectionPool::AddGroup(GroupQueueInfo *ginfo, uint32 de
- // add group or player (grp == NULL) to bg queue with the given leader and bg specifications
- GroupQueueInfo * BattleGroundQueue::AddGroup(Player *leader, Group* grp, BattleGroundTypeId BgTypeId, uint8 ArenaType, bool isRated, bool isPremade, uint32 arenaRating, uint32 arenateamid)
- {
- - BGQueueIdBasedOnLevel queue_id = leader->GetBattleGroundQueueIdFromLevel();
- + uint8 queue_id = leader->GetBGLevelQueueId();
- // create new ginfo
- GroupQueueInfo* ginfo = new GroupQueueInfo;
- @@ -222,7 +233,7 @@ GroupQueueInfo * BattleGroundQueue::AddGroup(Player *leader, Group* grp, BattleG
- uint32 qHorde = 0;
- uint32 qAlliance = 0;
- uint32 q_min_level = (queue_id + 1) * 10;
- - GroupsQueueType::const_iterator itr;
- + GroupQueueInfoList::const_iterator itr;
- for(itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].begin(); itr != m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].end(); ++itr)
- if (!(*itr)->IsInvitedToBGInstanceGUID)
- qAlliance += (*itr)->Players.size();
- @@ -250,7 +261,7 @@ GroupQueueInfo * BattleGroundQueue::AddGroup(Player *leader, Group* grp, BattleG
- return ginfo;
- }
- -void BattleGroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id)
- +void BattleGroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, uint8 queue_id)
- {
- uint32 timeInQueue = getMSTimeDiff(ginfo->JoinTime, getMSTime());
- uint8 team_index = BG_TEAM_ALLIANCE; //default set to BG_TEAM_ALLIANCE - or non rated arenas!
- @@ -278,7 +289,7 @@ void BattleGroundQueue::PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* g
- (*lastPlayerAddedPointer) %= COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME;
- }
- -uint32 BattleGroundQueue::GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id)
- +uint32 BattleGroundQueue::GetAverageQueueWaitTime(GroupQueueInfo* ginfo, uint8 queue_id)
- {
- uint8 team_index = BG_TEAM_ALLIANCE; //default set to BG_TEAM_ALLIANCE - or non rated arenas!
- if (!ginfo->ArenaType)
- @@ -317,13 +328,13 @@ void BattleGroundQueue::RemovePlayer(const uint64& guid, bool decreaseInvitedCou
- }
- GroupQueueInfo* group = itr->second.GroupInfo;
- - GroupsQueueType::iterator group_itr, group_itr_tmp;
- + GroupQueueInfoList::iterator group_itr, group_itr_tmp;
- // mostly people with the highest levels are in battlegrounds, thats why
- // we count from MAX_BATTLEGROUND_QUEUES - 1 to 0
- // variable index removes useless searching in other team's queue
- uint32 index = (group->Team == HORDE) ? BG_TEAM_HORDE : BG_TEAM_ALLIANCE;
- - for (int32 queue_id_tmp = MAX_BATTLEGROUND_QUEUES - 1; queue_id_tmp >= 0 && queue_id == -1; --queue_id_tmp)
- + for (int32 queue_id_tmp = sBattleGroundMgr.GetMaxQueueId() - 1; queue_id_tmp >= 0 && queue_id == -1; --queue_id_tmp)
- {
- //we must check premade and normal team's queue - because when players from premade are joining bg,
- //they leave groupinfo so we can't use its players size to find out index
- @@ -453,7 +464,7 @@ bool BattleGroundQueue::InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * b
- ginfo->IsInvitedToBGInstanceGUID = bg->GetInstanceID();
- BattleGroundTypeId bgTypeId = bg->GetTypeID();
- BattleGroundQueueTypeId bgQueueTypeId = BattleGroundMgr::BGQueueTypeId(bgTypeId, bg->GetArenaType());
- - BGQueueIdBasedOnLevel queue_id = bg->GetQueueId();
- + uint8 queue_id = bg->GetQueueId();
- // set ArenaTeamId for rated matches
- if (bg->isArena() && bg->isRated())
- @@ -507,13 +518,13 @@ This function is inviting players to already running battlegrounds
- Invitation type is based on config file
- large groups are disadvantageous, because they will be kicked first if invitation type = 1
- */
- -void BattleGroundQueue::FillPlayersToBG(BattleGround* bg, BGQueueIdBasedOnLevel queue_id)
- +void BattleGroundQueue::FillPlayersToBG(BattleGround* bg, uint8 queue_id)
- {
- int32 hordeFree = bg->GetFreeSlotsForTeam(HORDE);
- int32 aliFree = bg->GetFreeSlotsForTeam(ALLIANCE);
- //iterator for iterating through bg queue
- - GroupsQueueType::const_iterator Ali_itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
- + GroupQueueInfoList::const_iterator Ali_itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].begin();
- //count of groups in queue - used to stop cycles
- uint32 aliCount = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE].size();
- //index to queue which group is current
- @@ -521,7 +532,7 @@ void BattleGroundQueue::FillPlayersToBG(BattleGround* bg, BGQueueIdBasedOnLevel
- for (; aliIndex < aliCount && m_SelectionPools[BG_TEAM_ALLIANCE].AddGroup((*Ali_itr), aliFree); aliIndex++)
- ++Ali_itr;
- //the same thing for horde
- - GroupsQueueType::const_iterator Horde_itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_HORDE].begin();
- + GroupQueueInfoList::const_iterator Horde_itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_HORDE].begin();
- uint32 hordeCount = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_HORDE].size();
- uint32 hordeIndex = 0;
- for (; hordeIndex < hordeCount && m_SelectionPools[BG_TEAM_HORDE].AddGroup((*Horde_itr), hordeFree); hordeIndex++)
- @@ -585,14 +596,14 @@ void BattleGroundQueue::FillPlayersToBG(BattleGround* bg, BGQueueIdBasedOnLevel
- // this method checks if premade versus premade battleground is possible
- // then after 30 mins (default) in queue it moves premade group to normal queue
- // it tries to invite as much players as it can - to MaxPlayersPerTeam, because premade groups have more than MinPlayersPerTeam players
- -bool BattleGroundQueue::CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
- +bool BattleGroundQueue::CheckPremadeMatch(uint8 queue_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam)
- {
- //check match
- if (!m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE].empty() && !m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_HORDE].empty())
- {
- //start premade match
- //if groups aren't invited
- - GroupsQueueType::const_iterator ali_group, horde_group;
- + GroupQueueInfoList::const_iterator ali_group, horde_group;
- for( ali_group = m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE].begin(); ali_group != m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE].end(); ++ali_group)
- if (!(*ali_group)->IsInvitedToBGInstanceGUID)
- break;
- @@ -606,7 +617,7 @@ bool BattleGroundQueue::CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32
- m_SelectionPools[BG_TEAM_HORDE].AddGroup((*horde_group), MaxPlayersPerTeam);
- //add groups/players from normal queue to size of bigger group
- uint32 maxPlayers = std::max(m_SelectionPools[BG_TEAM_ALLIANCE].GetPlayerCount(), m_SelectionPools[BG_TEAM_HORDE].GetPlayerCount());
- - GroupsQueueType::const_iterator itr;
- + GroupQueueInfoList::const_iterator itr;
- for(uint32 i = 0; i < BG_TEAMS_COUNT; i++)
- {
- for(itr = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin(); itr != m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + i].end(); ++itr)
- @@ -629,7 +640,7 @@ bool BattleGroundQueue::CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32
- {
- if (!m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE + i].empty())
- {
- - GroupsQueueType::iterator itr = m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE + i].begin();
- + GroupQueueInfoList::iterator itr = m_QueuedGroups[queue_id][BG_QUEUE_PREMADE_ALLIANCE + i].begin();
- if (!(*itr)->IsInvitedToBGInstanceGUID && ((*itr)->JoinTime < time_before || (*itr)->Players.size() < MinPlayersPerTeam))
- {
- //we must insert group to normal queue and erase pointer from premade queue
- @@ -643,9 +654,9 @@ bool BattleGroundQueue::CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32
- }
- // this method tries to create battleground or arena with MinPlayersPerTeam against MinPlayersPerTeam
- -bool BattleGroundQueue::CheckNormalMatch(BattleGround* bg_template, BGQueueIdBasedOnLevel queue_id, uint32 minPlayers, uint32 maxPlayers)
- +bool BattleGroundQueue::CheckNormalMatch(BattleGround* bg_template, uint8 queue_id, uint32 minPlayers, uint32 maxPlayers)
- {
- - GroupsQueueType::const_iterator itr_team[BG_TEAMS_COUNT];
- + GroupQueueInfoList::const_iterator itr_team[BG_TEAMS_COUNT];
- for(uint32 i = 0; i < BG_TEAMS_COUNT; i++)
- {
- itr_team[i] = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + i].begin();
- @@ -686,7 +697,7 @@ bool BattleGroundQueue::CheckNormalMatch(BattleGround* bg_template, BGQueueIdBas
- }
- // this method will check if we can invite players to same faction skirmish match
- -bool BattleGroundQueue::CheckSkirmishForSameFaction(BGQueueIdBasedOnLevel queue_id, uint32 minPlayersPerTeam)
- +bool BattleGroundQueue::CheckSkirmishForSameFaction(uint8 queue_id, uint32 minPlayersPerTeam)
- {
- if (m_SelectionPools[BG_TEAM_ALLIANCE].GetPlayerCount() < minPlayersPerTeam && m_SelectionPools[BG_TEAM_HORDE].GetPlayerCount() < minPlayersPerTeam)
- return false;
- @@ -704,13 +715,13 @@ bool BattleGroundQueue::CheckSkirmishForSameFaction(BGQueueIdBasedOnLevel queue_
- //store last ginfo pointer
- GroupQueueInfo* ginfo = m_SelectionPools[teamIndex].SelectedGroups.back();
- //set itr_team to group that was added to selection pool latest
- - GroupsQueueType::iterator itr_team = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].begin();
- + GroupQueueInfoList::iterator itr_team = m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].begin();
- for(; itr_team != m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr_team)
- if (ginfo == *itr_team)
- break;
- if (itr_team == m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end())
- return false;
- - GroupsQueueType::iterator itr_team2 = itr_team;
- + GroupQueueInfoList::iterator itr_team2 = itr_team;
- ++itr_team2;
- //invite players to other selection pool
- for(; itr_team2 != m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr_team2)
- @@ -723,14 +734,14 @@ bool BattleGroundQueue::CheckSkirmishForSameFaction(BGQueueIdBasedOnLevel queue_
- return false;
- //here we have correct 2 selections and we need to change one teams team and move selection pool teams to other team's queue
- - for(GroupsQueueType::iterator itr = m_SelectionPools[otherTeam].SelectedGroups.begin(); itr != m_SelectionPools[otherTeam].SelectedGroups.end(); ++itr)
- + for(GroupQueueInfoList::iterator itr = m_SelectionPools[otherTeam].SelectedGroups.begin(); itr != m_SelectionPools[otherTeam].SelectedGroups.end(); ++itr)
- {
- //set correct team
- (*itr)->Team = otherTeamId;
- //add team to other queue
- m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + otherTeam].push_front(*itr);
- //remove team from old queue
- - GroupsQueueType::iterator itr2 = itr_team;
- + GroupQueueInfoList::iterator itr2 = itr_team;
- ++itr2;
- for(; itr2 != m_QueuedGroups[queue_id][BG_QUEUE_NORMAL_ALLIANCE + teamIndex].end(); ++itr2)
- {
- @@ -749,7 +760,7 @@ this method is called when group is inserted, or player / group is removed from
- it must be called after fully adding the members of a group to ensure group joining
- should be called from BattleGround::RemovePlayer function in some cases
- */
- -void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated, uint32 arenaRating)
- +void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, uint8 queue_id, uint8 arenaType, bool isRated, uint32 arenaRating)
- {
- //ACE_Guard<ACE_Recursive_Thread_Mutex> guard(m_Lock);
- //if no players in queue - do nothing
- @@ -781,9 +792,9 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve
- FillPlayersToBG(bg, queue_id);
- // now everything is set, invite players
- - for(GroupsQueueType::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE].SelectedGroups.end(); ++citr)
- + for(GroupQueueInfoList::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE].SelectedGroups.end(); ++citr)
- InviteGroupToBG((*citr), bg, (*citr)->Team);
- - for(GroupsQueueType::const_iterator citr = m_SelectionPools[BG_TEAM_HORDE].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_HORDE].SelectedGroups.end(); ++citr)
- + for(GroupQueueInfoList::const_iterator citr = m_SelectionPools[BG_TEAM_HORDE].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_HORDE].SelectedGroups.end(); ++citr)
- InviteGroupToBG((*citr), bg, (*citr)->Team);
- if (!bg->HasFreeSlots())
- @@ -810,31 +821,9 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve
- if (bg_template->isArena())
- {
- if (sBattleGroundMgr.isArenaTesting())
- - {
- - MaxPlayersPerTeam = 1;
- - MinPlayersPerTeam = 1;
- - }
- + MaxPlayersPerTeam = MinPlayersPerTeam = 1;
- else
- - {
- - //this switch can be much shorter
- - MaxPlayersPerTeam = arenaType;
- - MinPlayersPerTeam = arenaType;
- - /*switch(arenaType)
- - {
- - case ARENA_TYPE_2v2:
- - MaxPlayersPerTeam = 2;
- - MinPlayersPerTeam = 2;
- - break;
- - case ARENA_TYPE_3v3:
- - MaxPlayersPerTeam = 3;
- - MinPlayersPerTeam = 3;
- - break;
- - case ARENA_TYPE_5v5:
- - MaxPlayersPerTeam = 5;
- - MinPlayersPerTeam = 5;
- - break;
- - }*/
- - }
- + MaxPlayersPerTeam = MinPlayersPerTeam = arenaType;
- }
- m_SelectionPools[BG_TEAM_ALLIANCE].Init();
- @@ -854,7 +843,7 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve
- }
- //invite those selection pools
- for(uint32 i = 0; i < BG_TEAMS_COUNT; i++)
- - for(GroupsQueueType::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
- + for(GroupQueueInfoList::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
- InviteGroupToBG((*citr), bg2, (*citr)->Team);
- //start bg
- bg2->StartBattleGround();
- @@ -881,7 +870,7 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve
- // invite those selection pools
- for(uint32 i = 0; i < BG_TEAMS_COUNT; i++)
- - for(GroupsQueueType::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
- + for(GroupQueueInfoList::const_iterator citr = m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.begin(); citr != m_SelectionPools[BG_TEAM_ALLIANCE + i].SelectedGroups.end(); ++citr)
- InviteGroupToBG((*citr), bg2, (*citr)->Team);
- // start bg
- bg2->StartBattleGround();
- @@ -926,7 +915,7 @@ void BattleGroundQueue::Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLeve
- // we need to find 2 teams which will play next game
- - GroupsQueueType::iterator itr_team[BG_TEAMS_COUNT];
- + GroupQueueInfoList::iterator itr_team[BG_TEAMS_COUNT];
- //optimalization : --- we dont need to use selection_pools - each update we select max 2 groups
- @@ -1117,8 +1106,6 @@ void BGQueueRemoveEvent::Abort(uint64 /*e_time*/)
- BattleGroundMgr::BattleGroundMgr() : m_AutoDistributionTimeChecker(0), m_ArenaTesting(false)
- {
- - for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++)
- - m_BattleGrounds[i].clear();
- m_NextRatingDiscardUpdate = sWorld.getConfig(CONFIG_ARENA_RATING_DISCARD_TIMER);
- m_Testing=false;
- }
- @@ -1130,54 +1117,63 @@ BattleGroundMgr::~BattleGroundMgr()
- void BattleGroundMgr::DeleteAllBattleGrounds()
- {
- - for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++)
- + // destroy template battlegrounds that listed only in queues (other already terminated)
- +
- + for(MapBattleGround::iterator itr = m_BattleGrounds.begin(); itr != m_BattleGrounds.end(); itr++)
- {
- - for(BattleGroundSet::iterator itr = m_BattleGrounds[i].begin(); itr != m_BattleGrounds[i].end();)
- + for(BattleGroundSet::iterator itr_bg = itr->second.begin(); itr_bg != itr->second.end(); itr_bg++)
- {
- - BattleGround * bg = itr->second;
- - m_BattleGrounds[i].erase(itr++);
- - if (!m_ClientBattleGroundIds[i][bg->GetQueueId()].empty())
- - m_ClientBattleGroundIds[i][bg->GetQueueId()].erase(bg->GetClientInstanceID());
- + BattleGround * bg = itr_bg->second;
- + uint8 BgQueueId = bg->GetQueueId();
- + BattleGroundTypeId bgTypeId = bg->GetTypeID();
- +
- + itr->second.erase(itr_bg);
- + if (m_ClientBattleGroundIds.find(bgTypeId) != m_ClientBattleGroundIds.end() &&
- + m_ClientBattleGroundIds[bgTypeId].find(BgQueueId) != m_ClientBattleGroundIds[bgTypeId].end())
- + {
- + m_ClientBattleGroundIds[bgTypeId][BgQueueId].erase(bg->GetClientInstanceID());
- + MapBGClientId::iterator iterInst = m_ClientBattleGroundIds[bgTypeId][BgQueueId].find(bg->GetClientInstanceID());
- + if(iterInst != m_ClientBattleGroundIds[bgTypeId][BgQueueId].end())
- + m_ClientBattleGroundIds[bgTypeId][BgQueueId].erase(iterInst);
- + }
- +
- + // ~BattleGround call unregistring BG from queue
- + if(BGFreeSlotQueue.find(bgTypeId) != BGFreeSlotQueue.end())
- + {
- + while(!BGFreeSlotQueue[bgTypeId].empty())
- + delete BGFreeSlotQueue[bgTypeId].front();
- + }
- +
- delete bg;
- }
- - }
- + }
- +}
- - // destroy template battlegrounds that listed only in queues (other already terminated)
- - for(uint32 bgTypeId = 0; bgTypeId < MAX_BATTLEGROUND_TYPE_ID; ++bgTypeId)
- - {
- - // ~BattleGround call unregistring BG from queue
- - while(!BGFreeSlotQueue[bgTypeId].empty())
- - delete BGFreeSlotQueue[bgTypeId].front();
- - }
- +void BattleGroundMgr::DestroyBattleGround(BattleGround *BG)
- +{
- + uint8 QueueId = BG->GetQueueId();
- + BattleGroundTypeId bgTypeId = BG->GetTypeID();
- +
- + if(m_BattleGrounds.find(bgTypeId) == m_BattleGrounds.end())
- + return;
- +
- + BattleGroundSet::iterator itr = m_BattleGrounds[bgTypeId].find(BG->GetInstanceID());
- +
- + if(itr != m_BattleGrounds[bgTypeId].end())
- + m_BattleGrounds[bgTypeId].erase(itr);
- +
- + MapBGClientId BgMap = m_ClientBattleGroundIds[bgTypeId][QueueId];
- + MapBGClientId::iterator iter = BgMap.find(BG->GetClientInstanceID());
- +
- + if(BgMap.end() != iter)
- + BgMap.erase(iter);
- +
- + delete BG;
- }
- // used to update running battlegrounds, and delete finished ones
- void BattleGroundMgr::Update(uint32 diff)
- {
- - BattleGroundSet::iterator itr, next;
- - for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++)
- - {
- - itr = m_BattleGrounds[i].begin();
- - // skip updating battleground template
- - if (itr != m_BattleGrounds[i].end())
- - ++itr;
- - for(; itr != m_BattleGrounds[i].end(); itr = next)
- - {
- - next = itr;
- - ++next;
- - itr->second->Update(diff);
- - // use the SetDeleteThis variable
- - // direct deletion caused crashes
- - if (itr->second->m_SetDeleteThis)
- - {
- - BattleGround * bg = itr->second;
- - m_BattleGrounds[i].erase(itr);
- - if (!m_ClientBattleGroundIds[i][bg->GetQueueId()].empty())
- - m_ClientBattleGroundIds[i][bg->GetQueueId()].erase(bg->GetClientInstanceID());
- - delete bg;
- - }
- - }
- - }
- // update scheduled queues
- if (!m_QueueUpdateScheduler.empty())
- @@ -1194,11 +1190,11 @@ void BattleGroundMgr::Update(uint32 diff)
- for (uint8 i = 0; i < scheduled.size(); i++)
- {
- - uint32 arenaRating = scheduled[i] >> 32;
- - uint8 arenaType = scheduled[i] >> 24 & 255;
- - BattleGroundQueueTypeId bgQueueTypeId = BattleGroundQueueTypeId(scheduled[i] >> 16 & 255);
- - BattleGroundTypeId bgTypeId = BattleGroundTypeId((scheduled[i] >> 8) & 255);
- - BGQueueIdBasedOnLevel queue_id = BGQueueIdBasedOnLevel(scheduled[i] & 255);
- + uint8 queue_id = scheduled[i] & 0xFF;
- + uint32 arenaRating = scheduled[i] >> 0x20;
- + uint8 arenaType = scheduled[i] >> 0x18 & 0xFF;
- + BattleGroundQueueTypeId bgQueueTypeId = BattleGroundQueueTypeId(scheduled[i] >> 0x10 & 0xFF);
- + BattleGroundTypeId bgTypeId = BattleGroundTypeId((scheduled[i] >> 0x08) & 0xFF);
- m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, queue_id, arenaType, arenaRating > 0, arenaRating);
- }
- }
- @@ -1209,14 +1205,15 @@ void BattleGroundMgr::Update(uint32 diff)
- // it's time to force update
- if (m_NextRatingDiscardUpdate < diff)
- {
- - // forced update for level 70 rated arenas
- - sLog.outDebug("BattleGroundMgr: UPDATING ARENA QUEUES");
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_2v2].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_79, ARENA_TYPE_2v2, true, 0);
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_2v2].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_80, ARENA_TYPE_2v2, true, 0);
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_3v3].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_79, ARENA_TYPE_3v3, true, 0);
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_3v3].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_80, ARENA_TYPE_3v3, true, 0);
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_5v5].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_79, ARENA_TYPE_5v5, true, 0);
- - m_BattleGroundQueues[BATTLEGROUND_QUEUE_5v5].Update(BATTLEGROUND_AA, QUEUE_ID_MAX_LEVEL_80, ARENA_TYPE_5v5, true, 0);
- + // forced update for max level rated arenas
- +
- + uint8 MaxQueueId = GetMaxQueueId() - 1;
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_2v2].Update(BATTLEGROUND_AA, MaxQueueId-1, ARENA_TYPE_2v2, true, 0);
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_2v2].Update(BATTLEGROUND_AA, MaxQueueId, ARENA_TYPE_2v2, true, 0);
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_3v3].Update(BATTLEGROUND_AA, MaxQueueId-1, ARENA_TYPE_3v3, true, 0);
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_3v3].Update(BATTLEGROUND_AA, MaxQueueId, ARENA_TYPE_3v3, true, 0);
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_5v5].Update(BATTLEGROUND_AA, MaxQueueId-1, ARENA_TYPE_5v5, true, 0);
- + m_BattleGroundQueues[BATTLEGROUND_QUEUE_5v5].Update(BATTLEGROUND_AA, MaxQueueId, ARENA_TYPE_5v5, true, 0);
- m_NextRatingDiscardUpdate = sWorld.getConfig(CONFIG_ARENA_RATING_DISCARD_TIMER);
- }
- else
- @@ -1479,75 +1476,102 @@ void BattleGroundMgr::BuildPlayerJoinedBattleGroundPacket(WorldPacket *data, Pla
- *data << uint64(plr->GetGUID());
- }
- -BattleGround * BattleGroundMgr::GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId)
- +BattleGround * BattleGroundMgr::GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, int16 QueueId)
- {
- - //cause at HandleBattleGroundJoinOpcode the clients sends the instanceid he gets from
- - //SMSG_BATTLEFIELD_LIST we need to find the battleground with this clientinstance-id
- - BattleGround* bg = GetBattleGroundTemplate(bgTypeId);
- - if (!bg)
- - return NULL;
- + if(!IsValidBattleGround(bgTypeId,QueueId))
- + return NULL;
- - if (bg->isArena())
- - return GetBattleGround(instanceId, bgTypeId);
- -
- - for(BattleGroundSet::iterator itr = m_BattleGrounds[bgTypeId].begin(); itr != m_BattleGrounds[bgTypeId].end(); ++itr)
- + //If QueueId != -1 then InstanceID is Client Instance ID , so we convert it to Map instance Id
- + if(QueueId != -1 && !IsArenaType(bgTypeId))
- {
- - if (itr->second->GetClientInstanceID() == instanceId)
- - return itr->second;
- + MapBGClientId::iterator itr = m_ClientBattleGroundIds[bgTypeId][uint8(QueueId)].find(InstanceID);
- + if(itr != m_ClientBattleGroundIds[bgTypeId][uint8(QueueId)].end())
- + InstanceID = itr->second;
- }
- - return NULL;
- -}
- -BattleGround * BattleGroundMgr::GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId)
- -{
- - //search if needed
- - BattleGroundSet::iterator itr;
- if (bgTypeId == BATTLEGROUND_TYPE_NONE)
- {
- - for(uint32 i = BATTLEGROUND_AV; i < MAX_BATTLEGROUND_TYPE_ID; i++)
- - {
- - itr = m_BattleGrounds[i].find(InstanceID);
- - if (itr != m_BattleGrounds[i].end())
- - return itr->second;
- - }
- + for(MapBattleGround::iterator itr = m_BattleGrounds.begin(); itr != m_BattleGrounds.end(); itr++)
- + if(itr->second.find(InstanceID) != itr->second.end())
- + return itr->second[InstanceID];
- +
- return NULL;
- }
- - itr = m_BattleGrounds[bgTypeId].find(InstanceID);
- - return ( (itr != m_BattleGrounds[bgTypeId].end()) ? itr->second : NULL );
- +
- + if(m_BattleGrounds.find(bgTypeId) != m_BattleGrounds.end() && m_BattleGrounds[bgTypeId].find(InstanceID) != m_BattleGrounds[bgTypeId].end())
- + return m_BattleGrounds[bgTypeId][InstanceID];
- +
- + return NULL;
- }
- BattleGround * BattleGroundMgr::GetBattleGroundTemplate(BattleGroundTypeId bgTypeId)
- {
- - //map is sorted and we can be sure that lowest instance id has only BG template
- - return m_BattleGrounds[bgTypeId].empty() ? NULL : m_BattleGrounds[bgTypeId].begin()->second;
- + return m_BGTemplates.find(bgTypeId) == m_BGTemplates.end() ? NULL : m_BGTemplates[bgTypeId];
- }
- -uint32 BattleGroundMgr::CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id)
- +uint32 BattleGroundMgr::CreateClientInstId(BattleGroundTypeId bgTypeId, uint8 QueueId, uint32 InstanceID)
- {
- - if (IsArenaType(bgTypeId))
- - return 0; //arenas don't have client-instanceids
- -
- - // we create here an instanceid, which is just for
- - // displaying this to the client and without any other use..
- - // the client-instanceIds are unique for each battleground-type
- - // the instance-id just needs to be as low as possible, beginning with 1
- - // the following works, because std::set is default ordered with "<"
- - // the optimalization would be to use as bitmask std::vector<uint32> - but that would only make code unreadable
- - uint32 lastId = 0;
- - for(std::set<uint32>::iterator itr = m_ClientBattleGroundIds[bgTypeId][queue_id].begin(); itr != m_ClientBattleGroundIds[bgTypeId][queue_id].end();)
- - {
- - if( (++lastId) != *itr) //if there is a gap between the ids, we will break..
- - break;
- - lastId = *itr;
- + if (IsArenaType(bgTypeId) || IsValidBattleGround(bgTypeId,QueueId))
- + return 0; //arenas don't have client-instanceids
- +
- + uint32 NewId = 0;
- +
- + for(uint8 i = 1; i <= 0xFF; i++)
- + {
- + if(m_ClientBattleGroundIds[bgTypeId][QueueId].find(i)==m_ClientBattleGroundIds[bgTypeId][QueueId].end())
- + {
- + m_ClientBattleGroundIds[bgTypeId][QueueId][i] = InstanceID;
- + return i;
- + }
- }
- - m_ClientBattleGroundIds[bgTypeId][queue_id].insert(lastId + 1);
- - return lastId + 1;
- +
- + return 0;
- +}
- +
- +bool BattleGroundMgr::IsValidBattleGround(BattleGroundTypeId bgType,int16 QueueId)
- +{
- + if(QueueId != -1 && uint8(QueueId) >= GetMaxQueueId())
- + return false;
- +
- + if(!sBattlemasterListStore.LookupEntry(uint32(bgType)))
- + return false;
- +
- + return true;
- +}
- +
- +BattleGroundTypeId BattleGroundMgr::GetBgTypeByMap(uint32 MapId)
- +{
- + for(uint8 i = 0; i < sBattlemasterListStore.GetNumRows(); i++)
- + if(BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(i))
- + if(bl->GetMapCount() == 1 && bl->mapid[0] == MapId)
- + return BattleGroundTypeId(bl->id);
- +
- + return BATTLEGROUND_TYPE_NONE;
- +}
- +
- +BattleGroundTypeId BattleGroundMgr::GetArenaType()
- +{
- + for(uint8 i = 0; i < sBattlemasterListStore.GetNumRows(); i++)
- + if(BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(i))
- + if(bl->GetMapCount() > 1 && bl->type == TYPE_ARENA)
- + return GetBgTypeByMap(bl->mapid[urand(0,bl->GetMapCount())]);
- +
- + return BATTLEGROUND_NA;
- +}
- +
- +uint8 BattleGroundMgr::GetMaxQueueId()
- +{
- + return uint8(sWorld.getConfig(CONFIG_MAX_PLAYER_LEVEL) / 0x0A);
- }
- // create a new battleground that will really be used to play
- -BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated)
- +BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeId, uint8 queue_id, uint8 arenaType, bool isRated)
- {
- // get the template BG
- +
- + if(IsArenaType(bgTypeId))
- + bgTypeId = GetArenaType();
- +
- BattleGround *bg_template = GetBattleGroundTemplate(bgTypeId);
- if (!bg_template)
- {
- @@ -1555,20 +1579,6 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
- return NULL;
- }
- - //for arenas there is random map used
- - if (bg_template->isArena())
- - {
- - BattleGroundTypeId arenas[] = {BATTLEGROUND_NA, BATTLEGROUND_BE, BATTLEGROUND_RL};
- - uint32 arena_num = urand(0,2);
- - bgTypeId = arenas[arena_num];
- - bg_template = GetBattleGroundTemplate(bgTypeId);
- - if (!bg_template)
- - {
- - sLog.outError("BattleGround: CreateNewBattleGround - bg template not found for %u", bgTypeId);
- - return NULL;
- - }
- - }
- -
- BattleGround *bg = NULL;
- // create a copy of the BG template
- switch(bgTypeId)
- @@ -1618,8 +1628,11 @@ BattleGround * BattleGroundMgr::CreateNewBattleGround(BattleGroundTypeId bgTypeI
- }
- // generate a new instance id
- - bg->SetInstanceID(sMapMgr.GenerateInstanceId()); // set instance id
- - bg->SetClientInstanceID(CreateClientVisibleInstanceId(bgTypeId, queue_id));
- + uint32 InstanceID = MapManager::Instance().GenerateInstanceId();
- + uint32 ClientID = CreateClientInstId(bgTypeId, queue_id, InstanceID);
- +
- + bg->SetInstanceID(InstanceID);
- + bg->SetClientInstanceID(ClientID);
- // reset the new bg (set status to status_wait_queue from status_none)
- bg->Reset();
- @@ -1669,8 +1682,7 @@ uint32 BattleGroundMgr::CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsA
- bg->SetTeamStartLoc(HORDE, Team2StartLocX, Team2StartLocY, Team2StartLocZ, Team2StartLocO);
- bg->SetLevelRange(LevelMin, LevelMax);
- - // add bg to update list
- - AddBattleGround(bg->GetInstanceID(), bg->GetTypeID(), bg);
- + m_BGTemplates[bgTypeId] = bg;
- // return some not-null value, bgTypeId is good enough for me
- return bgTypeId;
- @@ -1872,8 +1884,7 @@ void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket *data, const uint6
- if (!plr)
- return;
- - uint32 PlayerLevel = 10;
- - PlayerLevel = plr->getLevel();
- + uint32 PlayerLevel = plr->getLevel();
- data->Initialize(SMSG_BATTLEFIELD_LIST);
- *data << uint64(guid); // battlemaster guid
- @@ -1892,11 +1903,13 @@ void BattleGroundMgr::BuildBattleGroundListPacket(WorldPacket *data, const uint6
- uint32 count = 0;
- *data << uint32(0x00); // number of bg instances
- - uint32 queue_id = plr->GetBattleGroundQueueIdFromLevel();
- - for(std::set<uint32>::iterator itr = m_ClientBattleGroundIds[bgTypeId][queue_id].begin(); itr != m_ClientBattleGroundIds[bgTypeId][queue_id].end();++itr)
- + MapBGClientId ClientIDs = m_ClientBattleGroundIds[bgTypeId][plr->GetBGLevelQueueId()];
- +
- + for(MapBGClientId::iterator itr = ClientIDs.begin(), next; itr != ClientIDs.end(); itr = next)
- {
- - *data << uint32(*itr);
- - ++count;
- + next = itr; ++next;
- + *data << uint32(itr->first);
- + ++count;
- }
- data->put<uint32>( count_pos , count);
- }
- @@ -1925,10 +1938,9 @@ void BattleGroundMgr::SendToBattleGround(Player *pl, uint32 instanceId, BattleGr
- bool BattleGroundMgr::IsArenaType(BattleGroundTypeId bgTypeId)
- {
- - return ( bgTypeId == BATTLEGROUND_AA ||
- - bgTypeId == BATTLEGROUND_BE ||
- - bgTypeId == BATTLEGROUND_NA ||
- - bgTypeId == BATTLEGROUND_RL );
- + if(BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId))
- + return(bl->type == TYPE_ARENA);
- + return false;
- }
- BattleGroundQueueTypeId BattleGroundMgr::BGQueueTypeId(BattleGroundTypeId bgTypeId, uint8 arenaType)
- @@ -2029,11 +2041,11 @@ void BattleGroundMgr::ToggleArenaTesting()
- sWorld.SendWorldText(LANG_DEBUG_ARENA_OFF);
- }
- -void BattleGroundMgr::ScheduleQueueUpdate(uint32 arenaRating, uint8 arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id)
- +void BattleGroundMgr::ScheduleQueueUpdate(uint32 arenaRating, uint8 arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, uint8 queue_id)
- {
- //ACE_Guard<ACE_Thread_Mutex> guard(SchedulerLock);
- //we will use only 1 number created of bgTypeId and queue_id
- - uint64 schedule_id = ((uint64)arenaRating << 32) | (arenaType << 24) | (bgQueueTypeId << 16) | (bgTypeId << 8) | queue_id;
- + uint64 schedule_id = ((uint64)arenaRating << 0x20) | (arenaType << 0x18) | (bgQueueTypeId << 0x10) | (bgTypeId << 8) | queue_id;
- bool found = false;
- for (uint8 i = 0; i < m_QueueUpdateScheduler.size(); i++)
- {
- @@ -2117,12 +2129,16 @@ bool BattleGroundMgr::IsBGWeekend(BattleGroundTypeId bgTypeId)
- {
- case BATTLEGROUND_AV:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_AV);
- - case BATTLEGROUND_EY:
- - return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_EY);
- case BATTLEGROUND_WS:
- return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_WS);
- + case BATTLEGROUND_AB:
- + return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_AB);
- + case BATTLEGROUND_EY:
- + return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_EY);
- case BATTLEGROUND_SA:
- - return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_SA);
- + return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_SA);
- + case BATTLEGROUND_IC:
- + return IsHolidayActive(HOLIDAY_CALL_TO_ARMS_ISLE_OF_C);
- default:
- return false;
- }
- diff --git a/src/game/BattleGroundMgr.h b/src/game/BattleGroundMgr.h
- index 7b646c6..838046c 100644
- --- a/src/game/BattleGroundMgr.h
- +++ b/src/game/BattleGroundMgr.h
- @@ -26,7 +26,9 @@
- #include "ace/Recursive_Thread_Mutex.h"
- typedef std::map<uint32, BattleGround*> BattleGroundSet;
- +typedef std::map<uint32, BattleGroundSet> MapBattleGround;
- +typedef std::map<uint8, uint32> MapBGClientId;
- //this container can't be deque, because deque doesn't like removing the last element - if you remove it, it invalidates next iterator and crash appears
- typedef std::list<BattleGround*> BGFreeSlotQueueType;
- @@ -75,18 +77,18 @@ class BattleGroundQueue
- BattleGroundQueue();
- ~BattleGroundQueue();
- - void Update(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType = 0, bool isRated = false, uint32 minRating = 0);
- + void Update(BattleGroundTypeId bgTypeId, uint8 queue_id, uint8 arenaType = 0, bool isRated = false, uint32 minRating = 0);
- - void FillPlayersToBG(BattleGround* bg, BGQueueIdBasedOnLevel queue_id);
- - bool CheckPremadeMatch(BGQueueIdBasedOnLevel queue_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam);
- - bool CheckNormalMatch(BattleGround* bg_template, BGQueueIdBasedOnLevel queue_id, uint32 minPlayers, uint32 maxPlayers);
- - bool CheckSkirmishForSameFaction(BGQueueIdBasedOnLevel queue_id, uint32 minPlayersPerTeam);
- + void FillPlayersToBG(BattleGround* bg, uint8 queue_id);
- + bool CheckPremadeMatch(uint8 queue_id, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam);
- + bool CheckNormalMatch(BattleGround* bg_template, uint8 queue_id, uint32 minPlayers, uint32 maxPlayers);
- + bool CheckSkirmishForSameFaction(uint8 queue_id, uint32 minPlayersPerTeam);
- GroupQueueInfo * AddGroup(Player* leader, Group* group, BattleGroundTypeId bgTypeId, uint8 ArenaType, bool isRated, bool isPremade, uint32 ArenaRating, uint32 ArenaTeamId = 0);
- void RemovePlayer(const uint64& guid, bool decreaseInvitedCount);
- bool IsPlayerInvited(const uint64& pl_guid, const uint32 bgInstanceGuid, const uint32 removeTime);
- bool GetPlayerGroupInfoData(const uint64& guid, GroupQueueInfo* ginfo);
- - void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id);
- - uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, BGQueueIdBasedOnLevel queue_id);
- + void PlayerInvitedToBGUpdateAverageWaitTime(GroupQueueInfo* ginfo, uint8 queue_id);
- + uint32 GetAverageQueueWaitTime(GroupQueueInfo* ginfo, uint8 queue_id);
- private:
- //mutex that should not allow changing private data, nor allowing to update Queue during private data change.
- @@ -97,8 +99,8 @@ class BattleGroundQueue
- QueuedPlayersMap m_QueuedPlayers;
- //we need constant add to begin and constant remove / add from the end, therefore deque suits our problem well
- - typedef std::list<GroupQueueInfo*> GroupsQueueType;
- -
- + typedef std::list<GroupQueueInfo*> GroupQueueInfoList;
- + typedef std::vector < std::vector< GroupQueueInfoList > > GroupsQueueType;
- /*
- This two dimensional array is used to store All queued groups
- First dimension specifies the bgTypeId
- @@ -108,7 +110,7 @@ class BattleGroundQueue
- BG_QUEUE_NORMAL_ALLIANCE is used for normal (or small) alliance groups or non-rated arena matches
- BG_QUEUE_NORMAL_HORDE is used for normal (or small) horde groups or non-rated arena matches
- */
- - GroupsQueueType m_QueuedGroups[MAX_BATTLEGROUND_QUEUES][BG_QUEUE_GROUP_TYPES_COUNT];
- + GroupsQueueType m_QueuedGroups;
- // class to select and invite groups to bg
- class SelectionPool
- @@ -119,7 +121,7 @@ class BattleGroundQueue
- bool KickGroup(uint32 size);
- uint32 GetPlayerCount() const {return PlayerCount;}
- public:
- - GroupsQueueType SelectedGroups;
- + GroupQueueInfoList SelectedGroups;
- private:
- uint32 PlayerCount;
- };
- @@ -128,9 +130,9 @@ class BattleGroundQueue
- SelectionPool m_SelectionPools[BG_TEAMS_COUNT];
- bool InviteGroupToBG(GroupQueueInfo * ginfo, BattleGround * bg, uint32 side);
- - uint32 m_WaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES][COUNT_OF_PLAYERS_TO_AVERAGE_WAIT_TIME];
- - uint32 m_WaitTimeLastPlayer[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES];
- - uint32 m_SumOfWaitTimes[BG_TEAMS_COUNT][MAX_BATTLEGROUND_QUEUES];
- + std::map<uint8, std::vector<uint32> > m_WaitTimes[BG_TEAMS_COUNT];
- + std::map<uint8, uint32> m_WaitTimeLastPlayer[BG_TEAMS_COUNT];
- + std::map<uint8, uint32> m_SumOfWaitTimes[BG_TEAMS_COUNT];
- };
- /*
- @@ -199,17 +201,23 @@ class BattleGroundMgr
- void BuildPlaySoundPacket(WorldPacket *data, uint32 soundid);
- /* Battlegrounds */
- - BattleGround* GetBattleGroundThroughClientInstance(uint32 instanceId, BattleGroundTypeId bgTypeId);
- - BattleGround* GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId); //there must be uint32 because MAX_BATTLEGROUND_TYPE_ID means unknown
- + static uint8 GetMaxQueueId();
- + BattleGroundTypeId GetArenaType();
- + uint32 GetBgMapByType(BattleGroundTypeId type);
- + BattleGroundTypeId GetBgTypeByMap(uint32 MapId);
- + Map *GetBgMapPtrByType(BattleGroundTypeId type);
- + bool IsValidBattleGround(BattleGroundTypeId bgType, int16 QueueId = -1);
- + BattleGround* GetBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, int16 QueueId = -1);
- BattleGround* GetBattleGroundTemplate(BattleGroundTypeId bgTypeId);
- - BattleGround* CreateNewBattleGround(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id, uint8 arenaType, bool isRated);
- + BattleGround* CreateNewBattleGround(BattleGroundTypeId bgTypeId, uint8 queue_id, uint8 arenaType, bool isRated);
- uint32 CreateBattleGround(BattleGroundTypeId bgTypeId, bool IsArena, uint32 MinPlayersPerTeam, uint32 MaxPlayersPerTeam, uint32 LevelMin, uint32 LevelMax, char* BattleGroundName, uint32 MapID, float Team1StartLocX, float Team1StartLocY, float Team1StartLocZ, float Team1StartLocO, float Team2StartLocX, float Team2StartLocY, float Team2StartLocZ, float Team2StartLocO);
- void AddBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId, BattleGround* BG) { m_BattleGrounds[bgTypeId][InstanceID] = BG; };
- - void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); }
- - uint32 CreateClientVisibleInstanceId(BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id);
- + void RemoveBattleGround(uint32 InstanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(InstanceID); }
- + uint32 CreateClientInstId(BattleGroundTypeId bgTypeId, uint8 queue_id, uint32 InstanceID);
- + void DestroyBattleGround(BattleGround *BG);
- void CreateInitialBattleGrounds();
- void DeleteAllBattleGrounds();
- @@ -220,9 +228,9 @@ class BattleGroundMgr
- //these queues are instantiated when creating BattlegroundMrg
- BattleGroundQueue m_BattleGroundQueues[MAX_BATTLEGROUND_QUEUE_TYPES]; // public, because we need to access them in BG handler code
- - BGFreeSlotQueueType BGFreeSlotQueue[MAX_BATTLEGROUND_TYPE_ID];
- + std::map<uint32,BGFreeSlotQueueType> BGFreeSlotQueue;
- - void ScheduleQueueUpdate(uint32 arenaRating, uint8 arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, BGQueueIdBasedOnLevel queue_id);
- + void ScheduleQueueUpdate(uint32 arenaRating, uint8 arenaType, BattleGroundQueueTypeId bgQueueTypeId, BattleGroundTypeId bgTypeId, uint8 queue_id);
- uint32 GetMaxRatingDifference() const;
- uint32 GetRatingDiscardTimer() const;
- uint32 GetPrematureFinishTime() const;
- @@ -274,12 +282,16 @@ class BattleGroundMgr
- GameObjectBattleEventIndexesMap m_GameObjectBattleEventIndexMap;
- /* Battlegrounds */
- - BattleGroundSet m_BattleGrounds[MAX_BATTLEGROUND_TYPE_ID];
- - std::vector<uint64> m_QueueUpdateScheduler;
- - std::set<uint32> m_ClientBattleGroundIds[MAX_BATTLEGROUND_TYPE_ID][MAX_BATTLEGROUND_QUEUES]; //the instanceids just visible for the client
- +
- uint32 m_NextRatingDiscardUpdate;
- time_t m_NextAutoDistributionTime;
- uint32 m_AutoDistributionTimeChecker;
- + std::vector<uint64>m_QueueUpdateScheduler;
- +
- + MapBattleGround m_BattleGrounds;
- + std::map<BattleGroundTypeId,BattleGround *> m_BGTemplates;
- + std::map<uint32, std::map<uint8,MapBGClientId> > m_ClientBattleGroundIds;
- +
- bool m_ArenaTesting;
- bool m_Testing;
- };
- diff --git a/src/game/BattleGroundNA.cpp b/src/game/BattleGroundNA.cpp
- index ba7e18f..23baffb 100644
- --- a/src/game/BattleGroundNA.cpp
- +++ b/src/game/BattleGroundNA.cpp
- @@ -73,7 +73,7 @@ void BattleGroundNA::AddPlayer(Player *plr)
- UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
- }
- -void BattleGroundNA::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- +void BattleGroundNA::RemovePlayer(Player* player, uint64 guid)
- {
- if (GetStatus() == STATUS_WAIT_LEAVE)
- return;
- @@ -81,7 +81,7 @@ void BattleGroundNA::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
- - CheckArenaWinConditions();
- + BattleGround::RemovePlayer(player, guid);
- }
- void BattleGroundNA::HandleKillPlayer(Player *player, Player *killer)
- @@ -99,8 +99,6 @@ void BattleGroundNA::HandleKillPlayer(Player *player, Player *killer)
- UpdateWorldState(0xa0f, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0xa10, GetAlivePlayersCountByTeam(HORDE));
- -
- - CheckArenaWinConditions();
- }
- bool BattleGroundNA::HandlePlayerUnderMap(Player *player)
- diff --git a/src/game/BattleGroundRL.cpp b/src/game/BattleGroundRL.cpp
- index 009e0e9..6198bf0 100644
- --- a/src/game/BattleGroundRL.cpp
- +++ b/src/game/BattleGroundRL.cpp
- @@ -73,7 +73,7 @@ void BattleGroundRL::AddPlayer(Player *plr)
- UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
- }
- -void BattleGroundRL::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- +void BattleGroundRL::RemovePlayer(Player* player, uint64 guid)
- {
- if (GetStatus() == STATUS_WAIT_LEAVE)
- return;
- @@ -81,7 +81,7 @@ void BattleGroundRL::RemovePlayer(Player* /*plr*/, uint64 /*guid*/)
- UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
- - CheckArenaWinConditions();
- + BattleGround::RemovePlayer(player, guid);
- }
- void BattleGroundRL::HandleKillPlayer(Player *player, Player *killer)
- @@ -100,7 +100,6 @@ void BattleGroundRL::HandleKillPlayer(Player *player, Player *killer)
- UpdateWorldState(0xbb8, GetAlivePlayersCountByTeam(ALLIANCE));
- UpdateWorldState(0xbb9, GetAlivePlayersCountByTeam(HORDE));
- - CheckArenaWinConditions();
- }
- bool BattleGroundRL::HandlePlayerUnderMap(Player *player)
- diff --git a/src/game/BattleGroundRV.cpp b/src/game/BattleGroundRV.cpp
- index 8c252c3..2993ffc 100644
- --- a/src/game/BattleGroundRV.cpp
- +++ b/src/game/BattleGroundRV.cpp
- @@ -19,6 +19,7 @@
- #include "Player.h"
- #include "BattleGround.h"
- #include "BattleGroundRV.h"
- +#include "WorldPacket.h"
- #include "Language.h"
- BattleGroundRV::BattleGroundRV()
- @@ -60,21 +61,49 @@ void BattleGroundRV::AddPlayer(Player *plr)
- BattleGroundRVScore* sc = new BattleGroundRVScore;
- m_PlayerScores[plr->GetGUID()] = sc;
- +
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- }
- -void BattleGroundRV::RemovePlayer(Player * /*plr*/, uint64 /*guid*/)
- +void BattleGroundRV::RemovePlayer(Player * player, uint64 guid)
- {
- + if (GetStatus() == STATUS_WAIT_LEAVE)
- + return;
- +
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- +
- + BattleGround::RemovePlayer(player, guid);
- }
- void BattleGroundRV::HandleKillPlayer(Player* player, Player* killer)
- -{
- +{
- + if (GetStatus() != STATUS_IN_PROGRESS)
- + return;
- +
- + if (!killer)
- + {
- + sLog.outError("BattleGroundRV: Killer player not found");
- + return;
- + }
- +
- BattleGround::HandleKillPlayer(player, killer);
- + UpdateWorldState(0xe11, GetAlivePlayersCountByTeam(ALLIANCE));
- + UpdateWorldState(0xe10, GetAlivePlayersCountByTeam(HORDE));
- }
- void BattleGroundRV::HandleAreaTrigger(Player * /*Source*/, uint32 /*Trigger*/)
- {
- }
- +void BattleGroundRV::FillInitialWorldStates(WorldPacket &data)
- +{
- + data << uint32(0xe11) << uint32(GetAlivePlayersCountByTeam(ALLIANCE)); // 7
- + data << uint32(0xe10) << uint32(GetAlivePlayersCountByTeam(HORDE)); // 8
- + data << uint32(0xe1a) << uint32(1); // 9
- +}
- +
- bool BattleGroundRV::SetupBattleGround()
- {
- return true;
- diff --git a/src/game/BattleGroundRV.h b/src/game/BattleGroundRV.h
- index e3e94ba..bf612b8 100644
- --- a/src/game/BattleGroundRV.h
- +++ b/src/game/BattleGroundRV.h
- @@ -45,6 +45,7 @@ class BattleGroundRV : public BattleGround
- void RemovePlayer(Player *plr, uint64 guid);
- void HandleAreaTrigger(Player *Source, uint32 Trigger);
- bool SetupBattleGround();
- + virtual void FillInitialWorldStates(WorldPacket &d);
- void HandleKillPlayer(Player* player, Player *killer);
- };
- #endif
- diff --git a/src/game/CharacterHandler.cpp b/src/game/CharacterHandler.cpp
- index 69cd034..97e3be2 100644
- --- a/src/game/CharacterHandler.cpp
- +++ b/src/game/CharacterHandler.cpp
- @@ -30,6 +30,7 @@
- #include "Guild.h"
- #include "UpdateMask.h"
- #include "Auth/md5.h"
- +#include "MapManager.h"
- #include "ObjectAccessor.h"
- #include "Group.h"
- #include "Database/DatabaseImpl.h"
- @@ -552,6 +553,7 @@ void WorldSession::HandlePlayerLoginOpcode( WorldPacket & recv_data )
- void WorldSession::HandlePlayerLogin(LoginQueryHolder *holder)
- {
- + SetUpdating(true);
- uint64 playerGuid = holder->GetGuid();
- Player *pCurrChar = new Player(this);
- @@ -566,6 +568,22 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder *holder)
- m_playerLoading = false;
- return;
- }
- + //Map is being restarted so we cant enter
- + if(Map *map = sMapMgr.FindMap(pCurrChar->GetMapId()))
- + {
- + if(map->GetUpdaterStatus() != UPDATER_ACTIVE)
- + {
- + WorldPacket data(SMSG_CHARACTER_LOGIN_FAILED, 9);
- + data << uint64(pCurrChar->GetGUID());
- + data << uint8(CHAR_LOGIN_NO_WORLD);
- + m_playerRecentlyLogout = true;
- + m_playerLoading = false;
- + SendPacket(&data);
- + delete pCurrChar; // delete it manually
- + delete holder; // delete all unprocessed queries
- + return;
- + }
- + }
- SetPlayer(pCurrChar);
- @@ -782,6 +800,9 @@ void WorldSession::HandlePlayerLogin(LoginQueryHolder *holder)
- m_playerLoading = false;
- delete holder;
- +
- + SetUpdating(false);
- + SetUpdateStatus(SESSION_UPDATE_MAP);
- }
- void WorldSession::HandleSetFactionAtWar( WorldPacket & recv_data )
- diff --git a/src/game/DBCStructure.h b/src/game/DBCStructure.h
- index e799e99..514afa4 100644
- --- a/src/game/DBCStructure.h
- +++ b/src/game/DBCStructure.h
- @@ -572,11 +572,21 @@ struct BattlemasterListEntry
- uint32 maxplayersperteam; // 12
- // 13 minplayers
- // 14 0 or 9
- - // 15
- + uint32 IsActive; // 15 Is bg active?
- char* name[16]; // 16-31
- // 32 string flag, unused
- // 33 unused
- //uint32 unk; // 34 new 3.1
- +
- + uint8 GetMapCount() const
- + {
- + if(!IsActive)
- + return 0;
- +
- + uint8 i = 0;
- + while(i < 8 && mapid[i] != -1)i++;
- + return i;
- + }
- };
- #define MAX_OUTFIT_ITEMS 24
- diff --git a/src/game/DBCfmt.h b/src/game/DBCfmt.h
- index aa51050..fc96ca2 100644
- --- a/src/game/DBCfmt.h
- +++ b/src/game/DBCfmt.h
- @@ -27,7 +27,7 @@ const char AreaTriggerEntryfmt[]="niffffffff";
- const char AuctionHouseEntryfmt[]="niiixxxxxxxxxxxxxxxxx";
- const char BankBagSlotPricesEntryfmt[]="ni";
- const char BarberShopStyleEntryfmt[]="nixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxiii";
- -const char BattlemasterListEntryfmt[]="niiiiiiiiiiiixxxssssssssssssssssxxx";
- +const char BattlemasterListEntryfmt[]="niiiiiiiiiiiixxissssssssssssssssxxx";
- const char CharStartOutfitEntryfmt[]="diiiiiiiiiiiiiiiiiiiiiiiiixxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
- const char CharTitlesEntryfmt[]="nxssssssssssssssssxxxxxxxxxxxxxxxxxxi";
- const char ChatChannelsEntryfmt[]="iixssssssssssssssssxxxxxxxxxxxxxxxxxx";
- diff --git a/src/game/GameEventMgr.cpp b/src/game/GameEventMgr.cpp
- index 2249b94..8ad5b53 100644
- --- a/src/game/GameEventMgr.cpp
- +++ b/src/game/GameEventMgr.cpp
- @@ -24,92 +24,80 @@
- #include "ProgressBar.h"
- #include "Language.h"
- #include "Log.h"
- +#include "WorldPacket.h"
- #include "MapManager.h"
- #include "Policies/SingletonImp.h"
- INSTANTIATE_SINGLETON_1(GameEventMgr);
- -bool GameEventMgr::CheckOneGameEvent(uint16 entry) const
- +bool GameEventMgr::CheckOneGameEvent(GameEventData Event) const
- {
- // Get the event information
- time_t currenttime = time(NULL);
- - if( mGameEvent[entry].start < currenttime && currenttime < mGameEvent[entry].end &&
- - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE)) < (mGameEvent[entry].length * MINUTE) )
- + if( Event.start < currenttime && currenttime < Event.end &&
- + ((currenttime - Event.start) % (Event.occurence * MINUTE)) < (Event.length * MINUTE) )
- return true;
- else
- return false;
- }
- -uint32 GameEventMgr::NextCheck(uint16 entry) const
- +uint32 GameEventMgr::NextCheck(GameEventData Event) const
- {
- time_t currenttime = time(NULL);
- // outdated event: we return max
- - if (currenttime > mGameEvent[entry].end)
- + if (currenttime > Event.end)
- return max_ge_check_delay;
- // never started event, we return delay before start
- - if (mGameEvent[entry].start > currenttime)
- - return (mGameEvent[entry].start - currenttime);
- + if (Event.start > currenttime)
- + return (Event.start - currenttime);
- uint32 delay;
- // in event, we return the end of it
- - if ((((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * 60)) < (mGameEvent[entry].length * 60)))
- + if ((((currenttime - Event.start) % (Event.occurence * 60)) < (Event.length * 60)))
- // we return the delay before it ends
- - delay = (mGameEvent[entry].length * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE));
- + delay = (Event.length * MINUTE) - ((currenttime - Event.start) % (Event.occurence * MINUTE));
- else // not in window, we return the delay before next start
- - delay = (mGameEvent[entry].occurence * MINUTE) - ((currenttime - mGameEvent[entry].start) % (mGameEvent[entry].occurence * MINUTE));
- + delay = (Event.occurence * MINUTE) - ((currenttime - Event.start) % (Event.occurence * MINUTE));
- // In case the end is before next check
- - if (mGameEvent[entry].end < time_t(currenttime + delay))
- - return (mGameEvent[entry].end - currenttime);
- + if (Event.end < time_t(currenttime + delay))
- + return (Event.end - currenttime);
- else
- return delay;
- }
- -void GameEventMgr::StartEvent( uint16 event_id, bool overwrite )
- +void GameEventMgr::StartEvent( uint16 EventId, bool OverWrite )
- {
- - AddActiveEvent(event_id);
- - ApplyNewEvent(event_id);
- - if(overwrite)
- + GameEventData *Event = &mGameEvent[EventId];
- + Event->active = true;
- + ApplyNewEvent(EventId);
- +
- + if(OverWrite)
- {
- - mGameEvent[event_id].start = time(NULL);
- - if(mGameEvent[event_id].end <= mGameEvent[event_id].start)
- - mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length;
- + Event->start = time(NULL);
- + if(Event->end <= Event->start)
- + Event->end = time_t(Event->start+Event->length);
- }
- }
- -void GameEventMgr::StopEvent( uint16 event_id, bool overwrite )
- +void GameEventMgr::StopEvent( uint16 EventId, bool OverWrite )
- {
- - RemoveActiveEvent(event_id);
- - UnApplyEvent(event_id);
- - if(overwrite)
- + GameEventData *Event = &mGameEvent[EventId];
- + Event->active = false;
- + UnApplyEvent(EventId);
- +
- + if(OverWrite)
- {
- - mGameEvent[event_id].start = time(NULL) - mGameEvent[event_id].length * MINUTE;
- - if(mGameEvent[event_id].end <= mGameEvent[event_id].start)
- - mGameEvent[event_id].end = mGameEvent[event_id].start+mGameEvent[event_id].length;
- + Event->start = time(NULL) - Event->length * MINUTE;
- + if(Event->end <= Event->start)
- + Event->end = time_t(Event->start+Event->length);
- }
- }
- void GameEventMgr::LoadFromDB()
- {
- - {
- - QueryResult *result = WorldDatabase.Query("SELECT MAX(entry) FROM game_event");
- - if( !result )
- - {
- - sLog.outString(">> Table game_event is empty.");
- - sLog.outString();
- - return;
- - }
- -
- - Field *fields = result->Fetch();
- -
- - uint32 max_event_id = fields[0].GetUInt16();
- - delete result;
- -
- - mGameEvent.resize(max_event_id+1);
- - }
- -
- - QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,description FROM game_event");
- + QueryResult *result = WorldDatabase.Query("SELECT entry,UNIX_TIMESTAMP(start_time),UNIX_TIMESTAMP(end_time),occurence,length,holiday,node,description FROM game_event");
- if( !result )
- {
- mGameEvent.clear();
- @@ -144,7 +132,7 @@ void GameEventMgr::LoadFromDB()
- pGameEvent.occurence = fields[3].GetUInt32();
- pGameEvent.length = fields[4].GetUInt32();
- pGameEvent.holiday_id = fields[5].GetUInt32();
- -
- + pGameEvent.node = fields[6].GetUInt32();
- if(pGameEvent.length==0) // length>0 is validity check
- {
- @@ -161,7 +149,7 @@ void GameEventMgr::LoadFromDB()
- }
- }
- - pGameEvent.description = fields[6].GetCppString();
- + pGameEvent.description = fields[7].GetCppString();
- } while( result->NextRow() );
- delete result;
- @@ -170,7 +158,6 @@ void GameEventMgr::LoadFromDB()
- sLog.outString( ">> Loaded %u game events", count );
- }
- - mGameEventCreatureGuids.resize(mGameEvent.size()*2-1);
- // 1 2
- result = WorldDatabase.Query("SELECT creature.guid, game_event_creature.event "
- "FROM creature JOIN game_event_creature ON creature.guid = game_event_creature.guid");
- @@ -193,21 +180,17 @@ void GameEventMgr::LoadFromDB()
- Field *fields = result->Fetch();
- bar.step();
- -
- - uint32 guid = fields[0].GetUInt32();
- - int16 event_id = fields[1].GetInt16();
- -
- - int32 internal_event_id = mGameEvent.size() + event_id - 1;
- -
- - if(internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size())
- + uint32 Guid = fields[0].GetUInt32();
- + int16 EventId = fields[1].GetInt16 ();
- + uint16 RealEventId = uint16(EventId < 0 ? EventId * -1 : EventId);
- + if(mGameEvent.find(RealEventId)==mGameEvent.end())
- {
- - sLog.outErrorDb("`game_event_creature` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
- + sLog.outErrorDb("`game_event_creature` game event id (%u) is out of range compared to max event id in `game_event`",RealEventId);
- continue;
- }
- ++count;
- - GuidList& crelist = mGameEventCreatureGuids[internal_event_id];
- - crelist.push_back(guid);
- + mGameEventCreatureGuids[EventId].push_back(Guid);
- } while( result->NextRow() );
- delete result;
- @@ -216,7 +199,6 @@ void GameEventMgr::LoadFromDB()
- sLog.outString( ">> Loaded %u creatures in game events", count );
- }
- - mGameEventGameobjectGuids.resize(mGameEvent.size()*2-1);
- // 1 2
- result = WorldDatabase.Query("SELECT gameobject.guid, game_event_gameobject.event "
- "FROM gameobject JOIN game_event_gameobject ON gameobject.guid=game_event_gameobject.guid");
- @@ -240,20 +222,18 @@ void GameEventMgr::LoadFromDB()
- bar.step();
- - uint32 guid = fields[0].GetUInt32();
- - int16 event_id = fields[1].GetInt16();
- -
- - int32 internal_event_id = mGameEvent.size() + event_id - 1;
- + uint32 Guid = fields[0].GetUInt32();
- + uint16 EventId = fields[1].GetUInt16();
- + uint16 RealEventId = uint16(EventId < 0 ? EventId * -1 : EventId);
- - if(internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size())
- + if(mGameEvent.find(EventId)==mGameEvent.end())
- {
- - sLog.outErrorDb("`game_event_gameobject` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
- + sLog.outErrorDb("`game_event_gameobject` game event id (%u) not exist in `game_event`",RealEventId);
- continue;
- }
- ++count;
- - GuidList& golist = mGameEventGameobjectGuids[internal_event_id];
- - golist.push_back(guid);
- + mGameEventGameobjectGuids[EventId].push_back(Guid);
- } while( result->NextRow() );
- delete result;
- @@ -262,7 +242,6 @@ void GameEventMgr::LoadFromDB()
- sLog.outString( ">> Loaded %u gameobjects in game events", count );
- }
- - mGameEventModelEquip.resize(mGameEvent.size());
- // 0 1 2
- result = WorldDatabase.Query("SELECT creature.guid, game_event_model_equip.event, game_event_model_equip.modelid,"
- // 3
- @@ -287,17 +266,16 @@ void GameEventMgr::LoadFromDB()
- Field *fields = result->Fetch();
- bar.step();
- - uint32 guid = fields[0].GetUInt32();
- - uint16 event_id = fields[1].GetUInt16();
- + uint32 Guid = fields[0].GetUInt32();
- + uint16 EventId = fields[1].GetUInt16();
- - if(event_id >= mGameEventModelEquip.size())
- + if(mGameEvent.find(EventId)==mGameEvent.end())
- {
- - sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
- + sLog.outErrorDb("`game_event_model_equip` game event id (%u) is out of range compared to max event id in `game_event`",EventId);
- continue;
- }
- ++count;
- - ModelEquipList& equiplist = mGameEventModelEquip[event_id];
- ModelEquip newModelEquipSet;
- newModelEquipSet.modelid = fields[2].GetUInt32();
- newModelEquipSet.equipment_id = fields[3].GetUInt32();
- @@ -308,12 +286,12 @@ void GameEventMgr::LoadFromDB()
- {
- if(!sObjectMgr.GetEquipmentInfo(newModelEquipSet.equipment_id))
- {
- - sLog.outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", guid, newModelEquipSet.equipment_id);
- + sLog.outErrorDb("Table `game_event_model_equip` have creature (Guid: %u) with equipment_id %u not found in table `creature_equip_template`, set to no equipment.", Guid, newModelEquipSet.equipment_id);
- continue;
- }
- }
- - equiplist.push_back(std::pair<uint32, ModelEquip>(guid, newModelEquipSet));
- + mGameEventModelEquip[EventId].push_back(std::pair<uint32, ModelEquip>(Guid, newModelEquipSet));
- } while( result->NextRow() );
- delete result;
- @@ -322,7 +300,6 @@ void GameEventMgr::LoadFromDB()
- sLog.outString( ">> Loaded %u model/equipment changes in game events", count );
- }
- - mGameEventQuests.resize(mGameEvent.size());
- // 0 1 2
- result = WorldDatabase.Query("SELECT id, quest, event FROM game_event_creature_quest");
- @@ -344,19 +321,18 @@ void GameEventMgr::LoadFromDB()
- Field *fields = result->Fetch();
- bar.step();
- - uint32 id = fields[0].GetUInt32();
- - uint32 quest = fields[1].GetUInt32();
- - uint16 event_id = fields[2].GetUInt16();
- + uint32 Id = fields[0].GetUInt32();
- + uint32 Quest = fields[1].GetUInt32();
- + uint16 EventId = fields[2].GetUInt16();
- - if(event_id >= mGameEventQuests.size())
- + if(mGameEvent.find(EventId)==mGameEvent.end())
- {
- - sLog.outErrorDb("`game_event_creature_quest` game event id (%u) is out of range compared to max event id in `game_event`",event_id);
- + sLog.outErrorDb("`game_event_creature_quest` game event id (%u) not exist in `game_event`",EventId);
- continue;
- }
- ++count;
- - QuestRelList& questlist = mGameEventQuests[event_id];
- - questlist.push_back(QuestRelation(id, quest));
- + mGameEventQuests[EventId].push_back(QuestRelation(Id, Quest));
- } while( result->NextRow() );
- delete result;
- @@ -365,7 +341,6 @@ void GameEventMgr::LoadFromDB()
- sLog.outString( ">> Loaded %u quests additions in game events", count );
- }
- - mGameEventPoolIds.resize(mGameEvent.size()*2-1);
- // 1 2
- result = WorldDatabase.Query("SELECT pool_template.entry, game_event_pool.event "
- "FROM pool_template JOIN game_event_pool ON pool_template.entry = game_event_pool.pool_entry");
- @@ -389,26 +364,23 @@ void GameEventMgr::LoadFromDB()
- bar2.step();
- - uint32 entry = fields[0].GetUInt16();
- - int16 event_id = fields[1].GetInt16();
- -
- - int32 internal_event_id = mGameEvent.size() + event_id - 1;
- -
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventPoolIds.size())
- + uint32 Entry = fields[0].GetUInt16();
- + int16 EventId = fields[1].GetInt16();
- + uint16 RealEventId = uint16(EventId < 0 ? EventId * -1 : EventId);
- + if(mGameEvent.find(RealEventId)==mGameEvent.end())
- {
- - sLog.outErrorDb("`game_event_pool` game event id (%i) is out of range compared to max event id in `game_event`",event_id);
- + sLog.outErrorDb("`game_event_pool` game event id (%u) not exist in `game_event`",RealEventId);
- continue;
- }
- - if (!sPoolMgr.CheckPool(entry))
- + if (!sPoolMgr.CheckPool(Entry))
- {
- - sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", entry);
- + sLog.outErrorDb("Pool Id (%u) has all creatures or gameobjects with explicit chance sum <>100 and no equal chance defined. The pool system cannot pick one to spawn.", Entry);
- continue;
- }
- ++count;
- - IdList& poollist = mGameEventPoolIds[internal_event_id];
- - poollist.push_back(entry);
- + mGameEventPoolIds[EventId].push_back(Entry);
- } while( result->NextRow() );
- sLog.outString();
- @@ -419,7 +391,6 @@ void GameEventMgr::LoadFromDB()
- uint32 GameEventMgr::Initialize() // return the next event delay in ms
- {
- - m_ActiveEvents.clear();
- uint32 delay = Update();
- sLog.outBasic("Game Event system initialized." );
- m_IsGameEventsInit = true;
- @@ -430,34 +401,34 @@ uint32 GameEventMgr::Update() // return the next e
- {
- uint32 nextEventDelay = max_ge_check_delay; // 1 day
- uint32 calcDelay;
- - for (uint16 itr = 1; itr < mGameEvent.size(); ++itr)
- +
- + for (GameEventDataMap::iterator iter = mGameEvent.begin(); iter != mGameEvent.end(); iter++)
- {
- //sLog.outErrorDb("Checking event %u",itr);
- - if (CheckOneGameEvent(itr))
- + if (CheckOneGameEvent(iter->second))
- {
- //sLog.outDebug("GameEvent %u is active",itr->first);
- - if (!IsActiveEvent(itr))
- - StartEvent(itr);
- + if (!iter->second.active)
- + StartEvent(iter->first);
- }
- else
- {
- //sLog.outDebug("GameEvent %u is not active",itr->first);
- - if (IsActiveEvent(itr))
- - StopEvent(itr);
- + if (iter->second.active)
- + StopEvent(iter->first);
- else
- {
- if (!m_IsGameEventsInit)
- {
- - int16 event_nid = (-1) * (itr);
- // spawn all negative ones for this event
- - GameEventSpawn(event_nid);
- + GameEventSpawn(int16(iter->first * -1));
- // disable any event specific quest (for cases where creature is spawned, but event not active).
- - UpdateEventQuests(itr, false);
- + UpdateEventQuests(iter->first, false);
- }
- }
- }
- - calcDelay = NextCheck(itr);
- + calcDelay = NextCheck(iter->second);
- if (calcDelay < nextEventDelay)
- nextEventDelay = calcDelay;
- }
- @@ -465,55 +436,58 @@ uint32 GameEventMgr::Update() // return the next e
- return (nextEventDelay + 1) * IN_MILISECONDS; // Add 1 second to be sure event has started/stopped at next call
- }
- -void GameEventMgr::UnApplyEvent(uint16 event_id)
- +void GameEventMgr::UnApplyEvent(uint16 EventId)
- {
- - sLog.outString("GameEvent %u \"%s\" removed.", event_id, mGameEvent[event_id].description.c_str());
- + GameEventData gEvent = mGameEvent[EventId];
- + sLog.outString("GameEvent %u \"%s\" removed.", EventId, gEvent.description.c_str());
- // un-spawn positive event tagged objects
- - GameEventUnspawn(event_id);
- + GameEventUnspawn(EventId);
- // spawn negative event tagget objects
- - int16 event_nid = (-1) * event_id;
- - GameEventSpawn(event_nid);
- + GameEventSpawn(-1 * int16(EventId));
- // restore equipment or model
- - ChangeEquipOrModel(event_id, false);
- + ChangeEquipOrModel(EventId, false);
- // Remove quests that are events only to non event npc
- - UpdateEventQuests(event_id, false);
- -}
- + UpdateEventQuests(EventId, false);
- -void GameEventMgr::ApplyNewEvent(uint16 event_id)
- -{
- - switch(sWorld.getConfig(CONFIG_EVENT_ANNOUNCE))
- + if(gEvent.node) // Update World Node Status
- {
- - case 0: // disable
- - break;
- - case 1: // announce events
- - sWorld.SendWorldText(LANG_EVENTMESSAGE, mGameEvent[event_id].description.c_str());
- - break;
- + WorldPacket data(SMSG_UPDATE_WORLD_STATE, 8);
- + data << uint32(gEvent.node) << uint32(false);
- + sWorld.SendGlobalMessage(&data);
- }
- +}
- +
- +void GameEventMgr::ApplyNewEvent(uint16 EventId)
- +{
- + GameEventData gEvent = mGameEvent[EventId];
- + if(sWorld.getConfig(CONFIG_EVENT_ANNOUNCE))
- + sWorld.SendWorldText(LANG_EVENTMESSAGE, gEvent.description.c_str());
- - sLog.outString("GameEvent %u \"%s\" started.", event_id, mGameEvent[event_id].description.c_str());
- + sLog.outString("GameEvent %u \"%s\" started.", EventId, gEvent.description.c_str());
- // spawn positive event tagget objects
- - GameEventSpawn(event_id);
- + GameEventSpawn(EventId);
- // un-spawn negative event tagged objects
- - int16 event_nid = (-1) * event_id;
- - GameEventUnspawn(event_nid);
- + GameEventUnspawn(-1 * int16(EventId));
- // Change equipement or model
- - ChangeEquipOrModel(event_id, true);
- + ChangeEquipOrModel(EventId, true);
- // Add quests that are events only to non event npc
- - UpdateEventQuests(event_id, true);
- + UpdateEventQuests(EventId, true);
- +
- + if(gEvent.node) // Update World Node Status
- + {
- + WorldPacket data(SMSG_UPDATE_WORLD_STATE, 8);
- + data << uint32(gEvent.node) << uint32(true);
- + sWorld.SendGlobalMessage(&data);
- + }
- }
- -void GameEventMgr::GameEventSpawn(int16 event_id)
- +void GameEventMgr::GameEventSpawn(int16 EventId)
- {
- - int32 internal_event_id = mGameEvent.size() + event_id - 1;
- -
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size())
- - {
- - sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventCreatureGuids.size());
- - return;
- - }
- -
- - for (GuidList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin();itr != mGameEventCreatureGuids[internal_event_id].end();++itr)
- + if(mGameEventCreatureGuids.find(EventId) != mGameEventCreatureGuids.end())
- {
- + GuidList CreatureList = mGameEventCreatureGuids[EventId];
- + for (GuidList::iterator itr = CreatureList.begin();itr != CreatureList.end();++itr)
- + {
- // Add to correct cell
- CreatureData const* data = sObjectMgr.GetCreatureData(*itr);
- if (data)
- @@ -536,69 +510,58 @@ void GameEventMgr::GameEventSpawn(int16 event_id)
- map->Add(pCreature);
- }
- }
- - }
- - }
- -
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size())
- - {
- - sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventGameobjectGuids.size());
- - return;
- + }
- + }
- }
- - for (GuidList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin();itr != mGameEventGameobjectGuids[internal_event_id].end();++itr)
- + if(mGameEventGameobjectGuids.find(EventId) != mGameEventGameobjectGuids.end())
- {
- - // Add to correct cell
- - GameObjectData const* data = sObjectMgr.GetGOData(*itr);
- - if (data)
- - {
- - sObjectMgr.AddGameobjectToGrid(*itr, data);
- - // Spawn if necessary (loaded grids only)
- - // this base map checked as non-instanced and then only existed
- - Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
- - // We use current coords to unspawn, not spawn coords since creature can have changed grid
- - if(!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
- - {
- - GameObject* pGameobject = new GameObject;
- - //sLog.outDebug("Spawning gameobject %u", *itr);
- - if (!pGameobject->LoadFromDB(*itr, map))
- - {
- - delete pGameobject;
- - }
- - else
- - {
- - if(pGameobject->isSpawnedByDefault())
- - map->Add(pGameobject);
- - }
- - }
- + GuidList GameObjectList = mGameEventGameobjectGuids[EventId];
- + for (GuidList::iterator itr = GameObjectList.begin();itr != GameObjectList.end();++itr)
- + {
- +
- + // Add to correct cell
- + GameObjectData const* data = sObjectMgr.GetGOData(*itr);
- + if (data)
- + {
- + sObjectMgr.AddGameobjectToGrid(*itr, data);
- + // Spawn if necessary (loaded grids only)
- + // this base map checked as non-instanced and then only existed
- + Map* map = const_cast<Map*>(sMapMgr.CreateBaseMap(data->mapid));
- + // We use current coords to unspawn, not spawn coords since creature can have changed grid
- + if(!map->Instanceable() && map->IsLoaded(data->posX, data->posY))
- + {
- + GameObject* pGameobject = new GameObject;
- + if (!pGameobject->LoadFromDB(*itr, map))
- + delete pGameobject;
- + else if(pGameobject->isSpawnedByDefault())
- + map->Add(pGameobject);
- + }
- }
- + }
- }
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventPoolIds.size())
- - {
- - sLog.outError("GameEventMgr::GameEventSpawn attempt access to out of range mGameEventPoolIds element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventPoolIds.size());
- - return;
- - }
- - for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
- + if(mGameEventPoolIds.find(EventId) != mGameEventPoolIds.end())
- {
- + IdList PoolList = mGameEventPoolIds[EventId];
- + for (IdList::iterator itr = PoolList.begin();itr != PoolList.end();++itr)
- + {
- sPoolMgr.SpawnPool(*itr, 0, 0);
- sPoolMgr.SpawnPool(*itr, 0, TYPEID_GAMEOBJECT);
- sPoolMgr.SpawnPool(*itr, 0, TYPEID_UNIT);
- + }
- }
- }
- -void GameEventMgr::GameEventUnspawn(int16 event_id)
- +void GameEventMgr::GameEventUnspawn(int16 EventId)
- {
- - int32 internal_event_id = mGameEvent.size() + event_id - 1;
- -
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventCreatureGuids.size())
- - {
- - sLog.outError("GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventCreatureGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventCreatureGuids.size());
- - return;
- - }
- - for (GuidList::iterator itr = mGameEventCreatureGuids[internal_event_id].begin();itr != mGameEventCreatureGuids[internal_event_id].end();++itr)
- + if(mGameEventCreatureGuids.find(EventId) != mGameEventCreatureGuids.end())
- {
- + GuidList CreatureList = mGameEventCreatureGuids[EventId];
- + for (GuidList::iterator itr = CreatureList.begin();itr != CreatureList.end();++itr)
- + {
- // Remove the creature from grid
- if( CreatureData const* data = sObjectMgr.GetCreatureData(*itr) )
- {
- @@ -607,16 +570,14 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
- if( Creature* pCreature = ObjectAccessor::GetCreatureInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_UNIT)) )
- pCreature->AddObjectToRemoveList();
- }
- + }
- }
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventGameobjectGuids.size())
- - {
- - sLog.outError("GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventGameobjectGuids element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventGameobjectGuids.size());
- - return;
- - }
- -
- - for (GuidList::iterator itr = mGameEventGameobjectGuids[internal_event_id].begin();itr != mGameEventGameobjectGuids[internal_event_id].end();++itr)
- + if(mGameEventGameobjectGuids.find(EventId) != mGameEventGameobjectGuids.end())
- {
- + GuidList GameObjectList = mGameEventGameobjectGuids[EventId];
- + for (GuidList::iterator itr = GameObjectList.begin();itr != GameObjectList.end();++itr)
- + {
- // Remove the gameobject from grid
- if(GameObjectData const* data = sObjectMgr.GetGOData(*itr))
- {
- @@ -625,17 +586,15 @@ void GameEventMgr::GameEventUnspawn(int16 event_id)
- if( GameObject* pGameobject = ObjectAccessor::GetGameObjectInWorld(MAKE_NEW_GUID(*itr, data->id, HIGHGUID_GAMEOBJECT)) )
- pGameobject->AddObjectToRemoveList();
- }
- - }
- - if (internal_event_id < 0 || (size_t)internal_event_id >= mGameEventPoolIds.size())
- - {
- - sLog.outError("GameEventMgr::GameEventUnspawn attempt access to out of range mGameEventPoolIds element %i (size: " SIZEFMTD ")",internal_event_id,mGameEventPoolIds.size());
- - return;
- + }
- }
- - for (IdList::iterator itr = mGameEventPoolIds[internal_event_id].begin();itr != mGameEventPoolIds[internal_event_id].end();++itr)
- + if(mGameEventPoolIds.find(EventId) != mGameEventPoolIds.end())
- {
- - sPoolMgr.DespawnPool(*itr);
- - }
- + IdList PoolList = mGameEventPoolIds[EventId];
- + for (IdList::iterator itr = PoolList.begin();itr != PoolList.end();++itr)
- + sPoolMgr.DespawnPool(*itr);
- + }
- }
- void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
- @@ -751,11 +710,9 @@ GameEventMgr::GameEventMgr()
- MANGOS_DLL_SPEC bool IsHolidayActive( HolidayIds id )
- {
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- - GameEventMgr::ActiveEvents const& ae = sGameEventMgr.GetActiveEventList();
- -
- - for(GameEventMgr::ActiveEvents::const_iterator itr = ae.begin(); itr != ae.end(); ++itr)
- - if (events[*itr].holiday_id == id)
- + GameEventMgr::GameEventDataMap const& Events = sGameEventMgr.GetEventMap();
- + for(GameEventMgr::GameEventDataMap::const_iterator itr = Events.begin(); itr != Events.end(); ++itr)
- + if(itr->second.holiday_id==id && itr->second.active)
- return true;
- return false;
- diff --git a/src/game/GameEventMgr.h b/src/game/GameEventMgr.h
- index cc61c4c..476d684 100644
- --- a/src/game/GameEventMgr.h
- +++ b/src/game/GameEventMgr.h
- @@ -31,15 +31,15 @@ class GameObject;
- struct GameEventData
- {
- - GameEventData() : start(1),end(0),occurence(0),length(0) {}
- + GameEventData() : start(1),end(0),occurence(0),length(0),holiday_id(0),node(0),active(false) {}
- time_t start;
- time_t end;
- + bool active;
- uint32 occurence;
- uint32 length;
- + uint32 node;
- uint32 holiday_id;
- std::string description;
- -
- - bool isValid() const { return length > 0; }
- };
- struct ModelEquip
- @@ -55,21 +55,19 @@ class GameEventMgr
- public:
- GameEventMgr();
- ~GameEventMgr() {};
- - typedef std::set<uint16> ActiveEvents;
- - typedef std::vector<GameEventData> GameEventDataMap;
- - ActiveEvents const& GetActiveEventList() const { return m_ActiveEvents; }
- - GameEventDataMap const& GetEventMap() const { return mGameEvent; }
- - bool CheckOneGameEvent(uint16 entry) const;
- - uint32 NextCheck(uint16 entry) const;
- - void LoadFromDB();
- + typedef std::map<uint16,GameEventData> GameEventDataMap;
- +
- uint32 Update();
- - bool IsActiveEvent(uint16 event_id) { return ( m_ActiveEvents.find(event_id)!=m_ActiveEvents.end()); }
- +
- + void LoadFromDB();
- uint32 Initialize();
- - void StartEvent(uint16 event_id, bool overwrite = false);
- - void StopEvent(uint16 event_id, bool overwrite = false);
- + uint32 NextCheck(GameEventData Event) const;
- + bool CheckOneGameEvent(GameEventData Event) const;
- + GameEventDataMap const& GetEventMap() const { return mGameEvent; }
- +
- + void StopEvent(uint16 EventId, bool OverWrite = false);
- + void StartEvent(uint16 EventId, bool OverWrite = false);
- private:
- - void AddActiveEvent(uint16 event_id) { m_ActiveEvents.insert(event_id); }
- - void RemoveActiveEvent(uint16 event_id) { m_ActiveEvents.erase(event_id); }
- void ApplyNewEvent(uint16 event_id);
- void UnApplyEvent(uint16 event_id);
- void GameEventSpawn(int16 event_id);
- @@ -79,21 +77,21 @@ class GameEventMgr
- protected:
- typedef std::list<uint32> GuidList;
- typedef std::list<uint16> IdList;
- - typedef std::vector<GuidList> GameEventGuidMap;
- - typedef std::vector<IdList> GameEventIdMap;
- + typedef std::map<int16,GuidList> GameEventGuidMap;
- + typedef std::map<int16,IdList> GameEventIdMap;
- typedef std::pair<uint32, ModelEquip> ModelEquipPair;
- typedef std::list<ModelEquipPair> ModelEquipList;
- - typedef std::vector<ModelEquipList> GameEventModelEquipMap;
- + typedef std::map<uint16,ModelEquipList> GameEventModelEquipMap;
- typedef std::pair<uint32, uint32> QuestRelation;
- typedef std::list<QuestRelation> QuestRelList;
- - typedef std::vector<QuestRelList> GameEventQuestMap;
- - GameEventQuestMap mGameEventQuests;
- + typedef std::map<uint16,QuestRelList> GameEventQuestMap;
- +
- GameEventModelEquipMap mGameEventModelEquip;
- - GameEventGuidMap mGameEventCreatureGuids;
- GameEventGuidMap mGameEventGameobjectGuids;
- + GameEventGuidMap mGameEventCreatureGuids;
- GameEventIdMap mGameEventPoolIds;
- + GameEventQuestMap mGameEventQuests;
- GameEventDataMap mGameEvent;
- - ActiveEvents m_ActiveEvents;
- bool m_IsGameEventsInit;
- };
- diff --git a/src/game/GridDefines.h b/src/game/GridDefines.h
- index ebfbf20..864489c 100644
- --- a/src/game/GridDefines.h
- +++ b/src/game/GridDefines.h
- @@ -40,7 +40,7 @@ class Player;
- #define CENTER_GRID_OFFSET (SIZE_OF_GRIDS/2)
- #define MIN_GRID_DELAY (MINUTE*IN_MILISECONDS)
- -#define MIN_MAP_UPDATE_DELAY 50
- +#define MIN_MAP_UPDATE_DELAY 35
- #define MAX_NUMBER_OF_CELLS 8
- #define SIZE_OF_GRID_CELL (SIZE_OF_GRIDS/MAX_NUMBER_OF_CELLS)
- diff --git a/src/game/Group.cpp b/src/game/Group.cpp
- index 18e77bf..2ca13a0 100644
- --- a/src/game/Group.cpp
- +++ b/src/game/Group.cpp
- @@ -1444,7 +1444,7 @@ uint32 Group::CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId, BattleGround
- if(!reference)
- return BG_JOIN_ERR_OFFLINE_MEMBER;
- - BGQueueIdBasedOnLevel queue_id = reference->GetBattleGroundQueueIdFromLevel();
- + uint8 queue_id = reference->GetBGLevelQueueId();
- uint32 arenaTeamId = reference->GetArenaTeamId(arenaSlot);
- uint32 team = reference->GetTeam();
- @@ -1459,7 +1459,7 @@ uint32 Group::CanJoinBattleGroundQueue(BattleGroundTypeId bgTypeId, BattleGround
- if(member->GetTeam() != team)
- return BG_JOIN_ERR_MIXED_FACTION;
- // not in the same battleground level braket, don't let join
- - if(member->GetBattleGroundQueueIdFromLevel() != queue_id)
- + if(member->GetBGLevelQueueId() != queue_id)
- return BG_JOIN_ERR_MIXED_LEVELS;
- // don't let join rated matches if the arena team id doesn't match
- if(isRated && member->GetArenaTeamId(arenaSlot) != arenaTeamId)
- diff --git a/src/game/InstanceData.cpp b/src/game/InstanceData.cpp
- index 394aa58..c1f236a 100644
- --- a/src/game/InstanceData.cpp
- +++ b/src/game/InstanceData.cpp
- @@ -22,8 +22,10 @@
- void InstanceData::SaveToDB()
- {
- - if(!Save()) return;
- - std::string data = Save();
- - CharacterDatabase.escape_string(data);
- - CharacterDatabase.PExecute("UPDATE instance SET data = '%s' WHERE id = '%d'", data.c_str(), instance->GetInstanceId());
- + if(const char *data_str = Save())
- + {
- + std::string data = data_str;
- + CharacterDatabase.escape_string(data);
- + CharacterDatabase.PExecute("UPDATE instance SET data = '%s' WHERE id = '%d'", data.c_str(), instance->GetInstanceId());
- + }
- }
- diff --git a/src/game/Level2.cpp b/src/game/Level2.cpp
- index ca2cc96..9bc41c5 100644
- --- a/src/game/Level2.cpp
- +++ b/src/game/Level2.cpp
- @@ -398,9 +398,9 @@ bool ChatHandler::HandleGoObjectCommand(const char* args)
- bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
- {
- - Player* pl = m_session->GetPlayer();
- QueryResult *result;
- - GameEventMgr::ActiveEvents const& activeEventsList = sGameEventMgr.GetActiveEventList();
- + Player* pl = m_session->GetPlayer();
- + GameEventMgr::GameEventDataMap const& Events = sGameEventMgr.GetEventMap();
- if(*args)
- {
- // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
- @@ -429,15 +429,18 @@ bool ChatHandler::HandleGameObjectTargetCommand(const char* args)
- eventFilter << " AND (event IS NULL ";
- bool initString = true;
- - for (GameEventMgr::ActiveEvents::const_iterator itr = activeEventsList.begin(); itr != activeEventsList.end(); ++itr)
- + for (GameEventMgr::GameEventDataMap::const_iterator itr = Events.begin(); itr != Events.end(); ++itr)
- {
- + if(itr->second.active)
- + {
- if (initString)
- {
- - eventFilter << "OR event IN (" <<*itr;
- - initString =false;
- + eventFilter << "OR event IN (" << itr->first;
- + initString =false;
- }
- else
- - eventFilter << "," << *itr;
- + eventFilter << "," << itr->first;
- + }
- }
- if (!initString)
- @@ -3689,12 +3692,10 @@ bool ChatHandler::HandleLookupEventCommand(const char* args)
- uint32 counter = 0;
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- - GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
- -
- - for(uint32 id = 0; id < events.size(); ++id )
- + GameEventMgr::GameEventDataMap const &gEvents = sGameEventMgr.GetEventMap();
- + for (GameEventMgr::GameEventDataMap::const_iterator iter = gEvents.begin(); iter != gEvents.end(); iter++)
- {
- - GameEventData const& eventData = events[id];
- + GameEventData eventData = iter->second;
- std::string descr = eventData.description;
- if(descr.empty())
- @@ -3702,12 +3703,12 @@ bool ChatHandler::HandleLookupEventCommand(const char* args)
- if (Utf8FitTo(descr, wnamepart))
- {
- - char const* active = activeEvents.find(id) != activeEvents.end() ? GetMangosString(LANG_ACTIVE) : "";
- + char const* active = eventData.active ? GetMangosString(LANG_ACTIVE) : "";
- if(m_session)
- - PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT,id,id,eventData.description.c_str(),active );
- + PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT,iter->first,iter->first,eventData.description.c_str(),active );
- else
- - PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE,id,eventData.description.c_str(),active );
- + PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE,iter->first,eventData.description.c_str(),active );
- ++counter;
- }
- @@ -3727,16 +3728,15 @@ bool ChatHandler::HandleEventListCommand(const char* args)
- if (arg == "all")
- all = true;
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- - GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
- + GameEventMgr::GameEventDataMap const& gEvents = sGameEventMgr.GetEventMap();
- char const* active = GetMangosString(LANG_ACTIVE);
- char const* inactive = GetMangosString(LANG_FACTION_INACTIVE);
- char const* state = "";
- - for (uint32 event_id = 0; event_id < events.size(); ++event_id)
- + for (GameEventMgr::GameEventDataMap::const_iterator iter = gEvents.begin(); iter != gEvents.end(); iter++)
- {
- - if (activeEvents.find(event_id) == activeEvents.end())
- + if (!iter->second.active)
- {
- if (!all)
- continue;
- @@ -3745,12 +3745,12 @@ bool ChatHandler::HandleEventListCommand(const char* args)
- else
- state = active;
- - GameEventData const& eventData = events[event_id];
- + GameEventData eventData = iter->second;
- if(m_session)
- - PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, event_id, event_id, eventData.description.c_str(), state);
- + PSendSysMessage(LANG_EVENT_ENTRY_LIST_CHAT, iter->first, iter->first, eventData.description.c_str(), state);
- else
- - PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, event_id, eventData.description.c_str(), state);
- + PSendSysMessage(LANG_EVENT_ENTRY_LIST_CONSOLE, iter->first, eventData.description.c_str(), state);
- ++counter;
- }
- @@ -3771,33 +3771,23 @@ bool ChatHandler::HandleEventInfoCommand(const char* args)
- if(!cId)
- return false;
- - uint32 event_id = atoi(cId);
- + uint32 event_id = uint32(atoi(cId));
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- -
- - if(event_id >=events.size())
- - {
- - SendSysMessage(LANG_EVENT_NOT_EXIST);
- - SetSentErrorMessage(true);
- - return false;
- - }
- + GameEventMgr::GameEventDataMap gEvents = ((GameEventMgr::GameEventDataMap)sGameEventMgr.GetEventMap());
- - GameEventData const& eventData = events[event_id];
- - if(!eventData.isValid())
- + if(gEvents.find(event_id) == gEvents.end())
- {
- SendSysMessage(LANG_EVENT_NOT_EXIST);
- SetSentErrorMessage(true);
- return false;
- }
- - GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
- - bool active = activeEvents.find(event_id) != activeEvents.end();
- - char const* activeStr = active ? GetMangosString(LANG_ACTIVE) : "";
- -
- + GameEventData eventData = gEvents[event_id];
- + char const* activeStr = eventData.active ? GetMangosString(LANG_ACTIVE) : "";
- std::string startTimeStr = TimeToTimestampStr(eventData.start);
- std::string endTimeStr = TimeToTimestampStr(eventData.end);
- - uint32 delay = sGameEventMgr.NextCheck(event_id);
- + uint32 delay = sGameEventMgr.NextCheck(eventData);
- time_t nextTime = time(NULL)+delay;
- std::string nextStr = nextTime >= eventData.start && nextTime < eventData.end ? TimeToTimestampStr(time(NULL)+delay) : "-";
- @@ -3820,27 +3810,18 @@ bool ChatHandler::HandleEventStartCommand(const char* args)
- if(!cId)
- return false;
- - int32 event_id = atoi(cId);
- -
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- -
- - if(event_id < 1 || event_id >=events.size())
- - {
- - SendSysMessage(LANG_EVENT_NOT_EXIST);
- - SetSentErrorMessage(true);
- - return false;
- - }
- + uint32 event_id = uint32(atoi(cId));
- + GameEventMgr::GameEventDataMap events = ((GameEventMgr::GameEventDataMap)sGameEventMgr.GetEventMap());
- - GameEventData const& eventData = events[event_id];
- - if(!eventData.isValid())
- + if(events.find(event_id)==events.end())
- {
- SendSysMessage(LANG_EVENT_NOT_EXIST);
- SetSentErrorMessage(true);
- return false;
- }
- + GameEventData eventData = events[event_id];
- - GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
- - if(activeEvents.find(event_id) != activeEvents.end())
- + if(eventData.active)
- {
- PSendSysMessage(LANG_EVENT_ALREADY_ACTIVE,event_id);
- SetSentErrorMessage(true);
- @@ -3862,28 +3843,19 @@ bool ChatHandler::HandleEventStopCommand(const char* args)
- if(!cId)
- return false;
- - int32 event_id = atoi(cId);
- -
- - GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- -
- - if(event_id < 1 || event_id >=events.size())
- - {
- - SendSysMessage(LANG_EVENT_NOT_EXIST);
- - SetSentErrorMessage(true);
- - return false;
- - }
- + uint32 event_id = uint32(atoi(cId));
- + GameEventMgr::GameEventDataMap gEvents = ((GameEventMgr::GameEventDataMap)sGameEventMgr.GetEventMap());
- - GameEventData const& eventData = events[event_id];
- - if(!eventData.isValid())
- + if(gEvents.find(event_id) == gEvents.end())
- {
- SendSysMessage(LANG_EVENT_NOT_EXIST);
- SetSentErrorMessage(true);
- return false;
- }
- - GameEventMgr::ActiveEvents const& activeEvents = sGameEventMgr.GetActiveEventList();
- + GameEventData eventData = gEvents[event_id];
- - if(activeEvents.find(event_id) == activeEvents.end())
- + if(!eventData.active)
- {
- PSendSysMessage(LANG_EVENT_NOT_ACTIVE,event_id);
- SetSentErrorMessage(true);
- diff --git a/src/game/Map.cpp b/src/game/Map.cpp
- index 2347b00..9807287 100644
- --- a/src/game/Map.cpp
- +++ b/src/game/Map.cpp
- @@ -25,7 +25,9 @@
- #include "CellImpl.h"
- #include "InstanceData.h"
- #include "Map.h"
- +#include "BattleGroundMgr.h"
- #include "GridNotifiersImpl.h"
- +#include "Database/DatabaseImpl.h"
- #include "Config/ConfigEnv.h"
- #include "Transports.h"
- #include "ObjectAccessor.h"
- @@ -54,6 +56,44 @@ struct ScriptAction
- ScriptInfo const* script; // pointer to static script data
- };
- +class MapRunnable : public ACE_Based::Runnable //Map Updater Class
- +{
- + public:
- + MapRunnable(Map *map) : m_Map(map),m_resultQueue(NULL){}
- + ~MapRunnable(){ CharacterDatabase.UnSetResultQueue(m_resultQueue); }
- +
- + void run()
- + {
- + IntervalTimer i_timer;
- + uint32 realCurrTime = 0,realPrevTime = getMSTime();
- + i_timer.SetInterval(sWorld.getConfig(CONFIG_MAPUPDATER_INTERVAL));
- + while(!sWorld.m_WorldStarted) // Sleep while server isnt completly online
- + ACE_Based::Thread::Sleep(MIN_UNLOAD_DELAY);
- +
- + m_resultQueue = new SqlResultQueue;
- + CharacterDatabase.SetResultQueue(m_resultQueue);
- +
- + while(!World::IsStopped())
- + {
- + realCurrTime = getMSTime();
- + i_timer.Update(realCurrTime - realPrevTime);
- +
- + if(i_timer.Passed())
- + {
- + m_Map->Update(i_timer.GetCurrent());
- + m_resultQueue->Update();
- + i_timer.SetCurrent(0);
- + }else ACE_Based::Thread::Sleep(MIN_UNLOAD_DELAY); //Avoid High CPU Usage
- +
- + realPrevTime = realCurrTime;
- + }
- + }
- +
- + protected:
- + Map *m_Map;
- + SqlResultQueue *m_resultQueue;
- +};
- +
- Map::~Map()
- {
- ObjectAccessor::DelinkMap(this);
- @@ -198,12 +238,11 @@ void Map::DeleteStateMachine()
- }
- Map::Map(uint32 id, time_t expiry, uint32 InstanceId, uint8 SpawnMode, Map* _parent)
- - : i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode),
- - i_id(id), i_InstanceId(InstanceId), m_unloadTimer(0),
- - m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE),
- - m_activeNonPlayersIter(m_activeNonPlayers.end()),
- - i_gridExpiry(expiry), m_parentMap(_parent ? _parent : this),
- - m_hiDynObjectGuid(1), m_hiPetGuid(1), m_hiVehicleGuid(1)
- +: i_mapEntry (sMapStore.LookupEntry(id)), i_spawnMode(SpawnMode), m_hiVehicleGuid(1),
- +m_hiPetGuid(1), i_InstanceId(InstanceId), stUpdater(UPDATER_ACTIVE), m_unloadTimer(0),
- +m_activeNonPlayersIter(m_activeNonPlayers.end()), i_id(id),m_hiDynObjectGuid(1),
- +i_gridExpiry(expiry), m_parentMap(_parent ? _parent : this),
- +m_VisibleDistance(DEFAULT_VISIBILITY_DISTANCE)
- {
- for(unsigned int idx=0; idx < MAX_NUMBER_OF_GRIDS; ++idx)
- {
- @@ -585,15 +624,32 @@ bool Map::loaded(const GridPair &p) const
- return ( getNGrid(p.x_coord, p.y_coord) && isGridObjectDataLoaded(p.x_coord, p.y_coord) );
- }
- +bool Map::HaveParentPlayers()
- +{
- + if(!i_InstanceId && Instanceable())
- + {
- + MapInstanced::InstancedMaps InstanceList = ((MapInstanced*)this)->GetInstancedMaps();
- + for(MapInstanced::InstancedMaps::iterator m_Iter = InstanceList.begin(); m_Iter != InstanceList.end(); m_Iter++)
- + if(!m_Iter->second->GetPlayers().isEmpty())
- + return true;
- + }
- + else if(!GetPlayers().isEmpty())
- + return true;
- + return false;
- +}
- +
- void Map::Update(const uint32 &t_diff)
- {
- - /// update players at tick
- - for(m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); ++m_mapRefIter)
- - {
- - Player* plr = m_mapRefIter->getSource();
- - if(plr && plr->IsInWorld())
- - plr->Update(t_diff);
- - }
- + //Unload unused map only if there isnt transports, if isnt a continent and isnt a BG or arena
- + if(m_parentMap == this && sMapMgr.m_TransportsByMap.end() == sMapMgr.m_TransportsByMap.find(i_id) &&
- + Instanceable() && !IsBattleGroundOrArena())
- + {
- + bool bHavePlayers = HaveParentPlayers();
- + if(bHavePlayers && m_unloadTimer)
- + m_unloadTimer = 0;
- + else if(!bHavePlayers && !m_unloadTimer)
- + m_unloadTimer = sWorld.getConfig(CONFIG_MAPUPDATER_UNLOAD_DELAY);
- + }
- /// update active cells around players and active objects
- resetMarkedCells();
- @@ -606,11 +662,32 @@ void Map::Update(const uint32 &t_diff)
- // the player iterator is stored in the map object
- // to make sure calls to Map::Remove don't invalidate it
- - for(m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); ++m_mapRefIter)
- + MapRefManager::iterator m_mapNextRefIter = m_mapRefIter;
- + for(m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); m_mapRefIter = m_mapNextRefIter)
- {
- - Player* plr = m_mapRefIter->getSource();
- + //Avoid crash at erase somewhere
- + m_mapNextRefIter = m_mapRefIter; ++m_mapNextRefIter;
- +
- + if(Player* plr = m_mapRefIter->getSource())
- + {
- + if(WorldSession *m_sess = plr->GetSession())
- + {
- + if(!m_sess->IsUpdating())
- + {
- + m_sess->SetUpdating(true);
- - if(!plr->IsInWorld())
- + if(plr->IsInWorld())
- + plr->Update(t_diff);
- +
- + if(m_sess->GetUpdateStatus() == SESSION_UPDATE_MAP)
- + if(!m_sess->Update(0)) // If session update fails move it to remove queue
- + m_sess->SetUpdateStatus(SESSION_REMOVE_QUEUE);
- +
- + m_sess->SetUpdating(false);
- + }
- + }
- +
- + if(!plr->IsInWorld())
- continue;
- CellPair standing_cell(MaNGOS::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()));
- @@ -646,6 +723,7 @@ void Map::Update(const uint32 &t_diff)
- }
- }
- }
- + }
- }
- // non-player active objects
- @@ -718,6 +796,15 @@ void Map::Update(const uint32 &t_diff)
- ///- Process necessary scripts
- if (!m_scriptSchedule.empty())
- ScriptsProcess();
- +
- + DoDelayedMovesAndRemoves();
- +}
- +
- +void Map::DelayedNotifyPosition(Player *player)
- +{
- + CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
- + Cell cell(p);
- + AddNotifier(player,cell,p);
- }
- void Map::Remove(Player *player, bool remove)
- @@ -1116,8 +1203,9 @@ bool Map::UnloadGrid(const uint32 &x, const uint32 &y, bool pForce)
- void Map::UnloadAll(bool pForce)
- {
- - // clear all delayed moves, useless anyway do this moves before map unload.
- - i_creaturesToMove.clear();
- +
- + i_creaturesToMove.clear(); // clear all delayed moves
- + i_objectsToClientUpdate.clear(); //Clear update object set
- for (GridRefManager<NGridType>::iterator i = GridRefManager<NGridType>::begin(); i != GridRefManager<NGridType>::end(); )
- {
- @@ -2198,6 +2286,77 @@ uint32 Map::GetPlayersCountExceptGMs() const
- return count;
- }
- +void Map::Restart()
- +{
- + stUpdater = UPDATER_RESTARTING;
- +
- + if(Instanceable())
- + {
- + // Process Players in instances on this map
- + MapInstanced::InstancedMaps InstanceList = ((MapInstanced*)this)->GetInstancedMaps();
- + for(MapInstanced::InstancedMaps::iterator m_Iter = InstanceList.begin(); m_Iter != InstanceList.end(); m_Iter++)
- + {
- + PlayerList const& pList = m_Iter->second->GetPlayers();
- +
- + for(PlayerList::const_iterator itr = pList.begin(), next; itr != pList.end(); itr = next)
- + {
- + next = itr; ++next;
- + if(Player *_player = itr->getSource())
- + {
- + if(WorldSession *m_sess = _player->GetSession())
- + {
- + uint32 B_Time = getMSTime(); // Try to prevent full crash for 2 seconds if it's login
- + while(m_sess->PlayerLoading() && m_sess->IsUpdating() && (getMSTime()-B_Time) < 2000);
- + _player->CombatStop(true); //Stop Attacking
- + _player->getHostileRefManager().deleteReferences();
- + m_sess->LogoutPlayer(true); // Send logout to players
- + m_sess->SetUpdating(false); //
- + m_sess->SetUpdateStatus(SESSION_UPDATE_WORLD); // Change Session processor to World Thread
- + }
- + }
- + }
- +
- + if(InstanceData *i_data = ((InstanceMap *)m_Iter->second)->GetInstanceData())
- + i_data->SaveToDB(); // Save all InstanceData on this map
- + }
- + }
- + else
- + { //Process players in Continent map
- + MapRefManager::iterator next;
- + for(m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); m_mapRefIter = next)
- + {
- + next = m_mapRefIter; ++next;
- + if(Player *_player = m_mapRefIter->getSource())
- + {
- + if(WorldSession *m_sess = _player ? _player->GetSession() : NULL)
- + {
- + uint32 B_Time = getMSTime(); // Try to prevent full crash for 2 seconds if it's login
- + while(m_sess->PlayerLoading() && m_sess->IsUpdating() && (getMSTime()-B_Time) < 2000);
- + _player->CombatStop(true); //Stop Attacking
- + _player->getHostileRefManager().deleteReferences();
- + m_sess->LogoutPlayer(true); // Send logout to players
- + m_sess->SetUpdating(false); //
- + m_sess->SetUpdateStatus(SESSION_UPDATE_WORLD); //Change Session processor to World Thread
- + }
- + }
- + }
- + }
- +
- + UnloadAll(true); //Map Unload
- + stUpdater = UPDATER_PAUSED;
- +}
- +
- +bool Map::StartUpdater()
- +{
- + sLog.outDebug("MapUpdater: Initializated for map %u.\r\n",GetId());
- + uThread = new ACE_Based::Thread(new MapRunnable(this));
- + stUpdater = UPDATER_ACTIVE;
- + return bool(uThread->ThreadId());
- +}
- +
- +bool Map::StopUpdater()
- +{ return ACE_Based::Thread::kill_self(); }
- +
- void Map::SendToPlayers(WorldPacket const* data) const
- {
- for(MapRefManager::const_iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
- @@ -2671,6 +2830,19 @@ bool BattleGroundMap::CanEnter(Player * player)
- return Map::CanEnter(player);
- }
- +void BattleGroundMap::Update(const uint32& t_diff)
- +{
- + Map::Update(t_diff);
- + if(m_bg)
- + {
- + m_bg->Update(t_diff);
- +
- + if (m_bg->CanUnload())
- + sBattleGroundMgr.DestroyBattleGround(m_bg);
- + }
- +
- +}
- +
- bool BattleGroundMap::Add(Player * player)
- {
- {
- diff --git a/src/game/Map.h b/src/game/Map.h
- index d63cb51..10d7148 100644
- --- a/src/game/Map.h
- +++ b/src/game/Map.h
- @@ -68,6 +68,14 @@ typedef RGuard<GridRWLock, ACE_Thread_Mutex> GridReadGuard;
- typedef WGuard<GridRWLock, ACE_Thread_Mutex> GridWriteGuard;
- typedef MaNGOS::SingleThreaded<GridRWLock>::Lock NullGuard;
- +enum UpdaterStatus
- +{
- + UPDATER_ACTIVE = 1,
- + UPDATER_RESTARTING = 2,
- + UPDATER_PAUSED = 3,
- + UPDATER_STOP = 4
- +};
- +
- //******************************************
- // Map file format defines
- //******************************************
- @@ -397,6 +405,7 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
- }
- void AddObjectToRemoveList(WorldObject *obj);
- + void DelayedNotifyPosition( Player * player );
- void DoDelayedMovesAndRemoves();
- virtual bool RemoveBones(uint64 guid, float x, float y);
- @@ -409,10 +418,16 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
- bool isCellMarked(uint32 pCellId) { return marked_cells.test(pCellId); }
- void markCell(uint32 pCellId) { marked_cells.set(pCellId); }
- + bool HaveParentPlayers();
- bool HavePlayers() const { return !m_mapRefManager.isEmpty(); }
- uint32 GetPlayersCountExceptGMs() const;
- bool ActiveObjectsNearGrid(uint32 x,uint32 y) const;
- + void Restart();
- + bool StopUpdater();
- + bool StartUpdater();
- + ACE_Based::Thread *GetThread(){ return uThread; }
- + UpdaterStatus GetUpdaterStatus() { return stUpdater; }
- void SendToPlayers(WorldPacket const* data) const;
- typedef MapRefManager PlayerList;
- @@ -517,6 +532,8 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>, public MaNGOS::Obj
- MapRefManager m_mapRefManager;
- MapRefManager::iterator m_mapRefIter;
- + ACE_Based::Thread *uThread;
- + UpdaterStatus stUpdater;
- typedef std::set<WorldObject*> ActiveNonPlayers;
- ActiveNonPlayers m_activeNonPlayers;
- @@ -621,12 +638,12 @@ class MANGOS_DLL_SPEC BattleGroundMap : public Map
- BattleGroundMap(uint32 id, time_t, uint32 InstanceId, Map* _parent, uint8 spawnMode);
- ~BattleGroundMap();
- + void SetUnload();
- bool Add(Player *);
- + void Update(const uint32&);
- void Remove(Player *, bool);
- - bool CanEnter(Player* player);
- - void SetUnload();
- void UnloadAll(bool pForce);
- -
- + bool CanEnter(Player* player);
- virtual void InitVisibilityDistance();
- BattleGround* GetBG() { return m_bg; }
- void SetBG(BattleGround* bg) { m_bg = bg; }
- diff --git a/src/game/MapInstanced.cpp b/src/game/MapInstanced.cpp
- index 1b76f73..25ef956 100644
- --- a/src/game/MapInstanced.cpp
- +++ b/src/game/MapInstanced.cpp
- @@ -20,6 +20,7 @@
- #include "ObjectMgr.h"
- #include "MapManager.h"
- #include "BattleGround.h"
- +#include "BattleGroundMgr.h"
- #include "VMapFactory.h"
- #include "InstanceSaveMgr.h"
- #include "World.h"
- @@ -217,7 +218,8 @@ BattleGroundMap* MapInstanced::CreateBattleGroundMap(uint32 InstanceId, BattleGr
- sLog.outDebug("MapInstanced::CreateBattleGroundMap: instance:%d for map:%d and bgType:%d created.", InstanceId, GetId(), bg->GetTypeID());
- // 0-59 normal spawn 60-69 difficulty_1, 70-79 difficulty_2, 80 dufficulty_3
- - uint8 spawnMode = (bg->GetQueueId() > QUEUE_ID_MAX_LEVEL_59) ? (bg->GetQueueId() - QUEUE_ID_MAX_LEVEL_59) : 0;
- + uint8 SpawnQueue = uint8(float(sBattleGroundMgr.GetMaxQueueId()) * 0.75f);
- + uint8 spawnMode = (bg->GetQueueId() > SpawnQueue) ? (bg->GetQueueId() - SpawnQueue) : 0;
- // some bgs don't have different spawnmodes, with this we can stay close to dbc-data
- while (!GetMapDifficultyData(GetId(), Difficulty(spawnMode)))
- spawnMode--;
- diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp
- index 94055bf..f615f3b 100644
- --- a/src/game/MapManager.cpp
- +++ b/src/game/MapManager.cpp
- @@ -36,9 +36,9 @@ INSTANTIATE_CLASS_MUTEX(MapManager, ACE_Thread_Mutex);
- extern GridState* si_GridStates[]; // debugging code, should be deleted some day
- -MapManager::MapManager() : i_gridCleanUpDelay(sWorld.getConfig(CONFIG_INTERVAL_GRIDCLEAN))
- +MapManager::MapManager() : i_gridCleanUpDelay(sWorld.getConfig(CONFIG_INTERVAL_GRIDCLEAN)), uCrashCount(0)
- {
- - i_timer.SetInterval(sWorld.getConfig(CONFIG_INTERVAL_MAPUPDATE));
- + SetMapUpdateInterval(sWorld.getConfig(CONFIG_MAPUPDATER_INTERVAL));
- }
- MapManager::~MapManager()
- @@ -120,6 +120,8 @@ MapManager::_createBaseMap(uint32 id)
- {
- m = new Map(id, i_gridCleanUpDelay, 0, REGULAR_DIFFICULTY);
- }
- +
- + assert(m->StartUpdater());
- i_maps[id] = m;
- }
- @@ -138,6 +140,15 @@ Map* MapManager::CreateMap(uint32 id, const WorldObject* obj)
- return m;
- }
- +Map* MapManager::FindMapByThread(ACE_thread_t tId)
- +{
- + for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
- + if(ACE_Based::Thread *Updater = iter->second->GetThread())
- + if(Updater->ThreadId() == tId)
- + return iter->second;
- + return NULL;
- +}
- +
- Map* MapManager::FindMap(uint32 mapid, uint32 instanceId) const
- {
- Map *map = _findMap(mapid);
- @@ -256,19 +267,38 @@ void
- MapManager::Update(uint32 diff)
- {
- i_timer.Update(diff);
- - if( !i_timer.Passed() )
- - return;
- -
- - for(MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
- - {
- - checkAndCorrectGridStatesArray(); // debugging code, should be deleted some day
- - iter->second->Update(i_timer.GetCurrent());
- - }
- -
- - for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
- - (*iter)->Update(i_timer.GetCurrent());
- -
- - i_timer.SetCurrent(0);
- + if( i_timer.Passed() )
- + {
- +
- + for (TransportSet::iterator iter = m_Transports.begin(); iter != m_Transports.end(); ++iter)
- + (*iter)->Update(i_timer.GetCurrent());
- +
- + for(MapMapType::iterator iter=i_maps.begin(),next; iter != i_maps.end(); iter = next)
- + {
- + next = iter;++next;
- + UpdaterStatus MapStatus = iter->second->GetUpdaterStatus();
- + if(MapStatus == UPDATER_PAUSED)
- + {
- + delete iter->second->GetThread();
- + iter->second->StartUpdater();
- + }
- + //If is possible and no player enter in the map by a time, delete it
- + else if(MapStatus == UPDATER_ACTIVE && iter->second->CanUnload(diff))
- + {
- + sLog.outDebug("MapUpdater: Unloading Map %u",iter->second->GetId());
- + ACE_Based::Thread *t_Thread = iter->second->GetThread();
- + t_Thread->kill(SIGTERM);
- + t_Thread->wait();
- +
- + delete iter->second;
- + delete t_Thread;
- + i_maps.erase(iter);
- + }
- +
- + }
- +
- + i_timer.SetCurrent(0);
- + }
- }
- void MapManager::DoDelayedMovesAndRemoves()
- diff --git a/src/game/MapManager.h b/src/game/MapManager.h
- index 3586845..0fbeced 100644
- --- a/src/game/MapManager.h
- +++ b/src/game/MapManager.h
- @@ -75,7 +75,9 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
- void SetMapUpdateInterval(uint32 t)
- {
- - if( t > MIN_MAP_UPDATE_DELAY )
- + t >>= 2;
- + // Manager updates 4 times more faster than maps
- + if( t < MIN_MAP_UPDATE_DELAY )
- t = MIN_MAP_UPDATE_DELAY;
- i_timer.SetInterval(t);
- @@ -111,6 +113,9 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
- void DoDelayedMovesAndRemoves();
- void LoadTransports();
- + uint16 GetCrashCount(){ return uCrashCount; }
- + void IncreaseCrashCount(){ uCrashCount++; }
- + Map* FindMapByThread(ACE_thread_t tId);
- typedef std::set<Transport *> TransportSet;
- TransportSet m_Transports;
- @@ -151,7 +156,7 @@ class MANGOS_DLL_DECL MapManager : public MaNGOS::Singleton<MapManager, MaNGOS::
- uint32 i_gridCleanUpDelay;
- MapMapType i_maps;
- IntervalTimer i_timer;
- -
- + uint16 uCrashCount;
- uint32 i_MaxInstanceId;
- };
- diff --git a/src/game/MovementHandler.cpp b/src/game/MovementHandler.cpp
- index 5853824..6a36f7f 100644
- --- a/src/game/MovementHandler.cpp
- +++ b/src/game/MovementHandler.cpp
- @@ -44,8 +44,10 @@ void WorldSession::HandleMoveWorldportAckOpcode()
- if(!GetPlayer()->IsBeingTeleportedFar())
- return;
- - // get the teleport destination
- - WorldLocation &loc = GetPlayer()->GetTeleportDest();
- + // get the teleport destination and original localization
- + WorldLocation org_loc, loc;
- + GetPlayer()->GetPosition(org_loc);
- + loc = GetPlayer()->GetTeleportDest();
- // possible errors in the coordinate validity check
- if(!MapManager::IsValidMapCoord(loc.mapid, loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation))
- @@ -74,6 +76,19 @@ void WorldSession::HandleMoveWorldportAckOpcode()
- GetPlayer()->Relocate(loc.coord_x, loc.coord_y, loc.coord_z, loc.orientation);
- GetPlayer()->SendInitialPacketsBeforeAddToMap();
- + //Abort teleport to map not activated
- +
- + if(Map *m_Map_p = sMapMgr.FindMap(loc.mapid))
- + {
- + if(m_Map_p->GetUpdaterStatus() != UPDATER_ACTIVE)
- + {
- + GetPlayer()->ResetMap();
- + GetPlayer()->SendTransferAborted(loc.mapid, TRANSFER_ABORT_MAP_NOT_ALLOWED,0);
- + GetPlayer()->TeleportTo(org_loc.mapid, org_loc.coord_x, org_loc.coord_y, org_loc.coord_z, org_loc.orientation);
- + return;
- + }
- + }
- +
- // the CanEnter checks are done in TeleporTo but conditions may change
- // while the player is in transit, for example the map may get full
- if(!GetPlayer()->GetMap()->Add(GetPlayer()))
- @@ -164,6 +179,9 @@ void WorldSession::HandleMoveWorldportAckOpcode()
- //lets process all delayed operations on successful teleport
- GetPlayer()->ProcessDelayedOperations();
- +
- + // Set session updater to map again
- + SetUpdateStatus(SESSION_UPDATE_MAP);
- }
- void WorldSession::HandleMoveTeleportAck(WorldPacket& recv_data)
- diff --git a/src/game/Object.cpp b/src/game/Object.cpp
- index c3aaa99..f8f5d91 100644
- --- a/src/game/Object.cpp
- +++ b/src/game/Object.cpp
- @@ -1924,9 +1924,12 @@ struct WorldObjectChangeAccumulator
- WorldObjectChangeAccumulator(WorldObject &obj, UpdateDataMapType &d) : i_updateDatas(d), i_object(obj) {}
- void Visit(PlayerMapType &m)
- {
- - for(PlayerMapType::iterator iter = m.begin(); iter != m.end(); ++iter)
- + for(PlayerMapType::iterator iter = m.begin(), next; iter != m.end(); iter = next)
- + {
- + next = iter; ++next;
- if(iter->getSource()->HaveAtClient(&i_object))
- i_object.BuildUpdateDataForPlayer(iter->getSource(), i_updateDatas);
- + }
- }
- template<class SKIP> void Visit(GridRefManager<SKIP> &) {}
- diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
- index 3407fd9..eedd9d5 100644
- --- a/src/game/ObjectMgr.cpp
- +++ b/src/game/ObjectMgr.cpp
- @@ -7233,7 +7233,12 @@ bool PlayerCondition::Meets(Player const * player) const
- case CONDITION_NO_AURA:
- return !player->HasAura(value1, value2);
- case CONDITION_ACTIVE_EVENT:
- - return sGameEventMgr.IsActiveEvent(value1);
- + {
- + GameEventMgr::GameEventDataMap gEvents = ((GameEventMgr::GameEventDataMap)sGameEventMgr.GetEventMap());
- + if(gEvents.find(value1) != gEvents.end())
- + return gEvents[value1].active;
- + return false;
- + }
- default:
- return false;
- }
- @@ -7371,7 +7376,7 @@ bool PlayerCondition::IsValid(ConditionType condition, uint32 value1, uint32 val
- case CONDITION_ACTIVE_EVENT:
- {
- GameEventMgr::GameEventDataMap const& events = sGameEventMgr.GetEventMap();
- - if(value1 >=events.size() || !events[value1].isValid())
- + if(events.find(value1) == events.end())
- {
- sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1);
- return false;
- diff --git a/src/game/Player.cpp b/src/game/Player.cpp
- index bec9861..d721d3e 100644
- --- a/src/game/Player.cpp
- +++ b/src/game/Player.cpp
- @@ -36,6 +36,7 @@
- #include "ChannelMgr.h"
- #include "MapManager.h"
- #include "MapInstanced.h"
- +#include "GameEventMgr.h"
- #include "InstanceSaveMgr.h"
- #include "GridNotifiers.h"
- #include "GridNotifiersImpl.h"
- @@ -318,6 +319,7 @@ Player::Player (WorldSession *session): Unit(), m_achievementMgr(this), m_reputa
- m_zoneUpdateTimer = 0;
- m_areaUpdateId = 0;
- + bPosNotifyAfterAddToMap = false;
- m_nextSave = sWorld.getConfig(CONFIG_INTERVAL_SAVE);
- @@ -1068,6 +1070,12 @@ void Player::Update( uint32 p_time )
- m_nextMailDelivereTime = 0;
- }
- + if(bPosNotifyAfterAddToMap)
- + {
- + GetMap()->DelayedNotifyPosition(this);
- + bPosNotifyAfterAddToMap = false;
- + }
- +
- //used to implement delayed far teleports
- SetCanDelayTeleport(true);
- Unit::Update( p_time );
- @@ -1704,6 +1712,9 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
- return true;
- }
- + // Change session updater to world thread at teleport
- + m_session->SetUpdateStatus(SESSION_UPDATE_WORLD);
- +
- SetSelection(0);
- CombatStop();
- @@ -1872,6 +1883,8 @@ void Player::AddToWorld()
- if(m_items[i])
- m_items[i]->AddToWorld();
- }
- +
- + bPosNotifyAfterAddToMap = true;
- }
- void Player::RemoveFromWorld()
- @@ -7764,7 +7777,8 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
- data << uint32(mapid); // mapid
- data << uint32(zoneid); // zone id
- data << uint32(areaid); // area id, new 2.1.0
- - data << uint16(NumberOfFields); // count of uint64 blocks
- + size_t count_pos = data.wpos();
- + data << uint16(0); // count of uint64 blocks
- data << uint32(0x8d8) << uint32(0x0); // 1
- data << uint32(0x8d7) << uint32(0x0); // 2
- data << uint32(0x8d6) << uint32(0x0); // 3
- @@ -7775,6 +7789,18 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
- data << uint32(0xC77) << uint32(sWorld.getConfig(CONFIG_ARENA_SEASON_IN_PROGRESS));
- // 8 Arena season id
- data << uint32(0xF3D) << uint32(sWorld.getConfig(CONFIG_ARENA_SEASON_ID));
- +
- + // Events nodes
- + GameEventMgr::GameEventDataMap const& Events = sGameEventMgr.GetEventMap();
- + for(GameEventMgr::GameEventDataMap::const_iterator iter = Events.begin(); iter != Events.end(); iter++)
- + {
- + if(iter->second.node)
- + {
- + data << uint32(iter->second.node) << uint32(iter->second.active);
- + NumberOfFields++;
- + }
- + }
- +
- if(mapid == 530) // Outland
- {
- data << uint32(0x9bf) << uint32(0x0); // 7
- @@ -8080,6 +8106,8 @@ void Player::SendInitWorldStates(uint32 zoneid, uint32 areaid)
- data << uint32(0x915) << uint32(0x0); // 10
- break;
- }
- +
- + data.put<uint16>(count_pos,NumberOfFields);
- GetSession()->SendPacket(&data);
- }
- @@ -18691,16 +18719,16 @@ bool Player::GetBGAccessByLevel(BattleGroundTypeId bgTypeId) const
- return true;
- }
- -BGQueueIdBasedOnLevel Player::GetBattleGroundQueueIdFromLevel() const
- +uint8 Player::GetBGLevelQueueId() const
- {
- - // for ranges 0 - 19, 20 - 29, 30 - 39, 40 - 49, 50 - 59, 60 - 69, 70 - 79, 80
- - uint32 queue_id = ( getLevel() / 10) - 1;
- - if( queue_id >= MAX_BATTLEGROUND_QUEUES )
- + uint8 QueueId = uint8(( getLevel() / 10) - 1), MaxQueueId = sBattleGroundMgr.GetMaxQueueId();
- +
- + if( QueueId >= MaxQueueId )
- {
- - sLog.outError("BattleGround: too high queue_id %u this shouldn't happen", queue_id);
- - return QUEUE_ID_MAX_LEVEL_80;
- + sLog.outError("BattleGround: too high queue_id %u this shouldn't happen", QueueId);
- + return uint8(MaxQueueId - 1);
- }
- - return BGQueueIdBasedOnLevel(queue_id);
- + return QueueId;
- }
- float Player::GetReputationPriceDiscount( Creature const* pCreature ) const
- diff --git a/src/game/Player.h b/src/game/Player.h
- index c3b6469..df0338e 100644
- --- a/src/game/Player.h
- +++ b/src/game/Player.h
- @@ -1958,7 +1958,7 @@ class MANGOS_DLL_SPEC Player : public Unit
- BattleGround* GetBattleGround() const;
- - BGQueueIdBasedOnLevel GetBattleGroundQueueIdFromLevel() const;
- + uint8 GetBGLevelQueueId() const;
- bool InBattleGroundQueue() const
- {
- @@ -2507,7 +2507,7 @@ class MANGOS_DLL_SPEC Player : public Unit
- uint32 m_teleport_options;
- bool mSemaphoreTeleport_Near;
- bool mSemaphoreTeleport_Far;
- -
- + bool bPosNotifyAfterAddToMap;
- uint32 m_DelayedOperations;
- bool m_bCanDelayTeleport;
- bool m_bHasDelayedTeleport;
- diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp
- index a71d259..dc8ebf0 100644
- --- a/src/game/Spell.cpp
- +++ b/src/game/Spell.cpp
- @@ -5826,6 +5826,16 @@ bool Spell::CheckTarget( Unit* target, uint32 eff )
- return true;
- }
- +bool Spell::IsDeletable()
- +{
- + if(m_caster && m_caster->GetOwner() && m_caster->GetOwner()->GetTypeId() == TYPEID_PLAYER)
- + {
- + Player *mo_caster = ((Player *)m_caster->GetOwner());
- + if(mo_caster->GetSession()->PlayerLoading() && mo_caster->GetSession()->IsUpdating())
- + return false;
- + }
- + return !m_referencedFromCurrentSpell && !m_executedCurrently;
- +}
- bool Spell::IsNeedSendToClient() const
- {
- diff --git a/src/game/Spell.h b/src/game/Spell.h
- index bda3a18..ed7fe95 100644
- --- a/src/game/Spell.h
- +++ b/src/game/Spell.h
- @@ -425,7 +425,7 @@ class Spell
- bool IsMeleeAttackResetSpell() const { return !m_IsTriggeredSpell && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
- bool IsRangedAttackResetSpell() const { return !m_IsTriggeredSpell && IsRangedSpell() && (m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_AUTOATTACK); }
- - bool IsDeletable() const { return !m_referencedFromCurrentSpell && !m_executedCurrently; }
- + bool IsDeletable();
- void SetReferencedFromCurrent(bool yes) { m_referencedFromCurrentSpell = yes; }
- void SetExecutedCurrently(bool yes) { m_executedCurrently = yes; }
- uint64 GetDelayStart() const { return m_delayStart; }
- diff --git a/src/game/World.cpp b/src/game/World.cpp
- index ca23473..5f265b5 100644
- --- a/src/game/World.cpp
- +++ b/src/game/World.cpp
- @@ -86,6 +86,7 @@ World::World()
- m_ShutdownMask = 0;
- m_ShutdownTimer = 0;
- m_gameTime=time(NULL);
- + m_WorldStarted = false;
- m_startTime=m_gameTime;
- m_maxActiveSessionCount = 0;
- m_maxQueuedSessionCount = 0;
- @@ -571,14 +572,13 @@ void World::LoadConfigSettings(bool reload)
- if(reload)
- sMapMgr.SetGridCleanUpDelay(m_configs[CONFIG_INTERVAL_GRIDCLEAN]);
- - m_configs[CONFIG_INTERVAL_MAPUPDATE] = sConfig.GetIntDefault("MapUpdateInterval", 100);
- - if(m_configs[CONFIG_INTERVAL_MAPUPDATE] < MIN_MAP_UPDATE_DELAY)
- - {
- - sLog.outError("MapUpdateInterval (%i) must be greater %u. Use this minimal value.",m_configs[CONFIG_INTERVAL_MAPUPDATE],MIN_MAP_UPDATE_DELAY);
- - m_configs[CONFIG_INTERVAL_MAPUPDATE] = MIN_MAP_UPDATE_DELAY;
- - }
- + m_configs[CONFIG_MAPUPDATER_BACKTRACE] = sConfig.GetIntDefault("MapUpdater.BackTrace", 1);
- + m_configs[CONFIG_MAPUPDATER_SHUT_ATCRASH] = sConfig.GetIntDefault("MapUpdater.ShutdownAtCrash", 20);
- + m_configs[CONFIG_MAPUPDATER_INTERVAL] = sConfig.GetIntDefault("MapUpdater.Interval", 100);
- + m_configs[CONFIG_MAPUPDATER_UNLOAD_DELAY] = sConfig.GetIntDefault("MapUpdater.UnloadDelay", 600000);
- +
- if(reload)
- - sMapMgr.SetMapUpdateInterval(m_configs[CONFIG_INTERVAL_MAPUPDATE]);
- + sMapMgr.SetMapUpdateInterval(m_configs[CONFIG_MAPUPDATER_INTERVAL]);
- m_configs[CONFIG_INTERVAL_CHANGEWEATHER] = sConfig.GetIntDefault("ChangeWeatherInterval", 10 * MINUTE * IN_MILISECONDS);
- @@ -1668,10 +1668,6 @@ void World::Update(uint32 diff)
- m_timers[WUPDATE_EVENTS].Reset();
- }
- - /// </ul>
- - ///- Move all creatures with "delayed move" and remove and delete all objects with "delayed remove"
- - sMapMgr.DoDelayedMovesAndRemoves();
- -
- // update the instance reset times
- sInstanceSaveMgr.Update();
- @@ -2051,11 +2047,23 @@ void World::UpdateSessions( uint32 diff )
- next = itr;
- ++next;
- ///- and remove not active sessions from the list
- - if(!itr->second->Update(diff)) // As interval = 0
- + if(!itr->second->IsUpdating())
- {
- - RemoveQueuedPlayer (itr->second);
- - delete itr->second;
- - m_sessions.erase(itr);
- + itr->second->SetUpdating(true);
- + if(SESSION_UPDATE_WORLD == itr->second->GetUpdateStatus())
- + {
- + ///- and remove not active sessions from the list
- + if(!itr->second->Update(0)) // As interval = 0
- + itr->second->SetUpdateStatus(SESSION_REMOVE_QUEUE);
- + }
- +
- + if(SESSION_REMOVE_QUEUE == itr->second->GetUpdateStatus())
- + {
- + RemoveQueuedPlayer (itr->second);
- + delete itr->second;
- + m_sessions.erase(itr);
- + }
- + itr->second->SetUpdating(false);
- }
- }
- }
- diff --git a/src/game/World.h b/src/game/World.h
- index 74c897a..5295d0e 100644
- --- a/src/game/World.h
- +++ b/src/game/World.h
- @@ -87,7 +87,10 @@ enum WorldConfigs
- CONFIG_GRID_UNLOAD,
- CONFIG_INTERVAL_SAVE,
- CONFIG_INTERVAL_GRIDCLEAN,
- - CONFIG_INTERVAL_MAPUPDATE,
- + CONFIG_MAPUPDATER_INTERVAL,
- + CONFIG_MAPUPDATER_BACKTRACE,
- + CONFIG_MAPUPDATER_SHUT_ATCRASH,
- + CONFIG_MAPUPDATER_UNLOAD_DELAY,
- CONFIG_INTERVAL_CHANGEWEATHER,
- CONFIG_PORT_WORLD,
- CONFIG_SOCKET_SELECTTIME,
- @@ -381,6 +384,7 @@ class World
- World();
- ~World();
- + bool m_WorldStarted;
- WorldSession* FindSession(uint32 id) const;
- void AddSession(WorldSession *s);
- bool RemoveSession(uint32 id);
- diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
- index 3ee5a7f..9832e94 100644
- --- a/src/game/WorldSession.cpp
- +++ b/src/game/WorldSession.cpp
- @@ -39,11 +39,11 @@
- /// WorldSession constructor
- WorldSession::WorldSession(uint32 id, WorldSocket *sock, AccountTypes sec, uint8 expansion, time_t mute_time, LocaleConstant locale) :
- -LookingForGroup_auto_join(false), LookingForGroup_auto_add(false), m_muteTime(mute_time),
- -_player(NULL), m_Socket(sock),_security(sec), _accountId(id), m_expansion(expansion),
- +LookingForGroup_auto_join(false), LookingForGroup_auto_add(false), m_muteTime(mute_time), eUpdateStatus(SESSION_UPDATE_WORLD),
- +_player(NULL), m_Socket(sock),_security(sec), _accountId(id), m_expansion(expansion), b_UpdatingSess(false), m_latency(0),
- m_sessionDbcLocale(sWorld.GetAvailableDbcLocale(locale)), m_sessionDbLocaleIndex(sObjectMgr.GetIndexForLocale(locale)),
- _logoutTime(0), m_inQueue(false), m_playerLoading(false), m_playerLogout(false), m_playerRecentlyLogout(false), m_playerSave(false),
- -m_latency(0), m_TutorialsChanged(false)
- +m_TutorialsChanged(false)
- {
- if (sock)
- {
- @@ -289,6 +289,8 @@ void WorldSession::LogoutPlayer(bool Save)
- m_playerLogout = true;
- m_playerSave = Save;
- +
- + eUpdateStatus = SESSION_UPDATE_WORLD;
- if (_player)
- {
- diff --git a/src/game/WorldSession.h b/src/game/WorldSession.h
- index d8e2eb0..279d02f 100644
- --- a/src/game/WorldSession.h
- +++ b/src/game/WorldSession.h
- @@ -103,6 +103,13 @@ enum PartyResult
- PARTY_RESULT_INVITE_RESTRICTED = 13
- };
- +enum SessionUpdateStatus
- +{
- + SESSION_UPDATE_MAP = 1,
- + SESSION_UPDATE_WORLD = 2,
- + SESSION_REMOVE_QUEUE = 3
- +};
- +
- /// Player session in the World
- class MANGOS_DLL_SPEC WorldSession
- {
- @@ -137,6 +144,11 @@ class MANGOS_DLL_SPEC WorldSession
- AccountTypes GetSecurity() const { return _security; }
- uint32 GetAccountId() const { return _accountId; }
- Player* GetPlayer() const { return _player; }
- +
- + bool IsUpdating(){ return b_UpdatingSess; }
- + void SetUpdating(bool bUpd){ b_UpdatingSess = bUpd; }
- + SessionUpdateStatus GetUpdateStatus(){ return eUpdateStatus; }
- + void SetUpdateStatus(SessionUpdateStatus Status) { eUpdateStatus = Status; }
- char const* GetPlayerName() const;
- void SetSecurity(AccountTypes security) { _security = security; }
- std::string const& GetRemoteAddress() { return m_Address; }
- @@ -741,7 +753,9 @@ class MANGOS_DLL_SPEC WorldSession
- WorldSocket *m_Socket;
- std::string m_Address;
- + SessionUpdateStatus eUpdateStatus;
- AccountTypes _security;
- + bool b_UpdatingSess;
- uint32 _accountId;
- uint8 m_expansion;
- diff --git a/src/mangosd/Master.cpp b/src/mangosd/Master.cpp
- index 1117a17..6157178 100644
- --- a/src/mangosd/Master.cpp
- +++ b/src/mangosd/Master.cpp
- @@ -27,6 +27,7 @@
- #include "Master.h"
- #include "WorldSocket.h"
- #include "WorldRunnable.h"
- +#include "MapManager.h"
- #include "World.h"
- #include "Log.h"
- #include "Timer.h"
- @@ -519,29 +520,68 @@ void Master::clearOnlineAccounts()
- }
- /// Handle termination signals
- -void Master::_OnSignal(int s)
- +void Master::_OnSignal(int Signal)
- {
- - switch (s)
- - {
- - case SIGINT:
- - World::StopNow(RESTART_EXIT_CODE);
- - break;
- - case SIGTERM:
- - #ifdef _WIN32
- - case SIGBREAK:
- - #endif
- - World::StopNow(SHUTDOWN_EXIT_CODE);
- - break;
- - }
- -
- - signal(s, _OnSignal);
- + ACE_thread_t ThreadId = ACE_Based::Thread::currentId();
- + sLog.outDebug("Signal Handler: Signal %.2u received from thread "I64FMT".\r\n",Signal,ThreadId);
- +
- + if(Signal == SIGINT)
- + World::StopNow(RESTART_EXIT_CODE);
- + else if(Signal == SIGTERM
- + #ifdef _WIN32
- + || Signal == SIGBREAK
- + #endif
- + )
- + {
- + if(Map *map = MapManager::Instance().FindMapByThread(ThreadId))
- + map->StopUpdater();
- + else World::StopNow(SHUTDOWN_EXIT_CODE);
- + }
- + else
- + {
- + MapManager::Instance().IncreaseCrashCount();
- + uint16 CrashCount = sWorld.getConfig(CONFIG_MAPUPDATER_SHUT_ATCRASH);
- + if(CrashCount && CrashCount <= MapManager::Instance().GetCrashCount())
- + {
- + sLog.outError("Signal Handler: Too many crash detected. Shutting down server...\r\n");
- + ObjectAccessor::Instance().SaveAllPlayers();
- + exit(Signal);
- + }
- + else if(Map *map = MapManager::Instance().FindMapByThread(ThreadId))
- + {
- + sLog.outError("MapUpdater: Map %u has crashed. Saving data and restarting the map...",map->GetId());
- +
- + if(sWorld.getConfig(CONFIG_MAPUPDATER_BACKTRACE))
- + {
- + ACE_Stack_Trace StackTrace;
- + sLog.outError("\r\n************ BackTrace ************\r\n************************"
- + "***********\r\n%s\r\n***********************************\r\n",StackTrace.c_str());
- + }
- +
- + map->Restart();
- + map->StopUpdater();
- +
- + }
- + else
- + {
- + ACE_Stack_Trace StackTrace;
- + sLog.outError("\r\n************ BackTrace ************\r\n************************"
- + "***********\r\n%s\r\n***********************************\r\n",StackTrace.c_str());
- + sLog.outDebug("Signal Handler: Crash detected from unknown thread "I64FMT".\r\n",ThreadId);
- + exit(Signal);
- + }
- + }
- + signal(Signal, _OnSignal);
- }
- /// Define hook '_OnSignal' for all termination signals
- void Master::_HookSignals()
- {
- - signal(SIGINT, _OnSignal);
- - signal(SIGTERM, _OnSignal);
- + signal(SIGINT, _OnSignal);
- + signal(SIGTERM, _OnSignal);
- + signal(SIGSEGV, _OnSignal);
- + signal(SIGABRT, _OnSignal);
- + signal(SIGFPE , _OnSignal);
- #ifdef _WIN32
- signal(SIGBREAK, _OnSignal);
- #endif
- @@ -550,8 +590,11 @@ void Master::_HookSignals()
- /// Unhook the signals before leaving
- void Master::_UnhookSignals()
- {
- - signal(SIGINT, 0);
- - signal(SIGTERM, 0);
- + signal(SIGINT, 0);
- + signal(SIGTERM, 0);
- + signal(SIGSEGV, 0);
- + signal(SIGABRT, 0);
- + signal(SIGFPE , 0);
- #ifdef _WIN32
- signal(SIGBREAK, 0);
- #endif
- diff --git a/src/mangosd/WorldRunnable.cpp b/src/mangosd/WorldRunnable.cpp
- index 28c4bf8..5782bf3 100644
- --- a/src/mangosd/WorldRunnable.cpp
- +++ b/src/mangosd/WorldRunnable.cpp
- @@ -49,6 +49,7 @@ void WorldRunnable::run()
- uint32 prevSleepTime = 0; // used for balanced full tick time length near WORLD_SLEEP_CONST
- + sWorld.m_WorldStarted = true;
- ///- While we have not World::m_stopEvent, update the world
- while (!World::IsStopped())
- {
- diff --git a/src/mangosd/mangosd.conf.dist.in b/src/mangosd/mangosd.conf.dist.in
- index d925a15..73e7afb 100644
- --- a/src/mangosd/mangosd.conf.dist.in
- +++ b/src/mangosd/mangosd.conf.dist.in
- @@ -1,4 +1,4 @@
- -#####################################
- +Ԫ�#####################################
- # MaNGOS Configuration file #
- #####################################
- ConfVersion=2008080101
- @@ -104,10 +104,6 @@ BindIP = "0.0.0.0"
- # Grid clean up delay (in milliseconds)
- # Default: 300000 (5 min)
- #
- -# MapUpdateInterval
- -# Map update interval (in milliseconds)
- -# Default: 100
- -#
- # ChangeWeatherInterval
- # Weather update interval (in milliseconds)
- # Default: 600000 (10 min)
- @@ -170,7 +166,6 @@ MaxOverspeedPings = 2
- GridUnload = 1
- SocketSelectTime = 10000
- GridCleanUpDelay = 300000
- -MapUpdateInterval = 100
- ChangeWeatherInterval = 600000
- PlayerSaveInterval = 900000
- vmap.enableLOS = 0
- @@ -184,6 +179,32 @@ MaxCoreStuckTime = 0
- AddonChannel = 1
- ###################################################################################################################
- +# MAP UPDATER
- +#
- +# Backtrace
- +# Set to 1 to output a backtrace
- +# Default: 1 ( ON )
- +#
- +# Interval
- +# MapUpdater interval between map updating ( and manager )
- +# Default: 100
- +#
- +# UnloadDelay
- +# Unloading map delay if there's no players (in ms)
- +# Default: 300000 ( 5 minutes )
- +#
- +# ShutdownAtCrash
- +# Set this to 0 if you dont want to get shutdown at x map crashes and else the crash number
- +# Default: 0 ( Don't shutdown )
- +#
- +###################################################################################################################
- +
- +MapUpdater.BackTrace = 1
- +MapUpdater.Interval = 100
- +MapUpdater.UnloadDelay = 600000
- +MapUpdater.ShutdownAtCrash = 20
- +
- +###################################################################################################################
- # SERVER LOGGING
- #
- # LogSQL
- diff --git a/src/shared/Database/Database.cpp b/src/shared/Database/Database.cpp
- index dff2ff1..60061c4 100644
- --- a/src/shared/Database/Database.cpp
- +++ b/src/shared/Database/Database.cpp
- @@ -112,6 +112,16 @@ void Database::SetResultQueue(SqlResultQueue * queue)
- }
- +void Database::UnSetResultQueue(SqlResultQueue * queue)
- +{
- + QueryQueues::iterator itr = m_queryQueues.find(ACE_Based::Thread::current());
- + if(itr != m_queryQueues.end())
- + {
- + delete itr->second;
- + m_queryQueues.erase(itr);
- + }
- +}
- +
- QueryResult* Database::PQuery(const char *format,...)
- {
- if(!format) return NULL;
- diff --git a/src/shared/Database/Database.h b/src/shared/Database/Database.h
- index 5935692..9b31a39 100644
- --- a/src/shared/Database/Database.h
- +++ b/src/shared/Database/Database.h
- @@ -59,36 +59,36 @@ class MANGOS_DLL_SPEC Database
- // Query / member
- template<class Class>
- - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
- + void AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql);
- template<class Class, typename ParamType1>
- - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
- + void AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
- template<class Class, typename ParamType1, typename ParamType2>
- - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
- + void AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
- template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- - bool AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
- + void AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
- // Query / static
- template<typename ParamType1>
- - bool AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
- + void AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql);
- template<typename ParamType1, typename ParamType2>
- - bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
- + void AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql);
- template<typename ParamType1, typename ParamType2, typename ParamType3>
- - bool AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
- + void AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql);
- // PQuery / member
- template<class Class>
- - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
- + void AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...) ATTR_PRINTF(4,5);
- template<class Class, typename ParamType1>
- - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
- + void AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(5,6);
- template<class Class, typename ParamType1, typename ParamType2>
- - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7);
- + void AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(6,7);
- template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- - bool AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8);
- + void AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(7,8);
- // PQuery / static
- template<typename ParamType1>
- - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5);
- + void AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...) ATTR_PRINTF(4,5);
- template<typename ParamType1, typename ParamType2>
- - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
- + void AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...) ATTR_PRINTF(5,6);
- template<typename ParamType1, typename ParamType2, typename ParamType3>
- - bool AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7);
- + void AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...) ATTR_PRINTF(6,7);
- template<class Class>
- // QueryHolder
- bool DelayQueryHolder(Class *object, void (Class::*method)(QueryResult*, SqlQueryHolder*), SqlQueryHolder *holder);
- @@ -128,6 +128,7 @@ class MANGOS_DLL_SPEC Database
- // sets the result queue of the current thread, be careful what thread you call this from
- void SetResultQueue(SqlResultQueue * queue);
- + void UnSetResultQueue(SqlResultQueue * queue);
- bool CheckRequiredField(char const* table_name, char const* required_name);
- private:
- diff --git a/src/shared/Database/DatabaseImpl.h b/src/shared/Database/DatabaseImpl.h
- index 3e0ea93..9c55eb3 100644
- --- a/src/shared/Database/DatabaseImpl.h
- +++ b/src/shared/Database/DatabaseImpl.h
- @@ -22,18 +22,18 @@
- /// Function body definitions for the template function members of the Database class
- #define ASYNC_QUERY_BODY(sql, queue_itr) \
- - if (!sql) return false; \
- + if (!sql) return; \
- \
- QueryQueues::iterator queue_itr; \
- \
- { \
- ACE_Based::Thread * queryThread = ACE_Based::Thread::current(); \
- queue_itr = m_queryQueues.find(queryThread); \
- - if (queue_itr == m_queryQueues.end()) return false; \
- + if (queue_itr == m_queryQueues.end()) return; \
- }
- #define ASYNC_PQUERY_BODY(format, szQuery) \
- - if(!format) return false; \
- + if(!format) return; \
- \
- char szQuery [MAX_QUERY_LEN]; \
- \
- @@ -47,7 +47,7 @@
- if(res==-1) \
- { \
- sLog.outError("SQL Query truncated (and not execute) for format: %s",format); \
- - return false; \
- + return; \
- } \
- }
- @@ -65,121 +65,121 @@
- // -- Query / member --
- template<class Class>
- -bool
- +void
- Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*), const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class>(object, method), itr->second));
- }
- template<class Class, typename ParamType1>
- -bool
- +void
- Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1>(object, method, (QueryResult*)NULL, param1), itr->second));
- }
- template<class Class, typename ParamType1, typename ParamType2>
- -bool
- +void
- Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2>(object, method, (QueryResult*)NULL, param1, param2), itr->second));
- }
- template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- -bool
- +void
- Database::AsyncQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::QueryCallback<Class, ParamType1, ParamType2, ParamType3>(object, method, (QueryResult*)NULL, param1, param2, param3), itr->second));
- }
- // -- Query / static --
- template<typename ParamType1>
- -bool
- +void
- Database::AsyncQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1>(method, (QueryResult*)NULL, param1), itr->second));
- }
- template<typename ParamType1, typename ParamType2>
- -bool
- +void
- Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2>(method, (QueryResult*)NULL, param1, param2), itr->second));
- }
- template<typename ParamType1, typename ParamType2, typename ParamType3>
- -bool
- +void
- Database::AsyncQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *sql)
- {
- ASYNC_QUERY_BODY(sql, itr)
- - return m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), itr->second));
- + m_threadBody->Delay(new SqlQuery(sql, new MaNGOS::SQueryCallback<ParamType1, ParamType2, ParamType3>(method, (QueryResult*)NULL, param1, param2, param3), itr->second));
- }
- // -- PQuery / member --
- template<class Class>
- -bool
- +void
- Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*), const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(object, method, szQuery);
- + AsyncQuery(object, method, szQuery);
- }
- template<class Class, typename ParamType1>
- -bool
- +void
- Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(object, method, param1, szQuery);
- + AsyncQuery(object, method, param1, szQuery);
- }
- template<class Class, typename ParamType1, typename ParamType2>
- -bool
- +void
- Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(object, method, param1, param2, szQuery);
- + AsyncQuery(object, method, param1, param2, szQuery);
- }
- template<class Class, typename ParamType1, typename ParamType2, typename ParamType3>
- -bool
- +void
- Database::AsyncPQuery(Class *object, void (Class::*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(object, method, param1, param2, param3, szQuery);
- + AsyncQuery(object, method, param1, param2, param3, szQuery);
- }
- // -- PQuery / static --
- template<typename ParamType1>
- -bool
- +void
- Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1), ParamType1 param1, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(method, param1, szQuery);
- + AsyncQuery(method, param1, szQuery);
- }
- template<typename ParamType1, typename ParamType2>
- -bool
- +void
- Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2), ParamType1 param1, ParamType2 param2, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(method, param1, param2, szQuery);
- + AsyncQuery(method, param1, param2, szQuery);
- }
- template<typename ParamType1, typename ParamType2, typename ParamType3>
- -bool
- +void
- Database::AsyncPQuery(void (*method)(QueryResult*, ParamType1, ParamType2, ParamType3), ParamType1 param1, ParamType2 param2, ParamType3 param3, const char *format,...)
- {
- ASYNC_PQUERY_BODY(format, szQuery)
- - return AsyncQuery(method, param1, param2, param3, szQuery);
- + AsyncQuery(method, param1, param2, param3, szQuery);
- }
- // -- QueryHolder --
- diff --git a/src/shared/Database/SqlDelayThread.cpp b/src/shared/Database/SqlDelayThread.cpp
- index 9ad6756..544f050 100644
- --- a/src/shared/Database/SqlDelayThread.cpp
- +++ b/src/shared/Database/SqlDelayThread.cpp
- @@ -36,8 +36,10 @@ void SqlDelayThread::run()
- // empty the queue before exiting
- ACE_Based::Thread::Sleep(10);
- SqlOperation* s;
- - while (m_sqlQueue.next(s))
- + while (!m_sqlQueue.empty())
- {
- + SqlQueue::iterator i = m_sqlQueue.begin();
- + SqlOperation* s = *i; m_sqlQueue.erase(i);
- s->Execute(m_dbEngine);
- delete s;
- }
- diff --git a/src/shared/Database/SqlDelayThread.h b/src/shared/Database/SqlDelayThread.h
- index 4e78e99..2cfd1f2 100644
- --- a/src/shared/Database/SqlDelayThread.h
- +++ b/src/shared/Database/SqlDelayThread.h
- @@ -29,7 +29,7 @@ class SqlOperation;
- class SqlDelayThread : public ACE_Based::Runnable
- {
- - typedef ACE_Based::LockedQueue<SqlOperation*, ACE_Thread_Mutex> SqlQueue;
- + typedef std::deque<SqlOperation*> SqlQueue;
- private:
- SqlQueue m_sqlQueue; ///< Queue of SQL statements
- @@ -41,7 +41,7 @@ class SqlDelayThread : public ACE_Based::Runnable
- SqlDelayThread(Database* db);
- ///< Put sql statement to delay queue
- - bool Delay(SqlOperation* sql) { m_sqlQueue.add(sql); return true; }
- + void Delay(SqlOperation* sql) { m_sqlQueue.push_back(sql); }
- virtual void Stop(); ///< Stop event
- virtual void run(); ///< Main Thread loop
- diff --git a/src/shared/Threading.cpp b/src/shared/Threading.cpp
- index 3938286..a5e1b5e 100644
- --- a/src/shared/Threading.cpp
- +++ b/src/shared/Threading.cpp
- @@ -152,6 +152,28 @@ bool Thread::wait()
- return (_res == 0);
- }
- +bool Thread::kill_self( )
- +{
- + #if defined (ACE_HAS_WTHREADS)
- + return TerminateThread(currentHandle(),SIGTERM);
- + #elif(ACE_HAS_PTHREADS)
- + pthread_exit( (void *) SIGTERM );
- + #else
- + return !ACE_Thread::kill(currentId(), SIGTERM);
- + #endif
- +}
- +
- +bool Thread::kill( int Signal )
- +{
- + #if defined (ACE_HAS_WTHREADS)
- + return TerminateThread(m_hThreadHandle,Signal);
- + #elif(ACE_HAS_PTHREADS)
- + pthread_kill(m_iThreadId, Signal);
- + #else
- + return !ACE_Thread::kill(m_iThreadId, Signal);
- + #endif
- +}
- +
- void Thread::destroy()
- {
- if (!m_iThreadId || !m_task)
- diff --git a/src/shared/Threading.h b/src/shared/Threading.h
- index 574b964..71df9be 100644
- --- a/src/shared/Threading.h
- +++ b/src/shared/Threading.h
- @@ -73,8 +73,9 @@ namespace ACE_Based
- explicit Thread(Runnable* instance);
- ~Thread();
- - bool start();
- bool wait();
- + bool start();
- + bool kill(int);
- void destroy();
- void suspend();
- @@ -82,9 +83,12 @@ namespace ACE_Based
- void setPriority(Priority type);
- + static bool kill_self();
- static void Sleep(unsigned long msecs);
- static ACE_thread_t currentId();
- static ACE_hthread_t currentHandle();
- + inline ACE_thread_t ThreadId(){ return m_iThreadId; }
- + inline ACE_hthread_t Handle( ){ return m_hThreadHandle; }
- static Thread * current();
- private:
- --
- 1.6.2.msysgit.0.186.gf7512
- [/quote]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement