Add ServerShuttingDownCountdown

This commit is contained in:
Dan Balasescu 2022-09-15 20:54:06 +09:00
parent 8d725f7744
commit 433bb5ae24
6 changed files with 54 additions and 4 deletions

View File

@ -18,6 +18,7 @@ using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Multiplayer.Countdown; using osu.Game.Online.Multiplayer.Countdown;
using osu.Game.Online.Rooms; using osu.Game.Online.Rooms;
using osu.Game.Online.Rooms.RoomStatuses; using osu.Game.Online.Rooms.RoomStatuses;
using osu.Game.Overlays.Notifications;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Utils; using osu.Game.Utils;
@ -26,6 +27,8 @@ namespace osu.Game.Online.Multiplayer
{ {
public abstract class MultiplayerClient : Component, IMultiplayerClient, IMultiplayerRoomServer public abstract class MultiplayerClient : Component, IMultiplayerClient, IMultiplayerRoomServer
{ {
public Action<Notification>? PostNotification { protected get; set; }
/// <summary> /// <summary>
/// Invoked when any change occurs to the multiplayer room. /// Invoked when any change occurs to the multiplayer room.
/// </summary> /// </summary>
@ -554,6 +557,14 @@ namespace osu.Game.Online.Multiplayer
{ {
case CountdownStartedEvent countdownStartedEvent: case CountdownStartedEvent countdownStartedEvent:
Room.ActiveCountdowns.Add(countdownStartedEvent.Countdown); Room.ActiveCountdowns.Add(countdownStartedEvent.Countdown);
switch (countdownStartedEvent.Countdown)
{
case ServerShuttingDownCountdown:
postServerShuttingDownNotification();
break;
}
break; break;
case CountdownStoppedEvent countdownStoppedEvent: case CountdownStoppedEvent countdownStoppedEvent:
@ -569,6 +580,21 @@ namespace osu.Game.Online.Multiplayer
return Task.CompletedTask; return Task.CompletedTask;
} }
private void postServerShuttingDownNotification()
{
ServerShuttingDownCountdown? countdown = room?.ActiveCountdowns.OfType<ServerShuttingDownCountdown>().FirstOrDefault();
if (countdown == null)
return;
PostNotification?.Invoke(new SimpleNotification
{
Text = countdown.FinalNotification
? $"The multiplayer server is restarting in {countdown.TimeRemaining:hh\\:mm\\:ss}. This multiplayer room will be closed shortly."
: $"The multiplayer server is restarting in {countdown.TimeRemaining:hh\\:mm\\:ss}."
});
}
Task IMultiplayerClient.UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability) Task IMultiplayerClient.UserBeatmapAvailabilityChanged(int userId, BeatmapAvailability beatmapAvailability)
{ {
Scheduler.Add(() => Scheduler.Add(() =>

View File

@ -13,6 +13,7 @@ namespace osu.Game.Online.Multiplayer
[MessagePackObject] [MessagePackObject]
[Union(0, typeof(MatchStartCountdown))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types. [Union(0, typeof(MatchStartCountdown))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
[Union(1, typeof(ForceGameplayStartCountdown))] [Union(1, typeof(ForceGameplayStartCountdown))]
[Union(2, typeof(ServerShuttingDownCountdown))]
public abstract class MultiplayerCountdown public abstract class MultiplayerCountdown
{ {
/// <summary> /// <summary>

View File

@ -0,0 +1,20 @@
// 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 MessagePack;
namespace osu.Game.Online.Multiplayer
{
/// <summary>
/// A countdown that indicates the current multiplayer server is shutting down.
/// </summary>
[MessagePackObject]
public class ServerShuttingDownCountdown : MultiplayerCountdown
{
/// <summary>
/// If this is the final notification, no more <see cref="ServerShuttingDownCountdown"/> events will be sent after this.
/// </summary>
[Key(2)]
public bool FinalNotification { get; set; }
}
}

View File

@ -28,7 +28,8 @@ namespace osu.Game.Online
(typeof(TeamVersusRoomState), typeof(MatchRoomState)), (typeof(TeamVersusRoomState), typeof(MatchRoomState)),
(typeof(TeamVersusUserState), typeof(MatchUserState)), (typeof(TeamVersusUserState), typeof(MatchUserState)),
(typeof(MatchStartCountdown), typeof(MultiplayerCountdown)), (typeof(MatchStartCountdown), typeof(MultiplayerCountdown)),
(typeof(ForceGameplayStartCountdown), typeof(MultiplayerCountdown)) (typeof(ForceGameplayStartCountdown), typeof(MultiplayerCountdown)),
(typeof(ServerShuttingDownCountdown), typeof(MultiplayerCountdown)),
}; };
} }
} }

View File

@ -730,6 +730,8 @@ namespace osu.Game
ScoreManager.PostNotification = n => Notifications.Post(n); ScoreManager.PostNotification = n => Notifications.Post(n);
ScoreManager.PresentImport = items => PresentScore(items.First().Value); ScoreManager.PresentImport = items => PresentScore(items.First().Value);
MultiplayerClient.PostNotification = n => Notifications.Post(n);
// make config aware of how to lookup skins for on-screen display purposes. // make config aware of how to lookup skins for on-screen display purposes.
// if this becomes a more common thing, tracked settings should be reconsidered to allow local DI. // if this becomes a more common thing, tracked settings should be reconsidered to allow local DI.
LocalConfig.LookupSkinName = id => SkinManager.Query(s => s.ID == id)?.ToString() ?? "Unknown"; LocalConfig.LookupSkinName = id => SkinManager.Query(s => s.ID == id)?.ToString() ?? "Unknown";

View File

@ -179,7 +179,7 @@ namespace osu.Game
private SpectatorClient spectatorClient; private SpectatorClient spectatorClient;
private MultiplayerClient multiplayerClient; protected MultiplayerClient MultiplayerClient { get; private set; }
private MetadataClient metadataClient; private MetadataClient metadataClient;
@ -284,7 +284,7 @@ namespace osu.Game
// TODO: OsuGame or OsuGameBase? // TODO: OsuGame or OsuGameBase?
dependencies.CacheAs(beatmapUpdater = new BeatmapUpdater(BeatmapManager, difficultyCache, API, Storage)); dependencies.CacheAs(beatmapUpdater = new BeatmapUpdater(BeatmapManager, difficultyCache, API, Storage));
dependencies.CacheAs(spectatorClient = new OnlineSpectatorClient(endpoints)); dependencies.CacheAs(spectatorClient = new OnlineSpectatorClient(endpoints));
dependencies.CacheAs(multiplayerClient = new OnlineMultiplayerClient(endpoints)); dependencies.CacheAs(MultiplayerClient = new OnlineMultiplayerClient(endpoints));
dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints)); dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints));
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient)); AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
@ -329,7 +329,7 @@ namespace osu.Game
AddInternal(apiAccess); AddInternal(apiAccess);
AddInternal(spectatorClient); AddInternal(spectatorClient);
AddInternal(multiplayerClient); AddInternal(MultiplayerClient);
AddInternal(metadataClient); AddInternal(metadataClient);
AddInternal(rulesetConfigCache); AddInternal(rulesetConfigCache);