Skip to content

Commit 52d1842

Browse files
committed
Make online status only handled by the config
1 parent 7ca3a6f commit 52d1842

File tree

8 files changed

+34
-28
lines changed

8 files changed

+34
-28
lines changed

osu.Desktop/DiscordRichPresence.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal partial class DiscordRichPresence : Component
5454
[Resolved]
5555
private OsuConfigManager config { get; set; } = null!;
5656

57-
private readonly IBindable<UserStatus> status = new Bindable<UserStatus>();
57+
private readonly Bindable<UserStatus> status = new Bindable<UserStatus>();
5858
private readonly IBindable<UserActivity?> activity = new Bindable<UserActivity?>();
5959
private readonly Bindable<DiscordRichPresenceMode> privacyMode = new Bindable<DiscordRichPresenceMode>();
6060

@@ -106,9 +106,9 @@ protected override void LoadComplete()
106106
base.LoadComplete();
107107

108108
config.BindWith(OsuSetting.DiscordRichPresence, privacyMode);
109+
config.BindWith(OsuSetting.UserOnlineStatus, status);
109110

110111
user = api.LocalUser.GetBoundCopy();
111-
status.BindTo(api.Status);
112112
activity.BindTo(api.Activity);
113113

114114
ruleset.BindValueChanged(_ => schedulePresenceUpdate());

osu.Game.Tests/Visual/Menus/TestSceneLoginOverlay.cs

+14-13
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ public partial class TestSceneLoginOverlay : OsuManualInputManagerTestScene
2929
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
3030

3131
private LoginOverlay loginOverlay = null!;
32-
33-
[Resolved]
34-
private OsuConfigManager configManager { get; set; } = null!;
32+
private OsuConfigManager localConfig = null!;
3533

3634
[Cached(typeof(LocalUserStatisticsProvider))]
3735
private readonly TestSceneUserPanel.TestUserStatisticsProvider statisticsProvider = new TestSceneUserPanel.TestUserStatisticsProvider();
3836

3937
[BackgroundDependencyLoader]
4038
private void load()
4139
{
40+
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
41+
4242
Child = loginOverlay = new LoginOverlay
4343
{
4444
Anchor = Anchor.Centre,
@@ -49,6 +49,7 @@ private void load()
4949
[SetUpSteps]
5050
public void SetUpSteps()
5151
{
52+
AddStep("reset online state", () => localConfig.SetValue(OsuSetting.UserOnlineStatus, UserStatus.Online));
5253
AddStep("show login overlay", () => loginOverlay.Show());
5354
}
5455

@@ -89,7 +90,7 @@ public void TestLoginSuccess()
8990
AddStep("clear handler", () => dummyAPI.HandleRequest = null);
9091

9192
assertDropdownState(UserAction.Online);
92-
AddStep("change user state", () => dummyAPI.Status.Value = UserStatus.DoNotDisturb);
93+
AddStep("change user state", () => localConfig.SetValue(OsuSetting.UserOnlineStatus, UserStatus.DoNotDisturb));
9394
assertDropdownState(UserAction.DoNotDisturb);
9495
}
9596

@@ -188,31 +189,31 @@ public void TestClickingOnFlagClosesOverlay()
188189
public void TestUncheckingRememberUsernameClearsIt()
189190
{
190191
AddStep("logout", () => API.Logout());
191-
AddStep("set username", () => configManager.SetValue(OsuSetting.Username, "test_user"));
192-
AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true));
192+
AddStep("set username", () => localConfig.SetValue(OsuSetting.Username, "test_user"));
193+
AddStep("set remember password", () => localConfig.SetValue(OsuSetting.SavePassword, true));
193194
AddStep("uncheck remember username", () =>
194195
{
195196
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().First());
196197
InputManager.Click(MouseButton.Left);
197198
});
198-
AddAssert("remember username off", () => configManager.Get<bool>(OsuSetting.SaveUsername), () => Is.False);
199-
AddAssert("remember password off", () => configManager.Get<bool>(OsuSetting.SavePassword), () => Is.False);
200-
AddAssert("username cleared", () => configManager.Get<string>(OsuSetting.Username), () => Is.Empty);
199+
AddAssert("remember username off", () => localConfig.Get<bool>(OsuSetting.SaveUsername), () => Is.False);
200+
AddAssert("remember password off", () => localConfig.Get<bool>(OsuSetting.SavePassword), () => Is.False);
201+
AddAssert("username cleared", () => localConfig.Get<string>(OsuSetting.Username), () => Is.Empty);
201202
}
202203

203204
[Test]
204205
public void TestUncheckingRememberPasswordClearsToken()
205206
{
206207
AddStep("logout", () => API.Logout());
207-
AddStep("set token", () => configManager.SetValue(OsuSetting.Token, "test_token"));
208-
AddStep("set remember password", () => configManager.SetValue(OsuSetting.SavePassword, true));
208+
AddStep("set token", () => localConfig.SetValue(OsuSetting.Token, "test_token"));
209+
AddStep("set remember password", () => localConfig.SetValue(OsuSetting.SavePassword, true));
209210
AddStep("uncheck remember token", () =>
210211
{
211212
InputManager.MoveMouseTo(loginOverlay.ChildrenOfType<SettingsCheckbox>().Last());
212213
InputManager.Click(MouseButton.Left);
213214
});
214-
AddAssert("remember password off", () => configManager.Get<bool>(OsuSetting.SavePassword), () => Is.False);
215-
AddAssert("token cleared", () => configManager.Get<string>(OsuSetting.Token), () => Is.Empty);
215+
AddAssert("remember password off", () => localConfig.Get<bool>(OsuSetting.SavePassword), () => Is.False);
216+
AddAssert("token cleared", () => localConfig.Get<string>(OsuSetting.Token), () => Is.Empty);
216217
}
217218
}
218219
}

