Skip to content

Commit

Permalink
refactor(research): Improve initial research client registration (#1086)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

---------

Co-authored-by: Nemanja <[email protected]>
(cherry picked from commit aaf5d0d)
  • Loading branch information
exincore committed Mar 11, 2024
1 parent b5a9528 commit 31e3931
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Content.Server/Research/Systems/ResearchSystem.Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Entity<ResearchServerComponent>>();
_lookup.GetChildEntities(grid, servers);

var allServers = EntityQuery<ResearchServerComponent>(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)
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions Content.Server/Research/Systems/ResearchSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 31e3931

Please sign in to comment.