mirror of
https://github.com/mangosfour/server.git
synced 2025-12-13 04:37:00 +00:00
[7414] Fixed premature finish timer messages for battleground (va_start was broken).
Fixed typo with BattleGroundPlayerMap. Optimized implementation for removing offline players from battleground. Fixed typo in BattleGroundMgr::DeleteAllBattleGrounds. Patch is tested and should work. TODO there is a bug if you disable premature finish timer, that can cause battlegrounds to be never ending! TODO rewrite BattleGround::RemovePlayer function - and fix bugs there! I might not have today enough time to fix those bugs. Signed-off-by: Triply <triply@getmangos.com>
This commit is contained in:
parent
722395be75
commit
ee5feab3eb
7 changed files with 57 additions and 38 deletions
|
|
@ -117,7 +117,7 @@ namespace MaNGOS
|
|||
template<class Do>
|
||||
void BattleGround::BroadcastWorker(Do& _do)
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
if(Player *plr = ObjectAccessor::FindPlayer(MAKE_NEW_GUID(itr->first, 0, HIGHGUID_PLAYER)))
|
||||
_do(plr);
|
||||
}
|
||||
|
|
@ -254,18 +254,16 @@ void BattleGround::Update(uint32 diff)
|
|||
}
|
||||
|
||||
// remove offline players from bg after 5 minutes
|
||||
if(GetPlayersSize())
|
||||
if( !m_OfflineQueue.empty() )
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
BattleGroundPlayerMap::iterator itr = m_Players.find(*(m_OfflineQueue.begin()));
|
||||
if( itr != m_Players.end() )
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
itr->second.LastOnlineTime += diff;
|
||||
|
||||
if(plr)
|
||||
itr->second.LastOnlineTime = 0; // update last online time
|
||||
else
|
||||
if(itr->second.LastOnlineTime >= MAX_OFFLINE_TIME)
|
||||
m_RemovedPlayers[itr->first] = 1; // add to remove list (BG)
|
||||
if( itr->second.OfflineRemoveTime <= sWorld.GetGameTime() )
|
||||
{
|
||||
m_RemovedPlayers[itr->first] = 1; // add to remove list (BG)
|
||||
m_OfflineQueue.pop_front(); // remove from offline queue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -447,7 +445,7 @@ void BattleGround::Update(uint32 diff)
|
|||
m_EndTime += diff;
|
||||
if(m_EndTime >= TIME_TO_AUTOREMOVE) // 2 minutes
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
m_RemovedPlayers[itr->first] = 1; // add to remove list (BG)
|
||||
}
|
||||
|
|
@ -468,7 +466,7 @@ void BattleGround::SetTeamStartLoc(uint32 TeamID, float X, float Y, float Z, flo
|
|||
|
||||
void BattleGround::SendPacketToAll(WorldPacket *packet)
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
if(plr)
|
||||
|
|
@ -480,7 +478,7 @@ void BattleGround::SendPacketToAll(WorldPacket *packet)
|
|||
|
||||
void BattleGround::SendPacketToTeam(uint32 TeamID, WorldPacket *packet, Player *sender, bool self)
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -512,7 +510,7 @@ void BattleGround::PlaySoundToTeam(uint32 SoundID, uint32 TeamID)
|
|||
{
|
||||
WorldPacket data;
|
||||
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -535,7 +533,7 @@ void BattleGround::PlaySoundToTeam(uint32 SoundID, uint32 TeamID)
|
|||
|
||||
void BattleGround::CastSpellOnTeam(uint32 SpellID, uint32 TeamID)
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -555,7 +553,7 @@ void BattleGround::CastSpellOnTeam(uint32 SpellID, uint32 TeamID)
|
|||
|
||||
void BattleGround::RewardHonorToTeam(uint32 Honor, uint32 TeamID)
|
||||
{
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -580,7 +578,7 @@ void BattleGround::RewardReputationToTeam(uint32 faction_id, uint32 Reputation,
|
|||
if(!factionEntry)
|
||||
return;
|
||||
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -685,7 +683,7 @@ void BattleGround::EndBattleGround(uint32 winner)
|
|||
}
|
||||
}
|
||||
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
if(!plr)
|
||||
|
|
@ -907,7 +905,7 @@ void BattleGround::RemovePlayerAtLeave(uint64 guid, bool Transport, bool SendPac
|
|||
uint32 team = GetPlayerTeam(guid);
|
||||
bool participant = false;
|
||||
// Remove from lists/maps
|
||||
std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.find(guid);
|
||||
BattleGroundPlayerMap::iterator itr = m_Players.find(guid);
|
||||
if(itr != m_Players.end())
|
||||
{
|
||||
UpdatePlayersCountByTeam(team, true); // -1 player
|
||||
|
|
@ -1084,7 +1082,7 @@ void BattleGround::AddPlayer(Player *plr)
|
|||
uint32 team = plr->GetBGTeam();
|
||||
|
||||
BattleGroundPlayer bp;
|
||||
bp.LastOnlineTime = 0;
|
||||
bp.OfflineRemoveTime = 0;
|
||||
bp.Team = team;
|
||||
|
||||
// Add to list/maps
|
||||
|
|
@ -1147,7 +1145,7 @@ void BattleGround::AddPlayer(Player *plr)
|
|||
}
|
||||
|
||||
// setup BG group membership
|
||||
PlayerRelogin(plr);
|
||||
PlayerAddedToBGCheckIfBGIsRunning(plr);
|
||||
AddOrSetPlayerToCorrectBgGroup(plr, guid, team);
|
||||
|
||||
// Log
|
||||
|
|
@ -1176,9 +1174,28 @@ void BattleGround::AddOrSetPlayerToCorrectBgGroup(Player *plr, uint64 plr_guid,
|
|||
}
|
||||
}
|
||||
|
||||
// This method should be called when player logs into running battleground
|
||||
void BattleGround::EventPlayerLoggedIn(Player* player, uint64 plr_guid)
|
||||
{
|
||||
// player is correct pointer
|
||||
for(std::deque<uint64>::iterator itr = m_OfflineQueue.begin(); itr != m_OfflineQueue.end(); ++itr)
|
||||
{
|
||||
if( *itr == plr_guid )
|
||||
{
|
||||
m_OfflineQueue.erase(itr);
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_Players[plr_guid].OfflineRemoveTime = 0;
|
||||
PlayerAddedToBGCheckIfBGIsRunning(player);
|
||||
}
|
||||
|
||||
// This method should be called when player logs out from running battleground
|
||||
void BattleGround::EventPlayerLoggedOut(Player* player)
|
||||
{
|
||||
// player is correct pointer, it is checked in WorldSession::LogoutPlayer()
|
||||
m_OfflineQueue.push_back(player->GetGUID());
|
||||
m_Players[player->GetGUID()].OfflineRemoveTime = sWorld.GetGameTime() + MAX_OFFLINE_TIME;
|
||||
if( GetStatus() == STATUS_IN_PROGRESS )
|
||||
{
|
||||
if( isBattleGround() )
|
||||
|
|
@ -1562,7 +1579,7 @@ void BattleGround::SendMessageToAll(int32 entry, ChatMsg type, Player const* sou
|
|||
void BattleGround::PSendMessageToAll(int32 entry, ChatMsg type, Player const* source, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, type);
|
||||
va_start(ap, source);
|
||||
|
||||
MaNGOS::BattleGroundChatBuilder bg_builder(type, entry, source, &ap);
|
||||
MaNGOS::LocalizedPacketDo<MaNGOS::BattleGroundChatBuilder> bg_do(bg_builder);
|
||||
|
|
@ -1640,7 +1657,7 @@ void BattleGround::HandleKillPlayer( Player *player, Player *killer )
|
|||
UpdatePlayerScore(killer, SCORE_HONORABLE_KILLS, 1);
|
||||
UpdatePlayerScore(killer, SCORE_KILLING_BLOWS, 1);
|
||||
|
||||
for(std::map<uint64, BattleGroundPlayer>::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
Player *plr = objmgr.GetPlayer(itr->first);
|
||||
|
||||
|
|
@ -1660,7 +1677,7 @@ void BattleGround::HandleKillPlayer( Player *player, Player *killer )
|
|||
// used in same faction arena matches mainly
|
||||
uint32 BattleGround::GetPlayerTeam(uint64 guid)
|
||||
{
|
||||
std::map<uint64, BattleGroundPlayer>::const_iterator itr = m_Players.find(guid);
|
||||
BattleGroundPlayerMap::const_iterator itr = m_Players.find(guid);
|
||||
if(itr!=m_Players.end())
|
||||
return itr->second.Team;
|
||||
return 0;
|
||||
|
|
@ -1668,13 +1685,13 @@ uint32 BattleGround::GetPlayerTeam(uint64 guid)
|
|||
|
||||
bool BattleGround::IsPlayerInBattleGround(uint64 guid)
|
||||
{
|
||||
std::map<uint64, BattleGroundPlayer>::const_iterator itr = m_Players.find(guid);
|
||||
if(itr!=m_Players.end())
|
||||
BattleGroundPlayerMap::const_iterator itr = m_Players.find(guid);
|
||||
if(itr != m_Players.end())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void BattleGround::PlayerRelogin(Player* plr)
|
||||
void BattleGround::PlayerAddedToBGCheckIfBGIsRunning(Player* plr)
|
||||
{
|
||||
if(GetStatus() != STATUS_WAIT_LEAVE)
|
||||
return;
|
||||
|
|
@ -1694,7 +1711,7 @@ void BattleGround::PlayerRelogin(Player* plr)
|
|||
uint32 BattleGround::GetAlivePlayersCountByTeam(uint32 Team) const
|
||||
{
|
||||
int count = 0;
|
||||
for(std::map<uint64, BattleGroundPlayer>::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
for(BattleGroundPlayerMap::const_iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
|
||||
{
|
||||
if(itr->second.Team == Team)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ enum BattleGroundTimeIntervals
|
|||
INVITATION_REMIND_TIME = 60000, // ms
|
||||
INVITE_ACCEPT_WAIT_TIME = 80000, // ms
|
||||
TIME_TO_AUTOREMOVE = 120000, // ms
|
||||
MAX_OFFLINE_TIME = 300000, // ms
|
||||
MAX_OFFLINE_TIME = 300, // secs
|
||||
RESPAWN_ONE_DAY = 86400, // secs
|
||||
RESPAWN_IMMEDIATELY = 0, // secs
|
||||
BUFF_RESPAWN_TIME = 180, // secs
|
||||
|
|
@ -125,7 +125,7 @@ enum BattleGroundStatus
|
|||
|
||||
struct BattleGroundPlayer
|
||||
{
|
||||
uint32 LastOnlineTime; // for tracking and removing offline players from queue after 5 minutes
|
||||
time_t OfflineRemoveTime; // for tracking and removing offline players from queue after 5 minutes
|
||||
uint32 Team; // Player's team
|
||||
};
|
||||
|
||||
|
|
@ -456,6 +456,7 @@ class BattleGround
|
|||
virtual void EventPlayerDroppedFlag(Player* /*player*/) {}
|
||||
virtual void EventPlayerClickedOnFlag(Player* /*player*/, GameObject* /*target_obj*/) {}
|
||||
virtual void EventPlayerCapturedFlag(Player* /*player*/) {}
|
||||
void EventPlayerLoggedIn(Player* player, uint64 plr_guid);
|
||||
void EventPlayerLoggedOut(Player* player);
|
||||
|
||||
/* Death related */
|
||||
|
|
@ -491,13 +492,13 @@ class BattleGround
|
|||
// since arenas can be AvA or Hvh, we have to get the "temporary" team of a player
|
||||
uint32 GetPlayerTeam(uint64 guid);
|
||||
bool IsPlayerInBattleGround(uint64 guid);
|
||||
void PlayerRelogin(Player* plr);
|
||||
|
||||
void SetDeleteThis() {m_SetDeleteThis = true;}
|
||||
|
||||
protected:
|
||||
//this method is called, when BG cannot spawn its own spirit guide, or something is wrong, It correctly ends BattleGround
|
||||
void EndNow();
|
||||
void PlayerAddedToBGCheckIfBGIsRunning(Player* plr);
|
||||
|
||||
/* Scorekeeping */
|
||||
// Player scores
|
||||
|
|
@ -542,6 +543,7 @@ class BattleGround
|
|||
|
||||
/* Player lists */
|
||||
std::vector<uint64> m_ResurrectQueue; // Player GUID
|
||||
std::deque<uint64> m_OfflineQueue; // Player GUID
|
||||
std::map<uint64, uint8> m_RemovedPlayers; // uint8 is remove type (0 - bgqueue, 1 - bg, 2 - resurrect queue)
|
||||
|
||||
/* Invited counters are useful for player invitation to BG - do not allow, if BG is started to one faction to have 2 more players than another faction */
|
||||
|
|
|
|||
|
|
@ -1077,10 +1077,10 @@ BattleGroundMgr::BattleGroundMgr() : m_AutoDistributionTimeChecker(0), m_ArenaTe
|
|||
|
||||
BattleGroundMgr::~BattleGroundMgr()
|
||||
{
|
||||
DeleteAlllBattleGrounds();
|
||||
DeleteAllBattleGrounds();
|
||||
}
|
||||
|
||||
void BattleGroundMgr::DeleteAlllBattleGrounds()
|
||||
void BattleGroundMgr::DeleteAllBattleGrounds()
|
||||
{
|
||||
for(uint32 i = BATTLEGROUND_TYPE_NONE; i < MAX_BATTLEGROUND_TYPE_ID; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class BattleGroundMgr
|
|||
void RemoveBattleGround(uint32 instanceID, BattleGroundTypeId bgTypeId) { m_BattleGrounds[bgTypeId].erase(instanceID); }
|
||||
|
||||
void CreateInitialBattleGrounds();
|
||||
void DeleteAlllBattleGrounds();
|
||||
void DeleteAllBattleGrounds();
|
||||
|
||||
void SendToBattleGround(Player *pl, uint32 InstanceID, BattleGroundTypeId bgTypeId);
|
||||
|
||||
|
|
|
|||
|
|
@ -14299,7 +14299,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
|
|||
SetBGTeam(bgteam);
|
||||
|
||||
//join player to battleground group
|
||||
currentBg->PlayerRelogin(this);
|
||||
currentBg->EventPlayerLoggedIn(this, GetGUID());
|
||||
currentBg->AddOrSetPlayerToCorrectBgGroup(this, GetGUID(), bgteam);
|
||||
|
||||
SetInviteForBattleGroundQueueType(bgQueueTypeId,currentBg->GetInstanceID());
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ void WorldRunnable::run()
|
|||
sWorld.UpdateSessions( 1 ); // real players unload required UpdateSessions call
|
||||
|
||||
// unload battleground templates before different singletons destroyed
|
||||
sBattleGroundMgr.DeleteAlllBattleGrounds();
|
||||
sBattleGroundMgr.DeleteAllBattleGrounds();
|
||||
|
||||
sWorldSocketMgr->StopNetwork();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#ifndef __REVISION_NR_H__
|
||||
#define __REVISION_NR_H__
|
||||
#define REVISION_NR "7413"
|
||||
#define REVISION_NR "7414"
|
||||
#endif // __REVISION_NR_H__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue