1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 13:37:25 +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));
}
/// <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)
{
RoomID.Value = other.RoomID.Value;

View File

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