# Conflicts: # .github/CODEOWNERS # .github/ISSUE_TEMPLATE/config.yml # .github/ISSUE_TEMPLATE/issue_report.md # Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs # Content.Client/Medical/CrewMonitoring/CrewMonitoringWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml # Content.Client/UserInterface/Systems/Ghost/Controls/Roles/MakeGhostRoleWindow.xaml.cs # Content.Client/Weapons/Ranged/Systems/GunSystem.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageGroupTest.cs # Content.IntegrationTests/Tests/Destructible/DestructibleDamageTypeTest.cs # Content.Server/Administration/Systems/AdminVerbSystem.Smites.cs # Content.Server/Arcade/SpaceVillainGame/SpaceVillainArcadeComponent.cs # Content.Server/Atmos/EntitySystems/FlammableSystem.cs # Content.Server/Chat/Systems/ChatSystem.cs # Content.Server/Destructible/Thresholds/DamageThreshold.cs # Content.Server/Entry/EntryPoint.cs # Content.Server/Fluids/EntitySystems/PuddleSystem.cs # Content.Server/GuideGenerator/ReagentEntry.cs # Content.Server/IoC/ServerContentIoC.cs # Content.Server/Medical/HealthAnalyzerSystem.cs # Content.Server/Medical/VomitSystem.cs # Content.Server/Radio/EntitySystems/HeadsetSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.cs # Content.Server/Weapons/Ranged/Systems/GunSystem.cs # Content.Shared/Armor/SharedArmorSystem.cs # Content.Shared/Bed/Sleep/SleepingSystem.cs # Content.Shared/Cabinet/ItemCabinetSystem.cs # Content.Shared/Chat/SharedChatSystem.Emote.cs # Content.Shared/Chat/SharedChatSystem.cs # Content.Shared/Clothing/EntitySystems/MaskSystem.cs # Content.Shared/Clothing/EntitySystems/SharedChameleonClothingSystem.cs # Content.Shared/Damage/Systems/DamageableSystem.cs # Content.Shared/EntityEffects/Effects/StatusEffects/GenericStatusEffect.cs # Content.Shared/EntityEffects/Effects/Transform/ExplosionEntityEffect.cs # Content.Shared/Humanoid/HumanoidCharacterAppearance.cs # Content.Shared/IoC/SharedContentIoC.cs # Content.Shared/Lock/LockSystem.cs # Content.Shared/Ninja/Components/NinjaSuitComponent.cs # Content.Shared/Preferences/HumanoidCharacterProfile.cs # Content.Shared/Revenant/Components/RevenantComponent.cs # Content.Shared/Silicons/StationAi/SharedStationAiSystem.Airlock.cs # Content.Shared/Trigger/Systems/TriggerSystem.Condition.cs # Content.Shared/VendingMachines/SharedVendingMachineSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/Weapons/Ranged/HitscanPrototype.cs # Content.Shared/Xenoarchaeology/Artifact/XAT/BaseQueryUpdateXATSystem.cs # README.md # Resources/Audio/Weapons/attributions.yml # Resources/Locale/en-US/_strings/ghost/make-ghost-gui.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/_strings/guidebook/chemistry/statuseffects.ftl # Resources/Locale/en-US/_strings/job/job-description.ftl # Resources/Locale/en-US/_strings/medical/components/crew-monitoring-component.ftl # Resources/Locale/en-US/_strings/npc/hugbot.ftl # Resources/Locale/en-US/_strings/npc/npc-debug.ftl # Resources/Locale/en-US/_strings/speech/speech-triggers.ftl # Resources/Locale/en-US/_strings/ui/stat-values.ftl # Resources/Locale/en-US/guidebook/chemistry/conditions.ftl # Resources/Locale/en-US/guidebook/chemistry/effects.ftl # Resources/Locale/en-US/guidebook/chemistry/healthchange.ftl # Resources/Locale/en-US/guidebook/entity-effects/conditions.ftl # Resources/Locale/en-US/guidebook/entity-effects/effects.ftl # Resources/Locale/en-US/guidebook/entity-effects/healthchange.ftl # Resources/Maps/Shuttles/cargo_relic.yml # Resources/Maps/_Sunrise/Station/bagel.yml # Resources/Maps/_Sunrise/Station/barratry.yml # Resources/Maps/_Sunrise/Station/fland.yml # Resources/Maps/_Sunrise/Station/marathon.yml # Resources/Maps/_Sunrise/Station/oasis.yml # Resources/Maps/_Sunrise/Station/packed.yml # Resources/Maps/_Sunrise/Station/plasma.yml # Resources/Maps/_Sunrise/Station/relic.yml # Resources/Maps/_Sunrise/event/clon_mine.yml # Resources/Maps/_Sunrise/event/void.yml # Resources/Prototypes/Body/Prototypes/vox.yml # Resources/Prototypes/Catalog/Fills/Boxes/emergency.yml # Resources/Prototypes/Catalog/Fills/Crates/fun.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/security.yml # Resources/Prototypes/Entities/Clothing/Belt/belts.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/suits.yml # Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml # Resources/Prototypes/Entities/Mobs/Species/skeleton.yml # Resources/Prototypes/Entities/Objects/Devices/Electronics/base_electronics.yml # Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Cartridges/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Ammunition/Magazines/pistol.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Battery/battery_guns.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/hitscan.yml # Resources/Prototypes/Entities/Objects/Weapons/Guns/Projectiles/projectiles.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/access.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/airlocks.yml # Resources/Prototypes/Entities/Structures/Doors/MaterialDoors/material_doors.yml # Resources/Prototypes/Entities/Structures/Machines/lathe.yml # Resources/Prototypes/Entities/Structures/Specific/Atmospherics/sensor.yml # Resources/Prototypes/Loadouts/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Loadouts/Jobs/Science/scientist.yml # Resources/Prototypes/Loadouts/Jobs/Security/security_officer.yml # Resources/Prototypes/Loadouts/Miscellaneous/glasses.yml # Resources/Prototypes/Loadouts/loadout_groups.yml # Resources/Prototypes/Objectives/objectiveGroups.yml # Resources/Prototypes/Reagents/Consumable/Drink/alcohol.yml # Resources/Prototypes/Reagents/medicine.yml # Resources/Prototypes/Reagents/narcotics.yml # Resources/Prototypes/Reagents/toxins.yml # Resources/Prototypes/Recipes/Lathes/Packs/biogen.yml # Resources/Prototypes/Recipes/Lathes/Packs/security.yml # Resources/Prototypes/Recipes/Lathes/biogen.yml # Resources/Prototypes/Roles/Antags/nukeops.yml # Resources/Prototypes/Roles/Antags/revolutionary.yml # Resources/Prototypes/Roles/Antags/thief.yml # Resources/Prototypes/Roles/Antags/traitor.yml # Resources/Prototypes/Roles/Antags/wizard.yml # Resources/Prototypes/Roles/Antags/zombie.yml # Resources/Prototypes/Roles/Jobs/Cargo/salvage_specialist.yml # Resources/Prototypes/Roles/Jobs/Civilian/bartender.yml # Resources/Prototypes/Roles/Jobs/Civilian/chef.yml # Resources/Prototypes/Roles/Jobs/Civilian/mime.yml # Resources/Prototypes/Roles/Jobs/Engineering/atmospheric_technician.yml # Resources/Prototypes/Roles/Jobs/Engineering/station_engineer.yml # Resources/Prototypes/Roles/Jobs/Engineering/technical_assistant.yml # Resources/Prototypes/Roles/Jobs/Medical/chemist.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_doctor.yml # Resources/Prototypes/Roles/Jobs/Medical/medical_intern.yml # Resources/Prototypes/Roles/Jobs/Medical/paramedic.yml # Resources/Prototypes/Roles/Jobs/Science/borg.yml # Resources/Prototypes/Roles/Jobs/Science/research_assistant.yml # Resources/Prototypes/Roles/Jobs/Science/scientist.yml # Resources/Prototypes/Roles/Jobs/Security/security_cadet.yml # Resources/Prototypes/Roles/Jobs/Security/security_officer.yml # Resources/Prototypes/Roles/Jobs/Security/warden.yml # Resources/Prototypes/Stacks/Materials/crystals.yml # Resources/Prototypes/Stacks/floor_tile_stacks.yml # Resources/Prototypes/tags.yml # Resources/ServerInfo/Guidebook/Science/ArtifactReports.xml # Resources/ServerInfo/Guidebook/Science/Xenoarchaeology.xml # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/equipped-HAND.png # Resources/Textures/Clothing/Hands/Gloves/Color/black.rsi/meta.json # Resources/Textures/Clothing/Head/Hardsuits/mime.rsi/meta.json # Resources/Textures/Effects/speech.rsi/moth3.png # Resources/Textures/Interface/Misc/job_icons.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/meta.json # Resources/Textures/Structures/Machines/microwave.rsi/mw.png # Resources/Textures/Structures/Machines/microwave.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody0.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloody1.png # Resources/Textures/Structures/Machines/microwave.rsi/mwbloodyo.png # Resources/Textures/Structures/Machines/microwave.rsi/mwo.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/meta.json # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw0.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_running_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mw_unlit.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwb.png # Resources/Textures/Structures/Machines/microwave_syndie.rsi/mwo.png # Resources/migration.yml # RobustToolbox
671 lines
24 KiB
C#
671 lines
24 KiB
C#
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
using System.Numerics;
|
|
using Content.Client.Administration.UI.CustomControls;
|
|
using Content.Shared.Administration;
|
|
using Content.Shared.CCVar;
|
|
using Content.Shared.Database;
|
|
using Content.Shared.Roles;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.Graphics;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Configuration;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Timing;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client.Administration.UI.BanPanel;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class BanPanel : DefaultWindow
|
|
{
|
|
public event Action<Ban>? BanSubmitted;
|
|
public event Action<string>? PlayerChanged;
|
|
private string? PlayerUsername { get; set; }
|
|
private (IPAddress, int)? IpAddress { get; set; }
|
|
private ImmutableTypedHwid? Hwid { get; set; }
|
|
private double TimeEntered { get; set; }
|
|
private uint Multiplier { get; set; }
|
|
private bool HasBanFlag { get; set; }
|
|
private TimeSpan? ButtonResetOn { get; set; }
|
|
|
|
// This is less efficient than just holding a reference to the root control and enumerating children, but you
|
|
// have to know how the controls are nested, which makes the code more complicated.
|
|
// Role group name -> the role buttons themselves.
|
|
private readonly Dictionary<string, List<(Button, IPrototype)>> _roleCheckboxes = new();
|
|
private readonly ISawmill _banPanelSawmill;
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
|
[Dependency] private readonly ILogManager _logManager = default!;
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
[Dependency] private readonly IPrototypeManager _protoMan = default!;
|
|
|
|
private const string ExpandedArrow = "▼";
|
|
private const string ContractedArrow = "▶";
|
|
|
|
private readonly string _antagCategory = Loc.GetString("ban-panel-role-selection-antag");
|
|
private readonly string _antagAllSelection = Loc.GetString("ban-panel-role-selection-antag-all-option");
|
|
|
|
private enum TabNumbers
|
|
{
|
|
BasicInfo,
|
|
//Text,
|
|
Players,
|
|
Roles
|
|
}
|
|
|
|
private enum Multipliers
|
|
{
|
|
Minutes,
|
|
Hours,
|
|
Days,
|
|
Weeks,
|
|
Months,
|
|
Years,
|
|
Permanent
|
|
}
|
|
|
|
private enum Types
|
|
{
|
|
None,
|
|
Server,
|
|
Role
|
|
}
|
|
|
|
public BanPanel()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
_banPanelSawmill = _logManager.GetSawmill("admin.banpanel");
|
|
PlayerList.OnSelectionChanged += OnPlayerSelectionChanged;
|
|
PlayerNameLine.OnFocusExit += _ => OnPlayerNameChanged();
|
|
PlayerCheckbox.OnPressed += _ =>
|
|
{
|
|
PlayerNameLine.Editable = PlayerCheckbox.Pressed;
|
|
PlayerNameLine.ModulateSelfOverride = null;
|
|
};
|
|
TimeLine.OnTextChanged += OnMinutesChanged;
|
|
MultiplierOption.OnItemSelected += args =>
|
|
{
|
|
MultiplierOption.SelectId(args.Id);
|
|
OnMultiplierChanged();
|
|
};
|
|
IpLine.OnFocusExit += _ => OnIpChanged();
|
|
IpCheckbox.OnPressed += _ =>
|
|
{
|
|
IpLine.Editable = IpCheckbox.Pressed;
|
|
OnIpChanged();
|
|
};
|
|
HwidLine.OnFocusExit += _ => OnHwidChanged();
|
|
HwidCheckbox.OnPressed += _ =>
|
|
{
|
|
HwidLine.Editable = HwidCheckbox.Pressed;
|
|
OnHwidChanged();
|
|
};
|
|
TypeOption.OnItemSelected += args =>
|
|
{
|
|
TypeOption.SelectId(args.Id);
|
|
OnTypeChanged();
|
|
};
|
|
LastConnCheckbox.OnPressed += _ =>
|
|
{
|
|
IpLine.ModulateSelfOverride = null;
|
|
HwidLine.ModulateSelfOverride = null;
|
|
OnIpChanged();
|
|
OnHwidChanged();
|
|
};
|
|
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
|
|
|
|
IpCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanIpBanDefault);
|
|
HwidCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanHwidBanDefault);
|
|
LastConnCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanUseLastDetails);
|
|
EraseCheckbox.Pressed = _cfg.GetCVar(CCVars.ServerBanErasePlayer);
|
|
|
|
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-none"), (int) NoteSeverity.None);
|
|
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-low"), (int) NoteSeverity.Minor);
|
|
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-medium"), (int) NoteSeverity.Medium);
|
|
SeverityOption.AddItem(Loc.GetString("admin-note-editor-severity-high"), (int) NoteSeverity.High);
|
|
SeverityOption.SelectId((int) NoteSeverity.Medium);
|
|
SeverityOption.OnItemSelected += args => SeverityOption.SelectId(args.Id);
|
|
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-minutes"), (int) Multipliers.Minutes);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-hours"), (int) Multipliers.Hours);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-days"), (int) Multipliers.Days);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-weeks"), (int) Multipliers.Weeks);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-months"), (int) Multipliers.Months);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-years"), (int) Multipliers.Years);
|
|
MultiplierOption.AddItem(Loc.GetString("ban-panel-permanent"), (int) Multipliers.Permanent);
|
|
MultiplierOption.SelectId((int) Multipliers.Minutes);
|
|
OnMultiplierChanged();
|
|
|
|
Tabs.SetTabTitle((int) TabNumbers.BasicInfo, Loc.GetString("ban-panel-tabs-basic"));
|
|
//Tabs.SetTabTitle((int) TabNumbers.Text, Loc.GetString("ban-panel-tabs-reason"));
|
|
Tabs.SetTabTitle((int) TabNumbers.Players, Loc.GetString("ban-panel-tabs-players"));
|
|
Tabs.SetTabTitle((int) TabNumbers.Roles, Loc.GetString("ban-panel-tabs-role"));
|
|
Tabs.SetTabVisible((int) TabNumbers.Roles, false);
|
|
|
|
TypeOption.AddItem(Loc.GetString("ban-panel-select"), (int) Types.None);
|
|
TypeOption.AddItem(Loc.GetString("ban-panel-server"), (int) Types.Server);
|
|
TypeOption.AddItem(Loc.GetString("ban-panel-role"), (int) Types.Role);
|
|
|
|
|
|
|
|
ReasonTextEdit.Placeholder = new Rope.Leaf(Loc.GetString("ban-panel-reason"));
|
|
|
|
var departmentJobs = _protoMan.EnumeratePrototypes<DepartmentPrototype>()
|
|
.OrderBy(x => x.Weight);
|
|
foreach (var proto in departmentJobs)
|
|
{
|
|
var roles = proto.Roles.Select(x => _protoMan.Index(x))
|
|
.OrderBy(x => x.ID);
|
|
CreateRoleGroup(proto.ID, proto.Color, roles);
|
|
}
|
|
|
|
var antagRoles = _protoMan.EnumeratePrototypes<AntagPrototype>()
|
|
.OrderBy(x => x.ID);
|
|
CreateRoleGroup(AntagPrototype.GroupName, AntagPrototype.GroupColor, antagRoles);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates a "Role group" which stores information and logic for one "group" of roll bans.
|
|
/// For example, all antags are one group, logi is a group, medical is a group, etc...
|
|
/// </summary>
|
|
private void CreateRoleGroup<T>(string groupName, Color color, IEnumerable<T> roles) where T : class, IPrototype
|
|
{
|
|
var outerContainer = new BoxContainer
|
|
{
|
|
Name = $"{groupName}GroupOuterBox",
|
|
HorizontalExpand = true,
|
|
VerticalExpand = true,
|
|
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
|
Margin = new Thickness(4),
|
|
};
|
|
|
|
// Stores stuff like ban all and expand buttons.
|
|
var roleGroupHeader = new BoxContainer
|
|
{
|
|
Orientation = BoxContainer.LayoutOrientation.Horizontal,
|
|
};
|
|
|
|
// Stores the role checkboxes themselves.
|
|
var innerContainer = new GridContainer
|
|
{
|
|
Name = $"{groupName}GroupInnerBox",
|
|
HorizontalExpand = true,
|
|
Columns = 2,
|
|
Visible = false,
|
|
Margin = new Thickness(15, 5, 0, 5),
|
|
};
|
|
|
|
var roleGroupCheckbox = CreateRoleGroupHeader(groupName, roleGroupHeader, color, innerContainer);
|
|
|
|
outerContainer.AddChild(roleGroupHeader);
|
|
|
|
// Add the roles themselves
|
|
foreach (var role in roles)
|
|
{
|
|
AddRoleCheckbox(groupName, role.ID, innerContainer, roleGroupCheckbox);
|
|
}
|
|
|
|
outerContainer.AddChild(innerContainer);
|
|
|
|
RolesContainer.AddChild(new PanelContainer
|
|
{
|
|
PanelOverride = new StyleBoxFlat
|
|
{
|
|
BackgroundColor = color
|
|
}
|
|
});
|
|
RolesContainer.AddChild(outerContainer);
|
|
RolesContainer.AddChild(new HSeparator());
|
|
}
|
|
|
|
private Button CreateRoleGroupHeader(string groupName, BoxContainer header, Color color, GridContainer innerContainer)
|
|
{
|
|
var roleGroupCheckbox = new Button
|
|
{
|
|
Name = $"{groupName}GroupCheckbox",
|
|
Text = Loc.GetString("role-bans-ban-group"),
|
|
Margin = new Thickness(0, 0, 5, 0),
|
|
ToggleMode = true,
|
|
};
|
|
|
|
// When this is toggled, toggle all buttons in this group so they match.
|
|
roleGroupCheckbox.OnToggled += args =>
|
|
{
|
|
foreach (var role in _roleCheckboxes[groupName])
|
|
{
|
|
role.Item1.Pressed = args.Pressed;
|
|
}
|
|
|
|
if (args.Pressed)
|
|
{
|
|
if (!Enum.TryParse(_cfg.GetCVar(CCVars.DepartmentBanDefaultSeverity), true, out NoteSeverity newSeverity))
|
|
{
|
|
_banPanelSawmill
|
|
.Warning("Departmental role ban severity could not be parsed from config!");
|
|
return;
|
|
}
|
|
SeverityOption.SelectId((int)newSeverity);
|
|
}
|
|
else
|
|
{
|
|
foreach (var roleButtons in _roleCheckboxes.Values)
|
|
{
|
|
foreach (var button in roleButtons)
|
|
{
|
|
if (button.Item1.Pressed)
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (!Enum.TryParse(_cfg.GetCVar(CCVars.RoleBanDefaultSeverity), true, out NoteSeverity newSeverity))
|
|
{
|
|
_banPanelSawmill
|
|
.Warning("Role ban severity could not be parsed from config!");
|
|
return;
|
|
}
|
|
SeverityOption.SelectId((int)newSeverity);
|
|
}
|
|
};
|
|
|
|
var hideButton = new Button
|
|
{
|
|
Text = Loc.GetString("role-bans-expand-roles") + " " + ContractedArrow,
|
|
ToggleMode = true,
|
|
};
|
|
hideButton.OnPressed += args =>
|
|
{
|
|
innerContainer.Visible = args.Button.Pressed;
|
|
((Button)args.Button).Text = args.Button.Pressed
|
|
? Loc.GetString("role-bans-contract-roles") + " " + ExpandedArrow
|
|
: Loc.GetString("role-bans-expand-roles") + " " + ContractedArrow;
|
|
};
|
|
header.AddChild(new Label
|
|
{
|
|
Text = groupName,
|
|
Modulate = color,
|
|
Margin = new Thickness(0, 0, 5, 0),
|
|
});
|
|
header.AddChild(roleGroupCheckbox);
|
|
header.AddChild(hideButton);
|
|
return roleGroupCheckbox;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a check button specifically for one "role" in a "group"
|
|
/// E.g. it would add the Chief Medical Officer "role" into the "Medical" group.
|
|
/// </summary>
|
|
private void AddRoleCheckbox(string group, string role, GridContainer roleGroupInnerContainer, Button roleGroupCheckbox)
|
|
{
|
|
var roleCheckboxContainer = new BoxContainer();
|
|
var roleCheckButton = new Button
|
|
{
|
|
Name = role,
|
|
Text = role,
|
|
ToggleMode = true,
|
|
};
|
|
roleCheckButton.OnToggled += args =>
|
|
{
|
|
// Checks the role group checkbox if all the children are pressed
|
|
if (args.Pressed && _roleCheckboxes[group].All(e => e.Item1.Pressed))
|
|
roleGroupCheckbox.Pressed = args.Pressed;
|
|
else
|
|
roleGroupCheckbox.Pressed = false;
|
|
};
|
|
|
|
IPrototype rolePrototype;
|
|
|
|
if (_protoMan.TryIndex<JobPrototype>(role, out var jobPrototype))
|
|
rolePrototype = jobPrototype;
|
|
else if (_protoMan.TryIndex<AntagPrototype>(role, out var antagPrototype))
|
|
rolePrototype = antagPrototype;
|
|
else
|
|
{
|
|
_banPanelSawmill.Error($"Adding a role checkbox for role {role}: role is not a JobPrototype or AntagPrototype.");
|
|
|
|
return;
|
|
}
|
|
|
|
// This is adding the icon before the role name
|
|
// TODO: This should not be using raw strings for prototypes as it means it won't be validated at all.
|
|
// // I know the ban manager is doing the same thing, but that should not leak into UI code.
|
|
if (jobPrototype is not null && _protoMan.TryIndex(jobPrototype.Icon, out var iconProto))
|
|
{
|
|
var jobIconTexture = new TextureRect
|
|
{
|
|
Texture = _entMan.System<SpriteSystem>().Frame0(iconProto.Icon),
|
|
TextureScale = new Vector2(2.5f, 2.5f),
|
|
Stretch = TextureRect.StretchMode.KeepCentered,
|
|
Margin = new Thickness(5, 0, 0, 0),
|
|
};
|
|
roleCheckboxContainer.AddChild(jobIconTexture);
|
|
}
|
|
|
|
roleCheckboxContainer.AddChild(roleCheckButton);
|
|
|
|
roleGroupInnerContainer.AddChild(roleCheckboxContainer);
|
|
|
|
_roleCheckboxes.TryAdd(group, []);
|
|
_roleCheckboxes[group].Add((roleCheckButton, rolePrototype));
|
|
}
|
|
|
|
public void UpdateBanFlag(bool newFlag)
|
|
{
|
|
HasBanFlag = newFlag;
|
|
SubmitButton.Visible = HasBanFlag;
|
|
ModulateSelfOverride = HasBanFlag ? Color.Red : null;
|
|
}
|
|
|
|
public void UpdatePlayerData(string playerName)
|
|
{
|
|
if (string.IsNullOrEmpty(playerName))
|
|
{
|
|
PlayerNameLine.ModulateSelfOverride = Color.Red;
|
|
ErrorLevel |= ErrorLevelEnum.PlayerName;
|
|
UpdateSubmitEnabled();
|
|
return;
|
|
}
|
|
PlayerNameLine.ModulateSelfOverride = null;
|
|
ErrorLevel &= ~ErrorLevelEnum.PlayerName;
|
|
UpdateSubmitEnabled();
|
|
PlayerUsername = playerName;
|
|
PlayerNameLine.Text = playerName;
|
|
}
|
|
|
|
[Flags]
|
|
private enum ErrorLevelEnum : byte
|
|
{
|
|
None = 0,
|
|
Minutes = 1 << 0,
|
|
PlayerName = 1 << 1,
|
|
IpAddress = 1 << 2,
|
|
Hwid = 1 << 3,
|
|
}
|
|
|
|
private ErrorLevelEnum ErrorLevel { get; set; }
|
|
|
|
private void OnMinutesChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
TimeLine.Text = args.Text;
|
|
if (!double.TryParse(args.Text, out var result))
|
|
{
|
|
ExpiresLabel.Text = Loc.GetString("ban-panel-expiry-error");
|
|
ErrorLevel |= ErrorLevelEnum.Minutes;
|
|
TimeLine.ModulateSelfOverride = Color.Red;
|
|
UpdateSubmitEnabled();
|
|
return;
|
|
}
|
|
|
|
ErrorLevel &= ~ErrorLevelEnum.Minutes;
|
|
TimeLine.ModulateSelfOverride = null;
|
|
TimeEntered = result;
|
|
UpdateSubmitEnabled();
|
|
UpdateExpiresLabel();
|
|
}
|
|
|
|
private void OnMultiplierChanged()
|
|
{
|
|
TimeLine.Editable = MultiplierOption.SelectedId != (int) Multipliers.Permanent;
|
|
Multiplier = MultiplierOption.SelectedId switch
|
|
{
|
|
(int) Multipliers.Minutes => 1,
|
|
(int) Multipliers.Hours => 60,
|
|
(int) Multipliers.Days => 60 * 24,
|
|
(int) Multipliers.Weeks => 60 * 24 * 7,
|
|
(int) Multipliers.Months => 60 * 24 * 30,
|
|
(int) Multipliers.Years => 60 * 24 * 365,
|
|
(int) Multipliers.Permanent => 0,
|
|
_ => throw new ArgumentOutOfRangeException(nameof(MultiplierOption.SelectedId), "Multiplier out of range")
|
|
};
|
|
UpdateExpiresLabel();
|
|
}
|
|
|
|
private void UpdateExpiresLabel()
|
|
{
|
|
var minutes = (uint) (TimeEntered * Multiplier);
|
|
ExpiresLabel.Text = minutes == 0
|
|
? $"{Loc.GetString("admin-note-editor-expiry-label")} {Loc.GetString("server-ban-string-never")}"
|
|
: $"{Loc.GetString("admin-note-editor-expiry-label")} {DateTime.Now + TimeSpan.FromMinutes(minutes):yyyy/MM/dd HH:mm:ss}";
|
|
}
|
|
|
|
private void OnIpChanged()
|
|
{
|
|
if (LastConnCheckbox.Pressed && IpAddress is null || !IpCheckbox.Pressed)
|
|
{
|
|
IpAddress = null;
|
|
ErrorLevel &= ~ErrorLevelEnum.IpAddress;
|
|
IpLine.ModulateSelfOverride = null;
|
|
UpdateSubmitEnabled();
|
|
return;
|
|
}
|
|
var ip = IpLine.Text;
|
|
var hid = "0";
|
|
if (ip.Contains('/'))
|
|
{
|
|
var split = ip.Split('/');
|
|
ip = split[0];
|
|
hid = split[1];
|
|
}
|
|
|
|
if (!IPAddress.TryParse(ip, out var parsedIp) || !byte.TryParse(hid, out var hidInt) || hidInt > 128 || hidInt > 32 && parsedIp.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
ErrorLevel |= ErrorLevelEnum.IpAddress;
|
|
IpLine.ModulateSelfOverride = Color.Red;
|
|
UpdateSubmitEnabled();
|
|
return;
|
|
}
|
|
|
|
if (hidInt == 0)
|
|
hidInt = (byte) (parsedIp.AddressFamily == AddressFamily.InterNetworkV6 ? 128 : 32);
|
|
IpAddress = (parsedIp, hidInt);
|
|
ErrorLevel &= ~ErrorLevelEnum.IpAddress;
|
|
IpLine.ModulateSelfOverride = null;
|
|
UpdateSubmitEnabled();
|
|
}
|
|
|
|
private void OnHwidChanged()
|
|
{
|
|
var hwidString = HwidLine.Text;
|
|
ImmutableTypedHwid? hwid = null;
|
|
if (HwidCheckbox.Pressed && !(string.IsNullOrEmpty(hwidString) && LastConnCheckbox.Pressed) && !ImmutableTypedHwid.TryParse(hwidString, out hwid))
|
|
{
|
|
ErrorLevel |= ErrorLevelEnum.Hwid;
|
|
HwidLine.ModulateSelfOverride = Color.Red;
|
|
UpdateSubmitEnabled();
|
|
return;
|
|
}
|
|
|
|
ErrorLevel &= ~ErrorLevelEnum.Hwid;
|
|
HwidLine.ModulateSelfOverride = null;
|
|
UpdateSubmitEnabled();
|
|
|
|
if (LastConnCheckbox.Pressed || !HwidCheckbox.Pressed)
|
|
{
|
|
Hwid = null;
|
|
return;
|
|
}
|
|
Hwid = hwid;
|
|
}
|
|
|
|
private void OnTypeChanged()
|
|
{
|
|
TypeOption.ModulateSelfOverride = null;
|
|
Tabs.SetTabVisible((int) TabNumbers.Roles, TypeOption.SelectedId == (int) Types.Role);
|
|
NoteSeverity? newSeverity = null;
|
|
switch (TypeOption.SelectedId)
|
|
{
|
|
case (int)Types.Server:
|
|
if (Enum.TryParse(_cfg.GetCVar(CCVars.ServerBanDefaultSeverity), true, out NoteSeverity serverSeverity))
|
|
newSeverity = serverSeverity;
|
|
else
|
|
{
|
|
_banPanelSawmill
|
|
.Warning("Server ban severity could not be parsed from config!");
|
|
}
|
|
|
|
break;
|
|
case (int) Types.Role:
|
|
|
|
if (Enum.TryParse(_cfg.GetCVar(CCVars.RoleBanDefaultSeverity), true, out NoteSeverity roleSeverity))
|
|
{
|
|
newSeverity = roleSeverity;
|
|
}
|
|
else
|
|
{
|
|
_banPanelSawmill
|
|
.Warning("Role ban severity could not be parsed from config!");
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (newSeverity != null)
|
|
SeverityOption.SelectId((int) newSeverity.Value);
|
|
}
|
|
|
|
private void UpdateSubmitEnabled()
|
|
{
|
|
SubmitButton.Disabled = ErrorLevel != ErrorLevelEnum.None;
|
|
}
|
|
|
|
private void OnPlayerNameChanged()
|
|
{
|
|
if (PlayerUsername == PlayerNameLine.Text)
|
|
return;
|
|
PlayerUsername = PlayerNameLine.Text;
|
|
if (!PlayerCheckbox.Pressed)
|
|
return;
|
|
if (string.IsNullOrWhiteSpace(PlayerUsername))
|
|
ErrorLevel |= ErrorLevelEnum.PlayerName;
|
|
else
|
|
ErrorLevel &= ~ErrorLevelEnum.PlayerName;
|
|
|
|
UpdateSubmitEnabled();
|
|
PlayerChanged?.Invoke(PlayerUsername);
|
|
}
|
|
|
|
public void OnPlayerSelectionChanged(PlayerInfo? player)
|
|
{
|
|
PlayerNameLine.Text = player?.Username ?? string.Empty;
|
|
OnPlayerNameChanged();
|
|
}
|
|
|
|
private void ResetTextEditor(GUIBoundKeyEventArgs _)
|
|
{
|
|
ReasonTextEdit.ModulateSelfOverride = null;
|
|
ReasonTextEdit.OnKeyBindDown -= ResetTextEditor;
|
|
}
|
|
|
|
private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
|
{
|
|
ProtoId<JobPrototype>[]? jobs = null;
|
|
ProtoId<AntagPrototype>[]? antags = null;
|
|
|
|
if (TypeOption.SelectedId == (int) Types.Role)
|
|
{
|
|
var jobList = new List<ProtoId<JobPrototype>>();
|
|
var antagList = new List<ProtoId<AntagPrototype>>();
|
|
|
|
if (_roleCheckboxes.Count == 0)
|
|
throw new DebugAssertException("RoleCheckboxes was empty");
|
|
|
|
foreach (var button in _roleCheckboxes.Values.SelectMany(departmentButtons => departmentButtons))
|
|
{
|
|
if (button.Item1 is { Pressed: true, Name: not null })
|
|
{
|
|
switch (button.Item2)
|
|
{
|
|
case JobPrototype:
|
|
jobList.Add(button.Item2.ID);
|
|
|
|
break;
|
|
case AntagPrototype:
|
|
antagList.Add(button.Item2.ID);
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (jobList.Count + antagList.Count == 0)
|
|
{
|
|
Tabs.CurrentTab = (int) TabNumbers.Roles;
|
|
|
|
return;
|
|
}
|
|
|
|
jobs = jobList.ToArray();
|
|
antags = antagList.ToArray();
|
|
}
|
|
|
|
if (TypeOption.SelectedId == (int) Types.None)
|
|
{
|
|
TypeOption.ModulateSelfOverride = Color.Red;
|
|
Tabs.CurrentTab = (int) TabNumbers.BasicInfo;
|
|
|
|
return;
|
|
}
|
|
|
|
var reason = Rope.Collapse(ReasonTextEdit.TextRope);
|
|
if (string.IsNullOrWhiteSpace(reason))
|
|
{
|
|
//Tabs.CurrentTab = (int) TabNumbers.Text;
|
|
Tabs.CurrentTab = (int) TabNumbers.BasicInfo;
|
|
ReasonTextEdit.GrabKeyboardFocus();
|
|
ReasonTextEdit.ModulateSelfOverride = Color.Red;
|
|
ReasonTextEdit.OnKeyBindDown += ResetTextEditor;
|
|
|
|
return;
|
|
}
|
|
|
|
if (ButtonResetOn is null)
|
|
{
|
|
ButtonResetOn = _gameTiming.CurTime.Add(TimeSpan.FromSeconds(3));
|
|
SubmitButton.ModulateSelfOverride = Color.Red;
|
|
SubmitButton.Text = Loc.GetString("ban-panel-confirm");
|
|
|
|
return;
|
|
}
|
|
|
|
var player = PlayerCheckbox.Pressed ? PlayerUsername : null;
|
|
var useLastIp = IpCheckbox.Pressed && LastConnCheckbox.Pressed && IpAddress is null;
|
|
var useLastHwid = HwidCheckbox.Pressed && LastConnCheckbox.Pressed && Hwid is null;
|
|
var severity = (NoteSeverity) SeverityOption.SelectedId;
|
|
var erase = EraseCheckbox.Pressed;
|
|
|
|
var ban = new Ban(
|
|
player,
|
|
IpAddress,
|
|
useLastIp,
|
|
Hwid,
|
|
useLastHwid,
|
|
(uint)(TimeEntered * Multiplier),
|
|
reason,
|
|
severity,
|
|
jobs,
|
|
antags,
|
|
erase
|
|
);
|
|
|
|
BanSubmitted?.Invoke(ban);
|
|
}
|
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
|
{
|
|
base.FrameUpdate(args);
|
|
|
|
// This checks for null for free, do not invert it as null always produces a false value
|
|
if (_gameTiming.CurTime > ButtonResetOn)
|
|
{
|
|
ButtonResetOn = null;
|
|
SubmitButton.ModulateSelfOverride = null;
|
|
SubmitButton.Text = Loc.GetString("ban-panel-submit");
|
|
}
|
|
}
|
|
}
|