-
Notifications
You must be signed in to change notification settings - Fork 25
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
Ability for server to override level pages #210
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c3db1d2
Fix serialization of !DeletedUser
jvyden b78b586
Add theoretical support for overriding level lists
jvyden 376fd2b
Start writing tests for overriding
jvyden 1b67c49
Merge branch 'main' into level-overriding
jvyden aae0937
Merge branch 'main' into level-overriding
jvyden 9560d8c
Merge branch 'main' into level-overriding
jvyden bf6d048
API endpoint for setting an individual level as an override
jvyden 3701a9e
fix wtf formatting
jvyden 69b8589
Add in-game command for setting a level override
jvyden 182e2eb
Don't require passing in LevelListOverrideService into cvommand invoc…
jvyden 6fe50c7
dont FUCK up
jvyden f515882
FUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUCCCCCCCCCCCCKKKKKKKKKK
jvyden 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 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 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 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 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 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 |
---|---|---|
|
@@ -6,4 +6,5 @@ public enum RefreshContext | |
Worker, | ||
Discord, | ||
PasswordReset, | ||
LevelListOverride, | ||
} |
This file contains 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 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 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,50 @@ | ||
using System.Diagnostics; | ||
using Bunkum.Core.Services; | ||
using MongoDB.Bson; | ||
using NotEnoughLogs; | ||
using Refresh.GameServer.Database; | ||
using Refresh.GameServer.Types.Levels; | ||
using Refresh.GameServer.Types.UserData; | ||
|
||
namespace Refresh.GameServer.Services; | ||
|
||
public class LevelListOverrideService : EndpointService | ||
{ | ||
public LevelListOverrideService(Logger logger) : base(logger) | ||
{} | ||
|
||
private readonly Dictionary<ObjectId, List<int>> _userIdsToLevelList = new(1); | ||
|
||
public bool UserHasOverrides(GameUser user) | ||
{ | ||
bool result = this._userIdsToLevelList.ContainsKey(user.UserId); | ||
|
||
this.Logger.LogTrace(RefreshContext.LevelListOverride, "{0} has overrides: {1}", user.Username, result); | ||
return result; | ||
} | ||
|
||
public void AddOverridesForUser(GameUser user, GameLevel level) | ||
{ | ||
this.AddOverridesForUser(user, new[] { level }); | ||
} | ||
|
||
public void AddOverridesForUser(GameUser user, IEnumerable<GameLevel> levels) | ||
{ | ||
Debug.Assert(!this.UserHasOverrides(user), "User already has overrides"); | ||
|
||
List<int> ids = levels.Select(l => l.LevelId).ToList(); | ||
this.Logger.LogDebug(RefreshContext.LevelListOverride, "Adding level override for {0}: [{1}]", user.Username, string.Join(", ", ids)); | ||
this._userIdsToLevelList.Add(user.UserId, ids); | ||
} | ||
|
||
public IEnumerable<GameLevel> GetOverridesForUser(GameUser user, GameDatabaseContext database) | ||
{ | ||
Debug.Assert(this.UserHasOverrides(user), "User does not have overrides, should be checked first"); | ||
|
||
List<int> overrides = this._userIdsToLevelList[user.UserId]; | ||
this.Logger.LogDebug(RefreshContext.LevelListOverride, "Getting level override for {0}: [{1}]", user.Username, string.Join(", ", overrides)); | ||
this._userIdsToLevelList.Remove(user.UserId); | ||
|
||
return overrides.Select(database.GetLevelById)!; | ||
} | ||
} |
This file contains 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im not sure how i feel about this, this should be something exposed in Bunkum, but since its non-critical test code it should be fine, non-blocking for merge but i'd like to see this more cleanly resolved at some point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the reasoning behind that behind choice in Bunkum was I wanted to discourage handling of Bunkum's objects, but as Bunkum grew that use-case became more acceptable (think database providers outside of the main BunkumServer for instance). I'll definitely implement this in Bunkum.