2010-10-07 15:35:36 +02:00
/*
2012-01-01 00:32:13 +01:00
* Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
2010-10-07 15:35:36 +02:00
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
2008-10-11 14:16:25 -05:00
*/
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
#include "Common.h"
2009-06-04 21:41:07 +02:00
#include "ObjectAccessor.h"
2008-10-11 14:16:25 -05:00
#include "ObjectMgr.h"
2011-05-03 15:01:10 +02:00
#include "ArenaTeamMgr.h"
2009-06-04 21:41:07 +02:00
#include "WorldPacket.h"
2008-10-11 14:16:25 -05:00
#include "WorldSession.h"
2009-10-17 15:51:44 -07:00
2009-06-04 21:41:07 +02:00
#include "ArenaTeam.h"
2010-08-08 04:37:24 +02:00
#include "BattlegroundMgr.h"
#include "Battleground.h"
2009-06-04 21:41:07 +02:00
#include "Chat.h"
2008-12-19 16:05:13 -06:00
#include "Language.h"
2009-06-04 21:41:07 +02:00
#include "Log.h"
#include "Player.h"
#include "Object.h"
#include "Opcodes.h"
2010-07-21 12:14:23 +02:00
#include "DisableMgr.h"
2010-11-29 07:50:31 +01:00
#include "Group.h"
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattlemasterHelloOpcode ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
uint64 guid ;
recv_data >> guid ;
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEMASTER_HELLO Message from (GUID: %u TypeId:%u)" , GUID_LOPART ( guid ), GuidHigh2TypeId ( GUID_HIPART ( guid )));
2009-10-17 15:51:44 -07:00
2011-06-12 01:47:45 +02:00
Creature * unit = GetPlayer () -> GetMap () -> GetCreature ( guid );
2009-04-08 16:33:46 -05:00
if ( ! unit )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! unit -> isBattleMaster ()) // it's not battlemaster
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// Stop the npc if moving
unit -> StopMoving ();
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
BattlegroundTypeId bgTypeId = sBattlegroundMgr -> GetBattleMasterBG ( unit -> GetEntry ());
2009-10-17 15:51:44 -07:00
2009-04-08 16:33:46 -05:00
if ( ! _player -> GetBGAccessByLevel ( bgTypeId ))
2008-10-11 14:16:25 -05:00
{
// temp, must be gossip message...
SendNotification ( LANG_YOUR_BG_LEVEL_REQ_ERROR );
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
SendBattlegGroundList ( guid , bgTypeId );
}
2009-10-17 15:51:44 -07:00
2010-08-08 04:37:24 +02:00
void WorldSession :: SendBattlegGroundList ( uint64 guid , BattlegroundTypeId bgTypeId )
2008-10-11 14:16:25 -05:00
{
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundListPacket ( & data , guid , _player , bgTypeId , 0 );
2010-04-07 22:59:46 +02:00
SendPacket ( & data );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattlemasterJoinOpcode ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
uint64 guid ;
2009-02-09 22:08:06 -06:00
uint32 bgTypeId_ ;
2008-10-11 14:16:25 -05:00
uint32 instanceId ;
uint8 joinAsGroup ;
2009-02-27 12:13:59 -06:00
bool isPremade = false ;
2011-09-15 14:08:17 +02:00
Group * grp = NULL ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
recv_data >> guid ; // battlemaster guid
2009-02-09 22:08:06 -06:00
recv_data >> bgTypeId_ ; // battleground type id (DBC id)
2008-10-11 14:16:25 -05:00
recv_data >> instanceId ; // instance id, 0 if First Available selected
recv_data >> joinAsGroup ; // join as group
2009-10-17 15:51:44 -07:00
2009-04-08 16:33:46 -05:00
if ( ! sBattlemasterListStore . LookupEntry ( bgTypeId_ ))
2008-10-11 14:16:25 -05:00
{
2011-04-29 20:47:02 +02:00
sLog -> outError ( "Battleground: invalid bgtype (%u) received. possible cheater? player guid %u" , bgTypeId_ , _player -> GetGUIDLow ());
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-09-09 14:27:23 +02:00
if ( DisableMgr :: IsDisabledFor ( DISABLE_TYPE_BATTLEGROUND , bgTypeId_ , NULL ))
2010-07-21 12:14:23 +02:00
{
ChatHandler ( this ). PSendSysMessage ( LANG_BG_DISABLED );
return ;
}
2010-08-08 04:37:24 +02:00
BattlegroundTypeId bgTypeId = BattlegroundTypeId ( bgTypeId_ );
2009-10-17 15:51:44 -07:00
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from (GUID: %u TypeId:%u)" , GUID_LOPART ( guid ), GuidHigh2TypeId ( GUID_HIPART ( guid )));
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// can do this, since it's battleground, not arena
2010-08-08 04:37:24 +02:00
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr :: BGQueueTypeId ( bgTypeId , 0 );
BattlegroundQueueTypeId bgQueueTypeIdRandom = BattlegroundMgr :: BGQueueTypeId ( BATTLEGROUND_RB , 0 );
2009-10-17 15:51:44 -07:00
2008-12-19 16:05:13 -06:00
// ignore if player is already in BG
2010-08-08 04:37:24 +02:00
if ( _player -> InBattleground ())
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// get bg instance or bg template if instance not found
2011-09-15 14:08:17 +02:00
Battleground * bg = NULL ;
2009-04-08 16:33:46 -05:00
if ( instanceId )
2010-12-22 21:25:23 +01:00
bg = sBattlegroundMgr -> GetBattlegroundThroughClientInstance ( instanceId , bgTypeId );
2009-10-17 15:51:44 -07:00
2010-04-19 17:03:10 +02:00
if ( ! bg )
2010-12-22 21:25:23 +01:00
bg = sBattlegroundMgr -> GetBattlegroundTemplate ( bgTypeId );
2010-04-19 17:03:10 +02:00
if ( ! bg )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-02-15 15:31:27 +01:00
// expected bracket entry
2011-04-29 20:47:02 +02:00
PvPDifficultyEntry const * bracketEntry = GetBattlegroundBracketByLevel ( bg -> GetMapId (), _player -> getLevel ());
2010-02-15 15:31:27 +01:00
if ( ! bracketEntry )
return ;
2010-04-11 11:22:29 +04:00
GroupJoinBattlegroundResult err ;
// check queue conditions
2009-04-08 16:33:46 -05:00
if ( ! joinAsGroup )
2008-10-11 14:16:25 -05:00
{
2010-11-24 15:37:22 +01:00
if ( GetPlayer () -> isUsingLfg ())
{
// player is using dungeon finder or raid finder
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , ERR_LFG_CANT_USE_BATTLEGROUND );
2010-11-24 15:37:22 +01:00
GetPlayer () -> GetSession () -> SendPacket ( & data );
return ;
}
2008-10-11 14:16:25 -05:00
// check Deserter debuff
2009-04-08 16:33:46 -05:00
if ( ! _player -> CanJoinToBattleground ())
2008-10-11 14:16:25 -05:00
{
2010-04-11 11:22:29 +04:00
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS );
2008-10-11 14:16:25 -05:00
_player -> GetSession () -> SendPacket ( & data );
return ;
}
2010-05-26 11:34:37 +02:00
2010-08-08 04:37:24 +02:00
if ( _player -> GetBattlegroundQueueIndex ( bgQueueTypeIdRandom ) < PLAYER_MAX_BATTLEGROUND_QUEUES )
2010-05-26 11:34:37 +02:00
{
//player is already in random queue
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , ERR_IN_RANDOM_BG );
2010-05-26 11:34:37 +02:00
_player -> GetSession () -> SendPacket ( & data );
return ;
}
2010-08-08 19:45:53 +02:00
2010-08-08 04:37:24 +02:00
if ( _player -> InBattlegroundQueue () && bgTypeId == BATTLEGROUND_RB )
2010-05-26 11:34:37 +02:00
{
//player is already in queue, can't start random queue
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , ERR_IN_NON_RANDOM_BG );
2010-05-26 11:34:37 +02:00
_player -> GetSession () -> SendPacket ( & data );
return ;
}
2008-10-11 14:16:25 -05:00
// check if already in queue
2010-08-08 04:37:24 +02:00
if ( _player -> GetBattlegroundQueueIndex ( bgQueueTypeId ) < PLAYER_MAX_BATTLEGROUND_QUEUES )
2008-10-11 14:16:25 -05:00
//player is already in this queue
return ;
2010-05-26 11:34:37 +02:00
2008-10-11 14:16:25 -05:00
// check if has free queue slots
2010-08-08 04:37:24 +02:00
if ( ! _player -> HasFreeBattlegroundQueueId ())
2010-05-26 11:34:37 +02:00
{
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , ERR_BATTLEGROUND_TOO_MANY_QUEUES );
2010-05-26 11:34:37 +02:00
_player -> GetSession () -> SendPacket ( & data );
2008-10-11 14:16:25 -05:00
return ;
2010-05-26 11:34:37 +02:00
}
2010-12-22 21:25:23 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> m_BattlegroundQueues [ bgQueueTypeId ];
2010-04-19 09:26:37 +02:00
2011-09-15 14:08:17 +02:00
GroupQueueInfo * ginfo = bgQueue . AddGroup ( _player , NULL , bgTypeId , bracketEntry , 0 , false , isPremade , 0 , 0 );
2010-04-19 09:26:37 +02:00
uint32 avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
// already checked if queueSlot is valid, now just get it
2010-08-08 04:37:24 +02:00
uint32 queueSlot = _player -> AddBattlegroundQueueId ( bgQueueTypeId );
2010-04-19 09:26:37 +02:00
WorldPacket data ;
// send status packet (in queue)
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_WAIT_QUEUE , avgTime , 0 , ginfo -> ArenaType );
2010-04-19 09:26:37 +02:00
SendPacket ( & data );
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s" , bgQueueTypeId , bgTypeId , _player -> GetGUIDLow (), _player -> GetName ());
2008-10-11 14:16:25 -05:00
}
else
{
grp = _player -> GetGroup ();
// no group found, error
2009-04-08 16:33:46 -05:00
if ( ! grp )
2008-10-11 14:16:25 -05:00
return ;
2010-04-11 11:22:29 +04:00
if ( grp -> GetLeaderGUID () != _player -> GetGUID ())
2008-10-11 14:16:25 -05:00
return ;
2010-08-08 04:37:24 +02:00
err = grp -> CanJoinBattlegroundQueue ( bg , bgQueueTypeId , 0 , bg -> GetMaxPlayersPerTeam (), false , 0 );
2010-04-11 11:22:29 +04:00
isPremade = ( grp -> GetMembersCount () >= bg -> GetMinPlayersPerTeam ());
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> m_BattlegroundQueues [ bgQueueTypeId ];
2011-09-15 14:08:17 +02:00
GroupQueueInfo * ginfo = NULL ;
2010-05-01 22:25:14 +02:00
uint32 avgTime = 0 ;
2010-04-11 11:22:29 +04:00
2010-04-24 17:48:52 +02:00
if ( err > 0 )
2010-04-11 11:22:29 +04:00
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: the following players are joining as group:" );
2010-08-27 18:18:26 +02:00
ginfo = bgQueue . AddGroup ( _player , grp , bgTypeId , bracketEntry , 0 , false , isPremade , 0 , 0 );
2010-04-11 20:20:38 +02:00
avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
}
2010-04-11 11:22:29 +04:00
2011-09-15 14:08:17 +02:00
for ( GroupReference * itr = grp -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2008-10-11 14:16:25 -05:00
{
2011-09-15 14:08:17 +02:00
Player * member = itr -> getSource ();
2010-04-07 19:14:10 +02:00
if ( ! member ) continue ; // this should never happen
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
2010-04-11 20:20:38 +02:00
2010-04-24 17:48:52 +02:00
if ( err <= 0 )
2010-04-11 20:20:38 +02:00
{
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , err );
2010-04-11 20:20:38 +02:00
member -> GetSession () -> SendPacket ( & data );
continue ;
2010-04-11 11:22:29 +04:00
}
2010-04-11 20:20:38 +02:00
// add to queue
2010-08-08 04:37:24 +02:00
uint32 queueSlot = member -> AddBattlegroundQueueId ( bgQueueTypeId );
2010-04-11 11:22:29 +04:00
// send status packet (in queue)
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_WAIT_QUEUE , avgTime , 0 , ginfo -> ArenaType );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , err );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s" , bgQueueTypeId , bgTypeId , member -> GetGUIDLow (), member -> GetName ());
2008-10-11 14:16:25 -05:00
}
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: group end" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
}
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> ScheduleQueueUpdate ( 0 , 0 , bgQueueTypeId , bgTypeId , bracketEntry -> GetBracketId ());
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-08-08 04:37:24 +02:00
void WorldSession :: HandleBattlegroundPlayerPositionsOpcode ( WorldPacket & /*recv_data*/ )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd MSG_BATTLEGROUND_PLAYER_POSITIONS Message" );
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
Battleground * bg = _player -> GetBattleground ();
2010-04-07 19:14:10 +02:00
if ( ! bg ) // can't be received if player not in battleground
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2011-09-29 10:21:33 +02:00
uint32 count = 0 ;
Player * aplr = NULL ;
Player * hplr = NULL ;
2011-09-09 13:05:51 +02:00
2011-09-29 10:21:33 +02:00
if ( uint64 guid = bg -> GetFlagPickerGUID ( BG_TEAM_ALLIANCE ))
{
aplr = ObjectAccessor :: FindPlayer ( guid );
if ( aplr )
++ count ;
}
2011-09-09 13:05:51 +02:00
2011-09-29 10:21:33 +02:00
if ( uint64 guid = bg -> GetFlagPickerGUID ( BG_TEAM_HORDE ))
{
hplr = ObjectAccessor :: FindPlayer ( guid );
if ( hplr )
++ count ;
}
2011-09-09 13:05:51 +02:00
2011-09-29 10:21:33 +02:00
WorldPacket data ( MSG_BATTLEGROUND_PLAYER_POSITIONS , 4 + 4 + 16 * count );
data << 0 ;
data << count ;
if ( aplr )
{
data << uint64 ( aplr -> GetGUID ());
data << float ( aplr -> GetPositionX ());
data << float ( aplr -> GetPositionY ());
}
2011-09-09 13:05:51 +02:00
2011-09-29 10:21:33 +02:00
if ( hplr )
{
data << uint64 ( hplr -> GetGUID ());
data << float ( hplr -> GetPositionX ());
data << float ( hplr -> GetPositionY ());
2008-10-11 14:16:25 -05:00
}
2011-09-29 10:21:33 +02:00
SendPacket ( & data );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandlePVPLogDataOpcode ( WorldPacket & /*recv_data*/ )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd MSG_PVP_LOG_DATA Message" );
2009-10-17 15:51:44 -07:00
2011-06-27 02:50:00 +02:00
Battleground * bg = _player -> GetBattleground ();
2009-04-08 16:33:46 -05:00
if ( ! bg )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2011-06-27 02:50:00 +02:00
// Prevent players from sending BuildPvpLogDataPacket in an arena except for when sent in BattleGround::EndBattleGround.
if ( bg -> isArena ())
return ;
2008-10-11 14:16:25 -05:00
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildPvpLogDataPacket ( & data , bg );
2008-10-11 14:16:25 -05:00
SendPacket ( & data );
2009-10-17 15:51:44 -07:00
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Sent MSG_PVP_LOG_DATA Message" );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattlefieldListOpcode ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEFIELD_LIST Message" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 bgTypeId ;
recv_data >> bgTypeId ; // id from DBC
2009-10-17 15:51:44 -07:00
2009-06-11 00:45:59 -05:00
uint8 fromWhere ;
2009-12-17 10:43:12 +01:00
recv_data >> fromWhere ; // 0 - battlemaster (lua: ShowBattlefieldList), 1 - UI (lua: RequestBattlegroundInstanceInfo)
2009-12-18 13:41:30 -08:00
2009-12-17 10:43:12 +01:00
uint8 unk1 ;
recv_data >> unk1 ; // Unknown 3.2.2
2009-10-17 15:51:44 -07:00
2009-02-09 22:08:06 -06:00
BattlemasterListEntry const * bl = sBattlemasterListStore . LookupEntry ( bgTypeId );
2009-04-08 16:33:46 -05:00
if ( ! bl )
2008-10-11 14:16:25 -05:00
{
2011-09-26 09:52:17 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "BattlegroundHandler: invalid bgtype (%u) with player (Name: %s, GUID: %u) received." , bgTypeId , _player -> GetName (), _player -> GetGUIDLow ());
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundListPacket ( & data , 0 , _player , BattlegroundTypeId ( bgTypeId ), fromWhere );
2010-04-07 22:59:46 +02:00
SendPacket ( & data );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattleFieldPortOpcode ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint8 type ; // arenatype if arena
uint8 unk2 ; // unk, can be 0x0 (may be if was invited?) and 0x1
2009-02-09 22:08:06 -06:00
uint32 bgTypeId_ ; // type id from dbc
2008-10-11 14:16:25 -05:00
uint16 unk ; // 0x1F90 constant?
uint8 action ; // enter battle 0x1, leave queue 0x0
2009-10-17 15:51:44 -07:00
2009-02-09 22:08:06 -06:00
recv_data >> type >> unk2 >> bgTypeId_ >> unk >> action ;
2009-10-17 15:51:44 -07:00
2009-04-08 16:33:46 -05:00
if ( ! sBattlemasterListStore . LookupEntry ( bgTypeId_ ))
2008-10-11 14:16:25 -05:00
{
2011-09-26 09:52:17 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "BattlegroundHandler: invalid bgtype (%u) with player (Name: %s, GUID: %u) received." , bgTypeId_ , _player -> GetName (), _player -> GetGUIDLow ());
2010-02-15 15:31:27 +01:00
return ;
}
2011-09-26 09:52:17 +02:00
2010-08-08 04:37:24 +02:00
if ( ! _player -> InBattlegroundQueue ())
2010-02-15 15:31:27 +01:00
{
2011-09-26 09:52:17 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "BattlegroundHandler: Invalid CMSG_BATTLEFIELD_PORT received from player (Name: %s, GUID: %u), he is not in bg_queue." , _player -> GetName (), _player -> GetGUIDLow ());
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2010-08-08 04:37:24 +02:00
//get GroupQueueInfo from BattlegroundQueue
BattlegroundTypeId bgTypeId = BattlegroundTypeId ( bgTypeId_ );
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr :: BGQueueTypeId ( bgTypeId , type );
2010-12-22 21:25:23 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> m_BattlegroundQueues [ bgQueueTypeId ];
2010-08-08 04:37:24 +02:00
//we must use temporary variable, because GroupQueueInfo pointer can be deleted in BattlegroundQueue::RemovePlayer() function
2010-02-15 15:31:27 +01:00
GroupQueueInfo ginfo ;
if ( ! bgQueue . GetPlayerGroupInfoData ( _player -> GetGUID (), & ginfo ))
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "BattlegroundHandler: itrplayerstatus not found." );
2008-10-11 14:16:25 -05:00
return ;
}
2009-03-12 14:50:59 -06:00
// if action == 1, then instanceId is required
2010-02-15 15:31:27 +01:00
if ( ! ginfo . IsInvitedToBGInstanceGUID && action == 1 )
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "BattlegroundHandler: instance not found." );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-09-15 14:08:17 +02:00
Battleground * bg = sBattlegroundMgr -> GetBattleground ( ginfo . IsInvitedToBGInstanceGUID , bgTypeId );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// bg template might and must be used in case of leaving queue, when instance is not created yet
2009-04-08 16:33:46 -05:00
if ( ! bg && action == 0 )
2010-12-22 21:25:23 +01:00
bg = sBattlegroundMgr -> GetBattlegroundTemplate ( bgTypeId );
2009-04-08 16:33:46 -05:00
if ( ! bg )
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "BattlegroundHandler: bg_template not found for type id %u." , bgTypeId );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2010-02-15 15:31:27 +01:00
// expected bracket entry
2011-04-29 20:47:02 +02:00
PvPDifficultyEntry const * bracketEntry = GetBattlegroundBracketByLevel ( bg -> GetMapId (), _player -> getLevel ());
2010-02-15 15:31:27 +01:00
if ( ! bracketEntry )
return ;
//some checks if player isn't cheating - it is not exactly cheating, but we cannot allow it
if ( action == 1 && ginfo . ArenaType == 0 )
2008-10-11 14:16:25 -05:00
{
2010-02-15 15:31:27 +01:00
//if player is trying to enter battleground (not arena!) and he has deserter debuff, we must just remove him from queue
if ( ! _player -> CanJoinToBattleground ())
2008-10-11 14:16:25 -05:00
{
2010-02-15 15:31:27 +01:00
//send bg command result to show nice message
2010-04-11 11:22:29 +04:00
WorldPacket data2 ;
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data2 , ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS );
2010-02-15 15:31:27 +01:00
_player -> GetSession () -> SendPacket ( & data2 );
action = 0 ;
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player %s (%u) has a deserter debuff, do not port him to battleground!" , _player -> GetName (), _player -> GetGUIDLow ());
2009-03-09 17:01:18 -06:00
}
2010-02-15 15:31:27 +01:00
//if player don't match battleground max level, then do not allow him to enter! (this might happen when player leveled up during his waiting in queue
if ( _player -> getLevel () > bg -> GetMaxLevel ())
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "Battleground: Player %s (%u) has level (%u) higher than maxlevel (%u) of battleground (%u)! Do not port him to battleground!" ,
2010-02-15 15:31:27 +01:00
_player -> GetName (), _player -> GetGUIDLow (), _player -> getLevel (), bg -> GetMaxLevel (), bg -> GetTypeID ());
action = 0 ;
}
}
2010-08-08 04:37:24 +02:00
uint32 queueSlot = _player -> GetBattlegroundQueueIndex ( bgQueueTypeId );
2010-02-15 15:31:27 +01:00
WorldPacket data ;
2011-09-29 12:43:05 +02:00
switch ( action )
2010-02-15 15:31:27 +01:00
{
case 1 : // port to battleground
2010-08-08 04:37:24 +02:00
if ( ! _player -> IsInvitedForBattlegroundQueueType ( bgQueueTypeId ))
2010-02-15 15:31:27 +01:00
return ; // cheating?
2009-10-17 15:51:44 -07:00
2010-08-08 04:37:24 +02:00
if ( ! _player -> InBattleground ())
_player -> SetBattlegroundEntryPoint ();
2009-10-17 15:51:44 -07:00
2010-02-15 15:31:27 +01:00
// resurrect the player
if ( ! _player -> isAlive ())
{
_player -> ResurrectPlayer ( 1.0f );
_player -> SpawnCorpseBones ();
}
// stop taxi flight at port
if ( _player -> isInFlight ())
{
_player -> GetMotionMaster () -> MovementExpired ();
2010-03-17 23:16:35 +01:00
_player -> CleanupAfterTaxiFlight ();
2010-02-15 15:31:27 +01:00
}
2009-10-17 15:51:44 -07:00
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_IN_PROGRESS , 0 , bg -> GetStartTime (), bg -> GetArenaType ());
2010-02-15 15:31:27 +01:00
_player -> GetSession () -> SendPacket ( & data );
// remove battleground queue status from BGmgr
bgQueue . RemovePlayer ( _player -> GetGUID (), false );
// this is still needed here if battleground "jumping" shouldn't add deserter debuff
2010-08-08 04:37:24 +02:00
// also this is required to prevent stuck at old battleground after SetBattlegroundId set to new
2011-09-15 14:08:17 +02:00
if ( Battleground * currentBg = _player -> GetBattleground ())
2010-02-15 15:31:27 +01:00
currentBg -> RemovePlayerAtLeave ( _player -> GetGUID (), false , true );
// set the destination instance id
2010-08-08 04:37:24 +02:00
_player -> SetBattlegroundId ( bg -> GetInstanceID (), bgTypeId );
2010-02-15 15:31:27 +01:00
// set the destination team
_player -> SetBGTeam ( ginfo . Team );
2010-08-08 04:37:24 +02:00
// bg->HandleBeforeTeleportToBattleground(_player);
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> SendToBattleground ( _player , ginfo . IsInvitedToBGInstanceGUID , bgTypeId );
2010-02-15 15:31:27 +01:00
// add only in HandleMoveWorldPortAck()
2011-04-29 20:47:02 +02:00
// bg->AddPlayer(_player, team);
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u." , _player -> GetName (), _player -> GetGUIDLow (), bg -> GetInstanceID (), bg -> GetTypeID (), bgQueueTypeId );
2010-02-15 15:31:27 +01:00
break ;
case 0 : // leave queue
// if player leaves rated arena match before match start, it is counted as he played but he lost
2010-12-15 14:25:10 +06:00
if ( ginfo . IsRated && ginfo . IsInvitedToBGInstanceGUID )
2010-02-15 15:31:27 +01:00
{
2011-09-15 14:08:17 +02:00
ArenaTeam * at = sArenaTeamMgr -> GetArenaTeamById ( ginfo . Team );
2010-02-15 15:31:27 +01:00
if ( at )
2008-12-19 16:05:13 -06:00
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "UPDATING memberLost's personal arena rating for %u by opponents rating: %u, because he has left queue!" , GUID_LOPART ( _player -> GetGUID ()), ginfo . OpponentsTeamRating );
2010-08-27 18:18:26 +02:00
at -> MemberLost ( _player , ginfo . OpponentsMatchmakerRating );
2010-02-15 15:31:27 +01:00
at -> SaveToDB ();
2008-12-19 16:05:13 -06:00
}
2010-02-15 15:31:27 +01:00
}
2010-08-08 04:37:24 +02:00
_player -> RemoveBattlegroundQueueId ( bgQueueTypeId ); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_NONE , 0 , 0 , 0 );
2010-02-15 15:31:27 +01:00
bgQueue . RemovePlayer ( _player -> GetGUID (), true );
// player left queue, we should update it - do not update Arena Queue
if ( ! ginfo . ArenaType )
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> ScheduleQueueUpdate ( ginfo . ArenaMatchmakerRating , ginfo . ArenaType , bgQueueTypeId , bgTypeId , bracketEntry -> GetBracketId ());
2010-02-15 15:31:27 +01:00
SendPacket ( & data );
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player %s (%u) left queue for bgtype %u, queue type %u." , _player -> GetName (), _player -> GetGUIDLow (), bg -> GetTypeID (), bgQueueTypeId );
2010-02-15 15:31:27 +01:00
break ;
default :
2010-12-23 23:25:44 +01:00
sLog -> outError ( "Battleground port: unknown action %u" , action );
2010-02-15 15:31:27 +01:00
break ;
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2010-01-16 19:28:36 +03:00
void WorldSession :: HandleLeaveBattlefieldOpcode ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_LEAVE_BATTLEFIELD Message" );
2009-10-17 15:51:44 -07:00
2010-01-16 19:28:36 +03:00
recv_data . read_skip < uint8 > (); // unk1
recv_data . read_skip < uint8 > (); // unk2
2010-08-08 04:37:24 +02:00
recv_data . read_skip < uint32 > (); // BattlegroundTypeId
2010-01-16 19:28:36 +03:00
recv_data . read_skip < uint16 > (); // unk3
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
// not allow leave battleground in combat
2009-04-08 16:33:46 -05:00
if ( _player -> isInCombat ())
2010-08-08 04:37:24 +02:00
if ( Battleground * bg = _player -> GetBattleground ())
2009-04-08 16:33:46 -05:00
if ( bg -> GetStatus () != STATUS_WAIT_LEAVE )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
_player -> LeaveBattleground ();
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattlefieldStatusOpcode ( WorldPacket & /*recv_data*/ )
2008-10-11 14:16:25 -05:00
{
// empty opcode
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: Battleground status" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
2009-03-13 18:06:36 -06:00
// we must update all queues here
2011-09-15 14:08:17 +02:00
Battleground * bg = NULL ;
2009-04-29 00:26:07 -05:00
for ( uint8 i = 0 ; i < PLAYER_MAX_BATTLEGROUND_QUEUES ; ++ i )
2008-10-11 14:16:25 -05:00
{
2010-08-08 04:37:24 +02:00
BattlegroundQueueTypeId bgQueueTypeId = _player -> GetBattlegroundQueueTypeId ( i );
2009-04-08 16:33:46 -05:00
if ( ! bgQueueTypeId )
2009-03-10 15:29:50 -06:00
continue ;
2010-08-08 04:37:24 +02:00
BattlegroundTypeId bgTypeId = BattlegroundMgr :: BGTemplateId ( bgQueueTypeId );
uint8 arenaType = BattlegroundMgr :: BGArenaType ( bgQueueTypeId );
if ( bgTypeId == _player -> GetBattlegroundTypeId ())
2009-03-13 18:06:36 -06:00
{
2010-08-08 04:37:24 +02:00
bg = _player -> GetBattleground ();
2009-03-13 18:06:36 -06:00
//i cannot check any variable from player class because player class doesn't know if player is in 2v2 / 3v3 or 5v5 arena
//so i must use bg pointer to get that information
2009-04-08 16:33:46 -05:00
if ( bg && bg -> GetArenaType () == arenaType )
2009-03-13 18:06:36 -06:00
{
// this line is checked, i only don't know if GetStartTime is changing itself after bg end!
2010-08-08 04:37:24 +02:00
// send status in Battleground
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , i , STATUS_IN_PROGRESS , bg -> GetEndTime (), bg -> GetStartTime (), arenaType );
2009-03-13 18:06:36 -06:00
SendPacket ( & data );
continue ;
}
}
//we are sending update to player about queue - he can be invited there!
//get GroupQueueInfo for queue status
2010-12-22 21:25:23 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> m_BattlegroundQueues [ bgQueueTypeId ];
2010-02-15 15:31:27 +01:00
GroupQueueInfo ginfo ;
if ( ! bgQueue . GetPlayerGroupInfoData ( _player -> GetGUID (), & ginfo ))
2009-03-10 15:29:50 -06:00
continue ;
2010-02-15 15:31:27 +01:00
if ( ginfo . IsInvitedToBGInstanceGUID )
2009-03-13 18:06:36 -06:00
{
2010-12-22 21:25:23 +01:00
bg = sBattlegroundMgr -> GetBattleground ( ginfo . IsInvitedToBGInstanceGUID , bgTypeId );
2009-04-08 16:33:46 -05:00
if ( ! bg )
2009-03-13 18:06:36 -06:00
continue ;
2010-02-15 15:31:27 +01:00
uint32 remainingTime = getMSTimeDiff ( getMSTime (), ginfo . RemoveInviteTime );
2010-08-08 04:37:24 +02:00
// send status invited to Battleground
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , i , STATUS_WAIT_JOIN , remainingTime , 0 , arenaType );
2009-03-13 18:06:36 -06:00
SendPacket ( & data );
}
else
{
2010-12-22 21:25:23 +01:00
bg = sBattlegroundMgr -> GetBattlegroundTemplate ( bgTypeId );
2009-04-08 16:33:46 -05:00
if ( ! bg )
2009-03-13 18:06:36 -06:00
continue ;
2010-02-15 15:31:27 +01:00
// expected bracket entry
2011-04-29 20:47:02 +02:00
PvPDifficultyEntry const * bracketEntry = GetBattlegroundBracketByLevel ( bg -> GetMapId (), _player -> getLevel ());
2010-02-15 15:31:27 +01:00
if ( ! bracketEntry )
continue ;
uint32 avgTime = bgQueue . GetAverageQueueWaitTime ( & ginfo , bracketEntry -> GetBracketId ());
2010-08-08 04:37:24 +02:00
// send status in Battleground Queue
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , i , STATUS_WAIT_QUEUE , avgTime , getMSTimeDiff ( ginfo . JoinTime , getMSTime ()), arenaType );
2009-03-13 18:06:36 -06:00
SendPacket ( & data );
}
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2011-06-28 13:05:15 +02:00
void WorldSession :: HandleAreaSpiritHealerQueryOpcode ( WorldPacket & recv_data )
{
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_AREA_SPIRIT_HEALER_QUERY" );
2011-09-15 14:08:17 +02:00
Battleground * bg = _player -> GetBattleground ();
2011-06-28 13:05:15 +02:00
uint64 guid ;
recv_data >> guid ;
Creature * unit = GetPlayer () -> GetMap () -> GetCreature ( guid );
if ( ! unit )
return ;
if ( ! unit -> isSpiritService ()) // it's not spirit service
return ;
if ( bg )
sBattlegroundMgr -> SendAreaSpiritHealerQueryOpcode ( _player , bg , guid );
}
void WorldSession :: HandleAreaSpiritHealerQueueOpcode ( WorldPacket & recv_data )
{
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_AREA_SPIRIT_HEALER_QUEUE" );
2011-09-15 14:08:17 +02:00
Battleground * bg = _player -> GetBattleground ();
2011-06-28 13:05:15 +02:00
uint64 guid ;
recv_data >> guid ;
Creature * unit = GetPlayer () -> GetMap () -> GetCreature ( guid );
if ( ! unit )
return ;
if ( ! unit -> isSpiritService ()) // it's not spirit service
return ;
if ( bg )
bg -> AddPlayerToResurrectQueue ( guid , _player -> GetGUID ());
}
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleBattlemasterJoinArena ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
2011-02-20 20:16:34 +01:00
sLog -> outDebug ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_BATTLEMASTER_JOIN_ARENA" );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint64 guid ; // arena Battlemaster guid
2009-02-13 19:56:22 -06:00
uint8 arenaslot ; // 2v2, 3v3 or 5v5
2008-10-11 14:16:25 -05:00
uint8 asGroup ; // asGroup
uint8 isRated ; // isRated
2011-09-15 14:08:17 +02:00
Group * grp = NULL ;
2009-10-17 15:51:44 -07:00
2009-02-13 19:56:22 -06:00
recv_data >> guid >> arenaslot >> asGroup >> isRated ;
2009-10-17 15:51:44 -07:00
2009-08-19 16:54:52 -05:00
// ignore if we already in BG or BG queue
2010-08-08 04:37:24 +02:00
if ( _player -> InBattleground ())
2009-08-19 16:54:52 -05:00
return ;
2009-10-17 15:51:44 -07:00
2011-06-12 01:47:45 +02:00
Creature * unit = GetPlayer () -> GetMap () -> GetCreature ( guid );
2009-04-08 16:33:46 -05:00
if ( ! unit )
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2010-04-07 19:14:10 +02:00
if ( ! unit -> isBattleMaster ()) // it's not battle master
2008-10-11 14:16:25 -05:00
return ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint8 arenatype = 0 ;
uint32 arenaRating = 0 ;
2010-08-27 18:18:26 +02:00
uint32 matchmakerRating = 0 ;
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
switch ( arenaslot )
2008-10-11 14:16:25 -05:00
{
case 0 :
arenatype = ARENA_TYPE_2v2 ;
break ;
case 1 :
arenatype = ARENA_TYPE_3v3 ;
break ;
case 2 :
arenatype = ARENA_TYPE_5v5 ;
break ;
default :
2010-12-23 23:25:44 +01:00
sLog -> outError ( "Unknown arena slot %u at HandleBattlemasterJoinArena()" , arenaslot );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
//check existance
2010-12-22 21:25:23 +01:00
Battleground * bg = sBattlegroundMgr -> GetBattlegroundTemplate ( BATTLEGROUND_AA );
2010-02-15 15:31:27 +01:00
if ( ! bg )
2008-10-11 14:16:25 -05:00
{
2010-12-23 23:25:44 +01:00
sLog -> outError ( "Battleground: template bg (all arenas) not found" );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-09-09 14:27:23 +02:00
if ( DisableMgr :: IsDisabledFor ( DISABLE_TYPE_BATTLEGROUND , BATTLEGROUND_AA , NULL ))
2010-07-21 12:14:23 +02:00
{
ChatHandler ( this ). PSendSysMessage ( LANG_ARENA_DISABLED );
return ;
}
2010-08-08 04:37:24 +02:00
BattlegroundTypeId bgTypeId = bg -> GetTypeID ();
BattlegroundQueueTypeId bgQueueTypeId = BattlegroundMgr :: BGQueueTypeId ( bgTypeId , arenatype );
2011-04-29 20:47:02 +02:00
PvPDifficultyEntry const * bracketEntry = GetBattlegroundBracketByLevel ( bg -> GetMapId (), _player -> getLevel ());
2010-02-15 15:31:27 +01:00
if ( ! bracketEntry )
return ;
2009-10-17 15:51:44 -07:00
2010-05-01 22:25:14 +02:00
GroupJoinBattlegroundResult err = ERR_GROUP_JOIN_BATTLEGROUND_FAIL ;
2010-04-11 11:22:29 +04:00
2009-04-08 16:33:46 -05:00
if ( ! asGroup )
2008-10-11 14:16:25 -05:00
{
// check if already in queue
2010-08-08 04:37:24 +02:00
if ( _player -> GetBattlegroundQueueIndex ( bgQueueTypeId ) < PLAYER_MAX_BATTLEGROUND_QUEUES )
2008-10-11 14:16:25 -05:00
//player is already in this queue
return ;
// check if has free queue slots
2010-08-08 04:37:24 +02:00
if ( ! _player -> HasFreeBattlegroundQueueId ())
2008-10-11 14:16:25 -05:00
return ;
}
else
{
grp = _player -> GetGroup ();
// no group found, error
2009-04-08 16:33:46 -05:00
if ( ! grp )
2008-10-11 14:16:25 -05:00
return ;
2010-04-11 11:22:29 +04:00
if ( grp -> GetLeaderGUID () != _player -> GetGUID ())
2010-04-11 20:20:38 +02:00
return ;
2010-08-08 04:37:24 +02:00
err = grp -> CanJoinBattlegroundQueue ( bg , bgQueueTypeId , arenatype , arenatype , ( bool ) isRated , arenaslot );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
uint32 ateamId = 0 ;
2009-10-17 15:51:44 -07:00
2009-04-08 16:33:46 -05:00
if ( isRated )
2008-10-11 14:16:25 -05:00
{
2009-02-13 19:56:22 -06:00
ateamId = _player -> GetArenaTeamId ( arenaslot );
2008-10-11 14:16:25 -05:00
// check real arenateam existence only here (if it was moved to group->CanJoin .. () then we would ahve to get it twice)
2011-09-15 14:08:17 +02:00
ArenaTeam * at = sArenaTeamMgr -> GetArenaTeamById ( ateamId );
2009-04-08 16:33:46 -05:00
if ( ! at )
2008-10-11 14:16:25 -05:00
{
_player -> GetSession () -> SendNotInArenaTeamPacket ( arenatype );
return ;
}
// get the team rating for queueing
arenaRating = at -> GetRating ();
2010-08-27 18:18:26 +02:00
matchmakerRating = at -> GetAverageMMR ( grp );
2008-10-11 14:16:25 -05:00
// the arenateam id must match for everyone in the group
2009-10-17 15:51:44 -07:00
2010-04-21 18:49:57 +02:00
if ( arenaRating <= 0 )
arenaRating = 1 ;
}
2010-04-17 12:36:41 +02:00
2010-12-22 21:25:23 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> m_BattlegroundQueues [ bgQueueTypeId ];
2009-04-08 16:33:46 -05:00
if ( asGroup )
2008-10-11 14:16:25 -05:00
{
2010-05-01 22:25:14 +02:00
uint32 avgTime = 0 ;
2010-04-11 20:20:38 +02:00
2010-04-24 17:48:52 +02:00
if ( err > 0 )
2010-04-11 20:20:38 +02:00
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: arena join as group start" );
2010-04-11 11:22:29 +04:00
if ( isRated )
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: arena team id %u, leader %s queued with matchmaker rating %u for type %u" , _player -> GetArenaTeamId ( arenaslot ), _player -> GetName (), matchmakerRating , arenatype );
2010-04-11 11:22:29 +04:00
bg -> SetRated ( true );
}
else
bg -> SetRated ( false );
2011-09-15 14:08:17 +02:00
GroupQueueInfo * ginfo = bgQueue . AddGroup ( _player , grp , bgTypeId , bracketEntry , arenatype , isRated , false , arenaRating , matchmakerRating , ateamId );
2010-04-11 20:20:38 +02:00
avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
2009-08-28 05:01:53 +02:00
}
2009-10-17 16:20:24 -07:00
2011-09-15 14:08:17 +02:00
for ( GroupReference * itr = grp -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2008-10-11 14:16:25 -05:00
{
2011-09-15 14:08:17 +02:00
Player * member = itr -> getSource ();
2010-04-11 11:22:29 +04:00
if ( ! member )
continue ;
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
2010-04-11 20:20:38 +02:00
2010-04-11 11:22:29 +04:00
if ( err <= 0 )
{
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , err );
2010-04-11 11:22:29 +04:00
member -> GetSession () -> SendPacket ( & data );
continue ;
}
// add to queue
2010-08-08 04:37:24 +02:00
uint32 queueSlot = member -> AddBattlegroundQueueId ( bgQueueTypeId );
2010-04-11 11:22:29 +04:00
2008-10-11 14:16:25 -05:00
// send status packet (in queue)
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_WAIT_QUEUE , avgTime , 0 , arenatype );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildGroupJoinedBattlegroundPacket ( & data , err );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "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 ());
2008-10-11 14:16:25 -05:00
}
}
else
{
2011-09-15 14:08:17 +02:00
GroupQueueInfo * ginfo = bgQueue . AddGroup ( _player , NULL , bgTypeId , bracketEntry , arenatype , isRated , false , arenaRating , matchmakerRating , ateamId );
2010-02-15 15:31:27 +01:00
uint32 avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
2010-08-08 04:37:24 +02:00
uint32 queueSlot = _player -> AddBattlegroundQueueId ( bgQueueTypeId );
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
WorldPacket data ;
// send status packet (in queue)
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , queueSlot , STATUS_WAIT_QUEUE , avgTime , 0 , arenatype );
2008-10-11 14:16:25 -05:00
SendPacket ( & data );
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "Battleground: player joined queue for arena, skirmish, bg queue type %u bg type %u: GUID %u, NAME %s" , bgQueueTypeId , bgTypeId , _player -> GetGUIDLow (), _player -> GetName ());
2008-10-11 14:16:25 -05:00
}
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> ScheduleQueueUpdate ( matchmakerRating , arenatype , bgQueueTypeId , bgTypeId , bracketEntry -> GetBracketId ());
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2010-04-07 22:59:46 +02:00
void WorldSession :: HandleReportPvPAFK ( WorldPacket & recv_data )
2008-10-11 14:16:25 -05:00
{
uint64 playerGuid ;
recv_data >> playerGuid ;
2011-09-15 14:08:17 +02:00
Player * reportedPlayer = ObjectAccessor :: FindPlayer ( playerGuid );
2009-10-17 15:51:44 -07:00
2009-04-08 16:33:46 -05:00
if ( ! reportedPlayer )
2008-10-11 14:16:25 -05:00
{
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "WorldSession::HandleReportPvPAFK: player not found" );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2011-04-29 20:47:02 +02:00
sLog -> outDebug ( LOG_FILTER_BATTLEGROUND , "WorldSession::HandleReportPvPAFK: %s reported %s" , _player -> GetName (), reportedPlayer -> GetName ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
reportedPlayer -> ReportedAfkBy ( _player );
}