mirror of
https://github.com/ppy/osu
synced 2025-01-25 07:13:22 +00:00
Ensure room is locked when mutating users
This commit is contained in:
parent
8ebdb5723b
commit
fdf025942b
@ -9,16 +9,33 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
||||
[Serializable]
|
||||
public class MultiplayerRoom
|
||||
{
|
||||
private object writeLock = new object();
|
||||
|
||||
public long RoomID { get; set; }
|
||||
|
||||
public MultiplayerRoomState State { get; set; }
|
||||
|
||||
public IReadOnlyList<MultiplayerRoomUser> Users => users;
|
||||
|
||||
private List<MultiplayerRoomUser> users = new List<MultiplayerRoomUser>();
|
||||
|
||||
public void Join(int user) => users.Add(new MultiplayerRoomUser(user));
|
||||
public IReadOnlyList<MultiplayerRoomUser> Users
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (writeLock)
|
||||
return users.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public void Leave(int user) => users.RemoveAll(u => u.UserID == user);
|
||||
public void Join(int user)
|
||||
{
|
||||
lock (writeLock)
|
||||
users.Add(new MultiplayerRoomUser(user));
|
||||
}
|
||||
|
||||
public void Leave(int user)
|
||||
{
|
||||
lock (writeLock)
|
||||
users.RemoveAll(u => u.UserID == user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user