From 68dbf5025385addeb572ebec1963cc851f64c81d Mon Sep 17 00:00:00 2001 From: FeTetra Date: Sun, 25 May 2025 20:10:26 -0400 Subject: [PATCH 01/11] Implement checking for the Patchwork user agent, move logout into standalone method --- .../Controllers/Login/LoginController.cs | 6 +++++- .../Controllers/Login/LogoutController.cs | 7 ++----- .../Controllers/MessageController.cs | 20 ++++++++++++++++++- .../Helpers/LogoutHelper.cs | 18 +++++++++++++++++ .../Helpers/PatchworkHelper.cs | 20 +++++++++++++++++++ .../Configuration/ServerConfiguration.cs | 7 ++++++- .../Types/Entities/Profile/UserEntity.cs | 2 ++ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs create mode 100644 ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index 077f1b00..827f9384 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -214,7 +214,11 @@ public class LoginController : ControllerBase Logger.Success($"Successfully logged in user {user.Username} as {token.GameVersion} client", LogArea.Login); - user.LastLogin = TimeHelper.TimestampMillis; + string userAgent = this.Request.Headers.UserAgent.ToString(); + if (!String.IsNullOrWhiteSpace(userAgent)) + { + user.UserAgent = userAgent; + } await database.SaveChangesAsync(); diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs index 89140f71..2003dc6a 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs @@ -1,6 +1,6 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; -using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; using Microsoft.AspNetCore.Authorization; @@ -30,10 +30,7 @@ public class LogoutController : ControllerBase UserEntity? user = await this.database.UserFromGameToken(token); if (user == null) return this.Forbid(); - user.LastLogout = TimeHelper.TimestampMillis; - - await this.database.GameTokens.RemoveWhere(t => t.TokenId == token.TokenId); - await this.database.LastContacts.RemoveWhere(c => c.UserId == token.UserId); + await LogoutHelper.Logout(token, user, database); return this.Ok(); } diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 42b1d1b7..ec7dfaa9 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -1,4 +1,5 @@ -using System.Text; +using System.Globalization; +using System.Text; using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; @@ -7,6 +8,7 @@ using LBPUnion.ProjectLighthouse.Localization; using LBPUnion.ProjectLighthouse.Localization.StringLists; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Serialization; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using LBPUnion.ProjectLighthouse.Types.Entities.Notifications; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; @@ -54,6 +56,10 @@ along with this program. If not, see ."; public async Task Announce() { GameTokenEntity token = this.GetToken(); + UserEntity? user = await this.database.UserFromGameToken(token); + + if (user == null) + return this.Forbid(); string username = await this.database.UsernameFromGameToken(token); @@ -67,6 +73,18 @@ along with this program. If not, see ."; announceText.Insert(0, BaseLayoutStrings.ReadOnlyWarn.Translate(LocalizationManager.DefaultLang) + "\n\n"); } + if (ServerConfiguration.Instance.RequirePatchworkUserAgent) + { + announceText.Append("This server instance requires the use of the Patchwork plugin for LBP.\n\n"); + + if (PatchworkHelper.userHasValidPatchworkUserAgent(user.UserAgent)) + { + announceText.Append("It appears you do not have the Patchwork plugin installed correctly." + + "Since this server instance requires it, you will not be able to play until you so."); + } + await LogoutHelper.Logout(token, user, database); + } + #if DEBUG announceText.Append("\n\n---DEBUG INFO---\n" + $"user.UserId: {token.UserId}\n" + diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs new file mode 100644 index 00000000..545aef94 --- /dev/null +++ b/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs @@ -0,0 +1,18 @@ +using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Database; +using LBPUnion.ProjectLighthouse.Extensions; +using LBPUnion.ProjectLighthouse.Types.Entities.Token; +using LBPUnion.ProjectLighthouse.Types.Entities.Profile; + +namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; + +public class LogoutHelper +{ + public static async Task Logout(GameTokenEntity token, UserEntity user, DatabaseContext database) + { + user.LastLogout = TimeHelper.TimestampMillis; + + await database.GameTokens.RemoveWhere(t => t.TokenId == token.TokenId); + await database.LastContacts.RemoveWhere(c => c.UserId == token.UserId); + } +} \ No newline at end of file diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs new file mode 100644 index 00000000..3438cade --- /dev/null +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -0,0 +1,20 @@ +using LBPUnion.ProjectLighthouse.Configuration; + +namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; + +public static class PatchworkHelper +{ + static int patchworkMajorVer = ServerConfiguration.Instance.PatchworkMajorVersionMinimum; + static int patchworkMinorVer = ServerConfiguration.Instance.PatchworkMinorVersionMinimum; + public static bool userHasValidPatchworkUserAgent(string userAgent) + { + if (userAgent.StartsWith("PatchworkLBP")) + return false; + + string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); + if (int.Parse(patchworkVer[0]) >= patchworkMajorVer && int.Parse(patchworkVer[1]) >= patchworkMinorVer) + return true; + + return false; + } +} \ No newline at end of file diff --git a/ProjectLighthouse/Configuration/ServerConfiguration.cs b/ProjectLighthouse/Configuration/ServerConfiguration.cs index ba9f7f4a..382c9d47 100644 --- a/ProjectLighthouse/Configuration/ServerConfiguration.cs +++ b/ProjectLighthouse/Configuration/ServerConfiguration.cs @@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase // This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly. // If you are modifying anything here, this value MUST be incremented. // Thanks for listening~ - public override int ConfigVersion { get; set; } = 27; + public override int ConfigVersion { get; set; } = 28; public override string ConfigName { get; set; } = "lighthouse.yml"; public string WebsiteListenUrl { get; set; } = "http://localhost:10060"; @@ -32,6 +32,11 @@ public class ServerConfiguration : ConfigurationBase public bool LogChatFiltering { get; set; } = false; public bool LogChatMessages { get; set; } = false; + // Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server + // Major and minor version minimums can be left alone if patchwork is not required + public bool RequirePatchworkUserAgent { get; set; } = false; + public int PatchworkMajorVersionMinimum { get; set; } = 0; + public int PatchworkMinorVersionMinimum { get; set; } = 0; public AuthenticationConfiguration Authentication { get; set; } = new(); public CaptchaConfiguration Captcha { get; set; } = new(); public DigestKeyConfiguration DigestKey { get; set; } = new(); diff --git a/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs b/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs index 6fb65301..c1615705 100644 --- a/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs +++ b/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs @@ -28,6 +28,8 @@ public class UserEntity public string IconHash { get; set; } + public string UserAgent { get; set;} + /// /// Markup that displays the username next to a polaroid with the user's icon. /// This can be used everywhere markup works ingame, e.g. news or notifications From 0c8ff50176626b81b5c68276cf0632644e965cd9 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Sun, 25 May 2025 22:10:31 -0400 Subject: [PATCH 02/11] Quick fixes (awesome name) --- .../Controllers/Login/LoginController.cs | 6 ------ .../Controllers/Login/LogoutController.cs | 3 +++ .../Controllers/MessageController.cs | 7 ++++--- .../Helpers/PatchworkHelper.cs | 10 ++++++++-- ProjectLighthouse/Types/Entities/Profile/UserEntity.cs | 2 -- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index 827f9384..f82e565b 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -214,12 +214,6 @@ public class LoginController : ControllerBase Logger.Success($"Successfully logged in user {user.Username} as {token.GameVersion} client", LogArea.Login); - string userAgent = this.Request.Headers.UserAgent.ToString(); - if (!String.IsNullOrWhiteSpace(userAgent)) - { - user.UserAgent = userAgent; - } - await database.SaveChangesAsync(); // Create a new room on LBP2/3/Vita diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs index 2003dc6a..51d2463a 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs @@ -1,6 +1,7 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; +using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; using Microsoft.AspNetCore.Authorization; @@ -32,6 +33,8 @@ public class LogoutController : ControllerBase await LogoutHelper.Logout(token, user, database); + user.LastLogin = TimeHelper.TimestampMillis; + return this.Ok(); } diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index ec7dfaa9..91397fb0 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -77,12 +77,13 @@ along with this program. If not, see ."; { announceText.Append("This server instance requires the use of the Patchwork plugin for LBP.\n\n"); - if (PatchworkHelper.userHasValidPatchworkUserAgent(user.UserAgent)) + if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) { announceText.Append("It appears you do not have the Patchwork plugin installed correctly." + - "Since this server instance requires it, you will not be able to play until you so."); + "Since this server instance requires it, you will not be able to play until you so."); + + await LogoutHelper.Logout(token, user, database); } - await LogoutHelper.Logout(token, user, database); } #if DEBUG diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index 3438cade..ca28307d 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -6,9 +6,15 @@ public static class PatchworkHelper { static int patchworkMajorVer = ServerConfiguration.Instance.PatchworkMajorVersionMinimum; static int patchworkMinorVer = ServerConfiguration.Instance.PatchworkMinorVersionMinimum; - public static bool userHasValidPatchworkUserAgent(string userAgent) + public static bool UserHasValidPatchworkUserAgent(string userAgent) { - if (userAgent.StartsWith("PatchworkLBP")) + string userAgentPrefix = "PatchworkLBP"; + char gameVersion = userAgent[userAgentPrefix.Length]; + + if (userAgent.StartsWith(userAgentPrefix)) + return false; + + if (gameVersion is not '1' or '2' or '3' or 'V') return false; string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); diff --git a/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs b/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs index c1615705..6fb65301 100644 --- a/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs +++ b/ProjectLighthouse/Types/Entities/Profile/UserEntity.cs @@ -28,8 +28,6 @@ public class UserEntity public string IconHash { get; set; } - public string UserAgent { get; set;} - /// /// Markup that displays the username next to a polaroid with the user's icon. /// This can be used everywhere markup works ingame, e.g. news or notifications From b84bf0237318483f20682fb3ad2c4c0e5878472c Mon Sep 17 00:00:00 2001 From: FeTetra Date: Sun, 25 May 2025 22:49:39 -0400 Subject: [PATCH 03/11] 403 user at login instead of logging out at /announce --- .../Controllers/Login/LoginController.cs | 8 ++++++++ .../Controllers/Login/LogoutController.cs | 6 +++--- .../Controllers/MessageController.cs | 15 --------------- .../Helpers/LogoutHelper.cs | 18 ------------------ 4 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index f82e565b..31cc050d 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -3,6 +3,7 @@ using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Tickets; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; @@ -66,6 +67,11 @@ public class LoginController : ControllerBase UserEntity? user; + if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) + { + return this.Forbid(); + } + switch (npTicket.Platform) { case Platform.RPCS3: @@ -214,6 +220,8 @@ public class LoginController : ControllerBase Logger.Success($"Successfully logged in user {user.Username} as {token.GameVersion} client", LogArea.Login); + user.LastLogin = TimeHelper.TimestampMillis; + await database.SaveChangesAsync(); // Create a new room on LBP2/3/Vita diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs index 51d2463a..029419b1 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs @@ -31,12 +31,12 @@ public class LogoutController : ControllerBase UserEntity? user = await this.database.UserFromGameToken(token); if (user == null) return this.Forbid(); - await LogoutHelper.Logout(token, user, database); + user.LastLogout = TimeHelper.TimestampMillis; - user.LastLogin = TimeHelper.TimestampMillis; + await this.database.GameTokens.RemoveWhere(t => t.TokenId == token.TokenId); + await this.database.LastContacts.RemoveWhere(c => c.UserId == token.UserId); return this.Ok(); } - } \ No newline at end of file diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 91397fb0..43ea5b03 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -1,4 +1,3 @@ -using System.Globalization; using System.Text; using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Database; @@ -8,7 +7,6 @@ using LBPUnion.ProjectLighthouse.Localization; using LBPUnion.ProjectLighthouse.Localization.StringLists; using LBPUnion.ProjectLighthouse.Logging; using LBPUnion.ProjectLighthouse.Serialization; -using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using LBPUnion.ProjectLighthouse.Types.Entities.Notifications; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; @@ -73,19 +71,6 @@ along with this program. If not, see ."; announceText.Insert(0, BaseLayoutStrings.ReadOnlyWarn.Translate(LocalizationManager.DefaultLang) + "\n\n"); } - if (ServerConfiguration.Instance.RequirePatchworkUserAgent) - { - announceText.Append("This server instance requires the use of the Patchwork plugin for LBP.\n\n"); - - if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) - { - announceText.Append("It appears you do not have the Patchwork plugin installed correctly." + - "Since this server instance requires it, you will not be able to play until you so."); - - await LogoutHelper.Logout(token, user, database); - } - } - #if DEBUG announceText.Append("\n\n---DEBUG INFO---\n" + $"user.UserId: {token.UserId}\n" + diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs deleted file mode 100644 index 545aef94..00000000 --- a/ProjectLighthouse.Servers.GameServer/Helpers/LogoutHelper.cs +++ /dev/null @@ -1,18 +0,0 @@ -using LBPUnion.ProjectLighthouse.Helpers; -using LBPUnion.ProjectLighthouse.Database; -using LBPUnion.ProjectLighthouse.Extensions; -using LBPUnion.ProjectLighthouse.Types.Entities.Token; -using LBPUnion.ProjectLighthouse.Types.Entities.Profile; - -namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; - -public class LogoutHelper -{ - public static async Task Logout(GameTokenEntity token, UserEntity user, DatabaseContext database) - { - user.LastLogout = TimeHelper.TimestampMillis; - - await database.GameTokens.RemoveWhere(t => t.TokenId == token.TokenId); - await database.LastContacts.RemoveWhere(c => c.UserId == token.UserId); - } -} \ No newline at end of file From 63b61d831c38944bae6c7018a3d5bbe0941ca472 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Sun, 25 May 2025 23:53:41 -0400 Subject: [PATCH 04/11] Move configuration and revert logout changes --- .../Controllers/Login/LoginController.cs | 7 +++++-- .../AuthenticationConfiguration.cs | 6 ++++++ ProjectLighthouse/Configuration/ServerConfiguration.cs | 8 +------- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index 31cc050d..be047229 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -67,9 +67,12 @@ public class LoginController : ControllerBase UserEntity? user; - if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) + if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) { - return this.Forbid(); + if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) + { + return this.Forbid(); + } } switch (npTicket.Platform) diff --git a/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs b/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs index 4c3abb36..399759c6 100644 --- a/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs +++ b/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs @@ -9,5 +9,11 @@ public class AuthenticationConfiguration public bool AllowRPCNSignup { get; set; } = true; public bool AllowPSNSignup { get; set; } = true; + + // Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server + // Major and minor version minimums can be left alone if patchwork is not required + public bool RequirePatchworkUserAgent { get; set; } = false; + public int PatchworkMajorVersionMinimum { get; set; } = 0; + public int PatchworkMinorVersionMinimum { get; set; } = 0; } \ No newline at end of file diff --git a/ProjectLighthouse/Configuration/ServerConfiguration.cs b/ProjectLighthouse/Configuration/ServerConfiguration.cs index 382c9d47..25f22cf6 100644 --- a/ProjectLighthouse/Configuration/ServerConfiguration.cs +++ b/ProjectLighthouse/Configuration/ServerConfiguration.cs @@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase // This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly. // If you are modifying anything here, this value MUST be incremented. // Thanks for listening~ - public override int ConfigVersion { get; set; } = 28; + public override int ConfigVersion { get; set; } = 29; public override string ConfigName { get; set; } = "lighthouse.yml"; public string WebsiteListenUrl { get; set; } = "http://localhost:10060"; @@ -31,12 +31,6 @@ public class ServerConfiguration : ConfigurationBase public bool CheckForUnsafeFiles { get; set; } = true; public bool LogChatFiltering { get; set; } = false; public bool LogChatMessages { get; set; } = false; - - // Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server - // Major and minor version minimums can be left alone if patchwork is not required - public bool RequirePatchworkUserAgent { get; set; } = false; - public int PatchworkMajorVersionMinimum { get; set; } = 0; - public int PatchworkMinorVersionMinimum { get; set; } = 0; public AuthenticationConfiguration Authentication { get; set; } = new(); public CaptchaConfiguration Captcha { get; set; } = new(); public DigestKeyConfiguration DigestKey { get; set; } = new(); From b77b7b3fb9b9bf09419de6bb57fd9c5e0f3ea987 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Sun, 25 May 2025 23:55:26 -0400 Subject: [PATCH 05/11] Rework parsing to check against GameVersion enum and game token GameVersion --- .../Controllers/Login/LoginController.cs | 16 ++++++------- .../Controllers/Login/LogoutController.cs | 1 - .../Helpers/PatchworkHelper.cs | 24 +++++++++++++++---- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index be047229..2d0e58ef 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -67,14 +67,6 @@ public class LoginController : ControllerBase UserEntity? user; - if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) - { - if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) - { - return this.Forbid(); - } - } - switch (npTicket.Platform) { case Platform.RPCS3: @@ -221,6 +213,14 @@ public class LoginController : ControllerBase return this.Forbid(); } + if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) + { + if (!PatchworkHelper.UserHasValidPatchworkUserAgent(token, this.Request.Headers.UserAgent.ToString())) + { + return this.Forbid(); + } + } + Logger.Success($"Successfully logged in user {user.Username} as {token.GameVersion} client", LogArea.Login); user.LastLogin = TimeHelper.TimestampMillis; diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs index 029419b1..a12f9d64 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LogoutController.cs @@ -1,6 +1,5 @@ using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Extensions; -using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Types.Entities.Profile; using LBPUnion.ProjectLighthouse.Types.Entities.Token; diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index ca28307d..4a5eaa8f 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -1,20 +1,36 @@ using LBPUnion.ProjectLighthouse.Configuration; +using LBPUnion.ProjectLighthouse.Configuration.ConfigurationCategories; +using LBPUnion.ProjectLighthouse.Types.Entities.Token; +using LBPUnion.ProjectLighthouse.Types.Users; namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; public static class PatchworkHelper { - static int patchworkMajorVer = ServerConfiguration.Instance.PatchworkMajorVersionMinimum; - static int patchworkMinorVer = ServerConfiguration.Instance.PatchworkMinorVersionMinimum; - public static bool UserHasValidPatchworkUserAgent(string userAgent) + static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; + static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; + public static bool UserHasValidPatchworkUserAgent(GameTokenEntity token, string userAgent) { string userAgentPrefix = "PatchworkLBP"; char gameVersion = userAgent[userAgentPrefix.Length]; + int numericVersion = 0; if (userAgent.StartsWith(userAgentPrefix)) return false; - if (gameVersion is not '1' or '2' or '3' or 'V') + if (char.IsLetterOrDigit(gameVersion)) + { + if (gameVersion == 'V') + numericVersion = 4; + } + else + numericVersion = gameVersion - '0'; + + // Don't want it to be 0 still because of Unknown (-1) in GameVersion + if (numericVersion == 0) + return false; + + if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion)) return false; string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); From bab8a0f10bb12e62be7daa6e6061e551e3d6275c Mon Sep 17 00:00:00 2001 From: FeTetra <166051662+FeTetra@users.noreply.github.com> Date: Mon, 26 May 2025 08:06:38 -0400 Subject: [PATCH 06/11] Fix logic error oopsie --- ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index 4a5eaa8f..25dfceac 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -30,7 +30,7 @@ public static class PatchworkHelper if (numericVersion == 0) return false; - if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion)) + if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion - 1)) return false; string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); From ef5bfd47eb70c96a3175a7848c00c3dc5a75bada Mon Sep 17 00:00:00 2001 From: FeTetra Date: Mon, 26 May 2025 18:27:00 -0400 Subject: [PATCH 07/11] Fix Zaprit suggestions --- .../Controllers/Login/LoginController.cs | 2 +- .../Controllers/MessageController.cs | 4 ---- .../Helpers/PatchworkHelper.cs | 7 ++----- .../ConfigurationCategories/AuthenticationConfiguration.cs | 2 +- ProjectLighthouse/Configuration/ServerConfiguration.cs | 2 +- 5 files changed, 5 insertions(+), 12 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index 2d0e58ef..f981cf34 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -215,7 +215,7 @@ public class LoginController : ControllerBase if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) { - if (!PatchworkHelper.UserHasValidPatchworkUserAgent(token, this.Request.Headers.UserAgent.ToString())) + if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) { return this.Forbid(); } diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs index 43ea5b03..cccc9b48 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/MessageController.cs @@ -54,10 +54,6 @@ along with this program. If not, see ."; public async Task Announce() { GameTokenEntity token = this.GetToken(); - UserEntity? user = await this.database.UserFromGameToken(token); - - if (user == null) - return this.Forbid(); string username = await this.database.UsernameFromGameToken(token); diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index 4a5eaa8f..6b39ebe7 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -9,7 +9,7 @@ public static class PatchworkHelper { static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; - public static bool UserHasValidPatchworkUserAgent(GameTokenEntity token, string userAgent) + public static bool UserHasValidPatchworkUserAgent(string userAgent) { string userAgentPrefix = "PatchworkLBP"; char gameVersion = userAgent[userAgentPrefix.Length]; @@ -27,10 +27,7 @@ public static class PatchworkHelper numericVersion = gameVersion - '0'; // Don't want it to be 0 still because of Unknown (-1) in GameVersion - if (numericVersion == 0) - return false; - - if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion)) + if (numericVersion - 1 == 0 || !Enum.IsDefined(typeof(GameVersion), numericVersion)) return false; string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); diff --git a/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs b/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs index 399759c6..057485ec 100644 --- a/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs +++ b/ProjectLighthouse/Configuration/ConfigurationCategories/AuthenticationConfiguration.cs @@ -13,7 +13,7 @@ public class AuthenticationConfiguration // Require use of Zaprit's "Patchwork" prx plugin's user agent when connecting to the server // Major and minor version minimums can be left alone if patchwork is not required public bool RequirePatchworkUserAgent { get; set; } = false; - public int PatchworkMajorVersionMinimum { get; set; } = 0; + public int PatchworkMajorVersionMinimum { get; set; } = 1; public int PatchworkMinorVersionMinimum { get; set; } = 0; } \ No newline at end of file diff --git a/ProjectLighthouse/Configuration/ServerConfiguration.cs b/ProjectLighthouse/Configuration/ServerConfiguration.cs index 25f22cf6..d9c66dee 100644 --- a/ProjectLighthouse/Configuration/ServerConfiguration.cs +++ b/ProjectLighthouse/Configuration/ServerConfiguration.cs @@ -11,7 +11,7 @@ public class ServerConfiguration : ConfigurationBase // This is so Lighthouse can properly identify outdated configurations and update them with newer settings accordingly. // If you are modifying anything here, this value MUST be incremented. // Thanks for listening~ - public override int ConfigVersion { get; set; } = 29; + public override int ConfigVersion { get; set; } = 30; public override string ConfigName { get; set; } = "lighthouse.yml"; public string WebsiteListenUrl { get; set; } = "http://localhost:10060"; From b838d805e2f31df4e7421115d02a7ddc153912ef Mon Sep 17 00:00:00 2001 From: FeTetra Date: Mon, 26 May 2025 19:54:33 -0400 Subject: [PATCH 08/11] Simplify patchwork game version test --- .../Helpers/PatchworkHelper.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index c1ff0641..f0f5aaed 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -1,5 +1,4 @@ using LBPUnion.ProjectLighthouse.Configuration; -using LBPUnion.ProjectLighthouse.Types.Users; namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; @@ -11,27 +10,24 @@ public static class PatchworkHelper { string userAgentPrefix = "PatchworkLBP"; char gameVersion = userAgent[userAgentPrefix.Length]; - int numericVersion = 0; - if (userAgent.StartsWith(userAgentPrefix)) + if (!userAgent.StartsWith(userAgentPrefix)) return false; - if (char.IsLetterOrDigit(gameVersion)) - { - if (gameVersion == 'V') - numericVersion = 4; + switch (gameVersion) { + case '1': + case '2': + case '3': + case 'V': + break; + default: + return false; } - else - numericVersion = gameVersion - '0'; - - // Don't want it to be 0 still because of Unknown (-1) in GameVersion - if (numericVersion - 1 == 0 || !Enum.IsDefined(typeof(GameVersion), numericVersion)) - return false; string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); - if (int.Parse(patchworkVer[0]) >= patchworkMajorVer && int.Parse(patchworkVer[1]) >= patchworkMinorVer) - return true; + if (int.Parse(patchworkVer[0]) !>= patchworkMajorVer || int.Parse(patchworkVer[1]) !>= patchworkMinorVer) + return false; - return false; + return true; } } \ No newline at end of file From e6c75d2b8671ff6041c73d50bed7522ae3dcc7df Mon Sep 17 00:00:00 2001 From: FeTetra Date: Mon, 26 May 2025 22:34:11 -0400 Subject: [PATCH 09/11] Test patchwork user agent with regex instead --- .../Controllers/Login/LoginController.cs | 2 +- .../Helpers/PatchworkHelper.cs | 26 ++++------- .../Unit/Helpers/PatchworkUserAgentTests.cs | 45 +++++++++++++++++++ 3 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs diff --git a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs index f981cf34..000b84aa 100644 --- a/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs +++ b/ProjectLighthouse.Servers.GameServer/Controllers/Login/LoginController.cs @@ -215,7 +215,7 @@ public class LoginController : ControllerBase if (ServerConfiguration.Instance.Authentication.RequirePatchworkUserAgent) { - if (!PatchworkHelper.UserHasValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) + if (!PatchworkHelper.IsValidPatchworkUserAgent(this.Request.Headers.UserAgent.ToString())) { return this.Forbid(); } diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index f0f5aaed..b981e050 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -1,31 +1,21 @@ using LBPUnion.ProjectLighthouse.Configuration; +using System.Text.RegularExpressions; namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; public static class PatchworkHelper { - static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; - static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; - public static bool UserHasValidPatchworkUserAgent(string userAgent) + static int requiredMajor = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; + static int requiredMinor = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; + public static bool IsValidPatchworkUserAgent(string userAgent) { - string userAgentPrefix = "PatchworkLBP"; - char gameVersion = userAgent[userAgentPrefix.Length]; + Match result = Regex.Match(userAgent, @"^PatchworkLBP[123V] (\d{1,5})\.(\d{1,5})$"); + if (!result.Success) return false; - if (!userAgent.StartsWith(userAgentPrefix)) + if (!int.TryParse(result.Groups[1].Value, out int major) || !int.TryParse(result.Groups[2].Value, out int minor)) return false; - switch (gameVersion) { - case '1': - case '2': - case '3': - case 'V': - break; - default: - return false; - } - - string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); - if (int.Parse(patchworkVer[0]) !>= patchworkMajorVer || int.Parse(patchworkVer[1]) !>= patchworkMinorVer) + if (major < requiredMajor || minor < requiredMinor) return false; return true; diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs new file mode 100644 index 00000000..786082a3 --- /dev/null +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/Helpers/PatchworkUserAgentTests.cs @@ -0,0 +1,45 @@ +using System; +using LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; +using Xunit; + +namespace ProjectLighthouse.Tests.GameApiTests.Unit.Helpers; + +[Trait("Category", "Unit")] +public class PatchworkUserAgentTests +{ + [Fact] + public void CanValidatePatchworkUserAgents() + { + string[] validUserAgents = { + "PatchworkLBP1 1.0", + "PatchworkLBP2 2.0", + "PatchworkLBP3 3.0", + "PatchworkLBPV 4.0", + "PatchworkLBP1 1.5", + }; + + string[] invalidUserAgents = { + // Matching + "patchworklbp1 1.0", // Case sensitive + "ptchwrklbp1 1.0", // Misspelled + "PatchworkLBP1 1", // Missing major/minor + "PatchworkLBP1 1.000001", // Major/minor too long + + // Data + "PatchworkLBP1 0.5", // Version number too low + "PatchworkLBP1 A.0" // Int cannot be parsed + }; + + bool result; + for (int i = 0; i < validUserAgents.Length; i++) + { + result = PatchworkHelper.IsValidPatchworkUserAgent(validUserAgents[i]); + Assert.True(result, $"Valid user agent: \"{validUserAgents[i]}\" was evaluated as {result}."); + } + for (int i = 0; i < invalidUserAgents.Length; i++) + { + result = PatchworkHelper.IsValidPatchworkUserAgent(invalidUserAgents[i]); + Assert.False(result, $"Invalid user agent: \"{invalidUserAgents[i]}\" was evaluated as {result}."); + } + } +} \ No newline at end of file From f681ef3ba73f7dbd9061a67217a3d8cf7dcfc611 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Mon, 26 May 2025 23:26:15 -0400 Subject: [PATCH 10/11] 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 From d90b4d293a89cb9bcee1e996c4ac8aa157330616 Mon Sep 17 00:00:00 2001 From: FeTetra Date: Tue, 3 Jun 2025 16:42:18 -0400 Subject: [PATCH 11/11] Fix remaining Qodana warnings --- .../Helpers/PatchworkHelper.cs | 4 ++-- .../Unit/PatchworkUserAgentTests.cs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs index 2723573c..3a7f604f 100644 --- a/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs +++ b/ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs @@ -5,8 +5,8 @@ namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; public static partial class PatchworkHelper { - static readonly int requiredMajor = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; - static readonly int requiredMinor = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; + private static readonly int requiredMajor = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; + private static readonly int requiredMinor = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; [GeneratedRegex(@"^PatchworkLBP[123V] (\d{1,5})\.(\d{1,5})$")] private static partial Regex PatchworkUserAgentRegex(); diff --git a/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs b/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs index b5658f73..5567fc91 100644 --- a/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs +++ b/ProjectLighthouse.Tests.GameApiTests/Unit/PatchworkUserAgentTests.cs @@ -30,15 +30,15 @@ public class PatchworkUserAgentTests }; bool result; - for (int i = 0; i < validUserAgents.Length; i++) + foreach (string userAgent in validUserAgents) { - result = PatchworkHelper.IsValidPatchworkUserAgent(validUserAgents[i]); - Assert.True(result, $"Valid user agent: \"{validUserAgents[i]}\" was evaluated as {result}."); + result = PatchworkHelper.IsValidPatchworkUserAgent(userAgent); + Assert.True(result, $"Valid user agent: \"{userAgent}\" was evaluated as {result}."); } - for (int i = 0; i < invalidUserAgents.Length; i++) + foreach (string userAgent in invalidUserAgents) { - result = PatchworkHelper.IsValidPatchworkUserAgent(invalidUserAgents[i]); - Assert.False(result, $"Invalid user agent: \"{invalidUserAgents[i]}\" was evaluated as {result}."); + result = PatchworkHelper.IsValidPatchworkUserAgent(userAgent); + Assert.False(result, $"Invalid user agent: \"{userAgent}\" was evaluated as {result}."); } } } \ No newline at end of file