mirror of https://github.com/ppy/osu
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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.RealtimeMultiplayer;
|
||||
|
@ -34,6 +36,8 @@ public class RealtimeMatchSubScreen : RoomSubScreen
|
|||
|
||||
private RealtimeMatchSettingsOverlay settingsOverlay;
|
||||
|
||||
private IBindable<bool> isConnected;
|
||||
|
||||
public RealtimeMatchSubScreen(Room room)
|
||||
{
|
||||
Title = room.RoomID.Value == null ? "New match" : room.Name.Value;
|
||||
|
@ -173,6 +177,16 @@ protected override void LoadComplete()
|
|||
Playlist.BindCollectionChanged(onPlaylistChanged, true);
|
||||
|
||||
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()
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
|
@ -30,6 +31,8 @@ public class RealtimePlayer : TimeshiftPlayer
|
|||
private readonly TaskCompletionSource<bool> resultsReady = new TaskCompletionSource<bool>();
|
||||
private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim();
|
||||
|
||||
private IBindable<bool> isConnected;
|
||||
|
||||
public RealtimePlayer(PlaylistItem playlistItem)
|
||||
: base(playlistItem, false)
|
||||
{
|
||||
|
@ -43,6 +46,15 @@ private void load()
|
|||
|
||||
client.MatchStarted += onMatchStarted;
|
||||
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);
|
||||
|
||||
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
||||
|
|
Loading…
Reference in New Issue