Skip to content

Commit

Permalink
Merge pull request #28194 from bdach/daily-challenge-models
Browse files Browse the repository at this point in the history
Add client/server models & operations for "daily challenge" feature
  • Loading branch information
peppy authored May 22, 2024
2 parents 20a539b + 61a415f commit 3a608aa
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
16 changes: 16 additions & 0 deletions osu.Game/Online/Metadata/DailyChallengeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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 MessagePack;

namespace osu.Game.Online.Metadata
{
[MessagePackObject]
[Serializable]
public struct DailyChallengeInfo
{
[Key(0)]
public long RoomID { get; set; }
}
}
6 changes: 6 additions & 0 deletions osu.Game/Online/Metadata/IMetadataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ public interface IMetadataClient : IStatefulUserHubClient
/// Delivers an update of the <see cref="UserPresence"/> of the user with the supplied <paramref name="userId"/>.
/// </summary>
Task UserPresenceUpdated(int userId, UserPresence? status);

/// <summary>
/// Delivers an update of the current "daily challenge" status.
/// Null value means there is no "daily challenge" currently active.
/// </summary>
Task DailyChallengeUpdated(DailyChallengeInfo? info);
}
}
7 changes: 6 additions & 1 deletion osu.Game/Online/Metadata/IMetadataServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
namespace osu.Game.Online.Metadata
{
/// <summary>
/// Metadata server is responsible for keeping the osu! client up-to-date with any changes.
/// Metadata server is responsible for keeping the osu! client up-to-date with various real-time happenings, such as:
/// <list type="bullet">
/// <item>beatmap updates via BSS,</item>
/// <item>online user activity/status updates,</item>
/// <item>other real-time happenings, such as current "daily challenge" status.</item>
/// </list>
/// </summary>
public interface IMetadataServer
{
Expand Down
9 changes: 9 additions & 0 deletions osu.Game/Online/Metadata/MetadataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ protected Task ProcessChanges(int[] beatmapSetIDs)

#endregion

#region Daily Challenge

public abstract IBindable<DailyChallengeInfo?> DailyChallengeInfo { get; }

/// <inheritdoc/>
public abstract Task DailyChallengeUpdated(DailyChallengeInfo? info);

#endregion

#region Disconnection handling

public event Action? Disconnecting;
Expand Down
11 changes: 11 additions & 0 deletions osu.Game/Online/Metadata/OnlineMetadataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public partial class OnlineMetadataClient : MetadataClient
public override IBindableDictionary<int, UserPresence> UserStates => userStates;
private readonly BindableDictionary<int, UserPresence> userStates = new BindableDictionary<int, UserPresence>();

public override IBindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo;
private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>();

private readonly string endpoint;

private IHubClientConnector? connector;
Expand Down Expand Up @@ -58,6 +61,7 @@ private void load(IAPIProvider api, OsuConfigManager config)
// https://github.com/dotnet/aspnetcore/issues/15198
connection.On<BeatmapUpdates>(nameof(IMetadataClient.BeatmapSetsUpdated), ((IMetadataClient)this).BeatmapSetsUpdated);
connection.On<int, UserPresence?>(nameof(IMetadataClient.UserPresenceUpdated), ((IMetadataClient)this).UserPresenceUpdated);
connection.On<DailyChallengeInfo?>(nameof(IMetadataClient.DailyChallengeUpdated), ((IMetadataClient)this).DailyChallengeUpdated);
connection.On(nameof(IStatefulUserHubClient.DisconnectRequested), ((IMetadataClient)this).DisconnectRequested);
};

Expand Down Expand Up @@ -101,6 +105,7 @@ private void isConnectedChanged(ValueChangedEvent<bool> connected)
{
isWatchingUserPresence.Value = false;
userStates.Clear();
dailyChallengeInfo.Value = null;
});
return;
}
Expand Down Expand Up @@ -229,6 +234,12 @@ public override async Task EndWatchingUserPresence()
}
}

public override Task DailyChallengeUpdated(DailyChallengeInfo? info)
{
Schedule(() => dailyChallengeInfo.Value = info);
return Task.CompletedTask;
}

public override async Task DisconnectRequested()
{
await base.DisconnectRequested().ConfigureAwait(false);
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Online/Rooms/RoomCategory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ public enum RoomCategory

[Description("Featured Artist")]
FeaturedArtist,

[Description("Daily Challenge")]
DailyChallenge,
}
}
9 changes: 9 additions & 0 deletions osu.Game/Tests/Visual/Metadata/TestMetadataClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ public partial class TestMetadataClient : MetadataClient
public override IBindableDictionary<int, UserPresence> UserStates => userStates;
private readonly BindableDictionary<int, UserPresence> userStates = new BindableDictionary<int, UserPresence>();

public override IBindable<DailyChallengeInfo?> DailyChallengeInfo => dailyChallengeInfo;
private readonly Bindable<DailyChallengeInfo?> dailyChallengeInfo = new Bindable<DailyChallengeInfo?>();

[Resolved]
private IAPIProvider api { get; set; } = null!;

Expand Down Expand Up @@ -77,5 +80,11 @@ public override Task<BeatmapUpdates> GetChangesSince(int queueId)
=> Task.FromResult(new BeatmapUpdates(Array.Empty<int>(), queueId));

public override Task BeatmapSetsUpdated(BeatmapUpdates updates) => Task.CompletedTask;

public override Task DailyChallengeUpdated(DailyChallengeInfo? info)
{
dailyChallengeInfo.Value = info;
return Task.CompletedTask;
}
}
}

0 comments on commit 3a608aa

Please sign in to comment.