change Whitelist -> ClientPair
This commit is contained in:
@@ -45,7 +45,7 @@ namespace MareSynchronos.Managers
|
|||||||
private string _lastSentHash = string.Empty;
|
private string _lastSentHash = string.Empty;
|
||||||
private Task? _playerChangedTask = null;
|
private Task? _playerChangedTask = null;
|
||||||
|
|
||||||
private HashSet<string> _onlineWhitelistedUsers = new();
|
private HashSet<string> _onlinePairedUsers = new();
|
||||||
|
|
||||||
public CharacterManager(ClientState clientState, Framework framework, ApiController apiController, ObjectTable objectTable, IpcManager ipcManager, FileReplacementFactory factory,
|
public CharacterManager(ClientState clientState, Framework framework, ApiController apiController, ObjectTable objectTable, IpcManager ipcManager, FileReplacementFactory factory,
|
||||||
Configuration pluginConfiguration)
|
Configuration pluginConfiguration)
|
||||||
@@ -148,14 +148,14 @@ namespace MareSynchronos.Managers
|
|||||||
_apiController.Connected -= ApiController_Connected;
|
_apiController.Connected -= ApiController_Connected;
|
||||||
_apiController.Disconnected -= ApiController_Disconnected;
|
_apiController.Disconnected -= ApiController_Disconnected;
|
||||||
_apiController.CharacterReceived -= ApiControllerOnCharacterReceived;
|
_apiController.CharacterReceived -= ApiControllerOnCharacterReceived;
|
||||||
_apiController.RemovedFromWhitelist -= ApiControllerOnRemovedFromWhitelist;
|
_apiController.UnpairedFromOther -= ApiControllerOnUnpairedFromOther;
|
||||||
_apiController.AddedToWhitelist -= ApiControllerOnAddedToWhitelist;
|
_apiController.PairedWithOther -= ApiControllerOnPairedWithOther;
|
||||||
_apiController.WhitelistedPlayerOffline -= ApiControllerOnWhitelistedPlayerOffline;
|
_apiController.PairedClientOffline -= ApiControllerOnPairedClientOffline;
|
||||||
_watcher.Disable();
|
_watcher.Disable();
|
||||||
_watcher.PlayerChanged -= Watcher_PlayerChanged;
|
_watcher.PlayerChanged -= Watcher_PlayerChanged;
|
||||||
_watcher?.Dispose();
|
_watcher?.Dispose();
|
||||||
|
|
||||||
foreach (var character in _onlineWhitelistedUsers)
|
foreach (var character in _onlinePairedUsers)
|
||||||
{
|
{
|
||||||
RestoreCharacter(character);
|
RestoreCharacter(character);
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ namespace MareSynchronos.Managers
|
|||||||
public async Task UpdatePlayersFromService(Dictionary<string, PlayerCharacter> currentLocalPlayers)
|
public async Task UpdatePlayersFromService(Dictionary<string, PlayerCharacter> currentLocalPlayers)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Updating local players from service");
|
PluginLog.Debug("Updating local players from service");
|
||||||
currentLocalPlayers = currentLocalPlayers.Where(k => _onlineWhitelistedUsers.Contains(k.Key))
|
currentLocalPlayers = currentLocalPlayers.Where(k => _onlinePairedUsers.Contains(k.Key))
|
||||||
.ToDictionary(k => k.Key, k => k.Value);
|
.ToDictionary(k => k.Key, k => k.Value);
|
||||||
await _apiController.GetCharacterData(currentLocalPlayers
|
await _apiController.GetCharacterData(currentLocalPlayers
|
||||||
.ToDictionary(
|
.ToDictionary(
|
||||||
@@ -190,10 +190,10 @@ namespace MareSynchronos.Managers
|
|||||||
_apiController.Connected += ApiController_Connected;
|
_apiController.Connected += ApiController_Connected;
|
||||||
_apiController.Disconnected += ApiController_Disconnected;
|
_apiController.Disconnected += ApiController_Disconnected;
|
||||||
_apiController.CharacterReceived += ApiControllerOnCharacterReceived;
|
_apiController.CharacterReceived += ApiControllerOnCharacterReceived;
|
||||||
_apiController.RemovedFromWhitelist += ApiControllerOnRemovedFromWhitelist;
|
_apiController.UnpairedFromOther += ApiControllerOnUnpairedFromOther;
|
||||||
_apiController.AddedToWhitelist += ApiControllerOnAddedToWhitelist;
|
_apiController.PairedWithOther += ApiControllerOnPairedWithOther;
|
||||||
_apiController.WhitelistedPlayerOffline += ApiControllerOnWhitelistedPlayerOffline;
|
_apiController.PairedClientOffline += ApiControllerOnPairedClientOffline;
|
||||||
_apiController.WhitelistedPlayerOnline += ApiControllerOnWhitelistedPlayerOnline;
|
_apiController.PairedClientOnline += ApiControllerOnPairedClientOnline;
|
||||||
|
|
||||||
PluginLog.Debug("Watching Player, ApiController is Connected: " + _apiController.IsConnected);
|
PluginLog.Debug("Watching Player, ApiController is Connected: " + _apiController.IsConnected);
|
||||||
if (_apiController.IsConnected)
|
if (_apiController.IsConnected)
|
||||||
@@ -210,10 +210,10 @@ namespace MareSynchronos.Managers
|
|||||||
|
|
||||||
Task.WaitAll(apiTask);
|
Task.WaitAll(apiTask);
|
||||||
|
|
||||||
_onlineWhitelistedUsers = new HashSet<string>(apiTask.Result);
|
_onlinePairedUsers = new HashSet<string>(apiTask.Result);
|
||||||
var assignTask = AssignLocalPlayersData();
|
var assignTask = AssignLocalPlayersData();
|
||||||
Task.WaitAll(assignTask);
|
Task.WaitAll(assignTask);
|
||||||
PluginLog.Debug("Online and whitelisted users: " + string.Join(",", _onlineWhitelistedUsers));
|
PluginLog.Debug("Online and paired users: " + string.Join(",", _onlinePairedUsers));
|
||||||
|
|
||||||
_framework.Update += Framework_Update;
|
_framework.Update += Framework_Update;
|
||||||
_ipcManager.PenumbraRedrawEvent += IpcManager_PenumbraRedrawEvent;
|
_ipcManager.PenumbraRedrawEvent += IpcManager_PenumbraRedrawEvent;
|
||||||
@@ -226,7 +226,7 @@ namespace MareSynchronos.Managers
|
|||||||
_framework.Update -= Framework_Update;
|
_framework.Update -= Framework_Update;
|
||||||
_ipcManager.PenumbraRedrawEvent -= IpcManager_PenumbraRedrawEvent;
|
_ipcManager.PenumbraRedrawEvent -= IpcManager_PenumbraRedrawEvent;
|
||||||
_clientState.TerritoryChanged -= ClientState_TerritoryChanged;
|
_clientState.TerritoryChanged -= ClientState_TerritoryChanged;
|
||||||
foreach (var character in _onlineWhitelistedUsers)
|
foreach (var character in _onlinePairedUsers)
|
||||||
{
|
{
|
||||||
RestoreCharacter(character);
|
RestoreCharacter(character);
|
||||||
}
|
}
|
||||||
@@ -234,14 +234,14 @@ namespace MareSynchronos.Managers
|
|||||||
_lastSentHash = string.Empty;
|
_lastSentHash = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnAddedToWhitelist(object? sender, EventArgs e)
|
private void ApiControllerOnPairedWithOther(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var characterHash = (string?)sender;
|
var characterHash = (string?)sender;
|
||||||
if (string.IsNullOrEmpty(characterHash)) return;
|
if (string.IsNullOrEmpty(characterHash)) return;
|
||||||
var players = GetLocalPlayers();
|
var players = GetLocalPlayers();
|
||||||
if (players.ContainsKey(characterHash))
|
if (players.ContainsKey(characterHash))
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Removed from whitelist, restoring data for " + characterHash);
|
PluginLog.Debug("Removed pairing, restoring data for " + characterHash);
|
||||||
_ = _apiController.GetCharacterData(new Dictionary<string, int> { { characterHash, (int)players[characterHash].ClassJob.Id } });
|
_ = _apiController.GetCharacterData(new Dictionary<string, int> { { characterHash, (int)players[characterHash].ClassJob.Id } });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -322,7 +322,7 @@ namespace MareSynchronos.Managers
|
|||||||
_ipcManager.PenumbraRedraw(otherPlayerName);
|
_ipcManager.PenumbraRedraw(otherPlayerName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnRemovedFromWhitelist(object? sender, EventArgs e)
|
private void ApiControllerOnUnpairedFromOther(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var characterHash = (string?)sender;
|
var characterHash = (string?)sender;
|
||||||
if (string.IsNullOrEmpty(characterHash)) return;
|
if (string.IsNullOrEmpty(characterHash)) return;
|
||||||
@@ -343,23 +343,23 @@ namespace MareSynchronos.Managers
|
|||||||
if (player.Key != characterHash) continue;
|
if (player.Key != characterHash) continue;
|
||||||
var playerName = player.Value.Name.ToString();
|
var playerName = player.Value.Name.ToString();
|
||||||
RestorePreviousCharacter(playerName);
|
RestorePreviousCharacter(playerName);
|
||||||
PluginLog.Debug("Removed from whitelist, restoring glamourer state for " + playerName);
|
PluginLog.Debug("Removed from pairing, restoring glamourer state for " + playerName);
|
||||||
_ipcManager.PenumbraRemoveTemporaryCollection(playerName);
|
_ipcManager.PenumbraRemoveTemporaryCollection(playerName);
|
||||||
_ipcManager.GlamourerRevertCharacterCustomization(playerName);
|
_ipcManager.GlamourerRevertCharacterCustomization(playerName);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnWhitelistedPlayerOffline(object? sender, EventArgs e)
|
private void ApiControllerOnPairedClientOffline(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Player offline: " + sender!);
|
PluginLog.Debug("Player offline: " + sender!);
|
||||||
_onlineWhitelistedUsers.Remove((string)sender!);
|
_onlinePairedUsers.Remove((string)sender!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApiControllerOnWhitelistedPlayerOnline(object? sender, EventArgs e)
|
private void ApiControllerOnPairedClientOnline(object? sender, EventArgs e)
|
||||||
{
|
{
|
||||||
PluginLog.Debug("Player online: " + sender!);
|
PluginLog.Debug("Player online: " + sender!);
|
||||||
_onlineWhitelistedUsers.Add((string)sender!);
|
_onlinePairedUsers.Add((string)sender!);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task AssignLocalPlayersData()
|
private async Task AssignLocalPlayersData()
|
||||||
@@ -428,7 +428,7 @@ namespace MareSynchronos.Managers
|
|||||||
var pObj = (PlayerCharacter)obj;
|
var pObj = (PlayerCharacter)obj;
|
||||||
var hashedName = Crypto.GetHash256(pObj.Name.ToString() + pObj.HomeWorld.Id.ToString());
|
var hashedName = Crypto.GetHash256(pObj.Name.ToString() + pObj.HomeWorld.Id.ToString());
|
||||||
|
|
||||||
if (!_onlineWhitelistedUsers.Contains(hashedName)) continue;
|
if (!_onlinePairedUsers.Contains(hashedName)) continue;
|
||||||
|
|
||||||
localPlayersList.Add(hashedName);
|
localPlayersList.Add(hashedName);
|
||||||
if (!_cachedLocalPlayers.ContainsKey(hashedName)) newPlayers[hashedName] = pObj;
|
if (!_cachedLocalPlayers.ContainsKey(hashedName)) newPlayers[hashedName] = pObj;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace MareSynchronos.UI
|
|||||||
ImGui.Text("Welcome to Mare Synchronos!");
|
ImGui.Text("Welcome to Mare Synchronos!");
|
||||||
ImGui.SetWindowFontScale(1.0f);
|
ImGui.SetWindowFontScale(1.0f);
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
UIShared.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other whitelisted Mare Synchronos users. " +
|
UIShared.TextWrapped("Mare Synchronos is a plugin that will replicate your full current character state including all Penumbra mods to other paired Mare Synchronos users. " +
|
||||||
"Note that you will have to have Penumbra as well as Glamourer installed to use this plugin.");
|
"Note that you will have to have Penumbra as well as Glamourer installed to use this plugin.");
|
||||||
UIShared.TextWrapped("We will have to setup a few things first before you can start using this plugin. Click on next to continue.");
|
UIShared.TextWrapped("We will have to setup a few things first before you can start using this plugin. Click on next to continue.");
|
||||||
|
|
||||||
@@ -90,11 +90,11 @@ namespace MareSynchronos.UI
|
|||||||
"Files present on the service that already represent your active mod files will not be uploaded again.");
|
"Files present on the service that already represent your active mod files will not be uploaded again.");
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudRed);
|
||||||
UIShared.TextWrapped("The mod files you are uploading are confidential and will not be distributed to parties other than the ones who are requesting the exact same mod files. " +
|
UIShared.TextWrapped("The mod files you are uploading are confidential and will not be distributed to parties other than the ones who are requesting the exact same mod files. " +
|
||||||
"Please think about who you are going to whitelist since it is unavoidable that they will receive and locally cache the necessary mod files that you have currently in use. " +
|
"Please think about who you are going to pair since it is unavoidable that they will receive and locally cache the necessary mod files that you have currently in use. " +
|
||||||
"Locally cached mod files will have arbitrary file names to discourage attempts at replicating the original mod.");
|
"Locally cached mod files will have arbitrary file names to discourage attempts at replicating the original mod.");
|
||||||
ImGui.PopStyleColor();
|
ImGui.PopStyleColor();
|
||||||
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
ImGui.PushStyleColor(ImGuiCol.Text, ImGuiColors.DalamudYellow);
|
||||||
UIShared.TextWrapped("The plugin creator tried their best to keep you secure. However, there is no guarantee for 100% security. Do not blindly add everyone to your whitelist.");
|
UIShared.TextWrapped("The plugin creator tried their best to keep you secure. However, there is no guarantee for 100% security. Do not blindly pair your client with everyone.");
|
||||||
ImGui.PopStyleColor();
|
ImGui.PopStyleColor();
|
||||||
UIShared.TextWrapped("Mod files that are saved on the service will remain on the service as long as there are requests for the files from clients. " +
|
UIShared.TextWrapped("Mod files that are saved on the service will remain on the service as long as there are requests for the files from clients. " +
|
||||||
"After a period of not being used, the mod files will be automatically deleted. " +
|
"After a period of not being used, the mod files will be automatically deleted. " +
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
using Dalamud.Interface;
|
using Dalamud.Interface;
|
||||||
using Dalamud.Interface.Colors;
|
using Dalamud.Interface.Colors;
|
||||||
using Dalamud.Interface.Windowing;
|
using Dalamud.Interface.Windowing;
|
||||||
using Dalamud.Logging;
|
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using MareSynchronos.WebAPI;
|
using MareSynchronos.WebAPI;
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Numerics;
|
|
||||||
using Dalamud.Configuration;
|
|
||||||
using MareSynchronos.API;
|
|
||||||
|
|
||||||
namespace MareSynchronos.UI
|
namespace MareSynchronos.UI
|
||||||
{
|
{
|
||||||
@@ -80,9 +76,9 @@ namespace MareSynchronos.UI
|
|||||||
{
|
{
|
||||||
ImGui.SetClipboardText(_apiController.UID);
|
ImGui.SetClipboardText(_apiController.UID);
|
||||||
}
|
}
|
||||||
ImGui.Text("Share this UID to other Mare users so they can add you to their whitelist.");
|
ImGui.Text("Share this UID to other Mare users so they pair their client with yours.");
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
DrawWhiteListContent();
|
DrawPairedClientsContent();
|
||||||
DrawFileCacheSettings();
|
DrawFileCacheSettings();
|
||||||
DrawCurrentTransfers();
|
DrawCurrentTransfers();
|
||||||
}
|
}
|
||||||
@@ -172,12 +168,12 @@ namespace MareSynchronos.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawWhiteListContent()
|
private void DrawPairedClientsContent()
|
||||||
{
|
{
|
||||||
if (!_apiController.ServerAlive) return;
|
if (!_apiController.ServerAlive) return;
|
||||||
if (ImGui.TreeNode("Whitelist Configuration"))
|
if (ImGui.TreeNode("PairedWithOther Clients"))
|
||||||
{
|
{
|
||||||
if (ImGui.BeginTable("WhitelistTable", 6))
|
if (ImGui.BeginTable("PairedClientsTable", 6))
|
||||||
{
|
{
|
||||||
ImGui.TableSetupColumn("Pause", ImGuiTableColumnFlags.WidthFixed, 50);
|
ImGui.TableSetupColumn("Pause", ImGuiTableColumnFlags.WidthFixed, 50);
|
||||||
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.WidthFixed, 110);
|
ImGui.TableSetupColumn("UID", ImGuiTableColumnFlags.WidthFixed, 110);
|
||||||
@@ -187,14 +183,16 @@ namespace MareSynchronos.UI
|
|||||||
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 70);
|
ImGui.TableSetupColumn("", ImGuiTableColumnFlags.WidthFixed, 70);
|
||||||
|
|
||||||
ImGui.TableHeadersRow();
|
ImGui.TableHeadersRow();
|
||||||
foreach (var item in _apiController.WhitelistEntries.ToList())
|
foreach (var item in _apiController.PairedClients.ToList())
|
||||||
{
|
{
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
bool isPaused = item.IsPaused;
|
ImGui.PushFont(UiBuilder.IconFont);
|
||||||
if (ImGui.Checkbox("##paused" + item.OtherUID, ref isPaused))
|
string pauseIcon = item.IsPaused ? FontAwesomeIcon.Play.ToIconString() : FontAwesomeIcon.Pause.ToIconString();
|
||||||
|
if (ImGui.Button(pauseIcon + "##paused" + item.OtherUID))
|
||||||
{
|
{
|
||||||
_ = _apiController.SendWhitelistPauseChange(item.OtherUID, isPaused);
|
_ = _apiController.SendPairedClientPauseChange(item.OtherUID, !item.IsPaused);
|
||||||
}
|
}
|
||||||
|
ImGui.PopFont();
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGui.TextColored(
|
ImGui.TextColored(
|
||||||
@@ -202,7 +200,7 @@ namespace MareSynchronos.UI
|
|||||||
item.OtherUID);
|
item.OtherUID);
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
ImGui.TextColored(UIShared.GetBoolColor(item.IsSynced),
|
ImGui.TextColored(UIShared.GetBoolColor(item.IsSynced),
|
||||||
!item.IsSynced ? "Has not added you" : "Whitelisted");
|
!item.IsSynced ? "Has not added you" : "PairedWithOther");
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
string pauseYou = item.IsPaused ? "You paused them" : "";
|
string pauseYou = item.IsPaused ? "You paused them" : "";
|
||||||
string pauseThey = item.IsPausedFromOthers ? "They paused you" : "";
|
string pauseThey = item.IsPausedFromOthers ? "They paused you" : "";
|
||||||
@@ -219,11 +217,13 @@ namespace MareSynchronos.UI
|
|||||||
_configuration.Save();
|
_configuration.Save();
|
||||||
}
|
}
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
if (ImGui.Button("Delete##" + item.OtherUID))
|
ImGui.PushFont(UiBuilder.IconFont);
|
||||||
|
if (ImGui.Button(FontAwesomeIcon.Trash.ToIconString() + "##" + item.OtherUID))
|
||||||
{
|
{
|
||||||
_ = _apiController.SendWhitelistRemoval(item.OtherUID);
|
_ = _apiController.SendPairedClientRemoval(item.OtherUID);
|
||||||
_apiController.WhitelistEntries.Remove(item);
|
_apiController.PairedClients.Remove(item);
|
||||||
}
|
}
|
||||||
|
ImGui.PopFont();
|
||||||
|
|
||||||
ImGui.TableNextRow();
|
ImGui.TableNextRow();
|
||||||
}
|
}
|
||||||
@@ -231,26 +231,22 @@ namespace MareSynchronos.UI
|
|||||||
ImGui.EndTable();
|
ImGui.EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
var whitelistEntry = tempDto.OtherUID;
|
var pairedClientEntry = tempNameUID;
|
||||||
ImGui.SetNextItemWidth(200);
|
ImGui.SetNextItemWidth(200);
|
||||||
if (ImGui.InputText("UID", ref whitelistEntry, 20))
|
if (ImGui.InputText("UID", ref pairedClientEntry, 20))
|
||||||
{
|
{
|
||||||
tempDto.OtherUID = whitelistEntry;
|
tempNameUID = pairedClientEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
if (ImGui.Button("Add to whitelist"))
|
ImGui.PushFont(UiBuilder.IconFont);
|
||||||
|
if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString()+"##addToPairedClients"))
|
||||||
{
|
{
|
||||||
if (_apiController.WhitelistEntries.All(w => w.OtherUID != tempDto.OtherUID))
|
if (_apiController.PairedClients.All(w => w.OtherUID != tempNameUID))
|
||||||
{
|
{
|
||||||
_apiController.WhitelistEntries.Add(new WhitelistDto()
|
_ = _apiController.SendPairedClientAddition(tempNameUID);
|
||||||
{
|
|
||||||
OtherUID = tempDto.OtherUID
|
|
||||||
});
|
|
||||||
|
|
||||||
_ = _apiController.SendWhitelistAddition(tempDto.OtherUID);
|
tempNameUID = string.Empty;
|
||||||
|
|
||||||
tempDto.OtherUID = string.Empty;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,6 +254,6 @@ namespace MareSynchronos.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private WhitelistDto tempDto = new WhitelistDto() { OtherUID = string.Empty };
|
private string tempNameUID = string.Empty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ namespace MareSynchronos.WebAPI
|
|||||||
public event EventHandler? Connected;
|
public event EventHandler? Connected;
|
||||||
public event EventHandler? Disconnected;
|
public event EventHandler? Disconnected;
|
||||||
public event EventHandler<CharacterReceivedEventArgs>? CharacterReceived;
|
public event EventHandler<CharacterReceivedEventArgs>? CharacterReceived;
|
||||||
public event EventHandler? RemovedFromWhitelist;
|
public event EventHandler? UnpairedFromOther;
|
||||||
public event EventHandler? AddedToWhitelist;
|
public event EventHandler? PairedWithOther;
|
||||||
public event EventHandler? WhitelistedPlayerOnline;
|
public event EventHandler? PairedClientOnline;
|
||||||
public event EventHandler? WhitelistedPlayerOffline;
|
public event EventHandler? PairedClientOffline;
|
||||||
|
|
||||||
public List<WhitelistDto> WhitelistEntries { get; set; } = new List<WhitelistDto>();
|
public List<ClientPairDto> PairedClients { get; set; } = new();
|
||||||
|
|
||||||
readonly CancellationTokenSource cts;
|
readonly CancellationTokenSource cts;
|
||||||
private HubConnection? _heartbeatHub;
|
private HubConnection? _heartbeatHub;
|
||||||
@@ -143,8 +143,8 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
private async Task LoadInitialData()
|
private async Task LoadInitialData()
|
||||||
{
|
{
|
||||||
var whiteList = await _userHub!.InvokeAsync<List<WhitelistDto>>("GetWhitelist");
|
var pairedClients = await _userHub!.InvokeAsync<List<ClientPairDto>>("GetPairedClients");
|
||||||
WhitelistEntries = whiteList.ToList();
|
PairedClients = pairedClients.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RestartHeartbeat()
|
public void RestartHeartbeat()
|
||||||
@@ -215,10 +215,10 @@ namespace MareSynchronos.WebAPI
|
|||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
await _userHub.StartAsync();
|
await _userHub.StartAsync();
|
||||||
_userHub.On<WhitelistDto, string>("UpdateWhitelist", UpdateLocalWhitelist);
|
_userHub.On<ClientPairDto, string>("UpdateClientPairs", UpdateLocalClientPairs);
|
||||||
_userHub.On<CharacterCacheDto, string>("ReceiveCharacterData", ReceiveCharacterData);
|
_userHub.On<CharacterCacheDto, string>("ReceiveCharacterData", ReceiveCharacterData);
|
||||||
_userHub.On<string>("RemoveOnlineWhitelistedPlayer", (s) => WhitelistedPlayerOffline?.Invoke(s, EventArgs.Empty));
|
_userHub.On<string>("RemoveOnlinePairedPlayer", (s) => PairedClientOffline?.Invoke(s, EventArgs.Empty));
|
||||||
_userHub.On<string>("AddOnlineWhitelistedPlayer", (s) => WhitelistedPlayerOnline?.Invoke(s, EventArgs.Empty));
|
_userHub.On<string>("AddOnlinePairedPlayer", (s) => PairedClientOnline?.Invoke(s, EventArgs.Empty));
|
||||||
|
|
||||||
PluginLog.Debug("Creating File Hub");
|
PluginLog.Debug("Creating File Hub");
|
||||||
_fileHub = new HubConnectionBuilder()
|
_fileHub = new HubConnectionBuilder()
|
||||||
@@ -239,19 +239,19 @@ namespace MareSynchronos.WebAPI
|
|||||||
await _fileHub.StartAsync(cts.Token);
|
await _fileHub.StartAsync(cts.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateLocalWhitelist(WhitelistDto dto, string characterIdentifier)
|
private void UpdateLocalClientPairs(ClientPairDto dto, string characterIdentifier)
|
||||||
{
|
{
|
||||||
var entry = WhitelistEntries.SingleOrDefault(e => e.OtherUID == dto.OtherUID);
|
var entry = PairedClients.SingleOrDefault(e => e.OtherUID == dto.OtherUID);
|
||||||
if (entry == null)
|
if (entry == null)
|
||||||
{
|
{
|
||||||
RemovedFromWhitelist?.Invoke(characterIdentifier, EventArgs.Empty);
|
UnpairedFromOther?.Invoke(characterIdentifier, EventArgs.Empty);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((entry.IsPausedFromOthers != dto.IsPausedFromOthers || entry.IsSynced != dto.IsSynced || entry.IsPaused != dto.IsPaused)
|
if ((entry.IsPausedFromOthers != dto.IsPausedFromOthers || entry.IsSynced != dto.IsSynced || entry.IsPaused != dto.IsPaused)
|
||||||
&& !dto.IsPaused && dto.IsSynced && !dto.IsPausedFromOthers)
|
&& !dto.IsPaused && dto.IsSynced && !dto.IsPausedFromOthers)
|
||||||
{
|
{
|
||||||
AddedToWhitelist?.Invoke(characterIdentifier, EventArgs.Empty);
|
PairedWithOther?.Invoke(characterIdentifier, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.IsPaused = dto.IsPaused;
|
entry.IsPaused = dto.IsPaused;
|
||||||
@@ -260,7 +260,7 @@ namespace MareSynchronos.WebAPI
|
|||||||
|
|
||||||
if (dto.IsPaused || dto.IsPausedFromOthers || !dto.IsSynced)
|
if (dto.IsPaused || dto.IsPausedFromOthers || !dto.IsSynced)
|
||||||
{
|
{
|
||||||
RemovedFromWhitelist?.Invoke(characterIdentifier, EventArgs.Empty);
|
UnpairedFromOther?.Invoke(characterIdentifier, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,37 +445,22 @@ namespace MareSynchronos.WebAPI
|
|||||||
hashedCharacterNames);
|
hashedCharacterNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendWhitelistPauseChange(string uid, bool paused)
|
public async Task SendPairedClientPauseChange(string uid, bool paused)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync("SendWhitelistPauseChange", uid, paused);
|
await _userHub!.SendAsync("SendPairedClientPauseChange", uid, paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendWhitelistAddition(string uid)
|
public async Task SendPairedClientAddition(string uid)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync("SendWhitelistAddition", uid);
|
await _userHub!.SendAsync("SendPairedClientAddition", uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendWhitelistRemoval(string uid)
|
public async Task SendPairedClientRemoval(string uid)
|
||||||
{
|
{
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
if (!IsConnected || SecretKey == "-") return;
|
||||||
await _userHub!.SendAsync("SendWhitelistRemoval", uid);
|
await _userHub!.SendAsync("SendPairedClientRemoval", uid);
|
||||||
}
|
|
||||||
|
|
||||||
public async Task SendWhitelist()
|
|
||||||
{
|
|
||||||
if (!IsConnected || SecretKey == "-") return;
|
|
||||||
await _userHub!.SendAsync("SendWhitelist", WhitelistEntries.ToList());
|
|
||||||
WhitelistEntries = (await _userHub!.InvokeAsync<List<WhitelistDto>>("GetWhitelist")).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task<List<string>> GetWhitelist()
|
|
||||||
{
|
|
||||||
PluginLog.Debug("Getting whitelist from service " + ApiUri);
|
|
||||||
|
|
||||||
List<string> whitelist = new();
|
|
||||||
return whitelist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
@@ -488,11 +473,5 @@ namespace MareSynchronos.WebAPI
|
|||||||
{
|
{
|
||||||
return await _userHub!.InvokeAsync<List<string>>("SendCharacterNameHash", hashedName);
|
return await _userHub!.InvokeAsync<List<string>>("SendCharacterNameHash", hashedName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SendVisibilityData(List<string> visibilities)
|
|
||||||
{
|
|
||||||
if (!IsConnected) return;
|
|
||||||
await _userHub!.SendAsync("SendVisibilityList", visibilities);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user