aboutsummaryrefslogtreecommitdiff
path: root/src/game/BattleGroundHandler.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/BattleGroundHandler.cpp')
-rw-r--r--src/game/BattleGroundHandler.cpp683
1 files changed, 507 insertions, 176 deletions
diff --git a/src/game/BattleGroundHandler.cpp b/src/game/BattleGroundHandler.cpp
index 85de6855563..486f828fbda 100644
--- a/src/game/BattleGroundHandler.cpp
+++ b/src/game/BattleGroundHandler.cpp
@@ -26,9 +26,12 @@
#include "MapManager.h"
#include "ObjectAccessor.h"
#include "Object.h"
+#include "Chat.h"
+#include "Language.h"
#include "BattleGroundMgr.h"
#include "BattleGroundWS.h"
#include "BattleGround.h"
+#include "ArenaTeam.h"
void WorldSession::HandleBattleGroundHelloOpcode( WorldPacket & recv_data )
{
@@ -75,16 +78,23 @@ void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data )
uint32 bgTypeId;
uint32 instanceId;
uint8 joinAsGroup;
+ Group * grp;
recv_data >> guid; // battlemaster guid
recv_data >> bgTypeId; // battleground type id (DBC id)
recv_data >> instanceId; // instance id, 0 if First Available selected
recv_data >> joinAsGroup; // join as group
- sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from: " I64FMT " for BG (Type: %u)", guid, bgTypeId);
-
- if(bgTypeId >= MAX_BATTLEGROUND_TYPES) // cheating?
+ if(bgTypeId >= MAX_BATTLEGROUND_TYPES)
+ {
+ sLog.outError("Battleground: invalid bgtype received. possible cheater? player guid %u",_player->GetGUIDLow());
return;
+ }
+
+ sLog.outDebug( "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from: " I64FMT, guid);
+
+ // can do this, since it's battleground, not arena
+ uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, 0);
// ignore if we already in BG or BG queue
if(_player->InBattleGround())
@@ -97,74 +107,150 @@ void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data )
if(!unit->isBattleMaster()) // it's not battlemaster
return;
- // check Deserter debuff
- if( !_player->CanJoinToBattleground() )
+ // get bg instance or bg template if instance not found
+ BattleGround * bg = 0;
+ if(instanceId)
+ BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId);
+
+ if(!bg && !(bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId)))
{
- WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4);
- data << (uint32) 0xFFFFFFFE;
- _player->GetSession()->SendPacket(&data);
+ sLog.outError("Battleground: no available bg / template found");
return;
}
- // check existence
- BattleGround *bg = sBattleGroundMgr.GetBattleGround(bgTypeId);
- if(!bg)
- return;
-
- if(joinAsGroup && _player->GetGroup())
+ // check queueing conditions
+ if(!joinAsGroup)
{
- Group *grp = _player->GetGroup();
- for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
+ // check Deserter debuff
+ if( !_player->CanJoinToBattleground() )
{
- Player *member = itr->getSource();
- if(!member) continue;
-
- if( !member->CanJoinToBattleground() )
+ WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4);
+ data << (uint32) 0xFFFFFFFE;
+ _player->GetSession()->SendPacket(&data);
+ return;
+ }
+ // check if already in queue
+ if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES)
+ //player is already in this queue
+ return;
+ // check if has free queue slots
+ if(!_player->HasFreeBattleGroundQueueId())
+ return;
+ }
+ else
+ {
+ grp = _player->GetGroup();
+ // no group found, error
+ if(!grp)
+ return;
+ uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, 0, bg->GetMaxPlayersPerTeam(), false, 0);
+ switch(err)
+ {
+ // TODO: add error-based feedback to players in all cases
+ case BG_JOIN_ERR_GROUP_TOO_MANY:
{
- WorldPacket data(SMSG_GROUP_JOINED_BATTLEGROUND, 4);
- data << (uint32) 0xFFFFFFFE;
- _player->GetSession()->SendPacket(&data);
- continue;
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_TOO_LARGE), NULL);
+ SendPacket(&data);
}
- if (member->InBattleGroundQueueForBattleGroundType(bgTypeId))
- //player is already in this queue
- continue;
-
+ return;
+ break;
+ case BG_JOIN_ERR_OFFLINE_MEMBER:
+ {
WorldPacket data;
- // add to queue
- uint32 queueSlot = member->AddBattleGroundQueueId(bgTypeId);
- if (queueSlot == PLAYER_MAX_BATTLEGROUND_QUEUES)
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_MIXED_FACTION:
{
- // fill data packet
- //member->GetSession()->SendPacket(data);
- continue;
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_FACTION), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_MIXED_LEVELS:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_LEVELS), NULL);
+ SendPacket(&data);
}
+ return;
+ break;
+ case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_GROUP_DESERTER:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_DESERTER), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_ALL_QUEUES_USED:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ // all ok, can join
+ case BG_JOIN_ERR_OK:
+ break;
+ // these aren't possible outcomes in bgs
+ case BG_JOIN_ERR_GROUP_NOT_ENOUGH:
+ case BG_JOIN_ERR_MIXED_ARENATEAM:
+ return;
+ break;
+ // not the above? shouldn't happen, don't let join
+ default:
+ return;
+ break;
+ };
+ }
+
+ // if we're here, then the conditions to join a bg are met. We can proceed in joining.
+
+ // _player->GetGroup() was already checked, grp is already initialized
+ if(joinAsGroup /* && _player->GetGroup()*/)
+ {
+ sLog.outDebug("Battleground: the following players are joining as group:");
+ GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0);
+ for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
+ {
+ Player *member = itr->getSource();
+ if(!member) continue; // this should never happen
+
+ uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId); // add to queue
// store entry point coords (same as leader entry point)
member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
+ WorldPacket data;
// send status packet (in queue)
sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0);
member->GetSession()->SendPacket(&data);
sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId);
member->GetSession()->SendPacket(&data);
- sBattleGroundMgr.m_BattleGroundQueues[bgTypeId].AddPlayer(member, bgTypeId);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo);
+ sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName());
}
+ sLog.outDebug("Battleground: group end");
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel());
}
else
{
- if (_player->InBattleGroundQueueForBattleGroundType(bgTypeId))
- //player is already in this queue
- return;
- uint32 queueSlot = _player->AddBattleGroundQueueId(bgTypeId);
- if (queueSlot == PLAYER_MAX_BATTLEGROUND_QUEUES)
- {
- WorldPacket data;
- // fill data packet
- //SendPacket(data);
- return;
- }
-
+ // already checked if queueSlot is valid, now just get it
+ uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId);
// store entry point coords
_player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
@@ -172,7 +258,11 @@ void WorldSession::HandleBattleGroundJoinOpcode( WorldPacket & recv_data )
// send status packet (in queue)
sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0);
SendPacket(&data);
- sBattleGroundMgr.m_BattleGroundQueues[bgTypeId].AddPlayer(_player, bgTypeId);
+
+ GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, 0, false, 0);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel());
+ sLog.outDebug("Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,_player->GetGUIDLow(), _player->GetName());
}
}
@@ -246,12 +336,11 @@ void WorldSession::HandleBattleGroundListOpcode( WorldPacket &recv_data )
uint32 bgTypeId;
recv_data >> bgTypeId; // id from DBC
- if(bgTypeId >= MAX_BATTLEGROUND_TYPES) // cheating?
- return;
-
- // can't be received if player not in BG queue
- if(!_player->InBattleGroundQueueForBattleGroundType(bgTypeId))
+ if(bgTypeId >= MAX_BATTLEGROUND_TYPES)
+ {
+ sLog.outError("Battleground: invalid bgtype received.");
return;
+ }
BattlemasterListEntry const* bl = sBattlemasterListStore.LookupEntry(bgTypeId);
@@ -269,80 +358,186 @@ void WorldSession::HandleBattleGroundPlayerPortOpcode( WorldPacket &recv_data )
sLog.outDebug( "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message");
- uint8 unk1;
+ uint8 type; // arenatype if arena
uint8 unk2; // unk, can be 0x0 (may be if was invited?) and 0x1
+ uint32 instanceId;
uint32 bgTypeId; // type id from dbc
uint16 unk; // 0x1F90 constant?
uint8 action; // enter battle 0x1, leave queue 0x0
- recv_data >> unk1 >> unk2 >> bgTypeId >> unk >> action;
+ recv_data >> type >> unk2 >> bgTypeId >> unk >> action;
- if(bgTypeId >= MAX_BATTLEGROUND_TYPES) // cheating?
- return;
+ if(bgTypeId >= MAX_BATTLEGROUND_TYPES)
+ {
+ sLog.outError("Battleground: invalid bgtype received.");
+ // update battleground slots for the player to fix his UI and sent data.
+ // this is a HACK, I don't know why the client starts sending invalid packets in the first place.
+ // it usually happens with extremely high latency (if debugging / stepping in the code for example)
+ if(_player->InBattleGroundQueue())
+ {
+ // update all queues, send invitation info if player is invited, queue info if queued
+ for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
+ {
+ uint32 queue_id = _player->GetBattleGroundQueueId(i);
+ if(!queue_id)
+ continue;
+ BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID());
+ // if the player is not in queue, contine
+ if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end())
+ continue;
- if(!_player->InBattleGroundQueueForBattleGroundType(bgTypeId))
- return;
+ // no group information, this should never happen
+ if(!itrPlayerStatus->second.GroupInfo)
+ continue;
- BattleGround *bg = sBattleGroundMgr.GetBattleGround(bgTypeId);
- if(!bg)
- return;
+ BattleGround * bg = NULL;
- uint32 queueSlot = 0;
- WorldPacket data;
- switch(action)
- {
- case 1: // port to battleground
- // cheating?
- if(!_player->IsInvitedForBattleGroundType(bgTypeId))
- return;
+ // get possibly needed data from groupinfo
+ bgTypeId = itrPlayerStatus->second.GroupInfo->BgTypeId;
+ uint8 arenatype = itrPlayerStatus->second.GroupInfo->ArenaType;
+ uint8 israted = itrPlayerStatus->second.GroupInfo->IsRated;
+ uint8 status = 0;
- // check if player is not deserter
- if( !_player->CanJoinToBattleground() )
- {
- WorldPacket data2;
- data2.Initialize(SMSG_GROUP_JOINED_BATTLEGROUND, 4);
- data2 << (uint32) 0xFFFFFFFE;
- SendPacket(&data2);
- return;
- }
+
+ if(!itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID)
+ {
+ // not invited to bg, get template
+ bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId);
+ status = STATUS_WAIT_QUEUE;
+ }
+ else
+ {
+ // get the bg we're invited to
+ BattleGround * bg = sBattleGroundMgr.GetBattleGround(itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID);
+ status = STATUS_WAIT_JOIN;
+ }
- // if the player is dead, resurrect him before teleport
- if(!_player->isAlive())
- {
- _player->ResurrectPlayer(1.0f,false);
- _player->SpawnCorpseBones();
+ // if bg not found, then continue
+ if(!bg)
+ continue;
+
+ // don't invite if already in the instance
+ if(_player->InBattleGround() && _player->GetBattleGround() && _player->GetBattleGround()->GetInstanceID() == bg->GetInstanceID())
+ continue;
+
+ // re - invite player with proper data
+ WorldPacket data;
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, itrPlayerStatus->second.GroupInfo->Team?itrPlayerStatus->second.GroupInfo->Team:_player->GetTeam(), i, status, INVITE_ACCEPT_WAIT_TIME, 0, arenatype, israted);
+ SendPacket(&data);
}
+ }
+ return;
+ }
- // leave current group
- _player->RemoveFromGroup();
+ uint32 bgQueueTypeId = 0;
+ // get the bg what we were invited to
+ BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus;
+ bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId,type);
+ itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID());
- // packet to player about BG status
- queueSlot = _player->GetBattleGroundQueueIndex(bgTypeId);
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime());
- _player->GetSession()->SendPacket(&data);
+ if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end())
+ {
+ sLog.outError("Battleground: itrplayerstatus not found.");
+ return;
+ }
+ instanceId = itrPlayerStatus->second.GroupInfo->IsInvitedToBGInstanceGUID;
- // remove battleground queue status from BGmgr
- sBattleGroundMgr.m_BattleGroundQueues[bgTypeId].RemovePlayer(_player->GetGUID(), false);
+ // if action == 1, then instanceId is _required_
+ if(!instanceId && action == 1)
+ {
+ sLog.outError("Battleground: instance not found.");
+ return;
+ }
- // this is still needed here if battleground "jumping" shouldn't add deserter debuff
- // also this required to prevent stuck at old battleground after SetBattleGroundId set to new
- if (BattleGround *currentBg = _player->GetBattleGround())
- currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true);
+ BattleGround *bg = sBattleGroundMgr.GetBattleGround(instanceId);
- _player->SetBattleGroundId(bg->GetTypeID());
- sBattleGroundMgr.SendToBattleGround(_player, bgTypeId);
- bg->AddPlayer(_player);
- break;
- case 0: // leave queue
- queueSlot = _player->GetBattleGroundQueueIndex(bgTypeId);
- _player->RemoveBattleGroundQueueId(bgTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_NONE, 0, 0);
- sBattleGroundMgr.m_BattleGroundQueues[bgTypeId].RemovePlayer(_player->GetGUID(), true);
- SendPacket(&data);
- break;
- default:
- sLog.outError("Battleground port: unknown action %u", action);
- break;
+ // bg template might and must be used in case of leaving queue, when instance is not created yet
+ if(!bg && action == 0)
+ bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId);
+
+ if(!bg)
+ {
+ sLog.outError("Battleground: bg not found.");
+ return;
+ }
+
+ bgTypeId = bg->GetTypeID();
+
+ if(_player->InBattleGroundQueue())
+ {
+ uint32 queueSlot = 0;
+ uint32 team = 0;
+ uint32 arenatype = 0;
+ uint32 israted = 0;
+ uint32 rating = 0;
+ // get the team info from the queue
+ BattleGroundQueue::QueuedPlayersMap::iterator pitr = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID());
+ if(pitr !=sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end()
+ && pitr->second.GroupInfo )
+ {
+ team = pitr->second.GroupInfo->Team;
+ arenatype = pitr->second.GroupInfo->ArenaType;
+ israted = pitr->second.GroupInfo->IsRated;
+ rating = pitr->second.GroupInfo->ArenaTeamRating;
+ }
+ else
+ {
+ sLog.outError("Battleground: Invalid player queue info!");
+ return;
+ }
+ WorldPacket data;
+ switch(action)
+ {
+ case 1: // port to battleground
+ if(!_player->IsInvitedForBattleGroundQueueType(bgQueueTypeId))
+ return; // cheating?
+ // resurrect the player
+ if(!_player->isAlive())
+ {
+ _player->ResurrectPlayer(1.0f,false);
+ _player->SpawnCorpseBones();
+ }
+ // stop taxi flight at port
+ if(_player->isInFlight())
+ {
+ _player->GetMotionMaster()->MovementExpired();
+ _player->m_taxi.ClearTaxiDestinations();
+ }
+ _player->RemoveFromGroup();
+ queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId);
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime());
+ _player->GetSession()->SendPacket(&data);
+ // remove battleground queue status from BGmgr
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), false);
+ // this is still needed here if battleground "jumping" shouldn't add deserter debuff
+ // also this required to prevent stuck at old battleground after SetBattleGroundId set to new
+ if( BattleGround *currentBg = _player->GetBattleGround() )
+ currentBg->RemovePlayerAtLeave(_player->GetGUID(), false, true);
+
+ // set the destination instance id
+ _player->SetBattleGroundId(bg->GetInstanceID());
+ // set the destination team
+ _player->SetBGTeam(team);
+ // bg->HandleBeforeTeleportToBattleGround(_player);
+ sBattleGroundMgr.SendToBattleGround(_player, instanceId);
+ // add only in HandleMoveWorldPortAck()
+ // bg->AddPlayer(_player,team);
+ sLog.outDebug("Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetInstanceID(),bg->GetTypeID(),bgQueueTypeId);
+ break;
+ case 0: // leave queue
+ queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId);
+ _player->RemoveBattleGroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_NONE, 0, 0);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].RemovePlayer(_player->GetGUID(), true);
+ // player left queue, we should update it, maybe now his group fits in
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId,_player->GetBattleGroundQueueIdFromLevel(),arenatype,israted,rating);
+ SendPacket(&data);
+ sLog.outDebug("Battleground: player %s (%u) left queue for bgtype %u, queue type %u.",_player->GetName(),_player->GetGUIDLow(),bg->GetTypeID(),bgQueueTypeId);
+ break;
+ default:
+ sLog.outError("Battleground port: unknown action %u", action);
+ break;
+ }
}
}
@@ -383,7 +578,8 @@ void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ )
BattleGround *bg = _player->GetBattleGround();
if(bg)
{
- uint32 queueSlot = _player->GetBattleGroundQueueIndex(bg->GetTypeID());
+ uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bg->GetTypeID(), bg->GetArenaType());
+ uint32 queueSlot = _player->GetBattleGroundQueueIndex(bgQueueTypeId);
if((bg->GetStatus() <= STATUS_IN_PROGRESS))
{
sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_IN_PROGRESS, 0, bg->GetStartTime());
@@ -391,15 +587,25 @@ void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ )
}
for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
{
- uint32 queue_id = _player->GetBattleGroundQueueId(i);
- if (i == queueSlot || !queue_id)
+ uint32 queue_id = _player->GetBattleGroundQueueId(i); // battlegroundqueueid stores the type id, not the instance id, so this is definitely wrong
+ uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id);
+ uint8 isRated = 0;
+ if (i == queueSlot || !queue_id) // we need to get the instance ids
+ continue;
+ BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID());
+ if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end())
continue;
- BattleGround *bg2 = sBattleGroundMgr.GetBattleGround(queue_id);
+ if(itrPlayerStatus->second.GroupInfo)
+ {
+ arenatype = itrPlayerStatus->second.GroupInfo->ArenaType;
+ isRated = itrPlayerStatus->second.GroupInfo->IsRated;
+ }
+ BattleGround *bg2 = sBattleGroundMgr.GetBattleGroundTemplate(sBattleGroundMgr.BGTemplateId(queue_id)); // try this
if(bg2)
{
//in this call is small bug, this call should be filled by player's waiting time in queue
//this call nulls all timers for client :
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg2, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0);
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg2, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0,arenatype,isRated);
SendPacket(&data);
}
}
@@ -410,16 +616,36 @@ void WorldSession::HandleBattlefieldStatusOpcode( WorldPacket & /*recv_data*/ )
// we should update all queues? .. i'm not sure if this code is correct
for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
{
- if(uint32 queue_id = _player->GetBattleGroundQueueId(i))
+ uint32 queue_id = _player->GetBattleGroundQueueId(i);
+ if(!queue_id)
+ continue;
+ uint32 bgTypeId = sBattleGroundMgr.BGTemplateId(queue_id);
+ uint8 arenatype = sBattleGroundMgr.BGArenaType(queue_id);
+ uint8 isRated = 0;
+ BattleGround *bg = sBattleGroundMgr.GetBattleGroundTemplate(bgTypeId);
+ BattleGroundQueue::QueuedPlayersMap::iterator itrPlayerStatus = sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].find(_player->GetGUID());
+ if(itrPlayerStatus == sBattleGroundMgr.m_BattleGroundQueues[queue_id].m_QueuedPlayers[_player->GetBattleGroundQueueIdFromLevel()].end())
+ continue;
+ if(itrPlayerStatus->second.GroupInfo)
{
- if(BattleGround *bg = sBattleGroundMgr.GetBattleGround(queue_id))
- {
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0);
- SendPacket(&data);
- }
+ arenatype = itrPlayerStatus->second.GroupInfo->ArenaType;
+ isRated = itrPlayerStatus->second.GroupInfo->IsRated;
+ }
+ if(bg && queue_id)
+ {
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), i, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated);
+ SendPacket(&data);
}
}
}
+/* else // not sure if it needed...
+ {
+ for (uint32 i = 0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; i++)
+ {
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, NULL, _player->GetTeam(),i , STATUS_NONE, 0, 0);
+ SendPacket(&data);
+ }
+ }*/
}
void WorldSession::HandleAreaSpiritHealerQueryOpcode( WorldPacket & recv_data )
@@ -479,16 +705,12 @@ void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data )
if(_player->InBattleGround())
return;
- for(int qId = 0; qId < PLAYER_MAX_BATTLEGROUND_QUEUES; ++qId)
- {
- if(_player->GetBattleGroundQueueId(qId) != 0)
- return;
- }
-
uint64 guid; // arena Battlemaster guid
uint8 type; // 2v2, 3v3 or 5v5
uint8 asGroup; // asGroup
uint8 isRated; // isRated
+ Group * grp;
+
recv_data >> guid >> type >> asGroup >> isRated;
Creature *unit = ObjectAccessor::GetCreature(*_player, guid);
@@ -499,6 +721,7 @@ void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data )
return;
uint8 arenatype = 0;
+ uint32 arenaRating = 0;
switch(type)
{
@@ -516,88 +739,196 @@ void WorldSession::HandleBattleGroundArenaJoin( WorldPacket & recv_data )
return;
}
- if(isRated && !_player->GetArenaTeamId(type)) // player not in arena team of that size
+ //check existance
+ BattleGround* bg = NULL;
+ if( !(bg = sBattleGroundMgr.GetBattleGroundTemplate(BATTLEGROUND_AA)) )
{
- _player->GetSession()->SendNotInArenaTeamPacket(arenatype);
+ sLog.outError("Battleground: template bg (all arenas) not found");
return;
}
- if(asGroup && !_player->GetGroup()) // player not in group
- return;
+ uint8 bgTypeId = bg->GetTypeID();
+ uint32 bgQueueTypeId = sBattleGroundMgr.BGQueueTypeId(bgTypeId, arenatype);
- // check existence
- BattleGround *bg = sBattleGroundMgr.GetBattleGround(BATTLEGROUND_AA);
- if(!bg)
- return;
+ // check queueing conditions
+ if(!asGroup)
+ {
+ // check if already in queue
+ if (_player->GetBattleGroundQueueIndex(bgQueueTypeId) < PLAYER_MAX_BATTLEGROUND_QUEUES)
+ //player is already in this queue
+ return;
+ // check if has free queue slots
+ if(!_player->HasFreeBattleGroundQueueId())
+ return;
+ }
+ else
+ {
+ grp = _player->GetGroup();
+ // no group found, error
+ if(!grp)
+ return;
+ uint32 err = grp->CanJoinBattleGroundQueue(bgTypeId, bgQueueTypeId, arenatype, arenatype, (bool)isRated, type);
+ switch(err)
+ {
+ // TODO: add error-based feedback to players in all cases
+ case BG_JOIN_ERR_GROUP_TOO_MANY:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_GROUP_TOO_LARGE), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_GROUP_NOT_ENOUGH:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_NOT_ENOUGH_PLAYERS), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_MIXED_ARENATEAM:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_ARENA_YOUR_TEAM_ONLY), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_OFFLINE_MEMBER:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_OFFLINE_MEMBER), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_MIXED_FACTION:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_FACTION), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_MIXED_LEVELS:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MIXED_LEVELS), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_GROUP_MEMBER_ALREADY_IN_QUEUE:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_ALREADY_IN_QUEUE), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_GROUP_DESERTER:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_DESERTER), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ case BG_JOIN_ERR_ALL_QUEUES_USED:
+ {
+ WorldPacket data;
+ ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_BG_SYSTEM_NEUTRAL, LANG_UNIVERSAL, NULL, 0, GetMangosString(LANG_BG_GROUP_MEMBER_NO_FREE_QUEUE_SLOTS), NULL);
+ SendPacket(&data);
+ }
+ return;
+ break;
+ // all ok, can join
+ case BG_JOIN_ERR_OK:
+ break;
+ // not the above? shouldn't happen, don't let join
+ default:
+ return;
+ break;
+ };
+ }
- bg->SetArenaType(arenatype);
- bg->SetRated(isRated);
+ uint32 ateamId = 0;
- if(asGroup && _player->GetGroup())
+ if(isRated)
{
- Group *grp = _player->GetGroup();
+ ateamId = _player->GetArenaTeamId(type);
+ // check real arenateam existence only here (if it was moved to group->CanJoin .. () then we would ahve to get it twice)
+ ArenaTeam * at = objmgr.GetArenaTeamById(ateamId);
+ if(!at)
+ {
+ _player->GetSession()->SendNotInArenaTeamPacket(arenatype);
+ return;
+ }
+ // get the team rating for queueing
+ arenaRating = at->GetRating();
+ // the arenateam id must match for everyone in the group
+ // get the personal ratings for queueing
+ uint32 avg_pers_rating = 0;
for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
{
Player *member = itr->getSource();
- if(!member) continue;
- /*if (!member->CanJoinToBattleground())
- //player has deserter aura .. do nothing
- */
+ // calc avg personal rating
+ avg_pers_rating += member->GetUInt32Value(PLAYER_FIELD_ARENA_TEAM_INFO_1_1 + (type*6) + 5);
+ }
- if (member->InBattleGroundQueueForBattleGroundType(BATTLEGROUND_AA))
- //player is already in this queue
- continue;
+ if( arenatype )
+ avg_pers_rating /= arenatype;
- // add to queue
- uint32 queueSlot = member->AddBattleGroundQueueId(BATTLEGROUND_AA);
- if (queueSlot == PLAYER_MAX_BATTLEGROUND_QUEUES)
- {
- WorldPacket data;
- //fill data
- //member->GetSession()->SendPacket(data);
- continue;
- }
+ // if avg personal rating is more than 150 points below the team’s rating, the team will be queued against an opponent matching or similar to the average personal rating
+ if(avg_pers_rating + 150 < arenaRating)
+ arenaRating = avg_pers_rating;
+ }
+
+ if(asGroup)
+ {
+ GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating, ateamId);
+ sLog.outDebug("Battleground: arena join as group start");
+ if(isRated)
+ sLog.outDebug("Battleground: arena team id %u, leader %s queued with rating %u for type %u",_player->GetArenaTeamId(type),_player->GetName(),arenaRating,arenatype);
+ for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
+ {
+ Player *member = itr->getSource();
+ if(!member) continue;
+
+ uint32 queueSlot = member->AddBattleGroundQueueId(bgQueueTypeId);// add to queue
// store entry point coords (same as leader entry point)
member->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
WorldPacket data;
// send status packet (in queue)
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0);
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, member->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated);
member->GetSession()->SendPacket(&data);
- sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, BATTLEGROUND_AA);
+ sBattleGroundMgr.BuildGroupJoinedBattlegroundPacket(&data, bgTypeId);
member->GetSession()->SendPacket(&data);
- sBattleGroundMgr.m_BattleGroundQueues[BATTLEGROUND_AA].AddPlayer(member, BATTLEGROUND_AA);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(member, ginfo);
+ sLog.outDebug("Battleground: player joined queue for arena as group bg queue type %u bg type %u: GUID %u, NAME %s",bgQueueTypeId,bgTypeId,member->GetGUIDLow(), member->GetName());
}
+ sLog.outDebug("Battleground: arena join as group end");
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating);
}
else
{
- /*if (!member->CanJoinToBattleground())
- //player has deserter aura .. do nothing
- */
-
- if (_player->InBattleGroundQueueForBattleGroundType(BATTLEGROUND_AA))
- //player is already in this queue
- return;
-
- uint32 queueSlot = _player->AddBattleGroundQueueId(BATTLEGROUND_AA);
- if (queueSlot == PLAYER_MAX_BATTLEGROUND_QUEUES)
- {
- WorldPacket data;
- //fill data (player is in 3 queues already)
- //SendPacket(data);
- return;
- }
+ uint32 queueSlot = _player->AddBattleGroundQueueId(bgQueueTypeId);
// store entry point coords
_player->SetBattleGroundEntryPoint(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
WorldPacket data;
// send status packet (in queue)
- sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0);
+ sBattleGroundMgr.BuildBattleGroundStatusPacket(&data, bg, _player->GetTeam(), queueSlot, STATUS_WAIT_QUEUE, 0, 0, arenatype, isRated);
SendPacket(&data);
- sBattleGroundMgr.m_BattleGroundQueues[BATTLEGROUND_AA].AddPlayer(_player, BATTLEGROUND_AA);
+ GroupQueueInfo * ginfo = sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddGroup(_player, bgTypeId, arenatype, isRated, arenaRating);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].AddPlayer(_player, ginfo);
+ sBattleGroundMgr.m_BattleGroundQueues[bgQueueTypeId].Update(bgTypeId, _player->GetBattleGroundQueueIdFromLevel(), arenatype, isRated, arenaRating);
+ 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());
}
}