Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions Refresh.Core/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,6 @@ public CommandService(Logger logger, PlayNowService levelListService) : base(log
this._levelListService = levelListService;
}

private readonly HashSet<ObjectId> _usersPublishing = [];

/// <summary>
/// Start tracking the user, eg. they started publishing
/// </summary>
/// <param name="id">The user ID</param>
public void StartPublishing(ObjectId id)
{
//Unconditionally add the user to the set
this._usersPublishing.Add(id);
}

/// <summary>
/// Stop tracking the user, eg. they stopped publishing
/// </summary>
/// <param name="id">The user ID</param>
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);

/// <summary>
/// Parse a command string into a command object
/// </summary>
Expand Down
10 changes: 1 addition & 9 deletions Refresh.Interfaces.Game/Endpoints/Levels/PublishEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
Expand Down
35 changes: 14 additions & 21 deletions Refresh.Interfaces.Game/Endpoints/ModerationEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,24 @@ public string Filter(RequestContext context, CommandService commandService, stri
body = body.Replace("&amp;", "&");
}

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
}
}

Expand Down