mirror of
https://github.com/ppy/osu
synced 2025-02-02 03:11:58 +00:00
Merge pull request #19189 from peppy/peform-actions-after-reconnect
Fix creating multiplayer game during server migration not joining new room correctly
This commit is contained in:
commit
c07f78409e
@ -64,26 +64,26 @@ namespace osu.Game.Online
|
||||
this.preferMessagePack = preferMessagePack;
|
||||
|
||||
apiState.BindTo(api.State);
|
||||
apiState.BindValueChanged(_ => connectIfPossible(), true);
|
||||
apiState.BindValueChanged(_ => Task.Run(connectIfPossible), true);
|
||||
}
|
||||
|
||||
public void Reconnect()
|
||||
public Task Reconnect()
|
||||
{
|
||||
Logger.Log($"{clientName} reconnecting...", LoggingTarget.Network);
|
||||
Task.Run(connectIfPossible);
|
||||
return Task.Run(connectIfPossible);
|
||||
}
|
||||
|
||||
private void connectIfPossible()
|
||||
private async Task connectIfPossible()
|
||||
{
|
||||
switch (apiState.Value)
|
||||
{
|
||||
case APIState.Failing:
|
||||
case APIState.Offline:
|
||||
Task.Run(() => disconnect(true));
|
||||
await disconnect(true);
|
||||
break;
|
||||
|
||||
case APIState.Online:
|
||||
Task.Run(connect);
|
||||
await connect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Online.API;
|
||||
@ -32,6 +33,6 @@ namespace osu.Game.Online
|
||||
/// <summary>
|
||||
/// Reconnect if already connected.
|
||||
/// </summary>
|
||||
void Reconnect();
|
||||
Task Reconnect();
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ using osu.Game.Online.Rooms.RoomStatuses;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Utils;
|
||||
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
|
||||
|
||||
namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
@ -91,7 +90,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// <summary>
|
||||
/// The joined <see cref="MultiplayerRoom"/>.
|
||||
/// </summary>
|
||||
public virtual MultiplayerRoom? Room
|
||||
public virtual MultiplayerRoom? Room // virtual for moq
|
||||
{
|
||||
get
|
||||
{
|
||||
@ -150,7 +149,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
// clean up local room state on server disconnect.
|
||||
if (!connected.NewValue && Room != null)
|
||||
{
|
||||
Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
|
||||
Logger.Log("Clearing room due to multiplayer server connection loss.", LoggingTarget.Runtime, LogLevel.Important);
|
||||
LeaveRoom();
|
||||
}
|
||||
}));
|
||||
|
@ -85,7 +85,13 @@ namespace osu.Game.Online.Multiplayer
|
||||
catch (HubException exception)
|
||||
{
|
||||
if (exception.GetHubExceptionMessage() == HubClientConnector.SERVER_SHUTDOWN_MESSAGE)
|
||||
connector?.Reconnect();
|
||||
{
|
||||
Debug.Assert(connector != null);
|
||||
|
||||
await connector.Reconnect();
|
||||
return await JoinRoom(roomId, password);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -61,7 +61,14 @@ namespace osu.Game.Online.Spectator
|
||||
catch (HubException exception)
|
||||
{
|
||||
if (exception.GetHubExceptionMessage() == HubClientConnector.SERVER_SHUTDOWN_MESSAGE)
|
||||
connector?.Reconnect();
|
||||
{
|
||||
Debug.Assert(connector != null);
|
||||
|
||||
await connector.Reconnect();
|
||||
await BeginPlayingInternal(state);
|
||||
return;
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -70,12 +70,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
client.LoadRequested += onLoadRequested;
|
||||
client.RoomUpdated += onRoomUpdated;
|
||||
|
||||
isConnected.BindTo(client.IsConnected);
|
||||
isConnected.BindValueChanged(connected =>
|
||||
{
|
||||
if (!connected.NewValue)
|
||||
handleRoomLost();
|
||||
}, true);
|
||||
if (!client.IsConnected.Value)
|
||||
handleRoomLost();
|
||||
}
|
||||
|
||||
protected override Drawable CreateMainContent() => new Container
|
||||
|
Loading…
Reference in New Issue
Block a user