Update 0.1.8.2 - Correctif UI, Correctif Nearby CompactUI, Add changelog

This commit is contained in:
2025-09-27 10:02:43 +02:00
parent bf770f19d9
commit 6572fdcc27
11 changed files with 481 additions and 69 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging;
using MareSynchronos.WebAPI.AutoDetect;
using MareSynchronos.MareConfiguration;
@@ -15,6 +17,11 @@ public class AutoDetectRequestService
private readonly MareConfigService _configService;
private readonly DalamudUtilService _dalamud;
private readonly MareMediator _mediator;
private readonly object _syncRoot = new();
private readonly Dictionary<string, DateTime> _activeCooldowns = new(StringComparer.Ordinal);
private readonly Dictionary<string, RefusalTracker> _refusalTrackers = new(StringComparer.Ordinal);
private static readonly TimeSpan RequestCooldown = TimeSpan.FromMinutes(5);
private static readonly TimeSpan RefusalLockDuration = TimeSpan.FromMinutes(15);
public AutoDetectRequestService(ILogger<AutoDetectRequestService> logger, DiscoveryConfigProvider configProvider, DiscoveryApiClient client, MareConfigService configService, MareMediator mediator, DalamudUtilService dalamudUtilService)
{
@@ -26,7 +33,7 @@ public class AutoDetectRequestService
_dalamud = dalamudUtilService;
}
public async Task<bool> SendRequestAsync(string token, CancellationToken ct = default)
public async Task<bool> SendRequestAsync(string token, string? uid = null, string? targetDisplayName = null, CancellationToken ct = default)
{
if (!_configService.Current.AllowAutoDetectPairRequests)
{
@@ -34,6 +41,47 @@ public class AutoDetectRequestService
_mediator.Publish(new NotificationMessage("Nearby request blocked", "Enable 'Allow pair requests' in Settings to send requests.", NotificationType.Info));
return false;
}
var targetKey = BuildTargetKey(uid, token, targetDisplayName);
if (!string.IsNullOrEmpty(targetKey))
{
var now = DateTime.UtcNow;
lock (_syncRoot)
{
if (_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value > now)
{
PublishLockNotification(tracker.LockUntil.Value - now);
return false;
}
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value <= now)
{
tracker.LockUntil = null;
tracker.Count = 0;
if (tracker.Count == 0 && tracker.LockUntil == null)
{
_refusalTrackers.Remove(targetKey);
}
}
}
if (_activeCooldowns.TryGetValue(targetKey, out var lastSent))
{
var elapsed = now - lastSent;
if (elapsed < RequestCooldown)
{
PublishCooldownNotification(RequestCooldown - elapsed);
return false;
}
if (elapsed >= RequestCooldown)
{
_activeCooldowns.Remove(targetKey);
}
}
}
}
var endpoint = _configProvider.RequestEndpoint;
if (string.IsNullOrEmpty(endpoint))
{
@@ -53,10 +101,51 @@ public class AutoDetectRequestService
var ok = await _client.SendRequestAsync(endpoint!, token, displayName, ct).ConfigureAwait(false);
if (ok)
{
if (!string.IsNullOrEmpty(targetKey))
{
lock (_syncRoot)
{
_activeCooldowns[targetKey] = DateTime.UtcNow;
if (_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
tracker.Count = 0;
tracker.LockUntil = null;
if (tracker.Count == 0 && tracker.LockUntil == null)
{
_refusalTrackers.Remove(targetKey);
}
}
}
}
_mediator.Publish(new NotificationMessage("Nearby request sent", "The other user will receive a request notification.", NotificationType.Info));
}
else
{
if (!string.IsNullOrEmpty(targetKey))
{
var now = DateTime.UtcNow;
lock (_syncRoot)
{
_activeCooldowns.Remove(targetKey);
if (!_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
tracker = new RefusalTracker();
_refusalTrackers[targetKey] = tracker;
}
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value <= now)
{
tracker.LockUntil = null;
tracker.Count = 0;
}
tracker.Count++;
if (tracker.Count >= 3)
{
tracker.LockUntil = now.Add(RefusalLockDuration);
}
}
}
_mediator.Publish(new NotificationMessage("Nearby request failed", "The server rejected the request. Try again soon.", NotificationType.Warning));
}
return ok;
@@ -80,4 +169,42 @@ public class AutoDetectRequestService
_logger.LogInformation("Nearby: sending accept notify via {endpoint}", endpoint);
return await _client.SendAcceptAsync(endpoint!, targetUid, displayName, ct).ConfigureAwait(false);
}
private static string? BuildTargetKey(string? uid, string? token, string? displayName)
{
if (!string.IsNullOrEmpty(uid)) return "uid:" + uid;
if (!string.IsNullOrEmpty(token)) return "token:" + token;
if (!string.IsNullOrEmpty(displayName)) return "name:" + displayName;
return null;
}
private void PublishCooldownNotification(TimeSpan remaining)
{
var durationText = FormatDuration(remaining);
_mediator.Publish(new NotificationMessage("Nearby request en attente", $"Nearby request déjà envoyée. Merci d'attendre environ {durationText} avant de réessayer.", NotificationType.Info, TimeSpan.FromSeconds(5)));
}
private void PublishLockNotification(TimeSpan remaining)
{
var durationText = FormatDuration(remaining);
_mediator.Publish(new NotificationMessage("Nearby request bloquée", $"Nearby request bloquée après plusieurs refus. Réessayez dans {durationText}.", NotificationType.Warning, TimeSpan.FromSeconds(5)));
}
private static string FormatDuration(TimeSpan remaining)
{
if (remaining.TotalMinutes >= 1)
{
var minutes = Math.Max(1, (int)Math.Ceiling(remaining.TotalMinutes));
return minutes == 1 ? "1 minute" : minutes + " minutes";
}
var seconds = Math.Max(1, (int)Math.Ceiling(remaining.TotalSeconds));
return seconds == 1 ? "1 seconde" : seconds + " secondes";
}
private sealed class RefusalTracker
{
public int Count;
public DateTime? LockUntil;
}
}

