Skip to content

Commit

Permalink
Merge pull request #19139 from frenzibyte/score-country-storage
Browse files Browse the repository at this point in the history
Support storing user country on databased scores
  • Loading branch information
peppy authored Jul 18, 2022
2 parents b675096 + 1e151ba commit 0c75245
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 7 deletions.
3 changes: 2 additions & 1 deletion osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ public class RealmAccess : IDisposable
/// 14 2022-03-01 Added BeatmapUserSettings to BeatmapInfo.
/// 15 2022-07-13 Added LastPlayed to BeatmapInfo.
/// 16 2022-07-15 Removed HasReplay from ScoreInfo.
/// 17 2022-07-16 Added CountryCode to RealmUser.
/// </summary>
private const int schema_version = 16;
private const int schema_version = 17;

/// <summary>
/// Lock object which is held during <see cref="BlockAllOperations"/> sections, blocking realm retrieval during blocking periods.
Expand Down
12 changes: 10 additions & 2 deletions osu.Game/Models/RealmUser.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using osu.Game.Database;
using osu.Game.Users;
Expand All @@ -17,6 +15,16 @@ public class RealmUser : EmbeddedObject, IUser, IEquatable<RealmUser>, IDeepClon

public string Username { get; set; } = string.Empty;

[Ignored]
public CountryCode CountryCode
{
get => Enum.TryParse(CountryString, out CountryCode country) ? country : CountryCode.Unknown;
set => CountryString = value.ToString();
}

[MapTo(nameof(CountryCode))]
public string CountryString { get; set; } = default(CountryCode).ToString();

public bool IsBot => false;

public bool Equals(RealmUser other)
Expand Down
1 change: 1 addition & 0 deletions osu.Game/Rulesets/Mods/ICreateReplayData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public ModReplayData(Replay replay, ModCreatedUser user = null)
public class ModCreatedUser : IUser
{
public int OnlineID => APIUser.SYSTEM_USER_ID;
public CountryCode CountryCode => default;
public bool IsBot => true;

public string Username { get; set; } = string.Empty;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Scoring/ScoreImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected override void PostImport(ScoreInfo model, Realm realm)
api.Perform(userRequest);

if (userRequest.Response is APIUser user)
model.RealmUser.OnlineID = user.Id;
model.User = user;
}
}
}
7 changes: 5 additions & 2 deletions osu.Game/Scoring/ScoreInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ public APIUser User
{
get => user ??= new APIUser
{
Username = RealmUser.Username,
Id = RealmUser.OnlineID,
Username = RealmUser.Username,
CountryCode = RealmUser.CountryCode,
};
set
{
Expand All @@ -95,7 +96,8 @@ public APIUser User
RealmUser = new RealmUser
{
OnlineID = user.OnlineID,
Username = user.Username
Username = user.Username,
CountryCode = user.CountryCode,
};
}
}
Expand Down Expand Up @@ -135,6 +137,7 @@ public ScoreInfo DeepClone()
{
OnlineID = RealmUser.OnlineID,
Username = RealmUser.Username,
CountryCode = RealmUser.CountryCode,
};

return clone;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Skinning/LegacyBeatmapSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static SkinInfo createSkinInfo(BeatmapInfo beatmapInfo) =>
new SkinInfo
{
Name = beatmapInfo.ToString(),
Creator = beatmapInfo.Metadata.Author.Username ?? string.Empty
Creator = beatmapInfo.Metadata.Author.Username
};
}
}
2 changes: 2 additions & 0 deletions osu.Game/Users/IUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface IUser : IHasOnlineID<int>, IEquatable<IUser>
{
string Username { get; }

CountryCode CountryCode { get; }

bool IsBot { get; }

bool IEquatable<IUser>.Equals(IUser? other)
Expand Down

0 comments on commit 0c75245

Please sign in to comment.