bump to 0.3.1
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: 50a447c4d0...1ee130413f
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>0.3.0</Version>
|
<Version>0.3.1</Version>
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Copyright></Copyright>
|
<Copyright></Copyright>
|
||||||
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Penumbra-Sync/client</PackageProjectUrl>
|
||||||
|
|||||||
@@ -63,10 +63,7 @@ namespace MareSynchronos.UI
|
|||||||
_windowContentWidth = UiShared.GetWindowContentRegionWidth();
|
_windowContentWidth = UiShared.GetWindowContentRegionWidth();
|
||||||
UiShared.DrawWithID("header", DrawUIDHeader);
|
UiShared.DrawWithID("header", DrawUIDHeader);
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
if (_apiController.ServerState is not ServerState.Offline)
|
UiShared.DrawWithID("serverstatus", DrawServerStatus);
|
||||||
{
|
|
||||||
UiShared.DrawWithID("serverstatus", DrawServerStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_apiController.ServerState is ServerState.Connected)
|
if (_apiController.ServerState is ServerState.Connected)
|
||||||
{
|
{
|
||||||
@@ -292,14 +289,13 @@ namespace MareSynchronos.UI
|
|||||||
|
|
||||||
private void DrawServerStatus()
|
private void DrawServerStatus()
|
||||||
{
|
{
|
||||||
if (_apiController.ServerAlive)
|
var originalY = ImGui.GetCursorPosY();
|
||||||
|
var buttonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Link);
|
||||||
|
var textSize = ImGui.CalcTextSize("%");
|
||||||
|
var textPos = originalY + buttonSize.Y / 2 - textSize.Y / 2;
|
||||||
|
|
||||||
|
if (_apiController.ServerState is ServerState.Connected)
|
||||||
{
|
{
|
||||||
var buttonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Link);
|
|
||||||
var textSize = ImGui.CalcTextSize(_apiController.SystemInfoDto.CpuUsage.ToString("0.00") + "%");
|
|
||||||
var originalY = ImGui.GetCursorPosY();
|
|
||||||
|
|
||||||
var textPos = originalY + buttonSize.Y / 2 - textSize.Y / 2;
|
|
||||||
|
|
||||||
ImGui.SetCursorPosY(textPos);
|
ImGui.SetCursorPosY(textPos);
|
||||||
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString());
|
ImGui.TextColored(ImGuiColors.ParsedGreen, _apiController.OnlineUsers.ToString());
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
@@ -312,35 +308,27 @@ namespace MareSynchronos.UI
|
|||||||
ImGui.SetCursorPosY(textPos);
|
ImGui.SetCursorPosY(textPos);
|
||||||
ImGui.Text("Load");
|
ImGui.Text("Load");
|
||||||
UiShared.AttachToolTip("This is the current servers' CPU load");
|
UiShared.AttachToolTip("This is the current servers' CPU load");
|
||||||
|
|
||||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X);
|
|
||||||
ImGui.SetCursorPosY(originalY);
|
|
||||||
var serverIsConnected = _apiController.ServerState is ServerState.Connected;
|
|
||||||
var color = UiShared.GetBoolColor(serverIsConnected);
|
|
||||||
var connectedIcon = serverIsConnected ? FontAwesomeIcon.Link : FontAwesomeIcon.Unlink;
|
|
||||||
|
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, color);
|
|
||||||
if (ImGuiComponents.IconButton(connectedIcon))
|
|
||||||
{
|
|
||||||
if (_apiController.ServerState == ServerState.Connected)
|
|
||||||
{
|
|
||||||
_configuration.FullPause = true;
|
|
||||||
_configuration.Save();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_configuration.FullPause = false;
|
|
||||||
_configuration.Save();
|
|
||||||
}
|
|
||||||
_ = _apiController.CreateConnections();
|
|
||||||
}
|
|
||||||
ImGui.PopStyleColor();
|
|
||||||
UiShared.AttachToolTip(_apiController.IsConnected ? "Disconnect from " + _apiController.ServerDictionary[_configuration.ApiUri] : "Connect to " + _apiController.ServerDictionary[_configuration.ApiUri]);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
UiShared.ColorTextWrapped("Server is offline", ImGuiColors.DalamudRed);
|
ImGui.SetCursorPosY(textPos);
|
||||||
|
ImGui.TextColored(ImGuiColors.DalamudRed, "Not connected to any server");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X);
|
||||||
|
ImGui.SetCursorPosY(originalY);
|
||||||
|
var color = UiShared.GetBoolColor(!_configuration.FullPause);
|
||||||
|
var connectedIcon = !_configuration.FullPause ? FontAwesomeIcon.Link : FontAwesomeIcon.Unlink;
|
||||||
|
|
||||||
|
ImGui.PushStyleColor(ImGuiCol.Text, color);
|
||||||
|
if (ImGuiComponents.IconButton(connectedIcon))
|
||||||
|
{
|
||||||
|
_configuration.FullPause = !_configuration.FullPause;
|
||||||
|
_configuration.Save();
|
||||||
|
_ = _apiController.CreateConnections();
|
||||||
|
}
|
||||||
|
ImGui.PopStyleColor();
|
||||||
|
UiShared.AttachToolTip(!_configuration.FullPause ? "Disconnect from " + _apiController.ServerDictionary[_configuration.ApiUri] : "Connect to " + _apiController.ServerDictionary[_configuration.ApiUri]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawTransfers()
|
private void DrawTransfers()
|
||||||
@@ -456,8 +444,8 @@ namespace MareSynchronos.UI
|
|||||||
ServerState.Unauthorized => "Your account is not present on the server anymore or you are banned.",
|
ServerState.Unauthorized => "Your account is not present on the server anymore or you are banned.",
|
||||||
ServerState.Offline => "Your selected Mare Synchronos server is currently offline.",
|
ServerState.Offline => "Your selected Mare Synchronos server is currently offline.",
|
||||||
ServerState.VersionMisMatch =>
|
ServerState.VersionMisMatch =>
|
||||||
"The plugin or server you are connecting to is outdated. Please update your plugin now. If you already did so, contact the server provider to update their server to the latest version.",
|
"Your plugin or the server you are connecting to is out of date. Please update your plugin now. If you already did so, contact the server provider to update their server to the latest version.",
|
||||||
ServerState.NoAccount => "Idk how you got here but you have no account. What are you doing?",
|
ServerState.RateLimited => "You are rate limited for (re)connecting too often. Wait and try again later.",
|
||||||
ServerState.Connected => string.Empty,
|
ServerState.Connected => string.Empty,
|
||||||
_ => string.Empty
|
_ => string.Empty
|
||||||
};
|
};
|
||||||
@@ -472,7 +460,7 @@ namespace MareSynchronos.UI
|
|||||||
ServerState.Unauthorized => ImGuiColors.DalamudRed,
|
ServerState.Unauthorized => ImGuiColors.DalamudRed,
|
||||||
ServerState.VersionMisMatch => ImGuiColors.DalamudRed,
|
ServerState.VersionMisMatch => ImGuiColors.DalamudRed,
|
||||||
ServerState.Offline => ImGuiColors.DalamudRed,
|
ServerState.Offline => ImGuiColors.DalamudRed,
|
||||||
ServerState.NoAccount => ImGuiColors.DalamudRed,
|
ServerState.RateLimited => ImGuiColors.DalamudYellow,
|
||||||
_ => ImGuiColors.DalamudRed
|
_ => ImGuiColors.DalamudRed
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -485,7 +473,7 @@ namespace MareSynchronos.UI
|
|||||||
ServerState.Unauthorized => "Unauthorized",
|
ServerState.Unauthorized => "Unauthorized",
|
||||||
ServerState.VersionMisMatch => "Version mismatch",
|
ServerState.VersionMisMatch => "Version mismatch",
|
||||||
ServerState.Offline => "Unavailable",
|
ServerState.Offline => "Unavailable",
|
||||||
ServerState.NoAccount => "No account",
|
ServerState.RateLimited => "Rate Limited",
|
||||||
ServerState.Connected => _apiController.UID,
|
ServerState.Connected => _apiController.UID,
|
||||||
_ => string.Empty
|
_ => string.Empty
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -233,7 +233,7 @@ namespace MareSynchronos.UI
|
|||||||
_uiShared.DrawFileScanState();
|
_uiShared.DrawFileScanState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else if (!_uiShared.ApiController.ServerAlive)
|
||||||
{
|
{
|
||||||
if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont);
|
if (_uiShared.UidFontBuilt) ImGui.PushFont(_uiShared.UidFont);
|
||||||
ImGui.TextUnformatted("Service Registration");
|
ImGui.TextUnformatted("Service Registration");
|
||||||
@@ -254,11 +254,12 @@ namespace MareSynchronos.UI
|
|||||||
|
|
||||||
UiShared.TextWrapped("Once you have received a secret key you can connect to the service using the tools provided below.");
|
UiShared.TextWrapped("Once you have received a secret key you can connect to the service using the tools provided below.");
|
||||||
|
|
||||||
_uiShared.DrawServiceSelection(() =>
|
_uiShared.DrawServiceSelection(() => { });
|
||||||
{
|
}
|
||||||
SwitchToMainUi?.Invoke();
|
else
|
||||||
IsOpen = false;
|
{
|
||||||
});
|
SwitchToMainUi?.Invoke();
|
||||||
|
IsOpen = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -159,12 +159,11 @@ namespace MareSynchronos.UI
|
|||||||
var serverName = _apiController.ServerDictionary.ContainsKey(_pluginConfiguration.ApiUri)
|
var serverName = _apiController.ServerDictionary.ContainsKey(_pluginConfiguration.ApiUri)
|
||||||
? _apiController.ServerDictionary[_pluginConfiguration.ApiUri]
|
? _apiController.ServerDictionary[_pluginConfiguration.ApiUri]
|
||||||
: _pluginConfiguration.ApiUri;
|
: _pluginConfiguration.ApiUri;
|
||||||
ImGui.TextUnformatted("Service " + serverName + ":");
|
if (_apiController.ServerState is ServerState.Connected)
|
||||||
ImGui.SameLine();
|
|
||||||
var color = _apiController.ServerAlive ? ImGuiColors.ParsedGreen : ImGuiColors.DalamudRed;
|
|
||||||
ImGui.TextColored(color, _apiController.ServerAlive ? "Available" : "Unavailable");
|
|
||||||
if (_apiController.ServerAlive)
|
|
||||||
{
|
{
|
||||||
|
ImGui.TextUnformatted("Service " + serverName + ":");
|
||||||
|
ImGui.SameLine();
|
||||||
|
ImGui.TextColored(ImGuiColors.ParsedGreen, "Available");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
ImGui.TextUnformatted("(");
|
ImGui.TextUnformatted("(");
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
@@ -350,14 +349,13 @@ namespace MareSynchronos.UI
|
|||||||
|
|
||||||
ImGui.SetNextItemWidth(400);
|
ImGui.SetNextItemWidth(400);
|
||||||
ImGui.InputText("Enter Secret Key", ref _secretKey, 255);
|
ImGui.InputText("Enter Secret Key", ref _secretKey, 255);
|
||||||
ImGui.SameLine();
|
|
||||||
if (_secretKey.Length > 0 && _secretKey.Length != 64)
|
if (_secretKey.Length > 0 && _secretKey.Length != 64)
|
||||||
{
|
{
|
||||||
ColorTextWrapped("Your secret key must be exactly 64 characters long. If try to enter your UID here, this is incorrect." +
|
ColorTextWrapped("Your secret key must be exactly 64 characters long. Don't enter your Lodestone auth here.", ImGuiColors.DalamudRed);
|
||||||
" Don't enter anything but a prior acquired secret key here.", ImGuiColors.DalamudRed);
|
|
||||||
}
|
}
|
||||||
else if (_secretKey.Length == 64)
|
else if (_secretKey.Length == 64)
|
||||||
{
|
{
|
||||||
|
ImGui.SameLine();
|
||||||
if (ImGui.Button("Save"))
|
if (ImGui.Button("Save"))
|
||||||
{
|
{
|
||||||
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey;
|
_pluginConfiguration.ClientSecret[_pluginConfiguration.ApiUri] = _secretKey;
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net.Http;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MareSynchronos.API;
|
using MareSynchronos.API;
|
||||||
using MareSynchronos.Utils;
|
using MareSynchronos.Utils;
|
||||||
using MareSynchronos.WebAPI.Utils;
|
using MareSynchronos.WebAPI.Utils;
|
||||||
using Microsoft.AspNetCore.Http.Connections;
|
using Microsoft.AspNetCore.Http.Connections;
|
||||||
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.AspNetCore.SignalR.Client;
|
using Microsoft.AspNetCore.SignalR.Client;
|
||||||
|
|
||||||
namespace MareSynchronos.WebAPI
|
namespace MareSynchronos.WebAPI
|
||||||
@@ -20,7 +22,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
Connected,
|
Connected,
|
||||||
Unauthorized,
|
Unauthorized,
|
||||||
VersionMisMatch,
|
VersionMisMatch,
|
||||||
NoAccount
|
RateLimited
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class ApiController : IDisposable
|
public partial class ApiController : IDisposable
|
||||||
@@ -54,6 +56,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
_connectionCancellationTokenSource = new CancellationTokenSource();
|
_connectionCancellationTokenSource = new CancellationTokenSource();
|
||||||
_dalamudUtil.LogIn += DalamudUtilOnLogIn;
|
_dalamudUtil.LogIn += DalamudUtilOnLogIn;
|
||||||
_dalamudUtil.LogOut += DalamudUtilOnLogOut;
|
_dalamudUtil.LogOut += DalamudUtilOnLogOut;
|
||||||
|
ServerState = ServerState.Offline;
|
||||||
|
|
||||||
if (_dalamudUtil.IsLoggedIn)
|
if (_dalamudUtil.IsLoggedIn)
|
||||||
{
|
{
|
||||||
@@ -107,11 +110,9 @@ namespace MareSynchronos.WebAPI
|
|||||||
public List<ClientPairDto> PairedClients { get; set; } = new();
|
public List<ClientPairDto> PairedClients { get; set; } = new();
|
||||||
|
|
||||||
public string SecretKey => _pluginConfiguration.ClientSecret.ContainsKey(ApiUri)
|
public string SecretKey => _pluginConfiguration.ClientSecret.ContainsKey(ApiUri)
|
||||||
? _pluginConfiguration.ClientSecret[ApiUri]
|
? _pluginConfiguration.ClientSecret[ApiUri] : string.Empty;
|
||||||
: "-";
|
|
||||||
|
|
||||||
public bool ServerAlive =>
|
public bool ServerAlive => ServerState is ServerState.Connected or ServerState.RateLimited or ServerState.Unauthorized or ServerState.Disconnected;
|
||||||
(_mareHub?.State ?? HubConnectionState.Disconnected) == HubConnectionState.Connected;
|
|
||||||
|
|
||||||
public Dictionary<string, string> ServerDictionary => new Dictionary<string, string>()
|
public Dictionary<string, string> ServerDictionary => new Dictionary<string, string>()
|
||||||
{ { MainServiceUri, MainServer } }
|
{ { MainServiceUri, MainServer } }
|
||||||
@@ -122,29 +123,17 @@ namespace MareSynchronos.WebAPI
|
|||||||
private string ApiUri => _pluginConfiguration.ApiUri;
|
private string ApiUri => _pluginConfiguration.ApiUri;
|
||||||
public int OnlineUsers => SystemInfoDto.OnlineUsers;
|
public int OnlineUsers => SystemInfoDto.OnlineUsers;
|
||||||
|
|
||||||
public ServerState ServerState
|
public ServerState ServerState { get; private set; }
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
var supportedByServer = SupportedServerVersions.Contains(_connectionDto?.ServerVersion ?? 0);
|
|
||||||
bool hasUid = !string.IsNullOrEmpty(UID);
|
|
||||||
if (_pluginConfiguration.FullPause)
|
|
||||||
return ServerState.Disconnected;
|
|
||||||
if (!ServerAlive)
|
|
||||||
return ServerState.Offline;
|
|
||||||
if (!hasUid && _pluginConfiguration.ClientSecret.ContainsKey(ApiUri))
|
|
||||||
return ServerState.Unauthorized;
|
|
||||||
if (!supportedByServer)
|
|
||||||
return ServerState.VersionMisMatch;
|
|
||||||
if (supportedByServer && hasUid)
|
|
||||||
return ServerState.Connected;
|
|
||||||
|
|
||||||
return ServerState.NoAccount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task CreateConnections()
|
public async Task CreateConnections()
|
||||||
{
|
{
|
||||||
|
if (_pluginConfiguration.FullPause)
|
||||||
|
{
|
||||||
|
ServerState = ServerState.Disconnected;
|
||||||
|
_connectionDto = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Logger.Info("Recreating Connection");
|
Logger.Info("Recreating Connection");
|
||||||
|
|
||||||
await StopConnection(_connectionCancellationTokenSource.Token);
|
await StopConnection(_connectionCancellationTokenSource.Token);
|
||||||
@@ -154,6 +143,12 @@ namespace MareSynchronos.WebAPI
|
|||||||
var token = _connectionCancellationTokenSource.Token;
|
var token = _connectionCancellationTokenSource.Token;
|
||||||
while (ServerState is not ServerState.Connected && !token.IsCancellationRequested)
|
while (ServerState is not ServerState.Connected && !token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(SecretKey))
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(2));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
await StopConnection(token);
|
await StopConnection(token);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -174,14 +169,18 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
_mareHub.On<SystemInfoDto>(Api.OnUpdateSystemInfo, (dto) => SystemInfoDto = dto);
|
_mareHub.On<SystemInfoDto>(Api.OnUpdateSystemInfo, (dto) => SystemInfoDto = dto);
|
||||||
|
|
||||||
if (_pluginConfiguration.FullPause)
|
_connectionDto =
|
||||||
|
await _mareHub.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed, token);
|
||||||
|
|
||||||
|
ServerState = ServerState.Connected;
|
||||||
|
|
||||||
|
if (_connectionDto.ServerVersion != Api.Version)
|
||||||
{
|
{
|
||||||
_connectionDto = null;
|
ServerState = ServerState.VersionMisMatch;
|
||||||
|
await StopConnection(token);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_connectionDto =
|
|
||||||
await _mareHub.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed, token);
|
|
||||||
if (ServerState is ServerState.Connected) // user is authorized && server is legit
|
if (ServerState is ServerState.Connected) // user is authorized && server is legit
|
||||||
{
|
{
|
||||||
await InitializeData(token);
|
await InitializeData(token);
|
||||||
@@ -190,17 +189,42 @@ namespace MareSynchronos.WebAPI
|
|||||||
_mareHub.Reconnected += MareHubOnReconnected;
|
_mareHub.Reconnected += MareHubOnReconnected;
|
||||||
_mareHub.Reconnecting += MareHubOnReconnecting;
|
_mareHub.Reconnecting += MareHubOnReconnecting;
|
||||||
}
|
}
|
||||||
else if (ServerState is ServerState.VersionMisMatch or ServerState.NoAccount or ServerState.Unauthorized)
|
}
|
||||||
|
catch (HubException ex)
|
||||||
|
{
|
||||||
|
Logger.Warn(ex.GetType().ToString());
|
||||||
|
Logger.Warn(ex.Message);
|
||||||
|
Logger.Warn(ex.StackTrace ?? string.Empty);
|
||||||
|
|
||||||
|
ServerState = ServerState.RateLimited;
|
||||||
|
await StopConnection(token);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (HttpRequestException ex)
|
||||||
|
{
|
||||||
|
Logger.Warn(ex.GetType().ToString());
|
||||||
|
Logger.Warn(ex.Message);
|
||||||
|
Logger.Warn(ex.StackTrace ?? string.Empty);
|
||||||
|
|
||||||
|
if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized)
|
||||||
{
|
{
|
||||||
break;
|
ServerState = ServerState.Unauthorized;
|
||||||
|
await StopConnection(token);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ServerState = ServerState.Offline;
|
||||||
|
Logger.Info("Failed to establish connection, retrying");
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Logger.Warn(ex.GetType().ToString());
|
||||||
Logger.Warn(ex.Message);
|
Logger.Warn(ex.Message);
|
||||||
Logger.Warn(ex.StackTrace ?? string.Empty);
|
Logger.Warn(ex.StackTrace ?? string.Empty);
|
||||||
Logger.Info("Failed to establish connection, retrying");
|
Logger.Info("Failed to establish connection, retrying");
|
||||||
await StopConnection(token);
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token);
|
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 20)), token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,11 +284,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
return new HubConnectionBuilder()
|
return new HubConnectionBuilder()
|
||||||
.WithUrl(ApiUri + hubName, options =>
|
.WithUrl(ApiUri + hubName, options =>
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(SecretKey) && !_pluginConfiguration.FullPause)
|
options.Headers.Add("Authorization", SecretKey);
|
||||||
{
|
|
||||||
options.Headers.Add("Authorization", SecretKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
options.Transports = HttpTransportType.WebSockets;
|
options.Transports = HttpTransportType.WebSockets;
|
||||||
})
|
})
|
||||||
.WithAutomaticReconnect(new ForeverRetryPolicy())
|
.WithAutomaticReconnect(new ForeverRetryPolicy())
|
||||||
@@ -278,6 +298,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
_uploadCancellationTokenSource?.Cancel();
|
_uploadCancellationTokenSource?.Cancel();
|
||||||
Logger.Info("Connection closed");
|
Logger.Info("Connection closed");
|
||||||
Disconnected?.Invoke();
|
Disconnected?.Invoke();
|
||||||
|
ServerState = ServerState.Offline;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,6 +315,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
CurrentUploads.Clear();
|
CurrentUploads.Clear();
|
||||||
CurrentDownloads.Clear();
|
CurrentDownloads.Clear();
|
||||||
_uploadCancellationTokenSource?.Cancel();
|
_uploadCancellationTokenSource?.Cancel();
|
||||||
|
ServerState = ServerState.Disconnected;
|
||||||
Logger.Warn("Connection closed... Reconnecting");
|
Logger.Warn("Connection closed... Reconnecting");
|
||||||
Logger.Warn(arg?.Message ?? string.Empty);
|
Logger.Warn(arg?.Message ?? string.Empty);
|
||||||
Logger.Warn(arg?.StackTrace ?? string.Empty);
|
Logger.Warn(arg?.StackTrace ?? string.Empty);
|
||||||
@@ -305,7 +327,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
if (_mareHub is not null)
|
if (_mareHub is not null)
|
||||||
{
|
{
|
||||||
Logger.Info("Stopping all connections");
|
Logger.Info("Stopping existing connection");
|
||||||
await _mareHub.StopAsync(token);
|
await _mareHub.StopAsync(token);
|
||||||
_mareHub.Closed -= MareHubOnClosed;
|
_mareHub.Closed -= MareHubOnClosed;
|
||||||
_mareHub.Reconnected -= MareHubOnReconnected;
|
_mareHub.Reconnected -= MareHubOnReconnected;
|
||||||
|
|||||||
Reference in New Issue
Block a user