mirror of
https://github.com/ppy/osu
synced 2024-12-14 02:46:27 +00:00
Refactor RequestHandlingMultiplayerRoomManager to avoid confusion
This commit is contained in:
parent
1e282432c9
commit
b672d4b936
@ -134,7 +134,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.RoomManager.AddRoom(new Room
|
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Playlist =
|
Playlist =
|
||||||
@ -164,7 +164,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.RoomManager.AddRoom(new Room
|
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Playlist =
|
Playlist =
|
||||||
@ -213,7 +213,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
AddStep("create room", () =>
|
AddStep("create room", () =>
|
||||||
{
|
{
|
||||||
multiplayerScreen.RoomManager.AddRoom(new Room
|
multiplayerScreen.RoomManager.AddServerSideRoom(new Room
|
||||||
{
|
{
|
||||||
Name = { Value = "Test Room" },
|
Name = { Value = "Test Room" },
|
||||||
Password = { Value = "password" },
|
Password = { Value = "password" },
|
||||||
|
@ -127,7 +127,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
protected override Task<MultiplayerRoom> JoinRoom(long roomId, string? password = null)
|
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)
|
if (password != apiRoom.Password.Value)
|
||||||
throw new InvalidOperationException("Invalid password.");
|
throw new InvalidOperationException("Invalid password.");
|
||||||
@ -260,7 +260,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
Debug.Assert(Room != null);
|
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
|
var set = apiRoom.Playlist.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
||||||
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;
|
?? beatmaps.QueryBeatmap(b => b.OnlineBeatmapID == beatmapId)?.BeatmapSet;
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private OsuGameBase game { get; set; }
|
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 currentRoomId;
|
||||||
private int currentPlaylistItemId;
|
private int currentPlaylistItemId;
|
||||||
@ -55,7 +55,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
|
||||||
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
apiRoom.Password.Value = createRoomRequest.Room.Password.Value;
|
||||||
|
|
||||||
AddRoom(apiRoom);
|
AddServerSideRoom(apiRoom);
|
||||||
|
|
||||||
var responseRoom = new APICreatedRoom();
|
var responseRoom = new APICreatedRoom();
|
||||||
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
responseRoom.CopyFrom(createResponseRoom(apiRoom, false));
|
||||||
@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
case JoinRoomRequest joinRoomRequest:
|
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)
|
if (joinRoomRequest.Password != room.Password.Value)
|
||||||
{
|
{
|
||||||
@ -84,14 +84,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
case GetRoomsRequest getRoomsRequest:
|
case GetRoomsRequest getRoomsRequest:
|
||||||
var roomsWithoutParticipants = new List<Room>();
|
var roomsWithoutParticipants = new List<Room>();
|
||||||
|
|
||||||
foreach (var r in Rooms)
|
foreach (var r in ServerSideRooms)
|
||||||
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
roomsWithoutParticipants.Add(createResponseRoom(r, false));
|
||||||
|
|
||||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
case GetRoomRequest getRoomRequest:
|
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;
|
return true;
|
||||||
|
|
||||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
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++;
|
room.RoomID.Value ??= currentRoomId++;
|
||||||
for (int i = 0; i < room.Playlist.Count; i++)
|
for (int i = 0; i < room.Playlist.Count; i++)
|
||||||
room.Playlist[i].ID = currentPlaylistItemId++;
|
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)
|
private Room createResponseRoom(Room room, bool withParticipants)
|
||||||
{
|
{
|
||||||
var responseRoom = new Room();
|
var responseRoom = new Room();
|
||||||
@ -147,9 +145,5 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
responseRoom.RecentParticipants.Clear();
|
responseRoom.RecentParticipants.Clear();
|
||||||
return responseRoom;
|
return responseRoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public new void ClearRooms() => base.ClearRooms();
|
|
||||||
|
|
||||||
public new void Schedule(Action action) => base.Schedule(action);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user