1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-21 10:50:20 +08:00
Files
osu-lazer/osu.Game/Online/Multiplayer/MultiplayerRoom.cs
T
Bartłomiej Dach 31c1168d76 Adjust multiplayer logic to accommodate for referees spectating in-game (#37152)
- Last part of / closes
https://github.com/ppy/osu-server-spectator/issues/406.
- Remaining work on slots will be tracked in
https://github.com/ppy/osu-server-spectator/issues/405.

This PR is a corollary of
https://github.com/ppy/osu-server-spectator/pull/453 and all of the
dispensations referee users in a multiplayer have received therein. The
goal here is to allow access to all relevant room management functions
even if the referee in question isn't host, as well as to disallow
access to all non-relevant functions to do with the actual match
gameplay.

I'm not going to lie, this logic *is* ugly. I would argue that it
already *was* ugly on `master` and my goal was to operate with as light
a touch as possible myself. But you could see this as copping out and
that I should try to refactor some of this. I will try - but only after
someone else's seen the initial approach and deemed it unsuitable.

The logic in `MatchStartControl` is awful - there are so many moving
pieces of state that dictate what can happen when with all the buttons,
and yes, I am making it worse here.

This time there is some test coverage. Not everything is covered, but
the coverage should be on par in all components and pieces of relevant
logic I touched that already had tests covering them. On that note,
please forgive the diffstat size, but the tests *are* most of that size.

---------

Co-authored-by: Dean Herbert <pe@ppy.sh>
2026-04-03 19:38:44 +09:00

100 lines
3.3 KiB
C#

// 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;
using System.Collections.Generic;
using System.Linq;
using MessagePack;
using Newtonsoft.Json;
using osu.Game.Online.Rooms;
namespace osu.Game.Online.Multiplayer
{
/// <summary>
/// A multiplayer room.
/// </summary>
[Serializable]
[MessagePackObject]
public class MultiplayerRoom
{
/// <summary>
/// The ID of the room, used for database persistence.
/// </summary>
[Key(0)]
public readonly long RoomID;
/// <summary>
/// The current state of the room (ie. whether it is in progress or otherwise).
/// </summary>
[Key(1)]
public MultiplayerRoomState State { get; set; }
/// <summary>
/// All currently enforced game settings for this room.
/// </summary>
[Key(2)]
public MultiplayerRoomSettings Settings { get; set; } = new MultiplayerRoomSettings();
/// <summary>
/// All users currently in this room.
/// </summary>
[Key(3)]
public IList<MultiplayerRoomUser> Users { get; set; } = new List<MultiplayerRoomUser>();
/// <summary>
/// The host of this room, in control of changing room settings.
/// </summary>
[Key(4)]
public MultiplayerRoomUser? Host { get; set; }
[Key(5)]
public MatchRoomState? MatchState { get; set; }
[Key(6)]
public IList<MultiplayerPlaylistItem> Playlist { get; set; } = new List<MultiplayerPlaylistItem>();
/// <summary>
/// The currently running countdowns.
/// </summary>
[Key(7)]
public IList<MultiplayerCountdown> ActiveCountdowns { get; set; } = new List<MultiplayerCountdown>();
/// <summary>
/// The ID of the chat channel for the room.
/// </summary>
[Key(8)]
public int ChannelID { get; set; }
[JsonConstructor]
[SerializationConstructor]
public MultiplayerRoom(long roomId)
{
RoomID = roomId;
}
public MultiplayerRoom(Room room)
{
RoomID = room.RoomID ?? 0;
ChannelID = room.ChannelId;
Settings = new MultiplayerRoomSettings(room);
Host = room.Host != null ? new MultiplayerRoomUser(room.Host.OnlineID) : null;
Playlist = room.Playlist.Select(p => new MultiplayerPlaylistItem(p)).ToArray();
}
/// <summary>
/// Retrieves the active <see cref="MultiplayerPlaylistItem"/> as determined by the room's current settings.
/// </summary>
[IgnoreMember]
[JsonIgnore]
public MultiplayerPlaylistItem CurrentPlaylistItem => Playlist.Single(item => item.ID == Settings.PlaylistItemId);
/// <summary>
/// Determines whether a user is able to add playlist items to this room.
/// </summary>
/// <param name="user">The user to check.</param>
public bool CanAddPlaylistItems(MultiplayerRoomUser user) => user.Equals(Host) || user.Role == MultiplayerRoomUserRole.Referee || Settings.QueueMode != QueueMode.HostOnly;
public override string ToString() => $"RoomID:{RoomID} Host:{Host?.UserID} Users:{Users.Count} State:{State} Settings: [{Settings}]";
}
}