2020-12-04 14:34:31 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using System;
|
2020-12-07 17:50:02 +08:00
|
|
|
using System.Collections.Generic;
|
2020-12-04 14:34:31 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Online.RealtimeMultiplayer
|
|
|
|
{
|
|
|
|
[Serializable]
|
|
|
|
public class MultiplayerRoom
|
|
|
|
{
|
2020-12-08 00:24:38 +08:00
|
|
|
private object writeLock = new object();
|
|
|
|
|
2020-12-04 14:34:31 +08:00
|
|
|
public long RoomID { get; set; }
|
|
|
|
|
|
|
|
public MultiplayerRoomState State { get; set; }
|
2020-12-07 17:50:02 +08:00
|
|
|
|
2020-12-08 13:33:38 +08:00
|
|
|
public MultiplayerRoomSettings Settings { get; set; }
|
|
|
|
|
2020-12-07 17:50:02 +08:00
|
|
|
private List<MultiplayerRoomUser> users = new List<MultiplayerRoomUser>();
|
|
|
|
|
2020-12-08 00:24:38 +08:00
|
|
|
public IReadOnlyList<MultiplayerRoomUser> Users
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
lock (writeLock)
|
|
|
|
return users.ToArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-08 00:35:29 +08:00
|
|
|
public MultiplayerRoomUser Join(int userId)
|
2020-12-08 00:24:38 +08:00
|
|
|
{
|
2020-12-08 00:35:29 +08:00
|
|
|
var user = new MultiplayerRoomUser(userId);
|
|
|
|
lock (writeLock) users.Add(user);
|
|
|
|
return user;
|
2020-12-08 00:24:38 +08:00
|
|
|
}
|
2020-12-07 17:50:02 +08:00
|
|
|
|
2020-12-08 00:35:29 +08:00
|
|
|
public MultiplayerRoomUser Leave(int userId)
|
2020-12-08 00:24:38 +08:00
|
|
|
{
|
|
|
|
lock (writeLock)
|
2020-12-08 00:35:29 +08:00
|
|
|
{
|
|
|
|
var user = users.Find(u => u.UserID == userId);
|
|
|
|
|
|
|
|
if (user == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
users.Remove(user);
|
|
|
|
return user;
|
|
|
|
}
|
2020-12-08 00:24:38 +08:00
|
|
|
}
|
2020-12-04 14:34:31 +08:00
|
|
|
}
|
|
|
|
}
|