|
1 | 1 | using LBPUnion.ProjectLighthouse.Configuration; |
| 2 | +using LBPUnion.ProjectLighthouse.Configuration.ConfigurationCategories; |
| 3 | +using LBPUnion.ProjectLighthouse.Types.Entities.Token; |
| 4 | +using LBPUnion.ProjectLighthouse.Types.Users; |
2 | 5 |
|
3 | 6 | namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Helpers; |
4 | 7 |
|
5 | 8 | public static class PatchworkHelper |
6 | 9 | { |
7 | | - static int patchworkMajorVer = ServerConfiguration.Instance.PatchworkMajorVersionMinimum; |
8 | | - static int patchworkMinorVer = ServerConfiguration.Instance.PatchworkMinorVersionMinimum; |
9 | | - public static bool UserHasValidPatchworkUserAgent(string userAgent) |
| 10 | + static int patchworkMajorVer = ServerConfiguration.Instance.Authentication.PatchworkMajorVersionMinimum; |
| 11 | + static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; |
| 12 | + public static bool UserHasValidPatchworkUserAgent(GameTokenEntity token, string userAgent) |
10 | 13 | { |
11 | 14 | string userAgentPrefix = "PatchworkLBP"; |
12 | 15 | char gameVersion = userAgent[userAgentPrefix.Length]; |
| 16 | + int numericVersion = 0; |
13 | 17 |
|
14 | 18 | if (userAgent.StartsWith(userAgentPrefix)) |
15 | 19 | return false; |
16 | 20 |
|
17 | | - if (gameVersion is not '1' or '2' or '3' or 'V') |
| 21 | + if (char.IsLetterOrDigit(gameVersion)) |
| 22 | + { |
| 23 | + if (gameVersion == 'V') |
| 24 | + numericVersion = 4; |
| 25 | + } |
| 26 | + else |
| 27 | + numericVersion = gameVersion - '0'; |
| 28 | + |
| 29 | + // Don't want it to be 0 still because of Unknown (-1) in GameVersion |
| 30 | + if (numericVersion == 0) |
| 31 | + return false; |
| 32 | + |
| 33 | + if (numericVersion - 1 != (int)token.GameVersion && !Enum.IsDefined(typeof(GameVersion), numericVersion)) |
18 | 34 | return false; |
19 | 35 |
|
20 | 36 | string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); |
|
0 commit comments