Track and display last known player names automatically

This commit is contained in:
Loporrit
2024-02-16 07:11:10 +00:00
parent 4091df858f
commit ab996692e3
15 changed files with 86 additions and 44 deletions

View File

@@ -27,13 +27,14 @@ public class MareConfig : IMareConfiguration
public int ParallelDownloads { get; set; } = 10;
public int DownloadSpeedLimitInBytes { get; set; } = 0;
public DownloadSpeeds DownloadSpeedType { get; set; } = DownloadSpeeds.MBps;
public bool PreferNotesOverNamesForVisible { get; set; } = false;
[Obsolete] public bool PreferNotesOverNamesForVisible { get; set; } = false;
public float ProfileDelay { get; set; } = 1.5f;
public bool ProfilePopoutRight { get; set; } = false;
public bool ProfilesAllowNsfw { get; set; } = false;
public bool ProfilesShow { get; set; } = false;
public bool ShowSyncshellUsersInVisible { get; set; } = true;
public bool ShowCharacterNameInsteadOfNotesForVisible { get; set; } = false;
[Obsolete] public bool ShowCharacterNameInsteadOfNotesForVisible { get; set; } = false;
public bool ShowCharacterNames { get; set; } = true;
public bool ShowOfflineUsersSeparately { get; set; } = true;
public bool ShowSyncshellOfflineUsersSeparately { get; set; } = true;
public bool GroupUpSyncshells { get; set; } = true;

View File

@@ -4,4 +4,5 @@ public class ServerNotesStorage
{
public Dictionary<string, string> GidServerComments { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, string> UidServerComments { get; set; } = new(StringComparer.Ordinal);
public Dictionary<string, string> UidLastSeenNames { get; set; } = new(StringComparer.Ordinal);
}

View File

@@ -1,4 +1,5 @@
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.MareConfiguration;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.Logging;
@@ -10,19 +11,21 @@ public class PairFactory
private readonly PairHandlerFactory _cachedPlayerFactory;
private readonly ILoggerFactory _loggerFactory;
private readonly MareMediator _mareMediator;
private readonly MareConfigService _mareConfig;
private readonly ServerConfigurationManager _serverConfigurationManager;
public PairFactory(ILoggerFactory loggerFactory, PairHandlerFactory cachedPlayerFactory,
MareMediator mareMediator, ServerConfigurationManager serverConfigurationManager)
MareMediator mareMediator, MareConfigService mareConfig, ServerConfigurationManager serverConfigurationManager)
{
_loggerFactory = loggerFactory;
_cachedPlayerFactory = cachedPlayerFactory;
_mareMediator = mareMediator;
_mareConfig = mareConfig;
_serverConfigurationManager = serverConfigurationManager;
}
public Pair Create()
{
return new Pair(_loggerFactory.CreateLogger<Pair>(), _cachedPlayerFactory, _mareMediator, _serverConfigurationManager);
return new Pair(_loggerFactory.CreateLogger<Pair>(), _cachedPlayerFactory, _mareMediator, _mareConfig, _serverConfigurationManager);
}
}

View File

