From f681ef3ba73f7dbd9061a67217a3d8cf7dcfc611 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Mon, 26 May 2025 23:26:15 -0400 Subject: [PATCH] Fix Qodana warnings --- .../Helpers/PatchworkHelper.cs | 17 +++++++++-------- .../{Helpers => }/PatchworkUserAgentTests.cs | 3 +-- 2 files changed, 10 insertions(+), 10 deletions(-) rename ProjectLighthouse.Tests.GameApiTests/Unit/{Helpers => }/PatchworkUserAgentTests.cs (94%) diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index b981e050..2723573c 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -3,21 +3,22 @@ using System.Text.RegularExpressions; namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; -public static class PatchworkHelper +public static partial class PatchworkHelper { - static int requiredMajor = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; - static int requiredMinor = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; + static readonly int requiredMajor = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; + static readonly int requiredMinor = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; + + [GeneratedRegex(@"^PatchworkLBP[123V] (\d{1,5})\.(\d{1,5})$")] + private static partial Regex PatchworkUserAgentRegex(); + public static bool IsValidPatchworkUserAgent(string userAgent) { - Match result = Regex.Match(userAgent, @"^PatchworkLBP[123V] (\d{1,5})\.(\d{1,5})$"); + Match result = PatchworkUserAgentRegex().Match(userAgent); if (!result.Success) return false; if (!int.TryParse(result.Groups[1].Value, out int major) || !int.TryParse(result.Groups[2].Value, out int minor)) return false; - if (major < requiredMajor || minor < requiredMinor) - return false; - - return true; + return major >= requiredMajor && minor >= requiredMinor; } } \ No newline at end of file diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs similarity index 94% rename from ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs rename to ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs index 786082a3..b5658f73 100644 --- a/ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs @@ -1,8 +1,7 @@ -using System; using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using Xunit; -namespace ProjectLighthouse.Tests.GameApiTests.Unit.Helpers; +namespace ProjectLighthouse.Tests.GameApiTests.Unit; [Trait("Category", "Unit")] public class PatchworkUserAgentTests