From 31e3931a0d74c000bfb1b032c9ab1a4039c68529 Mon Sep 17 00:00:00 2001 From: exincore Date: Mon, 11 Mar 2024 18:43:05 -0500 Subject: [PATCH] refactor(research): Improve initial research client registration (#1086) * refactor(research): Improve initial research client registration * refactor(research): Move EntityLookupSystem dependency to main class file * Fix `ResearchSystem.Client` `UpdateClientInterface` preconditions. (#25743) * fix(research): Fix `ResearchSystem.Client` `UpdateClientInterface` preconditions. Fixes a paradox where selecting a research server requires a research server to already be selected. This would softlock the research client until it is reconstructed. * style: Discards the discard operator Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> (cherry picked from commit aaf5d0d30254d27d319b2b5f5874ebe787537f0a) --- .../Research/Systems/ResearchSystem.Client.cs | 22 ++++++++----------- .../Research/Systems/ResearchSystem.cs | 1 + 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/Content.Server/Research/Systems/ResearchSystem.Client.cs b/Content.Server/Research/Systems/ResearchSystem.Client.cs index 1edd5d14bef..d6faea23d50 100644 --- a/Content.Server/Research/Systems/ResearchSystem.Client.cs +++ b/Content.Server/Research/Systems/ResearchSystem.Client.cs @@ -58,20 +58,17 @@ private void OnClientRegistrationChanged(EntityUid uid, ResearchClientComponent private void OnClientMapInit(EntityUid uid, ResearchClientComponent component, MapInitEvent args) { - // If the actual RD server on a map is initialized later, it won't work if we run this immediately. - // For the time being while a better solution is found, we register/unregister a little bit later. - // If we don't run this later, RD servers won't appear in the list on all machines on a ship. - Task.Run(async () => + var maybeGrid = Transform(uid).GridUid; + if (maybeGrid is { } grid) { - await Task.Delay(TimeSpan.FromSeconds(10)); + var servers = new HashSet>(); + _lookup.GetChildEntities(grid, servers); - var allServers = EntityQuery(true).ToArray(); - if (allServers.Length > 0) + foreach (var server in servers) { - RegisterClient(uid, allServers[0].Owner, component, allServers[0]); - UnregisterClient(uid, component); + RegisterClient(uid, server, component); } - }); + } } private void OnClientShutdown(EntityUid uid, ResearchClientComponent component, ComponentShutdown args) @@ -89,12 +86,11 @@ private void UpdateClientInterface(EntityUid uid, ResearchClientComponent? compo if (!Resolve(uid, ref component, false)) return; - if (!TryGetClientServer(uid, out _, out var serverComponent, component)) - return; + TryGetClientServer(uid, out _, out var serverComponent, component); var names = GetNFServerNames(uid); var state = new ResearchClientBoundInterfaceState(names.Length, names, - GetNFServerIds(uid), component.ConnectedToServer ? serverComponent.Id : -1); + GetNFServerIds(uid), serverComponent?.Id ?? -1); _uiSystem.TrySetUiState(uid, ResearchClientUiKey.Key, state); } diff --git a/Content.Server/Research/Systems/ResearchSystem.cs b/Content.Server/Research/Systems/ResearchSystem.cs index 852657f038a..fb7e09cb1d6 100644 --- a/Content.Server/Research/Systems/ResearchSystem.cs +++ b/Content.Server/Research/Systems/ResearchSystem.cs @@ -23,6 +23,7 @@ public sealed partial class ResearchSystem : SharedResearchSystem [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly RadioSystem _radio = default!; [Dependency] private readonly StationSystem _station = default!; + [Dependency] private readonly EntityLookupSystem _lookup = default!; public override void Initialize() {