@@ -5,6 +5,7 @@ using MareSynchronos.PlayerData.Handlers;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.PlayerData.Factories;
@@ -20,11 +21,12 @@ public class PairHandlerFactory
private readonly ILoggerFactory _loggerFactory;
private readonly MareMediator _mareMediator;
private readonly PluginWarningNotificationService _pluginWarningNotificationManager;
private readonly ServerConfigurationManager _serverConfigurationManager;
public PairHandlerFactory(ILoggerFactory loggerFactory, GameObjectHandlerFactory gameObjectHandlerFactory, IpcManager ipcManager,
FileDownloadManagerFactory fileDownloadManagerFactory, DalamudUtilService dalamudUtilService,
PluginWarningNotificationService pluginWarningNotificationManager, CancellationToken dalamudLifetime,
FileCacheManager fileCacheManager, MareMediator mareMediator)
PluginWarningNotificationService pluginWarningNotificationManager, ServerConfigurationManager serverConfigurationManager,
CancellationToken dalamudLifetime, FileCacheManager fileCacheManager, MareMediator mareMediator)
{
_loggerFactory = loggerFactory;
_gameObjectHandlerFactory = gameObjectHandlerFactory;
@@ -32,6 +34,7 @@ public class PairHandlerFactory
_fileDownloadManagerFactory = fileDownloadManagerFactory;
_dalamudUtilService = dalamudUtilService;
_pluginWarningNotificationManager = pluginWarningNotificationManager;
_serverConfigurationManager = serverConfigurationManager;
_dalamudLifetimeToken = dalamudLifetime;
_fileCacheManager = fileCacheManager;
_mareMediator = mareMediator;
@@ -40,7 +43,7 @@ public class PairHandlerFactory
public PairHandler Create(OnlineUserIdentDto onlineUserIdentDto)
{
return new PairHandler(_loggerFactory.CreateLogger<PairHandler>(), onlineUserIdentDto, _gameObjectHandlerFactory,
_ipcManager, _fileDownloadManagerFactory.Create(), _pluginWarningNotificationManager, _dalamudUtilService, _dalamudLifetimeToken,
_fileCacheManager, _mareMediator);
_ipcManager, _fileDownloadManagerFactory.Create(), _pluginWarningNotificationManager, _serverConfigurationManager, _dalamudUtilService,
_dalamudLifetimeToken, _fileCacheManager, _mareMediator);
}
}

View File

@@ -6,6 +6,7 @@ using MareSynchronos.PlayerData.Factories;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using MareSynchronos.Services.ServerConfiguration;
using MareSynchronos.Utils;
using MareSynchronos.WebAPI.Files;
using Microsoft.Extensions.Logging;
@@ -26,6 +27,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
private readonly IpcManager _ipcManager;
private readonly CancellationToken _lifetime;
private readonly PluginWarningNotificationService _pluginWarningNotificationManager;
private readonly ServerConfigurationManager _serverConfigurationManager;
private CancellationTokenSource? _applicationCancellationTokenSource = new();
private Guid _applicationId;
private Task? _applicationTask;
@@ -42,7 +44,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
public PairHandler(ILogger<PairHandler> logger, OnlineUserIdentDto onlineUser,
GameObjectHandlerFactory gameObjectHandlerFactory,
IpcManager ipcManager, FileDownloadManager transferManager,
PluginWarningNotificationService pluginWarningNotificationManager,
PluginWarningNotificationService pluginWarningNotificationManager, ServerConfigurationManager serverConfigurationManager,
DalamudUtilService dalamudUtil, CancellationToken lifetime,
FileCacheManager fileDbManager, MareMediator mediator) : base(logger, mediator)
{
@@ -51,6 +53,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
_ipcManager = ipcManager;
_downloadManager = transferManager;
_pluginWarningNotificationManager = pluginWarningNotificationManager;
_serverConfigurationManager = serverConfigurationManager;
_dalamudUtil = dalamudUtil;
_lifetime = lifetime;
_fileDbManager = fileDbManager;
@@ -507,6 +510,7 @@ public sealed class PairHandler : DisposableMediatorSubscriberBase
});
_ipcManager.PenumbraAssignTemporaryCollectionAsync(Logger, _penumbraCollection, _charaHandler.GetGameObject()!.ObjectIndex).GetAwaiter().GetResult();
_serverConfigurationManager.SetNameForUid(OnlineUser.User.UID, name);
}
private async Task RevertCustomizationDataAsync(ObjectKind objectKind, string name, Guid applicationId, CancellationToken cancelToken)

View File

