migrate to strong api calls (#29)
* migrate to strong api calls * set last added user to null on changing notes popup setting
This commit is contained in:
2
MareAPI
2
MareAPI
Submodule MareAPI updated: 1c3327f9bc...5db43c8e7a
@@ -79,7 +79,7 @@ public class OnlinePlayerManager : IDisposable
|
||||
|
||||
private void ApiControllerOnConnected()
|
||||
{
|
||||
var apiTask = _apiController.GetOnlineCharacters();
|
||||
var apiTask = _apiController.UserGetOnlineCharacters();
|
||||
|
||||
Task.WaitAll(apiTask);
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ public class CompactUi : Window, IDisposable
|
||||
{
|
||||
if (_apiController.PairedClients.All(w => !string.Equals(w.OtherUID, _pairToAdd, StringComparison.Ordinal)))
|
||||
{
|
||||
_ = _apiController.SendPairedClientAddition(_pairToAdd);
|
||||
_ = _apiController.UserAddPair(_pairToAdd);
|
||||
_pairToAdd = string.Empty;
|
||||
}
|
||||
}
|
||||
@@ -279,7 +279,7 @@ public class CompactUi : Window, IDisposable
|
||||
Logger.Debug(users.Count.ToString());
|
||||
foreach (var entry in users)
|
||||
{
|
||||
_ = _apiController.SendPairedClientPauseChange(entry.OtherUID, !entry.IsPaused);
|
||||
_ = _apiController.UserChangePairPauseStatus(entry.OtherUID, !entry.IsPaused);
|
||||
}
|
||||
|
||||
_timeout.Start();
|
||||
@@ -407,7 +407,7 @@ public class CompactUi : Window, IDisposable
|
||||
{
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
_ = _apiController.SendPairedClientRemoval(entry.OtherUID);
|
||||
_ = _apiController.UserRemovePair(entry.OtherUID);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL and click to unpair permanently from " + entryUID);
|
||||
@@ -418,7 +418,7 @@ public class CompactUi : Window, IDisposable
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
if (ImGuiComponents.IconButton(pauseIcon))
|
||||
{
|
||||
_ = _apiController.SendPairedClientPauseChange(entry.OtherUID, !entry.IsPaused);
|
||||
_ = _apiController.UserChangePairPauseStatus(entry.OtherUID, !entry.IsPaused);
|
||||
}
|
||||
UiShared.AttachToolTip(!entry.IsPaused
|
||||
? "Pause pairing with " + entryUID
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
var shell = _syncShellToJoin;
|
||||
var pw = _syncShellPassword;
|
||||
_errorGroupJoin = !_apiController.SendGroupJoin(shell, pw).Result;
|
||||
_errorGroupJoin = !_apiController.GroupJoin(shell, pw).Result;
|
||||
if (!_errorGroupJoin)
|
||||
{
|
||||
_syncShellToJoin = string.Empty;
|
||||
@@ -132,7 +132,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
try
|
||||
{
|
||||
_lastCreatedGroup = _apiController.CreateGroup().Result;
|
||||
_lastCreatedGroup = _apiController.GroupCreate().Result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -204,7 +204,7 @@ namespace MareSynchronos.UI
|
||||
var pauseIcon = (group.IsPaused ?? false) ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
|
||||
if (ImGuiComponents.IconButton(pauseIcon))
|
||||
{
|
||||
_ = _apiController.SendPauseGroup(group.GID, !group.IsPaused ?? false);
|
||||
_ = _apiController.GroupChangePauseState(group.GID, !group.IsPaused ?? false);
|
||||
}
|
||||
UiShared.AttachToolTip(((group.IsPaused ?? false) ? "Resume" : "Pause") + " pairing with all users in this Syncshell");
|
||||
ImGui.SameLine();
|
||||
@@ -299,7 +299,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
if (UiShared.IconTextButton(FontAwesomeIcon.Retweet, "Refresh Banlist from Server"))
|
||||
{
|
||||
_bannedUsers = _apiController.GetBannedUsersForGroup(group.GID).Result;
|
||||
_bannedUsers = _apiController.GroupGetBannedUsers(group.GID).Result;
|
||||
}
|
||||
|
||||
if (ImGui.BeginTable("bannedusertable" + group.GID, 5, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp | ImGuiTableFlags.ScrollY))
|
||||
@@ -325,7 +325,7 @@ namespace MareSynchronos.UI
|
||||
ImGui.TableNextColumn();
|
||||
if (UiShared.IconTextButton(FontAwesomeIcon.Check, "Unban"))
|
||||
{
|
||||
_ = _apiController.UnbanUserFromGroup(group.GID, bannedUser.UID);
|
||||
_ = _apiController.GroupUnbanUser(group.GID, bannedUser.UID);
|
||||
_bannedUsers.RemoveAll(b => string.Equals(b.UID, bannedUser.UID, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
@@ -354,7 +354,7 @@ namespace MareSynchronos.UI
|
||||
if (ImGui.Button("Change password"))
|
||||
{
|
||||
var pw = _newSyncShellPassword;
|
||||
_isPasswordValid = _apiController.ChangeGroupPassword(group.GID, pw).Result;
|
||||
_isPasswordValid = _apiController.GroupChangePassword(group.GID, pw).Result;
|
||||
_newSyncShellPassword = string.Empty;
|
||||
if (_isPasswordValid) _showModalChangePassword = false;
|
||||
}
|
||||
@@ -420,7 +420,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
_ = _apiController.SendLeaveGroup(entry.GID);
|
||||
_ = _apiController.GroupLeave(entry.GID);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL and click to leave this Syncshell" + (!string.Equals(entry.OwnedBy, _apiController.UID, StringComparison.Ordinal) ? string.Empty : Environment.NewLine
|
||||
@@ -450,7 +450,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.IconTextButton(changedToIcon, invitesEnabled ? "Lock Syncshell" : "Unlock Syncshell"))
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendGroupChangeInviteState(entry.GID, !entry.InvitesEnabled ?? true);
|
||||
_ = _apiController.GroupChangeInviteState(entry.GID, !entry.InvitesEnabled ?? true);
|
||||
}
|
||||
UiShared.AttachToolTip("Change Syncshell joining permissions" + Environment.NewLine + "Syncshell is currently " + (invitesEnabled ? "open" : "closed") + " for people to join");
|
||||
|
||||
@@ -468,7 +468,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendClearGroup(entry.GID);
|
||||
_ = _apiController.GroupClear(entry.GID);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL and click to clear this Syncshell." + Environment.NewLine + "WARNING: this action is irreversible." + Environment.NewLine
|
||||
@@ -488,7 +488,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed() && UiShared.ShiftPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendDeleteGroup(entry.GID);
|
||||
_ = _apiController.GroupDelete(entry.GID);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL and Shift and click to delete this Syncshell." + Environment.NewLine + "WARNING: this action is irreversible.");
|
||||
@@ -636,7 +636,7 @@ namespace MareSynchronos.UI
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
||||
{
|
||||
_ = _apiController.SendPairedClientAddition(entry.UserUID);
|
||||
_ = _apiController.UserAddPair(entry.UserUID);
|
||||
}
|
||||
UiShared.AttachToolTip("Pair with " + entryUID + " individually");
|
||||
}
|
||||
@@ -660,7 +660,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.IconTextButton(FontAwesomeIcon.Thumbtack, pinText))
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendChangeUserPinned(entry.GroupGID, entry.UserUID, !entry.IsPinned ?? false);
|
||||
_ = _apiController.GroupChangePinned(entry.GroupGID, entry.UserUID, !entry.IsPinned ?? false);
|
||||
}
|
||||
UiShared.AttachToolTip("Pin this user to the Syncshell. Pinned users will not be deleted in case of a manually initiated Syncshell clean");
|
||||
|
||||
@@ -669,7 +669,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendRemoveUserFromGroup(entry.GroupGID, entry.UserUID);
|
||||
_ = _apiController.GroupRemoveUser(entry.GroupGID, entry.UserUID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -690,7 +690,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SetModeratorForGroup(entry.GroupGID, entry.UserUID, !entry.IsModerator ?? false);
|
||||
_ = _apiController.GroupSetModerator(entry.GroupGID, entry.UserUID, !entry.IsModerator ?? false);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL to change the moderator status for " + (entry.UserAlias ?? entry.UserUID) + Environment.NewLine +
|
||||
@@ -700,7 +700,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed() && UiShared.ShiftPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.ChangeOwnerOfGroup(entry.GroupGID, entry.UserUID);
|
||||
_ = _apiController.GroupChangeOwnership(entry.GroupGID, entry.UserUID);
|
||||
}
|
||||
}
|
||||
UiShared.AttachToolTip("Hold CTRL and SHIFT and click to transfer ownership of this Syncshell to " + (entry.UserAlias ?? entry.UserUID) + Environment.NewLine + "WARNING: This action is irreversible.");
|
||||
@@ -730,7 +730,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
var reason = _banReason;
|
||||
_ = _apiController.BanUserFromGroup(entry.GroupGID, entry.UserUID, reason);
|
||||
_ = _apiController.GroupBanUser(entry.GroupGID, entry.UserUID, reason);
|
||||
_banReason = string.Empty;
|
||||
}
|
||||
UiShared.TextWrapped("The reason will be displayed in the banlist. The current server-side alias if present (Vanity ID) will automatically be attached to the reason.");
|
||||
|
||||
@@ -158,6 +158,7 @@ public class SettingsUi : Window, IDisposable
|
||||
ImGui.Separator();
|
||||
if (ImGui.Checkbox("Open Notes Popup on user addition", ref _openPopupOnAddition))
|
||||
{
|
||||
_apiController.LastAddedUser = null;
|
||||
_configuration.OpenPopupOnAdd = _openPopupOnAddition;
|
||||
_configuration.Save();
|
||||
}
|
||||
@@ -196,14 +197,14 @@ public class SettingsUi : Window, IDisposable
|
||||
if (ImGui.Button(
|
||||
FontAwesomeIcon.Upload.ToIconString() + "##updateFile" + forbiddenFile.Hash))
|
||||
{
|
||||
_ = _apiController.AddOrUpdateForbiddenFileEntry(forbiddenFile);
|
||||
_ = _apiController.AdminUpdateOrAddForbiddenFile(forbiddenFile);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString() + "##deleteFile" +
|
||||
forbiddenFile.Hash))
|
||||
{
|
||||
_ = _apiController.DeleteForbiddenFileEntry(forbiddenFile);
|
||||
_ = _apiController.AdminDeleteForbiddenFile(forbiddenFile);
|
||||
}
|
||||
|
||||
ImGui.PopFont();
|
||||
@@ -221,7 +222,7 @@ public class SettingsUi : Window, IDisposable
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString() + "##addForbiddenFile"))
|
||||
{
|
||||
_ = _apiController.AddOrUpdateForbiddenFileEntry(new ForbiddenFileDto()
|
||||
_ = _apiController.AdminUpdateOrAddForbiddenFile(new ForbiddenFileDto()
|
||||
{
|
||||
ForbiddenBy = _forbiddenFileHashForbiddenBy,
|
||||
Hash = _forbiddenFileHashEntry
|
||||
@@ -271,7 +272,7 @@ public class SettingsUi : Window, IDisposable
|
||||
if (ImGui.Button(FontAwesomeIcon.Upload.ToIconString() + "##updateUser" +
|
||||
bannedUser.CharacterHash))
|
||||
{
|
||||
_ = _apiController.AddOrUpdateBannedUserEntry(bannedUser);
|
||||
_ = _apiController.AdminUpdateOrAddBannedUser(bannedUser);
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
@@ -280,7 +281,7 @@ public class SettingsUi : Window, IDisposable
|
||||
if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString() + "##deleteUser" +
|
||||
bannedUser.CharacterHash))
|
||||
{
|
||||
_ = _apiController.DeleteBannedUserEntry(bannedUser);
|
||||
_ = _apiController.AdminDeleteBannedUser(bannedUser);
|
||||
}
|
||||
|
||||
ImGui.PopFont();
|
||||
@@ -305,7 +306,7 @@ public class SettingsUi : Window, IDisposable
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString() + "##addForbiddenFile"))
|
||||
{
|
||||
_ = _apiController.AddOrUpdateBannedUserEntry(new BannedUserDto()
|
||||
_ = _apiController.AdminUpdateOrAddBannedUser(new BannedUserDto()
|
||||
{
|
||||
CharacterHash = _forbiddenFileHashForbiddenBy,
|
||||
Reason = _forbiddenFileHashEntry
|
||||
@@ -378,7 +379,7 @@ public class SettingsUi : Window, IDisposable
|
||||
if (ImGui.Button(FontAwesomeIcon.SkullCrossbones.ToIconString() + "##onlineUserBan" +
|
||||
onlineUser.CharacterNameHash))
|
||||
{
|
||||
_ = _apiController.AddOrUpdateBannedUserEntry(new BannedUserDto
|
||||
_ = _apiController.AdminUpdateOrAddBannedUser(new BannedUserDto
|
||||
{
|
||||
CharacterHash = onlineUser.CharacterNameHash,
|
||||
Reason = "Banned by " + _uiShared.PlayerName
|
||||
@@ -393,7 +394,7 @@ public class SettingsUi : Window, IDisposable
|
||||
"##onlineUserModerator" +
|
||||
onlineUser.CharacterNameHash))
|
||||
{
|
||||
_apiController.PromoteToModerator(onlineUser.UID);
|
||||
_apiController.AdminChangeModeratorStatus(onlineUser.UID, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -402,7 +403,7 @@ public class SettingsUi : Window, IDisposable
|
||||
"##onlineUserNonModerator" +
|
||||
onlineUser.CharacterNameHash))
|
||||
{
|
||||
_apiController.DemoteFromModerator(onlineUser.UID);
|
||||
_apiController.AdminChangeModeratorStatus(onlineUser.UID, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -444,7 +445,7 @@ public class SettingsUi : Window, IDisposable
|
||||
|
||||
if (ImGui.Button("Delete everything", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
Task.Run(() => _apiController.DeleteAllMyFiles());
|
||||
Task.Run(() => _apiController.FilesDeleteAll());
|
||||
_deleteFilesPopupModalShown = false;
|
||||
}
|
||||
|
||||
@@ -481,7 +482,7 @@ public class SettingsUi : Window, IDisposable
|
||||
|
||||
if (ImGui.Button("Delete account", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
Task.Run(() => _apiController.DeleteAccount());
|
||||
Task.Run(() => _apiController.UserDelete());
|
||||
_deleteAccountPopupModalShown = false;
|
||||
SwitchToIntroUi?.Invoke();
|
||||
}
|
||||
|
||||
@@ -20,20 +20,25 @@ public partial class ApiController
|
||||
private readonly HashSet<string> _verifiedUploadedHashes;
|
||||
|
||||
private int _downloadId = 0;
|
||||
public void CancelUpload()
|
||||
public async void CancelUpload()
|
||||
{
|
||||
if (_uploadCancellationTokenSource != null)
|
||||
{
|
||||
Logger.Debug("Cancelling upload");
|
||||
_uploadCancellationTokenSource?.Cancel();
|
||||
_mareHub!.SendAsync(Api.SendFileAbortUpload);
|
||||
CurrentUploads.Clear();
|
||||
await FilesAbortUpload().ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DeleteAllMyFiles()
|
||||
public async Task FilesAbortUpload()
|
||||
{
|
||||
await _mareHub!.SendAsync(Api.SendFileDeleteAllFiles).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(FilesAbortUpload)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task FilesDeleteAll()
|
||||
{
|
||||
await _mareHub!.SendAsync(nameof(FilesDeleteAll)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private async Task<string> DownloadFile(int downloadId, string hash, Uri downloadUri, CancellationToken ct)
|
||||
@@ -95,7 +100,7 @@ public partial class ApiController
|
||||
Logger.Debug("Downloading files (Download ID " + currentDownloadId + ")");
|
||||
|
||||
List<DownloadFileDto> downloadFileInfoFromService = new();
|
||||
downloadFileInfoFromService.AddRange(await _mareHub!.InvokeAsync<List<DownloadFileDto>>(Api.InvokeGetFilesSizes, fileReplacementDto.Select(f => f.Hash).ToList(), ct).ConfigureAwait(false));
|
||||
downloadFileInfoFromService.AddRange(await FilesGetSizes(fileReplacementDto.Select(f => f.Hash).ToList()).ConfigureAwait(false));
|
||||
|
||||
Logger.Debug("Files with size 0 or less: " + string.Join(", ", downloadFileInfoFromService.Where(f => f.Size <= 0).Select(f => f.Hash)));
|
||||
|
||||
@@ -183,7 +188,7 @@ public partial class ApiController
|
||||
if (unverifiedUploadHashes.Any())
|
||||
{
|
||||
Logger.Debug("Verifying " + unverifiedUploadHashes.Count + " files");
|
||||
var filesToUpload = await _mareHub!.InvokeAsync<List<UploadFileDto>>(Api.InvokeFileSendFiles, unverifiedUploadHashes, uploadToken).ConfigureAwait(false);
|
||||
var filesToUpload = await FilesSend(unverifiedUploadHashes).ConfigureAwait(false);
|
||||
|
||||
foreach (var file in filesToUpload.Where(f => !f.IsForbidden))
|
||||
{
|
||||
@@ -233,11 +238,11 @@ public partial class ApiController
|
||||
}
|
||||
|
||||
Logger.Debug("Upload tasks complete, waiting for server to confirm");
|
||||
var anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken).ConfigureAwait(false);
|
||||
var anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false);
|
||||
Logger.Debug("Uploads open: " + anyUploadsOpen);
|
||||
while (anyUploadsOpen && !uploadToken.IsCancellationRequested)
|
||||
{
|
||||
anyUploadsOpen = await _mareHub!.InvokeAsync<bool>(Api.InvokeFileIsUploadFinished, uploadToken).ConfigureAwait(false);
|
||||
anyUploadsOpen = await FilesIsUploadFinished().ConfigureAwait(false);
|
||||
await Task.Delay(TimeSpan.FromSeconds(0.5), uploadToken).ConfigureAwait(false);
|
||||
Logger.Debug("Waiting for uploads to finish");
|
||||
}
|
||||
@@ -267,7 +272,7 @@ public partial class ApiController
|
||||
sb.AppendLine($"GlamourerData for {item.Key}: {!string.IsNullOrEmpty(item.Value)}");
|
||||
}
|
||||
Logger.Debug("Chara data contained: " + Environment.NewLine + sb.ToString());
|
||||
await _mareHub!.InvokeAsync(Api.InvokeUserPushCharacterDataToVisibleClients, character, visibleCharacterIds, uploadToken).ConfigureAwait(false);
|
||||
await UserPushData(character, visibleCharacterIds).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -303,9 +308,30 @@ public partial class ApiController
|
||||
}
|
||||
}
|
||||
|
||||
await _mareHub!.SendAsync(Api.SendFileUploadFileStreamAsync, fileHash, AsyncFileData(uploadToken), uploadToken).ConfigureAwait(false);
|
||||
await FilesUploadStreamAsync(fileHash, AsyncFileData(uploadToken)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task FilesUploadStreamAsync(string hash, IAsyncEnumerable<byte[]> fileContent)
|
||||
{
|
||||
await _mareHub!.SendAsync(nameof(FilesUploadStreamAsync), hash, fileContent).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<bool> FilesIsUploadFinished()
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<bool>(nameof(FilesIsUploadFinished)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<DownloadFileDto>> FilesGetSizes(List<string> hashes)
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<List<DownloadFileDto>>(nameof(FilesGetSizes), hashes).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<UploadFileDto>> FilesSend(List<string> fileListHashes)
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<List<UploadFileDto>>(nameof(FilesSend), fileListHashes).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
|
||||
public void CancelDownload(int downloadId)
|
||||
{
|
||||
while (CurrentDownloads.ContainsKey(downloadId))
|
||||
|
||||
@@ -7,36 +7,46 @@ namespace MareSynchronos.WebAPI;
|
||||
|
||||
public partial class ApiController
|
||||
{
|
||||
public async Task DeleteAccount()
|
||||
public async Task UserDelete()
|
||||
{
|
||||
_pluginConfiguration.ClientSecret.Remove(ApiUri);
|
||||
_pluginConfiguration.Save();
|
||||
await _mareHub!.SendAsync(Api.SendFileDeleteAllFiles).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(Api.SendUserDeleteAccount).ConfigureAwait(false);
|
||||
await FilesDeleteAll().ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(UserDelete)).ConfigureAwait(false);
|
||||
await CreateConnections().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<string>> GetOnlineCharacters()
|
||||
public async Task UserPushData(CharacterCacheDto characterCache, List<string> visibleCharacterIds)
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<List<string>>(Api.InvokeUserGetOnlineCharacters).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(UserPushData), characterCache, visibleCharacterIds).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendPairedClientAddition(string uid)
|
||||
public async Task<List<ClientPairDto>> UserGetPairedClients()
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendUserPairedClientAddition, uid.Trim()).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<List<ClientPairDto>>(nameof(UserGetPairedClients)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendPairedClientPauseChange(string uid, bool paused)
|
||||
public async Task<List<string>> UserGetOnlineCharacters()
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendUserPairedClientPauseChange, uid, paused).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<List<string>>(nameof(UserGetOnlineCharacters)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendPairedClientRemoval(string uid)
|
||||
public async Task UserAddPair(string uid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendUserPairedClientRemoval, uid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(UserAddPair), uid.Trim()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UserChangePairPauseStatus(string uid, bool paused)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(nameof(UserChangePairPauseStatus), uid, paused).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UserRemovePair(string uid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(nameof(UserRemovePair), uid).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,40 +8,50 @@ namespace MareSynchronos.WebAPI;
|
||||
|
||||
public partial class ApiController
|
||||
{
|
||||
public async Task AddOrUpdateForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
||||
public async Task AdminUpdateOrAddForbiddenFile(ForbiddenFileDto forbiddenFile)
|
||||
{
|
||||
await _mareHub!.SendAsync(Api.SendAdminUpdateOrAddForbiddenFile, forbiddenFile).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(AdminUpdateOrAddForbiddenFile), forbiddenFile).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task DeleteForbiddenFileEntry(ForbiddenFileDto forbiddenFile)
|
||||
public async Task AdminDeleteForbiddenFile(ForbiddenFileDto forbiddenFile)
|
||||
{
|
||||
await _mareHub!.SendAsync(Api.SendAdminDeleteForbiddenFile, forbiddenFile).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(AdminDeleteForbiddenFile), forbiddenFile).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task AddOrUpdateBannedUserEntry(BannedUserDto bannedUser)
|
||||
public async Task AdminUpdateOrAddBannedUser(BannedUserDto bannedUser)
|
||||
{
|
||||
await _mareHub!.SendAsync(Api.SendAdminUpdateOrAddBannedUser, bannedUser).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(AdminUpdateOrAddBannedUser), bannedUser).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task DeleteBannedUserEntry(BannedUserDto bannedUser)
|
||||
public async Task AdminDeleteBannedUser(BannedUserDto bannedUser)
|
||||
{
|
||||
await _mareHub!.SendAsync(Api.SendAdminDeleteBannedUser, bannedUser).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(AdminDeleteBannedUser), bannedUser).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task RefreshOnlineUsers()
|
||||
{
|
||||
AdminOnlineUsers = await _mareHub!.InvokeAsync<List<OnlineUserDto>>(Api.InvokeAdminGetOnlineUsers).ConfigureAwait(false);
|
||||
AdminOnlineUsers = await AdminGetOnlineUsers().ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<OnlineUserDto>> AdminGetOnlineUsers()
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<List<OnlineUserDto>>(nameof(AdminGetOnlineUsers)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public List<OnlineUserDto> AdminOnlineUsers { get; set; } = new List<OnlineUserDto>();
|
||||
|
||||
public void PromoteToModerator(string onlineUserUID)
|
||||
public async Task AdminChangeModeratorStatus(string onlineUserUID, bool isModerator)
|
||||
{
|
||||
_mareHub!.SendAsync(Api.SendAdminChangeModeratorStatus, onlineUserUID, true);
|
||||
await _mareHub!.SendAsync(nameof(AdminChangeModeratorStatus), onlineUserUID, isModerator).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public void DemoteFromModerator(string onlineUserUID)
|
||||
public async Task<List<ForbiddenFileDto>> AdminGetForbiddenFiles()
|
||||
{
|
||||
_mareHub!.SendAsync(Api.SendAdminChangeModeratorStatus, onlineUserUID, false);
|
||||
return await _mareHub!.InvokeAsync<List<ForbiddenFileDto>>(nameof(AdminGetForbiddenFiles)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<BannedUserDto>> AdminGetBannedUsers()
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<List<BannedUserDto>>(nameof(AdminGetBannedUsers)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
@@ -12,96 +12,115 @@ public partial class ApiController
|
||||
{
|
||||
public ClientPairDto? LastAddedUser { get; set; }
|
||||
|
||||
private void UserForcedReconnectCallback()
|
||||
public void OnUserUpdateClientPairs(Action<ClientPairDto> act)
|
||||
{
|
||||
_ = CreateConnections();
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_UserUpdateClientPairs), act);
|
||||
}
|
||||
|
||||
private void UpdateLocalClientPairsCallback(ClientPairDto dto)
|
||||
public void OnUpdateSystemInfo(Action<SystemInfoDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_UpdateSystemInfo), act);
|
||||
}
|
||||
|
||||
public void OnUserReceiveCharacterData(Action<CharacterCacheDto, string> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_UserReceiveCharacterData), act);
|
||||
}
|
||||
|
||||
public void OnUserChangePairedPlayer(Action<string, bool> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_UserChangePairedPlayer), act);
|
||||
}
|
||||
|
||||
public void OnGroupChange(Action<GroupDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_GroupChange), act);
|
||||
}
|
||||
|
||||
public void OnGroupUserChange(Action<GroupPairDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_GroupUserChange), act);
|
||||
}
|
||||
|
||||
public void OnAdminForcedReconnect(Action act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_AdminForcedReconnect), act);
|
||||
}
|
||||
|
||||
public void OnAdminDeleteBannedUser(Action<BannedUserDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_AdminDeleteBannedUser), act);
|
||||
}
|
||||
|
||||
public void OnAdminDeleteForbiddenFile(Action<ForbiddenFileDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_AdminDeleteForbiddenFile), act);
|
||||
}
|
||||
|
||||
public void OnAdminUpdateOrAddBannedUser(Action<BannedUserDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_AdminUpdateOrAddBannedUser), act);
|
||||
}
|
||||
|
||||
public void OnAdminUpdateOrAddForbiddenFile(Action<ForbiddenFileDto> act)
|
||||
{
|
||||
if (_initialized) return;
|
||||
_mareHub!.On(nameof(Client_AdminUpdateOrAddForbiddenFile), act);
|
||||
}
|
||||
|
||||
public Task Client_UserUpdateClientPairs(ClientPairDto dto)
|
||||
{
|
||||
var entry = PairedClients.SingleOrDefault(e => string.Equals(e.OtherUID, dto.OtherUID, System.StringComparison.Ordinal));
|
||||
if (dto.IsRemoved)
|
||||
{
|
||||
PairedClients.RemoveAll(p => string.Equals(p.OtherUID, dto.OtherUID, System.StringComparison.Ordinal));
|
||||
return;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
if (entry == null)
|
||||
{
|
||||
LastAddedUser = dto;
|
||||
PairedClients.Add(dto);
|
||||
return;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
entry.IsPaused = dto.IsPaused;
|
||||
entry.IsPausedFromOthers = dto.IsPausedFromOthers;
|
||||
entry.IsSynced = dto.IsSynced;
|
||||
}
|
||||
|
||||
private Task ReceiveCharacterDataCallback(CharacterCacheDto character, string characterHash)
|
||||
{
|
||||
Logger.Verbose("Received DTO for " + characterHash);
|
||||
CharacterReceived?.Invoke(null, new CharacterReceivedEventArgs(characterHash, character));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void UpdateOrAddBannedUserCallback(BannedUserDto obj)
|
||||
public Task Client_UpdateSystemInfo(SystemInfoDto systemInfo)
|
||||
{
|
||||
var user = AdminBannedUsers.SingleOrDefault(b => string.Equals(b.CharacterHash, obj.CharacterHash, System.StringComparison.Ordinal));
|
||||
if (user == null)
|
||||
{
|
||||
AdminBannedUsers.Add(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.Reason = obj.Reason;
|
||||
}
|
||||
SystemInfoDto = systemInfo;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void DeleteBannedUserCallback(BannedUserDto obj)
|
||||
public Task Client_UserReceiveCharacterData(CharacterCacheDto clientPairDto, string characterIdent)
|
||||
{
|
||||
AdminBannedUsers.RemoveAll(a => string.Equals(a.CharacterHash, obj.CharacterHash, System.StringComparison.Ordinal));
|
||||
Logger.Verbose("Received DTO for " + characterIdent);
|
||||
CharacterReceived?.Invoke(null, new CharacterReceivedEventArgs(characterIdent, clientPairDto));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void UpdateOrAddForbiddenFileCallback(ForbiddenFileDto obj)
|
||||
public Task Client_UserChangePairedPlayer(string characterIdent, bool isOnline)
|
||||
{
|
||||
var user = AdminForbiddenFiles.SingleOrDefault(b => string.Equals(b.Hash, obj.Hash, System.StringComparison.Ordinal));
|
||||
if (user == null)
|
||||
{
|
||||
AdminForbiddenFiles.Add(obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.ForbiddenBy = obj.ForbiddenBy;
|
||||
}
|
||||
if (isOnline) PairedClientOnline?.Invoke(characterIdent);
|
||||
else PairedClientOffline?.Invoke(characterIdent);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void DeleteForbiddenFileCallback(ForbiddenFileDto obj)
|
||||
{
|
||||
AdminForbiddenFiles.RemoveAll(f => string.Equals(f.Hash, obj.Hash, System.StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
private void GroupPairChangedCallback(GroupPairDto dto)
|
||||
{
|
||||
if (dto.IsRemoved.GetValueOrDefault(false))
|
||||
{
|
||||
GroupPairedClients.RemoveAll(g => string.Equals(g.GroupGID, dto.GroupGID, System.StringComparison.Ordinal) && string.Equals(g.UserUID, dto.UserUID, System.StringComparison.Ordinal));
|
||||
return;
|
||||
}
|
||||
|
||||
var existingUser = GroupPairedClients.FirstOrDefault(f => string.Equals(f.GroupGID, dto.GroupGID, System.StringComparison.Ordinal) && string.Equals(f.UserUID, dto.UserUID, System.StringComparison.Ordinal));
|
||||
if (existingUser == null)
|
||||
{
|
||||
GroupPairedClients.Add(dto);
|
||||
return;
|
||||
}
|
||||
|
||||
existingUser.IsPaused = dto.IsPaused ?? existingUser.IsPaused;
|
||||
existingUser.UserAlias = dto.UserAlias ?? existingUser.UserAlias;
|
||||
existingUser.IsPinned = dto.IsPinned ?? existingUser.IsPinned;
|
||||
existingUser.IsModerator = dto.IsModerator ?? existingUser.IsModerator;
|
||||
}
|
||||
|
||||
private async Task GroupChangedCallback(GroupDto dto)
|
||||
public async Task Client_GroupChange(GroupDto dto)
|
||||
{
|
||||
if (dto.IsDeleted.GetValueOrDefault(false))
|
||||
{
|
||||
@@ -114,7 +133,7 @@ public partial class ApiController
|
||||
if (existingGroup == null)
|
||||
{
|
||||
Groups.Add(dto);
|
||||
GroupPairedClients.AddRange(await _mareHub!.InvokeAsync<List<GroupPairDto>>(Api.InvokeGroupGetUsersInGroup, dto.GID).ConfigureAwait(false));
|
||||
GroupPairedClients.AddRange(await GroupsGetUsersInGroup(dto.GID).ConfigureAwait(false));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -123,4 +142,75 @@ public partial class ApiController
|
||||
existingGroup.IsPaused = dto.IsPaused ?? existingGroup.IsPaused;
|
||||
existingGroup.IsModerator = dto.IsModerator ?? existingGroup.IsModerator;
|
||||
}
|
||||
|
||||
public Task Client_GroupUserChange(GroupPairDto dto)
|
||||
{
|
||||
if (dto.IsRemoved.GetValueOrDefault(false))
|
||||
{
|
||||
GroupPairedClients.RemoveAll(g => string.Equals(g.GroupGID, dto.GroupGID, System.StringComparison.Ordinal) && string.Equals(g.UserUID, dto.UserUID, System.StringComparison.Ordinal));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var existingUser = GroupPairedClients.FirstOrDefault(f => string.Equals(f.GroupGID, dto.GroupGID, System.StringComparison.Ordinal) && string.Equals(f.UserUID, dto.UserUID, System.StringComparison.Ordinal));
|
||||
if (existingUser == null)
|
||||
{
|
||||
GroupPairedClients.Add(dto);
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
existingUser.IsPaused = dto.IsPaused ?? existingUser.IsPaused;
|
||||
existingUser.UserAlias = dto.UserAlias ?? existingUser.UserAlias;
|
||||
existingUser.IsPinned = dto.IsPinned ?? existingUser.IsPinned;
|
||||
existingUser.IsModerator = dto.IsModerator ?? existingUser.IsModerator;
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Client_AdminForcedReconnect()
|
||||
{
|
||||
_ = CreateConnections();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Client_AdminDeleteBannedUser(BannedUserDto dto)
|
||||
{
|
||||
AdminBannedUsers.RemoveAll(a => string.Equals(a.CharacterHash, dto.CharacterHash, System.StringComparison.Ordinal));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Client_AdminDeleteForbiddenFile(ForbiddenFileDto dto)
|
||||
{
|
||||
AdminForbiddenFiles.RemoveAll(f => string.Equals(f.Hash, dto.Hash, System.StringComparison.Ordinal));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Client_AdminUpdateOrAddBannedUser(BannedUserDto dto)
|
||||
{
|
||||
var user = AdminBannedUsers.SingleOrDefault(b => string.Equals(b.CharacterHash, dto.CharacterHash, System.StringComparison.Ordinal));
|
||||
if (user == null)
|
||||
{
|
||||
AdminBannedUsers.Add(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.Reason = dto.Reason;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Client_AdminUpdateOrAddForbiddenFile(ForbiddenFileDto dto)
|
||||
{
|
||||
var user = AdminForbiddenFiles.SingleOrDefault(b => string.Equals(b.Hash, dto.Hash, System.StringComparison.Ordinal));
|
||||
if (user == null)
|
||||
{
|
||||
AdminForbiddenFiles.Add(dto);
|
||||
}
|
||||
else
|
||||
{
|
||||
user.ForbiddenBy = dto.ForbiddenBy;
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
@@ -7,105 +6,105 @@ using System.Threading.Tasks;
|
||||
namespace MareSynchronos.WebAPI;
|
||||
public partial class ApiController
|
||||
{
|
||||
public async Task<GroupCreatedDto> CreateGroup()
|
||||
public async Task<GroupCreatedDto> GroupCreate()
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return new GroupCreatedDto();
|
||||
return await _mareHub!.InvokeAsync<GroupCreatedDto>(Api.InvokeGroupCreate).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<GroupCreatedDto>(nameof(GroupCreate)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<bool> ChangeGroupPassword(string gid, string newpassword)
|
||||
public async Task<bool> GroupChangePassword(string gid, string newpassword)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return false;
|
||||
return await _mareHub!.InvokeAsync<bool>(Api.InvokeGroupChangePassword, gid, newpassword).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<bool>(nameof(GroupChangePassword), gid, newpassword).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<GroupDto>> GetGroups()
|
||||
public async Task<List<GroupDto>> GroupsGetAll()
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return new List<GroupDto>();
|
||||
return await _mareHub!.InvokeAsync<List<GroupDto>>(Api.InvokeGroupGetGroups).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<List<GroupDto>>(nameof(GroupsGetAll)).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<GroupPairDto>> GetUsersInGroup(string gid)
|
||||
public async Task<List<GroupPairDto>> GroupsGetUsersInGroup(string gid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return new List<GroupPairDto>();
|
||||
return await _mareHub!.InvokeAsync<List<GroupPairDto>>(Api.InvokeGroupGetUsersInGroup, gid).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<List<GroupPairDto>>(nameof(GroupsGetUsersInGroup), gid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<bool> SendGroupJoin(string gid, string password)
|
||||
public async Task<bool> GroupJoin(string gid, string password)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return false;
|
||||
return await _mareHub!.InvokeAsync<bool>(Api.InvokeGroupJoin, gid.Trim(), password).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<bool>(nameof(GroupJoin), gid.Trim(), password).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendGroupChangeInviteState(string gid, bool opened)
|
||||
public async Task GroupChangeInviteState(string gid, bool opened)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupChangeInviteState, gid, opened).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupChangeInviteState), gid, opened).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendDeleteGroup(string gid)
|
||||
public async Task GroupDelete(string gid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupDelete, gid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupDelete), gid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendChangeUserPinned(string gid, string uid, bool isPinned)
|
||||
public async Task GroupChangePinned(string gid, string uid, bool isPinned)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupChangePinned, gid, uid, isPinned).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupChangePinned), gid, uid, isPinned).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendClearGroup(string gid)
|
||||
public async Task GroupClear(string gid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupClear, gid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupClear), gid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendLeaveGroup(string gid)
|
||||
public async Task GroupLeave(string gid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupLeave, gid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupLeave), gid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendPauseGroup(string gid, bool isPaused)
|
||||
public async Task GroupChangePauseState(string gid, bool isPaused)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupPause, gid, isPaused).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupChangePauseState), gid, isPaused).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SendRemoveUserFromGroup(string gid, string uid)
|
||||
public async Task GroupRemoveUser(string gid, string uid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupRemoveUser, gid, uid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupRemoveUser), gid, uid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task ChangeOwnerOfGroup(string gid, string uid)
|
||||
public async Task GroupChangeOwnership(string gid, string uid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupChangeOwner, gid, uid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupChangeOwnership), gid, uid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task BanUserFromGroup(string gid, string uid, string reason)
|
||||
public async Task GroupBanUser(string gid, string uid, string reason)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendBanUserFromGroup, gid, uid, reason).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupBanUser), gid, uid, reason).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task UnbanUserFromGroup(string gid, string uid)
|
||||
public async Task GroupUnbanUser(string gid, string uid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendUnbanUserFromGroup, gid, uid).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupUnbanUser), gid, uid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<List<BannedGroupUserDto>> GetBannedUsersForGroup(string gid)
|
||||
public async Task<List<BannedGroupUserDto>> GroupGetBannedUsers(string gid)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return new();
|
||||
return await _mareHub!.InvokeAsync<List<BannedGroupUserDto>>(Api.InvokeGetBannedUsersForGroup, gid).ConfigureAwait(false);
|
||||
return await _mareHub!.InvokeAsync<List<BannedGroupUserDto>>(nameof(GroupGetBannedUsers), gid).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task SetModeratorForGroup(string gid, string uid, bool isModerator)
|
||||
public async Task GroupSetModerator(string gid, string uid, bool isModerator)
|
||||
{
|
||||
if (!IsConnected || string.Equals(SecretKey, "-", System.StringComparison.Ordinal)) return;
|
||||
await _mareHub!.SendAsync(Api.SendGroupSetModerator, gid, uid, isModerator).ConfigureAwait(false);
|
||||
await _mareHub!.SendAsync(nameof(GroupSetModerator), gid, uid, isModerator).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,12 @@ namespace MareSynchronos.WebAPI;
|
||||
|
||||
public delegate void SimpleStringDelegate(string str);
|
||||
|
||||
public partial class ApiController : IDisposable
|
||||
public partial class ApiController : IDisposable, IMareHubClient
|
||||
{
|
||||
public const string MainServer = "Lunae Crescere Incipientis (Central Server EU)";
|
||||
public const string MainServiceUri = "wss://maresynchronos.com";
|
||||
|
||||
public readonly int[] SupportedServerVersions = { Api.Version };
|
||||
public readonly int[] SupportedServerVersions = { IMareHub.ApiVersion };
|
||||
|
||||
private readonly Configuration _pluginConfiguration;
|
||||
private readonly DalamudUtil _dalamudUtil;
|
||||
@@ -122,6 +122,8 @@ public partial class ApiController : IDisposable
|
||||
public int OnlineUsers => SystemInfoDto.OnlineUsers;
|
||||
|
||||
private ServerState _serverState;
|
||||
private bool _initialized;
|
||||
|
||||
public ServerState ServerState
|
||||
{
|
||||
get => _serverState;
|
||||
@@ -175,18 +177,17 @@ public partial class ApiController : IDisposable
|
||||
|
||||
if (token.IsCancellationRequested) break;
|
||||
|
||||
_mareHub = BuildHubConnection(Api.Path);
|
||||
_mareHub = BuildHubConnection(IMareHub.Path);
|
||||
|
||||
await _mareHub.StartAsync(token).ConfigureAwait(false);
|
||||
|
||||
_mareHub.On<SystemInfoDto>(Api.OnUpdateSystemInfo, (dto) => SystemInfoDto = dto);
|
||||
OnUpdateSystemInfo((dto) => Client_UpdateSystemInfo(dto));
|
||||
|
||||
_connectionDto =
|
||||
await _mareHub.InvokeAsync<ConnectionDto>(Api.InvokeHeartbeat, _dalamudUtil.PlayerNameHashed, token).ConfigureAwait(false);
|
||||
_connectionDto = await Heartbeat(_dalamudUtil.PlayerNameHashed).ConfigureAwait(false);
|
||||
|
||||
ServerState = ServerState.Connected;
|
||||
|
||||
if (_connectionDto.ServerVersion != Api.Version)
|
||||
if (_connectionDto.ServerVersion != IMareHub.ApiVersion)
|
||||
{
|
||||
ServerState = ServerState.VersionMisMatch;
|
||||
await StopConnection(token).ConfigureAwait(false);
|
||||
@@ -254,7 +255,7 @@ public partial class ApiController : IDisposable
|
||||
{
|
||||
await Task.Delay(TimeSpan.FromSeconds(30), ct).ConfigureAwait(false);
|
||||
if (ct.IsCancellationRequested) break;
|
||||
var needsRestart = await _mareHub!.InvokeAsync<bool>(Api.InvokeCheckClientHealth, ct).ConfigureAwait(false);
|
||||
var needsRestart = await CheckClientHealth().ConfigureAwait(false);
|
||||
Logger.Debug("Checked Client Health State, healthy: " + !needsRestart);
|
||||
if (needsRestart)
|
||||
{
|
||||
@@ -268,42 +269,30 @@ public partial class ApiController : IDisposable
|
||||
if (_mareHub == null) return;
|
||||
|
||||
Logger.Debug("Initializing data");
|
||||
_mareHub.On<ClientPairDto>(Api.OnUserUpdateClientPairs,
|
||||
UpdateLocalClientPairsCallback);
|
||||
_mareHub.On<CharacterCacheDto, string>(Api.OnUserReceiveCharacterData,
|
||||
ReceiveCharacterDataCallback);
|
||||
_mareHub.On<string>(Api.OnUserRemoveOnlinePairedPlayer,
|
||||
(s) => PairedClientOffline?.Invoke(s));
|
||||
_mareHub.On<string>(Api.OnUserAddOnlinePairedPlayer,
|
||||
(s) => PairedClientOnline?.Invoke(s));
|
||||
_mareHub.On(Api.OnAdminForcedReconnect, UserForcedReconnectCallback);
|
||||
_mareHub.On<GroupDto>(Api.OnGroupChange, GroupChangedCallback);
|
||||
_mareHub.On<GroupPairDto>(Api.OnGroupUserChange, GroupPairChangedCallback);
|
||||
OnUserUpdateClientPairs((dto) => Client_UserUpdateClientPairs(dto));
|
||||
OnUserChangePairedPlayer((ident, online) => Client_UserChangePairedPlayer(ident, online));
|
||||
OnUserReceiveCharacterData((dto, ident) => Client_UserReceiveCharacterData(dto, ident));
|
||||
OnGroupChange(async (dto) => await Client_GroupChange(dto).ConfigureAwait(false));
|
||||
OnGroupUserChange((dto) => Client_GroupUserChange(dto));
|
||||
|
||||
PairedClients =
|
||||
await _mareHub!.InvokeAsync<List<ClientPairDto>>(Api.InvokeUserGetPairedClients, token).ConfigureAwait(false);
|
||||
Groups = await GetGroups().ConfigureAwait(false);
|
||||
OnAdminForcedReconnect(() => Client_AdminForcedReconnect());
|
||||
|
||||
PairedClients = await UserGetPairedClients().ConfigureAwait(false);
|
||||
Groups = await GroupsGetAll().ConfigureAwait(false);
|
||||
GroupPairedClients.Clear();
|
||||
foreach (var group in Groups)
|
||||
{
|
||||
GroupPairedClients.AddRange(await GetUsersInGroup(group.GID).ConfigureAwait(false));
|
||||
GroupPairedClients.AddRange(await GroupsGetUsersInGroup(group.GID).ConfigureAwait(false));
|
||||
}
|
||||
|
||||
if (IsModerator)
|
||||
{
|
||||
AdminForbiddenFiles =
|
||||
await _mareHub.InvokeAsync<List<ForbiddenFileDto>>(Api.InvokeAdminGetForbiddenFiles,
|
||||
token).ConfigureAwait(false);
|
||||
AdminBannedUsers =
|
||||
await _mareHub.InvokeAsync<List<BannedUserDto>>(Api.InvokeAdminGetBannedUsers,
|
||||
token).ConfigureAwait(false);
|
||||
_mareHub.On<BannedUserDto>(Api.OnAdminUpdateOrAddBannedUser,
|
||||
UpdateOrAddBannedUserCallback);
|
||||
_mareHub.On<BannedUserDto>(Api.OnAdminDeleteBannedUser, DeleteBannedUserCallback);
|
||||
_mareHub.On<ForbiddenFileDto>(Api.OnAdminUpdateOrAddForbiddenFile,
|
||||
UpdateOrAddForbiddenFileCallback);
|
||||
_mareHub.On<ForbiddenFileDto>(Api.OnAdminDeleteForbiddenFile,
|
||||
DeleteForbiddenFileCallback);
|
||||
AdminForbiddenFiles = await AdminGetForbiddenFiles().ConfigureAwait(false);
|
||||
AdminBannedUsers = await AdminGetBannedUsers().ConfigureAwait(false);
|
||||
OnAdminUpdateOrAddBannedUser((dto) => Client_AdminUpdateOrAddBannedUser(dto));
|
||||
OnAdminDeleteBannedUser((dto) => Client_AdminDeleteBannedUser(dto));
|
||||
OnAdminUpdateOrAddForbiddenFile(dto => Client_AdminUpdateOrAddForbiddenFile(dto));
|
||||
OnAdminDeleteForbiddenFile(dto => Client_AdminDeleteForbiddenFile(dto));
|
||||
}
|
||||
|
||||
_healthCheckTokenSource?.Cancel();
|
||||
@@ -311,6 +300,7 @@ public partial class ApiController : IDisposable
|
||||
_healthCheckTokenSource = new CancellationTokenSource();
|
||||
_ = ClientHealthCheck(_healthCheckTokenSource.Token);
|
||||
|
||||
_initialized = true;
|
||||
Connected?.Invoke();
|
||||
}
|
||||
|
||||
@@ -370,6 +360,7 @@ public partial class ApiController : IDisposable
|
||||
{
|
||||
if (_mareHub is not null)
|
||||
{
|
||||
_initialized = false;
|
||||
_uploadCancellationTokenSource?.Cancel();
|
||||
Logger.Info("Stopping existing connection");
|
||||
_mareHub.Closed -= MareHubOnClosed;
|
||||
@@ -392,4 +383,14 @@ public partial class ApiController : IDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ConnectionDto> Heartbeat(string characterIdentification)
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<ConnectionDto>(nameof(Heartbeat), characterIdentification).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<bool> CheckClientHealth()
|
||||
{
|
||||
return await _mareHub!.InvokeAsync<bool>(nameof(CheckClientHealth)).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user