1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-18 09:49:53 +08:00
Files
osu-lazer/osu.Game/Online/Multiplayer/MultiplayerRoomUser.cs
T
Bartłomiej Dach 5afd6c6835 Add user role to MultiplayerRoomUser (#36652)
- Related to https://github.com/ppy/osu-server-spectator/issues/406

Adding this field to this model has several vague reasons that I can't
fully formulate yet, but I can't really see myself going forward
*without* this.

- People were very excited about having referees displayed on the room
participants' list, and so adding the referees as real
`MultiplayerRoomUser`s helps this. Having the role could even be used
client-side to show a special icon or other status on the participants
list. (Which isn't done yet, could be as an aesthetic follow-up after
the basics are in place.)
- Server-side, having this field is convenient for things like
permission checks or just plain logic, as with two hubs you just need to
do different *stuff* on a `MultiplayerRoomUser`.
2026-02-12 00:57:03 +09:00

108 lines
2.9 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.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
[MessagePackObject]
public class MultiplayerRoomUser : IEquatable<MultiplayerRoomUser>
{
[Key(0)]
public readonly int UserID;
[Key(1)]
public MultiplayerUserState State { get; set; } = MultiplayerUserState.Idle;
/// <summary>
/// The availability state of the current beatmap.
/// </summary>
[Key(2)]
public BeatmapAvailability BeatmapAvailability { get; set; } = BeatmapAvailability.Unknown();
/// <summary>
/// Any mods applicable only to the local user.
/// </summary>
[Key(3)]
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
[Key(4)]
public MatchUserState? MatchState { get; set; }
/// <summary>
/// If not-null, a local override for this user's ruleset selection.
/// </summary>
[Key(5)]
public int? RulesetId;
/// <summary>
/// If not-null, a local override for this user's beatmap selection.
/// </summary>
[Key(6)]
public int? BeatmapId;
/// <summary>
/// Whether this user voted to skip the beatmap intro.
/// </summary>
[Key(7)]
public bool VotedToSkipIntro;
/// <summary>
/// The role of this user in the room.
/// </summary>
[Key(8)]
public MultiplayerRoomUserRole Role;
[IgnoreMember]
public APIUser? User { get; set; }
[JsonConstructor]
public MultiplayerRoomUser(int userId)
{
UserID = userId;
}
public bool Equals(MultiplayerRoomUser? other)
{
if (ReferenceEquals(this, other)) return true;
if (other == null) return false;
return UserID == other.UserID;
}
public override bool Equals(object? obj)
{
if (ReferenceEquals(this, obj)) return true;
if (obj?.GetType() != GetType()) return false;
return Equals((MultiplayerRoomUser)obj);
}
public override int GetHashCode() => UserID.GetHashCode();
/// <summary>
/// Whether this user has finished loading and can start gameplay.
/// </summary>
public bool CanStartGameplay()
{
switch (State)
{
case MultiplayerUserState.Loaded:
case MultiplayerUserState.ReadyForGameplay:
return true;
default:
return false;
}
}
}
}