// create a new Battleground that will really be used to play public Battleground CreateNewBattleground(BattlegroundQueueTypeId queueId, PvpDifficultyRecord bracketEntry) { BattlegroundTypeId bgTypeId = GetRandomBG((BattlegroundTypeId)queueId.BattlemasterListId); // get the template BG Battleground bg_template = GetBattlegroundTemplate(bgTypeId); if (bg_template == null) { Log.outError(LogFilter.Battleground, "Battleground: CreateNewBattleground - bg template not found for {0}", bgTypeId); return(null); } if (bgTypeId == BattlegroundTypeId.RB || bgTypeId == BattlegroundTypeId.AA || bgTypeId == BattlegroundTypeId.RandomEpic) { return(null); } // create a copy of the BG template Battleground bg = bg_template.GetCopy(); bool isRandom = bgTypeId != (BattlegroundTypeId)queueId.BattlemasterListId && !bg.IsArena(); bg.SetQueueId(queueId); bg.SetBracket(bracketEntry); bg.SetInstanceID(Global.MapMgr.GenerateInstanceId()); bg.SetClientInstanceID(CreateClientVisibleInstanceId((BattlegroundTypeId)queueId.BattlemasterListId, bracketEntry.GetBracketId())); bg.Reset(); // reset the new bg (set status to status_wait_queue from status_none) bg.SetStatus(BattlegroundStatus.WaitJoin); // start the joining of the bg bg.SetArenaType((ArenaTypes)queueId.TeamSize); bg.SetRandomTypeID(bgTypeId); bg.SetRated(queueId.Rated); bg.SetRandom(isRandom); return(bg); }
// create a new Battleground that will really be used to play public Battleground CreateNewBattleground(BattlegroundTypeId originalBgTypeId, PvpDifficultyRecord bracketEntry, ArenaTypes arenaType, bool isRated) { BattlegroundTypeId bgTypeId = GetRandomBG(originalBgTypeId); // get the template BG Battleground bg_template = GetBattlegroundTemplate(bgTypeId); if (bg_template == null) { Log.outError(LogFilter.Battleground, "Battleground: CreateNewBattleground - bg template not found for {0}", bgTypeId); return(null); } if (bgTypeId == BattlegroundTypeId.RB || bgTypeId == BattlegroundTypeId.AA) { return(null); } // create a copy of the BG template Battleground bg = bg_template.GetCopy(); bool isRandom = bgTypeId != originalBgTypeId && !bg.isArena(); bg.SetBracket(bracketEntry); bg.SetInstanceID(Global.MapMgr.GenerateInstanceId()); bg.SetClientInstanceID(CreateClientVisibleInstanceId(isRandom ? BattlegroundTypeId.RB : bgTypeId, bracketEntry.GetBracketId())); bg.Reset(); // reset the new bg (set status to status_wait_queue from status_none) bg.SetStatus(BattlegroundStatus.WaitJoin); // start the joining of the bg bg.SetArenaType(arenaType); bg.SetTypeID(originalBgTypeId); bg.SetRandomTypeID(bgTypeId); bg.SetRated(isRated); bg.SetRandom(isRandom); bg.SetQueueId((ulong)bgTypeId | 0x1F10000000000000); // Set up correct min/max player counts for scoreboards if (bg.isArena()) { uint maxPlayersPerTeam = 0; switch (arenaType) { case ArenaTypes.Team2v2: maxPlayersPerTeam = 2; break; case ArenaTypes.Team3v3: maxPlayersPerTeam = 3; break; case ArenaTypes.Team5v5: maxPlayersPerTeam = 5; break; } bg.SetMaxPlayersPerTeam(maxPlayersPerTeam); bg.SetMaxPlayers(maxPlayersPerTeam * 2); } return(bg); }
void HandleBattlemasterJoin(BattlemasterJoin battlemasterJoin) { bool isPremade = false; if (battlemasterJoin.QueueIDs.Empty()) { Log.outError(LogFilter.Network, $"Battleground: no bgtype received. possible cheater? {_player.GetGUID()}"); return; } BattlegroundQueueTypeId bgQueueTypeId = BattlegroundQueueTypeId.FromPacked(battlemasterJoin.QueueIDs[0]); if (!Global.BattlegroundMgr.IsValidQueueId(bgQueueTypeId)) { Log.outError(LogFilter.Network, $"Battleground: invalid bg queue {bgQueueTypeId} received. possible cheater? {_player.GetGUID()}"); return; } BattlemasterListRecord battlemasterListEntry = CliDB.BattlemasterListStorage.LookupByKey(bgQueueTypeId.BattlemasterListId); if (Global.DisableMgr.IsDisabledFor(DisableType.Battleground, bgQueueTypeId.BattlemasterListId, null) || battlemasterListEntry.Flags.HasAnyFlag(BattlemasterListFlags.Disabled)) { GetPlayer().SendSysMessage(CypherStrings.BgDisabled); return; } BattlegroundTypeId bgTypeId = (BattlegroundTypeId)bgQueueTypeId.BattlemasterListId; // ignore if player is already in BG if (GetPlayer().InBattleground()) { return; } // get bg instance or bg template if instance not found Battleground bg = Global.BattlegroundMgr.GetBattlegroundTemplate(bgTypeId); if (!bg) { return; } // expected bracket entry PvpDifficultyRecord bracketEntry = Global.DB2Mgr.GetBattlegroundBracketByLevel(bg.GetMapId(), GetPlayer().GetLevel()); if (bracketEntry == null) { return; } GroupJoinBattlegroundResult err = GroupJoinBattlegroundResult.None; Group grp = _player.GetGroup(); BattlefieldStatusFailed battlefieldStatusFailed; // check queue conditions if (grp == null) { if (GetPlayer().IsUsingLfg()) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, GroupJoinBattlegroundResult.LfgCantUseBattleground); SendPacket(battlefieldStatusFailed); return; } // check Deserter debuff if (!GetPlayer().CanJoinToBattleground(bg)) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, GroupJoinBattlegroundResult.Deserters); SendPacket(battlefieldStatusFailed); return; } bool isInRandomBgQueue = _player.InBattlegroundQueueForBattlegroundQueueType(Global.BattlegroundMgr.BGQueueTypeId((ushort)BattlegroundTypeId.RB, BattlegroundQueueIdType.Battleground, false, 0)) || _player.InBattlegroundQueueForBattlegroundQueueType(Global.BattlegroundMgr.BGQueueTypeId((ushort)BattlegroundTypeId.RandomEpic, BattlegroundQueueIdType.Battleground, false, 0)); if (bgTypeId != BattlegroundTypeId.RB && bgTypeId != BattlegroundTypeId.RandomEpic && isInRandomBgQueue) { // player is already in random queue Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, GroupJoinBattlegroundResult.InRandomBg); SendPacket(battlefieldStatusFailed); return; } if (_player.InBattlegroundQueue() && !isInRandomBgQueue && (bgTypeId == BattlegroundTypeId.RB || bgTypeId == BattlegroundTypeId.RandomEpic)) { // player is already in queue, can't start random queue Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, GroupJoinBattlegroundResult.InNonRandomBg); SendPacket(battlefieldStatusFailed); return; } // check if already in queue if (GetPlayer().GetBattlegroundQueueIndex(bgQueueTypeId) < SharedConst.MaxPlayerBGQueues) { return; // player is already in this queue } // check if has free queue slots if (!GetPlayer().HasFreeBattlegroundQueueId()) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, GroupJoinBattlegroundResult.TooManyQueues); SendPacket(battlefieldStatusFailed); return; } // check Freeze debuff if (_player.HasAura(9454)) { return; } BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); GroupQueueInfo ginfo = bgQueue.AddGroup(GetPlayer(), null, bgTypeId, bracketEntry, 0, false, isPremade, 0, 0); uint avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); uint queueSlot = GetPlayer().AddBattlegroundQueueId(bgQueueTypeId); Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out BattlefieldStatusQueued battlefieldStatusQueued, bg, GetPlayer(), queueSlot, ginfo.JoinTime, bgQueueTypeId, avgTime, ginfo.ArenaType, false); SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, $"Battleground: player joined queue for bg queue {bgQueueTypeId}, {_player.GetGUID()}, NAME {_player.GetName()}"); } else { if (grp.GetLeaderGUID() != GetPlayer().GetGUID()) { return; } ObjectGuid errorGuid; err = grp.CanJoinBattlegroundQueue(bg, bgQueueTypeId, 0, bg.GetMaxPlayersPerTeam(), false, 0, out errorGuid); isPremade = (grp.GetMembersCount() >= bg.GetMinPlayersPerTeam()); BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); GroupQueueInfo ginfo = null; uint avgTime = 0; if (err == 0) { Log.outDebug(LogFilter.Battleground, "Battleground: the following players are joining as group:"); ginfo = bgQueue.AddGroup(GetPlayer(), grp, bgTypeId, bracketEntry, 0, false, isPremade, 0, 0); avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); } for (GroupReference refe = grp.GetFirstMember(); refe != null; refe = refe.Next()) { Player member = refe.GetSource(); if (!member) { continue; // this should never happen } if (err != 0) { BattlefieldStatusFailed battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatus, bg, GetPlayer(), 0, err, errorGuid); member.SendPacket(battlefieldStatus); continue; } // add to queue uint queueSlot = member.AddBattlegroundQueueId(bgQueueTypeId); Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out BattlefieldStatusQueued battlefieldStatusQueued, bg, member, queueSlot, ginfo.JoinTime, bgQueueTypeId, avgTime, ginfo.ArenaType, true); member.SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, $"Battleground: player joined queue for bg queue {bgQueueTypeId}, {member.GetGUID()}, NAME {member.GetName()}"); } Log.outDebug(LogFilter.Battleground, "Battleground: group end"); } Global.BattlegroundMgr.ScheduleQueueUpdate(0, bgQueueTypeId, bracketEntry.GetBracketId()); }
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((ushort)bgTypeId, BattlegroundQueueIdType.Arena, true, 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) { 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, err, errorGuid); member.SendPacket(battlefieldStatus); continue; } // add to queue uint queueSlot = member.AddBattlegroundQueueId(bgQueueTypeId); Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out BattlefieldStatusQueued battlefieldStatusQueued, bg, member, queueSlot, ginfo.JoinTime, bgQueueTypeId, avgTime, arenatype, true); member.SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, $"Battleground: player joined queue for arena as group bg queue {bgQueueTypeId}, {member.GetGUID()}, NAME {member.GetName()}"); } Global.BattlegroundMgr.ScheduleQueueUpdate(matchmakerRating, bgQueueTypeId, bracketEntry.GetBracketId()); }
void HandleRequestBattlefieldStatus(RequestBattlefieldStatus packet) { // we must update all queues here Battleground bg = null; for (byte i = 0; i < SharedConst.MaxPlayerBGQueues; ++i) { BattlegroundQueueTypeId bgQueueTypeId = GetPlayer().GetBattlegroundQueueTypeId(i); if (bgQueueTypeId == default) { continue; } BattlegroundTypeId bgTypeId = (BattlegroundTypeId)bgQueueTypeId.BattlemasterListId; ArenaTypes arenaType = (ArenaTypes)bgQueueTypeId.TeamSize; bg = _player.GetBattleground(); if (bg && bg.GetQueueId() == bgQueueTypeId) { //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 Global.BattlegroundMgr.BuildBattlegroundStatusActive(out BattlefieldStatusActive battlefieldStatus, bg, _player, i, _player.GetBattlegroundQueueJoinTime(bgQueueTypeId), arenaType); SendPacket(battlefieldStatus); continue; } //we are sending update to player about queue - he can be invited there! //get GroupQueueInfo for queue status BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); GroupQueueInfo ginfo; if (!bgQueue.GetPlayerGroupInfoData(GetPlayer().GetGUID(), out ginfo)) { continue; } if (ginfo.IsInvitedToBGInstanceGUID != 0) { bg = Global.BattlegroundMgr.GetBattleground(ginfo.IsInvitedToBGInstanceGUID, bgTypeId); if (!bg) { continue; } BattlefieldStatusNeedConfirmation battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusNeedConfirmation(out battlefieldStatus, bg, GetPlayer(), i, GetPlayer().GetBattlegroundQueueJoinTime(bgQueueTypeId), Time.GetMSTimeDiff(Time.GetMSTime(), ginfo.RemoveInviteTime), arenaType); SendPacket(battlefieldStatus); } else { bg = Global.BattlegroundMgr.GetBattlegroundTemplate(bgTypeId); if (!bg) { continue; } // expected bracket entry PvpDifficultyRecord bracketEntry = Global.DB2Mgr.GetBattlegroundBracketByLevel(bg.GetMapId(), GetPlayer().GetLevel()); if (bracketEntry == null) { continue; } uint avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); BattlefieldStatusQueued battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out battlefieldStatus, bg, GetPlayer(), i, GetPlayer().GetBattlegroundQueueJoinTime(bgQueueTypeId), bgQueueTypeId, avgTime, arenaType, ginfo.Players.Count > 1); SendPacket(battlefieldStatus); } } }
void HandleBattleFieldPort(BattlefieldPort battlefieldPort) { if (!GetPlayer().InBattlegroundQueue()) { Log.outDebug(LogFilter.Battleground, "CMSG_BATTLEFIELD_PORT {0} Slot: {1}, Unk: {2}, Time: {3}, AcceptedInvite: {4}. Player not in queue!", GetPlayerInfo(), battlefieldPort.Ticket.Id, battlefieldPort.Ticket.Type, battlefieldPort.Ticket.Time, battlefieldPort.AcceptedInvite); return; } BattlegroundQueueTypeId bgQueueTypeId = GetPlayer().GetBattlegroundQueueTypeId(battlefieldPort.Ticket.Id); if (bgQueueTypeId == default) { Log.outDebug(LogFilter.Battleground, "CMSG_BATTLEFIELD_PORT {0} Slot: {1}, Unk: {2}, Time: {3}, AcceptedInvite: {4}. Invalid queueSlot!", GetPlayerInfo(), battlefieldPort.Ticket.Id, battlefieldPort.Ticket.Type, battlefieldPort.Ticket.Time, battlefieldPort.AcceptedInvite); return; } BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); //we must use temporary variable, because GroupQueueInfo pointer can be deleted in BattlegroundQueue.RemovePlayer() function GroupQueueInfo ginfo; if (!bgQueue.GetPlayerGroupInfoData(GetPlayer().GetGUID(), out ginfo)) { Log.outDebug(LogFilter.Battleground, "CMSG_BATTLEFIELD_PORT {0} Slot: {1}, Unk: {2}, Time: {3}, AcceptedInvite: {4}. Player not in queue (No player Group Info)!", GetPlayerInfo(), battlefieldPort.Ticket.Id, battlefieldPort.Ticket.Type, battlefieldPort.Ticket.Time, battlefieldPort.AcceptedInvite); return; } // if action == 1, then instanceId is required if (ginfo.IsInvitedToBGInstanceGUID == 0 && battlefieldPort.AcceptedInvite) { Log.outDebug(LogFilter.Battleground, "CMSG_BATTLEFIELD_PORT {0} Slot: {1}, Unk: {2}, Time: {3}, AcceptedInvite: {4}. Player is not invited to any bg!", GetPlayerInfo(), battlefieldPort.Ticket.Id, battlefieldPort.Ticket.Type, battlefieldPort.Ticket.Time, battlefieldPort.AcceptedInvite); return; } BattlegroundTypeId bgTypeId = (BattlegroundTypeId)bgQueueTypeId.BattlemasterListId; // BGTemplateId returns Battleground_AA when it is arena queue. // Do instance id search as there is no AA bg instances. Battleground bg = Global.BattlegroundMgr.GetBattleground(ginfo.IsInvitedToBGInstanceGUID, bgTypeId == BattlegroundTypeId.AA ? BattlegroundTypeId.None : bgTypeId); if (!bg) { if (battlefieldPort.AcceptedInvite) { Log.outDebug(LogFilter.Battleground, "CMSG_BATTLEFIELD_PORT {0} Slot: {1}, Unk: {2}, Time: {3}, AcceptedInvite: {4}. Cant find BG with id {5}!", GetPlayerInfo(), battlefieldPort.Ticket.Id, battlefieldPort.Ticket.Type, battlefieldPort.Ticket.Time, battlefieldPort.AcceptedInvite, ginfo.IsInvitedToBGInstanceGUID); return; } bg = Global.BattlegroundMgr.GetBattlegroundTemplate(bgTypeId); if (!bg) { Log.outError(LogFilter.Network, "BattlegroundHandler: bg_template not found for type id {0}.", bgTypeId); return; } } // get real bg type bgTypeId = bg.GetTypeID(); // expected bracket entry PvpDifficultyRecord bracketEntry = Global.DB2Mgr.GetBattlegroundBracketByLevel(bg.GetMapId(), GetPlayer().GetLevel()); if (bracketEntry == null) { return; } //some checks if player isn't cheating - it is not exactly cheating, but we cannot allow it if (battlefieldPort.AcceptedInvite && ginfo.ArenaType == 0) { //if player is trying to enter Battleground(not arena!) and he has deserter debuff, we must just remove him from queue if (!GetPlayer().CanJoinToBattleground(bg)) { // send bg command result to show nice message BattlefieldStatusFailed battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatus, bg, GetPlayer(), battlefieldPort.Ticket.Id, GroupJoinBattlegroundResult.Deserters); SendPacket(battlefieldStatus); battlefieldPort.AcceptedInvite = false; Log.outDebug(LogFilter.Battleground, "Player {0} ({1}) has a deserter debuff, do not port him to Battleground!", GetPlayer().GetName(), GetPlayer().GetGUID().ToString()); } //if player don't match Battlegroundmax level, then do not allow him to enter! (this might happen when player leveled up during his waiting in queue if (GetPlayer().GetLevel() > bg.GetMaxLevel()) { Log.outDebug(LogFilter.Network, "Player {0} ({1}) has level ({2}) higher than maxlevel ({3}) of Battleground({4})! Do not port him to Battleground!", GetPlayer().GetName(), GetPlayer().GetGUID().ToString(), GetPlayer().GetLevel(), bg.GetMaxLevel(), bg.GetTypeID()); battlefieldPort.AcceptedInvite = false; } } if (battlefieldPort.AcceptedInvite) { // check Freeze debuff if (GetPlayer().HasAura(9454)) { return; } if (!GetPlayer().IsInvitedForBattlegroundQueueType(bgQueueTypeId)) { return; // cheating? } if (!GetPlayer().InBattleground()) { GetPlayer().SetBattlegroundEntryPoint(); } // resurrect the player if (!GetPlayer().IsAlive()) { GetPlayer().ResurrectPlayer(1.0f); GetPlayer().SpawnCorpseBones(); } // stop taxi flight at port if (GetPlayer().IsInFlight()) { GetPlayer().GetMotionMaster().MovementExpired(); GetPlayer().CleanupAfterTaxiFlight(); } BattlefieldStatusActive battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusActive(out battlefieldStatus, bg, GetPlayer(), battlefieldPort.Ticket.Id, GetPlayer().GetBattlegroundQueueJoinTime(bgQueueTypeId), bg.GetArenaType()); SendPacket(battlefieldStatus); // remove BattlegroundQueue status from BGmgr bgQueue.RemovePlayer(GetPlayer().GetGUID(), false); // this is still needed here if Battleground"jumping" shouldn't add deserter debuff // also this is required to prevent stuck at old Battlegroundafter SetBattlegroundId set to new Battleground currentBg = GetPlayer().GetBattleground(); if (currentBg) { currentBg.RemovePlayerAtLeave(GetPlayer().GetGUID(), false, true); } // set the destination instance id GetPlayer().SetBattlegroundId(bg.GetInstanceID(), bgTypeId); // set the destination team GetPlayer().SetBGTeam(ginfo.Team); Global.BattlegroundMgr.SendToBattleground(GetPlayer(), ginfo.IsInvitedToBGInstanceGUID, bgTypeId); Log.outDebug(LogFilter.Battleground, $"Battleground: player {_player.GetName()} ({_player.GetGUID()}) joined battle for bg {bg.GetInstanceID()}, bgtype {bg.GetTypeID()}, queue {bgQueueTypeId}."); } 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 != 0) { ArenaTeam at = Global.ArenaTeamMgr.GetArenaTeamById((uint)ginfo.Team); if (at != null) { Log.outDebug(LogFilter.Battleground, "UPDATING memberLost's personal arena rating for {0} by opponents rating: {1}, because he has left queue!", GetPlayer().GetGUID().ToString(), ginfo.OpponentsTeamRating); at.MemberLost(GetPlayer(), ginfo.OpponentsMatchmakerRating); at.SaveToDB(); } } BattlefieldStatusNone battlefieldStatus = new BattlefieldStatusNone(); battlefieldStatus.Ticket = battlefieldPort.Ticket; SendPacket(battlefieldStatus); GetPlayer().RemoveBattlegroundQueueId(bgQueueTypeId); // must be called this way, because if you move this call to queue.removeplayer, it causes bugs bgQueue.RemovePlayer(GetPlayer().GetGUID(), true); // player left queue, we should update it - do not update Arena Queue if (ginfo.ArenaType == 0) { Global.BattlegroundMgr.ScheduleQueueUpdate(ginfo.ArenaMatchmakerRating, bgQueueTypeId, bracketEntry.GetBracketId()); } Log.outDebug(LogFilter.Battleground, $"Battleground: player {_player.GetName()} ({_player.GetGUID()}) left queue for bgtype { bg.GetTypeID()}, queue {bgQueueTypeId}."); } }
void HandleBattlemasterJoin(BattlemasterJoin battlemasterJoin) { bool isPremade = false; Group grp = null; BattlefieldStatusFailed battlefieldStatusFailed; uint bgTypeId_ = (uint)(battlemasterJoin.QueueID & 0xFFFF); if (!CliDB.BattlemasterListStorage.ContainsKey(bgTypeId_)) { Log.outError(LogFilter.Network, "Battleground: invalid bgtype ({0}) received. possible cheater? player guid {1}", bgTypeId_, GetPlayer().GetGUID().ToString()); return; } if (Global.DisableMgr.IsDisabledFor(DisableType.Battleground, bgTypeId_, null)) { GetPlayer().SendSysMessage(CypherStrings.BgDisabled); return; } BattlegroundTypeId bgTypeId = (BattlegroundTypeId)bgTypeId_; // can do this, since it's Battleground, not arena BattlegroundQueueTypeId bgQueueTypeId = Global.BattlegroundMgr.BGQueueTypeId(bgTypeId, 0); BattlegroundQueueTypeId bgQueueTypeIdRandom = Global.BattlegroundMgr.BGQueueTypeId(BattlegroundTypeId.RB, 0); // ignore if player is already in BG if (GetPlayer().InBattleground()) { return; } // get bg instance or bg template if instance not found Battleground bg = Global.BattlegroundMgr.GetBattlegroundTemplate(bgTypeId); if (!bg) { return; } // expected bracket entry PvpDifficultyRecord bracketEntry = Global.DB2Mgr.GetBattlegroundBracketByLevel(bg.GetMapId(), GetPlayer().getLevel()); if (bracketEntry == null) { return; } GroupJoinBattlegroundResult err = GroupJoinBattlegroundResult.None; // check queue conditions if (!battlemasterJoin.JoinAsGroup) { if (GetPlayer().isUsingLfg()) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, 0, GroupJoinBattlegroundResult.LfgCantUseBattleground); SendPacket(battlefieldStatusFailed); return; } // check Deserter debuff if (!GetPlayer().CanJoinToBattleground(bg)) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, 0, GroupJoinBattlegroundResult.Deserters); SendPacket(battlefieldStatusFailed); return; } if (GetPlayer().GetBattlegroundQueueIndex(bgQueueTypeIdRandom) < SharedConst.MaxPlayerBGQueues) { // player is already in random queue Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, 0, GroupJoinBattlegroundResult.InRandomBg); SendPacket(battlefieldStatusFailed); return; } if (GetPlayer().InBattlegroundQueue() && bgTypeId == BattlegroundTypeId.RB) { // player is already in queue, can't start random queue Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, 0, GroupJoinBattlegroundResult.InNonRandomBg); SendPacket(battlefieldStatusFailed); return; } // check if already in queue if (GetPlayer().GetBattlegroundQueueIndex(bgQueueTypeId) < SharedConst.MaxPlayerBGQueues) { return; // player is already in this queue } // check if has free queue slots if (!GetPlayer().HasFreeBattlegroundQueueId()) { Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatusFailed, bg, GetPlayer(), 0, 0, GroupJoinBattlegroundResult.TooManyQueues); SendPacket(battlefieldStatusFailed); return; } // check Freeze debuff if (_player.HasAura(9454)) { return; } BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); GroupQueueInfo ginfo = bgQueue.AddGroup(GetPlayer(), null, bgTypeId, bracketEntry, 0, false, isPremade, 0, 0); uint avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); uint queueSlot = GetPlayer().AddBattlegroundQueueId(bgQueueTypeId); BattlefieldStatusQueued battlefieldStatusQueued; Global.BattlegroundMgr.BuildBattlegroundStatusQueued(out battlefieldStatusQueued, bg, GetPlayer(), queueSlot, ginfo.JoinTime, avgTime, ginfo.ArenaType, false); SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, "Battleground: player joined queue for bg queue type {0} bg type {1}: GUID {2}, NAME {3}", bgQueueTypeId, bgTypeId, GetPlayer().GetGUID().ToString(), GetPlayer().GetName()); } else { grp = GetPlayer().GetGroup(); if (!grp) { return; } if (grp.GetLeaderGUID() != GetPlayer().GetGUID()) { return; } ObjectGuid errorGuid; err = grp.CanJoinBattlegroundQueue(bg, bgQueueTypeId, 0, bg.GetMaxPlayersPerTeam(), false, 0, out errorGuid); isPremade = (grp.GetMembersCount() >= bg.GetMinPlayersPerTeam()); BattlegroundQueue bgQueue = Global.BattlegroundMgr.GetBattlegroundQueue(bgQueueTypeId); GroupQueueInfo ginfo = null; uint avgTime = 0; if (err == 0) { Log.outDebug(LogFilter.Battleground, "Battleground: the following players are joining as group:"); ginfo = bgQueue.AddGroup(GetPlayer(), grp, bgTypeId, bracketEntry, 0, false, isPremade, 0, 0); avgTime = bgQueue.GetAverageQueueWaitTime(ginfo, bracketEntry.GetBracketId()); } for (GroupReference refe = grp.GetFirstMember(); refe != null; refe = refe.next()) { Player member = refe.GetSource(); if (!member) { continue; // this should never happen } if (err != 0) { BattlefieldStatusFailed battlefieldStatus; Global.BattlegroundMgr.BuildBattlegroundStatusFailed(out battlefieldStatus, bg, GetPlayer(), 0, 0, 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, ginfo.ArenaType, true); member.SendPacket(battlefieldStatusQueued); Log.outDebug(LogFilter.Battleground, "Battleground: player joined queue for bg queue type {0} bg type {1}: GUID {2}, NAME {3}", bgQueueTypeId, bgTypeId, member.GetGUID().ToString(), member.GetName()); } Log.outDebug(LogFilter.Battleground, "Battleground: group end"); } Global.BattlegroundMgr.ScheduleQueueUpdate(0, 0, bgQueueTypeId, bgTypeId, bracketEntry.GetBracketId()); }