mirror of
https://github.com/ppy/osu.git
synced 2025-01-28 18:12:56 +08:00
Ensure appropriate screens handle exiting when the server gets disconnected
I would have liked for this to be handled via the `OnRoomChanged` event flow, but this isn't present in RealtimeMatchSubScreen due to inheritence woes.
This commit is contained in:
parent
00d50150de
commit
12df3056e6
@ -4,8 +4,10 @@
|
|||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
@ -34,6 +36,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
|
|
||||||
private RealtimeMatchSettingsOverlay settingsOverlay;
|
private RealtimeMatchSettingsOverlay settingsOverlay;
|
||||||
|
|
||||||
|
private IBindable<bool> isConnected;
|
||||||
|
|
||||||
public RealtimeMatchSubScreen(Room room)
|
public RealtimeMatchSubScreen(Room room)
|
||||||
{
|
{
|
||||||
Title = room.RoomID.Value == null ? "New match" : room.Name.Value;
|
Title = room.RoomID.Value == null ? "New match" : room.Name.Value;
|
||||||
@ -173,6 +177,16 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
||||||
|
|
||||||
client.LoadRequested += onLoadRequested;
|
client.LoadRequested += onLoadRequested;
|
||||||
|
|
||||||
|
isConnected = client.IsConnected.GetBoundCopy();
|
||||||
|
isConnected.BindValueChanged(connected =>
|
||||||
|
{
|
||||||
|
if (!connected.NewValue)
|
||||||
|
{
|
||||||
|
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
Schedule(this.Exit);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnBackButton()
|
public override bool OnBackButton()
|
||||||
|
@ -6,6 +6,7 @@ using System.Diagnostics;
|
|||||||
using System.Threading;
|
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.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Framework.Screens;
|
using osu.Framework.Screens;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
@ -30,6 +31,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
|
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
|
||||||
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
|
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
|
||||||
|
|
||||||
|
private IBindable<bool> isConnected;
|
||||||
|
|
||||||
public RealtimePlayer(PlaylistItem playlistItem)
|
public RealtimePlayer(PlaylistItem playlistItem)
|
||||||
: base(playlistItem, false)
|
: base(playlistItem, false)
|
||||||
{
|
{
|
||||||
@ -43,6 +46,15 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
|
|
||||||
client.MatchStarted += onMatchStarted;
|
client.MatchStarted += onMatchStarted;
|
||||||
client.ResultsReady += onResultsReady;
|
client.ResultsReady += onResultsReady;
|
||||||
|
|
||||||
|
isConnected = client.IsConnected.GetBoundCopy();
|
||||||
|
isConnected.BindValueChanged(connected =>
|
||||||
|
{
|
||||||
|
if (!connected.NewValue)
|
||||||
|
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
|
||||||
|
Schedule(this.Exit);
|
||||||
|
}, true);
|
||||||
|
|
||||||
client.ChangeState(MultiplayerUserState.Loaded);
|
client.ChangeState(MultiplayerUserState.Loaded);
|
||||||
|
|
||||||
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
||||||
|
Loading…
Reference in New Issue
Block a user