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

обновление whitelist логики в ui, обновление требований у цк ролей #933

Merged
merged 3 commits into from
Nov 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Client.Players.PlayTimeTracking;
using Content.Shared.Eui;
using Content.Shared.Ghost.Roles;
using Content.Shared.Players.JobWhitelist;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Utility;
Expand Down Expand Up @@ -94,7 +95,7 @@ public override void HandleState(EuiStateBase state)
// TODO: role.Requirements value doesn't work at all as an equality key, this must be fixed
// Grouping roles
var groupedRoles = ghostState.GhostRoles.GroupBy(
role => (role.Name, role.Description, role.Requirements, role.WhitelistRequired)); //backmen: whitelist
role => (role.Name, role.Description, role.Requirements, role.WhitelistRequired, role.DiscordRequired)); //backmen: whitelist

//start-backmen: whitelist
var cfg = IoCManager.Resolve<Robust.Shared.Configuration.IConfigurationManager>();
Expand All @@ -109,15 +110,16 @@ public override void HandleState(EuiStateBase state)
FormattedMessage? reason;

//start-backmen: whitelist
if (
group.Key.WhitelistRequired &&
cfg.GetCVar(Shared.Backmen.CCVar.CCVars.WhitelistRolesEnabled) &&
!requirementsManager.IsWhitelisted()
)
if (group.Key.WhitelistRequired)
{
hasAccess = false;
reason = FormattedMessage.FromMarkupOrThrow(Loc.GetString("playtime-deny-reason-not-whitelisted"));
}
else if (group.Key.DiscordRequired)
{
hasAccess = false;
reason = FormattedMessage.FromMarkupOrThrow(Loc.GetString("playtime-deny-reason-discord"));
}
else
//end-backmen: whitelist
if (!requirementsManager.CheckRoleRequirements(group.Key.Requirements, null, out reason))
Expand Down
39 changes: 34 additions & 5 deletions Content.Server/Backmen/Reinforcement/ReinforcementSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Content.Server.Ghost.Roles.Components;
using Content.Server.Ghost.Roles.Raffles;
using Content.Server.Mind;
using Content.Server.Players.JobWhitelist;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Popups;
using Content.Server.Roles;
Expand Down Expand Up @@ -71,6 +72,8 @@ public sealed class ReinforcementSystem : SharedReinforcementSystem
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly StationJobsSystem _stationJobs = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly GameTicker _ticker = default!;
[Dependency] private readonly JobWhitelistManager _jobWhitelistManager = default!;

public override void Initialize()
{
Expand Down Expand Up @@ -153,7 +156,10 @@ private void OnSpawnPlayer(ReinforcementSpawnPlayer args)
if (station == null)
return;

var character = HumanoidCharacterProfile.Random();
var character = _ticker.GetPlayerProfile(args.Player).Clone();
character.Name = HumanoidCharacterProfile.GetName(character.Species, character.Gender);

//var character = HumanoidCharacterProfile.RandomWithSpecies();
var newMind = _mind.CreateMind(args.Player.UserId, character.Name);
_mind.SetUserId(newMind, args.Player.UserId);

Expand Down Expand Up @@ -206,26 +212,35 @@ private void OnTakeoverTakeRole(Entity<ReinforcementSpawnerComponent> ent, ref T
var row = ent.Comp.Linked.Comp.Members.FirstOrDefault(x => x.Owner == ent.Owner);
if (row == null)
{
ent.Comp.Used = false;
return;
}

var proto = ent.Comp.Linked.Comp.GetById(row.Id, _prototype);
if (proto == null)
{
ent.Comp.Used = false;
return;
}

if (_banManager.GetRoleBans(args.Player.UserId)?.Contains("Job:"+proto.Job) ?? false)
if (_banManager.GetJobBans(args.Player.UserId)?.Contains(proto.Job) ?? false)
{
_popup.PopupCursor(Loc.GetString("role-ban"), args.Player, PopupType.LargeCaution);
ent.Comp.Used = false;
SendChatMsg(args.Player, Loc.GetString("role-ban"));
return;
}

if (!_playTimeTrackings.IsAllowed(args.Player,proto.Job))
{
_popup.PopupCursor(Loc.GetString("role-timer-locked"), args.Player, PopupType.LargeCaution);
ent.Comp.Used = false;
SendChatMsg(args.Player, Loc.GetString("role-timer-locked"));
return;
}

if (!_jobWhitelistManager.IsAllowed(args.Player, proto.Job))
{
ent.Comp.Used = false;
SendChatMsg(args.Player, Loc.GetString("role-not-whitelisted"));
return;
}

Expand Down Expand Up @@ -302,7 +317,9 @@ private void OnStartCall(Entity<ReinforcementConsoleComponent> ent, ref CallRein
ghost.Requirements = new HashSet<JobRequirement>(job.Requirements);
}

ghost.WhitelistRequired = job.Whitelisted;
ghost.JobProto = job.ID;

//ghost.WhitelistRequired = job.Whitelisted;
}

UpdateUserInterface(ent);
Expand Down Expand Up @@ -398,4 +415,16 @@ private void UpdateUserInterface(Entity<ReinforcementConsoleComponent> uid)

_ui.SetUiState(uid.Owner, ReinforcementConsoleKey.Key, msg);
}

