mirror of
https://github.com/ppy/osu.git
synced 2025-01-19 02:52:54 +08:00
7268b2e077
It proved to be too difficult to deal with the flow that clears user states on stopping the watching of global presence updates. It's not helped in the least that friends are updated via the API, so there's a third flow to consider (and the timings therein - both server-spectator and friends are updated concurrently). Simplest is to separate the friends flow, though this does mean some logic and state duplication.
110 lines
3.4 KiB
C#
110 lines
3.4 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.Linq;
|
|
using System.Threading.Tasks;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Graphics;
|
|
using osu.Game.Users;
|
|
|
|
namespace osu.Game.Online.Metadata
|
|
{
|
|
public abstract partial class MetadataClient : Component, IMetadataClient, IMetadataServer
|
|
{
|
|
public abstract IBindable<bool> IsConnected { get; }
|
|
|
|
#region Beatmap metadata updates
|
|
|
|
public abstract Task<BeatmapUpdates> GetChangesSince(int queueId);
|
|
|
|
public abstract Task BeatmapSetsUpdated(BeatmapUpdates updates);
|
|
|
|
public event Action<int[]>? ChangedBeatmapSetsArrived;
|
|
|
|
protected Task ProcessChanges(int[] beatmapSetIDs)
|
|
{
|
|
ChangedBeatmapSetsArrived?.Invoke(beatmapSetIDs.Distinct().ToArray());
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region User presence updates
|
|
|
|
/// <summary>
|
|
/// Whether the client is currently receiving user presence updates from the server.
|
|
/// </summary>
|
|
public abstract IBindable<bool> IsWatchingUserPresence { get; }
|
|
|
|
/// <summary>
|
|
/// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online users received from the server.
|
|
/// </summary>
|
|
public abstract IBindableDictionary<int, UserPresence> UserStates { get; }
|
|
|
|
/// <summary>
|
|
/// Dictionary keyed by user ID containing all of the <see cref="UserPresence"/> information about currently online friends received from the server.
|
|
/// </summary>
|
|
public abstract IBindableDictionary<int, UserPresence> FriendStates { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task UpdateActivity(UserActivity? activity);
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task UpdateStatus(UserStatus? status);
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task BeginWatchingUserPresence();
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task EndWatchingUserPresence();
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task UserPresenceUpdated(int userId, UserPresence? presence);
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task FriendPresenceUpdated(int userId, UserPresence? presence);
|
|
|
|
#endregion
|
|
|
|
#region Daily Challenge
|
|
|
|
public abstract IBindable<DailyChallengeInfo?> DailyChallengeInfo { get; }
|
|
|
|
/// <inheritdoc/>
|
|
public abstract Task DailyChallengeUpdated(DailyChallengeInfo? info);
|
|
|
|
#endregion
|
|
|
|
#region Multiplayer room watching
|
|
|
|
public abstract Task<MultiplayerPlaylistItemStats[]> BeginWatchingMultiplayerRoom(long id);
|
|
|
|
public abstract Task EndWatchingMultiplayerRoom(long id);
|
|
|
|
public event Action<MultiplayerRoomScoreSetEvent>? MultiplayerRoomScoreSet;
|
|
|
|
Task IMetadataClient.MultiplayerRoomScoreSet(MultiplayerRoomScoreSetEvent roomScoreSetEvent)
|
|
{
|
|
if (MultiplayerRoomScoreSet != null)
|
|
Schedule(MultiplayerRoomScoreSet, roomScoreSetEvent);
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Disconnection handling
|
|
|
|
public event Action? Disconnecting;
|
|
|
|
public virtual Task DisconnectRequested()
|
|
{
|
|
Schedule(() => Disconnecting?.Invoke());
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|