Skip to content

Commit

Permalink
almost ready
Browse files Browse the repository at this point in the history
  • Loading branch information
kanopus952 committed Jan 6, 2025
1 parent 76a93ba commit 1caab60
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 23 deletions.
86 changes: 85 additions & 1 deletion Content.Server/Access/Systems/AccessSystem.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,91 @@
using Content.Shared.Access.Systems;

using Content.Shared.Access.Components;
using Content.Server.Station.Systems;
using Content.Server.AlertLevel;
using Content.Shared.Station.Components;
namespace Content.Server.Access.Systems;

public sealed class AccessSystem : SharedAccessSystem
{
// <summary>
// Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent
// </summary>
[Dependency] private readonly StationSystem _station = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
}

private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
{
if (!TryComp<AlertLevelComponent>(ev.Station, out var alert))
return;

if (alert.AlertLevels == null)
return;

var query = EntityQueryEnumerator<AccessReaderComponent, TransformComponent>();
while (query.MoveNext(out var uid, out var reader, out var xform))
{
if (CompOrNull<StationMemberComponent>(xform.GridUid)?.Station != ev.Station)
continue;

if (alert.AlertLevels == null)
return;

if (!TryComp<AccessReaderComponent>(uid, out var comp))
return;

if (comp.AlertAccesses.Count == 0)
continue;

Update((uid, reader));
Dirty(uid, reader);
}
}

// <summary>
// Устанавливает значение из прототипа в зависимости от кода
// </summary>
public void Update(Entity<AccessReaderComponent> entity)
{

if (!TryComp<AlertLevelComponent>(_station.GetOwningStation(entity.Owner), out var alerts))
return;

if (entity.Comp.AlertAccesses.Count == 0)
return;

if (alerts.AlertLevels == null)
return;

if (alerts.CurrentLevel.Contains("blue"))
{
entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.blue, out var value);
entity.Comp.Group = value;
}
else if (alerts.CurrentLevel.Contains("red"))
{
entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.red, out var value);
entity.Comp.Group = value;
Dirty(entity);
}
else if (alerts.CurrentLevel.Contains("yellow"))
{
entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.yellow, out var value);
entity.Comp.Group = value;
}
else if (alerts.CurrentLevel.Contains("gamma"))
{
entity.Comp.AlertAccesses.TryGetValue(AccessReaderComponent.CurrentAlertLevel.gamma, out var value);
entity.Comp.Group = value;
}
else // Все остальные доступы
{
entity.Comp.Group = string.Empty;
}
}
}
24 changes: 21 additions & 3 deletions Content.Shared/Access/Components/AccessReaderComponent.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Text.RegularExpressions;
using Content.Shared.StationRecords;
using Content.Shared.Weapons.Melee;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Set;
using Robust.Shared.Toolshed.Syntax;

namespace Content.Shared.Access.Components;

Expand All @@ -20,17 +23,29 @@ public sealed partial class AccessReaderComponent : Component
[DataField]
public bool Enabled = true;

// Sunrise-start

/// <summary>
/// Именно от Group происходит проверка аварийных доступов
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("alertAccesses")]
public Dictionary<CurrentAlertLevel, ProtoId<AccessGroupPrototype>> AlertAccesses = new();
[DataField]
public ProtoId<AccessGroupPrototype> Group { get; set; } = string.Empty;

