mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 09:37:23 +08:00
Merge pull request #11265 from peppy/fix-multiplayer-server-disconnection-flow
This commit is contained in:
commit
2549039362
@ -130,7 +130,11 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
|||||||
public override async Task LeaveRoom()
|
public override async Task LeaveRoom()
|
||||||
{
|
{
|
||||||
if (!isConnected.Value)
|
if (!isConnected.Value)
|
||||||
|
{
|
||||||
|
// even if not connected, make sure the local room state can be cleaned up.
|
||||||
|
await base.LeaveRoom();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (Room == null)
|
if (Room == null)
|
||||||
return;
|
return;
|
||||||
|
@ -11,6 +11,7 @@ using osu.Framework.Allocation;
|
|||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
@ -75,6 +76,19 @@ namespace osu.Game.Online.RealtimeMultiplayer
|
|||||||
// Todo: This is temporary, until the multiplayer server returns the item id on match start or otherwise.
|
// Todo: This is temporary, until the multiplayer server returns the item id on match start or otherwise.
|
||||||
private int playlistItemId;
|
private int playlistItemId;
|
||||||
|
|
||||||
|
protected StatefulMultiplayerClient()
|
||||||
|
{
|
||||||
|
IsConnected.BindValueChanged(connected =>
|
||||||
|
{
|
||||||
|
// clean up local room state on server disconnect.
|
||||||
|
if (!connected.NewValue)
|
||||||
|
{
|
||||||
|
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
LeaveRoom();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Joins the <see cref="MultiplayerRoom"/> for a given API <see cref="Room"/>.
|
/// Joins the <see cref="MultiplayerRoom"/> for a given API <see cref="Room"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -184,7 +184,7 @@ namespace osu.Game.Screens.Multi.Lounge
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Push a room as a new subscreen.
|
/// Push a room as a new subscreen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Open(Room room)
|
public virtual void Open(Room room)
|
||||||
{
|
{
|
||||||
// Handles the case where a room is clicked 3 times in quick succession
|
// Handles the case where a room is clicked 3 times in quick succession
|
||||||
if (!this.IsCurrentScreen())
|
if (!this.IsCurrentScreen())
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
using osu.Game.Screens.Multi.Lounge;
|
using osu.Game.Screens.Multi.Lounge;
|
||||||
using osu.Game.Screens.Multi.Lounge.Components;
|
using osu.Game.Screens.Multi.Lounge.Components;
|
||||||
using osu.Game.Screens.Multi.Match;
|
using osu.Game.Screens.Multi.Match;
|
||||||
@ -13,5 +16,19 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
protected override FilterControl CreateFilterControl() => new RealtimeFilterControl();
|
protected override FilterControl CreateFilterControl() => new RealtimeFilterControl();
|
||||||
|
|
||||||
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new RealtimeMatchSubScreen(room);
|
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new RealtimeMatchSubScreen(room);
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private StatefulMultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
public override void Open(Room room)
|
||||||
|
{
|
||||||
|
if (!client.IsConnected.Value)
|
||||||
|
{
|
||||||
|
Logger.Log("Not currently connected to the multiplayer server.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Open(room);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
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.Screens;
|
using osu.Framework.Screens;
|
||||||
@ -16,6 +17,7 @@ using osu.Game.Screens.Multi.RealtimeMultiplayer.Match;
|
|||||||
using osu.Game.Screens.Multi.RealtimeMultiplayer.Participants;
|
using osu.Game.Screens.Multi.RealtimeMultiplayer.Participants;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
|
using ParticipantsList = osu.Game.Screens.Multi.RealtimeMultiplayer.Participants.ParticipantsList;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
namespace osu.Game.Screens.Multi.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;
|
||||||
@ -102,7 +106,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
new Drawable[] { new ParticipantsListHeader() },
|
new Drawable[] { new ParticipantsListHeader() },
|
||||||
new Drawable[]
|
new Drawable[]
|
||||||
{
|
{
|
||||||
new Participants.ParticipantsList
|
new ParticipantsList
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both
|
RelativeSizeAxes = Axes.Both
|
||||||
},
|
},
|
||||||
@ -173,6 +177,13 @@ 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)
|
||||||
|
Schedule(this.Exit);
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnBackButton()
|
public override bool OnBackButton()
|
||||||
|
@ -8,8 +8,8 @@ using System.Threading;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
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.Game.Online.Multiplayer;
|
using osu.Game.Online.Multiplayer;
|
||||||
using osu.Game.Online.RealtimeMultiplayer;
|
using osu.Game.Online.RealtimeMultiplayer;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -31,6 +31,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private StatefulMultiplayerClient client { get; set; }
|
private StatefulMultiplayerClient client { get; set; }
|
||||||
|
|
||||||
|
private IBindable<bool> isConnected;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
@ -50,17 +52,26 @@ 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)
|
||||||
|
{
|
||||||
|
startedEvent.Set();
|
||||||
|
|
||||||
|
// messaging to the user about this disconnect will be provided by the RealtimeMatchSubScreen.
|
||||||
|
Schedule(() => PerformExit(false));
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
|
|
||||||
client.ChangeState(MultiplayerUserState.Loaded);
|
client.ChangeState(MultiplayerUserState.Loaded);
|
||||||
|
|
||||||
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
if (!startedEvent.Wait(TimeSpan.FromSeconds(30)))
|
||||||
{
|
{
|
||||||
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important);
|
Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important);
|
||||||
|
|
||||||
Schedule(() =>
|
Schedule(() => PerformExit(false));
|
||||||
{
|
|
||||||
ValidForResume = false;
|
|
||||||
this.Exit();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Assert(client.Room != null);
|
Debug.Assert(client.Room != null);
|
||||||
|
@ -43,6 +43,12 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
|||||||
|
|
||||||
public override void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
public override void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||||
{
|
{
|
||||||
|
if (!multiplayerClient.IsConnected.Value)
|
||||||
|
{
|
||||||
|
onError?.Invoke("Not currently connected to the multiplayer server.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// this is done here as a pre-check to avoid clicking on already closed rooms in the lounge from triggering a server join.
|
// this is done here as a pre-check to avoid clicking on already closed rooms in the lounge from triggering a server join.
|
||||||
// should probably be done at a higher level, but due to the current structure of things this is the easiest place for now.
|
// should probably be done at a higher level, but due to the current structure of things this is the easiest place for now.
|
||||||
if (room.Status.Value is RoomStatusEnded)
|
if (room.Status.Value is RoomStatusEnded)
|
||||||
|
@ -386,7 +386,7 @@ namespace osu.Game.Screens.Play
|
|||||||
if (!this.IsCurrentScreen()) return;
|
if (!this.IsCurrentScreen()) return;
|
||||||
|
|
||||||
fadeOut(true);
|
fadeOut(true);
|
||||||
performImmediateExit();
|
PerformExit(true);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
|
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, },
|
||||||
@ -458,20 +458,30 @@ namespace osu.Game.Screens.Play
|
|||||||
return playable;
|
return playable;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performImmediateExit()
|
/// <summary>
|
||||||
|
/// Exits the <see cref="Player"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="userRequested">
|
||||||
|
/// Whether the exit is requested by the user, or a higher-level game component.
|
||||||
|
/// Pausing is allowed only in the former case.
|
||||||
|
/// </param>
|
||||||
|
protected void PerformExit(bool userRequested)
|
||||||
{
|
{
|
||||||
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
|
// if a restart has been requested, cancel any pending completion (user has shown intent to restart).
|
||||||
completionProgressDelegate?.Cancel();
|
completionProgressDelegate?.Cancel();
|
||||||
|
|
||||||
ValidForResume = false;
|
ValidForResume = false;
|
||||||
|
|
||||||
performUserRequestedExit();
|
if (!this.IsCurrentScreen()) return;
|
||||||
|
|
||||||
|
if (userRequested)
|
||||||
|
performUserRequestedExit();
|
||||||
|
else
|
||||||
|
this.Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void performUserRequestedExit()
|
private void performUserRequestedExit()
|
||||||
{
|
{
|
||||||
if (!this.IsCurrentScreen()) return;
|
|
||||||
|
|
||||||
if (ValidForResume && HasFailed && !FailOverlay.IsPresent)
|
if (ValidForResume && HasFailed && !FailOverlay.IsPresent)
|
||||||
{
|
{
|
||||||
failAnimation.FinishTransforms(true);
|
failAnimation.FinishTransforms(true);
|
||||||
@ -498,7 +508,7 @@ namespace osu.Game.Screens.Play
|
|||||||
RestartRequested?.Invoke();
|
RestartRequested?.Invoke();
|
||||||
|
|
||||||
if (this.IsCurrentScreen())
|
if (this.IsCurrentScreen())
|
||||||
performImmediateExit();
|
PerformExit(true);
|
||||||
else
|
else
|
||||||
this.MakeCurrent();
|
this.MakeCurrent();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user