mirror of
https://github.com/ppy/osu.git
synced 2024-12-13 08:32:57 +08:00
Make Room.Password
& Room.HasPassword
non-bindable
This commit is contained in:
parent
198681e644
commit
ec5be6dbc3
@ -24,7 +24,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
private readonly Room room = new Room
|
||||
{
|
||||
HasPassword = { Value = true }
|
||||
Password = "*"
|
||||
};
|
||||
|
||||
[Cached]
|
||||
|
@ -86,7 +86,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
{
|
||||
Name = "Private room",
|
||||
Status = new RoomStatusOpenPrivate(),
|
||||
HasPassword = { Value = true },
|
||||
Password = "*",
|
||||
EndDate = { Value = DateTimeOffset.Now.AddDays(1) },
|
||||
Type = MatchType.HeadToHead,
|
||||
Playlist = { item3 },
|
||||
@ -144,10 +144,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
|
||||
|
||||
AddStep("set password", () => room.Password.Value = "password");
|
||||
AddStep("set password", () => room.Password = "password");
|
||||
AddAssert("password icon visible", () => Precision.AlmostEquals(1, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
|
||||
|
||||
AddStep("unset password", () => room.Password.Value = string.Empty);
|
||||
AddStep("unset password", () => room.Password = string.Empty);
|
||||
AddAssert("password icon hidden", () => Precision.AlmostEquals(0, drawableRoom.ChildrenOfType<DrawableRoom.PasswordProtectedIcon>().Single().Alpha));
|
||||
}
|
||||
|
||||
|
@ -182,11 +182,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
AddStep("filter public rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Public });
|
||||
|
||||
AddUntilStep("private room hidden", () => container.Rooms.All(r => !r.Room.HasPassword.Value));
|
||||
AddUntilStep("private room hidden", () => container.Rooms.All(r => !r.Room.HasPassword));
|
||||
|
||||
AddStep("filter private rooms", () => container.Filter.Value = new FilterCriteria { Permissions = RoomPermissionsFilter.Private });
|
||||
|
||||
AddUntilStep("public room hidden", () => container.Rooms.All(r => r.Room.HasPassword.Value));
|
||||
AddUntilStep("public room hidden", () => container.Rooms.All(r => r.Room.HasPassword));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -318,7 +318,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
createRoom(() => new Room
|
||||
{
|
||||
Name = "Test Room",
|
||||
Password = { Value = "password" },
|
||||
Password = "password",
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
|
||||
@ -328,7 +328,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
});
|
||||
|
||||
AddUntilStep("room has password", () => multiplayerClient.ClientAPIRoom?.Password.Value == "password");
|
||||
AddUntilStep("room has password", () => multiplayerClient.ClientAPIRoom?.Password == "password");
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -339,7 +339,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
roomManager.AddServerSideRoom(new Room
|
||||
{
|
||||
Name = "Test Room",
|
||||
Password = { Value = "password" },
|
||||
Password = "password",
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
|
||||
@ -371,7 +371,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
createRoom(() => new Room
|
||||
{
|
||||
Name = "Test Room",
|
||||
Password = { Value = "password" },
|
||||
Password = "password",
|
||||
Playlist =
|
||||
{
|
||||
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
|
||||
@ -382,7 +382,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
});
|
||||
|
||||
AddStep("change password", () => multiplayerClient.ChangeSettings(password: "password2"));
|
||||
AddUntilStep("local password changed", () => multiplayerClient.ClientAPIRoom?.Password.Value == "password2");
|
||||
AddUntilStep("local password changed", () => multiplayerClient.ClientAPIRoom?.Password == "password2");
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -184,7 +184,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
Debug.Assert(room.RoomID != null);
|
||||
|
||||
// Join the server-side room.
|
||||
var joinedRoom = await JoinRoom(room.RoomID.Value, password ?? room.Password.Value).ConfigureAwait(false);
|
||||
var joinedRoom = await JoinRoom(room.RoomID.Value, password ?? room.Password).ConfigureAwait(false);
|
||||
Debug.Assert(joinedRoom != null);
|
||||
|
||||
// Populate users.
|
||||
@ -397,7 +397,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
switch (state)
|
||||
{
|
||||
case MultiplayerRoomState.Open:
|
||||
APIRoom.Status = APIRoom.HasPassword.Value ? new RoomStatusOpenPrivate() : new RoomStatusOpen();
|
||||
APIRoom.Status = APIRoom.HasPassword ? new RoomStatusOpenPrivate() : new RoomStatusOpen();
|
||||
break;
|
||||
|
||||
case MultiplayerRoomState.Playing:
|
||||
@ -842,7 +842,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
// Update a few properties of the room instantaneously.
|
||||
Room.Settings = settings;
|
||||
APIRoom.Name = Room.Settings.Name;
|
||||
APIRoom.Password.Value = Room.Settings.Password;
|
||||
APIRoom.Password = Room.Settings.Password;
|
||||
APIRoom.Status = string.IsNullOrEmpty(Room.Settings.Password) ? new RoomStatusOpen() : new RoomStatusOpenPrivate();
|
||||
APIRoom.Type = Room.Settings.MatchType;
|
||||
APIRoom.QueueMode = Room.Settings.QueueMode;
|
||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Online.Rooms
|
||||
{
|
||||
if (room.EndDate.Value != null && DateTimeOffset.Now >= room.EndDate.Value)
|
||||
room.Status = new RoomStatusEnded();
|
||||
else if (room.HasPassword.Value)
|
||||
else if (room.HasPassword)
|
||||
room.Status = new RoomStatusOpenPrivate();
|
||||
else
|
||||
room.Status = new RoomStatusOpen();
|
||||
|
@ -39,6 +39,35 @@ namespace osu.Game.Online.Rooms
|
||||
set => SetField(ref name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the room password. Will be <c>null</c> after the room is created.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To check if the room has a password, use <see cref="HasPassword"/>.
|
||||
/// </remarks>
|
||||
public string? Password
|
||||
{
|
||||
get => password;
|
||||
set
|
||||
{
|
||||
SetField(ref password, value);
|
||||
HasPassword = !string.IsNullOrEmpty(value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether the room has a password.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// To set a password, use <see cref="Password"/>.
|
||||
/// </remarks>
|
||||
[JsonProperty("has_password")]
|
||||
public bool HasPassword
|
||||
{
|
||||
get => hasPassword;
|
||||
private set => SetField(ref hasPassword, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The room host. Will be <c>null</c> while the room has not yet been created.
|
||||
/// </summary>
|
||||
@ -112,6 +141,12 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("name")]
|
||||
private string name = string.Empty;
|
||||
|
||||
[JsonProperty("password")]
|
||||
private string? password;
|
||||
|
||||
// Not serialised (internal use only).
|
||||
private bool hasPassword;
|
||||
|
||||
[JsonProperty("host")]
|
||||
private APIUser? host;
|
||||
|
||||
@ -172,9 +207,6 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("current_user_score")]
|
||||
public readonly Bindable<PlaylistAggregateScore> UserScore = new Bindable<PlaylistAggregateScore>();
|
||||
|
||||
[JsonProperty("has_password")]
|
||||
public readonly Bindable<bool> HasPassword = new Bindable<bool>();
|
||||
|
||||
[Cached]
|
||||
[JsonProperty("recent_participants")]
|
||||
public readonly BindableList<APIUser> RecentParticipants = new BindableList<APIUser>();
|
||||
@ -185,10 +217,6 @@ namespace osu.Game.Online.Rooms
|
||||
|
||||
#region Properties only used for room creation request
|
||||
|
||||
[Cached(Name = nameof(Password))]
|
||||
[JsonProperty("password")]
|
||||
public readonly Bindable<string?> Password = new Bindable<string?>();
|
||||
|
||||
[Cached]
|
||||
public readonly Bindable<TimeSpan?> Duration = new Bindable<TimeSpan?>();
|
||||
|
||||
@ -229,11 +257,6 @@ namespace osu.Game.Online.Rooms
|
||||
[JsonProperty("auto_skip")]
|
||||
public readonly Bindable<bool> AutoSkip = new Bindable<bool>();
|
||||
|
||||
public Room()
|
||||
{
|
||||
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies values from another <see cref="Room"/> into this one.
|
||||
/// </summary>
|
||||
@ -254,7 +277,7 @@ namespace osu.Game.Online.Rooms
|
||||
ChannelId.Value = other.ChannelId.Value;
|
||||
Status = other.Status;
|
||||
Availability = other.Availability;
|
||||
HasPassword.Value = other.HasPassword.Value;
|
||||
HasPassword = other.HasPassword;
|
||||
Type = other.Type;
|
||||
MaxParticipants.Value = other.MaxParticipants.Value;
|
||||
ParticipantCount.Value = other.ParticipantCount.Value;
|
||||
|
@ -259,12 +259,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
|
||||
wrapper.FadeInFromZero(200);
|
||||
|
||||
hasPassword.BindTo(Room.HasPassword);
|
||||
hasPassword.BindValueChanged(v => passwordIcon.Alpha = v.NewValue ? 1 : 0, true);
|
||||
|
||||
updateRoomName();
|
||||
updateRoomCategory();
|
||||
updateRoomType();
|
||||
updateRoomHasPassword();
|
||||
};
|
||||
|
||||
SelectedItem.BindValueChanged(item => background.Beatmap.Value = item.NewValue?.Beatmap, true);
|
||||
@ -285,6 +283,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
case nameof(Room.Type):
|
||||
updateRoomType();
|
||||
break;
|
||||
|
||||
case nameof(Room.HasPassword):
|
||||
updateRoomHasPassword();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -308,6 +310,12 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
endDateInfo.Alpha = Room.Type == MatchType.Playlists ? 1 : 0;
|
||||
}
|
||||
|
||||
private void updateRoomHasPassword()
|
||||
{
|
||||
if (passwordIcon != null)
|
||||
passwordIcon.Alpha = Room.HasPassword ? 1 : 0;
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
{
|
||||
return new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent))
|
||||
|
@ -101,10 +101,10 @@ namespace osu.Game.Screens.OnlinePlay.Lounge.Components
|
||||
return true;
|
||||
|
||||
case RoomPermissionsFilter.Public:
|
||||
return !room.Room.HasPassword.Value;
|
||||
return !room.Room.HasPassword;
|
||||
|
||||
case RoomPermissionsFilter.Private:
|
||||
return room.Room.HasPassword.Value;
|
||||
return room.Room.HasPassword;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(accessType), accessType, $"Unsupported {nameof(RoomPermissionsFilter)} in filter");
|
||||
|
@ -185,7 +185,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Room.HasPassword.Value)
|
||||
if (Room.HasPassword)
|
||||
{
|
||||
this.ShowPopover();
|
||||
return true;
|
||||
|
@ -351,7 +351,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
|
||||
TypePicker.Current.BindValueChanged(type => typeLabel.Text = type.NewValue.GetLocalisableDescription(), true);
|
||||
MaxParticipants.BindValueChanged(count => MaxParticipantsField.Text = count.NewValue?.ToString(), true);
|
||||
Password.BindValueChanged(password => PasswordTextBox.Text = password.NewValue ?? string.Empty, true);
|
||||
AutoStartDuration.BindValueChanged(duration => startModeDropdown.Current.Value = (StartMode)(int)duration.NewValue.TotalSeconds, true);
|
||||
AutoSkip.BindValueChanged(autoSkip => AutoSkipCheckbox.Current.Value = autoSkip.NewValue, true);
|
||||
|
||||
@ -377,6 +376,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
updateRoomName();
|
||||
updateRoomType();
|
||||
updateRoomQueueMode();
|
||||
updateRoomPassword();
|
||||
}
|
||||
|
||||
private void onRoomPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
@ -394,6 +394,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
case nameof(Room.QueueMode):
|
||||
updateRoomQueueMode();
|
||||
break;
|
||||
|
||||
case nameof(Room.Password):
|
||||
updateRoomPassword();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -406,6 +410,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
private void updateRoomQueueMode()
|
||||
=> QueueModeDropdown.Current.Value = room.QueueMode;
|
||||
|
||||
private void updateRoomPassword()
|
||||
=> PasswordTextBox.Text = room.Password ?? string.Empty;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
@ -449,7 +456,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
|
||||
{
|
||||
room.Name = NameField.Text;
|
||||
room.Type = TypePicker.Current.Value;
|
||||
room.Password.Value = PasswordTextBox.Current.Value;
|
||||
room.Password = PasswordTextBox.Current.Value;
|
||||
room.QueueMode = QueueModeDropdown.Current.Value;
|
||||
room.AutoStartDuration.Value = autoStartDuration;
|
||||
room.AutoSkip.Value = AutoSkipCheckbox.Current.Value;
|
||||
|
@ -19,7 +19,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
private MultiplayerClient multiplayerClient { get; set; } = null!;
|
||||
|
||||
public override void CreateRoom(Room room, Action<Room>? onSuccess = null, Action<string>? onError = null)
|
||||
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, r.Password.Value, onSuccess, onError), onError);
|
||||
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, r.Password, onSuccess, onError), onError);
|
||||
|
||||
public override void JoinRoom(Room room, string? password = null, Action<Room>? onSuccess = null, Action<string>? onError = null)
|
||||
{
|
||||
|
@ -45,9 +45,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<DateTimeOffset?> EndDate { get; private set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
public Bindable<string> Password { get; private set; } = null!;
|
||||
|
||||
[Resolved(typeof(Room))]
|
||||
protected Bindable<TimeSpan?> Duration { get; private set; } = null!;
|
||||
|
||||
|
@ -216,7 +216,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
ServerAPIRoom = roomManager.ServerSideRooms.Single(r => r.RoomID == roomId);
|
||||
|
||||
if (password != ServerAPIRoom.Password.Value)
|
||||
if (password != ServerAPIRoom.Password)
|
||||
throw new InvalidOperationException("Invalid password.");
|
||||
|
||||
lastPlaylistItemId = ServerAPIRoom.Playlist.Max(item => item.ID);
|
||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
};
|
||||
|
||||
if (withPassword)
|
||||
room.Password.Value = @"password";
|
||||
room.Password = @"password";
|
||||
|
||||
if (ruleset != null)
|
||||
{
|
||||
|
@ -51,8 +51,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
var apiRoom = cloneRoom(createRoomRequest.Room);
|
||||
|
||||
// Passwords are explicitly not copied between rooms.
|
||||
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
||||
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
||||
apiRoom.Password = createRoomRequest.Room.Password;
|
||||
|
||||
AddServerSideRoom(apiRoom, localUser);
|
||||
|
||||
@ -66,7 +65,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
{
|
||||
var room = ServerSideRooms.Single(r => r.RoomID == joinRoomRequest.Room.RoomID);
|
||||
|
||||
if (joinRoomRequest.Password != room.Password.Value)
|
||||
if (joinRoomRequest.Password != room.Password)
|
||||
{
|
||||
joinRoomRequest.TriggerFailure(new InvalidOperationException("Invalid password."));
|
||||
return true;
|
||||
@ -278,9 +277,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
|
||||
var responseRoom = cloneRoom(room);
|
||||
|
||||
// Password is hidden from the response, and is only propagated via HasPassword.
|
||||
bool hadPassword = responseRoom.HasPassword.Value;
|
||||
responseRoom.Password.Value = null;
|
||||
responseRoom.HasPassword.Value = hadPassword;
|
||||
responseRoom.Password = responseRoom.HasPassword ? Guid.NewGuid().ToString() : null;
|
||||
|
||||
if (!withParticipants)
|
||||
responseRoom.RecentParticipants.Clear();
|
||||
|
Loading…
Reference in New Issue
Block a user