From 0a40301e6cf7763e64c49a916b44c81048b85837 Mon Sep 17 00:00:00 2001 From: jvyden Date: Sat, 3 Aug 2024 14:32:05 -0400 Subject: [PATCH] Implement reupload marking for all levels of a user --- Refresh.GameServer/CommandLineManager.cs | 8 ++++++++ .../Database/GameDatabaseContext.Users.cs | 16 ++++++++++++++++ .../Game/DataTypes/Response/GameLevelResponse.cs | 2 +- Refresh.GameServer/RefreshGameServer.cs | 6 ++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Refresh.GameServer/CommandLineManager.cs b/Refresh.GameServer/CommandLineManager.cs index a23745d8..05e64263 100644 --- a/Refresh.GameServer/CommandLineManager.cs +++ b/Refresh.GameServer/CommandLineManager.cs @@ -67,6 +67,9 @@ private class Options [Option("fully-delete-user", HelpText = "Fully deletes a user, entirely removing the row and allowing people to register with that username once again. Not recommended.")] public bool FullyDeleteUser { get; set; } + + [Option("mark-all-reuploads", HelpText = "Marks all levels uploaded by a user as re-uploaded. Username or Email options are required if this is set.")] + public bool MarkAllReuploads { get; set; } } internal void StartWithArgs(string[] args) @@ -195,5 +198,10 @@ private void StartWithOptions(Options options) GameUser user = this.GetUserOrFail(options); this._server.FullyDeleteUser(user); } + else if (options.MarkAllReuploads) + { + GameUser user = this.GetUserOrFail(options); + this._server.MarkAllReuploads(user); + } } } \ No newline at end of file diff --git a/Refresh.GameServer/Database/GameDatabaseContext.Users.cs b/Refresh.GameServer/Database/GameDatabaseContext.Users.cs index f45aedb4..9f2f5ef2 100644 --- a/Refresh.GameServer/Database/GameDatabaseContext.Users.cs +++ b/Refresh.GameServer/Database/GameDatabaseContext.Users.cs @@ -413,4 +413,20 @@ public void SetPrivacySettings(GameUser user, SerializedPrivacySettings settings user.ProfileVisibility = settings.ProfileVisibility.Value; }); } + + public void MarkAllReuploads(GameUser user) + { + IQueryable levels = this.GameLevels.Where(l => l.Publisher == user); + + this.Write(() => + { + foreach (GameLevel level in levels) + { + level.IsReUpload = true; + // normally, we'd also set the original publisher when marking a reupload. + // but since were doing this blindly, we shouldn't because the level might already be a reupload. + // we'd be setting it to null here, which could be loss of information. + } + }); + } } \ No newline at end of file diff --git a/Refresh.GameServer/Endpoints/Game/DataTypes/Response/GameLevelResponse.cs b/Refresh.GameServer/Endpoints/Game/DataTypes/Response/GameLevelResponse.cs index 8177bdd5..238ccc52 100644 --- a/Refresh.GameServer/Endpoints/Game/DataTypes/Response/GameLevelResponse.cs +++ b/Refresh.GameServer/Endpoints/Game/DataTypes/Response/GameLevelResponse.cs @@ -187,7 +187,7 @@ public static GameLevelResponse FromHash(string hash, DataContext dataContext) { string publisher; if (!old.IsReUpload) - publisher = "!DeletedUser"; + publisher = FakeUserConstants.DeletedUserName; else publisher = string.IsNullOrEmpty(old.OriginalPublisher) ? FakeUserConstants.UnknownUserName diff --git a/Refresh.GameServer/RefreshGameServer.cs b/Refresh.GameServer/RefreshGameServer.cs index 8688caaf..62b6222b 100644 --- a/Refresh.GameServer/RefreshGameServer.cs +++ b/Refresh.GameServer/RefreshGameServer.cs @@ -251,6 +251,12 @@ public void FullyDeleteUser(GameUser user) using GameDatabaseContext context = this.GetContext(); context.FullyDeleteUser(user); } + + public void MarkAllReuploads(GameUser user) + { + using GameDatabaseContext context = this.GetContext(); + context.MarkAllReuploads(user); + } public override void Dispose() {