Skip to content

Commit

Permalink
Merge pull request #25077 from bdach/fix-guest-score-lookup
Browse files Browse the repository at this point in the history
Fix score importer looking up guest user by username online
  • Loading branch information
peppy committed Oct 10, 2023
2 parents a0bd91f + ea400a9 commit 1388f72
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
39 changes: 39 additions & 0 deletions osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
Expand All @@ -26,6 +29,7 @@
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources;
using osu.Game.Users;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Gameplay
Expand Down Expand Up @@ -98,6 +102,7 @@ public void TestLastPlayedUpdated()
{
DateTimeOffset? getLastPlayed() => Realm.Run(r => r.Find<BeatmapInfo>(Beatmap.Value.BeatmapInfo.ID)?.LastPlayed);

AddStep("reset last played", () => Realm.Write(r => r.Find<BeatmapInfo>(Beatmap.Value.BeatmapInfo.ID)!.LastPlayed = null));
AddAssert("last played is null", () => getLastPlayed() == null);

CreateTest();
Expand Down Expand Up @@ -150,6 +155,40 @@ public void TestScoreStoredLocally()
AddUntilStep("score in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null));
}

[Test]
public void TestGuestScoreIsStoredAsGuest()
{
AddStep("set up API", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case GetUserRequest userRequest:
userRequest.TriggerSuccess(new APIUser
{
Username = "Guest",
CountryCode = CountryCode.JP,
Id = 1234
});
return true;
default:
return false;
}
});

AddStep("log out", () => API.Logout());
CreateTest();

AddUntilStep("wait for track to start running", () => Beatmap.Value.Track.IsRunning);
AddStep("log back in", () => API.Login("username", "password"));

AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));

AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
AddUntilStep("score in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null));
AddAssert("score is not associated with online user", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID))!.UserID == APIUser.SYSTEM_USER_ID);
}

[Test]
public void TestReplayExport()
{
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Scoring/ScoreImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ protected override void PostImport(ScoreInfo model, Realm realm, ImportParameter
/// </summary>
private void populateUserDetails(ScoreInfo model)
{
if (model.RealmUser.OnlineID == APIUser.SYSTEM_USER_ID)
return;

string username = model.RealmUser.Username;

if (usernameLookupCache.TryGetValue(username, out var existing))
Expand Down

0 comments on commit 1388f72

Please sign in to comment.