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

Create, join, and part multiplayer rooms only via the multiplayer server #31637

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using osu.Framework.Testing;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Rooms;
using osu.Game.Tests.Visual.Multiplayer;

namespace osu.Game.Tests.NonVisual.Multiplayer
Expand Down Expand Up @@ -72,10 +71,6 @@ public void TestPlayingUsersUpdatedOnJoin()

AddStep("create room initially in gameplay", () =>
{
var newRoom = new Room();
newRoom.CopyFrom(SelectedRoom.Value!);

newRoom.RoomID = null;
MultiplayerClient.RoomSetupAction = room =>
{
room.State = MultiplayerRoomState.Playing;
Expand All @@ -86,7 +81,7 @@ public void TestPlayingUsersUpdatedOnJoin()
});
};

RoomManager.CreateRoom(newRoom);
MultiplayerClient.JoinRoom(MultiplayerClient.ServerSideRooms.Single()).ConfigureAwait(false);
});

AddUntilStep("wait for room join", () => RoomJoined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public partial class TestSceneDrawableLoungeRoom : OsuManualInputManagerTestScen
[BackgroundDependencyLoader]
private void load()
{
var mockLounge = new Mock<LoungeSubScreen>();
var mockLounge = new Mock<IOnlinePlayLounge>();
mockLounge
.Setup(l => l.Join(It.IsAny<Room>(), It.IsAny<string>(), It.IsAny<Action<Room>>(), It.IsAny<Action<string>>()))
.Callback<Room, string, Action<Room>, Action<string>>((_, _, _, d) =>
Expand Down
15 changes: 7 additions & 8 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneMultiplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public partial class TestSceneMultiplayer : ScreenTestScene
private TestMultiplayerComponents multiplayerComponents = null!;

private TestMultiplayerClient multiplayerClient => multiplayerComponents.MultiplayerClient;
private TestMultiplayerRoomManager roomManager => multiplayerComponents.RoomManager;

[Resolved]
private OsuConfigManager config { get; set; } = null!;
Expand Down Expand Up @@ -257,7 +256,7 @@ public void TestExitMidJoin()
{
AddStep("create room", () =>
{
roomManager.AddServerSideRoom(new Room
multiplayerClient.AddServerSideRoom(new Room
{
Name = "Test Room",
Playlist =
Expand Down Expand Up @@ -286,7 +285,7 @@ public void TestJoinRoomWithoutPassword()
{
AddStep("create room", () =>
{
roomManager.AddServerSideRoom(new Room
multiplayerClient.AddServerSideRoom(new Room
{
Name = "Test Room",
Playlist =
Expand Down Expand Up @@ -336,7 +335,7 @@ public void TestJoinRoomWithPassword()
{
AddStep("create room", () =>
{
roomManager.AddServerSideRoom(new Room
multiplayerClient.AddServerSideRoom(new Room
{
Name = "Test Room",
Password = "password",
Expand Down Expand Up @@ -789,7 +788,7 @@ public void TestRoomSettingsReQueriedWhenJoiningRoom()
{
AddStep("create room", () =>
{
roomManager.AddServerSideRoom(new Room
multiplayerClient.AddServerSideRoom(new Room
{
Name = "Test Room",
QueueMode = QueueMode.AllPlayers,
Expand All @@ -810,8 +809,8 @@ public void TestRoomSettingsReQueriedWhenJoiningRoom()
AddStep("disable polling", () => this.ChildrenOfType<ListingPollingComponent>().Single().TimeBetweenPolls.Value = 0);
AddStep("change server-side settings", () =>
{
roomManager.ServerSideRooms[0].Name = "New name";
roomManager.ServerSideRooms[0].Playlist =
multiplayerClient.ServerSideRooms[0].Name = "New name";
multiplayerClient.ServerSideRooms[0].Playlist =
[
new PlaylistItem(beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.Ruleset.OnlineID == 0)).BeatmapInfo)
{
Expand All @@ -828,7 +827,7 @@ public void TestRoomSettingsReQueriedWhenJoiningRoom()
AddAssert("local room has correct settings", () =>
{
var localRoom = this.ChildrenOfType<MultiplayerMatchSubScreen>().Single().Room;
return localRoom.Name == roomManager.ServerSideRooms[0].Name && localRoom.Playlist.Single().ID == 2;
return localRoom.Name == multiplayerClient.ServerSideRooms[0].Name && localRoom.Playlist.Single().ID == 2;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,33 @@
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
using osu.Game.Screens.OnlinePlay.Multiplayer;
using osu.Game.Tests.Visual.OnlinePlay;
using osuTK.Input;

namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneMultiplayerLoungeSubScreen : OnlinePlayTestScene
public partial class TestSceneMultiplayerLoungeSubScreen : MultiplayerTestScene
{
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;

private LoungeSubScreen loungeScreen = null!;
private Room? lastJoinedRoom;
private string? lastJoinedPassword;

private RoomsContainer roomsContainer => loungeScreen.ChildrenOfType<RoomsContainer>().First();

public TestSceneMultiplayerLoungeSubScreen()
: base(false)
{
}

public override void SetUpSteps()
{
base.SetUpSteps();

AddStep("push screen", () => LoadScreen(loungeScreen = new MultiplayerLoungeSubScreen()));

AddUntilStep("wait for present", () => loungeScreen.IsCurrentScreen());

AddStep("bind to event", () =>
{
lastJoinedRoom = null;
lastJoinedPassword = null;
RoomManager.JoinRoomRequested = onRoomJoined;
});
}

[Test]
Expand All @@ -47,8 +44,7 @@ public void TestJoinRoomWithoutPassword()
AddStep("select room", () => InputManager.Key(Key.Down));
AddStep("join room", () => InputManager.Key(Key.Enter));

AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
AddAssert("room join password correct", () => lastJoinedPassword == null);
AddAssert("room joined", () => MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -67,6 +63,8 @@ public void TestPopoverHidesOnBackButton()

AddStep("hit escape", () => InputManager.Key(Key.Escape));
AddUntilStep("password prompt hidden", () => !InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());

AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -79,6 +77,8 @@ public void TestPopoverHidesOnLeavingScreen()
AddUntilStep("password prompt appeared", () => InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());
AddStep("exit screen", () => Stack.Exit());
AddUntilStep("password prompt hidden", () => !InputManager.ChildrenOfType<DrawableLoungeRoom.PasswordEntryPopover>().Any());

AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -93,9 +93,11 @@ public void TestJoinRoomWithIncorrectPasswordViaButton()
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "wrong");
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());

AddAssert("room not joined", () => loungeScreen.IsCurrentScreen());
AddAssert("still at lounge", () => loungeScreen.IsCurrentScreen());
AddUntilStep("password prompt still visible", () => passwordEntryPopover!.State.Value == Visibility.Visible);
AddAssert("textbox still focused", () => InputManager.FocusedDrawable is OsuPasswordTextBox);

AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -110,9 +112,11 @@ public void TestJoinRoomWithIncorrectPasswordViaEnter()
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "wrong");
AddStep("press enter", () => InputManager.Key(Key.Enter));

AddAssert("room not joined", () => loungeScreen.IsCurrentScreen());
AddAssert("still at lounge", () => loungeScreen.IsCurrentScreen());
AddUntilStep("password prompt still visible", () => passwordEntryPopover!.State.Value == Visibility.Visible);
AddAssert("textbox still focused", () => InputManager.FocusedDrawable is OsuPasswordTextBox);

AddAssert("room not joined", () => !MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -127,8 +131,7 @@ public void TestJoinRoomWithCorrectPassword()
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
AddStep("press join room button", () => passwordEntryPopover.ChildrenOfType<OsuButton>().First().TriggerClick());

AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
AddAssert("room join password correct", () => lastJoinedPassword == "password");
AddUntilStep("room joined", () => MultiplayerClient.RoomJoined);
}

[Test]
Expand All @@ -143,14 +146,9 @@ public void TestJoinRoomWithPasswordViaKeyboardOnly()
AddStep("enter password in text box", () => passwordEntryPopover.ChildrenOfType<TextBox>().First().Text = "password");
AddStep("press enter", () => InputManager.Key(Key.Enter));

AddAssert("room join requested", () => lastJoinedRoom == RoomManager.Rooms.First());
AddAssert("room join password correct", () => lastJoinedPassword == "password");
AddAssert("room joined", () => MultiplayerClient.RoomJoined);
}

private void onRoomJoined(Room room, string? password)
{
lastJoinedRoom = room;
lastJoinedPassword = password;
}
protected override OnlinePlayTestSceneDependencies CreateOnlinePlayDependencies() => new MultiplayerTestSceneDependencies();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void TestListsClearedWhenRoomLeft()
addItemStep();
AddStep("finish current item", () => MultiplayerClient.FinishCurrentItem().WaitSafely());

AddStep("leave room", () => RoomManager.PartRoom());
AddStep("leave room", () => MultiplayerClient.LeaveRoom());
AddUntilStep("wait for room part", () => !RoomJoined);

AddUntilStep("item 0 not in lists", () => !inHistoryList(0) && !inQueueList(0));
Expand All @@ -148,7 +148,7 @@ public void TestQueueTabCount()
AddStep("finish current item", () => MultiplayerClient.FinishCurrentItem().WaitSafely());
assertQueueTabCount(2);

AddStep("leave room", () => RoomManager.PartRoom());
AddStep("leave room", () => MultiplayerClient.LeaveRoom());
AddUntilStep("wait for room part", () => !RoomJoined);
assertQueueTabCount(0);
}
Expand All @@ -157,12 +157,12 @@ public void TestQueueTabCount()
[Test]
public void TestJoinRoomWithMixedItemsAddedInCorrectLists()
{
AddStep("leave room", () => RoomManager.PartRoom());
AddStep("leave room", () => MultiplayerClient.LeaveRoom());
AddUntilStep("wait for room part", () => !RoomJoined);

AddStep("join room with items", () =>
{
RoomManager.CreateRoom(new Room
API.Queue(new CreateRoomRequest(new Room
{
Name = "test name",
Playlist =
Expand All @@ -177,7 +177,7 @@ public void TestJoinRoomWithMixedItemsAddedInCorrectLists()
Expired = true
}
]
});
}));
});

AddUntilStep("wait for room join", () => RoomJoined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public override void SetUpSteps()
public void TestManyRooms()
{
AddStep("add rooms", () => RoomManager.AddRooms(500));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 500);
}

[Test]
Expand Down Expand Up @@ -75,6 +76,7 @@ public void TestScrollSelectedIntoView()
public void TestEnteringRoomTakesLeaseOnSelection()
{
AddStep("add rooms", () => RoomManager.AddRooms(1));
AddUntilStep("wait for rooms", () => roomsContainer.Rooms.Count == 1);

AddAssert("selected room is not disabled", () => !loungeScreen.SelectedRoom.Disabled);

Expand Down
Loading
Loading