Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Network Configurator Fixes #1592

Merged
merged 2 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 43 additions & 4 deletions Content.Server/DeviceNetwork/Systems/NetworkConfiguratorSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
using Robust.Server.Audio;
using Robust.Server.GameObjects;
using Robust.Shared.Audio;
using Robust.Shared.Player;
using Robust.Shared.Map.Events;
using Robust.Shared.Timing;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -64,6 +64,42 @@ public override void Initialize()
SubscribeLocalEvent<NetworkConfiguratorComponent, NetworkConfiguratorButtonPressedMessage>(OnConfigButtonPressed);

SubscribeLocalEvent<DeviceListComponent, ComponentRemove>(OnComponentRemoved);

SubscribeLocalEvent<BeforeSaveEvent>(OnMapSave);
}

private void OnMapSave(BeforeSaveEvent ev)
{
var enumerator = AllEntityQuery<NetworkConfiguratorComponent>();
while (enumerator.MoveNext(out var uid, out var conf))
{
if (CompOrNull<TransformComponent>(conf.ActiveDeviceList)?.MapUid != ev.Map)
continue;

// The linked device list is (probably) being saved. Make sure that the configurator is also being saved
// (i.e., not in the hands of a mapper/ghost). In the future, map saving should raise a separate event
// containing a set of all entities that are about to be saved, which would make checking this much easier.
// This is a shitty bandaid, and will force close the UI during auto-saves.
// TODO Map serialization refactor

var xform = Transform(uid);
if (xform.MapUid == ev.Map && IsSaveable(uid))
continue;

_uiSystem.CloseUi(uid, NetworkConfiguratorUiKey.Configure);
DebugTools.AssertNull(conf.ActiveDeviceList);
}

bool IsSaveable(EntityUid uid)
{
while (uid.IsValid())
{
if (Prototype(uid)?.MapSavable == false)
return false;
uid = Transform(uid).ParentUid;
}
return true;
}
}

private void OnShutdown(EntityUid uid, NetworkConfiguratorComponent component, ComponentShutdown args)
Expand Down Expand Up @@ -435,11 +471,11 @@ private void OpenDeviceLinkUi(EntityUid configuratorUid, EntityUid? targetUid, E
if (Delay(configurator))
return;

if (!targetUid.HasValue || !configurator.ActiveDeviceLink.HasValue || !TryComp(userUid, out ActorComponent? actor) || !AccessCheck(targetUid.Value, userUid, configurator))
if (!targetUid.HasValue || !configurator.ActiveDeviceLink.HasValue || !AccessCheck(targetUid.Value, userUid, configurator))
return;


_uiSystem.OpenUi(configuratorUid, NetworkConfiguratorUiKey.Link, actor.PlayerSession);
_uiSystem.OpenUi(configuratorUid, NetworkConfiguratorUiKey.Link, userUid);
configurator.DeviceLinkTarget = targetUid;


Expand Down Expand Up @@ -490,6 +526,9 @@ private void OpenDeviceListUi(EntityUid configuratorUid, EntityUid? targetUid, E
if (!TryComp(targetUid, out DeviceListComponent? list))
return;

if (TryComp(configurator.ActiveDeviceList, out DeviceListComponent? oldList))
oldList.Configurators.Remove(configuratorUid);

list.Configurators.Add(configuratorUid);
configurator.ActiveDeviceList = targetUid;
Dirty(configuratorUid, configurator);
Expand Down Expand Up @@ -763,7 +802,7 @@ private void OnConfigButtonPressed(EntityUid uid, NetworkConfiguratorComponent c
{
if (query.TryGetComponent(device, out var comp))
{
component.Devices[addr] = device;
component.Devices.Add(addr, device);
comp.Configurators.Add(uid);
}
}
Expand Down
7 changes: 6 additions & 1 deletion Content.Shared/Access/Systems/AccessReaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,12 @@ public bool IsAllowed(
return IsAllowedInternal(access, stationKeys, reader);

if (!_containerSystem.TryGetContainer(target, reader.ContainerAccessProvider, out var container))
return Paused(target); // when mapping, containers with electronics arent spawned
return false;

// If entity is paused then always allow it at this point.
// Door electronics is kind of a mess but yeah, it should only be an unpaused ent interacting with it
if (Paused(target))
return true;

foreach (var entity in container.ContainedEntities)
{
Expand Down
Loading