1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-27 15:53:19 +08:00

Isolate "server-side" multiplayer rooms in testing

This commit is contained in:
Dan Balasescu 2022-06-03 19:17:31 +09:00
parent 538ad1bc98
commit 646f5f0f33
2 changed files with 12 additions and 5 deletions

View File

@ -162,6 +162,13 @@ namespace osu.Game.Online.Rooms
Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue)); Password.BindValueChanged(p => HasPassword.Value = !string.IsNullOrEmpty(p.NewValue));
} }
/// <summary>
/// Copies values from another <see cref="Room"/> into this one.
/// </summary>
/// <remarks>
/// **Beware**: This will store references between <see cref="Room"/>s.
/// </remarks>
/// <param name="other">The <see cref="Room"/> to copy values from.</param>
public void CopyFrom(Room other) public void CopyFrom(Room other)
{ {
RoomID.Value = other.RoomID.Value; RoomID.Value = other.RoomID.Value;

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Newtonsoft.Json;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests;
@ -44,9 +45,7 @@ namespace osu.Game.Tests.Visual.OnlinePlay
switch (request) switch (request)
{ {
case CreateRoomRequest createRoomRequest: case CreateRoomRequest createRoomRequest:
var apiRoom = new Room(); var apiRoom = cloneRoom(createRoomRequest.Room);
apiRoom.CopyFrom(createRoomRequest.Room);
// Passwords are explicitly not copied between rooms. // Passwords are explicitly not copied between rooms.
apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value); apiRoom.HasPassword.Value = !string.IsNullOrEmpty(createRoomRequest.Room.Password.Value);
@ -178,12 +177,13 @@ namespace osu.Game.Tests.Visual.OnlinePlay
private Room createResponseRoom(Room room, bool withParticipants) private Room createResponseRoom(Room room, bool withParticipants)
{ {
var responseRoom = new Room(); var responseRoom = cloneRoom(room);
responseRoom.CopyFrom(room);
responseRoom.Password.Value = null; responseRoom.Password.Value = null;
if (!withParticipants) if (!withParticipants)
responseRoom.RecentParticipants.Clear(); responseRoom.RecentParticipants.Clear();
return responseRoom; return responseRoom;
} }
private Room cloneRoom(Room source) => JsonConvert.DeserializeObject<Room>(JsonConvert.SerializeObject(source));
} }
} }