Client rework for API change and paradigm shift (#39)

* most of the groups refactoring on client

* register OnMethods for group stuff

* start implementing client (still pretty broken)

* finish implementing new api first iteration

* idk rework everything for pair shit (still WIP); goal is to remove PairedClients and GroupPairClients from ApiController

* move everything to PairManager, remove dictionaries from APiController

* remove admin stuff from client, cleanup

* adjust reconnection handling, add new settings, todo still to remove access from old stuff that's marked obsolete from config

* add back adding servers, fix intro ui

* fix obsolete calls

* adjust config namespace

* add UI for setting animation/sound permissions to syncshells

* add ConfigurationService to hot reload config on change from external

* move transient data cache to configuration

* add deleting service to ui

* fix saving of transient resources

* fix group pair user assignments

* halt scanner when penumbra inactive, add visible/online/offline split to individual pairs and tags

* add presence to syncshell ui

* move fullpause from config to server config

* fixes in code style

* more codestyle

* show info icon on player in shells, don't show icon when no changes from default state are made, add online notifs

* fixes to intro UI

---------

Co-authored-by: rootdarkarchon <root.darkarchon@outlook.com>
This commit is contained in:
rootdarkarchon
2023-01-29 15:13:53 +01:00
committed by GitHub
parent 616af3626a
commit b2276a1883
79 changed files with 3585 additions and 2701 deletions

View File

@@ -0,0 +1,9 @@
namespace MareSynchronos.MareConfiguration;
[Serializable]
public class Authentication
{
public string CharacterName { get; set; } = string.Empty;
public uint WorldId { get; set; } = 0;
public int SecretKeyIdx { get; set; } = -1;
}

View File

@@ -0,0 +1,149 @@
using Dalamud.Configuration;
using Dalamud.Plugin;
using MareSynchronos.Utils;
using MareSynchronos.WebAPI;
namespace MareSynchronos.MareConfiguration;
[Serializable]
[Obsolete("Migrated to MareConfig")]
public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 6;
[NonSerialized]
private DalamudPluginInterface? _pluginInterface;
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
{
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
};
public bool AcceptedAgreement { get; set; } = false;
public string CacheFolder { get; set; } = string.Empty;
public double MaxLocalCacheInGiB { get; set; } = 20;
public bool ReverseUserSort { get; set; } = false;
public int TimeSpanBetweenScansInSeconds { get; set; } = 30;
public bool FileScanPaused { get; set; } = false;
public bool InitialScanComplete { get; set; } = false;
public bool FullPause { get; set; } = false;
public bool HideInfoMessages { get; set; } = false;
public bool DisableOptionalPluginWarnings { get; set; } = false;
public bool OpenGposeImportOnGposeStart { get; set; } = false;
public bool ShowTransferWindow { get; set; } = true;
public bool OpenPopupOnAdd { get; set; } = true;
public string CurrentServer { get; set; } = string.Empty;
private string _apiUri = string.Empty;
public string ApiUri
{
get => string.IsNullOrEmpty(_apiUri) ? ApiController.MainServiceUri : _apiUri;
set => _apiUri = value;
}
public Dictionary<string, string> ClientSecret { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, string> CustomServerList { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, Dictionary<string, string>> UidServerComments { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, Dictionary<string, string>> GidServerComments { get; set; } = new(StringComparer.Ordinal);
/// <summary>
/// Each paired user can have multiple tags. Each tag will create a category, and the user will
/// be displayed into that category.
/// The dictionary first maps a server URL to a dictionary, and that
/// dictionary maps the OtherUID of the <see cref="ClientPairDto"/> to a list of tags.
/// </summary>
public Dictionary<string, Dictionary<string, List<string>>> UidServerPairedUserTags = new(StringComparer.Ordinal);
/// <summary>
/// A dictionary that maps a server URL to the tags the user has added for that server.
/// </summary>
public Dictionary<string, HashSet<string>> ServerAvailablePairTags = new(StringComparer.Ordinal);
public HashSet<string> OpenPairTags = new(StringComparer.Ordinal);
// the below exist just to make saving less cumbersome
public void Initialize(DalamudPluginInterface pluginInterface)
{
_pluginInterface = pluginInterface;
if (!Directory.Exists(CacheFolder))
{
InitialScanComplete = false;
}
Save();
}
public void Save()
{
_pluginInterface!.SavePluginConfig(this);
}
public MareConfig ToMareConfig()
{
MareConfig newConfig = new();
Logger.Info("Migrating Config to MareConfig");
newConfig.AcceptedAgreement = AcceptedAgreement;
newConfig.CacheFolder = CacheFolder;
newConfig.MaxLocalCacheInGiB = MaxLocalCacheInGiB;
newConfig.ReverseUserSort = ReverseUserSort;
newConfig.TimeSpanBetweenScansInSeconds = TimeSpanBetweenScansInSeconds;
newConfig.FileScanPaused = FileScanPaused;
newConfig.InitialScanComplete = InitialScanComplete;
newConfig.HideInfoMessages = HideInfoMessages;
newConfig.DisableOptionalPluginWarnings = DisableOptionalPluginWarnings;
newConfig.OpenGposeImportOnGposeStart = OpenGposeImportOnGposeStart;
newConfig.ShowTransferWindow = ShowTransferWindow;
newConfig.OpenPopupOnAdd = OpenPopupOnAdd;
newConfig.CurrentServer = ApiUri;
// create all server storage based on current clientsecret
foreach (var secret in ClientSecret)
{
Logger.Debug("Migrating " + secret.Key);
var apiuri = secret.Key;
var secretkey = secret.Value;
ServerStorage toAdd = new();
if (string.Equals(apiuri, ApiController.MainServiceUri, StringComparison.OrdinalIgnoreCase))
{
toAdd.ServerUri = ApiController.MainServiceUri;
toAdd.ServerName = ApiController.MainServer;
}
else
{
toAdd.ServerUri = apiuri;
if (!CustomServerList.TryGetValue(apiuri, out var serverName)) serverName = apiuri;
toAdd.ServerName = serverName;
}
toAdd.SecretKeys[0] = new SecretKey()
{
FriendlyName = "Auto Migrated Secret Key (" + DateTime.Now.ToString("yyyy-MM-dd") + ")",
Key = secretkey,
};
if (GidServerComments.TryGetValue(apiuri, out var gids))
{
toAdd.GidServerComments = gids;
}
if (UidServerComments.TryGetValue(apiuri, out var uids))
{
toAdd.UidServerComments = uids;
}
if (UidServerPairedUserTags.TryGetValue(apiuri, out var uidtag))
{
toAdd.UidServerPairedUserTags = uidtag;
}
if (ServerAvailablePairTags.TryGetValue(apiuri, out var servertag))
{
toAdd.ServerAvailablePairTags = servertag;
}
toAdd.OpenPairTags = OpenPairTags;
toAdd.FullPause = FullPause;
newConfig.ServerStorage[apiuri] = toAdd;
}
return newConfig;
}
public void Migrate()
{
}
}

View File

@@ -0,0 +1,11 @@
namespace MareSynchronos.MareConfiguration;
public static class ConfigurationExtensions
{
public static bool HasValidSetup(this MareConfig configuration)
{
return configuration.AcceptedAgreement && configuration.InitialScanComplete
&& !string.IsNullOrEmpty(configuration.CacheFolder)
&& Directory.Exists(configuration.CacheFolder);
}
}

View File

@@ -0,0 +1,81 @@
using Dalamud.Plugin;
using MareSynchronos.Utils;
using Newtonsoft.Json;
namespace MareSynchronos.MareConfiguration;
public class ConfigurationService : IDisposable
{
private const string _configurationName = "Config.json";
private string ConfigurationPath => Path.Combine(_pluginInterface.ConfigDirectory.FullName, _configurationName);
public string ConfigurationDirectory => _pluginInterface.ConfigDirectory.FullName;
private readonly DalamudPluginInterface _pluginInterface;
private readonly CancellationTokenSource _periodicCheckCts = new();
private DateTime _configLastWriteTime;
public MareConfig Current { get; private set; }
public ConfigurationService(DalamudPluginInterface pluginInterface)
{
_pluginInterface = pluginInterface;
if (pluginInterface.GetPluginConfig() is Configuration oldConfig)
{
Current = oldConfig.ToMareConfig();
File.Move(pluginInterface.ConfigFile.FullName, pluginInterface.ConfigFile.FullName + ".old", overwrite: true);
}
else
{
Current = LoadConfig();
}
Save();
Task.Run(CheckForConfigUpdatesInternal, _periodicCheckCts.Token);
}
private async Task CheckForConfigUpdatesInternal()
{
while (!_periodicCheckCts.IsCancellationRequested)
{
var lastWriteTime = GetConfigLastWriteTime();
if (lastWriteTime != _configLastWriteTime)
{
Logger.Debug("Config changed, reloading config");
Current = LoadConfig();
}
await Task.Delay(TimeSpan.FromSeconds(5), _periodicCheckCts.Token).ConfigureAwait(false);
}
}
private MareConfig LoadConfig()
{
MareConfig config;
if (!File.Exists(ConfigurationPath))
{
config = new();
}
else
{
config = JsonConvert.DeserializeObject<MareConfig>(File.ReadAllText(ConfigurationPath)) ?? new MareConfig();
}
_configLastWriteTime = GetConfigLastWriteTime();
return config;
}
private DateTime GetConfigLastWriteTime() => new FileInfo(ConfigurationPath).LastWriteTimeUtc;
public void Save()
{
File.WriteAllText(ConfigurationPath, JsonConvert.SerializeObject(Current, Formatting.Indented));
_configLastWriteTime = new FileInfo(ConfigurationPath).LastWriteTimeUtc;
}
public void Dispose()
{
Save();
_periodicCheckCts.Cancel();
}
}

View File

@@ -0,0 +1,30 @@
using Dalamud.Configuration;
using MareSynchronos.WebAPI;
namespace MareSynchronos.MareConfiguration;
[Serializable]
public class MareConfig : IPluginConfiguration
{
public int Version { get; set; } = 0;
public Dictionary<string, ServerStorage> ServerStorage { get; set; } = new(StringComparer.OrdinalIgnoreCase)
{
{ ApiController.MainServiceUri, new ServerStorage() { ServerName = ApiController.MainServer, ServerUri = ApiController.MainServiceUri } },
};
public Dictionary<string, HashSet<string>> PlayerPersistentTransientCache { get; set; } = new(StringComparer.Ordinal);
public bool AcceptedAgreement { get; set; } = false;
public string CacheFolder { get; set; } = string.Empty;
public double MaxLocalCacheInGiB { get; set; } = 20;
public bool ReverseUserSort { get; set; } = false;
public int TimeSpanBetweenScansInSeconds { get; set; } = 30;
public bool FileScanPaused { get; set; } = false;
public bool InitialScanComplete { get; set; } = false;
public bool HideInfoMessages { get; set; } = false;
public bool DisableOptionalPluginWarnings { get; set; } = false;
public bool OpenGposeImportOnGposeStart { get; set; } = false;
public bool ShowTransferWindow { get; set; } = true;
public bool OpenPopupOnAdd { get; set; } = true;
public string CurrentServer { get; set; } = string.Empty;
public bool ShowOnlineNotifications { get; set; } = false;
public bool ShowOnlineNotificationsOnlyForIndividualPairs { get; set; } = true;
}

View File

@@ -0,0 +1,8 @@
namespace MareSynchronos.MareConfiguration;
[Serializable]
public class SecretKey
{
public string Key { get; set; } = string.Empty;
public string FriendlyName { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,16 @@
namespace MareSynchronos.MareConfiguration;
[Serializable]
public class ServerStorage
{
public string ServerUri { get; set; } = string.Empty;
public string ServerName { get; set; } = string.Empty;
public List<Authentication> Authentications { get; set; } = new();
public Dictionary<string, string> UidServerComments { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, string> GidServerComments { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, List<string>> UidServerPairedUserTags = new(StringComparer.Ordinal);
public HashSet<string> ServerAvailablePairTags { get; set; } = new(StringComparer.Ordinal);
public HashSet<string> OpenPairTags { get; set; } = new(StringComparer.Ordinal);
public Dictionary<int, SecretKey> SecretKeys { get; set; } = new();
public bool FullPause { get; set; } = false;
}