From d3cf388bd72fb25b18c533f5e8ea71cf86bb216b Mon Sep 17 00:00:00 2001 From: hondacrx Date: Mon, 30 May 2022 14:41:19 -0400 Subject: [PATCH] Core/Misc: Verify LFG role selections by class Port From (https://github.com/TrinityCore/TrinityCore/commit/90b4c5afa22715cf2d73f727cbc20c4b667a2769) --- Source/Game/DungeonFinding/LFGManager.cs | 29 +++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Source/Game/DungeonFinding/LFGManager.cs b/Source/Game/DungeonFinding/LFGManager.cs index cfd7a3e43..4be551ae8 100644 --- a/Source/Game/DungeonFinding/LFGManager.cs +++ b/Source/Game/DungeonFinding/LFGManager.cs @@ -357,13 +357,14 @@ namespace Game.DungeonFinding if (!player || player.GetSession() == null || dungeons.Empty()) return; + // Sanitize input roles + roles &= LfgRoles.Any; + roles = FilterClassRoles(player, roles); + // At least 1 role must be selected if ((roles & (LfgRoles.Tank | LfgRoles.Healer | LfgRoles.Damage)) == 0) return; - // Sanitize input roles - roles &= LfgRoles.Any; - Group grp = player.GetGroup(); ObjectGuid guid = player.GetGUID(); ObjectGuid gguid = grp ? grp.GetGUID() : guid; @@ -679,6 +680,15 @@ namespace Game.DungeonFinding // Sanitize input roles roles &= LfgRoles.Any; + if (!guid.IsEmpty()) + { + Player player = Global.ObjAccessor.FindPlayer(guid); + if (player != null) + roles = FilterClassRoles(player, roles); + else + return; + } + bool sendRoleChosen = roleCheck.state != LfgRoleCheckState.Default && !guid.IsEmpty(); if (guid.IsEmpty()) @@ -1779,6 +1789,19 @@ namespace Game.DungeonFinding return PlayersStore[guid].GetTeam(); } + LfgRoles FilterClassRoles(Player player, LfgRoles roles) + { + uint allowedRoles = (uint)LfgRoles.Leader; + for (uint i = 0; i < PlayerConst.MaxSpecializations; ++i) + { + var specialization = Global.DB2Mgr.GetChrSpecializationByIndex(player.GetClass(), i); + if (specialization != null) + allowedRoles |= (1u << (specialization.Role + 1)); + } + + return roles & (LfgRoles)allowedRoles; + } + public byte RemovePlayerFromGroup(ObjectGuid gguid, ObjectGuid guid) { return GroupsStore[gguid].RemovePlayer(guid);