1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 11:35:35 +08:00

Perform actions after server reconnection

This commit is contained in:
Dean Herbert 2022-07-17 04:35:41 +09:00
parent 8e7e1e6b51
commit da7edd5d49
4 changed files with 23 additions and 9 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}

View File

@ -86,7 +86,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;
}
}

View File

@ -62,7 +62,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;
}
}