mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 02:32:55 +08:00
Add ServerShuttingDownCountdown
This commit is contained in:
parent
8d725f7744
commit
433bb5ae24
@ -18,6 +18,7 @@ using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Multiplayer.Countdown;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Online.Rooms.RoomStatuses;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
@ -26,6 +27,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
public abstract class MultiplayerClient : Component, IMultiplayerClient, IMultiplayerRoomServer
|
||||
{
|
||||
public Action<Notification>? PostNotification { protected get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when any change occurs to the multiplayer room.
|
||||
/// </summary>
|
||||
@ -554,6 +557,14 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
case CountdownStartedEvent countdownStartedEvent:
|
||||
Room.ActiveCountdowns.Add(countdownStartedEvent.Countdown);
|
||||
|
||||
switch (countdownStartedEvent.Countdown)
|
||||
{
|
||||
case ServerShuttingDownCountdown:
|
||||
postServerShuttingDownNotification();
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CountdownStoppedEvent countdownStoppedEvent:
|
||||
@ -569,6 +580,21 @@ namespace osu.Game.Online.Multiplayer
|
||||
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)
|
||||
{
|
||||
Scheduler.Add(() =>
|
||||
|
@ -13,6 +13,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
[MessagePackObject]
|
||||
[Union(0, typeof(MatchStartCountdown))] // IMPORTANT: Add rules to SignalRUnionWorkaroundResolver for new derived types.
|
||||
[Union(1, typeof(ForceGameplayStartCountdown))]
|
||||
[Union(2, typeof(ServerShuttingDownCountdown))]
|
||||
public abstract class MultiplayerCountdown
|
||||
{
|
||||
/// <summary>
|
||||
|
20
osu.Game/Online/Multiplayer/ServerShuttingDownCountdown.cs
Normal file
20
osu.Game/Online/Multiplayer/ServerShuttingDownCountdown.cs
Normal 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; }
|
||||
}
|
||||
}
|
@ -28,7 +28,8 @@ namespace osu.Game.Online
|
||||
(typeof(TeamVersusRoomState), typeof(MatchRoomState)),
|
||||
(typeof(TeamVersusUserState), typeof(MatchUserState)),
|
||||
(typeof(MatchStartCountdown), typeof(MultiplayerCountdown)),
|
||||
(typeof(ForceGameplayStartCountdown), typeof(MultiplayerCountdown))
|
||||
(typeof(ForceGameplayStartCountdown), typeof(MultiplayerCountdown)),
|
||||
(typeof(ServerShuttingDownCountdown), typeof(MultiplayerCountdown)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -730,6 +730,8 @@ namespace osu.Game
|
||||
ScoreManager.PostNotification = n => Notifications.Post(n);
|
||||
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.
|
||||
// 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";
|
||||
|
@ -179,7 +179,7 @@ namespace osu.Game
|
||||
|
||||
private SpectatorClient spectatorClient;
|
||||
|
||||
private MultiplayerClient multiplayerClient;
|
||||
protected MultiplayerClient MultiplayerClient { get; private set; }
|
||||
|
||||
private MetadataClient metadataClient;
|
||||
|
||||
@ -284,7 +284,7 @@ namespace osu.Game
|
||||
// TODO: OsuGame or OsuGameBase?
|
||||
dependencies.CacheAs(beatmapUpdater = new BeatmapUpdater(BeatmapManager, difficultyCache, API, Storage));
|
||||
dependencies.CacheAs(spectatorClient = new OnlineSpectatorClient(endpoints));
|
||||
dependencies.CacheAs(multiplayerClient = new OnlineMultiplayerClient(endpoints));
|
||||
dependencies.CacheAs(MultiplayerClient = new OnlineMultiplayerClient(endpoints));
|
||||
dependencies.CacheAs(metadataClient = new OnlineMetadataClient(endpoints));
|
||||
|
||||
AddInternal(new BeatmapOnlineChangeIngest(beatmapUpdater, realm, metadataClient));
|
||||
@ -329,7 +329,7 @@ namespace osu.Game
|
||||
AddInternal(apiAccess);
|
||||
|
||||
AddInternal(spectatorClient);
|
||||
AddInternal(multiplayerClient);
|
||||
AddInternal(MultiplayerClient);
|
||||
AddInternal(metadataClient);
|
||||
|
||||
AddInternal(rulesetConfigCache);
|
||||
|
Loading…
Reference in New Issue
Block a user