View File

@@ -201,7 +201,7 @@ public sealed class CharaDataNearbyManager : DisposableMediatorSubscriberBase
foreach (var data in _metaInfoCache.Where(d => (string.IsNullOrWhiteSpace(UserNoteFilter)
|| ((d.Key.Alias ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase)
|| d.Key.UID.Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase)
|| (_serverConfigurationManager.GetNoteForUid(UserNoteFilter) ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase))))
|| (_serverConfigurationManager.GetNoteForUid(d.Key.UID) ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase))))
.ToDictionary(k => k.Key, k => k.Value))
{
// filter all poses based on territory, that always must be correct

View File

@@ -1,4 +1,5 @@
using Dalamud.Game.Text.SeStringHandling;
using System;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.ImGuiNotification;
using Dalamud.Plugin.Services;
using MareSynchronos.MareConfiguration;
@@ -81,41 +82,94 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
if (!_dalamudUtilService.IsLoggedIn) return;
switch (msg.Type)
bool appendInstruction;
bool forceChat = ShouldForceChat(msg, out appendInstruction);
var effectiveMessage = forceChat && appendInstruction ? AppendUsyncInstruction(msg.Message) : msg.Message;
var adjustedMsg = forceChat && appendInstruction ? msg with { Message = effectiveMessage } : msg;
switch (adjustedMsg.Type)
{
case NotificationType.Info:
ShowNotificationLocationBased(msg, _configurationService.Current.InfoNotification);
ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.InfoNotification, forceChat);
break;
case NotificationType.Warning:
ShowNotificationLocationBased(msg, _configurationService.Current.WarningNotification);
ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.WarningNotification, forceChat);
break;
case NotificationType.Error:
ShowNotificationLocationBased(msg, _configurationService.Current.ErrorNotification);
ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.ErrorNotification, forceChat);
break;
}
}
private void ShowNotificationLocationBased(NotificationMessage msg, NotificationLocation location)
private static bool ShouldForceChat(NotificationMessage msg, out bool appendInstruction)
{
switch (location)
appendInstruction = false;
bool IsNearbyRequestText(string? text)
{
case NotificationLocation.Toast:
ShowToast(msg);
break;
if (string.IsNullOrEmpty(text)) return false;
return text.Contains("Nearby request", StringComparison.OrdinalIgnoreCase)
|| text.Contains("Nearby Request", StringComparison.Ordinal);
}
case NotificationLocation.Chat:
ShowChat(msg);
break;
bool IsNearbyAcceptText(string? text)
{
if (string.IsNullOrEmpty(text)) return false;
return text.Contains("Nearby Accept", StringComparison.OrdinalIgnoreCase);
}
case NotificationLocation.Both:
ShowToast(msg);
ShowChat(msg);
break;
bool isAccept = IsNearbyAcceptText(msg.Title) || IsNearbyAcceptText(msg.Message);
if (isAccept)
return false;
case NotificationLocation.Nowhere:
break;
bool isRequest = IsNearbyRequestText(msg.Title) || IsNearbyRequestText(msg.Message);
if (isRequest)
{
appendInstruction = !IsRequestSentConfirmation(msg);
return true;
}
return false;
}
private static bool IsRequestSentConfirmation(NotificationMessage msg)
{
if (string.Equals(msg.Title, "Nearby request sent", StringComparison.OrdinalIgnoreCase))
return true;
if (!string.IsNullOrEmpty(msg.Message) && msg.Message.Contains("The other user will receive a request notification.", StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
private static string AppendUsyncInstruction(string? message)
{
const string suffix = " | Ouvrez /usync pour voir l'invitation.";
if (string.IsNullOrWhiteSpace(message))
return suffix.TrimStart(' ', '|');
if (message.Contains("/usync", StringComparison.OrdinalIgnoreCase))
return message;
return message.TrimEnd() + suffix;
}
private void ShowNotificationLocationBased(NotificationMessage msg, NotificationLocation location, bool forceChat)
{
bool showToast = location is NotificationLocation.Toast or NotificationLocation.Both;
bool showChat = forceChat || location is NotificationLocation.Chat or NotificationLocation.Both;
if (showToast)
{
ShowToast(msg);
}
if (showChat)
{
ShowChat(msg);
}
}
@@ -138,4 +192,4 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
InitialDuration = msg.TimeShownOnScreen ?? TimeSpan.FromSeconds(3)
});
}
}
}