From c99165ab1caa78f7b08926ec472c6478b40bae79 Mon Sep 17 00:00:00 2001 From: Toaster Date: Tue, 26 Aug 2025 18:55:06 +0200 Subject: [PATCH] Don't try to block commands while uploading a level --- Refresh.Core/Services/CommandService.cs | 24 ------------- .../Endpoints/Levels/PublishEndpoints.cs | 10 +----- .../Endpoints/ModerationEndpoints.cs | 35 ++++++++----------- 3 files changed, 15 insertions(+), 54 deletions(-) diff --git a/Refresh.Core/Services/CommandService.cs b/Refresh.Core/Services/CommandService.cs index 2b2e11714..a36146b59 100644 --- a/Refresh.Core/Services/CommandService.cs +++ b/Refresh.Core/Services/CommandService.cs @@ -21,30 +21,6 @@ public CommandService(Logger logger, PlayNowService levelListService) : base(log this._levelListService = levelListService; } - private readonly HashSet _usersPublishing = []; - - /// - /// Start tracking the user, eg. they started publishing - /// - /// The user ID - public void StartPublishing(ObjectId id) - { - //Unconditionally add the user to the set - this._usersPublishing.Add(id); - } - - /// - /// Stop tracking the user, eg. they stopped publishing - /// - /// The user ID - public void StopPublishing(ObjectId id) - { - //Unconditionally remove the user from the set - this._usersPublishing.Remove(id); - } - - public bool IsPublishing(ObjectId id) => this._usersPublishing.Contains(id); - /// /// Parse a command string into a command object /// diff --git a/Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs b/Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs index 9131bdc43..df646fd9b 100644 --- a/Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs +++ b/Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs @@ -106,7 +106,6 @@ private static bool IsTimedLevelLimitReached(DataContext dataContext, GameUser u [RequireEmailVerified] public Response StartPublish(RequestContext context, GameLevelRequest body, - CommandService command, DataContext dataContext, GameServerConfig config, IDateTimeProvider dateTimeProvider) @@ -148,9 +147,6 @@ public Response StartPublish(RequestContext context, //Verify all hashes are valid SHA1 hashes if (hashes.Any(hash => !CommonPatterns.Sha1Regex().IsMatch(hash))) return BadRequest; - //Mark the user as publishing - command.StartPublishing(dataContext.User!.UserId); - SerializedLevelResources response = new() { Resources = hashes.Where(r => !dataContext.DataStore.ExistsInStore(r)).ToArray() @@ -164,7 +160,6 @@ public Response StartPublish(RequestContext context, [RateLimitSettings(RequestTimeoutDuration, MaxRequestAmount, RequestBlockDuration, BucketName)] public Response PublishLevel(RequestContext context, GameLevelRequest body, - CommandService commandService, DataContext dataContext, GameUser user, GameServerConfig config, @@ -231,9 +226,6 @@ public Response PublishLevel(RequestContext context, return new Response(GameLevelResponse.FromOld(levelToUpdate, dataContext)!, ContentType.Xml); } - // Mark the user as no longer publishing - commandService.StopPublishing(dataContext.User!.UserId); - GameLevel newLevel = dataContext.Database.AddLevel(body, dataContext.Game, user); dataContext.Database.UpdateSkillRewardsForLevel(newLevel, body.SkillRewards); @@ -250,7 +242,7 @@ public Response PublishLevel(RequestContext context, // NOTE: this wont do anything if the slot is uploaded before the level resource, // so we also do this same operation inside of ResourceEndpoints.UploadAsset to catch that case aswell dataContext.Database.UpdateLevelModdedStatus(newLevel); - dataContext.Database.CreateLevelUploadEvent(dataContext.User, newLevel); + dataContext.Database.CreateLevelUploadEvent(user, newLevel); return new Response(GameLevelResponse.FromOld(newLevel, dataContext)!, ContentType.Xml); } diff --git a/Refresh.Interfaces.Game/Endpoints/ModerationEndpoints.cs b/Refresh.Interfaces.Game/Endpoints/ModerationEndpoints.cs index a283028dd..d82f05d79 100644 --- a/Refresh.Interfaces.Game/Endpoints/ModerationEndpoints.cs +++ b/Refresh.Interfaces.Game/Endpoints/ModerationEndpoints.cs @@ -59,31 +59,24 @@ public string Filter(RequestContext context, CommandService commandService, stri body = body.Replace("&", "&"); } - if (commandService.IsPublishing(user.UserId)) - { - context.Logger.LogInfo(BunkumCategory.UserLevels, $"Publish filter: '{body}'"); - } - else - { - context.Logger.LogInfo(BunkumCategory.Filter, $"<{user}>: {body}"); + context.Logger.LogInfo(BunkumCategory.Filter, $"<{user}>: {body}"); - //If the text starts with a `/`, its a command, also only allow verified users to use commands - if (body.StartsWith('/') && user.EmailAddressVerified) + //If the text starts with a `/`, its a command, also only allow verified users to use commands + if (body.StartsWith('/') && user.EmailAddressVerified) + { + try { - try - { - CommandInvocation command = commandService.ParseCommand(body); + CommandInvocation command = commandService.ParseCommand(body); - context.Logger.LogInfo(BunkumCategory.Commands, $"User used command '{command.Name.ToString()}' with args '{command.Arguments.ToString()}'"); + context.Logger.LogInfo(BunkumCategory.Commands, $"User used command '{command.Name.ToString()}' with args '{command.Arguments.ToString()}'"); - commandService.HandleCommand(command, database, user, token); - return "(Command)"; - } - catch(Exception ex) - { - context.Logger.LogWarning(BunkumCategory.Commands, $"Error running command {body}. ex {ex}"); - //do nothing - } + commandService.HandleCommand(command, database, user, token); + return "(Command)"; + } + catch(Exception ex) + { + context.Logger.LogWarning(BunkumCategory.Commands, $"Error running command {body}. ex {ex}"); + //do nothing } }