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.
|
|
|
|
|
2020-12-08 15:15:51 +08:00
|
|
|
#nullable enable
|
|
|
|
|
2020-12-04 14:34:31 +08:00
|
|
|
using System;
|
2020-12-07 17:50:02 +08:00
|
|
|
using System.Collections.Generic;
|
2020-12-08 16:42:08 +08:00
|
|
|
using JetBrains.Annotations;
|
2020-12-04 14:34:31 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Online.RealtimeMultiplayer
|
|
|
|
{
|
2020-12-08 15:02:35 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A multiplayer room.
|
|
|
|
/// </summary>
|
2020-12-04 14:34:31 +08:00
|
|
|
[Serializable]
|
|
|
|
public class MultiplayerRoom
|
|
|
|
{
|
2020-12-08 14:54:52 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The ID of the room, used for database persistence.
|
|
|
|
/// </summary>
|
2020-12-08 15:44:47 +08:00
|
|
|
public readonly long RoomID;
|
2020-12-04 14:34:31 +08:00
|
|
|
|
2020-12-08 14:54:52 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The current state of the room (ie. whether it is in progress or otherwise).
|
|
|
|
/// </summary>
|
2020-12-04 14:34:31 +08:00
|
|
|
public MultiplayerRoomState State { get; set; }
|
2020-12-07 17:50:02 +08:00
|
|
|
|
2020-12-08 14:54:52 +08:00
|
|
|
/// <summary>
|
|
|
|
/// All currently enforced game settings for this room.
|
|
|
|
/// </summary>
|
2020-12-08 15:15:51 +08:00
|
|
|
public MultiplayerRoomSettings Settings { get; set; } = MultiplayerRoomSettings.Empty();
|
2020-12-08 13:33:38 +08:00
|
|
|
|
2020-12-08 14:54:52 +08:00
|
|
|
/// <summary>
|
2020-12-08 15:02:35 +08:00
|
|
|
/// All users currently in this room.
|
2020-12-08 14:54:52 +08:00
|
|
|
/// </summary>
|
2020-12-08 15:02:35 +08:00
|
|
|
public List<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
|
2020-12-08 14:46:11 +08:00
|
|
|
|
2020-12-08 15:15:51 +08:00
|
|
|
/// <summary>
|
|
|
|
/// The host of this room, in control of changing room settings.
|
|
|
|
/// </summary>
|
|
|
|
public MultiplayerRoomUser? Host { get; set; }
|
|
|
|
|
2020-12-08 15:02:35 +08:00
|
|
|
private object writeLock = new object();
|
2020-12-08 14:46:11 +08:00
|
|
|
|
2020-12-08 15:44:47 +08:00
|
|
|
public MultiplayerRoom(in long roomId)
|
|
|
|
{
|
|
|
|
RoomID = roomId;
|
|
|
|
}
|
|
|
|
|
2020-12-08 14:46:11 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Perform an update on this room in a thread-safe manner.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="action">The action to perform.</param>
|
2020-12-08 16:42:08 +08:00
|
|
|
public void PerformUpdate([InstantHandle] Action<MultiplayerRoom> action)
|
2020-12-08 14:46:11 +08:00
|
|
|
{
|
|
|
|
lock (writeLock) action(this);
|
2020-12-08 00:24:38 +08:00
|
|
|
}
|
2020-12-04 14:34:31 +08:00
|
|
|
}
|
|
|
|
}
|