]> git.deb.at Git - rhonda/impostor.git/commitdiff
Rework Color calculation loop to always terminate
authorminiduikboot <mini@duikbo.at>
Wed, 3 Apr 2024 19:18:08 +0000 (21:18 +0200)
committerminiduikboot <mini@duikbo.at>
Thu, 4 Apr 2024 18:12:44 +0000 (20:12 +0200)
src/Impostor.Server/Net/Inner/Objects/InnerPlayerControl.cs

index 5a7fbac34218c6ce18ae368d5921605ef61c86f6..34263178d8f53b0f99fe2af48850dbeec0cedeb5 100644 (file)
@@ -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)