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('.');