Don't dequeue a color when none are available

This commit is contained in:
miniduikboot committed 2024-04-04 20:10:23 +02:00
1 parent ba9eeb5bb4
commit bdd65e9e9f
1 file changed
+19 -17
@@ -713,29 +713,31 @@ namespace Impostor.Server.Net.Inner.Objects
}
else
{
if (!RequestedColorId.Any())
if (RequestedColorId.Any())
{
var expected = RequestedColorId.Dequeue();
while (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.CurrentOutfit.Color == expected))
{
expected = (ColorType)(((byte)expected + 1) % ColorsCount);
}
if (color != expected)
{
if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client sent SetColor with incorrect color"))
{
await SetColorAsync(expected);
return false;
}
}
}
else
{
if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client sent SetColor for a player that didn't request it"))
{
return false;
}
}
var expected = RequestedColorId.Dequeue();
while (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.CurrentOutfit.Color == expected))
{
expected = (ColorType)(((byte)expected + 1) % ColorsCount);
}
if (color != expected)
{
if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client sent SetColor with incorrect color"))
{
await SetColorAsync(expected);
return false;
}
}
}
PlayerInfo.CurrentOutfit.Color = color;