osu.Game/Configuration/OsuConfigManager.cs

+5
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,12 @@ public enum OsuSetting
443443
EditorShowSpeedChanges,
444444
TouchDisableGameplayTaps,
445445
ModSelectTextSearchStartsActive,
446+
447+
/// <summary>
448+
/// The status for the current user that should be broadcast to other players.
449+
/// </summary>
446450
UserOnlineStatus,
451+
447452
MultiplayerRoomFilter,
448453
HideCountryFlags,
449454
EditorTimelineShowTimingChanges,

osu.Game/Online/API/APIAccess.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ public partial class APIAccess : Component, IAPIProvider
6060

6161
public IBindable<APIUser> LocalUser => localUser;
6262
public IBindableList<APIRelation> Friends => friends;
63-
public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
6463
public IBindable<UserActivity> Activity => activity;
6564

6665
public INotificationsClient NotificationsClient { get; }
@@ -73,6 +72,8 @@ public partial class APIAccess : Component, IAPIProvider
7372

7473
private Bindable<UserActivity> activity { get; } = new Bindable<UserActivity>();
7574

75+
private Bindable<UserStatus> configStatus { get; } = new Bindable<UserStatus>();
76+
7677
protected bool HasLogin => authentication.Token.Value != null || (!string.IsNullOrEmpty(ProvidedUsername) && !string.IsNullOrEmpty(password));
7778

7879
private readonly CancellationTokenSource cancellationToken = new CancellationTokenSource();
@@ -108,7 +109,7 @@ public APIAccess(OsuGameBase game, OsuConfigManager config, EndpointConfiguratio
108109
authentication.TokenString = config.Get<string>(OsuSetting.Token);
109110
authentication.Token.ValueChanged += onTokenChanged;
110111

111-
config.BindWith(OsuSetting.UserOnlineStatus, Status);
112+
config.BindWith(OsuSetting.UserOnlineStatus, configStatus);
112113

113114
if (HasLogin)
114115
{
@@ -591,7 +592,9 @@ public void Logout()
591592
password = null;
592593
SecondFactorCode = null;
593594
authentication.Clear();
594-
Status.Value = UserStatus.Online;
595+
596+
// Reset the status to be broadcast on the next login, in case multiple players share the same system.
597+
configStatus.Value = UserStatus.Online;
595598

596599
// Scheduled prior to state change such that the state changed event is invoked with the correct user and their friends present
597600
Schedule(() =>

osu.Game/Online/API/DummyAPIAccess.cs

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public partial class DummyAPIAccess : Component, IAPIProvider
2828

2929
public BindableList<APIRelation> Friends { get; } = new BindableList<APIRelation>();
3030

31-
public Bindable<UserStatus> Status { get; } = new Bindable<UserStatus>(UserStatus.Online);
32-
3331
public Bindable<UserActivity?> Activity { get; } = new Bindable<UserActivity?>();
3432

3533
public DummyNotificationsClient NotificationsClient { get; } = new DummyNotificationsClient();

osu.Game/Online/API/IAPIProvider.cs

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public interface IAPIProvider
2424
/// </summary>
2525
IBindableList<APIRelation> Friends { get; }
2626

27-
/// <summary>
28-
/// The current user's status.
29-
/// </summary>
30-
Bindable<UserStatus> Status { get; }
31-
3227
/// <summary>
3328
/// The current user's activity.
3429
/// </summary>

osu.Game/Online/Metadata/OnlineMetadataClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ private void load(IAPIProvider api, OsuConfigManager config)
7474
}
7575

7676
lastQueueId = config.GetBindable<int>(OsuSetting.LastProcessedMetadataId);
77+
userStatus = config.GetBindable<UserStatus>(OsuSetting.UserOnlineStatus);
7778

7879
localUser = api.LocalUser.GetBoundCopy();
79-
userStatus = api.Status.GetBoundCopy();
8080
userActivity = api.Activity.GetBoundCopy()!;
8181
}
8282

osu.Game/Overlays/Login/LoginPanel.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using osu.Framework.Graphics.Containers;
1010
using osu.Framework.Graphics.Primitives;
1111
using osu.Framework.Input.Events;
12+
using osu.Game.Configuration;
1213
using osu.Game.Graphics;
1314
using osu.Game.Graphics.Containers;
1415
using osu.Game.Graphics.Sprites;
@@ -43,6 +44,9 @@ public partial class LoginPanel : Container
4344
[Resolved]
4445
private IAPIProvider api { get; set; } = null!;
4546

47+
[Resolved]
48+
private OsuConfigManager config { get; set; } = null!;
49+
4650
public override RectangleF BoundingBox => bounding ? base.BoundingBox : RectangleF.Empty;
4751

4852
public bool Bounding
@@ -65,10 +69,10 @@ protected override void LoadComplete()
6569
{
6670
base.LoadComplete();
6771

72+
config.BindWith(OsuSetting.UserOnlineStatus, status);
73+
6874
apiState.BindTo(api.State);
6975
apiState.BindValueChanged(onlineStateChanged, true);
70-
71-
status.BindTo(api.Status);
7276
status.BindValueChanged(e => updateDropdownCurrent(e.NewValue), true);
7377
}
7478

0 commit comments

Comments
 (0)