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
19 changes: 15 additions & 4 deletions Refresh.Core/Services/CommandService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ namespace Refresh.Core.Services;

public class CommandService : EndpointService
{
private readonly MatchService _match;
private readonly PlayNowService _levelListService;

public CommandService(Logger logger, MatchService match, PlayNowService levelListService) : base(logger) {
this._match = match;
public CommandService(Logger logger, PlayNowService levelListService) : base(logger)
{
this._levelListService = levelListService;
}

private readonly HashSet<ObjectId> _usersPublishing = new();
private readonly HashSet<ObjectId> _usersPublishing = [];

/// <summary>
/// Start tracking the user, eg. they started publishing
Expand Down Expand Up @@ -125,6 +124,18 @@ public void HandleCommand(CommandInvocation command, GameDatabaseContext databas
database.SetShowModdedContent(user, false);
break;
}
case "showreupload":
case "showreuploads":
{
database.SetShowReuploadedContent(user, true);
break;
}
case "hidereupload":
case "hidereuploads":
{
database.SetShowReuploadedContent(user, false);
break;
}
case "play":
{
if (CommonPatterns.Sha1Regex().IsMatch(command.Arguments))
Expand Down
8 changes: 7 additions & 1 deletion Refresh.Database/Extensions/LevelEnumerableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static IQueryable<GameLevel> FilterByLevelFilterSettings(this IQueryable<
// If the user has it disabled globally and the filter doesnt enable it, or the filter disables it, disable modded content from being shown
if ((user is { ShowModdedContent: false } && levelFilterSettings.ShowModdedLevels != true) || levelFilterSettings.ShowModdedLevels == false)
levels = levels.Where(l => !l.IsModded);

if ((user is { ShowReuploadedContent: false } && levelFilterSettings.ShowReuploadedLevels != true) || levelFilterSettings.ShowReuploadedLevels == false)
levels = levels.Where(l => !l.IsReUpload);

// Don't allow beta builds to use this filtering option
// If the client specifies this option then it will filter out *all* levels.
Expand Down Expand Up @@ -89,6 +92,9 @@ public static IEnumerable<GameLevel> FilterByLevelFilterSettings(this IEnumerabl
if ((user is { ShowModdedContent: false } && levelFilterSettings.ShowModdedLevels != true) || levelFilterSettings.ShowModdedLevels == false)
levels = levels.Where(l => !l.IsModded);

if ((user is { ShowReuploadedContent: false } && levelFilterSettings.ShowReuploadedLevels != true) || levelFilterSettings.ShowReuploadedLevels == false)
levels = levels.Where(l => !l.IsReUpload);

// Don't allow beta builds to use this filtering option
// If the client specifies this option then it will filter out *all* levels.
if (levelFilterSettings.GameVersion != TokenGame.BetaBuild)
Expand Down Expand Up @@ -122,7 +128,7 @@ public static IEnumerable<GameLevel> FilterByLevelFilterSettings(this IEnumerabl
// };

// Filter out sub levels that weren't published by self
levels = levels.Where(l => !l.IsSubLevel || l.Publisher?.UserId == user?.UserId);
levels = levels.Where(l => !l.IsSubLevel || l.Publisher == user);

return levels;
}
Expand Down
11 changes: 11 additions & 0 deletions Refresh.Database/GameDatabaseContext.Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ public void UpdateUserData(GameUser user, IApiEditUserRequest data)

if (data.ShowModdedContent != null)
user.ShowModdedContent = data.ShowModdedContent.Value;

if (data.ShowReuploadedContent != null)
user.ShowReuploadedContent = data.ShowReuploadedContent.Value;
});
}

Expand Down Expand Up @@ -380,6 +383,14 @@ public void SetShowModdedContent(GameUser user, bool value)
user.ShowModdedContent = value;
});
}

public void SetShowReuploadedContent(GameUser user, bool value)
{
this.Write(() =>
{
user.ShowReuploadedContent = value;
});
}

public void ClearForceMatch(GameUser user)
{
Expand Down
7 changes: 5 additions & 2 deletions Refresh.Database/GameDatabaseProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void Initialize()
#endif

#if !POSTGRES
protected override ulong SchemaVersion => 167;
protected override ulong SchemaVersion => 169;

protected override string Filename => "refreshGameServer.realm";

Expand Down Expand Up @@ -135,7 +135,7 @@ protected override void Migrate(Migration migration, ulong oldVersion)
{
IQueryable<dynamic>? oldUsers = migration.OldRealm.DynamicApi.All("GameUser");
IQueryable<GameUser>? newUsers = migration.NewRealm.All<GameUser>();
if (oldVersion < 165)
if (oldVersion < 169)
for (int i = 0; i < newUsers.Count(); i++)
{
dynamic oldUser = oldUsers.ElementAt(i);
Expand Down Expand Up @@ -340,6 +340,9 @@ protected override void Migrate(Migration migration, ulong oldVersion)
}
}
}

