Skip to content

Commit

Permalink
Merge branch 'main' into new-postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Jun 19, 2024
2 parents a2717b7 + d184aca commit a34c35a
Show file tree
Hide file tree
Showing 70 changed files with 1,277 additions and 719 deletions.
173 changes: 0 additions & 173 deletions Refresh.Analyzers/ActivityGenerator.cs

This file was deleted.

16 changes: 0 additions & 16 deletions Refresh.Analyzers/Refresh.Analyzers.csproj

This file was deleted.

20 changes: 0 additions & 20 deletions Refresh.Analyzers/SyntaxReceivers/EnumNameReceiver.cs

This file was deleted.

4 changes: 2 additions & 2 deletions Refresh.Common/Refresh.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Bunkum" Version="4.5.4" />
<PackageReference Include="Bunkum.Protocols.Http" Version="4.5.4" />
<PackageReference Include="Bunkum" Version="4.5.6" />
<PackageReference Include="Bunkum.Protocols.Http" Version="4.5.6" />
</ItemGroup>

</Project>
31 changes: 28 additions & 3 deletions Refresh.GameServer/CommandLineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,27 @@ private class Options

[Option("rename-user", HelpText = "Changes a user's username. (old) username or Email option is required if this is set.")]
public string? RenameUser { get; set; }

[Option("delete-user", HelpText = "Deletes a user's account, removing their data but keeping a record of their sign up.")]
public bool DeleteUser { get; set; }

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

internal void StartWithArgs(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(this.StartWithOptions);
try
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed(this.StartWithOptions);
}
catch (Exception e)
{
Fail($"An internal error occurred: {e}", 139);
}

Console.WriteLine("The operation completed successfully.");
}

[DoesNotReturn]
Expand All @@ -73,7 +88,7 @@ private static void Fail(string reason, int code = 1)

Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine(reason);
Console.WriteLine($"Failed with exit code {code}");
Console.WriteLine($"The operation failed with exit code {code}");
Console.ForegroundColor = oldColor;

Environment.Exit(code);
Expand Down Expand Up @@ -162,5 +177,15 @@ private void StartWithOptions(Options options)
GameUser user = this.GetUserOrFail(options);
this._server.RenameUser(user, options.RenameUser);
}
else if (options.DeleteUser)
{
GameUser user = this.GetUserOrFail(options);
this._server.DeleteUser(user);
}
else if (options.FullyDeleteUser)
{
GameUser user = this.GetUserOrFail(options);
this._server.FullyDeleteUser(user);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public DatabaseList<Event> GetUserRecentActivity(ActivityQueryParameters paramet
userFriends.Contains(e.User.UserId) ||
userFriends.Contains(e.StoredObjectId) ||
this.GetLevelById(e.StoredSequentialId ?? int.MaxValue)?.Publisher?.UserId == parameters.User.UserId ||
e.EventType == EventType.Level_TeamPick ||
e.EventType == EventType.User_FirstLogin
e.EventType == EventType.LevelTeamPick ||
e.EventType == EventType.UserFirstLogin
);
}

Expand All @@ -41,7 +41,7 @@ private IEnumerable<Event> GetRecentActivity(ActivityQueryParameters parameters)
if (parameters.Timestamp == 0)
parameters.Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

IEnumerable<Event> query = this._realm.All<Event>()
IEnumerable<Event> query = this.Events
.Where(e => e.Timestamp < parameters.Timestamp && e.Timestamp >= parameters.EndTimestamp)
.AsEnumerable();

Expand Down Expand Up @@ -91,5 +91,5 @@ ActivityQueryParameters parameters
.OrderByDescending(e => e.Timestamp), parameters.Skip, parameters.Count);
}

public int GetTotalEventCount() => this._realm.All<Event>().Count();
public int GetTotalEventCount() => this.Events.Count();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Diagnostics;
using Refresh.GameServer.Types.Activity;
using Refresh.GameServer.Types.Levels;
using Refresh.GameServer.Types.Relations;
using Refresh.GameServer.Types.UserData;
using Refresh.GameServer.Types.UserData.Leaderboard;

namespace Refresh.GameServer.Database;

public partial class GameDatabaseContext // ActivityRead
{
public GameUser? GetUserFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.User)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.User)})");

Debug.Assert(e.StoredObjectId != null);

return this.GetUserByObjectId(e.StoredObjectId);
}

public GameLevel? GetLevelFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.Level)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.Level)})");

Debug.Assert(e.StoredSequentialId != null);

return this.GetLevelById(e.StoredSequentialId.Value);
}

public GameSubmittedScore? GetScoreFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.Score)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.Score)})");

Debug.Assert(e.StoredObjectId != null);

return this.GetScoreByObjectId(e.StoredObjectId);
}

public RateLevelRelation? GetRateLevelRelationFromEvent(Event e)
{
if (e.StoredDataType != EventDataType.RateLevelRelation)
throw new InvalidOperationException($"Event does not store the correct data type (expected {nameof(EventDataType.RateLevelRelation)})");

Debug.Assert(e.StoredObjectId != null);

return this.RateLevelRelations
.FirstOrDefault(l => l.RateLevelRelationId == e.StoredObjectId);
}
}
Loading

0 comments on commit a34c35a

Please sign in to comment.