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

Fix score importer looking up guest user by username online #25077

Merged
merged 3 commits into from
Oct 10, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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