This commit is contained in:
Spatison
2024-09-06 20:18:36 +03:00
committed by GitHub
parent 510619c78e
commit dc76a9a889
4 changed files with 26 additions and 55 deletions

View File

@@ -29,18 +29,6 @@ public sealed class SingletonDeviceNetServerSystem : EntitySystem
return Resolve(serverId, ref serverComponent) && serverComponent.Active; return Resolve(serverId, ref serverComponent) && serverComponent.Active;
} }
/// <summary>
/// Set server active. WD EDIT
/// </summary>
public bool SetServerActive(EntityUid serverId, bool active, SingletonDeviceNetServerComponent? serverComponent = default)
{
if (!Resolve(serverId, ref serverComponent))
return false;
serverComponent.Active = active;
return true;
}
/// <summary> /// <summary>
/// Returns the address of the currently active server for the given station id if there is one.<br/> /// Returns the address of the currently active server for the given station id if there is one.<br/>
/// What kind of server you're trying to get the active instance of is determined by the component type parameter TComp.<br/> /// What kind of server you're trying to get the active instance of is determined by the component type parameter TComp.<br/>

View File

@@ -10,6 +10,8 @@ using Content.Server.DeviceNetwork.Systems;
using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork;
using Content.Server.Station.Systems; using Content.Server.Station.Systems;
using Content.Shared._White.CartridgeLoader.Cartridges; using Content.Shared._White.CartridgeLoader.Cartridges;
using Content.Shared.Inventory;
using Content.Shared.Mind.Components;
namespace Content.Server._White.CartridgeLoader.Cartridges; namespace Content.Server._White.CartridgeLoader.Cartridges;
@@ -22,6 +24,7 @@ public sealed class MessagesCartridgeSystem : EntitySystem
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
[Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!; [Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
[Dependency] private readonly StationSystem _stationSystem = default!; [Dependency] private readonly StationSystem _stationSystem = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
public override void Initialize() public override void Initialize()
{ {
@@ -33,18 +36,30 @@ public sealed class MessagesCartridgeSystem : EntitySystem
SubscribeLocalEvent<MessagesCartridgeComponent, CartridgeDeactivatedEvent>(OnCartDeactivation); SubscribeLocalEvent<MessagesCartridgeComponent, CartridgeDeactivatedEvent>(OnCartDeactivation);
SubscribeLocalEvent<MessagesCartridgeComponent, CartridgeAddedEvent>(OnCartInsertion); SubscribeLocalEvent<MessagesCartridgeComponent, CartridgeAddedEvent>(OnCartInsertion);
SubscribeLocalEvent<MessagesCartridgeComponent, ComponentRemove>(OnRemove); SubscribeLocalEvent<MessagesCartridgeComponent, ComponentRemove>(OnRemove);
SubscribeLocalEvent<PlayerSpawnCompleteEvent>(OnPlayerSpawned);
} }
public void Send(EntityUid uid, MessagesCartridgeComponent component) private void OnPlayerSpawned(PlayerSpawnCompleteEvent ev)
{ {
var stationId = _stationSystem.GetOwningStation(uid); if (!_inventorySystem.TryGetSlotEntity(ev.Mob, "id", out var pdaUid) || !HasComp<MindContainerComponent>(ev.Mob))
if (!stationId.HasValue || return;
!_singletonServerSystem.TryGetActiveServerAddress<MessagesServerComponent>(stationId.Value, MessagesCartridgeComponent? comp = null;
out var address) || !TryComp(uid, out CartridgeComponent? cartComponent))
var programs = _cartridgeLoaderSystem.GetInstalled(pdaUid.Value);
var program = programs.ToList().Find(program => TryComp(program, out comp));
if (comp == null)
return; return;
component.UserUid = cartComponent.LoaderUid?.Id; if (!TryComp(program, out CartridgeComponent? cartComponent))
SendName(uid, component, cartComponent, address); return;
var stationId = _stationSystem.GetOwningStation(pdaUid);
if (!stationId.HasValue || !_singletonServerSystem.TryGetActiveServerAddress<MessagesServerComponent>(stationId.Value, out var address))
return;
SendName(pdaUid.Value, comp, cartComponent, address);
} }
private void OnRemove(EntityUid uid, MessagesCartridgeComponent component, ComponentRemove args) private void OnRemove(EntityUid uid, MessagesCartridgeComponent component, ComponentRemove args)
@@ -172,7 +187,7 @@ public sealed class MessagesCartridgeSystem : EntitySystem
public void SendName(EntityUid uid, MessagesCartridgeComponent component, CartridgeComponent cartComponent, string? address) public void SendName(EntityUid uid, MessagesCartridgeComponent component, CartridgeComponent cartComponent, string? address)
{ {
TryGetMessagesUser(component, cartComponent, out var messagesUser); TryGetMessagesUser(component, cartComponent, out var messagesUser);
;
var packet = new NetworkPayload() var packet = new NetworkPayload()
{ {
[MessagesNetworkKeys.UserId] = component.UserUid, [MessagesNetworkKeys.UserId] = component.UserUid,

View File

@@ -1,13 +1,9 @@
using System.Linq; using System.Linq;
using Content.Server._White.CartridgeLoader.Cartridges;
using Content.Server._White.Radio.Components; using Content.Server._White.Radio.Components;
using Content.Server.Administration.Logs; using Content.Server.Administration.Logs;
using Content.Server.Chat.Systems; using Content.Server.Chat.Systems;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems; using Content.Server.DeviceNetwork.Systems;
using Content.Server.Station.Systems;
using Content.Shared._White.CartridgeLoader.Cartridges; using Content.Shared._White.CartridgeLoader.Cartridges;
using Content.Shared.CartridgeLoader;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.DeviceNetwork; using Content.Shared.DeviceNetwork;
@@ -18,37 +14,13 @@ public sealed class MessagesServerSystem : EntitySystem
{ {
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!; [Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
[Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!; [Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
[Dependency] private readonly MessagesCartridgeSystem _messagesSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!; [Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly ChatSystem _chat = default!; [Dependency] private readonly ChatSystem _chat = default!;
[Dependency] private readonly StationSystem _stationSystem = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<MessagesServerComponent, DeviceNetworkPacketEvent>(OnPacketReceived); SubscribeLocalEvent<MessagesServerComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
SubscribeLocalEvent<MessagesServerComponent, MapInitEvent>(OnInit);
}
private void OnInit(EntityUid uid, MessagesServerComponent component, MapInitEvent args)
{
if (!TryComp(uid, out DeviceNetworkComponent? device) || !_singletonServerSystem.SetServerActive(uid, true))
return;
_deviceNetworkSystem.ConnectDevice(uid, device);
var stationIdServer = _stationSystem.GetOwningStation(uid);
if (!stationIdServer.HasValue)
return;
var query = EntityQueryEnumerator<MessagesCartridgeComponent>();
while (query.MoveNext(out var entityUid, out var cartridge))
{
var stationId = _stationSystem.GetOwningStation(entityUid);
if (stationId.HasValue && stationIdServer == stationId && TryComp(entityUid, out CartridgeComponent? cartComponent))
_messagesSystem.SendName(entityUid, cartridge, cartComponent, device.Address);
}
} }
/// <summary> /// <summary>

View File

@@ -1,6 +1,6 @@
- type: entity - type: entity
id: MessagesServer id: MessagesServer
parent: BaseMachinePowered parent: BaseMachine
name: PDA messaging server name: PDA messaging server
description: Server that allows PDA messaging to function on the station. description: Server that allows PDA messaging to function on the station.
components: components:
@@ -9,9 +9,6 @@
layers: layers:
- state: server - state: server
- state: variant-research - state: variant-research
- type: ApcPowerReceiver
powerLoad: 200
- type: ExtensionCableReceiver
- type: Destructible - type: Destructible
thresholds: thresholds:
- trigger: - trigger:
@@ -43,11 +40,11 @@
- type: AmbientOnPowered - type: AmbientOnPowered
- type: MessagesServer - type: MessagesServer
- type: SingletonDeviceNetServer - type: SingletonDeviceNetServer
available: true
- type: DeviceNetwork - type: DeviceNetwork
deviceNetId: Wireless deviceNetId: Wireless
transmitFrequencyId: NTMessagesServer transmitFrequencyId: NTMessagesServer
receiveFrequencyId: NTMessagesClient receiveFrequencyId: NTMessagesClient
autoConnect: false
- type: StationLimitedNetwork - type: StationLimitedNetwork
- type: entity - type: entity
@@ -59,5 +56,4 @@
- type: DeviceNetwork - type: DeviceNetwork
deviceNetId: Wireless deviceNetId: Wireless
transmitFrequencyId: SyndicateMessagesServer transmitFrequencyId: SyndicateMessagesServer
receiveFrequencyId: SyndicateMessagesClient receiveFrequencyId: SyndicateMessagesClient
autoConnect: false