From: miniduikboot Date: Wed, 3 Apr 2024 19:18:08 +0000 (+0200) Subject: Rework Color calculation loop to always terminate X-Git-Tag: v1.9.2~7^2 X-Git-Url: https://git.deb.at/?a=commitdiff_plain;h=1a11b5f43ea026af66366431c49852975addf69c;p=rhonda%2Fimpostor.git Rework Color calculation loop to always terminate --- diff --git a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs index 5a7fbac..3426317 100644 --- a/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs +++ b/src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs @@ -717,9 +717,23 @@ namespace Impostor.Server.Net.Inner.Objects { var expected = RequestedColorId.Dequeue(); - while (Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.CurrentOutfit.Color == expected)) + for (var colorOffset = 0; colorOffset <= ColorsCount; colorOffset++) { - expected = (ColorType)(((byte)expected + 1) % ColorsCount); + var possibleColor = (ColorType)((byte)(expected + colorOffset) % ColorsCount); + if (!Game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.CurrentOutfit.Color == possibleColor)) + { + expected = possibleColor; + break; + } + + if (colorOffset == ColorsCount) + { + if (await sender.Client.ReportCheatAsync(RpcCalls.SetColor, CheatCategory.GameFlow, "Client sent SetColor but all colors are already in use")) + { + await SetColorAsync(expected); + return false; + } + } } if (color != expected)