fix reconnection to server
This commit is contained in:
@@ -149,7 +149,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
{
|
{
|
||||||
new KeyValuePair<string, string>("auth", auth),
|
new KeyValuePair<string, string>("auth", auth),
|
||||||
new KeyValuePair<string, string>("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
new KeyValuePair<string, string>("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)),
|
||||||
})).ConfigureAwait(false);
|
}), token).ConfigureAwait(false);
|
||||||
AuthFailureMessage = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
|
AuthFailureMessage = await result.Content.ReadAsStringAsync().ConfigureAwait(false);
|
||||||
result.EnsureSuccessStatusCode();
|
result.EnsureSuccessStatusCode();
|
||||||
_serverManager.SaveToken(await result.Content.ReadAsStringAsync().ConfigureAwait(false));
|
_serverManager.SaveToken(await result.Content.ReadAsStringAsync().ConfigureAwait(false));
|
||||||
@@ -202,6 +202,11 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
|
|
||||||
await LoadOnlinePairs().ConfigureAwait(false);
|
await LoadOnlinePairs().ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Logger.LogWarning("Connection attempt cancelled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
catch (HttpRequestException ex)
|
catch (HttpRequestException ex)
|
||||||
{
|
{
|
||||||
Logger.LogWarning(ex, "HttpRequestException on Connection");
|
Logger.LogWarning(ex, "HttpRequestException on Connection");
|
||||||
@@ -230,7 +235,7 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
{
|
{
|
||||||
CancellationTokenSource cts = new();
|
CancellationTokenSource cts = new();
|
||||||
cts.CancelAfter(TimeSpan.FromSeconds(5));
|
cts.CancelAfter(TimeSpan.FromSeconds(5));
|
||||||
Task.Run(async () =>
|
_ = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
var pair = _pairManager.GetOnlineUserPairs().Single(p => p.UserPair != null && p.UserData == userData);
|
var pair = _pairManager.GetOnlineUserPairs().Single(p => p.UserPair != null && p.UserData == userData);
|
||||||
var perm = pair.UserPair!.OwnPermissions;
|
var perm = pair.UserPair!.OwnPermissions;
|
||||||
@@ -404,17 +409,18 @@ public sealed partial class ApiController : DisposableMediatorSubscriberBase, IM
|
|||||||
{
|
{
|
||||||
ServerState = ServerState.Disconnecting;
|
ServerState = ServerState.Disconnecting;
|
||||||
|
|
||||||
|
Logger.LogInformation("Stopping existing connection");
|
||||||
|
await _hubFactory.DisposeHubAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
if (_mareHub is not null)
|
if (_mareHub is not null)
|
||||||
{
|
{
|
||||||
_initialized = false;
|
_initialized = false;
|
||||||
_healthCheckTokenSource?.Cancel();
|
_healthCheckTokenSource?.Cancel();
|
||||||
Logger.LogInformation("Stopping existing connection");
|
|
||||||
Mediator.Publish(new DisconnectedMessage());
|
Mediator.Publish(new DisconnectedMessage());
|
||||||
_mareHub = null;
|
_mareHub = null;
|
||||||
_connectionDto = null;
|
_connectionDto = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
await _hubFactory.DisposeHubAsync().ConfigureAwait(false);
|
|
||||||
|
|
||||||
ServerState = state;
|
ServerState = state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,5 +117,7 @@ public class HubFactory : MediatorSubscriberBase
|
|||||||
await _instance.DisposeAsync().ConfigureAwait(false);
|
await _instance.DisposeAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
_instance = null;
|
_instance = null;
|
||||||
|
|
||||||
|
Logger.LogDebug("Current HubConnection disposed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user