From 810bf78d9c7e5289a1ba1aec93bb0432d59ea2ca Mon Sep 17 00:00:00 2001 From: Loporrit <141286461+loporrit@users.noreply.github.com> Date: Mon, 30 Jun 2025 13:38:45 +0000 Subject: [PATCH] tabs->spaces etc --- .../Models/TextureShrinkMode.cs | 10 ++-- MareSynchronos/MareSynchronos.json | 14 ----- MareSynchronos/Utils/ChatUtils.cs | 42 +++++++------- MareSynchronos/Utils/HashingStream.cs | 2 +- MareSynchronos/Utils/LimitedStream.cs | 56 +++++++++---------- .../WebAPI/Files/FileDownloadManager.cs | 3 +- .../WebAPI/SignalR/HubConnectionConfig.cs | 38 ++++++------- MareSynchronos/WebAPI/SignalR/HubFactory.cs | 1 - .../WebAPI/SignalR/TokenProvider.cs | 10 ++-- 9 files changed, 80 insertions(+), 96 deletions(-) delete mode 100644 MareSynchronos/MareSynchronos.json diff --git a/MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs b/MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs index 0991d91..adbe6d0 100644 --- a/MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs +++ b/MareSynchronos/MareConfiguration/Models/TextureShrinkMode.cs @@ -2,9 +2,9 @@ public enum TextureShrinkMode { - Never, - Default, - DefaultHiRes, - Always, - AlwaysHiRes + Never, + Default, + DefaultHiRes, + Always, + AlwaysHiRes } diff --git a/MareSynchronos/MareSynchronos.json b/MareSynchronos/MareSynchronos.json deleted file mode 100644 index 82addc0..0000000 --- a/MareSynchronos/MareSynchronos.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "Author": "darkarchon", - "Name": "Mare Synchronos", - "Punchline": "Let others see you as you see yourself.", - "Description": "This plugin will synchronize your Penumbra mods and current Glamourer state with other paired clients automatically.", - "InternalName": "mareSynchronos", - "ApplicableVersion": "any", - "Tags": [ - "customization" - ], - "IconUrl": "https://raw.githubusercontent.com/Penumbra-Sync/client/main/MareSynchronos/images/logo.png", - "RepoUrl": "https://github.com/Penumbra-Sync/client", - "CanUnloadAsync": true -} \ No newline at end of file diff --git a/MareSynchronos/Utils/ChatUtils.cs b/MareSynchronos/Utils/ChatUtils.cs index 40a1b8e..b7a63b0 100644 --- a/MareSynchronos/Utils/ChatUtils.cs +++ b/MareSynchronos/Utils/ChatUtils.cs @@ -6,29 +6,29 @@ namespace MareSynchronos.Utils; public static class ChatUtils { - // Based on https://git.anna.lgbt/anna/ExtraChat/src/branch/main/client/ExtraChat/Util/PayloadUtil.cs - // This must store a Guid (16 bytes), as Chat 2 converts the data back to one + // Based on https://git.anna.lgbt/anna/ExtraChat/src/branch/main/client/ExtraChat/Util/PayloadUtil.cs + // This must store a Guid (16 bytes), as Chat 2 converts the data back to one - public static RawPayload CreateExtraChatTagPayload(Guid guid) - { - var header = (byte[])[ - 0x02, // Payload.START_BYTE - 0x27, // SeStringChunkType.Interactable - 2 + 16, // remaining length: ExtraChat sends 19 here but I think its an error - 0x20 // Custom ExtraChat InfoType - ]; + public static RawPayload CreateExtraChatTagPayload(Guid guid) + { + var header = (byte[])[ + 0x02, // Payload.START_BYTE + 0x27, // SeStringChunkType.Interactable + 2 + 16, // remaining length: ExtraChat sends 19 here but I think its an error + 0x20 // Custom ExtraChat InfoType + ]; - var footer = (byte)0x03; // Payload.END_BYTE + var footer = (byte)0x03; // Payload.END_BYTE - return new RawPayload([..header, ..guid.ToByteArray(), footer]); - } + return new RawPayload([..header, ..guid.ToByteArray(), footer]); + } - // We have a unique identifier in the form of a GID, which can be consistently mapped to the same GUID - public static RawPayload CreateExtraChatTagPayload(string gid) - { - var gidBytes = UTF8Encoding.UTF8.GetBytes(gid); - var hashedBytes = MD5.HashData(gidBytes); - var guid = new Guid(hashedBytes); - return CreateExtraChatTagPayload(guid); - } + // We have a unique identifier in the form of a GID, which can be consistently mapped to the same GUID + public static RawPayload CreateExtraChatTagPayload(string gid) + { + var gidBytes = UTF8Encoding.UTF8.GetBytes(gid); + var hashedBytes = MD5.HashData(gidBytes); + var guid = new Guid(hashedBytes); + return CreateExtraChatTagPayload(guid); + } } diff --git a/MareSynchronos/Utils/HashingStream.cs b/MareSynchronos/Utils/HashingStream.cs index 4fdcf5d..7b89740 100644 --- a/MareSynchronos/Utils/HashingStream.cs +++ b/MareSynchronos/Utils/HashingStream.cs @@ -1,6 +1,6 @@ using System.Security.Cryptography; -namespace MareSynchronosStaticFilesServer.Utils; +namespace MareSynchronos.Utils; // Calculates the hash of content read or written to a stream public class HashingStream : Stream diff --git a/MareSynchronos/Utils/LimitedStream.cs b/MareSynchronos/Utils/LimitedStream.cs index 6d62e26..daba37a 100644 --- a/MareSynchronos/Utils/LimitedStream.cs +++ b/MareSynchronos/Utils/LimitedStream.cs @@ -4,8 +4,8 @@ namespace MareSynchronos.Utils; public class LimitedStream : Stream { private readonly Stream _stream; - public long _estimatedPosition = 0; - public long MaxPosition { get; private init; } + public long _estimatedPosition = 0; + public long MaxPosition { get; private init; } public bool DisposeUnderlying = true; public Stream UnderlyingStream { get => _stream; } @@ -13,12 +13,12 @@ public class LimitedStream : Stream public LimitedStream(Stream underlyingStream, long byteLimit) { _stream = underlyingStream; - try - { - _estimatedPosition = Position; - } - catch { } - MaxPosition = _estimatedPosition + byteLimit; + try + { + _estimatedPosition = Position; + } + catch { } + MaxPosition = _estimatedPosition + byteLimit; } protected override void Dispose(bool disposing) @@ -42,33 +42,33 @@ public class LimitedStream : Stream public override int Read(byte[] buffer, int offset, int count) { - int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); + int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); - if (count > remainder) - count = remainder; + if (count > remainder) + count = remainder; int n = _stream.Read(buffer, offset, count); - _estimatedPosition += n; - return n; + _estimatedPosition += n; + return n; } public async override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); + int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); - if (count > remainder) - count = remainder; + if (count > remainder) + count = remainder; int n = await _stream.ReadAsync(buffer, offset, count, cancellationToken); - _estimatedPosition += n; - return n; + _estimatedPosition += n; + return n; } public override long Seek(long offset, SeekOrigin origin) { long result = _stream.Seek(offset, origin); - _estimatedPosition = result; - return result; + _estimatedPosition = result; + return result; } public override void SetLength(long value) @@ -78,23 +78,23 @@ public class LimitedStream : Stream public override void Write(byte[] buffer, int offset, int count) { - int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); + int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); - if (count > remainder) - count = remainder; + if (count > remainder) + count = remainder; _stream.Write(buffer, offset, count); - _estimatedPosition += count; + _estimatedPosition += count; } public async override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) { - int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); + int remainder = (int)long.Clamp(MaxPosition - _estimatedPosition, 0, int.MaxValue); - if (count > remainder) - count = remainder; + if (count > remainder) + count = remainder; await _stream.WriteAsync(buffer, offset, count, cancellationToken); - _estimatedPosition += count; + _estimatedPosition += count; } } diff --git a/MareSynchronos/WebAPI/Files/FileDownloadManager.cs b/MareSynchronos/WebAPI/Files/FileDownloadManager.cs index 7368001..757c79b 100644 --- a/MareSynchronos/WebAPI/Files/FileDownloadManager.cs +++ b/MareSynchronos/WebAPI/Files/FileDownloadManager.cs @@ -8,7 +8,6 @@ using MareSynchronos.PlayerData.Handlers; using MareSynchronos.Services.Mediator; using MareSynchronos.Utils; using MareSynchronos.WebAPI.Files.Models; -using MareSynchronosStaticFilesServer.Utils; using Microsoft.Extensions.Logging; using System.Net; using System.Net.Http.Json; @@ -189,7 +188,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase { throw; } - catch (Exception ex) + catch (Exception) { try { diff --git a/MareSynchronos/WebAPI/SignalR/HubConnectionConfig.cs b/MareSynchronos/WebAPI/SignalR/HubConnectionConfig.cs index dc5fabb..6ac65f2 100644 --- a/MareSynchronos/WebAPI/SignalR/HubConnectionConfig.cs +++ b/MareSynchronos/WebAPI/SignalR/HubConnectionConfig.cs @@ -5,8 +5,8 @@ namespace MareSynchronos.WebAPI.SignalR; public record HubConnectionConfig { - [JsonPropertyName("hub_url")] - public string HubUrl { get; set; } = string.Empty; + [JsonPropertyName("hub_url")] + public string HubUrl { get; set; } = string.Empty; private readonly bool? _skipNegotiation; @@ -20,28 +20,28 @@ public record HubConnectionConfig [JsonPropertyName("transports")] public string[]? Transports { get; set; } - [JsonIgnore] - public HttpTransportType TransportType - { - get - { - if (Transports == null || Transports.Length == 0) - return HttpTransportType.WebSockets; + [JsonIgnore] + public HttpTransportType TransportType + { + get + { + if (Transports == null || Transports.Length == 0) + return HttpTransportType.WebSockets; HttpTransportType result = HttpTransportType.None; foreach (var transport in Transports) { - result |= transport.ToLowerInvariant() switch - { - "websockets" => HttpTransportType.WebSockets, - "serversentevents" => HttpTransportType.ServerSentEvents, - "longpolling" => HttpTransportType.LongPolling, - _ => HttpTransportType.None - }; + result |= transport.ToLowerInvariant() switch + { + "websockets" => HttpTransportType.WebSockets, + "serversentevents" => HttpTransportType.ServerSentEvents, + "longpolling" => HttpTransportType.LongPolling, + _ => HttpTransportType.None + }; }; - return result; - } - } + return result; + } + } } diff --git a/MareSynchronos/WebAPI/SignalR/HubFactory.cs b/MareSynchronos/WebAPI/SignalR/HubFactory.cs index 37463af..8fb3f22 100644 --- a/MareSynchronos/WebAPI/SignalR/HubFactory.cs +++ b/MareSynchronos/WebAPI/SignalR/HubFactory.cs @@ -119,7 +119,6 @@ public class HubFactory : MediatorSubscriberBase var ver = Assembly.GetExecutingAssembly().GetName().Version; httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("MareSynchronos", ver!.Major + "." + ver!.Minor + "." + ver!.Build)); - // Make a GET request to the loporrit endpoint var response = await httpClient.GetAsync(wellKnownUrl).ConfigureAwait(false); if (!response.IsSuccessStatusCode) diff --git a/MareSynchronos/WebAPI/SignalR/TokenProvider.cs b/MareSynchronos/WebAPI/SignalR/TokenProvider.cs index c1c688b..b8b47aa 100644 --- a/MareSynchronos/WebAPI/SignalR/TokenProvider.cs +++ b/MareSynchronos/WebAPI/SignalR/TokenProvider.cs @@ -7,7 +7,7 @@ using MareSynchronos.Utils; using MareSynchronos.API.Dto; using Microsoft.Extensions.Logging; using System.Collections.Concurrent; -using System.IdentityModel.Tokens.Jwt; +using System.Net; using System.Net.Http.Headers; using System.Net.Http.Json; using System.Reflection; @@ -76,7 +76,7 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber new KeyValuePair("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)), }), token).ConfigureAwait(false); - if (!result.IsSuccessStatusCode) + if (result.StatusCode == HttpStatusCode.NotFound) { tokenUri = MareAuth.AuthFullPath(new Uri(_serverManager.CurrentApiUrl .Replace("wss://", "https://", StringComparison.OrdinalIgnoreCase) @@ -87,14 +87,14 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber new KeyValuePair("charaIdent", await _dalamudUtil.GetPlayerNameHashedAsync().ConfigureAwait(false)), }), token).ConfigureAwait(false); - var textResponse = await result.Content.ReadAsStringAsync().ConfigureAwait(false) ?? string.Empty; + var textResponse = await result.Content.ReadAsStringAsync(token).ConfigureAwait(false) ?? string.Empty; result.EnsureSuccessStatusCode(); _tokenCache[identifier] = textResponse; _wellKnownCache[_serverManager.CurrentApiUrl] = null; return textResponse; } - var response = await result.Content.ReadFromJsonAsync().ConfigureAwait(false) ?? new(); + var response = await result.Content.ReadFromJsonAsync(token).ConfigureAwait(false) ?? new(); result.EnsureSuccessStatusCode(); _tokenCache[identifier] = response.Token; _wellKnownCache[_serverManager.CurrentApiUrl] = response.WellKnown; @@ -107,7 +107,7 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber _logger.LogError(ex, "GetNewToken: Failure to get token"); - if (ex.StatusCode == System.Net.HttpStatusCode.Unauthorized) + if (ex.StatusCode == HttpStatusCode.Unauthorized) { Mediator.Publish(new NotificationMessage("Error refreshing token", "Your authentication token could not be renewed. Try reconnecting manually.", NotificationType.Error)); Mediator.Publish(new DisconnectedMessage());