merge
This commit is contained in:
@@ -79,7 +79,7 @@ public class OnlinePlayerManager : IDisposable
|
||||
|
||||
private void ApiControllerOnConnected()
|
||||
{
|
||||
var apiTask = _apiController.GetOnlineCharacters();
|
||||
var apiTask = _apiController.UserGetOnlineCharacters();
|
||||
|
||||
Task.WaitAll(apiTask);
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ public class CompactUi : Window, IDisposable
|
||||
_lastAddedUserComment = string.Empty;
|
||||
}
|
||||
|
||||
if (ImGui.BeginPopupModal("Set Notes for New User", ref _showModalForUserAddition, ImGuiWindowFlags.AlwaysAutoResize))
|
||||
if (ImGui.BeginPopupModal("Set Notes for New User", ref _showModalForUserAddition, UiShared.PopupWindowFlags))
|
||||
{
|
||||
if (_lastAddedUser == null)
|
||||
{
|
||||
@@ -180,6 +180,7 @@ public class CompactUi : Window, IDisposable
|
||||
_showModalForUserAddition = false;
|
||||
}
|
||||
}
|
||||
UiShared.SetScaledWindowSize(275);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
@@ -200,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;
|
||||
}
|
||||
}
|
||||
@@ -278,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();
|
||||
@@ -406,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);
|
||||
@@ -417,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
|
||||
@@ -477,14 +478,15 @@ public class CompactUi : Window, IDisposable
|
||||
string shardConnection = string.Equals(_apiController.ServerInfo.ShardName, "Main", StringComparison.OrdinalIgnoreCase) ? string.Empty : $"Shard: {_apiController.ServerInfo.ShardName}";
|
||||
#endif
|
||||
var shardTextSize = ImGui.CalcTextSize(shardConnection);
|
||||
var printShard = !string.IsNullOrEmpty(_apiController.ServerInfo.ShardName) && shardConnection != string.Empty;
|
||||
|
||||
if (_apiController.ServerState is ServerState.Connected)
|
||||
{
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X) / 2 - (userSize.X + textSize.X) / 2);
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X) / 2 - (userSize.X + textSize.X) / 2 - ImGui.GetStyle().ItemSpacing.X / 2);
|
||||
if (!printShard) ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextColored(ImGuiColors.ParsedGreen, userCount);
|
||||
ImGui.SameLine();
|
||||
ImGui.AlignTextToFramePadding();
|
||||
if (!printShard) ImGui.AlignTextToFramePadding();
|
||||
ImGui.Text("Users Online");
|
||||
}
|
||||
else
|
||||
@@ -492,8 +494,19 @@ public class CompactUi : Window, IDisposable
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextColored(ImGuiColors.DalamudRed, "Not connected to any server");
|
||||
}
|
||||
|
||||
if (printShard)
|
||||
{
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - ImGui.GetStyle().ItemSpacing.Y);
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X) / 2 - shardTextSize.X / 2);
|
||||
ImGui.TextUnformatted(shardConnection);
|
||||
}
|
||||
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X);
|
||||
if (printShard)
|
||||
{
|
||||
ImGui.SetCursorPosY(ImGui.GetCursorPosY() - ((userSize.Y + textSize.Y) / 2 + shardTextSize.Y) / 2 - ImGui.GetStyle().ItemSpacing.Y + buttonSize.Y / 2);
|
||||
}
|
||||
var color = UiShared.GetBoolColor(!_configuration.FullPause);
|
||||
var connectedIcon = !_configuration.FullPause ? FontAwesomeIcon.Link : FontAwesomeIcon.Unlink;
|
||||
|
||||
@@ -506,12 +519,6 @@ public class CompactUi : Window, IDisposable
|
||||
}
|
||||
ImGui.PopStyleColor();
|
||||
UiShared.AttachToolTip(!_configuration.FullPause ? "Disconnect from " + _apiController.ServerDictionary[_configuration.ApiUri] : "Connect to " + _apiController.ServerDictionary[_configuration.ApiUri]);
|
||||
|
||||
if (!string.IsNullOrEmpty(_apiController.ServerInfo.ShardName))
|
||||
{
|
||||
ImGui.SetCursorPosX((ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth()) / 2 - shardTextSize.X / 2);
|
||||
ImGui.TextUnformatted(shardConnection);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawTransfers()
|
||||
|
||||
@@ -95,11 +95,12 @@ namespace MareSynchronos.UI
|
||||
? (userCanCreateMoreGroups ? "Create Syncshell" : $"You cannot create more than {_apiController.ServerInfo.MaxGroupsCreatedByUser} Syncshells")
|
||||
: (userCanJoinMoreGroups ? "Join Syncshell" + _syncShellToJoin : $"You cannot join more than {_apiController.ServerInfo.MaxGroupsJoinedByUser} Syncshells"));
|
||||
|
||||
if (ImGui.BeginPopupModal("Enter Syncshell Password", ref _showModalEnterPassword, ImGuiWindowFlags.AlwaysAutoResize))
|
||||
if (ImGui.BeginPopupModal("Enter Syncshell Password", ref _showModalEnterPassword, UiShared.PopupWindowFlags))
|
||||
{
|
||||
UiShared.TextWrapped("Before joining any Syncshells please be aware that you will be automatically paired with everyone in the Syncshell.");
|
||||
ImGui.Separator();
|
||||
UiShared.TextWrapped("Enter the password for Syncshell " + _syncShellToJoin + ":");
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
ImGui.InputTextWithHint("##password", _syncShellToJoin + " Password", ref _syncShellPassword, 255, ImGuiInputTextFlags.Password);
|
||||
if (_errorGroupJoin)
|
||||
{
|
||||
@@ -111,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;
|
||||
@@ -119,19 +120,19 @@ namespace MareSynchronos.UI
|
||||
}
|
||||
_syncShellPassword = string.Empty;
|
||||
}
|
||||
UiShared.SetScaledWindowSize(290);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
if (ImGui.BeginPopupModal("Create Syncshell", ref _showModalCreateGroup))
|
||||
if (ImGui.BeginPopupModal("Create Syncshell", ref _showModalCreateGroup, UiShared.PopupWindowFlags))
|
||||
{
|
||||
ImGui.SetWindowSize(new(400, 200));
|
||||
UiShared.TextWrapped("Press the button below to create a new Syncshell.");
|
||||
ImGui.SetNextItemWidth(200);
|
||||
if (ImGui.Button("Create Syncshell"))
|
||||
{
|
||||
try
|
||||
{
|
||||
_lastCreatedGroup = _apiController.CreateGroup().Result;
|
||||
_lastCreatedGroup = _apiController.GroupCreate().Result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -145,6 +146,7 @@ namespace MareSynchronos.UI
|
||||
ImGui.Separator();
|
||||
_errorGroupCreate = false;
|
||||
ImGui.TextUnformatted("Syncshell ID: " + _lastCreatedGroup.GID);
|
||||
ImGui.AlignTextToFramePadding();
|
||||
ImGui.TextUnformatted("Syncshell Password: " + _lastCreatedGroup.Password);
|
||||
ImGui.SameLine();
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Copy))
|
||||
@@ -160,6 +162,7 @@ namespace MareSynchronos.UI
|
||||
new Vector4(1, 0, 0, 1));
|
||||
}
|
||||
|
||||
UiShared.SetScaledWindowSize(350);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
@@ -201,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();
|
||||
@@ -292,15 +295,14 @@ namespace MareSynchronos.UI
|
||||
|
||||
if (!_showModalBanList) _modalBanListOpened = false;
|
||||
|
||||
if (ImGui.BeginPopupModal("Manage Banlist for " + group.GID, ref _showModalBanList))
|
||||
if (ImGui.BeginPopupModal("Manage Banlist for " + group.GID, ref _showModalBanList, UiShared.PopupWindowFlags))
|
||||
{
|
||||
ImGui.SetWindowSize(new Vector2(700, 300));
|
||||
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))
|
||||
if (ImGui.BeginTable("bannedusertable" + group.GID, 5, ImGuiTableFlags.RowBg | ImGuiTableFlags.SizingStretchProp | ImGuiTableFlags.ScrollY))
|
||||
{
|
||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.None, 1);
|
||||
ImGui.TableSetupColumn("By", ImGuiTableColumnFlags.None, 1);
|
||||
@@ -323,14 +325,14 @@ 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));
|
||||
}
|
||||
ImGui.TableNextColumn();
|
||||
}
|
||||
|
||||
ImGui.EndTable();
|
||||
}
|
||||
UiShared.SetScaledWindowSize(700, 300);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
@@ -343,15 +345,16 @@ namespace MareSynchronos.UI
|
||||
if (!_showModalChangePassword) _modalChangePwOpened = false;
|
||||
|
||||
|
||||
if (ImGui.BeginPopupModal("Change Syncshell Password", ref _showModalChangePassword, ImGuiWindowFlags.AlwaysAutoResize))
|
||||
if (ImGui.BeginPopupModal("Change Syncshell Password", ref _showModalChangePassword, UiShared.PopupWindowFlags))
|
||||
{
|
||||
UiShared.TextWrapped("Enter the new Syncshell password for Syncshell " + name + " here.");
|
||||
UiShared.TextWrapped("This action is irreversible");
|
||||
ImGui.SetNextItemWidth(-1);
|
||||
ImGui.InputTextWithHint("##changepw", "New password for " + name, ref _newSyncShellPassword, 255);
|
||||
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;
|
||||
}
|
||||
@@ -361,6 +364,7 @@ namespace MareSynchronos.UI
|
||||
UiShared.ColorTextWrapped("The selected password is too short. It must be at least 10 characters.", new Vector4(1, 0, 0, 1));
|
||||
}
|
||||
|
||||
UiShared.SetScaledWindowSize(290);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
@@ -394,15 +398,17 @@ namespace MareSynchronos.UI
|
||||
bool invitesEnabled = entry.InvitesEnabled ?? true;
|
||||
var lockedIcon = invitesEnabled ? FontAwesomeIcon.LockOpen : FontAwesomeIcon.Lock;
|
||||
var iconSize = UiShared.GetIconSize(lockedIcon);
|
||||
var diffLockUnlockIcons = invitesEnabled ? 0 : (UiShared.GetIconSize(FontAwesomeIcon.LockOpen).X - iconSize.X) / 2;
|
||||
var barbuttonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars);
|
||||
var isOwner = string.Equals(entry.OwnedBy, _apiController.UID, StringComparison.Ordinal);
|
||||
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - barbuttonSize.X - iconSize.X - ImGui.GetStyle().ItemSpacing.X);
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - barbuttonSize.X - iconSize.X - diffLockUnlockIcons - ImGui.GetStyle().ItemSpacing.X);
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
ImGui.Text(lockedIcon.ToIconString());
|
||||
ImGui.PopFont();
|
||||
UiShared.AttachToolTip(invitesEnabled ? "Syncshell is open for new joiners" : "Syncshell is closed for new joiners");
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(ImGui.GetCursorPosX() + diffLockUnlockIcons);
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
|
||||
{
|
||||
ImGui.OpenPopup("ShellPopup");
|
||||
@@ -414,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
|
||||
@@ -440,10 +446,11 @@ namespace MareSynchronos.UI
|
||||
|
||||
if (isOwner)
|
||||
{
|
||||
if (UiShared.IconTextButton(lockedIcon, invitesEnabled ? "Lock Syncshell" : "Unlock Syncshell"))
|
||||
var changedToIcon = !invitesEnabled ? FontAwesomeIcon.LockOpen : FontAwesomeIcon.Lock;
|
||||
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");
|
||||
|
||||
@@ -461,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
|
||||
@@ -471,7 +478,7 @@ namespace MareSynchronos.UI
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_showModalBanList = true;
|
||||
_bannedUsers = new();
|
||||
_bannedUsers = _apiController.GetBannedUsersForGroup(entry.GID).Result;
|
||||
}
|
||||
|
||||
if (isOwner)
|
||||
@@ -481,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.");
|
||||
@@ -622,11 +629,14 @@ namespace MareSynchronos.UI
|
||||
if (plusButtonShown)
|
||||
{
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - plusButtonSize.X - (isOwner ? barButtonSize.X + ImGui.GetStyle().ItemSpacing.X : 0));
|
||||
var barWidth = isOwner || (isModerator && !userIsMod && !userIsOwner)
|
||||
? barButtonSize.X + ImGui.GetStyle().ItemSpacing.X
|
||||
: 0;
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - plusButtonSize.X - barWidth);
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
||||
{
|
||||
_ = _apiController.SendPairedClientAddition(entry.UserUID);
|
||||
_ = _apiController.UserAddPair(entry.UserUID);
|
||||
}
|
||||
UiShared.AttachToolTip("Pair with " + entryUID + " individually");
|
||||
}
|
||||
@@ -634,7 +644,6 @@ namespace MareSynchronos.UI
|
||||
if (isOwner || (isModerator && !userIsMod && !userIsOwner))
|
||||
{
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
var subtractedWidth = plusButtonShown ? (plusButtonSize.X) : 0;
|
||||
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - barButtonSize.X);
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
|
||||
@@ -651,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");
|
||||
|
||||
@@ -660,7 +669,7 @@ namespace MareSynchronos.UI
|
||||
if (UiShared.CtrlPressed())
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_ = _apiController.SendRemoveUserFromGroup(entry.GroupGID, entry.UserUID);
|
||||
_ = _apiController.GroupRemoveUser(entry.GroupGID, entry.UserUID);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -681,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 +
|
||||
@@ -691,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.");
|
||||
@@ -699,6 +708,12 @@ namespace MareSynchronos.UI
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
if (!plusButtonShown && !(isOwner || (isModerator && !userIsMod && !userIsOwner)))
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.Dummy(barButtonSize with { X = 0 });
|
||||
}
|
||||
|
||||
if (_showModalBanUser && !_banUserPopupOpen)
|
||||
{
|
||||
ImGui.OpenPopup("Ban User");
|
||||
@@ -707,19 +722,19 @@ namespace MareSynchronos.UI
|
||||
|
||||
if (!_showModalBanUser) _banUserPopupOpen = false;
|
||||
|
||||
if (ImGui.BeginPopupModal("Ban User", ref _showModalBanUser))
|
||||
if (ImGui.BeginPopupModal("Ban User", ref _showModalBanUser, UiShared.PopupWindowFlags))
|
||||
{
|
||||
ImGui.SetWindowSize(new Vector2(300, 200));
|
||||
UiShared.TextWrapped("User " + (entry.UserAlias ?? entry.UserUID) + " will be banned and removed from this Syncshell.");
|
||||
ImGui.InputTextWithHint("##banreason", "Ban Reason", ref _banReason, 255);
|
||||
if (ImGui.Button("Ban User"))
|
||||
{
|
||||
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.");
|
||||
UiShared.SetScaledWindowSize(300);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,28 +432,31 @@ public class SettingsUi : Window, IDisposable
|
||||
|
||||
UiShared.DrawHelpText("Completely deletes all your uploaded files on the service.");
|
||||
|
||||
if (ImGui.BeginPopupModal("Delete all your files?", ref _deleteFilesPopupModalShown,
|
||||
ImGuiWindowFlags.AlwaysAutoResize))
|
||||
if (ImGui.BeginPopupModal("Delete all your files?", ref _deleteFilesPopupModalShown, UiShared.PopupWindowFlags))
|
||||
{
|
||||
UiShared.TextWrapped(
|
||||
"All your own uploaded files on the service will be deleted.\nThis operation cannot be undone.");
|
||||
ImGui.Text("Are you sure you want to continue?");
|
||||
ImGui.Separator();
|
||||
if (ImGui.Button("Delete everything", new Vector2(150, 0)))
|
||||
ImGui.Spacing();
|
||||
|
||||
var buttonSize = (ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X -
|
||||
ImGui.GetStyle().ItemSpacing.X) / 2;
|
||||
|
||||
if (ImGui.Button("Delete everything", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
Task.Run(() => _apiController.DeleteAllMyFiles());
|
||||
ImGui.CloseCurrentPopup();
|
||||
Task.Run(() => _apiController.FilesDeleteAll());
|
||||
_deleteFilesPopupModalShown = false;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.Button("Cancel##cancelDelete", new Vector2(150, 0)))
|
||||
if (ImGui.Button("Cancel##cancelDelete", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_deleteFilesPopupModalShown = false;
|
||||
}
|
||||
|
||||
UiShared.SetScaledWindowSize(325);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
|
||||
@@ -464,30 +468,33 @@ public class SettingsUi : Window, IDisposable
|
||||
|
||||
UiShared.DrawHelpText("Completely deletes your account and all uploaded files to the service.");
|
||||
|
||||
if (ImGui.BeginPopupModal("Delete your account?", ref _deleteAccountPopupModalShown,
|
||||
ImGuiWindowFlags.AlwaysAutoResize))
|
||||
if (ImGui.BeginPopupModal("Delete your account?", ref _deleteAccountPopupModalShown, UiShared.PopupWindowFlags))
|
||||
{
|
||||
UiShared.TextWrapped(
|
||||
"Your account and all associated files and data on the service will be deleted.");
|
||||
UiShared.TextWrapped("Your UID will be removed from all pairing lists.");
|
||||
ImGui.Text("Are you sure you want to continue?");
|
||||
ImGui.Separator();
|
||||
if (ImGui.Button("Delete account", new Vector2(150, 0)))
|
||||
ImGui.Spacing();
|
||||
|
||||
var buttonSize = (ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X -
|
||||
ImGui.GetStyle().ItemSpacing.X) / 2;
|
||||
|
||||
if (ImGui.Button("Delete account", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
Task.Run(() => _apiController.DeleteAccount());
|
||||
ImGui.CloseCurrentPopup();
|
||||
Task.Run(() => _apiController.UserDelete());
|
||||
_deleteAccountPopupModalShown = false;
|
||||
SwitchToIntroUi?.Invoke();
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
|
||||
if (ImGui.Button("Cancel##cancelDelete", new Vector2(150, 0)))
|
||||
if (ImGui.Button("Cancel##cancelDelete", new Vector2(buttonSize, 0)))
|
||||
{
|
||||
ImGui.CloseCurrentPopup();
|
||||
_deleteAccountPopupModalShown = false;
|
||||
}
|
||||
|
||||
UiShared.SetScaledWindowSize(325);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,10 @@ public class UiShared : IDisposable
|
||||
public bool UidFontBuilt { get; private set; }
|
||||
public static bool CtrlPressed() => (GetKeyState(0xA2) & 0x8000) != 0 || (GetKeyState(0xA3) & 0x8000) != 0;
|
||||
public static bool ShiftPressed() => (GetKeyState(0xA1) & 0x8000) != 0 || (GetKeyState(0xA0) & 0x8000) != 0;
|
||||
|
||||
public static ImGuiWindowFlags PopupWindowFlags = ImGuiWindowFlags.NoResize |
|
||||
ImGuiWindowFlags.NoScrollbar |
|
||||
ImGuiWindowFlags.NoScrollWithMouse;
|
||||
|
||||
public ApiController ApiController => _apiController;
|
||||
|
||||
@@ -98,6 +102,38 @@ public class UiShared : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetScaledWindowSize(float width, bool centerWindow = true)
|
||||
{
|
||||
var newLineHeight = ImGui.GetCursorPosY();
|
||||
ImGui.NewLine();
|
||||
newLineHeight = ImGui.GetCursorPosY() - newLineHeight;
|
||||
var x = width * ImGuiHelpers.GlobalScale;
|
||||
var y = ImGui.GetCursorPos().Y + ImGui.GetWindowContentRegionMin().Y - newLineHeight * 2 - ImGui.GetStyle().ItemSpacing.Y;
|
||||
|
||||
if (centerWindow)
|
||||
{
|
||||
var center = ImGui.GetMainViewport().GetCenter();
|
||||
ImGui.SetWindowPos(new Vector2(center.X - x / 2, center.Y - y / 2));
|
||||
}
|
||||
|
||||
ImGui.SetWindowSize(new Vector2(x, y));
|
||||
}
|
||||
|
||||
public static void SetScaledWindowSize(float width, float height, bool centerWindow = true)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
var x = width * ImGuiHelpers.GlobalScale;
|
||||
var y = height * ImGuiHelpers.GlobalScale;
|
||||
|
||||
if (centerWindow)
|
||||
{
|
||||
var center = ImGui.GetMainViewport().GetCenter();
|
||||
ImGui.SetWindowPos(new Vector2(center.X - x / 2, center.Y - y / 2));
|
||||
}
|
||||
|
||||
ImGui.SetWindowSize(new Vector2(x, y));
|
||||
}
|
||||
|
||||
public static void DrawWithID(string id, Action drawSubSection)
|
||||
{
|
||||
ImGui.PushID(id);
|
||||
@@ -569,23 +605,19 @@ public class UiShared : IDisposable
|
||||
var buttonSizeY = (iconSize.Y > textSize.Y ? iconSize.Y : textSize.Y) + padding.Y * 2;
|
||||
var buttonSize = new Vector2(buttonSizeX, buttonSizeY);
|
||||
|
||||
if (ImGui.BeginChild(icon.ToIconString() + text, buttonSize))
|
||||
if (ImGui.Button("###" + icon.ToIconString() + text, buttonSize))
|
||||
{
|
||||
if (ImGui.Button("", buttonSize))
|
||||
{
|
||||
buttonClicked = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(padding.X);
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
ImGui.Text(icon.ToIconString());
|
||||
ImGui.PopFont();
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(text);
|
||||
ImGui.EndChild();
|
||||
buttonClicked = true;
|
||||
}
|
||||
|
||||
ImGui.SameLine();
|
||||
ImGui.SetCursorPosX(ImGui.GetCursorPosX() - buttonSize.X - padding.X);
|
||||
ImGui.PushFont(UiBuilder.IconFont);
|
||||
ImGui.Text(icon.ToIconString());
|
||||
ImGui.PopFont();
|
||||
ImGui.SameLine();
|
||||
ImGui.Text(text);
|
||||
|
||||
return buttonClicked;
|
||||
}
|
||||
|
||||
|
||||
@@ -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