a few fixes related to highscore notifications

This commit is contained in:
Kat 2025-01-11 20:02:04 -08:00
commit ff948d04fd
No known key found for this signature in database
GPG key ID: 11C549BC42DB9B8A

View file

@ -152,7 +152,9 @@ public class ScoreController : ControllerBase
this.database.Scores.Add(existingScore); this.database.Scores.Add(existingScore);
} }
if (score.Points > existingScore.Points) bool personalBest = score.Points > existingScore.Points;
if (personalBest)
{ {
existingScore.Points = score.Points; existingScore.Points = score.Points;
existingScore.Timestamp = TimeHelper.TimestampMillis; existingScore.Timestamp = TimeHelper.TimestampMillis;
@ -172,12 +174,14 @@ public class ScoreController : ControllerBase
TargetPlayerIds = null, 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)
{ {
GameScore? second = scores.Scores[1]; GameScore? second = scores.Scores[1];
UserEntity? user = await this.database.UserFromGameToken(token); 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); return this.Ok(scores);