mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Scope creep my ass * why was this shit not pushed???? * gone... * fix that * review plus buildd * asfsafsafsafsafas * grug * burber * I'll fix this later * shrimply die * also this * it's snerf or snuthin * assaads * round snend * aaaa * fix this shit for real * actually, don't start GameRules until MapInit now that I think aboot it. * forgot u * don't actually need this part nullable * Deffer comp removal * one liner * do that too * chungus * Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?) * deferred removal :V * aaaaaaaaaaaaaaa * whhop * Whoop * better * landmine that I placed for myself then forgot about lmao * cleanup * FUCKING `!` * gotovo * amogus * please don't check by metadata I beg * waawsasfdfsasfa * sfafsasfafsas * fdsaasffsasfa * code * fix * fasasffasfasfsad * chungaas * I may be stupid * gra * graaaaaaaaaaaaaaaaa * comment * gra * clearing is not predicted and would require major refactors, so don't cache on client. * lame shit :P * last holes * nukeopsfsafsasafsfafsa * why was that shit public bruh * bubrbgwahrghfaka * dynamic * revert change that did nothing lmao
88 lines
3.4 KiB
C#
88 lines
3.4 KiB
C#
using Content.Server.DeviceNetwork.Components;
|
|
using Content.Server.Station.Systems;
|
|
using Content.Shared.DeviceNetwork.Events;
|
|
using JetBrains.Annotations;
|
|
|
|
namespace Content.Server.DeviceNetwork.Systems
|
|
{
|
|
/// <summary>
|
|
/// This system requires the StationLimitedNetworkComponent to be on the the sending entity as well as the receiving entity
|
|
/// </summary>
|
|
[UsedImplicitly]
|
|
public sealed partial class StationLimitedNetworkSystem : EntitySystem
|
|
{
|
|
[Dependency] private ServerStationSystem _stationSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<StationLimitedNetworkComponent, MapInitEvent>(OnMapInit);
|
|
SubscribeLocalEvent<StationLimitedNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets the station id the device is limited to.
|
|
/// </summary>
|
|
public void SetStation(EntityUid uid, EntityUid? stationId, StationLimitedNetworkComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component))
|
|
return;
|
|
|
|
component.StationId = stationId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tries to set the station id to the current station if the device is currently on a station
|
|
/// </summary>
|
|
public bool TrySetStationId(EntityUid uid, StationLimitedNetworkComponent? component = null)
|
|
{
|
|
if (!Resolve(uid, ref component) || !Transform(uid).GridUid.HasValue)
|
|
return false;
|
|
|
|
component.StationId = _stationSystem.GetOwningStation(uid);
|
|
return component.StationId.HasValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Set the station id to the one the entity is on when the station limited component is added
|
|
/// </summary>
|
|
private void OnMapInit(EntityUid uid, StationLimitedNetworkComponent networkComponent, MapInitEvent args)
|
|
{
|
|
networkComponent.StationId = _stationSystem.GetOwningStation(uid);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if both devices are limited to the same station
|
|
/// </summary>
|
|
private void OnBeforePacketSent(Entity<StationLimitedNetworkComponent> ent, ref BeforePacketSentEvent args)
|
|
{
|
|
var (uid, component) = ent;
|
|
if (!component.StationId.HasValue)
|
|
TrySetStationId(uid, component);
|
|
|
|
if (!CheckStationId(args.Sender, component.AllowNonStationPackets, component.StationId))
|
|
{
|
|
args.Cancelled = true;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Compares the station IDs of the sending and receiving network components.
|
|
/// Returns false if either of them doesn't have a station ID or if their station ID isn't equal.
|
|
/// Returns true even when the sending entity isn't tied to a station if `allowNonStationPackets` is set to true.
|
|
/// </summary>
|
|
private bool CheckStationId(EntityUid senderUid, bool allowNonStationPackets, EntityUid? receiverStationId, StationLimitedNetworkComponent? sender = null)
|
|
{
|
|
if (!receiverStationId.HasValue)
|
|
return false;
|
|
|
|
if (!Resolve(senderUid, ref sender, false))
|
|
return allowNonStationPackets;
|
|
|
|
if (!sender.StationId.HasValue)
|
|
TrySetStationId(senderUid, sender);
|
|
|
|
return sender.StationId == receiverStationId;
|
|
}
|
|
}
|
|
}
|