[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public Dictionary<CurrentAlertLevel, ProtoId<AccessGroupPrototype>> AlertAccesses { get; set; } = new();

[Flags]
public enum CurrentAlertLevel : byte
{
blue,
red,
yellow,
gamma
}
// Sunrise-end

/// <summary>
/// The set of tags that will automatically deny an allowed check, if any of them are present.
/// </summary>
Expand Down Expand Up @@ -111,20 +126,23 @@ public sealed class AccessReaderComponentState : ComponentState

public List<HashSet<ProtoId<AccessLevelPrototype>>> AccessLists;

public ProtoId<AccessGroupPrototype> Group; // Sunrise-alertAccesses

public List<(NetEntity, uint)> AccessKeys;

public Queue<AccessRecord> AccessLog;

public int AccessLogLimit;

public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit)
public AccessReaderComponentState(bool enabled, HashSet<ProtoId<AccessLevelPrototype>> denyTags, List<HashSet<ProtoId<AccessLevelPrototype>>> accessLists, ProtoId<AccessGroupPrototype> group, List<(NetEntity, uint)> accessKeys, Queue<AccessRecord> accessLog, int accessLogLimit)
{
Enabled = enabled;
DenyTags = denyTags;
AccessLists = accessLists;
AccessKeys = accessKeys;
AccessLog = accessLog;
AccessLogLimit = accessLogLimit;
Group = group; // Sunrise-alertAccesses
}
}

Expand Down
24 changes: 14 additions & 10 deletions Content.Shared/Access/Systems/AccessReaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void Initialize()

private void OnGetState(EntityUid uid, AccessReaderComponent component, ref ComponentGetState args)
{
args.State = new AccessReaderComponentState(component.Enabled, component.DenyTags, component.AccessLists,
args.State = new AccessReaderComponentState(component.Enabled, component.DenyTags, component.AccessLists, component.Group,
_recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit);
}

Expand All @@ -64,6 +64,7 @@ private void OnHandleState(EntityUid uid, AccessReaderComponent component, ref C
component.AccessLists = new(state.AccessLists);
component.DenyTags = new(state.DenyTags);
component.AccessLog = new(state.AccessLog);
component.Group = new(state.Group);
component.AccessLogLimit = state.AccessLogLimit;
}

Expand Down Expand Up @@ -214,20 +215,23 @@ public bool AreAccessTagsAllowed(ICollection<ProtoId<AccessLevelPrototype>> acce

public bool AreAccessTagsAllowedAlert(ICollection<ProtoId<AccessLevelPrototype>> access, AccessReaderComponent reader)
{
foreach (var (stationCode, alertAccesses) in reader.AlertAccesses)
{
if (!_prototype.TryIndex<AccessGroupPrototype>(alertAccesses, out var accessTags))
return false;
if (reader.Group == string.Empty)
return false;

if (accessTags == null)
return false;
if (!_prototype.TryIndex<AccessGroupPrototype>(reader.Group, out var accessTags))
return false;

if (accessTags.Tags.Count == 0)
return false;
if (accessTags == null)
return false;

if (accessTags.Tags.IsSubsetOf(access))
if (accessTags.Tags.Count == 0)
return false;
foreach (var ent in accessTags.Tags)
{
if (access.Contains(ent))
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@
components:
- type: AccessReader
access: [["Janitor"]]
alertAccesses:
red: RedAlertAccesses
blue: BlueAlertAccesses
yellow: YellowAlertAccesses

- type: entity
parent: DoorElectronics
Expand All @@ -105,6 +109,9 @@
components:
- type: AccessReader
access: [["Service"]]
alertAccess:
red: RedAlertAccesses
yellow: YellowAlertAccesses

# Cargo
- type: entity
Expand Down
22 changes: 13 additions & 9 deletions Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
id: RedAlertAccesses
tags:
- Security
- HeadOfSecurity

- type: accessGroup
id: SecurityBlueAlertAccesses
id: BlueAlertAccesses
tags:
- Maintance
- Security
- HeadOfSecurity

- type: accessGroup
id: SecurityGammaAlertAccesses
id: YellowAlertAccesses
tags:
- Command
- Captain
- HeadOfPersonnel
- Cryogenics
- BlueShield
- Ntrep
- Engineering
- HeadOfSecurity

- type: accessGroup
id: GammaAlertAccesses
tags:
- Security
- HeadOfSecurity

# Потом дополню доступы

0 comments on commit 1caab60

Please sign in to comment.