-
Notifications
You must be signed in to change notification settings - Fork 56
Implement checking for the Patchwork user agent #1090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
68dbf50
Implement checking for the Patchwork user agent, move logout into sta…
FeTetra 0c8ff50
Quick fixes (awesome name)
FeTetra b84bf02
403 user at login instead of logging out at /announce
FeTetra 63b61d8
Move configuration and revert logout changes
FeTetra b77b7b3
Rework parsing to check against GameVersion enum and game token GameV…
FeTetra bab8a0f
Fix logic error
FeTetra ef5bfd4
Fix Zaprit suggestions
FeTetra c29eb38
Fix Zaprit suggestions
FeTetra b838d80
Simplify patchwork game version test
FeTetra e6c75d2
Test patchwork user agent with regex instead
FeTetra f681ef3
Fix Qodana warnings
FeTetra d90b4d2
Fix remaining Qodana warnings
FeTetra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
ProjectLighthouse.Servers.GameServer/Helpers/PatchworkHelper.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| 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.Authentication.PatchworkMajorVersionMinimum; | ||
| static int patchworkMinorVer = ServerConfiguration.Instance.Authentication.PatchworkMinorVersionMinimum; | ||
| public static bool UserHasValidPatchworkUserAgent(GameTokenEntity token, string userAgent) | ||
FeTetra marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| string userAgentPrefix = "PatchworkLBP"; | ||
| char gameVersion = userAgent[userAgentPrefix.Length]; | ||
| int numericVersion = 0; | ||
|
|
||
| if (userAgent.StartsWith(userAgentPrefix)) | ||
| return false; | ||
|
|
||
| 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 - 1)) | ||
| return false; | ||
|
|
||
| string[] patchworkVer = userAgent.Split(' ')[1].Split('.'); | ||
| if (int.Parse(patchworkVer[0]) >= patchworkMajorVer && int.Parse(patchworkVer[1]) >= patchworkMinorVer) | ||
| return true; | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.