2010-10-07 15:35:36 +02:00
/*
2012-12-31 23:15:50 +01:00
* Copyright (C) 2008-2013 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
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleBattlemasterHelloOpcode ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
uint64 guid ;
2012-08-05 19:40:30 -05:00
recvData >> guid ;
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( 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
2012-05-30 08:01:02 +02:00
SendBattleGroundList ( guid , bgTypeId );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-05-30 08:01:02 +02:00
void WorldSession :: SendBattleGroundList ( uint64 guid , BattlegroundTypeId bgTypeId )
2008-10-11 14:16:25 -05:00
{
WorldPacket data ;
2011-11-27 23:31:46 +01:00
sBattlegroundMgr -> BuildBattlegroundListPacket ( & data , guid , _player , bgTypeId );
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
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleBattlemasterJoinOpcode ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
2009-02-09 22:08:06 -06:00
uint32 bgTypeId_ ;
2008-10-11 14:16:25 -05:00
uint32 instanceId ;
2012-08-28 23:42:15 +01:00
uint8 asGroup ;
2009-02-27 12:13:59 -06:00
bool isPremade = false ;
2011-09-15 14:08:17 +02:00
Group * grp = NULL ;
2012-08-28 23:42:15 +01:00
ObjectGuid guid ;
recvData >> instanceId ; // Instance Id
guid [ 2 ] = recvData . ReadBit ();
guid [ 0 ] = recvData . ReadBit ();
guid [ 3 ] = recvData . ReadBit ();
guid [ 1 ] = recvData . ReadBit ();
guid [ 5 ] = recvData . ReadBit ();
asGroup = recvData . ReadBit (); // As Group
guid [ 4 ] = recvData . ReadBit ();
guid [ 6 ] = recvData . ReadBit ();
guid [ 7 ] = recvData . ReadBit ();
recvData . ReadByteSeq ( guid [ 2 ]);
recvData . ReadByteSeq ( guid [ 6 ]);
recvData . ReadByteSeq ( guid [ 4 ]);
recvData . ReadByteSeq ( guid [ 3 ]);
recvData . ReadByteSeq ( guid [ 7 ]);
recvData . ReadByteSeq ( guid [ 0 ]);
recvData . ReadByteSeq ( guid [ 5 ]);
recvData . ReadByteSeq ( guid [ 1 ]);
//extract from guid
bgTypeId_ = GUID_LOPART ( guid );
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
{
2013-05-13 15:07:36 +02:00
TC_LOG_ERROR ( LOG_FILTER_NETWORKIO , "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
2013-05-21 09:55:09 +02:00
//TC_LOG_DEBUG(LOG_FILTER_NETWORKIO, "WORLD: Recvd CMSG_BATTLEMASTER_JOIN Message from (GUID:"UI64FMTD" TypeId:%u)", guid, bgTypeId_);
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 ;
2012-10-12 00:26:05 +02:00
GroupJoinBattlegroundResult err = ERR_BATTLEGROUND_NONE ;
2010-04-11 11:22:29 +04:00
// check queue conditions
2012-08-28 23:42:15 +01:00
if ( ! asGroup )
2008-10-11 14:16:25 -05:00
{
2010-11-24 15:37:22 +01:00
if ( GetPlayer () -> isUsingLfg ())
{
WorldPacket data ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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
2013-01-17 17:35:47 +01:00
if ( ! _player -> CanJoinToBattleground ( bg ))
2008-10-11 14:16:25 -05:00
{
2010-04-11 11:22:29 +04:00
WorldPacket data ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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
{
2012-10-04 10:39:37 +02:00
// player is already in random queue
2010-05-26 11:34:37 +02:00
WorldPacket data ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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
{
2012-10-04 10:39:37 +02:00
// player is already in queue, can't start random queue
2010-05-26 11:34:37 +02:00
WorldPacket data ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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 )
2012-10-04 10:39:37 +02:00
// player is already in this queue
2008-10-11 14:16:25 -05:00
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 ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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
}
2012-10-04 10:39:37 +02:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> GetBattlegroundQueue ( bgQueueTypeId );
2011-09-15 14:08:17 +02:00
GroupQueueInfo * ginfo = bgQueue . AddGroup ( _player , NULL , bgTypeId , bracketEntry , 0 , false , isPremade , 0 , 0 );
2012-10-12 00:26:05 +02:00
2010-04-19 09:26:37 +02:00
uint32 avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
2010-08-08 04:37:24 +02:00
uint32 queueSlot = _player -> AddBattlegroundQueueId ( bgQueueTypeId );
2010-04-19 09:26:37 +02:00
2012-10-12 00:26:05 +02:00
// add joined time data
_player -> AddBattlegroundQueueJoinTime ( bgTypeId , ginfo -> JoinTime );
WorldPacket data ; // send status packet (in queue)
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , _player , queueSlot , STATUS_WAIT_QUEUE , avgTime , ginfo -> JoinTime , ginfo -> ArenaType );
2010-04-19 09:26:37 +02:00
SendPacket ( & data );
2012-10-12 00:26:05 +02:00
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s" ,
2012-10-24 13:29:34 +02:00
bgQueueTypeId , bgTypeId , _player -> GetGUIDLow (), _player -> GetName (). c_str ());
2008-10-11 14:16:25 -05:00
}
else
{
grp = _player -> GetGroup ();
2012-10-12 00:26:05 +02:00
2009-04-08 16:33:46 -05:00
if ( ! grp )
2008-10-11 14:16:25 -05:00
return ;
2012-10-12 00:26:05 +02:00
2010-04-11 11:22:29 +04:00
if ( grp -> GetLeaderGUID () != _player -> GetGUID ())
2008-10-11 14:16:25 -05:00
return ;
2012-11-07 23:21:19 +01:00
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
2012-10-04 10:39:37 +02:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> GetBattlegroundQueue ( 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
2012-10-12 00:26:05 +02:00
if ( ! err )
2010-04-11 11:22:29 +04:00
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( 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 ();
2012-05-30 08:01:02 +02:00
if ( ! member )
continue ; // this should never happen
2009-10-17 15:51:44 -07:00
2012-10-12 00:26:05 +02:00
if ( err )
2010-04-11 20:20:38 +02:00
{
2012-10-12 00:26:05 +02:00
WorldPacket data ;
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , 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
2012-10-12 00:26:05 +02:00
// add joined time data
member -> AddBattlegroundQueueJoinTime ( bgTypeId , ginfo -> JoinTime );
WorldPacket data ; // send status packet (in queue)
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , member , queueSlot , STATUS_WAIT_QUEUE , avgTime , ginfo -> JoinTime , ginfo -> ArenaType );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: player joined queue for bg queue type %u bg type %u: GUID %u, NAME %s" ,
2012-10-24 13:29:34 +02:00
bgQueueTypeId , bgTypeId , member -> GetGUIDLow (), member -> GetName (). c_str ());
2008-10-11 14:16:25 -05:00
}
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: group end" );
2008-10-11 14:16:25 -05:00
}
2012-10-12 00:26:05 +02: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
2012-11-02 22:23:14 +01:00
void WorldSession :: HandleBattlegroundPlayerPositionsOpcode ( WorldPacket & /*recvData*/ )
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_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
2012-08-28 23:42:15 +01:00
uint32 acount = 0 ;
uint32 hcount = 0 ;
2011-09-29 10:21:33 +02:00
Player * aplr = NULL ;
Player * hplr = NULL ;
2011-09-09 13:05:51 +02:00
2012-10-04 10:57:32 +02:00
if ( uint64 guid = bg -> GetFlagPickerGUID ( TEAM_ALLIANCE ))
2011-09-29 10:21:33 +02:00
{
aplr = ObjectAccessor :: FindPlayer ( guid );
if ( aplr )
2012-08-28 23:42:15 +01:00
++ acount ;
2011-09-29 10:21:33 +02:00
}
2011-09-09 13:05:51 +02:00
2012-10-04 10:57:32 +02:00
if ( uint64 guid = bg -> GetFlagPickerGUID ( TEAM_HORDE ))
2011-09-29 10:21:33 +02:00
{
hplr = ObjectAccessor :: FindPlayer ( guid );
if ( hplr )
2012-08-28 23:42:15 +01:00
++ hcount ;
2011-09-29 10:21:33 +02:00
}
2011-09-09 13:05:51 +02:00
2012-08-28 23:42:15 +01:00
ObjectGuid aguid = aplr ? aplr -> GetGUID () : 0 ;
ObjectGuid hguid = hplr ? hplr -> GetGUID () : 0 ;
WorldPacket data ( SMSG_BATTLEFIELD_PLAYER_POSITIONS );
data . WriteBits ( acount , 22 );
for ( uint8 i = 0 ; i < acount ; i ++ )
2011-09-29 10:21:33 +02:00
{
2012-08-28 23:42:15 +01:00
data . WriteBit ( aguid [ 3 ]);
data . WriteBit ( aguid [ 5 ]);
data . WriteBit ( aguid [ 1 ]);
data . WriteBit ( aguid [ 6 ]);
data . WriteBit ( aguid [ 7 ]);
data . WriteBit ( aguid [ 0 ]);
data . WriteBit ( aguid [ 2 ]);
data . WriteBit ( aguid [ 4 ]);
2011-09-29 10:21:33 +02:00
}
2011-09-09 13:05:51 +02:00
2012-08-28 23:42:15 +01:00
data . WriteBits ( hcount , 22 );
for ( uint8 i = 0 ; i < hcount ; i ++ )
2011-09-29 10:21:33 +02:00
{
2012-08-28 23:42:15 +01:00
data . WriteBit ( hguid [ 6 ]);
data . WriteBit ( hguid [ 5 ]);
data . WriteBit ( hguid [ 4 ]);
data . WriteBit ( hguid [ 7 ]);
data . WriteBit ( hguid [ 2 ]);
data . WriteBit ( hguid [ 1 ]);
data . WriteBit ( hguid [ 0 ]);
data . WriteBit ( hguid [ 3 ]);
}
data . FlushBits ();
for ( uint8 i = 0 ; i < hcount ; i ++ )
{
data . WriteByteSeq ( hguid [ 2 ]);
data . WriteByteSeq ( hguid [ 1 ]);
2011-09-29 10:21:33 +02:00
data << float ( hplr -> GetPositionY ());
2012-08-28 23:42:15 +01:00
data . WriteByteSeq ( hguid [ 5 ]);
data . WriteByteSeq ( hguid [ 4 ]);
data . WriteByteSeq ( hguid [ 7 ]);
data . WriteByteSeq ( hguid [ 0 ]);
data . WriteByteSeq ( hguid [ 6 ]);
data . WriteByteSeq ( hguid [ 3 ]);
data << float ( hplr -> GetPositionX ());
}
for ( uint8 i = 0 ; i < acount ; i ++ )
{
data . WriteByteSeq ( aguid [ 6 ]);
data << float ( aplr -> GetPositionX ());
data . WriteByteSeq ( aguid [ 5 ]);
data . WriteByteSeq ( aguid [ 3 ]);
data << float ( aplr -> GetPositionY ());
data . WriteByteSeq ( aguid [ 1 ]);
data . WriteByteSeq ( aguid [ 7 ]);
data . WriteByteSeq ( aguid [ 0 ]);
data . WriteByteSeq ( aguid [ 2 ]);
data . WriteByteSeq ( aguid [ 4 ]);
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
2012-08-05 19:40:30 -05:00
void WorldSession :: HandlePVPLogDataOpcode ( WorldPacket & /*recvData*/ )
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_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
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Sent SMSG_PVP_LOG_DATA Message" );
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleBattlefieldListOpcode ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( 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 ;
2012-08-05 19:40:30 -05:00
recvData >> bgTypeId ; // id from DBC
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
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "BattlegroundHandler: invalid bgtype (%u) with player (Name: %s, GUID: %u) received." , bgTypeId , _player -> GetName (). c_str (), _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 ;
2011-11-27 23:31:46 +01:00
sBattlegroundMgr -> BuildBattlegroundListPacket ( & data , 0 , _player , BattlegroundTypeId ( bgTypeId ));
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
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleBattleFieldPortOpcode ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEFIELD_PORT Message" );
2009-10-17 15:51:44 -07:00
2012-09-02 12:17:38 +02:00
uint32 time ;
2012-10-12 00:26:05 +02:00
uint32 queueSlot ;
uint32 unk ;
uint8 action ; // enter battle 0x1, leave queue 0x0
2012-09-02 12:17:38 +02:00
ObjectGuid guid ;
recvData >> time ;
2012-10-12 00:26:05 +02:00
recvData >> queueSlot ;
recvData >> unk ;
2012-09-02 12:17:38 +02:00
guid [ 0 ] = recvData . ReadBit ();
guid [ 1 ] = recvData . ReadBit ();
guid [ 5 ] = recvData . ReadBit ();
guid [ 6 ] = recvData . ReadBit ();
guid [ 7 ] = recvData . ReadBit ();
guid [ 4 ] = recvData . ReadBit ();
guid [ 3 ] = recvData . ReadBit ();
guid [ 2 ] = recvData . ReadBit ();
2009-10-17 15:51:44 -07:00
2012-09-02 12:17:38 +02:00
action = recvData . ReadBit ();
recvData . ReadByteSeq ( guid [ 1 ]);
recvData . ReadByteSeq ( guid [ 3 ]);
recvData . ReadByteSeq ( guid [ 5 ]);
recvData . ReadByteSeq ( guid [ 7 ]);
recvData . ReadByteSeq ( guid [ 0 ]);
recvData . ReadByteSeq ( guid [ 2 ]);
recvData . ReadByteSeq ( guid [ 6 ]);
recvData . ReadByteSeq ( guid [ 4 ]);
2009-10-17 15:51:44 -07:00
2012-10-12 00:26:05 +02:00
if ( ! _player -> InBattlegroundQueue ())
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u. Player not in queue!" ,
2012-11-16 08:51:15 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action );
2010-02-15 15:31:27 +01:00
return ;
}
2011-09-26 09:52:17 +02:00
2012-10-12 00:26:05 +02:00
BattlegroundQueueTypeId bgQueueTypeId = _player -> GetBattlegroundQueueTypeId ( queueSlot );
if ( bgQueueTypeId == BATTLEGROUND_QUEUE_NONE )
2010-02-15 15:31:27 +01:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u. Invalid queueSlot!" ,
2012-11-16 08:51:15 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2012-10-04 10:39:37 +02:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> GetBattlegroundQueue ( bgQueueTypeId );
2012-10-12 00:26:05 +02:00
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
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u. Player not in queue (No player Group Info)!" ,
2012-11-16 08:51:15 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action );
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
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u. Player is not invited to any bg!" ,
2012-11-16 08:51:15 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action );
2008-10-11 14:16:25 -05:00
return ;
}
2009-10-17 15:51:44 -07:00
2012-11-20 10:37:25 +01:00
BattlegroundTypeId bgTypeId = BattlegroundMgr :: BGTemplateId ( bgQueueTypeId );
// BGTemplateId returns BATTLEGROUND_AA when it is arena queue.
// Do instance id search as there is no AA bg instances.
Battleground * bg = sBattlegroundMgr -> GetBattleground ( ginfo . IsInvitedToBGInstanceGUID , bgTypeId == BATTLEGROUND_AA ? BATTLEGROUND_TYPE_NONE : bgTypeId );
2009-04-08 16:33:46 -05:00
if ( ! bg )
2008-10-11 14:16:25 -05:00
{
2012-11-14 19:33:21 +01:00
if ( action )
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u. Cant find BG with id %u!" ,
2012-11-16 09:09:27 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action , ginfo . IsInvitedToBGInstanceGUID );
2012-11-14 19:33:21 +01:00
return ;
}
bg = sBattlegroundMgr -> GetBattlegroundTemplate ( bgTypeId );
if ( ! bg )
{
2013-05-13 15:07:36 +02:00
TC_LOG_ERROR ( LOG_FILTER_NETWORKIO , "BattlegroundHandler: bg_template not found for type id %u." , bgTypeId );
2012-11-14 19:33:21 +01:00
return ;
}
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "CMSG_BATTLEFIELD_PORT %s Slot: %u, Unk: %u, Time: %u, Action: %u." ,
2012-11-16 08:51:15 +01:00
GetPlayerInfo (). c_str (), queueSlot , unk , time , action );
2012-11-14 19:33:21 +01:00
2012-11-20 10:37:25 +01:00
// get real bg type
bgTypeId = bg -> GetTypeID ();
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
2013-01-17 17:35:47 +01:00
if ( ! _player -> CanJoinToBattleground ( bg ))
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 ;
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildStatusFailedPacket ( & data2 , bg , _player , 0 , ERR_GROUP_JOIN_BATTLEGROUND_DESERTERS );
2010-02-15 15:31:27 +01:00
_player -> GetSession () -> SendPacket ( & data2 );
action = 0 ;
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Player %s (%u) has a deserter debuff, do not port him to battleground!" , _player -> GetName (). c_str (), _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
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "Player %s (%u) has level (%u) higher than maxlevel (%u) of battleground (%u)! Do not port him to battleground!" ,
2012-10-24 13:29:34 +02:00
_player -> GetName (). c_str (), _player -> GetGUIDLow (), _player -> getLevel (), bg -> GetMaxLevel (), bg -> GetTypeID ());
2010-02-15 15:31:27 +01:00
action = 0 ;
}
}
2012-10-12 00:26:05 +02:00
2010-02-15 15:31:27 +01:00
WorldPacket data ;
2012-11-14 19:33:21 +01:00
if ( action )
2010-02-15 15:31:27 +01:00
{
2012-11-14 19:33:21 +01:00
if ( ! _player -> IsInvitedForBattlegroundQueueType ( bgQueueTypeId ))
return ; // cheating?
2009-10-17 15:51:44 -07:00
2012-11-14 19:33:21 +01:00
if ( ! _player -> InBattleground ())
_player -> SetBattlegroundEntryPoint ();
2009-10-17 15:51:44 -07:00
2012-11-14 19:33:21 +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 ();
_player -> CleanupAfterTaxiFlight ();
}
2009-10-17 15:51:44 -07:00
2013-01-28 02:54:27 +00:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , _player , queueSlot , STATUS_IN_PROGRESS , _player -> GetBattlegroundQueueJoinTime ( bgTypeId ), bg -> GetElapsedTime (), bg -> GetArenaType ());
2012-11-14 19:33:21 +01:00
_player -> GetSession () -> SendPacket ( & data );
2013-01-20 19:44:38 +01:00
2012-11-14 19:33:21 +01:00
// remove battleground queue status from BGmgr
bgQueue . RemovePlayer ( _player -> GetGUID (), false );
// this is still needed here if battleground "jumping" shouldn't add deserter debuff
// also this is 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 (), bgTypeId );
// set the destination team
_player -> SetBGTeam ( ginfo . Team );
2013-01-20 19:44:38 +01:00
2012-11-14 19:33:21 +01:00
// bg->HandleBeforeTeleportToBattleground(_player);
sBattlegroundMgr -> SendToBattleground ( _player , ginfo . IsInvitedToBGInstanceGUID , bgTypeId );
// add only in HandleMoveWorldPortAck()
// bg->AddPlayer(_player, team);
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: player %s (%u) joined battle for bg %u, bgtype %u, queue type %u." , _player -> GetName (). c_str (), _player -> GetGUIDLow (), bg -> GetInstanceID (), bg -> GetTypeID (), bgQueueTypeId );
2012-11-14 19:33:21 +01:00
}
else // leave queue
{
// if player leaves rated arena match before match start, it is counted as he played but he lost
if ( ginfo . IsRated && ginfo . IsInvitedToBGInstanceGUID )
{
ArenaTeam * at = sArenaTeamMgr -> GetArenaTeamById ( ginfo . Team );
if ( at )
2010-02-15 15:31:27 +01:00
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( 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 );
2012-11-14 19:33:21 +01:00
at -> MemberLost ( _player , ginfo . OpponentsMatchmakerRating );
at -> SaveToDB ();
2010-02-15 15:31:27 +01:00
}
2012-11-14 19:33:21 +01:00
}
2012-11-16 08:51:15 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , _player , queueSlot , STATUS_NONE , _player -> GetBattlegroundQueueJoinTime ( bgTypeId ), 0 , 0 );
2012-11-20 10:37:25 +01:00
SendPacket ( & data );
2012-11-16 08:51:15 +01:00
2012-11-20 10:37:25 +01:00
_player -> RemoveBattlegroundQueueId ( bgQueueTypeId ); // must be called this way, because if you move this call to queue->removeplayer, it causes bugs
2012-11-14 19:33:21 +01:00
bgQueue . RemovePlayer ( _player -> GetGUID (), true );
// player left queue, we should update it - do not update Arena Queue
if ( ! ginfo . ArenaType )
sBattlegroundMgr -> ScheduleQueueUpdate ( ginfo . ArenaMatchmakerRating , ginfo . ArenaType , bgQueueTypeId , bgTypeId , bracketEntry -> GetBracketId ());
2012-11-20 10:37:25 +01:00
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: player %s (%u) left queue for bgtype %u, queue type %u." , _player -> GetName (). c_str (), _player -> GetGUIDLow (), bg -> GetTypeID (), bgQueueTypeId );
2008-10-11 14:16:25 -05:00
}
}
2009-10-17 15:51:44 -07:00
2012-10-16 09:35:15 +02:00
void WorldSession :: HandleBattlefieldLeaveOpcode ( WorldPacket & /*recvData*/ )
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEFIELD_LEAVE Message" );
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
2012-08-05 19:40:30 -05:00
void WorldSession :: HandleBattlefieldStatusOpcode ( WorldPacket & /*recvData*/ )
2008-10-11 14:16:25 -05:00
{
// empty opcode
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: Recvd CMSG_BATTLEFIELD_STATUS Message" );
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
{
2012-10-12 00:26:05 +02:00
// this line is checked, i only don't know if GetElapsedTime() is changing itself after bg end!
2010-08-08 04:37:24 +02:00
// send status in Battleground
2013-01-28 02:54:27 +00:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , GetPlayer (), i , STATUS_IN_PROGRESS , _player -> GetBattlegroundQueueJoinTime ( bgTypeId ), bg -> GetElapsedTime (), arenaType );
2009-03-13 18:06:36 -06:00
SendPacket ( & data );
continue ;
}
}
2012-10-12 00:26:05 +02:00
2009-03-13 18:06:36 -06:00
//we are sending update to player about queue - he can be invited there!
//get GroupQueueInfo for queue status
2012-10-04 10:39:37 +02:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> GetBattlegroundQueue ( 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 ;
2012-10-12 00:26:05 +02:00
2010-08-08 04:37:24 +02:00
// send status invited to Battleground
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , GetPlayer (), i , STATUS_WAIT_JOIN , getMSTimeDiff ( getMSTime (), ginfo . RemoveInviteTime ), _player -> GetBattlegroundQueueJoinTime ( bgTypeId ), 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
2012-10-12 00:26:05 +02:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , GetPlayer (), i , STATUS_WAIT_QUEUE , avgTime , _player -> GetBattlegroundQueueJoinTime ( bgTypeId ), 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
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleBattlemasterJoinArena ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_BATTLEMASTER_JOIN_ARENA" );
2009-10-17 15:51:44 -07:00
2009-02-13 19:56:22 -06:00
uint8 arenaslot ; // 2v2, 3v3 or 5v5
2009-10-17 15:51:44 -07:00
2012-11-20 10:37:25 +01:00
recvData >> arenaslot ;
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
2008-10-11 14:16:25 -05:00
uint32 arenaRating = 0 ;
2010-08-27 18:18:26 +02:00
uint32 matchmakerRating = 0 ;
2009-10-17 15:51:44 -07:00
2012-11-20 10:37:25 +01:00
uint8 arenatype = ArenaTeam :: GetTypeBySlot ( arenaslot );
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
{
2013-05-13 15:07:36 +02:00
TC_LOG_ERROR ( LOG_FILTER_NETWORKIO , "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
2012-10-12 00:26:05 +02:00
GroupJoinBattlegroundResult err = ERR_BATTLEGROUND_NONE ;
2010-04-11 11:22:29 +04:00
2012-11-20 10:37:25 +01:00
Group * grp = _player -> GetGroup ();
// no group found, error
if ( ! grp )
return ;
if ( grp -> GetLeaderGUID () != _player -> GetGUID ())
return ;
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
uint32 ateamId = _player -> GetArenaTeamId ( arenaslot );
// check real arenateam existence only here (if it was moved to group->CanJoin .. () then we would ahve to get it twice)
ArenaTeam * at = sArenaTeamMgr -> GetArenaTeamById ( ateamId );
if ( ! at )
2008-10-11 14:16:25 -05:00
{
2012-11-20 10:37:25 +01:00
_player -> GetSession () -> SendNotInArenaTeamPacket ( arenatype );
return ;
2008-10-11 14:16:25 -05:00
}
2009-10-17 15:51:44 -07:00
2012-11-20 10:37:25 +01:00
// get the team rating for queueing
arenaRating = at -> GetRating ();
matchmakerRating = at -> GetAverageMMR ( grp );
// the arenateam id must match for everyone in the group
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
if ( arenaRating <= 0 )
arenaRating = 1 ;
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
BattlegroundQueue & bgQueue = sBattlegroundMgr -> GetBattlegroundQueue ( bgQueueTypeId );
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
uint32 avgTime = 0 ;
2013-01-14 15:05:30 +01:00
GroupQueueInfo * ginfo = NULL ;
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
err = grp -> CanJoinBattlegroundQueue ( bg , bgQueueTypeId , arenatype , arenatype , true , arenaslot );
if ( ! err )
2008-10-11 14:16:25 -05:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "Battleground: arena team id %u, leader %s queued with matchmaker rating %u for type %u" , _player -> GetArenaTeamId ( arenaslot ), _player -> GetName (). c_str (), matchmakerRating , arenatype );
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
ginfo = bgQueue . AddGroup ( _player , grp , bgTypeId , bracketEntry , arenatype , true , false , arenaRating , matchmakerRating , ateamId );
avgTime = bgQueue . GetAverageQueueWaitTime ( ginfo , bracketEntry -> GetBracketId ());
2010-04-21 18:49:57 +02:00
}
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
for ( GroupReference * itr = grp -> GetFirstMember (); itr != NULL ; itr = itr -> next ())
2008-10-11 14:16:25 -05:00
{
2012-11-20 10:37:25 +01:00
Player * member = itr -> getSource ();
if ( ! member )
continue ;
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
if ( err )
2008-10-11 14:16:25 -05:00
{
2012-11-20 10:37:25 +01:00
WorldPacket data ;
sBattlegroundMgr -> BuildStatusFailedPacket ( & data , bg , _player , 0 , err );
2008-10-11 14:16:25 -05:00
member -> GetSession () -> SendPacket ( & data );
2012-11-20 10:37:25 +01:00
continue ;
2008-10-11 14:16:25 -05:00
}
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
// add to queue
uint32 queueSlot = member -> AddBattlegroundQueueId ( bgQueueTypeId );
2012-11-21 18:26:28 +01:00
2012-11-20 10:37:25 +01:00
// add joined time data
member -> AddBattlegroundQueueJoinTime ( bgTypeId , ginfo -> JoinTime );
2012-11-21 18:26:28 +01:00
2012-10-12 00:26:05 +02:00
WorldPacket data ; // send status packet (in queue)
2012-11-20 10:37:25 +01:00
sBattlegroundMgr -> BuildBattlegroundStatusPacket ( & data , bg , member , queueSlot , STATUS_WAIT_QUEUE , avgTime , ginfo -> JoinTime , arenatype );
member -> GetSession () -> SendPacket ( & data );
2012-11-21 18:26:28 +01:00
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( 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 (). c_str ());
2008-10-11 14:16:25 -05:00
}
2012-11-21 18:26:28 +01: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
2012-11-27 13:02:04 +01:00
void WorldSession :: HandleReportPvPAFK ( WorldPacket & recvData )
2008-10-11 14:16:25 -05:00
{
uint64 playerGuid ;
2012-08-05 19:40:30 -05:00
recvData >> 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
{
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( 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
2013-05-13 15:07:36 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "WorldSession::HandleReportPvPAFK: %s reported %s" , _player -> GetName (). c_str (), reportedPlayer -> GetName (). c_str ());
2009-10-17 15:51:44 -07:00
2008-10-11 14:16:25 -05:00
reportedPlayer -> ReportedAfkBy ( _player );
}
2012-11-21 18:25:23 +01:00
void WorldSession :: HandleRequestRatedBgInfo ( WorldPacket & recvData )
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_REQUEST_RATED_BG_INFO" );
2012-11-21 18:25:23 +01:00
uint8 unk ;
recvData >> unk ;
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_BATTLEGROUND , "WorldSession::HandleRequestRatedBgInfo: unk = %u" , unk );
2012-11-21 18:25:23 +01:00
/// @Todo: perfome research in this case
/// The unk fields are related to arenas
WorldPacket data ( SMSG_RATED_BG_STATS , 72 );
data << uint32 ( 0 ); // BgWeeklyWins20vs20
data << uint32 ( 0 ); // BgWeeklyPlayed20vs20
data << uint32 ( 0 ); // BgWeeklyPlayed15vs15
data << uint32 ( 0 );
data << uint32 ( 0 ); // BgWeeklyWins10vs10
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 ); // BgWeeklyWins15vs15
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 );
data << uint32 ( 0 ); // BgWeeklyPlayed10vs10
data << uint32 ( 0 );
data << uint32 ( 0 );
SendPacket ( & data );
}
2013-01-02 13:30:51 +01:00
void WorldSession :: HandleRequestPvpOptions ( WorldPacket & /*recvData*/ )
2012-11-21 18:25:23 +01:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_REQUEST_PVP_OPTIONS_ENABLED" );
2012-11-21 18:25:23 +01:00
/// @Todo: perfome research in this case
WorldPacket data ( SMSG_PVP_OPTIONS_ENABLED , 1 );
data . WriteBit ( 1 );
data . WriteBit ( 1 ); // WargamesEnabled
data . WriteBit ( 1 );
data . WriteBit ( 1 ); // RatedBGsEnabled
data . WriteBit ( 1 ); // RatedArenasEnabled
data . FlushBits ();
SendPacket ( & data );
}
2013-01-02 13:30:51 +01:00
void WorldSession :: HandleRequestPvpReward ( WorldPacket & /*recvData*/ )
2012-11-21 18:25:23 +01:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_REQUEST_PVP_REWARDS" );
2012-11-21 18:25:23 +01:00
_player -> SendPvpRewards ();
}
2013-01-02 13:30:51 +01:00
void WorldSession :: HandleRequestRatedBgStats ( WorldPacket & /*recvData*/ )
2012-11-21 18:25:23 +01:00
{
2013-05-21 09:55:09 +02:00
TC_LOG_DEBUG ( LOG_FILTER_NETWORKIO , "WORLD: CMSG_REQUEST_RATED_BG_STATS" );
2012-11-21 18:25:23 +01:00
WorldPacket data ( SMSG_BATTLEFIELD_RATED_INFO , 29 );
data << uint32 ( 0 ); // Reward
data << uint8 ( 3 ); // unk
data << uint32 ( 0 ); // unk
data << uint32 ( 0 ); // unk
2013-01-23 09:19:49 +01:00
data << _player -> GetCurrencyWeekCap ( CURRENCY_TYPE_CONQUEST_META_RBG , true );
2012-11-21 18:25:23 +01:00
data << uint32 ( 0 ); // unk
data << uint32 ( 0 ); // unk
data << _player -> GetCurrency ( CURRENCY_TYPE_CONQUEST_POINTS , true );
SendPacket ( & data );
2012-11-27 14:15:12 +01:00
}