1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Setup all multiplayer model classes for MessagePack support

This commit is contained in:
Dean Herbert 2021-01-26 16:26:03 +09:00
parent 60ae87ec38
commit e4fc604163
5 changed files with 34 additions and 4 deletions

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using Humanizer;
using MessagePack;
using Newtonsoft.Json;
using osu.Framework.Bindables;
using osu.Game.Configuration;
@ -13,16 +14,20 @@ using osu.Game.Rulesets.Mods;
namespace osu.Game.Online.API
{
[MessagePackObject]
public class APIMod : IMod
{
[JsonProperty("acronym")]
[Key(0)]
public string Acronym { get; set; }
[JsonProperty("settings")]
[Key(1)]
public Dictionary<string, object> Settings { get; set; } = new Dictionary<string, object>();
[JsonConstructor]
private APIMod()
[SerializationConstructor]
public APIMod()
{
}

View File

@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using MessagePack;
using Newtonsoft.Json;
namespace osu.Game.Online.Multiplayer
@ -13,35 +14,42 @@ namespace osu.Game.Online.Multiplayer
/// 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 List<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; }
[JsonConstructor]
public MultiplayerRoom(in long roomId)
[SerializationConstructor]
public MultiplayerRoom(long roomId)
{
RoomID = roomId;
}

View File

@ -7,22 +7,29 @@ using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using MessagePack;
using osu.Game.Online.API;
namespace osu.Game.Online.Multiplayer
{
[Serializable]
[MessagePackObject]
public class MultiplayerRoomSettings : IEquatable<MultiplayerRoomSettings>
{
[Key(0)]
public int BeatmapID { get; set; }
[Key(1)]
public int RulesetID { get; set; }
[Key(2)]
public string BeatmapChecksum { get; set; } = string.Empty;
[Key(3)]
public string Name { get; set; } = "Unnamed room";
[NotNull]
[Key(4)]
public IEnumerable<APIMod> Mods { get; set; } = Enumerable.Empty<APIMod>();
public bool Equals(MultiplayerRoomSettings other)

View File

@ -4,6 +4,7 @@
#nullable enable
using System;
using MessagePack;
using Newtonsoft.Json;
using osu.Game.Online.Rooms;
using osu.Game.Users;
@ -11,21 +12,26 @@ using osu.Game.Users;
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.LocallyAvailable();
[IgnoreMember]
public User? User { get; set; }
[JsonConstructor]
public MultiplayerRoomUser(in int userId)
public MultiplayerRoomUser(int userId)
{
UserID = userId;
}

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using MessagePack;
using Newtonsoft.Json;
namespace osu.Game.Online.Rooms
@ -9,20 +10,23 @@ namespace osu.Game.Online.Rooms
/// <summary>
/// The local availability information about a certain beatmap for the client.
/// </summary>
[MessagePackObject]
public class BeatmapAvailability : IEquatable<BeatmapAvailability>
{
/// <summary>
/// The beatmap's availability state.
/// </summary>
[Key(0)]
public readonly DownloadState State;
/// <summary>
/// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state.
/// </summary>
[Key(1)]
public readonly double? DownloadProgress;
[JsonConstructor]
private BeatmapAvailability(DownloadState state, double? downloadProgress = null)
public BeatmapAvailability(DownloadState state, double? downloadProgress = null)
{
State = state;
DownloadProgress = downloadProgress;