private void SendChatMsg(ICommonSession sess, string message)
{
_popup.PopupCursor(message, sess, PopupType.LargeCaution);
_chatManager.ChatMessageToOne(Shared.Chat.ChatChannel.Server,
message,
Loc.GetString("chat-manager-server-wrap-message", ("message", message)),
default,
false,
sess.Channel,
Color.Red);
}
}
27 changes: 26 additions & 1 deletion Content.Server/Ghost/Roles/GhostRoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Content.Shared.Ghost.Roles.Raffles;
using Content.Server.Ghost.Roles.UI;
using Content.Server.Mind.Commands;
using Content.Server.Players.JobWhitelist;
using Content.Shared.Administration;
using Content.Shared.CCVar;
using Content.Shared.Database;
Expand Down Expand Up @@ -54,6 +55,8 @@ public sealed class GhostRoleSystem : EntitySystem
[Dependency] private readonly IPrototypeManager _prototype = default!;

[Dependency] private readonly Backmen.RoleWhitelist.WhitelistSystem _roleWhitelist = default!; // backmen: whitelist
[Dependency] private readonly JobWhitelistManager _wlRole = default!; // backmen: whitelist
[Dependency] private readonly Content.Corvax.Interfaces.Server.IServerDiscordAuthManager _discordAuthManager = default!; // backmen: whitelist

private uint _nextRoleIdentifier;
private bool _needsUpdateGhostRoleCount = true;
Expand Down Expand Up @@ -578,6 +581,27 @@ public GhostRoleInfo[] GetGhostRolesInfo(ICommonSession? player)
? _timing.CurTime.Add(raffle.Countdown)
: TimeSpan.MinValue;

// start-backmen: whitelist
var whitelistRequired = false;
var discordRequired = false;
if (_prototype.TryIndex(role.JobProto, out var job) && player != null)
{
if (role.WhitelistRequired)
{
whitelistRequired = true;
}
else if (!_wlRole.IsAllowed(player, job))
{
whitelistRequired = true;
}

if (_discordAuthManager.IsEnabled && job.DiscordRequired)
{
discordRequired = true;
}
}
// end-backmen: whitelist

roles.Add(new GhostRoleInfo
{
Identifier = id,
Expand All @@ -588,7 +612,8 @@ public GhostRoleInfo[] GetGhostRolesInfo(ICommonSession? player)
Kind = kind,
RafflePlayerCount = rafflePlayerCount,
RaffleEndTime = raffleEndTime,
WhitelistRequired = role.WhitelistRequired // backmen: whitelist
WhitelistRequired = whitelistRequired, // backmen: whitelist
DiscordRequired = discordRequired, // backmen: whitelist
});
}

Expand Down
1 change: 1 addition & 0 deletions Content.Shared/Ghost/Roles/GhostRolesEuiMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public struct GhostRoleInfo
public string Description { get; set; }
public string Rules { get; set; }
public bool WhitelistRequired { get; set; } // backmen: Whitelist
public bool DiscordRequired { get; set; } // backmen: Whitelist

// TODO ROLE TIMERS
// Actually make use of / enforce this requirement?
Expand Down
1 change: 1 addition & 0 deletions Resources/Locale/en-US/backmen/playtime.ftl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
playtime-deny-reason-not-whitelisted = You need be [color=yellow]Whitelist[/color] to keep this role
playtime-deny-reason-discord = You should complete [color=yellow]Discord[/color]-auth to keep this role
ghost-role-whitelist-text = {$num} roles are not shown because they require whitelisting to play.
ghost-role-whitelist-text-one = One role is not shown because it requires whitelisting to play.
1 change: 1 addition & 0 deletions Resources/Locale/ru-RU/backmen/playtime.ftl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
playtime-deny-reason-not-whitelisted = Вам нужно быть в [color=yellow]Whitelist[/color], чтобы взять эту роль
playtime-deny-reason-discord = Вам нужно пройти [color=yellow]Discord[/color] авторизацию, чтобы взять эту роль
ghost-role-whitelist-text = { $num } роли(-ей) не показываются, т.к. вы не в Whitelist
ghost-role-whitelist-text-one = Одна(или больше) ролей не показываются, т.к. вы не в Whitelist
ui-escape-discord = Написать заявку можно в дискорде
1 change: 0 additions & 1 deletion Resources/Maps/centcomm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2728,7 +2728,6 @@ entities:
- type: GasTileOverlay
- type: SpreaderGrid
- type: GridPathfinding
- type: ProtectedGrid
- proto: AcousticGuitarInstrument
entities:
- uid: 1455
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/_Backmen/CentComm/BKCCAssistant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@

