From 6b0445277412dd5f2b288e599899d342b121ec3d Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Mon, 19 Aug 2024 20:02:12 +0200 Subject: [PATCH] fix some minor issues --- MareSynchronos/Plugin.cs | 16 +++++++++- .../ServerConfigurationManager.cs | 4 +++ MareSynchronos/UI/IntroUI.cs | 31 +++++++++++++++---- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 898e12d..9425470 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -48,7 +48,21 @@ public sealed class Plugin : IDalamudPlugin .Select(f => new FileInfo(f)) .OrderByDescending(f => f.LastWriteTimeUtc).Skip(9)) { - file.Delete(); + int attempts = 0; + bool deleted = false; + while (!deleted && attempts < 5) + { + try + { + file.Delete(); + deleted = true; + } + catch + { + attempts++; + Thread.Sleep(500); + } + } } _host = new HostBuilder() diff --git a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs index 4e82ab6..68c3d80 100644 --- a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -173,6 +173,10 @@ public class ServerConfigurationManager { if (serverSelectionIndex == -1) serverSelectionIndex = CurrentServerIndex; var server = GetServerByIndex(serverSelectionIndex); + if (server.Authentications.Any(c => string.Equals(c.CharacterName, _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), StringComparison.Ordinal) + && c.WorldId == _dalamudUtil.GetHomeWorldIdAsync().GetAwaiter().GetResult())) + return; + server.Authentications.Add(new Authentication() { CharacterName = _dalamudUtil.GetPlayerNameAsync().GetAwaiter().GetResult(), diff --git a/MareSynchronos/UI/IntroUI.cs b/MareSynchronos/UI/IntroUI.cs index 1376f94..d7a9eba 100644 --- a/MareSynchronos/UI/IntroUI.cs +++ b/MareSynchronos/UI/IntroUI.cs @@ -11,10 +11,11 @@ using MareSynchronos.Services.Mediator; using MareSynchronos.Services.ServerConfiguration; using Microsoft.Extensions.Logging; using System.Numerics; +using System.Text.RegularExpressions; namespace MareSynchronos.UI; -public class IntroUi : WindowMediatorSubscriberBase +public partial class IntroUi : WindowMediatorSubscriberBase { private readonly MareConfigService _configService; private readonly CacheMonitor _cacheMonitor; @@ -226,18 +227,33 @@ public class IntroUi : WindowMediatorSubscriberBase { UiSharedService.ColorTextWrapped("Your secret key must be exactly 64 characters long. Don't enter your Lodestone auth here.", ImGuiColors.DalamudRed); } + else if (_secretKey.Length == 64 && !HexRegex().IsMatch(_secretKey)) + { + UiSharedService.ColorTextWrapped("Your secret key can only contain ABCDEF and the numbers 0-9.", ImGuiColors.DalamudRed); + } else if (_secretKey.Length == 64) { ImGui.SameLine(); if (ImGui.Button(buttonText)) { if (_serverConfigurationManager.CurrentServer == null) _serverConfigurationManager.SelectServer(0); - _serverConfigurationManager.CurrentServer!.SecretKeys.Add(_serverConfigurationManager.CurrentServer.SecretKeys.Select(k => k.Key).LastOrDefault() + 1, new SecretKey() + if (!_serverConfigurationManager.CurrentServer!.SecretKeys.Any()) { - FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})", - Key = _secretKey, - }); - _serverConfigurationManager.AddCurrentCharacterToServer(addLastSecretKey: true); + _serverConfigurationManager.CurrentServer!.SecretKeys.Add(_serverConfigurationManager.CurrentServer.SecretKeys.Select(k => k.Key).LastOrDefault() + 1, new SecretKey() + { + FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})", + Key = _secretKey, + }); + _serverConfigurationManager.AddCurrentCharacterToServer(addLastSecretKey: true); + } + else + { + _serverConfigurationManager.CurrentServer!.SecretKeys[0] = new SecretKey() + { + FriendlyName = $"Secret Key added on Setup ({DateTime.Now:yyyy-MM-dd})", + Key = _secretKey, + }; + } _secretKey = string.Empty; _ = Task.Run(() => _uiShared.ApiController.CreateConnections()); } @@ -259,4 +275,7 @@ public class IntroUi : WindowMediatorSubscriberBase _tosParagraphs = [Strings.ToS.Paragraph1, Strings.ToS.Paragraph2, Strings.ToS.Paragraph3, Strings.ToS.Paragraph4, Strings.ToS.Paragraph5, Strings.ToS.Paragraph6]; } + + [GeneratedRegex("^([A-F0-9]{2}\\s+)+")] + private static partial Regex HexRegex(); } \ No newline at end of file