Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanopus952 committed Jan 6, 2025
1 parent 1caab60 commit 1891219
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 37 deletions.
55 changes: 25 additions & 30 deletions Content.Server/Access/Systems/AccessSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
using Content.Server.Station.Systems;
using Content.Server.AlertLevel;
using Content.Shared.Station.Components;
namespace Content.Server.Access.Systems;

namespace Content.Server.Access.Systems; //Sunrise-edited

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

public override void Initialize()
Expand All @@ -18,9 +16,12 @@ public override void Initialize()

SubscribeLocalEvent<AlertLevelChangedEvent>(OnAlertLevelChanged);
}

/// <summary>
/// Запускает обновление уровня аварийных доступов на всех сущностях с AccessReaderComponent
/// </summary>
private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
{

if (!TryComp<AlertLevelComponent>(ev.Station, out var alert))
return;

Expand All @@ -30,6 +31,7 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
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;

Expand All @@ -47,9 +49,9 @@ private void OnAlertLevelChanged(AlertLevelChangedEvent ev)
}
}

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

Expand All @@ -62,30 +64,23 @@ public void Update(Entity<AccessReaderComponent> entity)
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"))
var alertLevels = new Dictionary<string, AccessReaderComponent.CurrentAlertLevel>
{
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 // Все остальные доступы
{ "blue", AccessReaderComponent.CurrentAlertLevel.blue },
{ "red", AccessReaderComponent.CurrentAlertLevel.red },
{ "yellow", AccessReaderComponent.CurrentAlertLevel.yellow },
{ "gamma", AccessReaderComponent.CurrentAlertLevel.gamma }
};

entity.Comp.Group = string.Empty; // Значение по умолчанию
foreach (var level in alertLevels)
{
entity.Comp.Group = string.Empty;
if (alerts.CurrentLevel.Contains(level.Key))
{
entity.Comp.AlertAccesses.TryGetValue(level.Value, out var value);
entity.Comp.Group = value;
break;
}
}
}
}
9 changes: 7 additions & 2 deletions Content.Shared/Access/Components/AccessReaderComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,20 @@ public sealed class AccessReaderComponentState : ComponentState

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

public ProtoId<AccessGroupPrototype> Group; // Sunrise-alertAccesses
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, ProtoId<AccessGroupPrototype> group, 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) //Sunrise-edit
{
Enabled = enabled;
DenyTags = denyTags;
Expand Down
11 changes: 9 additions & 2 deletions Content.Shared/Access/Systems/AccessReaderSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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, component.Group,
_recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit);
_recordsSystem.Convert(component.AccessKeys), component.AccessLog, component.AccessLogLimit); // Sunrise-edit
}

private void OnHandleState(EntityUid uid, AccessReaderComponent component, ref ComponentHandleState args)
Expand All @@ -64,7 +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.Group = new(state.Group); // Sunrise-alertAccesses
component.AccessLogLimit = state.AccessLogLimit;
}

Expand Down Expand Up @@ -167,8 +167,10 @@ public bool IsAllowed(
if (!TryComp(entity, out AccessReaderComponent? containedReader))
continue;

// Sunrise-start
if (AreAccessTagsAllowedAlert(access, containedReader))
return true;
// Sunrise-end

if (IsAllowed(access, stationKeys, entity, containedReader))
return true;
Expand Down Expand Up @@ -213,6 +215,10 @@ public bool AreAccessTagsAllowed(ICollection<ProtoId<AccessLevelPrototype>> acce
return false;
}

// Sunrise-start
/// <summary>
/// Сравнивает список аварийных доступов с доступами на карте.
/// </summary>
public bool AreAccessTagsAllowedAlert(ICollection<ProtoId<AccessLevelPrototype>> access, AccessReaderComponent reader)
{
if (reader.Group == string.Empty)
Expand All @@ -234,6 +240,7 @@ public bool AreAccessTagsAllowedAlert(ICollection<ProtoId<AccessLevelPrototype>>

return false;
}
// Sunrise-end

/// <summary>
/// Compares the given stationrecordkeys with the accessreader to see if it is allowed.
Expand Down
13 changes: 10 additions & 3 deletions Resources/Prototypes/_Sunrise/Access/AccessGroup/access_group.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
- type: accessGroup
id: RedAlertAccesses
tags:
- Security
- HeadOfSecurity
- Security
- Armory
- Detective
- Cryogenics

- type: accessGroup
id: BlueAlertAccesses
tags:
- Security
- HeadOfSecurity
- Security
- Armory
- Detective
- Cryogenics

- type: accessGroup
id: YellowAlertAccesses
tags:
- ChiefEngineer
- Engineering
- HeadOfSecurity
- Atmospherics

- type: accessGroup
id: GammaAlertAccesses
Expand Down

0 comments on commit 1891219

Please sign in to comment.