- type: entity
name: Ассистент ЦК
suffix: Спавнер, Директор Событий
suffix: Директор Событий
parent: MobHumanCombine
id: MobHumanCMBKCCAssistant
description: ""
components:
- type: Icon
sprite: Markers/jobs.rsi
Expand Down
3 changes: 2 additions & 1 deletion Resources/Prototypes/_Backmen/CentComm/BKCCCargo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
suffix: Директор Событий
parent: MobHumanCombine
id: MobHumanCMBKCCCargo
description: ""
components:
- type: Icon
sprite: Markers/jobs.rsi
Expand All @@ -55,7 +56,7 @@
factions:
- CentralCommand
- type: Loadout
prototypes: [CCCargo]
prototypes: [CCCargoFull]
- type: RandomHumanoidAppearance
randomizeName: true
- type: AntagImmune
2 changes: 1 addition & 1 deletion Resources/Prototypes/_Backmen/CentComm/BKCCOperator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
name: Оператор ЦК
suffix: Директор Событий
parent: MobHumanCombine
description: Офисный клерк.
description: Офисный клерк
id: MobHumanCMBKCCOperator
components:
- type: Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
shoes: ClothingShoesColorBlack
head: ClothingHeadHatCargosoft

- type: startingGear
id: CCCargoFull
equipment:
id: CCCargoPDA
ears: ClothingHeadsetCentCom
pocket1: AppraisalTool
shoes: ClothingShoesColorBlack
head: ClothingHeadHatCargosoft
jumpsuit: ClothingUniformJumpsuitCargo
neck: ClothingNeckCloakCap
back: ClothingBackpack


# Jumpsuit
- type: loadout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
requireAdminNotify: true
joinNotifyCrew: true
whitelisted: true
discordRequired: true
requirements:
- !type:RoleTimeRequirement
role: JobHeadOfSecurity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
weight: 1
requireAdminNotify: true
joinNotifyCrew: true
discordRequired: true
requirements:
- !type:DepartmentTimeRequirement
department: Cargo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
requireAdminNotify: true
joinNotifyCrew: true
whitelisted: true
discordRequired: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the script results, I can now generate the final response since I have enough information to verify the concern:

Discord requirement missing in several Central Command roles

The following Central Command role files need the discordRequired: true field added to align with the PR objectives:

  • Resources/Prototypes/_Backmen/Roles/Jobs/CentCom/operator.yml
  • Resources/Prototypes/_Backmen/Roles/Jobs/CentCom/blueshield.yml
  • Resources/Prototypes/_Backmen/Roles/Jobs/CentCom/head_of_security.yml
  • Resources/Prototypes/_Backmen/Roles/Jobs/CentCom/cargotech.yml
🔗 Analysis chain

LGTM! Verify Discord requirement across all Central Command roles.

Adding Discord authorization requirement for the Admiral role is appropriate given its high-privilege access groups and special capabilities.

Let's verify that all Central Command roles have the Discord requirement:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if all Central Command role configurations have discordRequired set to true

# Search for job definitions in Central Command role files
rg -U --multiline '(?s)- type: job.*?^[^ -]' Resources/Prototypes/_Backmen/Roles/Jobs/CentCom/ | while read -r job; do
    if ! echo "$job" | rg -q "discordRequired: true"; then
        echo "WARNING: Missing Discord requirement in job definition:"
        echo "$job"
        echo "---"
    fi
done

Length of output: 161927

requirements:
- !type:RoleTimeRequirement
role: JobCentralCommandOperator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
requireAdminNotify: true
joinNotifyCrew: true
whitelisted: true
discordRequired: true
requirements:
- !type:DepartmentTimeRequirement
department: CentCom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
requireAdminNotify: true
joinNotifyCrew: true
whitelisted: true
discordRequired: true
requirements:
- !type:RoleTimeRequirement
role: JobCentralCommandAssistant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
weight: 1
requireAdminNotify: true
joinNotifyCrew: true
discordRequired: true
requirements:
- !type:DepartmentTimeRequirement
department: Engineering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
requireAdminNotify: true
joinNotifyCrew: true
whitelisted: true
discordRequired: true
requirements:
- !type:RoleTimeRequirement
role: JobCentralCommandAssistant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
weight: 1
requireAdminNotify: true
joinNotifyCrew: true
discordRequired: true
Rxup marked this conversation as resolved.
Show resolved Hide resolved
requirements:
- !type:DepartmentTimeRequirement
department: Security
Expand Down
Loading