Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a few fixes related to highscore notifications #1086

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#nullable enable

Check warning on line 1 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant nullable directive

Redundant nullable directive
using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Helpers;
Expand All @@ -25,7 +25,7 @@
{
private readonly DatabaseContext database;

public ScoreController(DatabaseContext database)

Check notice on line 28 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Convert constructor into primary constructor

Convert into primary constructor
{
this.database = database;
}
Expand All @@ -34,7 +34,7 @@
{
UserFriendData? store = UserFriendStore.GetUserFriendData(userId);
List<int>? friendIds = store?.FriendIds;
friendIds ??= new List<int>();

Check notice on line 37 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
friendIds.Add(userId);

return friendIds.Distinct().ToArray();
Expand Down Expand Up @@ -64,7 +64,7 @@
// Workaround for parsing player ids of versus levels
if (score.PlayerIds.Length == 1)
{
char[] delimiters = { ':', ',', };

Check notice on line 67 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
score.PlayerIds = score.PlayerIds[0].Split(delimiters).Distinct().ToArray();
}

Expand Down Expand Up @@ -152,7 +152,9 @@
this.database.Scores.Add(existingScore);
}

if (score.Points > existingScore.Points)
bool personalBest = score.Points > existingScore.Points;

if (personalBest)
{
existingScore.Points = score.Points;
existingScore.Timestamp = TimeHelper.TimestampMillis;
Expand All @@ -172,12 +174,14 @@
TargetPlayerIds = null,
});

if (score.Type == 1 && scores.YourRank == 1 && scores.Total > 1)
// if this is a PB, singleplayer, at the top of the leaderboard (not scores.YourRank==1 because it might be tied), and there is at least one other score,
// send a notification to the user with the previous highscore
if (personalBest && score.Type == 1 && scores.Scores[0].UserId == token.UserId && scores.Total > 1)

Check notice on line 179 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invert 'if' statement to reduce nesting

Invert 'if' statement to reduce nesting
{
GameScore? second = scores.Scores[1];
UserEntity? user = await this.database.UserFromGameToken(token);

await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", true);
await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", false);
}

return this.Ok(scores);
Expand All @@ -202,7 +206,7 @@
};
if (!HttpMethods.IsPost(this.Request.Method))
{
List<PlayerScoreboardResponse> scoreboardResponses = new();

Check notice on line 209 in ProjectLighthouse.Servers.GameServer/Controllers/Slots/ScoreController.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Use collection expression syntax

Use collection expression
for (int i = 1; i <= 4; i++)
{
options.ScoreType = i;
Expand Down
Loading