@@ -1,11 +1,13 @@
using Dalamud.ContextMenu;
using Dalamud.Game.Text.SeStringHandling;
using Lumina.Excel.GeneratedSheets2;
using MareSynchronos.API.Data;
using MareSynchronos.API.Data.Comparer;
using MareSynchronos.API.Data.Enum;
using MareSynchronos.API.Data.Extensions;
using MareSynchronos.API.Dto.Group;
using MareSynchronos.API.Dto.User;
using MareSynchronos.MareConfiguration;
using MareSynchronos.PlayerData.Factories;
using MareSynchronos.PlayerData.Handlers;
using MareSynchronos.Services.Mediator;
@@ -21,16 +23,19 @@ public class Pair
private readonly SemaphoreSlim _creationSemaphore = new(1);
private readonly ILogger<Pair> _logger;
private readonly MareMediator _mediator;
private readonly MareConfigService _mareConfig;
private readonly ServerConfigurationManager _serverConfigurationManager;
private CancellationTokenSource _applicationCts = new CancellationTokenSource();
private OnlineUserIdentDto? _onlineUserIdentDto = null;
private string? _playerName = null;
public Pair(ILogger<Pair> logger, PairHandlerFactory cachedPlayerFactory,
MareMediator mediator, ServerConfigurationManager serverConfigurationManager)
MareMediator mediator, MareConfigService mareConfig, ServerConfigurationManager serverConfigurationManager)
{
_logger = logger;
_cachedPlayerFactory = cachedPlayerFactory;
_mediator = mediator;
_mareConfig = mareConfig;
_serverConfigurationManager = serverConfigurationManager;
}
@@ -43,7 +48,7 @@ public class Pair
public bool IsVisible => CachedPlayer?.IsVisible ?? false;
public CharacterData? LastReceivedCharacterData { get; set; }
public string? PlayerName => CachedPlayer?.PlayerName ?? string.Empty;
public string? PlayerName => GetPlayerName();
public long LastAppliedDataSize => CachedPlayer?.LastAppliedDataSize ?? -1;
public UserData UserData => UserPair?.User ?? GroupPair.First().Value.User;
@@ -154,6 +159,23 @@ public class Pair
return _serverConfigurationManager.GetNoteForUid(UserData.UID);
}
public string? GetPlayerName()
{
if (CachedPlayer != null && CachedPlayer.PlayerName != null)
return CachedPlayer.PlayerName;
else
return _serverConfigurationManager.GetNameForUid(UserData.UID);
}
public string? GetNoteOrName()
{
string? note = GetNote();
if (_mareConfig.Current.ShowCharacterNames || IsVisible)
return note ?? GetPlayerName();
else
return note;
}
public string GetPlayerNameHash()
{
return CachedPlayer?.PlayerNameHash ?? string.Empty;

View File

@@ -123,7 +123,7 @@ public sealed class PairManager : DisposableMediatorSubscriberBase
&& (_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs && !string.IsNullOrEmpty(pair.GetNote())
|| !_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs))
{
string? note = pair.GetNote();
string? note = pair.GetNoteOrName();
var msg = !string.IsNullOrEmpty(note)
? $"{note} ({pair.UserData.AliasOrUID}) is now online"
: $"{pair.UserData.AliasOrUID} is now online";

View File

@@ -80,7 +80,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton<FileDownloadManagerFactory>();
collection.AddSingleton((s) => new PairHandlerFactory(s.GetRequiredService<ILoggerFactory>(), s.GetRequiredService<GameObjectHandlerFactory>(),
s.GetRequiredService<IpcManager>(), s.GetRequiredService<FileDownloadManagerFactory>(), s.GetRequiredService<DalamudUtilService>(),
s.GetRequiredService<PluginWarningNotificationService>(),
s.GetRequiredService<PluginWarningNotificationService>(), s.GetRequiredService<ServerConfigurationManager>(),
CancellationTokenSource.CreateLinkedTokenSource(addonLifecycle.GameShuttingDownToken, addonLifecycle.DalamudUnloadingToken).Token,
s.GetRequiredService<FileCacheManager>(), s.GetRequiredService<MareMediator>()));
collection.AddSingleton<PairFactory>();
@@ -104,7 +104,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddSingleton((s) => new NotesConfigService(pluginInterface.ConfigDirectory.FullName));
collection.AddSingleton((s) => new ServerTagConfigService(pluginInterface.ConfigDirectory.FullName));
collection.AddSingleton((s) => new TransientConfigService(pluginInterface.ConfigDirectory.FullName));
collection.AddSingleton((s) => new ConfigurationMigrator(s.GetRequiredService<ILogger<ConfigurationMigrator>>(), pluginInterface));
collection.AddSingleton((s) => new ConfigurationMigrator(s.GetRequiredService<ILogger<ConfigurationMigrator>>(), pluginInterface, s.GetRequiredService<NotesConfigService>()));
collection.AddSingleton<HubFactory>();
// add scoped services

View File

@@ -229,6 +229,16 @@ public class ServerConfigurationManager
return null;
}
internal string? GetNameForUid(string uid)
{
if (CurrentNotesStorage().UidLastSeenNames.TryGetValue(uid, out var name))
{
if (string.IsNullOrEmpty(name)) return null;
return name;
}
return null;
}
internal HashSet<string> GetServerAvailablePairTags()
{
return CurrentServerTagStorage().ServerAvailablePairTags;
@@ -324,6 +334,17 @@ public class ServerConfigurationManager
_notesConfig.Save();
}
internal void SetNameForUid(string uid, string name)
{
if (string.IsNullOrEmpty(uid)) return;
if (CurrentNotesStorage().UidLastSeenNames.TryGetValue(uid, out var currentName) && currentName == name)
return;
CurrentNotesStorage().UidLastSeenNames[uid] = name;
_notesConfig.Save();
}
private ServerNotesStorage CurrentNotesStorage()
{
TryCreateCurrentNotesStorage();

View File

@@ -368,11 +368,7 @@ public class CompactUi : WindowMediatorSubscriberBase
var ySize = TransferPartHeight == 0
? 1
: (ImGui.GetWindowContentRegionMax().Y - ImGui.GetWindowContentRegionMin().Y) - TransferPartHeight - ImGui.GetCursorPosY();
var users = GetFilteredUsers()
.OrderBy(
u => _configService.Current.ShowCharacterNameInsteadOfNotesForVisible && !string.IsNullOrEmpty(u.PlayerName)
? (_configService.Current.PreferNotesOverNamesForVisible ? u.GetNote() : u.PlayerName)
: (u.GetNote() ?? u.UserData.AliasOrUID), StringComparer.OrdinalIgnoreCase).ToList();
var users = GetFilteredUsers().OrderBy(u => u.GetNoteOrName());
var onlineUsers = users.Where(u => u.UserPair!.OtherPermissions.IsPaired() && (u.IsOnline || u.UserPair!.OwnPermissions.IsPaused())).Select(c => new DrawUserPair("Online" + c.UserData.UID, c, _uidDisplayHandler, _apiController, Mediator, _selectGroupForPairUi)).ToList();
var visibleUsers = users.Where(u => u.IsVisible).Select(c => new DrawUserPair("Visible" + c.UserData.UID, c, _uidDisplayHandler, _apiController, Mediator, _selectGroupForPairUi)).ToList();

View File

@@ -399,7 +399,7 @@ internal sealed class GroupPanel
.OrderByDescending(u => string.Equals(u.UserData.UID, groupDto.OwnerUID, StringComparison.Ordinal))
.ThenByDescending(u => u.GroupPair[groupDto].GroupPairStatusInfo.IsModerator())
.ThenByDescending(u => u.GroupPair[groupDto].GroupPairStatusInfo.IsPinned())
.ThenBy(u => u.GetNote() ?? u.UserData.AliasOrUID, StringComparer.OrdinalIgnoreCase);
.ThenBy(u => u.GetNoteOrName() ?? u.UserData.AliasOrUID, StringComparer.OrdinalIgnoreCase);
var visibleUsers = new List<DrawGroupPair>();
var onlineUsers = new List<DrawGroupPair>();

View File

@@ -144,13 +144,13 @@ public sealed class DtrEntry : IDisposable, IHostedService
{
visiblePairs = _pairManager.GetOnlineUserPairs()
.Where(x => x.IsVisible)
.Select(x => string.Format("{0} ({1})", _configService.Current.PreferNoteInDtrTooltip ? x.GetNote() ?? x.PlayerName : x.PlayerName, x.UserData.AliasOrUID ));
.Select(x => string.Format("{0} ({1})", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName, x.UserData.AliasOrUID ));
}
else
{
visiblePairs = _pairManager.GetOnlineUserPairs()
.Where(x => x.IsVisible)
.Select(x => string.Format("{0}", _configService.Current.PreferNoteInDtrTooltip ? x.GetNote() ?? x.PlayerName : x.PlayerName));
.Select(x => string.Format("{0}", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName));
}
tooltip = $"Loporrit: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}";

View File

@@ -165,12 +165,13 @@ public class UidDisplayHandler
playerText = pair.UserData.AliasOrUID;
}
if (_mareConfigService.Current.ShowCharacterNameInsteadOfNotesForVisible && pair.IsVisible && !showUidInsteadOfName)
if (_mareConfigService.Current.ShowCharacterNames && textIsUid && !showUidInsteadOfName)
{
playerText = pair.PlayerName;
textIsUid = false;
if (_mareConfigService.Current.PreferNotesOverNamesForVisible)
var name = pair.PlayerName;
if (name != null)
{
playerText = name;
textIsUid = false;
var note = pair.GetNote();
if (note != null)
{

View File

@@ -653,7 +653,7 @@ public class SettingsUi : WindowMediatorSubscriberBase
ImGui.Separator();
UiSharedService.FontText("UI", _uiShared.UidFont);
var showNameInsteadOfNotes = _configService.Current.ShowCharacterNameInsteadOfNotesForVisible;
var showCharacterNames = _configService.Current.ShowCharacterNames;
var showVisibleSeparate = _configService.Current.ShowVisibleUsersSeparately;
var showOfflineSeparate = _configService.Current.ShowOfflineUsersSeparately;
var showProfiles = _configService.Current.ProfilesShow;
@@ -718,23 +718,12 @@ public class SettingsUi : WindowMediatorSubscriberBase
}
UiSharedService.DrawHelpText("This will show all currently offline users in a special 'Offline' group in the main UI.");
if (ImGui.Checkbox("Show player name for visible players", ref showNameInsteadOfNotes))
if (ImGui.Checkbox("Show player names", ref showCharacterNames))
{
_configService.Current.ShowCharacterNameInsteadOfNotesForVisible = showNameInsteadOfNotes;
_configService.Current.ShowCharacterNames = showCharacterNames;
_configService.Save();
}
UiSharedService.DrawHelpText("This will show the character name instead of custom set note when a character is visible");
ImGui.Indent();
if (!_configService.Current.ShowCharacterNameInsteadOfNotesForVisible) ImGui.BeginDisabled();
if (ImGui.Checkbox("Prefer notes over player names for visible players", ref preferNotesInsteadOfName))
{
_configService.Current.PreferNotesOverNamesForVisible = preferNotesInsteadOfName;
_configService.Save();
}
UiSharedService.DrawHelpText("If you set a note for a player it will be shown instead of the player name");
if (!_configService.Current.ShowCharacterNameInsteadOfNotesForVisible) ImGui.EndDisabled();
ImGui.Unindent();
UiSharedService.DrawHelpText("This will show character names instead of UIDs when possible");
if (ImGui.Checkbox("Show Profiles on Hover", ref showProfiles))
{

View File

@@ -155,9 +155,10 @@ public class SyncshellAdminUI : WindowMediatorSubscriberBase
ImGui.TableNextColumn(); // online/name
string onlineText = pair.Key.IsOnline ? "Online" : "Offline";
if (!string.IsNullOrEmpty(pair.Key.PlayerName))
string? name = pair.Key.GetNoteOrName();
if (!string.IsNullOrEmpty(name))
{
onlineText += " (" + pair.Key.PlayerName + ")";
onlineText += " (" + name + ")";
}
var boolcolor = UiSharedService.GetBoolColor(pair.Key.IsOnline);
ImGui.AlignTextToFramePadding();