if (oldVersion < 169)
newUser.ShowReuploadedContent = true;
}

IQueryable<dynamic>? oldLevels = migration.OldRealm.DynamicApi.All("GameLevel");
Expand Down
7 changes: 6 additions & 1 deletion Refresh.Database/Models/Users/GameUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,15 @@ [Ignored] public GameUserRole Role
}

/// <summary>
/// Whether or not modded content should be shown in level listings
/// Whether modded content should be shown in level listings
/// </summary>
public bool ShowModdedContent { get; set; } = true;

/// <summary>
/// Whether reuploaded content should be shown in level listings
/// </summary>
public bool ShowReuploadedContent { get; set; } = true;

// ReSharper disable once InconsistentNaming
internal byte _Role { get; set; }

Expand Down
1 change: 1 addition & 0 deletions Refresh.Database/Query/IApiEditUserRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface IApiEditUserRequest
bool? UnescapeXmlSequences { get; set; }
string? EmailAddress { get; set; }
bool? ShowModdedContent { get; set; }
bool? ShowReuploadedContent { get; set; }
Visibility? LevelVisibility { get; set; }
Visibility? ProfileVisibility { get; set; }
}
17 changes: 16 additions & 1 deletion Refresh.Database/Query/LevelFilterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ public class LevelFilterSettings
public TokenGame GameVersion;

/// <summary>
/// Whether or not to force showing/hiding modded content.
/// Whether to force showing/hiding modded content.
/// </summary>
public bool? ShowModdedLevels;

/// <summary>
/// Whether to force showing/hiding reuploaded content.
/// </summary>
public bool? ShowReuploadedLevels;

/// <summary>
/// The seed used for lucky dip/random levels.
/// </summary>
Expand Down Expand Up @@ -183,5 +188,15 @@ public LevelFilterSettings(RequestContext context, TokenGame game) : this(game)

this.ShowModdedLevels = showModdedLevels;
}

string? reuploadedFilter = context.QueryString.Get("includeReuploaded");

if (reuploadedFilter != null)
{
if (!bool.TryParse(moddedFilter, out bool showReuploadedLevels))
throw new FormatException("Could not parse reuploaded filter setting because the boolean was invalid.");

this.ShowModdedLevels = showReuploadedLevels;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public class ApiUpdateUserRequest : IApiEditUserRequest
public string? EmailAddress { get; set; }

public bool? ShowModdedContent { get; set; }

public bool? ShowReuploadedContent { get; set; }

public Visibility? LevelVisibility { get; set; }
public Visibility? ProfileVisibility { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class ApiExtendedGameUserResponse : IApiResponse, IDataConvertableFrom<Ap
public required bool AllowIpAuthentication { get; set; }

public required bool ShowModdedContent { get; set; }
public required bool ShowReuploadedContent { get; set; }

public required Visibility LevelVisibility { get; set; }
public required Visibility ProfileVisibility { get; set; }
Expand Down Expand Up @@ -76,6 +77,7 @@ public class ApiExtendedGameUserResponse : IApiResponse, IDataConvertableFrom<Ap
LevelVisibility = user.LevelVisibility,
ProfileVisibility = user.ProfileVisibility,
ShowModdedContent = user.ShowModdedContent,
ShowReuploadedContent = user.ShowReuploadedContent,
ConnectedToPresenceServer = user.PresenceServerAuthToken != null,
};
}
Expand Down
6 changes: 3 additions & 3 deletions RefreshTests.GameServer/Tests/Commands/CommandParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private void ParseTest(CommandService service, ReadOnlySpan<char> input, ReadOnl
public void ParsingTest()
{
using Logger logger = new([new NUnitSink()]);
CommandService service = new(logger, new MatchService(logger), new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));
CommandService service = new(logger, new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));

ParseTest(service, "/parse test", "parse", "test");
ParseTest(service, "/noargs", "noargs", "");
Expand All @@ -32,7 +32,7 @@ public void ParsingTest()
public void NoSlashThrows()
{
using Logger logger = new([new NUnitSink()]);
CommandService service = new(logger, new MatchService(logger), new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));
CommandService service = new(logger, new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));

Assert.That(() => _ = service.ParseCommand("parse test"), Throws.InstanceOf<FormatException>());
}
Expand All @@ -41,7 +41,7 @@ public void NoSlashThrows()
public void BlankCommandThrows()
{
using Logger logger = new([new NUnitSink()]);
CommandService service = new(logger, new MatchService(logger), new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));
CommandService service = new(logger, new PlayNowService(logger, new PresenceService(logger, new IntegrationConfig())));

Assert.That(() => _ = service.ParseCommand("/ test"), Throws.InstanceOf<FormatException>());
}
Expand Down