void HandleBattlemasterJoinArena(BattlemasterJoinArena packet) { // ignore if we already in BG or BG queue if (GetPlayer().InBattleground()) { return; } ArenaTypes arenatype = (ArenaTypes)ArenaTeam.GetTypeBySlot(packet.TeamSizeIndex); //check existence Battleground bg = Global.BattlegroundMgr.GetBattlegroundTemplate(BattlegroundTypeId.AA); if (!bg) { Log.outError(LogFilter.Network, "Battleground: template bg (all arenas) not found"); return; } if (Global.DisableMgr.IsDisabledFor(DisableType.Battleground, (uint)BattlegroundTypeId.AA, null)) { GetPlayer().SendSysMessage(CypherStrings.ArenaDisabled); return; } BattlegroundTypeId bgTypeId = bg.GetTypeID(); BattlegroundQueueTypeId bgQueueTypeId = Global.BattlegroundMgr.BGQueueTypeId(bgTypeId, arenatype); PVPDifficultyRecord bracketEntry = Global.DB2Mgr.GetBattlegroundBracketByLevel(bg.GetMapId(), GetPlayer().getLevel()); if (bracketEntry == null) { return; } Group grp = GetPlayer().GetGroup(); // no group found, error if (!grp) { return; } if (grp.GetLeaderGUID() != GetPlayer().GetGUID()) { return; } uint ateamId = GetPlayer().GetArenaTeamId(packet.TeamSizeIndex); // check real arenateam existence only here (if it was moved to group.CanJoin .. () then we would ahve to get it twice) ArenaTeam at = Global.ArenaTeamMgr.GetArenaTeamById(ateamId); if (at == null) { GetPlayer().GetSession().SendNotInArenaTeamPacket(arenatype); return; } // get the team rating for queuing uint arenaRating = at.GetRating(); uint matchmakerRating = at.GetAverageMMR(grp); // the arenateam id must match for everyone in the group if (arenaRating <= 0) { arenaRating = 1; } BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); uint avgTime = 0; GroupQueueInfo ginfo = null; ObjectGuid errorGuid; var err = grp.CanJoinBattlegroundQueue(bg, bgQueueTypeId, (uint)arenatype, (uint)arenatype, true, packet.TeamSizeIndex, out errorGuid); if (err == 0) { Log.outDebug(LogFilter.Battleground, "Battleground: arena team id {0}, leader {1} queued with matchmaker rating {2} for type {3}", GetPlayer().GetArenaTeamId(packet.TeamSizeIndex), GetPlayer().GetName(), matchmakerRating, arenatype); ginfo = bgQueue.AddGroup(GetPlayer(), grp, bgTypeId, bracketEntry, arenatype, true, false, arenaRating, matchmakerRating, ateamId); avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); } for (GroupReference refe = grp.GetFirstMember(); refe != null; refe = refe.next()) { Player member = refe.GetSource(); if (!member) { continue; } if (err != 0) { BattlefieldStatusFailed battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatus, bg, GetPlayer(), 0, arenatype, err, errorGuid); member.SendPacket(battlefieldStatus); continue; } // add to queue uint queueSlot = member.AddBattlegroundQueueId(bgQueueTypeId); BattlefieldStatusQueued battlefieldStatusQueued; Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out battlefieldStatusQueued, bg, member, queueSlot, ginfo.JoinTime, avgTime, arenatype, true); member.SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, "Battleground: player joined queue for arena as group bg queue type {0} bg type {1}: GUID {2}, NAME {3}", bgQueueTypeId, bgTypeId, member.GetGUID().ToString(), member.GetName()); } Global.BattlegroundMgr.ScheduleQueueUpdate(matchmakerRating, arenatype, bgQueueTypeId, bgTypeId, bracketEntry.GetBracketId()); }