diff --git a/Pal.Client/Configuration/AccountConfigurationV7.cs b/Pal.Client/Configuration/AccountConfigurationV7.cs index 093fcce..b0b462b 100644 --- a/Pal.Client/Configuration/AccountConfigurationV7.cs +++ b/Pal.Client/Configuration/AccountConfigurationV7.cs @@ -10,9 +10,6 @@ public sealed class AccountConfigurationV7 : IAccountConfiguration { private const int DefaultEntropyLength = 16; - private static readonly ILogger _logger = - DependencyInjectionContext.LoggerProvider.CreateLogger(); - [JsonConstructor] public AccountConfigurationV7() { @@ -75,9 +72,8 @@ public sealed class AccountConfigurationV7 : IAccountConfiguration byte[] guidBytes = ProtectedData.Unprotect(Convert.FromBase64String(EncryptedId), Entropy, DataProtectionScope.CurrentUser); return new Guid(guidBytes); } - catch (Exception e) + catch (Exception) { - _logger.LogTrace(e, "Could not load account id {Id}", EncryptedId); return null; } } diff --git a/Pal.Client/Configuration/ConfigurationData.cs b/Pal.Client/Configuration/ConfigurationData.cs index c4a7c7c..70b9367 100644 --- a/Pal.Client/Configuration/ConfigurationData.cs +++ b/Pal.Client/Configuration/ConfigurationData.cs @@ -7,15 +7,13 @@ namespace Pal.Client.Configuration; internal static class ConfigurationData { - private static readonly ILogger _logger = - DependencyInjectionContext.LoggerProvider.CreateLogger(typeof(ConfigurationData)); - [Obsolete("for V1 import")] internal static readonly byte[] FixedV1Entropy = { 0x22, 0x4b, 0xe7, 0x21, 0x44, 0x83, 0x69, 0x55, 0x80, 0x38 }; public const string ConfigFileName = "palace-pal.config.json"; private static bool? _supportsDpapi; + public static bool SupportsDpapi { get @@ -34,9 +32,8 @@ internal static class ConfigurationData { _supportsDpapi = false; } - - _logger.LogTrace("DPAPI support: {Supported}", _supportsDpapi); } + return _supportsDpapi.Value; } } diff --git a/Pal.Client/DependencyInjectionContext.cs b/Pal.Client/DependencyInjectionContext.cs index 19eaa5e..bd86fe8 100644 --- a/Pal.Client/DependencyInjectionContext.cs +++ b/Pal.Client/DependencyInjectionContext.cs @@ -34,7 +34,6 @@ namespace Pal.Client; internal sealed class DependencyInjectionContext : IDisposable { public const string DatabaseFileName = "palace-pal.data.sqlite3"; - public static DalamudLoggerProvider LoggerProvider { get; private set; } = null!; /// /// Initialized as temporary logger, will be overriden once context is ready with a logger that supports scopes. @@ -59,8 +58,8 @@ internal sealed class DependencyInjectionContext : IDisposable IPluginLog pluginLog, Plugin plugin) { - LoggerProvider = new DalamudLoggerProvider(pluginLog); - _logger = LoggerProvider.CreateLogger(); + var loggerProvider = new DalamudLoggerProvider(pluginLog); + _logger = loggerProvider.CreateLogger(); _logger.LogInformation("Building dalamud service container for {Assembly}", typeof(DependencyInjectionContext).Assembly.FullName); diff --git a/Pal.Client/Floors/FrameworkService.cs b/Pal.Client/Floors/FrameworkService.cs index fe63269..1d6b32b 100644 --- a/Pal.Client/Floors/FrameworkService.cs +++ b/Pal.Client/Floors/FrameworkService.cs @@ -447,7 +447,6 @@ internal sealed class FrameworkService : IDisposable Position = obj.Position, Seen = true, Source = ClientLocation.ESource.ExplodedLocally, - }); } } diff --git a/Pal.Client/Floors/ObjectTableDebug.cs b/Pal.Client/Floors/ObjectTableDebug.cs index 912065f..e40fb02 100644 --- a/Pal.Client/Floors/ObjectTableDebug.cs +++ b/Pal.Client/Floors/ObjectTableDebug.cs @@ -23,7 +23,8 @@ internal sealed class ObjectTableDebug : IDisposable private readonly IGameGui _gameGui; private readonly IClientState _clientState; - public ObjectTableDebug(DalamudPluginInterface pluginInterface, IObjectTable objectTable, IGameGui gameGui, IClientState clientState) + public ObjectTableDebug(DalamudPluginInterface pluginInterface, IObjectTable objectTable, IGameGui gameGui, + IClientState clientState) { _pluginInterface = pluginInterface; _objectTable = objectTable; diff --git a/Pal.Client/Floors/Tasks/DbTask.cs b/Pal.Client/Floors/Tasks/DbTask.cs index c7a1747..e899d34 100644 --- a/Pal.Client/Floors/Tasks/DbTask.cs +++ b/Pal.Client/Floors/Tasks/DbTask.cs @@ -24,14 +24,20 @@ internal abstract class DbTask { using var scope = _serviceScopeFactory.CreateScope(); ILogger logger = scope.ServiceProvider.GetRequiredService>(); - using var dbContext = scope.ServiceProvider.GetRequiredService(); + try + { + using var dbContext = scope.ServiceProvider.GetRequiredService(); - Run(dbContext, logger); + Run(dbContext, logger); + } + catch (Exception e) + { + logger.LogError(e, "Failed to run DbTask"); + } } - catch (Exception e) + catch (Exception) { - DependencyInjectionContext.LoggerProvider.CreateLogger>() - .LogError(e, "Failed to run DbTask"); + // nothing we can do here but catch it, if we don't we crash the game } }); } diff --git a/Pal.Client/Floors/Tasks/MarkLocalSeen.cs b/Pal.Client/Floors/Tasks/MarkLocalSeen.cs index 79cb36c..635baa4 100644 --- a/Pal.Client/Floors/Tasks/MarkLocalSeen.cs +++ b/Pal.Client/Floors/Tasks/MarkLocalSeen.cs @@ -24,7 +24,8 @@ internal sealed class MarkLocalSeen : DbTask { lock (_territory.LockObj) { - logger.LogInformation("Marking {Count} locations as seen locally in territory {Territory}", _locations.Count, + logger.LogInformation("Marking {Count} locations as seen locally in territory {Territory}", + _locations.Count, _territory.TerritoryType); List localIds = _locations.Select(l => l.LocalId).Where(x => x != null).Cast().ToList(); dbContext.Locations diff --git a/Pal.Client/Floors/TerritoryState.cs b/Pal.Client/Floors/TerritoryState.cs index e3f5b25..40291a0 100644 --- a/Pal.Client/Floors/TerritoryState.cs +++ b/Pal.Client/Floors/TerritoryState.cs @@ -23,7 +23,6 @@ public sealed class TerritoryState _clientState.IsLoggedIn && _condition[ConditionFlag.InDeepDungeon] && typeof(ETerritoryType).IsEnumDefined(_clientState.TerritoryType); - } public enum PomanderState diff --git a/Pal.Client/Net/JwtClaims.cs b/Pal.Client/Net/JwtClaims.cs index 3927c77..76b0c04 100644 --- a/Pal.Client/Net/JwtClaims.cs +++ b/Pal.Client/Net/JwtClaims.cs @@ -40,7 +40,8 @@ internal sealed class JwtClaims payload += "="; string content = Encoding.UTF8.GetString(Convert.FromBase64String(payload)); - return JsonSerializer.Deserialize(content) ?? throw new InvalidOperationException("token deserialization returned null"); + return JsonSerializer.Deserialize(content) ?? + throw new InvalidOperationException("token deserialization returned null"); } } @@ -73,5 +74,6 @@ internal sealed class JwtRoleConverter : JsonConverter> throw new JsonException("bad token type"); } - public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) => throw new NotImplementedException(); + public override void Write(Utf8JsonWriter writer, List value, JsonSerializerOptions options) => + throw new NotImplementedException(); } diff --git a/Pal.Client/Net/JwtDateConverter.cs b/Pal.Client/Net/JwtDateConverter.cs index 11a7508..3975ca2 100644 --- a/Pal.Client/Net/JwtDateConverter.cs +++ b/Pal.Client/Net/JwtDateConverter.cs @@ -16,5 +16,6 @@ public sealed class JwtDateConverter : JsonConverter return Zero.AddSeconds(reader.GetInt64()); } - public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) => throw new NotImplementedException(); + public override void Write(Utf8JsonWriter writer, DateTimeOffset value, JsonSerializerOptions options) => + throw new NotImplementedException(); } diff --git a/Pal.Client/Net/RemoteApi.AccountService.cs b/Pal.Client/Net/RemoteApi.AccountService.cs index cc25d89..2d848c2 100644 --- a/Pal.Client/Net/RemoteApi.AccountService.cs +++ b/Pal.Client/Net/RemoteApi.AccountService.cs @@ -11,11 +11,13 @@ using Microsoft.Extensions.Logging; using Pal.Client.Configuration; using Pal.Client.Extensions; using Pal.Client.Properties; +using Version = System.Version; namespace Pal.Client.Net; internal partial class RemoteApi { + private static readonly Version PluginVersion = typeof(Plugin).Assembly.GetName().Version!; private readonly SemaphoreSlim _connectLock = new(1, 1); private async Task<(bool Success, string Error)> TryConnect(CancellationToken cancellationToken, @@ -73,7 +75,14 @@ internal partial class RemoteApi if (configuredAccount == null) { _logger.LogInformation("No account information saved for {Url}, creating new account", RemoteUrl); - var createAccountReply = await accountClient.CreateAccountAsync(new CreateAccountRequest(), + var createAccountReply = await accountClient.CreateAccountAsync(new CreateAccountRequest + { + Version = new() + { + Major = PluginVersion.Major, + Minor = PluginVersion.Minor, + }, + }, headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken); if (createAccountReply.Success) @@ -115,7 +124,15 @@ internal partial class RemoteApi _logger.LogInformation("Logging in with account id {AccountId}", configuredAccount.AccountId.ToPartialId()); LoginReply loginReply = await accountClient.LoginAsync( - new LoginRequest { AccountId = configuredAccount.AccountId.ToString() }, + new LoginRequest + { + AccountId = configuredAccount.AccountId.ToString(), + Version = new() + { + Major = PluginVersion.Major, + Minor = PluginVersion.Minor, + }, + }, headers: UnauthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken); diff --git a/Pal.Client/Net/RemoteApi.ExportService.cs b/Pal.Client/Net/RemoteApi.ExportService.cs index 7489f82..0a0cea8 100644 --- a/Pal.Client/Net/RemoteApi.ExportService.cs +++ b/Pal.Client/Net/RemoteApi.ExportService.cs @@ -14,9 +14,10 @@ internal partial class RemoteApi var exportClient = new ExportService.ExportServiceClient(_channel); var exportReply = await exportClient.ExportAsync(new ExportRequest - { - ServerUrl = RemoteUrl, - }, headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(120), cancellationToken: cancellationToken); + { + ServerUrl = RemoteUrl, + }, headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(120), + cancellationToken: cancellationToken); return (exportReply.Success, exportReply.Data); } } diff --git a/Pal.Client/Net/RemoteApi.PalaceService.cs b/Pal.Client/Net/RemoteApi.PalaceService.cs index b1f34c8..bcffc82 100644 --- a/Pal.Client/Net/RemoteApi.PalaceService.cs +++ b/Pal.Client/Net/RemoteApi.PalaceService.cs @@ -12,17 +12,21 @@ namespace Pal.Client.Net; internal partial class RemoteApi { - public async Task<(bool, List)> DownloadRemoteMarkers(ushort territoryId, CancellationToken cancellationToken = default) + public async Task<(bool, List)> DownloadRemoteMarkers(ushort territoryId, + CancellationToken cancellationToken = default) { if (!await Connect(cancellationToken)) return (false, new()); var palaceClient = new PalaceService.PalaceServiceClient(_channel); - var downloadReply = await palaceClient.DownloadFloorsAsync(new DownloadFloorsRequest { TerritoryType = territoryId }, headers: AuthorizedHeaders(), cancellationToken: cancellationToken); + var downloadReply = await palaceClient.DownloadFloorsAsync( + new DownloadFloorsRequest { TerritoryType = territoryId }, headers: AuthorizedHeaders(), + cancellationToken: cancellationToken); return (downloadReply.Success, downloadReply.Objects.Select(CreateLocationFromNetworkObject).ToList()); } - public async Task<(bool, List)> UploadLocations(ushort territoryType, IReadOnlyList locations, CancellationToken cancellationToken = default) + public async Task<(bool, List)> UploadLocations(ushort territoryType, + IReadOnlyList locations, CancellationToken cancellationToken = default) { if (locations.Count == 0) return (true, new()); @@ -42,11 +46,13 @@ internal partial class RemoteApi Y = m.Position.Y, Z = m.Position.Z })); - var uploadReply = await palaceClient.UploadFloorsAsync(uploadRequest, headers: AuthorizedHeaders(), cancellationToken: cancellationToken); + var uploadReply = await palaceClient.UploadFloorsAsync(uploadRequest, headers: AuthorizedHeaders(), + cancellationToken: cancellationToken); return (uploadReply.Success, uploadReply.Objects.Select(CreateLocationFromNetworkObject).ToList()); } - public async Task MarkAsSeen(ushort territoryType, IReadOnlyList locations, CancellationToken cancellationToken = default) + public async Task MarkAsSeen(ushort territoryType, IReadOnlyList locations, + CancellationToken cancellationToken = default) { if (locations.Count == 0) return true; @@ -59,7 +65,8 @@ internal partial class RemoteApi foreach (var marker in locations) seenRequest.NetworkIds.Add(marker.NetworkId.ToString()); - var seenReply = await palaceClient.MarkObjectsSeenAsync(seenRequest, headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken); + var seenReply = await palaceClient.MarkObjectsSeenAsync(seenRequest, headers: AuthorizedHeaders(), + deadline: DateTime.UtcNow.AddSeconds(10), cancellationToken: cancellationToken); return seenReply.Success; } @@ -80,7 +87,9 @@ internal partial class RemoteApi return new(false, new List()); var palaceClient = new PalaceService.PalaceServiceClient(_channel); - var statisticsReply = await palaceClient.FetchStatisticsAsync(new StatisticsRequest(), headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(30), cancellationToken: cancellationToken); + var statisticsReply = await palaceClient.FetchStatisticsAsync(new StatisticsRequest(), + headers: AuthorizedHeaders(), deadline: DateTime.UtcNow.AddSeconds(30), + cancellationToken: cancellationToken); return (statisticsReply.Success, statisticsReply.FloorStatistics.ToList()); } } diff --git a/Pal.Client/Pal.Client.csproj b/Pal.Client/Pal.Client.csproj index 6a56c76..7e77637 100644 --- a/Pal.Client/Pal.Client.csproj +++ b/Pal.Client/Pal.Client.csproj @@ -29,18 +29,18 @@ - + - + - - - - + + + + all @@ -48,24 +48,24 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + + - - - + + + @@ -124,10 +124,10 @@ - + - + diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index e8e002f..b69031a 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Dalamud.Extensions.MicrosoftLogging; using Dalamud.Game.Command; using Dalamud.Interface.Windowing; using Dalamud.Plugin; @@ -40,7 +41,7 @@ internal sealed class Plugin : IDalamudPlugin private ELoadState _loadState = ELoadState.Initializing; private DependencyInjectionContext? _dependencyInjectionContext; - private ILogger _logger = DependencyInjectionContext.LoggerProvider.CreateLogger(); + private ILogger _logger; private WindowSystem? _windowSystem; private IServiceScope? _rootScope; private Action? _loginAction; @@ -50,13 +51,15 @@ internal sealed class Plugin : IDalamudPlugin ICommandManager commandManager, IClientState clientState, IChatGui chatGui, - IFramework framework) + IFramework framework, + IPluginLog pluginLog) { _pluginInterface = pluginInterface; _commandManager = commandManager; _clientState = clientState; _chatGui = chatGui; _framework = framework; + _logger = new DalamudLoggerProvider(pluginLog).CreateLogger(); // set up the current UI language before creating anything Localization.Culture = new CultureInfo(_pluginInterface.UiLanguage); @@ -73,8 +76,6 @@ internal sealed class Plugin : IDalamudPlugin Task.Run(async () => await CreateDependencyContext()); } - public string Name => Localization.Palace_Pal; - private async Task CreateDependencyContext() { try diff --git a/Pal.Client/README.md b/Pal.Client/README.md index 71ef729..02a8e5e 100644 --- a/Pal.Client/README.md +++ b/Pal.Client/README.md @@ -15,6 +15,7 @@ dotnet ef migrations add MigrationName --configuration EF ``` To rebuild the compiled model: + ```shell dotnet ef dbcontext optimize --output-dir Database/Compiled --namespace Pal.Client.Database.Compiled --configuration EF ``` diff --git a/Pal.Common/Protos/account.proto b/Pal.Common/Protos/account.proto index f0a7d14..e35db92 100644 --- a/Pal.Common/Protos/account.proto +++ b/Pal.Common/Protos/account.proto @@ -18,6 +18,7 @@ service AccountService { } message CreateAccountRequest { + Version version = 1; } message CreateAccountReply { @@ -35,6 +36,7 @@ enum CreateAccountError { message LoginRequest { string accountId = 1; + Version version = 2; } message LoginReply { @@ -55,4 +57,9 @@ message VerifyRequest { } message VerifyReply { -} \ No newline at end of file +} + +message Version { + int32 major = 1; + int32 minor = 2; +} diff --git a/Pal.Server b/Pal.Server index 4326872..4f629ce 160000 --- a/Pal.Server +++ b/Pal.Server @@ -1 +1 @@ -Subproject commit 43268725eb4fc0ccef31af61a1a917832f83d3fd +Subproject commit 4f629ceb6965a20fad98bd9da8b8ed4f02b7f3ed diff --git a/Pal.Server.Tests b/Pal.Server.Tests index d67d342..9dff2ca 160000 --- a/Pal.Server.Tests +++ b/Pal.Server.Tests @@ -1 +1 @@ -Subproject commit d67d342f395da8447131e389143d9683c0bdfbae +Subproject commit 9dff2ca46b46339565ef144e6b4b365eb516daaf