Refactor RequestHandlingMultiplayerRoomManager to avoid confusion

This commit is contained in:
smoogipoo 2021-08-17 09:42:17 +09:00
parent 1e282432c9
commit b672d4b936
3 changed files with 12 additions and 18 deletions

View File

@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("create room", () =>
{
multiplayerScreen.RoomManager.AddRoom(new Room
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
{
Name = { Value = "Test Room" },
Playlist =
@ -164,7 +164,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("create room", () =>
{
multiplayerScreen.RoomManager.AddRoom(new Room
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
{
Name = { Value = "Test Room" },
Playlist =
@ -213,7 +213,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddStep("create room", () =>
{
multiplayerScreen.RoomManager.AddRoom(new Room
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
{
Name = { Value = "Test Room" },
Password = { Value = "password" },

View File

@ -127,7 +127,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
protected override Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
{
var apiRoom = roomManager.Rooms.Single(r => r.RoomID.Value == roomId);
var apiRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == roomId);
if (password != apiRoom.Password.Value)
throw new InvalidOperationException("Invalid password.");
@ -260,7 +260,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
Debug.Assert(Room != null);
var apiRoom = roomManager.Rooms.Single(r => r.RoomID.Value == Room.RoomID);
var apiRoom = roomManager.ServerSideRooms.Single(r => r.RoomID.Value == Room.RoomID);
var set = apiRoom.Playlist.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;

View File

@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
[Resolved]
private OsuGameBase game { get; set; }
public new readonly List<Room> Rooms = new List<Room>();
public readonly List<Room> ServerSideRooms = new List<Room>();
private int currentRoomId;
private int currentPlaylistItemId;
@ -55,7 +55,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
AddRoom(apiRoom);
AddServerSideRoom(apiRoom);
var responseRoom = new APICreatedRoom();
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
case JoinRoomRequest joinRoomRequest:
{
var room = Rooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
var room = ServerSideRooms.Single(r => r.RoomID.Value == joinRoomRequest.Room.RoomID.Value);
if (joinRoomRequest.Password != room.Password.Value)
{
@ -84,14 +84,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
case GetRoomsRequest getRoomsRequest:
var roomsWithoutParticipants = new List<Room>();
foreach (var r in Rooms)
foreach (var r in ServerSideRooms)
roomsWithoutParticipants.Add(createResponseRoom(r, false));
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
return true;
case GetRoomRequest getRoomRequest:
getRoomRequest.TriggerSuccess(createResponseRoom(Rooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
getRoomRequest.TriggerSuccess(createResponseRoom(ServerSideRooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId), true));
return true;
case GetBeatmapSetRequest getBeatmapSetRequest:
@ -127,17 +127,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
};
}
public void AddRoom(Room room)
public void AddServerSideRoom(Room room)
{
room.RoomID.Value ??= currentRoomId++;
for (int i = 0; i < room.Playlist.Count; i++)
room.Playlist[i].ID = currentPlaylistItemId++;
Rooms.Add(room);
ServerSideRooms.Add(room);
}
public new void RemoveRoom(Room room) => base.RemoveRoom(room);
private Room createResponseRoom(Room room, bool withParticipants)
{
var responseRoom = new Room();
@ -147,9 +145,5 @@ namespace osu.Game.Tests.Visual.Multiplayer
responseRoom.RecentParticipants.Clear();
return responseRoom;
}
public new void ClearRooms() => base.ClearRooms();
public new void Schedule(Action action) => base.Schedule(action);
}
}