mirror of
https://github.com/osukey/osukey.git
synced 2025-08-08 00:53:56 +09:00
Add request to add a new playlist item
This commit is contained in:
@ -4,6 +4,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
|
using osu.Game.Online.Multiplayer.Queueing;
|
||||||
|
|
||||||
namespace osu.Game.Online.Multiplayer
|
namespace osu.Game.Online.Multiplayer
|
||||||
{
|
{
|
||||||
@ -13,6 +14,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
[MessagePackObject]
|
[MessagePackObject]
|
||||||
[Union(0, typeof(ChangeTeamRequest))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
[Union(0, typeof(ChangeTeamRequest))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||||
|
[Union(1, typeof(AddPlaylistItemRequest))]
|
||||||
public abstract class MatchUserRequest
|
public abstract class MatchUserRequest
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,6 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
@ -212,39 +211,18 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <param name="name">The new room name, if any.</param>
|
/// <param name="name">The new room name, if any.</param>
|
||||||
/// <param name="password">The new password, if any.</param>
|
/// <param name="password">The new password, if any.</param>
|
||||||
/// <param name="matchType">The type of the match, if any.</param>
|
/// <param name="matchType">The type of the match, if any.</param>
|
||||||
/// <param name="item">The new room playlist item, if any.</param>
|
|
||||||
/// <param name="queueMode">The new queue mode, if any.</param>
|
/// <param name="queueMode">The new queue mode, if any.</param>
|
||||||
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<MatchType> matchType = default, Optional<PlaylistItem> item = default,
|
public Task ChangeSettings(Optional<string> name = default, Optional<string> password = default, Optional<MatchType> matchType = default, Optional<QueueModes> queueMode = default)
|
||||||
Optional<QueueModes> queueMode = default)
|
|
||||||
{
|
{
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
throw new InvalidOperationException("Must be joined to a match to change settings.");
|
||||||
|
|
||||||
// A dummy playlist item filled with the current room settings (except mods).
|
|
||||||
var existingPlaylistItem = new PlaylistItem
|
|
||||||
{
|
|
||||||
Beatmap =
|
|
||||||
{
|
|
||||||
Value = new BeatmapInfo
|
|
||||||
{
|
|
||||||
OnlineBeatmapID = Room.Settings.BeatmapID,
|
|
||||||
MD5Hash = Room.Settings.BeatmapChecksum
|
|
||||||
}
|
|
||||||
},
|
|
||||||
RulesetID = Room.Settings.RulesetID
|
|
||||||
};
|
|
||||||
|
|
||||||
return ChangeSettings(new MultiplayerRoomSettings
|
return ChangeSettings(new MultiplayerRoomSettings
|
||||||
{
|
{
|
||||||
Name = name.GetOr(Room.Settings.Name),
|
Name = name.GetOr(Room.Settings.Name),
|
||||||
Password = password.GetOr(Room.Settings.Password),
|
Password = password.GetOr(Room.Settings.Password),
|
||||||
BeatmapID = item.GetOr(existingPlaylistItem).BeatmapID,
|
|
||||||
BeatmapChecksum = item.GetOr(existingPlaylistItem).Beatmap.Value.MD5Hash,
|
|
||||||
RulesetID = item.GetOr(existingPlaylistItem).RulesetID,
|
|
||||||
MatchType = matchType.GetOr(Room.Settings.MatchType),
|
MatchType = matchType.GetOr(Room.Settings.MatchType),
|
||||||
QueueMode = queueMode.GetOr(Room.Settings.QueueMode),
|
QueueMode = queueMode.GetOr(Room.Settings.QueueMode),
|
||||||
RequiredMods = item.HasValue ? item.Value.AsNonNull().RequiredMods.Select(m => new APIMod(m)).ToList() : Room.Settings.RequiredMods,
|
|
||||||
AllowedMods = item.HasValue ? item.Value.AsNonNull().AllowedMods.Select(m => new APIMod(m)).ToList() : Room.Settings.AllowedMods,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using MessagePack;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Multiplayer.Queueing
|
||||||
|
{
|
||||||
|
public class AddPlaylistItemRequest : MatchUserRequest
|
||||||
|
{
|
||||||
|
[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 IEnumerable<APIMod> RequiredMods { get; set; } = Enumerable.Empty<APIMod>();
|
||||||
|
|
||||||
|
[Key(4)]
|
||||||
|
public IEnumerable<APIMod> AllowedMods { get; set; } = Enumerable.Empty<APIMod>();
|
||||||
|
}
|
||||||
|
}
|
@ -8,6 +8,7 @@ using MessagePack.Formatters;
|
|||||||
using MessagePack.Resolvers;
|
using MessagePack.Resolvers;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
using osu.Game.Online.Multiplayer.MatchTypes.TeamVersus;
|
||||||
|
using osu.Game.Online.Multiplayer.Queueing;
|
||||||
|
|
||||||
namespace osu.Game.Online
|
namespace osu.Game.Online
|
||||||
{
|
{
|
||||||
@ -25,6 +26,7 @@ namespace osu.Game.Online
|
|||||||
{ typeof(TeamVersusUserState), new TypeRedirectingFormatter<TeamVersusUserState, MatchUserState>() },
|
{ typeof(TeamVersusUserState), new TypeRedirectingFormatter<TeamVersusUserState, MatchUserState>() },
|
||||||
{ typeof(TeamVersusRoomState), new TypeRedirectingFormatter<TeamVersusRoomState, MatchRoomState>() },
|
{ typeof(TeamVersusRoomState), new TypeRedirectingFormatter<TeamVersusRoomState, MatchRoomState>() },
|
||||||
{ typeof(ChangeTeamRequest), new TypeRedirectingFormatter<ChangeTeamRequest, MatchUserRequest>() },
|
{ typeof(ChangeTeamRequest), new TypeRedirectingFormatter<ChangeTeamRequest, MatchUserRequest>() },
|
||||||
|
{ typeof(AddPlaylistItemRequest), new TypeRedirectingFormatter<AddPlaylistItemRequest, MatchUserRequest>() },
|
||||||
|
|
||||||
// These should not be required. The fallback should work. But something is weird with the way caching is done.
|
// These should not be required. The fallback should work. But something is weird with the way caching is done.
|
||||||
// For future adventurers, I would not advise looking into this further. It's likely not worth the effort.
|
// For future adventurers, I would not advise looking into this further. It's likely not worth the effort.
|
||||||
|
@ -1,12 +1,15 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Multiplayer.Queueing;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
@ -54,7 +57,14 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
{
|
{
|
||||||
loadingLayer.Show();
|
loadingLayer.Show();
|
||||||
|
|
||||||
client.ChangeSettings(item: item).ContinueWith(t =>
|
client.SendMatchRequest(new AddPlaylistItemRequest
|
||||||
|
{
|
||||||
|
BeatmapID = item.BeatmapID,
|
||||||
|
RulesetID = item.RulesetID,
|
||||||
|
BeatmapChecksum = item.Beatmap.Value.MD5Hash,
|
||||||
|
RequiredMods = item.RequiredMods.Select(m => new APIMod(m)).ToArray(),
|
||||||
|
AllowedMods = item.AllowedMods.Select(m => new APIMod(m)).ToArray()
|
||||||
|
}).ContinueWith(t =>
|
||||||
{
|
{
|
||||||
Schedule(() =>
|
Schedule(() =>
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user