replace multiple hubs with one
This commit is contained in:
@@ -78,7 +78,7 @@ namespace MareSynchronos
|
|||||||
public Dictionary<string, Dictionary<string, string>> UidServerComments { get; set; } = new();
|
public Dictionary<string, Dictionary<string, string>> UidServerComments { get; set; } = new();
|
||||||
|
|
||||||
public Dictionary<string, string> UidComments { get; set; } = new();
|
public Dictionary<string, string> UidComments { get; set; } = new();
|
||||||
public int Version { get; set; } = 3;
|
public int Version { get; set; } = 4;
|
||||||
|
|
||||||
public bool ShowTransferWindow { get; set; } = true;
|
public bool ShowTransferWindow { get; set; } = true;
|
||||||
|
|
||||||
@@ -157,6 +157,33 @@ namespace MareSynchronos
|
|||||||
Version = 3;
|
Version = 3;
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Version == 3)
|
||||||
|
{
|
||||||
|
Logger.Debug("Migrating Configuration from V3 to V4");
|
||||||
|
|
||||||
|
ApiUri = ApiUri.Replace("wss://v2202207178628194299.powersrv.de:6871", "wss://v2202207178628194299.powersrv.de:6872");
|
||||||
|
foreach (var kvp in ClientSecret.ToList())
|
||||||
|
{
|
||||||
|
var newKey = kvp.Key.Replace("wss://v2202207178628194299.powersrv.de:6871", "wss://v2202207178628194299.powersrv.de:6872");
|
||||||
|
ClientSecret.Remove(kvp.Key);
|
||||||
|
if (ClientSecret.ContainsKey(newKey))
|
||||||
|
{
|
||||||
|
ClientSecret[newKey] = kvp.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ClientSecret.Add(newKey, kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var kvp in UidServerComments.ToList())
|
||||||
|
{
|
||||||
|
var newKey = kvp.Key.Replace("wss://v2202207178628194299.powersrv.de:6871", "wss://v2202207178628194299.powersrv.de:6872");
|
||||||
|
UidServerComments.Remove(kvp.Key);
|
||||||
|
UidServerComments.Add(newKey, kvp.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>0.1.10.0</Version>
|
<Version>0.1.11.0</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>
|
||||||
|
|||||||
@@ -23,19 +23,19 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
Logger.Warn("Cancelling upload");
|
Logger.Warn("Cancelling upload");
|
||||||
_uploadCancellationTokenSource?.Cancel();
|
_uploadCancellationTokenSource?.Cancel();
|
||||||
_fileHub!.SendAsync(FilesHubAPI.SendAbortUpload);
|
_mareHub!.SendAsync(FilesHubAPI.SendAbortUpload);
|
||||||
CurrentUploads.Clear();
|
CurrentUploads.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteAllMyFiles()
|
public async Task DeleteAllMyFiles()
|
||||||
{
|
{
|
||||||
await _fileHub!.SendAsync(FilesHubAPI.SendDeleteAllFiles);
|
await _mareHub!.SendAsync(FilesHubAPI.SendDeleteAllFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
|
private async Task<string> DownloadFile(int downloadId, string hash, CancellationToken ct)
|
||||||
{
|
{
|
||||||
var reader = _fileHub!.StreamAsync<byte[]>(FilesHubAPI.StreamDownloadFileAsync, hash, ct);
|
var reader = _mareHub!.StreamAsync<byte[]>(FilesHubAPI.StreamDownloadFileAsync, hash, ct);
|
||||||
string fileName = Path.GetTempFileName();
|
string fileName = Path.GetTempFileName();
|
||||||
await using var fs = File.OpenWrite(fileName);
|
await using var fs = File.OpenWrite(fileName);
|
||||||
await foreach (var data in reader.WithCancellation(ct))
|
await foreach (var data in reader.WithCancellation(ct))
|
||||||
@@ -56,7 +56,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
List<DownloadFileDto> downloadFileInfoFromService = new List<DownloadFileDto>();
|
List<DownloadFileDto> downloadFileInfoFromService = new List<DownloadFileDto>();
|
||||||
foreach (var file in fileReplacementDto)
|
foreach (var file in fileReplacementDto)
|
||||||
{
|
{
|
||||||
downloadFileInfoFromService.Add(await _fileHub!.InvokeAsync<DownloadFileDto>(FilesHubAPI.InvokeGetFileSize, file.Hash, ct));
|
downloadFileInfoFromService.Add(await _mareHub!.InvokeAsync<DownloadFileDto>(FilesHubAPI.InvokeGetFileSize, file.Hash, ct));
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentDownloads[currentDownloadId] = downloadFileInfoFromService.Distinct().Select(d => new DownloadFileTransfer(d))
|
CurrentDownloads[currentDownloadId] = downloadFileInfoFromService.Distinct().Select(d => new DownloadFileTransfer(d))
|
||||||
@@ -128,7 +128,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
var uploadToken = _uploadCancellationTokenSource.Token;
|
var uploadToken = _uploadCancellationTokenSource.Token;
|
||||||
Logger.Verbose("New Token Created");
|
Logger.Verbose("New Token Created");
|
||||||
|
|
||||||
var filesToUpload = await _fileHub!.InvokeAsync<List<UploadFileDto>>(FilesHubAPI.InvokeSendFiles, character.FileReplacements.Select(c => c.Hash).Distinct(), uploadToken);
|
var filesToUpload = await _mareHub!.InvokeAsync<List<UploadFileDto>>(FilesHubAPI.InvokeSendFiles, character.FileReplacements.Select(c => c.Hash).Distinct(), uploadToken);
|
||||||
|
|
||||||
foreach (var file in filesToUpload.Where(f => !f.IsForbidden))
|
foreach (var file in filesToUpload.Where(f => !f.IsForbidden))
|
||||||
{
|
{
|
||||||
@@ -183,11 +183,11 @@ namespace MareSynchronos.WebAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.Verbose("Upload tasks complete, waiting for server to confirm");
|
Logger.Verbose("Upload tasks complete, waiting for server to confirm");
|
||||||
var anyUploadsOpen = await _fileHub!.InvokeAsync<bool>(FilesHubAPI.InvokeIsUploadFinished, uploadToken);
|
var anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(FilesHubAPI.InvokeIsUploadFinished, uploadToken);
|
||||||
Logger.Verbose("Uploads open: " + anyUploadsOpen);
|
Logger.Verbose("Uploads open: " + anyUploadsOpen);
|
||||||
while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
|
while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
anyUploadsOpen = await _fileHub!.InvokeAsync<bool>(FilesHubAPI.InvokeIsUploadFinished, uploadToken);
|
anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(FilesHubAPI.InvokeIsUploadFinished, uploadToken);
|
||||||
await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken);
|
await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken);
|
||||||
Logger.Verbose("Waiting for uploads to finish");
|
Logger.Verbose("Waiting for uploads to finish");
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
if (!uploadToken.IsCancellationRequested)
|
if (!uploadToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
Logger.Verbose("=== Pushing character data ===");
|
Logger.Verbose("=== Pushing character data ===");
|
||||||
await _userHub!.InvokeAsync(UserHubAPI.InvokePushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken);
|
await _mareHub!.InvokeAsync(UserHubAPI.InvokePushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -234,7 +234,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await _fileHub!.SendAsync(FilesHubAPI.SendUploadFileStreamAsync, fileHash, AsyncFileData(uploadToken), uploadToken);
|
await _mareHub!.SendAsync(FilesHubAPI.SendUploadFileStreamAsync, fileHash, AsyncFileData(uploadToken), uploadToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CancelDownload(int downloadId)
|
public void CancelDownload(int downloadId)
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
_pluginConfiguration.ClientSecret.Remove(ApiUri);
|
_pluginConfiguration.ClientSecret.Remove(ApiUri);
|
||||||
_pluginConfiguration.Save();
|
_pluginConfiguration.Save();
|
||||||
await _fileHub!.SendAsync(FilesHubAPI.SendDeleteAllFiles);
|
await _mareHub!.SendAsync(FilesHubAPI.SendDeleteAllFiles);
|
||||||
await _userHub!.SendAsync(UserHubAPI.SendDeleteAccount);
|
await _mareHub!.SendAsync(UserHubAPI.SendDeleteAccount);
|
||||||
await CreateConnections();
|
await CreateConnections();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
if (!ServerAlive) return;
|
if (!ServerAlive) return;
|
||||||
Logger.Debug("Registering at service " + ApiUri);
|
Logger.Debug("Registering at service " + ApiUri);
|
||||||
var response = await _userHub!.InvokeAsync<string>(UserHubAPI.InvokeRegister);
|
var response = await _mareHub!.InvokeAsync<string>(UserHubAPI.InvokeRegister);
|
||||||
_pluginConfiguration.ClientSecret[ApiUri] = response;
|
_pluginConfiguration.ClientSecret[ApiUri] = response;
|
||||||
_pluginConfiguration.Save();
|
_pluginConfiguration.Save();
|
||||||
if (!isIntroUi)
|
if (!isIntroUi)
|
||||||
@@ -35,25 +35,25 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
public async Task<List<string>> GetOnlineCharacters()
|
public async Task<List<string>> GetOnlineCharacters()
|
||||||
{
|
{
|
||||||
return await _userHub!.InvokeAsync<List<string>>(UserHubAPI.InvokeGetOnlineCharacters);
|
return await _mareHub!.InvokeAsync<List<string>>(UserHubAPI.InvokeGetOnlineCharacters);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendPairedClientAddition(string uid)
|
public async Task SendPairedClientAddition(string uid)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync(UserHubAPI.SendPairedClientAddition, uid);
|
await _mareHub!.SendAsync(UserHubAPI.SendPairedClientAddition, uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendPairedClientPauseChange(string uid, bool paused)
|
public async Task SendPairedClientPauseChange(string uid, bool paused)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync(UserHubAPI.SendPairedClientPauseChange, uid, paused);
|
await _mareHub!.SendAsync(UserHubAPI.SendPairedClientPauseChange, uid, paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendPairedClientRemoval(string uid)
|
public async Task SendPairedClientRemoval(string uid)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync(UserHubAPI.SendPairedClientRemoval, uid);
|
await _mareHub!.SendAsync(UserHubAPI.SendPairedClientRemoval, uid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
public partial class ApiController : IDisposable
|
public partial class ApiController : IDisposable
|
||||||
{
|
{
|
||||||
public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)";
|
public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)";
|
||||||
public const string MainServiceUri = "wss://v2202207178628194299.powersrv.de:6871";
|
public const string MainServiceUri = "wss://v2202207178628194299.powersrv.de:6872";
|
||||||
|
|
||||||
public readonly int[] SupportedServerVersions = { API.API.Version };
|
public readonly int[] SupportedServerVersions = { API.API.Version };
|
||||||
|
|
||||||
@@ -38,15 +38,10 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
private CancellationTokenSource _connectionCancellationTokenSource;
|
private CancellationTokenSource _connectionCancellationTokenSource;
|
||||||
|
|
||||||
private HubConnection? _fileHub;
|
private HubConnection? _mareHub;
|
||||||
|
|
||||||
private HubConnection? _connectionHub;
|
|
||||||
|
|
||||||
private HubConnection? _adminHub;
|
|
||||||
|
|
||||||
private CancellationTokenSource? _uploadCancellationTokenSource;
|
private CancellationTokenSource? _uploadCancellationTokenSource;
|
||||||
|
|
||||||
private HubConnection? _userHub;
|
|
||||||
private ConnectionDto? _connectionDto;
|
private ConnectionDto? _connectionDto;
|
||||||
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
||||||
public bool IsModerator => (_connectionDto?.IsAdmin ?? false) || (_connectionDto?.IsModerator ?? false);
|
public bool IsModerator => (_connectionDto?.IsAdmin ?? false) || (_connectionDto?.IsModerator ?? false);
|
||||||
@@ -71,7 +66,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
private void DalamudUtilOnLogOut()
|
private void DalamudUtilOnLogOut()
|
||||||
{
|
{
|
||||||
Task.Run(async () => await StopAllConnections(_connectionCancellationTokenSource.Token));
|
Task.Run(async () => await StopConnection(_connectionCancellationTokenSource.Token));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DalamudUtilOnLogIn()
|
private void DalamudUtilOnLogIn()
|
||||||
@@ -119,7 +114,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
: "-";
|
: "-";
|
||||||
|
|
||||||
public bool ServerAlive =>
|
public bool ServerAlive =>
|
||||||
(_connectionHub?.State ?? HubConnectionState.Disconnected) == HubConnectionState.Connected;
|
(_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 } }
|
||||||
@@ -155,14 +150,14 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
Logger.Verbose("Recreating Connection");
|
Logger.Verbose("Recreating Connection");
|
||||||
|
|
||||||
await StopAllConnections(_connectionCancellationTokenSource.Token);
|
await StopConnection(_connectionCancellationTokenSource.Token);
|
||||||
|
|
||||||
_connectionCancellationTokenSource.Cancel();
|
_connectionCancellationTokenSource.Cancel();
|
||||||
_connectionCancellationTokenSource = new CancellationTokenSource();
|
_connectionCancellationTokenSource = new CancellationTokenSource();
|
||||||
var token = _connectionCancellationTokenSource.Token;
|
var token = _connectionCancellationTokenSource.Token;
|
||||||
while (ServerState is not ServerState.Connected && !token.IsCancellationRequested)
|
while (ServerState is not ServerState.Connected && !token.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
await StopAllConnections(token);
|
await StopConnection(token);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -176,17 +171,11 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
if (token.IsCancellationRequested) break;
|
if (token.IsCancellationRequested) break;
|
||||||
|
|
||||||
_connectionHub = BuildHubConnection(ConnectionHubAPI.Path);
|
_mareHub = BuildHubConnection(API.API.Path);
|
||||||
_userHub = BuildHubConnection(UserHubAPI.Path);
|
|
||||||
_fileHub = BuildHubConnection(FilesHubAPI.Path);
|
|
||||||
_adminHub = BuildHubConnection(AdminHubAPI.Path);
|
|
||||||
|
|
||||||
await _connectionHub.StartAsync(token);
|
await _mareHub.StartAsync(token);
|
||||||
await _userHub.StartAsync(token);
|
|
||||||
await _fileHub.StartAsync(token);
|
|
||||||
await _adminHub.StartAsync(token);
|
|
||||||
|
|
||||||
_connectionHub.On<SystemInfoDto>(ConnectionHubAPI.OnUpdateSystemInfo, (dto) => SystemInfoDto = dto);
|
_mareHub.On<SystemInfoDto>(ConnectionHubAPI.OnUpdateSystemInfo, (dto) => SystemInfoDto = dto);
|
||||||
|
|
||||||
if (_pluginConfiguration.FullPause)
|
if (_pluginConfiguration.FullPause)
|
||||||
{
|
{
|
||||||
@@ -195,41 +184,41 @@ namespace MareSynchronos.WebAPI
|
|||||||
}
|
}
|
||||||
|
|
||||||
_connectionDto =
|
_connectionDto =
|
||||||
await _connectionHub.InvokeAsync<ConnectionDto>(ConnectionHubAPI.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed, token);
|
await _mareHub.InvokeAsync<ConnectionDto>(ConnectionHubAPI.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
|
||||||
{
|
{
|
||||||
Logger.Debug("Initializing data");
|
Logger.Debug("Initializing data");
|
||||||
_userHub.On<ClientPairDto, string>(UserHubAPI.OnUpdateClientPairs,
|
_mareHub.On<ClientPairDto, string>(UserHubAPI.OnUpdateClientPairs,
|
||||||
UpdateLocalClientPairsCallback);
|
UpdateLocalClientPairsCallback);
|
||||||
_userHub.On<CharacterCacheDto, string>(UserHubAPI.OnReceiveCharacterData,
|
_mareHub.On<CharacterCacheDto, string>(UserHubAPI.OnReceiveCharacterData,
|
||||||
ReceiveCharacterDataCallback);
|
ReceiveCharacterDataCallback);
|
||||||
_userHub.On<string>(UserHubAPI.OnRemoveOnlinePairedPlayer,
|
_mareHub.On<string>(UserHubAPI.OnRemoveOnlinePairedPlayer,
|
||||||
(s) => PairedClientOffline?.Invoke(s));
|
(s) => PairedClientOffline?.Invoke(s));
|
||||||
_userHub.On<string>(UserHubAPI.OnAddOnlinePairedPlayer,
|
_mareHub.On<string>(UserHubAPI.OnAddOnlinePairedPlayer,
|
||||||
(s) => PairedClientOnline?.Invoke(s));
|
(s) => PairedClientOnline?.Invoke(s));
|
||||||
_adminHub.On(AdminHubAPI.OnForcedReconnect, UserForcedReconnectCallback);
|
_mareHub.On(AdminHubAPI.OnForcedReconnect, UserForcedReconnectCallback);
|
||||||
|
|
||||||
PairedClients =
|
PairedClients =
|
||||||
await _userHub!.InvokeAsync<List<ClientPairDto>>(UserHubAPI.InvokeGetPairedClients, token);
|
await _mareHub!.InvokeAsync<List<ClientPairDto>>(UserHubAPI.InvokeGetPairedClients, token);
|
||||||
|
|
||||||
_connectionHub.Closed += ConnectionHubOnClosed;
|
_mareHub.Closed += MareHubOnClosed;
|
||||||
_connectionHub.Reconnected += ConnectionHubOnReconnected;
|
_mareHub.Reconnected += MareHubOnReconnected;
|
||||||
_connectionHub.Reconnecting += ConnectionHubOnReconnecting;
|
_mareHub.Reconnecting += MareHubOnReconnecting;
|
||||||
|
|
||||||
if (IsModerator)
|
if (IsModerator)
|
||||||
{
|
{
|
||||||
AdminForbiddenFiles =
|
AdminForbiddenFiles =
|
||||||
await _adminHub.InvokeAsync<List<ForbiddenFileDto>>(AdminHubAPI.InvokeGetForbiddenFiles,
|
await _mareHub.InvokeAsync<List<ForbiddenFileDto>>(AdminHubAPI.InvokeGetForbiddenFiles,
|
||||||
token);
|
token);
|
||||||
AdminBannedUsers =
|
AdminBannedUsers =
|
||||||
await _adminHub.InvokeAsync<List<BannedUserDto>>(AdminHubAPI.InvokeGetBannedUsers,
|
await _mareHub.InvokeAsync<List<BannedUserDto>>(AdminHubAPI.InvokeGetBannedUsers,
|
||||||
token);
|
token);
|
||||||
_adminHub.On<BannedUserDto>(AdminHubAPI.OnUpdateOrAddBannedUser,
|
_mareHub.On<BannedUserDto>(AdminHubAPI.OnUpdateOrAddBannedUser,
|
||||||
UpdateOrAddBannedUserCallback);
|
UpdateOrAddBannedUserCallback);
|
||||||
_adminHub.On<BannedUserDto>(AdminHubAPI.OnDeleteBannedUser, DeleteBannedUserCallback);
|
_mareHub.On<BannedUserDto>(AdminHubAPI.OnDeleteBannedUser, DeleteBannedUserCallback);
|
||||||
_adminHub.On<ForbiddenFileDto>(AdminHubAPI.OnUpdateOrAddForbiddenFile,
|
_mareHub.On<ForbiddenFileDto>(AdminHubAPI.OnUpdateOrAddForbiddenFile,
|
||||||
UpdateOrAddForbiddenFileCallback);
|
UpdateOrAddForbiddenFileCallback);
|
||||||
_adminHub.On<ForbiddenFileDto>(AdminHubAPI.OnDeleteForbiddenFile,
|
_mareHub.On<ForbiddenFileDto>(AdminHubAPI.OnDeleteForbiddenFile,
|
||||||
DeleteForbiddenFileCallback);
|
DeleteForbiddenFileCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +234,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
Logger.Warn(ex.Message);
|
Logger.Warn(ex.Message);
|
||||||
Logger.Warn(ex.StackTrace ?? string.Empty);
|
Logger.Warn(ex.StackTrace ?? string.Empty);
|
||||||
Logger.Debug("Failed to establish connection, retrying");
|
Logger.Debug("Failed to establish connection, retrying");
|
||||||
await StopAllConnections(token);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,7 +247,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
_dalamudUtil.LogIn -= DalamudUtilOnLogIn;
|
_dalamudUtil.LogIn -= DalamudUtilOnLogIn;
|
||||||
_dalamudUtil.LogOut -= DalamudUtilOnLogOut;
|
_dalamudUtil.LogOut -= DalamudUtilOnLogOut;
|
||||||
|
|
||||||
Task.Run(async () => await StopAllConnections(_connectionCancellationTokenSource.Token));
|
Task.Run(async () => await StopConnection(_connectionCancellationTokenSource.Token));
|
||||||
_connectionCancellationTokenSource?.Cancel();
|
_connectionCancellationTokenSource?.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,7 +267,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
.Build();
|
.Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task ConnectionHubOnClosed(Exception? arg)
|
private Task MareHubOnClosed(Exception? arg)
|
||||||
{
|
{
|
||||||
CurrentUploads.Clear();
|
CurrentUploads.Clear();
|
||||||
CurrentDownloads.Clear();
|
CurrentDownloads.Clear();
|
||||||
@@ -288,15 +277,15 @@ namespace MareSynchronos.WebAPI
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ConnectionHubOnReconnected(string? arg)
|
private async Task MareHubOnReconnected(string? arg)
|
||||||
{
|
{
|
||||||
Logger.Debug("Connection restored");
|
Logger.Debug("Connection restored");
|
||||||
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 10)));
|
await Task.Delay(TimeSpan.FromSeconds(new Random().Next(5, 10)));
|
||||||
_connectionDto = await _connectionHub!.InvokeAsync<ConnectionDto>(ConnectionHubAPI.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed);
|
_connectionDto = await _mareHub!.InvokeAsync<ConnectionDto>(ConnectionHubAPI.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed);
|
||||||
Connected?.Invoke();
|
Connected?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task ConnectionHubOnReconnecting(Exception? arg)
|
private Task MareHubOnReconnecting(Exception? arg)
|
||||||
{
|
{
|
||||||
CurrentUploads.Clear();
|
CurrentUploads.Clear();
|
||||||
CurrentDownloads.Clear();
|
CurrentDownloads.Clear();
|
||||||
@@ -306,38 +295,17 @@ namespace MareSynchronos.WebAPI
|
|||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StopAllConnections(CancellationToken token)
|
private async Task StopConnection(CancellationToken token)
|
||||||
{
|
{
|
||||||
Logger.Verbose("Stopping all connections");
|
Logger.Verbose("Stopping all connections");
|
||||||
if (_connectionHub is not null)
|
if (_mareHub is not null)
|
||||||
{
|
{
|
||||||
await _connectionHub.StopAsync(token);
|
await _mareHub.StopAsync(token);
|
||||||
_connectionHub.Closed -= ConnectionHubOnClosed;
|
_mareHub.Closed -= MareHubOnClosed;
|
||||||
_connectionHub.Reconnected -= ConnectionHubOnReconnected;
|
_mareHub.Reconnected -= MareHubOnReconnected;
|
||||||
_connectionHub.Reconnecting += ConnectionHubOnReconnecting;
|
_mareHub.Reconnecting += MareHubOnReconnecting;
|
||||||
await _connectionHub.DisposeAsync();
|
await _mareHub.DisposeAsync();
|
||||||
_connectionHub = null;
|
_mareHub = null;
|
||||||
}
|
|
||||||
|
|
||||||
if (_fileHub is not null)
|
|
||||||
{
|
|
||||||
await _fileHub.StopAsync(token);
|
|
||||||
await _fileHub.DisposeAsync();
|
|
||||||
_fileHub = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_userHub is not null)
|
|
||||||
{
|
|
||||||
await _userHub.StopAsync(token);
|
|
||||||
await _userHub.DisposeAsync();
|
|
||||||
_userHub = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_adminHub is not null)
|
|
||||||
{
|
|
||||||
await _adminHub.StopAsync(token);
|
|
||||||
await _adminHub.DisposeAsync();
|
|
||||||
_adminHub = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,39 +9,39 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
public async Task AddOrUpdateForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
public async Task AddOrUpdateForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
||||||
{
|
{
|
||||||
await _adminHub!.SendAsync(AdminHubAPI.SendUpdateOrAddForbiddenFile, forbiddenFile);
|
await _mareHub!.SendAsync(AdminHubAPI.SendUpdateOrAddForbiddenFile, forbiddenFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
public async Task DeleteForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
||||||
{
|
{
|
||||||
await _adminHub!.SendAsync(AdminHubAPI.SendDeleteForbiddenFile, forbiddenFile);
|
await _mareHub!.SendAsync(AdminHubAPI.SendDeleteForbiddenFile, forbiddenFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task AddOrUpdateBannedUserEntry(BannedUserDto bannedUser)
|
public async Task AddOrUpdateBannedUserEntry(BannedUserDto bannedUser)
|
||||||
{
|
{
|
||||||
await _adminHub!.SendAsync(AdminHubAPI.SendUpdateOrAddBannedUser, bannedUser);
|
await _mareHub!.SendAsync(AdminHubAPI.SendUpdateOrAddBannedUser, bannedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task DeleteBannedUserEntry(BannedUserDto bannedUser)
|
public async Task DeleteBannedUserEntry(BannedUserDto bannedUser)
|
||||||
{
|
{
|
||||||
await _adminHub!.SendAsync(AdminHubAPI.SendDeleteBannedUser, bannedUser);
|
await _mareHub!.SendAsync(AdminHubAPI.SendDeleteBannedUser, bannedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RefreshOnlineUsers()
|
public async Task RefreshOnlineUsers()
|
||||||
{
|
{
|
||||||
AdminOnlineUsers = await _adminHub!.InvokeAsync<List<OnlineUserDto>>(AdminHubAPI.InvokeGetOnlineUsers);
|
AdminOnlineUsers = await _mareHub!.InvokeAsync<List<OnlineUserDto>>(AdminHubAPI.InvokeGetOnlineUsers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OnlineUserDto> AdminOnlineUsers { get; set; } = new List<OnlineUserDto>();
|
public List<OnlineUserDto> AdminOnlineUsers { get; set; } = new List<OnlineUserDto>();
|
||||||
|
|
||||||
public void PromoteToModerator(string onlineUserUID)
|
public void PromoteToModerator(string onlineUserUID)
|
||||||
{
|
{
|
||||||
_adminHub!.SendAsync(AdminHubAPI.SendChangeModeratorStatus, onlineUserUID, true);
|
_mareHub!.SendAsync(AdminHubAPI.SendChangeModeratorStatus, onlineUserUID, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DemoteFromModerator(string onlineUserUID)
|
public void DemoteFromModerator(string onlineUserUID)
|
||||||
{
|
{
|
||||||
_adminHub!.SendAsync(AdminHubAPI.SendChangeModeratorStatus, onlineUserUID, false);
|
_mareHub!.SendAsync(AdminHubAPI.SendChangeModeratorStatus, onlineUserUID, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user