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:
@@ -1,10 +1,8 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronos.Utils;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using MareSynchronos.API.Data.Enum;
|
||||
using MareSynchronos.API.Data;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
@@ -34,10 +32,10 @@ public class CharacterData
|
||||
|
||||
if (!FileReplacements.ContainsKey(objectKind)) FileReplacements.Add(objectKind, new List<FileReplacement>());
|
||||
|
||||
var existingReplacement = FileReplacements[objectKind].SingleOrDefault(f => string.Equals(f.ResolvedPath, fileReplacement.ResolvedPath, System.StringComparison.OrdinalIgnoreCase));
|
||||
var existingReplacement = FileReplacements[objectKind].SingleOrDefault(f => string.Equals(f.ResolvedPath, fileReplacement.ResolvedPath, StringComparison.OrdinalIgnoreCase));
|
||||
if (existingReplacement != null)
|
||||
{
|
||||
existingReplacement.GamePaths.AddRange(fileReplacement.GamePaths.Where(e => !existingReplacement.GamePaths.Contains(e, System.StringComparer.OrdinalIgnoreCase)));
|
||||
existingReplacement.GamePaths.AddRange(fileReplacement.GamePaths.Where(e => !existingReplacement.GamePaths.Contains(e, StringComparer.OrdinalIgnoreCase)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,13 +43,13 @@ public class CharacterData
|
||||
}
|
||||
}
|
||||
|
||||
public CharacterCacheDto ToCharacterCacheDto()
|
||||
public API.Data.CharacterData ToAPI()
|
||||
{
|
||||
var fileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap).GroupBy(f => f.Hash, System.StringComparer.OrdinalIgnoreCase).Select(g =>
|
||||
var fileReplacements = FileReplacements.ToDictionary(k => k.Key, k => k.Value.Where(f => f.HasFileReplacement && !f.IsFileSwap).GroupBy(f => f.Hash, StringComparer.OrdinalIgnoreCase).Select(g =>
|
||||
{
|
||||
return new FileReplacementDto()
|
||||
return new FileReplacementData()
|
||||
{
|
||||
GamePaths = g.SelectMany(f => f.GamePaths).Distinct(System.StringComparer.OrdinalIgnoreCase).ToArray(),
|
||||
GamePaths = g.SelectMany(f => f.GamePaths).Distinct(StringComparer.OrdinalIgnoreCase).ToArray(),
|
||||
Hash = g.First().Hash,
|
||||
};
|
||||
}).ToList());
|
||||
@@ -69,20 +67,20 @@ public class CharacterData
|
||||
fileReplacements[item.Key].AddRange(fileSwapsToAdd);
|
||||
}
|
||||
|
||||
return new CharacterCacheDto()
|
||||
return new API.Data.CharacterData()
|
||||
{
|
||||
FileReplacements = fileReplacements,
|
||||
GlamourerData = GlamourerString.ToDictionary(d => d.Key, d => d.Value),
|
||||
ManipulationData = ManipulationString,
|
||||
HeelsOffset = HeelsOffset,
|
||||
CustomizePlusData = CustomizePlusScale
|
||||
CustomizePlusData = CustomizePlusScale,
|
||||
};
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder stringBuilder = new();
|
||||
foreach (var fileReplacement in FileReplacements.SelectMany(k => k.Value).OrderBy(a => a.GamePaths[0]))
|
||||
foreach (var fileReplacement in FileReplacements.SelectMany(k => k.Value).OrderBy(a => a.GamePaths[0], StringComparer.Ordinal))
|
||||
{
|
||||
stringBuilder.AppendLine(fileReplacement.ToString());
|
||||
}
|
||||
|
||||
@@ -1,34 +1,30 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using MareSynchronos.FileCache;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.Utils;
|
||||
using System;
|
||||
using MareSynchronos.API.Data;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public class FileReplacement
|
||||
{
|
||||
private readonly FileCacheManager fileDbManager;
|
||||
private readonly IpcManager ipcManager;
|
||||
private readonly FileCacheManager _fileDbManager;
|
||||
private readonly IpcManager _ipcManager;
|
||||
|
||||
public FileReplacement(FileCacheManager fileDbManager, IpcManager ipcManager)
|
||||
{
|
||||
this.fileDbManager = fileDbManager;
|
||||
this.ipcManager = ipcManager;
|
||||
_fileDbManager = fileDbManager;
|
||||
_ipcManager = ipcManager;
|
||||
}
|
||||
|
||||
public bool Computed => IsFileSwap || !HasFileReplacement || !string.IsNullOrEmpty(Hash);
|
||||
|
||||
public List<string> GamePaths { get; set; } = new();
|
||||
|
||||
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => !string.Equals(p, ResolvedPath, System.StringComparison.Ordinal));
|
||||
public bool HasFileReplacement => GamePaths.Count >= 1 && GamePaths.Any(p => !string.Equals(p, ResolvedPath, StringComparison.Ordinal));
|
||||
|
||||
public bool IsFileSwap => !Regex.IsMatch(ResolvedPath, @"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript) && !string.Equals(GamePaths.First(), ResolvedPath, System.StringComparison.Ordinal);
|
||||
public bool IsFileSwap => !Regex.IsMatch(ResolvedPath, @"^[a-zA-Z]:(/|\\)", RegexOptions.ECMAScript) && !string.Equals(GamePaths[0], ResolvedPath, StringComparison.Ordinal);
|
||||
|
||||
public string Hash { get; private set; } = string.Empty;
|
||||
|
||||
@@ -43,13 +39,13 @@ public class FileReplacement
|
||||
{
|
||||
try
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath)!;
|
||||
var cache = _fileDbManager.GetFileCacheByPath(ResolvedPath)!;
|
||||
Hash = cache.Hash;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warn("Could not set Hash for " + ResolvedPath + ", resetting to original");
|
||||
ResolvedPath = GamePaths.First();
|
||||
Logger.Warn("Could not set Hash for " + ResolvedPath + ", resetting to original", ex);
|
||||
ResolvedPath = GamePaths[0];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -58,34 +54,34 @@ public class FileReplacement
|
||||
{
|
||||
if (!IsFileSwap)
|
||||
{
|
||||
var cache = fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
var cache = _fileDbManager.GetFileCacheByPath(ResolvedPath);
|
||||
if (cache == null)
|
||||
{
|
||||
Logger.Warn("Replacement Failed verification: " + GamePaths.First());
|
||||
Logger.Warn("Replacement Failed verification: " + GamePaths[0]);
|
||||
return false;
|
||||
}
|
||||
Hash = cache.Hash;
|
||||
return true;
|
||||
}
|
||||
|
||||
ResolvePath(GamePaths.First());
|
||||
ResolvePath(GamePaths[0]);
|
||||
|
||||
var success = IsFileSwap;
|
||||
if (!success)
|
||||
{
|
||||
Logger.Warn("FileSwap Failed verification: " + GamePaths.First());
|
||||
Logger.Warn("FileSwap Failed verification: " + GamePaths[0]);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public FileReplacementDto ToFileReplacementDto()
|
||||
public FileReplacementData ToFileReplacementDto()
|
||||
{
|
||||
return new FileReplacementDto
|
||||
return new FileReplacementData
|
||||
{
|
||||
GamePaths = GamePaths.ToArray(),
|
||||
Hash = Hash,
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty
|
||||
FileSwapPath = IsFileSwap ? ResolvedPath : string.Empty,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,13 +94,13 @@ public class FileReplacement
|
||||
|
||||
internal void ReverseResolvePath(string path)
|
||||
{
|
||||
GamePaths = ipcManager.PenumbraReverseResolvePlayer(path).ToList();
|
||||
GamePaths = _ipcManager.PenumbraReverseResolvePlayer(path).ToList();
|
||||
SetResolvedPath(path);
|
||||
}
|
||||
|
||||
internal void ResolvePath(string path)
|
||||
{
|
||||
GamePaths = new List<string> { path };
|
||||
SetResolvedPath(ipcManager.PenumbraResolvePath(path));
|
||||
SetResolvedPath(_ipcManager.PenumbraResolvePath(path));
|
||||
}
|
||||
}
|
||||
|
||||
3
MareSynchronos/Models/JwtCache.cs
Normal file
3
MareSynchronos/Models/JwtCache.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public record JwtCache(string ApiUrl, string PlayerName, uint WorldId, string SecretKey);
|
||||
135
MareSynchronos/Models/Pair.cs
Normal file
135
MareSynchronos/Models/Pair.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using Dalamud.Utility;
|
||||
using MareSynchronos.API.Data;
|
||||
using MareSynchronos.API.Data.Comparer;
|
||||
using MareSynchronos.API.Data.Extensions;
|
||||
using MareSynchronos.API.Dto.Group;
|
||||
using MareSynchronos.API.Dto.User;
|
||||
using MareSynchronos.Managers;
|
||||
using MareSynchronos.MareConfiguration;
|
||||
using MareSynchronos.Utils;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
public class Pair
|
||||
{
|
||||
private readonly ConfigurationService _configService;
|
||||
private readonly ServerConfigurationManager _serverConfigurationManager;
|
||||
private OptionalPluginWarning? _pluginWarnings;
|
||||
|
||||
public Pair(ConfigurationService configService, ServerConfigurationManager serverConfigurationManager)
|
||||
{
|
||||
_configService = configService;
|
||||
_serverConfigurationManager = serverConfigurationManager;
|
||||
}
|
||||
|
||||
public UserPairDto? UserPair { get; set; }
|
||||
public CachedPlayer? CachedPlayer { get; set; }
|
||||
public API.Data.CharacterData? LastReceivedCharacterData { get; set; }
|
||||
public Dictionary<GroupFullInfoDto, GroupPairFullInfoDto> GroupPair { get; set; } = new(GroupDtoComparer.Instance);
|
||||
public string PlayerNameHash => CachedPlayer?.PlayerNameHash ?? string.Empty;
|
||||
public string? PlayerName => CachedPlayer?.PlayerName ?? string.Empty;
|
||||
public UserData UserData => UserPair?.User ?? GroupPair.First().Value.User;
|
||||
public bool IsOnline => CachedPlayer != null;
|
||||
public bool IsVisible => CachedPlayer != null && CachedPlayer.IsVisible;
|
||||
public bool IsPaused => UserPair != null && UserPair.OtherPermissions.IsPaired() ? (UserPair.OtherPermissions.IsPaused() || UserPair.OwnPermissions.IsPaused())
|
||||
: GroupPair.All(p => p.Key.GroupUserPermissions.IsPaused() || p.Value.GroupUserPermissions.IsPaused());
|
||||
|
||||
public string? GetNote()
|
||||
{
|
||||
if (_serverConfigurationManager.CurrentServer!.UidServerComments.TryGetValue(UserData.UID, out string? note))
|
||||
{
|
||||
return string.IsNullOrEmpty(note) ? null : note;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void SetNote(string note)
|
||||
{
|
||||
_serverConfigurationManager.CurrentServer!.UidServerComments[UserData.UID] = note;
|
||||
_serverConfigurationManager.Save();
|
||||
}
|
||||
|
||||
public bool HasAnyConnection()
|
||||
{
|
||||
return UserPair != null || GroupPair.Any();
|
||||
}
|
||||
|
||||
public void InitializePair(nint address, string name)
|
||||
{
|
||||
if (!PlayerName.IsNullOrEmpty()) return;
|
||||
|
||||
if (CachedPlayer == null) throw new InvalidOperationException("CachedPlayer not initialized");
|
||||
_pluginWarnings ??= new()
|
||||
{
|
||||
ShownCustomizePlusWarning = _configService.Current.DisableOptionalPluginWarnings,
|
||||
ShownHeelsWarning = _configService.Current.DisableOptionalPluginWarnings,
|
||||
};
|
||||
|
||||
CachedPlayer.Initialize(address, name);
|
||||
|
||||
ApplyLastReceivedData();
|
||||
}
|
||||
|
||||
public void ApplyData(OnlineUserCharaDataDto data)
|
||||
{
|
||||
if (CachedPlayer == null) throw new InvalidOperationException("CachedPlayer not initialized");
|
||||
|
||||
if (string.Equals(LastReceivedCharacterData?.DataHash.Value, data.CharaData.DataHash.Value, StringComparison.Ordinal)) return;
|
||||
|
||||
LastReceivedCharacterData = data.CharaData;
|
||||
|
||||
ApplyLastReceivedData();
|
||||
}
|
||||
|
||||
public void ApplyLastReceivedData()
|
||||
{
|
||||
if (CachedPlayer == null) return;
|
||||
if (LastReceivedCharacterData == null) return;
|
||||
|
||||
_pluginWarnings ??= new()
|
||||
{
|
||||
ShownCustomizePlusWarning = _configService.Current.DisableOptionalPluginWarnings,
|
||||
ShownHeelsWarning = _configService.Current.DisableOptionalPluginWarnings,
|
||||
};
|
||||
|
||||
CachedPlayer.ApplyCharacterData(RemoveNotSyncedFiles(LastReceivedCharacterData.DeepClone())!, _pluginWarnings);
|
||||
}
|
||||
|
||||
private API.Data.CharacterData? RemoveNotSyncedFiles(API.Data.CharacterData? data)
|
||||
{
|
||||
Logger.Verbose("Removing not synced files");
|
||||
if (data == null || (UserPair != null && UserPair.OtherPermissions.IsPaired()))
|
||||
{
|
||||
Logger.Verbose("Nothing to remove or user is paired directly");
|
||||
return data;
|
||||
}
|
||||
|
||||
bool disableAnimations = GroupPair.All(pair =>
|
||||
{
|
||||
return pair.Value.GroupUserPermissions.IsDisableAnimations() || pair.Key.GroupPermissions.IsDisableAnimations() || pair.Key.GroupUserPermissions.IsDisableAnimations();
|
||||
});
|
||||
bool disableSounds = GroupPair.All(pair =>
|
||||
{
|
||||
return pair.Value.GroupUserPermissions.IsDisableSounds() || pair.Key.GroupPermissions.IsDisableSounds() || pair.Key.GroupUserPermissions.IsDisableSounds();
|
||||
});
|
||||
|
||||
if (disableAnimations || disableSounds)
|
||||
{
|
||||
Logger.Verbose($"Data cleaned up: Animations disabled: {disableAnimations}, Sounds disabled: {disableSounds}");
|
||||
foreach (var kvp in data.FileReplacements)
|
||||
{
|
||||
if (disableSounds)
|
||||
data.FileReplacements[kvp.Key] = data.FileReplacements[kvp.Key]
|
||||
.Where(f => !f.GamePaths.Any(p => p.EndsWith("scd", StringComparison.OrdinalIgnoreCase)))
|
||||
.ToList();
|
||||
if (disableAnimations)
|
||||
data.FileReplacements[kvp.Key] = data.FileReplacements[kvp.Key]
|
||||
.Where(f => !f.GamePaths.Any(p => p.EndsWith("tmb", StringComparison.OrdinalIgnoreCase) || p.EndsWith("pap", StringComparison.OrdinalIgnoreCase)))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using MareSynchronos.API;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using FFXIVClientStructs.FFXIV.Client.Game.Character;
|
||||
using System.Runtime.InteropServices;
|
||||
using MareSynchronos.Utils;
|
||||
using Penumbra.String;
|
||||
using MareSynchronos.API.Data.Enum;
|
||||
|
||||
namespace MareSynchronos.Models;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user