Core/Misc: Verify LFG role selections by class

Port From (https://github.com/TrinityCore/TrinityCore/commit/90b4c5afa22715cf2d73f727cbc20c4b667a2769)
This commit is contained in:
hondacrx
2022-05-30 14:41:19 -04:00
parent 972d48173d
commit d3cf388bd7
+26 -3
View File
@@ -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);