1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 09:42:54 +08:00

Move business logic out of MultiplayerRoom

This commit is contained in:
Dean Herbert 2020-12-08 16:02:35 +09:00
parent 42b1e9d6a4
commit 2365d65610

View File

@ -6,6 +6,9 @@ using System.Collections.Generic;
namespace osu.Game.Online.RealtimeMultiplayer
{
/// <summary>
/// A multiplayer room.
/// </summary>
[Serializable]
public class MultiplayerRoom
{
@ -24,50 +27,13 @@ namespace osu.Game.Online.RealtimeMultiplayer
/// </summary>
public MultiplayerRoomSettings Settings { get; set; }
private List<MultiplayerRoomUser> users = new List<MultiplayerRoomUser>();
/// <summary>
/// All users currently in this room.
/// </summary>
public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
private object writeLock = new object();
/// <summary>
/// All users which are currently in this room, in any state.
/// </summary>
public IReadOnlyList<MultiplayerRoomUser> Users
{
get
{
lock (writeLock)
return users.ToArray();
}
}
/// <summary>
/// Join a new user to this room.
/// </summary>
public MultiplayerRoomUser Join(int userId)
{
var user = new MultiplayerRoomUser(userId);
PerformUpdate(_ => users.Add(user));
return user;
}
/// <summary>
/// Remove a user from this room.
/// </summary>
public MultiplayerRoomUser Leave(int userId)
{
MultiplayerRoomUser user = null;
PerformUpdate(_ =>
{
user = users.Find(u => u.UserID == userId);
if (user != null)
users.Remove(user);
});
return user;
}
/// <summary>
/// Perform an update on this room in a thread-safe manner.
/// </summary>