Files
crystall-punk-14/Content.Server/Administration/Systems/AdminSystem.cs
Ed 684ec72541 Upstrearm sync (#94)
* Fix for the salvage ice labs map. (#26928)

* done

* more work

* Automatic changelog update

* Update Credits (#26938)

Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com>

* Fix cryostorage identifying unknown characters as captain (#26927)

Fixed cryostorage getting captain's record for unknown jobs.
Also localized Unknown job string.

* Automatic changelog update

* Fixed Honkbot/jonkbot honking like crazy, gave honkbot/jonkbot standard idle ai. (#26939)

* Fixed Honkbot/jonkbot honking like crazy, gave honkbot/jonkbot standard idle ai.

* Update Resources/Prototypes/Entities/Mobs/NPCs/silicon.yml

---------

Co-authored-by: Tayrtahn <tayrtahn@gmail.com>

* Automatic changelog update

* Bug fix: Force cancellation of RCD constructions if the construction type is changed (#26935)

Force cancellation of RCD constructions if the construction type is changed

* Fix standart -> standard and dressfilled test fail (#26942)

Fix standart -> standard

* Add Ability to stop sound when MobState is Dead (#26905)

* Add stopsWhenEntityDead to sound components

* Convert component

* Review

* Fix dupe sub

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>

* Automatic changelog update

* Fix rockets and lasers looking like they have nothing loaded (#26933)

* Automatic changelog update

* You can now see paper on crates (with color!) (#26834)

* Implement changes on not-cooked branch

* Made it work

* Fix update appearance calls

* Fix extra indents, clean-up code, fix tests hopefully

* Fix hammy cagecrate

* Fix messing up the yml, add artifact crate specific labels back in

* Visual Studio hates yml, sad

* Seperate the colors for cargonia

* sorry json

* make label move with artifact door

* Apply suggestion changes

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>

* Fix remaining crate offsets, add a few for livestock and graves (why are you labeling graves) and coffin label sprites (why are you labeling coffins??)

---------

Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>

* Make UtensilSystem and SharpSystem not run AfterInteract if it has already been handled (#25826)

* Make UtensilSystem and SharpSystem not run AfterInteract if it has already been handled

* merge conflicts

---------

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>

* Automatic changelog update

* Add two-message overload to PopupPredicted (#26907)

Added two-message overload to PopupPredicted

* Update submodule to 218.0.0 (#26945)

* Autism pins! (#25597)

* hee hee he ha ha

* added gold varients, forgive me for my spritework

* maints loot, copying from past PRs

* Trying to fix RSI

* speedran these sprites in break time, pictures will be later

* Fixed/Tweaked glows

* consensus

* gregregation

* dam copiryte

* oops i forgot to delete 2 fields hope this works

* Automatic changelog update

* Fix database round start date issues (#26838)

How can ONE DATABASE COLUMN have so many cursed issues I don't know, but it certainly pissed off the devil in its previous life.

The start_date column on round entities in the database was added by https://github.com/space-wizards/space-station-14/pull/21153. For some reason, this PR gave the column a nonsensical default value instead of making it nullable. This default value causes the code from #25280 to break. It actually trips an assert though that's not what the original issue report ran into.

This didn't get noticed on wizden servers because we at some point backfilled the start_date column based on the stored admin logs.

So I change the database model to make this column nullable, updated the C# code to match, and made the existing migration set the invalid values to be NULL instead. Cool.

Wait how's SQLite handle in this scenario anyways? Well actually turns out the column was *completely broken* in the first place!

The code for inserting into the round table was copy pasted between SQLite and PostgreSQL, with the only difference being that the SQLite key manually assigned the primary key instead of letting SQLite AUTOINCREMENT it. And then the code to give a start_date value was only added to the PostgreSQL version (which is actually in the base class already). So for SQLite that column's been filled up with the same invalid default the whole time.

Why was the code manually assigning a PK? I checked the SQLite docs for AUTOINCREMENT[1], and the behavior seems appropriate.

I removed the SQLite-specific code path and it just seems to work regardless. The migration just sets the old values to NULL too.

BUT WAIT, THERE'S MORE!

Turns out just doing the migration on SQLite is a pain in the ass! EF Core has to create a new table to apply the nullability change, because SQLite doesn't support proper ALTER COLUMN. This causes the generated SQL commands to be weird and the UPDATE for the migration goes BEFORE the nullability change... I ended up having to make TWO migrations for SQLite. Yay.

Fixes #26800

[1]: https://www.sqlite.org/autoinc.html

* Fix options menu crashing in replays (#26911)

Not having the nullable set properly is annoying but fixing that would probably be a significant amount of work.

* Greyscale color clothing (#26943)

* greyscales color gloves, color jumpsuits, and shoes

* remove popbob

* fix test fails

* Automatic changelog update

* WT550 Buffs + Burst Mode for WT550 & C-20R (#26886)

* Slightly increased WT550 Firerate, drastically reduced recoil, and given it the option to fire in 5 round bursts.

* Given the C-20 a 5 round burst aswell

* Automatic changelog update

* make holoparasites actually holographic (#26862)

it's over

* Automatic changelog update

* Add character sheets to board game crate (#26926)

add character sheets to board game crate

* Automatic changelog update

* Game server admin API (#26880)

* Reapply "Game server api" (#26871)

This reverts commit 3aee197923.

* Rewrite 75% of the code it's good now

* Wield recoil components (#26915)

* WieldRecoilComponents

* WieldRecoilComponents

* Update Content.Shared/Weapons/Ranged/Components/GunWieldBonusComponent.cs

Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>

* Update Content.Shared/Weapons/Ranged/Components/GunWieldBonusComponent.cs

---------

Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Clown shoes make you waddle, as God intended (#26338)

* Clown shoes make you waddle, as God intended

* OOPS

* Toned down, client system name fix

* Tidy namespacing for @deltanedas

* Refactor to handle prediction better, etc.

* Resolve PR comments.

* Automatic changelog update

* Use round time instead of server time for criminal history (#26949)

make criminal records computer use round time for history instead of the server time

* Rotate and Offset station CCVar nuke (#26175)

* no content

* add noRot to Europa

* bruh. and this

* yay

* fix

* Update debug.yml

---------

Co-authored-by: Boaz1111 <149967078+Boaz1111@users.noreply.github.com>
Co-authored-by: PJBot <pieterjan.briers+bot@gmail.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tayrtahn <tayrtahn@gmail.com>
Co-authored-by: superjj18 <gagnonjake@gmail.com>
Co-authored-by: chromiumboy <50505512+chromiumboy@users.noreply.github.com>
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: GreaseMonk <1354802+GreaseMonk@users.noreply.github.com>
Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
Co-authored-by: DrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Co-authored-by: Verm <32827189+Vermidia@users.noreply.github.com>
Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
Co-authored-by: Terraspark4941 <terraspark4941@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: Flareguy <78941145+Flareguy@users.noreply.github.com>
Co-authored-by: BramvanZijp <56019239+BramvanZijp@users.noreply.github.com>
Co-authored-by: Mr. 27 <45323883+Dutch-VanDerLinde@users.noreply.github.com>
Co-authored-by: Tyzemol <85772526+Tyzemol@users.noreply.github.com>
Co-authored-by: Froffy025 <78222136+Froffy025@users.noreply.github.com>
Co-authored-by: Whisper <121047731+QuietlyWhisper@users.noreply.github.com>
Co-authored-by: Hannah Giovanna Dawson <karakkaraz@gmail.com>
Co-authored-by: ilya.mikheev.coder <imc-ext+github@ilyamikcoder.com>
2024-04-14 20:34:16 +03:00

388 lines
15 KiB
C#

using System.Linq;
using Content.Server.Administration.Managers;
using Content.Server.Chat.Managers;
using Content.Server.Forensics;
using Content.Server.GameTicking;
using Content.Server.Hands.Systems;
using Content.Server.IdentityManagement;
using Content.Server.Mind;
using Content.Server.Players.PlayTimeTracking;
using Content.Server.Popups;
using Content.Server.StationRecords.Systems;
using Content.Shared.Administration;
using Content.Shared.Administration.Events;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement;
using Content.Shared.Inventory;
using Content.Shared.PDA;
using Content.Shared.Players.PlayTimeTracking;
using Content.Shared.Popups;
using Content.Shared.Roles;
using Content.Shared.Roles.Jobs;
using Content.Shared.StationRecords;
using Content.Shared.Throwing;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Enums;
using Robust.Shared.Network;
using Robust.Shared.Player;
namespace Content.Server.Administration.Systems
{
public sealed class AdminSystem : EntitySystem
{
[Dependency] private readonly IAdminManager _adminManager = default!;
[Dependency] private readonly IChatManager _chat = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly HandsSystem _hands = default!;
[Dependency] private readonly SharedJobSystem _jobs = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly MindSystem _minds = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PhysicsSystem _physics = default!;
[Dependency] private readonly PlayTimeTrackingManager _playTime = default!;
[Dependency] private readonly SharedRoleSystem _role = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationRecordsSystem _stationRecords = default!;
[Dependency] private readonly TransformSystem _transform = default!;
private readonly Dictionary<NetUserId, PlayerInfo> _playerList = new();
/// <summary>
/// Set of players that have participated in this round.
/// </summary>
public IReadOnlySet<NetUserId> RoundActivePlayers => _roundActivePlayers;
private readonly HashSet<NetUserId> _roundActivePlayers = new();
public readonly PanicBunkerStatus PanicBunker = new();
public override void Initialize()
{
base.Initialize();
_playerManager.PlayerStatusChanged += OnPlayerStatusChanged;
_adminManager.OnPermsChanged += OnAdminPermsChanged;
Subs.CVar(_config, CCVars.PanicBunkerEnabled, OnPanicBunkerChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerDisableWithAdmins, OnPanicBunkerDisableWithAdminsChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerEnableWithoutAdmins, OnPanicBunkerEnableWithoutAdminsChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerCountDeadminnedAdmins, OnPanicBunkerCountDeadminnedAdminsChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerShowReason, OnShowReasonChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerMinAccountAge, OnPanicBunkerMinAccountAgeChanged, true);
Subs.CVar(_config, CCVars.PanicBunkerMinOverallHours, OnPanicBunkerMinOverallHoursChanged, true);
SubscribeLocalEvent<IdentityChangedEvent>(OnIdentityChanged);
SubscribeLocalEvent<PlayerAttachedEvent>(OnPlayerAttached);
SubscribeLocalEvent<PlayerDetachedEvent>(OnPlayerDetached);
SubscribeLocalEvent<RoleAddedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoleRemovedEvent>(OnRoleEvent);
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
}
private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev)
{
_roundActivePlayers.Clear();
foreach (var (id, data) in _playerList)
{
if (!data.ActiveThisRound)
continue;
if (!_playerManager.TryGetPlayerData(id, out var playerData))
return;
_playerManager.TryGetSessionById(id, out var session);
_playerList[id] = GetPlayerInfo(playerData, session);
}
var updateEv = new FullPlayerListEvent() { PlayersInfo = _playerList.Values.ToList() };
foreach (var admin in _adminManager.ActiveAdmins)
{
RaiseNetworkEvent(updateEv, admin.Channel);
}
}
public void UpdatePlayerList(ICommonSession player)
{
_playerList[player.UserId] = GetPlayerInfo(player.Data, player);
var playerInfoChangedEvent = new PlayerInfoChangedEvent
{
PlayerInfo = _playerList[player.UserId]
};
foreach (var admin in _adminManager.ActiveAdmins)
{
RaiseNetworkEvent(playerInfoChangedEvent, admin.Channel);
}
}
public PlayerInfo? GetCachedPlayerInfo(NetUserId? netUserId)
{
if (netUserId == null)
return null;
_playerList.TryGetValue(netUserId.Value, out var value);
return value ?? null;
}
private void OnIdentityChanged(ref IdentityChangedEvent ev)
{
if (!TryComp<ActorComponent>(ev.CharacterEntity, out var actor))
return;
UpdatePlayerList(actor.PlayerSession);
}
private void OnRoleEvent(RoleEvent ev)
{
var session = _minds.GetSession(ev.Mind);
if (!ev.Antagonist || session == null)
return;
UpdatePlayerList(session);
}
private void OnAdminPermsChanged(AdminPermsChangedEventArgs obj)
{
UpdatePanicBunker();
if (!obj.IsAdmin)
{
RaiseNetworkEvent(new FullPlayerListEvent(), obj.Player.Channel);
return;
}
SendFullPlayerList(obj.Player);
}
private void OnPlayerDetached(PlayerDetachedEvent ev)
{
// If disconnected then the player won't have a connected entity to get character name from.
// The disconnected state gets sent by OnPlayerStatusChanged.
if (ev.Player.Status == SessionStatus.Disconnected)
return;
UpdatePlayerList(ev.Player);
}
private void OnPlayerAttached(PlayerAttachedEvent ev)
{
if (ev.Player.Status == SessionStatus.Disconnected)
return;
_roundActivePlayers.Add(ev.Player.UserId);
UpdatePlayerList(ev.Player);
}
public override void Shutdown()
{
base.Shutdown();
_playerManager.PlayerStatusChanged -= OnPlayerStatusChanged;
_adminManager.OnPermsChanged -= OnAdminPermsChanged;
}
private void OnPlayerStatusChanged(object? sender, SessionStatusEventArgs e)
{
UpdatePlayerList(e.Session);
UpdatePanicBunker();
}
private void SendFullPlayerList(ICommonSession playerSession)
{
var ev = new FullPlayerListEvent();
ev.PlayersInfo = _playerList.Values.ToList();
RaiseNetworkEvent(ev, playerSession.Channel);
}
private PlayerInfo GetPlayerInfo(SessionData data, ICommonSession? session)
{
var name = data.UserName;
var entityName = string.Empty;
var identityName = string.Empty;
if (session?.AttachedEntity != null)
{
entityName = EntityManager.GetComponent<MetaDataComponent>(session.AttachedEntity.Value).EntityName;
identityName = Identity.Name(session.AttachedEntity.Value, EntityManager);
}
var antag = false;
var startingRole = string.Empty;
if (_minds.TryGetMind(session, out var mindId, out _))
{
antag = _role.MindIsAntagonist(mindId);
startingRole = _jobs.MindTryGetJobName(mindId);
}
var connected = session != null && session.Status is SessionStatus.Connected or SessionStatus.InGame;
TimeSpan? overallPlaytime = null;
if (session != null &&
_playTime.TryGetTrackerTimes(session, out var playTimes) &&
playTimes.TryGetValue(PlayTimeTrackingShared.TrackerOverall, out var playTime))
{
overallPlaytime = playTime;
}
return new PlayerInfo(name, entityName, identityName, startingRole, antag, GetNetEntity(session?.AttachedEntity), data.UserId,
connected, _roundActivePlayers.Contains(data.UserId), overallPlaytime);
}
private void OnPanicBunkerChanged(bool enabled)
{
PanicBunker.Enabled = enabled;
_chat.SendAdminAlert(Loc.GetString(enabled
? "admin-ui-panic-bunker-enabled-admin-alert"
: "admin-ui-panic-bunker-disabled-admin-alert"
));
SendPanicBunkerStatusAll();
}
private void OnPanicBunkerDisableWithAdminsChanged(bool enabled)
{
PanicBunker.DisableWithAdmins = enabled;
UpdatePanicBunker();
}
private void OnPanicBunkerEnableWithoutAdminsChanged(bool enabled)
{
PanicBunker.EnableWithoutAdmins = enabled;
UpdatePanicBunker();
}
private void OnPanicBunkerCountDeadminnedAdminsChanged(bool enabled)
{
PanicBunker.CountDeadminnedAdmins = enabled;
UpdatePanicBunker();
}
private void OnShowReasonChanged(bool enabled)
{
PanicBunker.ShowReason = enabled;
SendPanicBunkerStatusAll();
}
private void OnPanicBunkerMinAccountAgeChanged(int minutes)
{
PanicBunker.MinAccountAgeHours = minutes / 60;
SendPanicBunkerStatusAll();
}
private void OnPanicBunkerMinOverallHoursChanged(int hours)
{
PanicBunker.MinOverallHours = hours;
SendPanicBunkerStatusAll();
}
private void UpdatePanicBunker()
{
var admins = PanicBunker.CountDeadminnedAdmins
? _adminManager.AllAdmins
: _adminManager.ActiveAdmins;
var hasAdmins = admins.Any();
if (hasAdmins && PanicBunker.DisableWithAdmins)
{
_config.SetCVar(CCVars.PanicBunkerEnabled, false);
}
else if (!hasAdmins && PanicBunker.EnableWithoutAdmins)
{
_config.SetCVar(CCVars.PanicBunkerEnabled, true);
}
SendPanicBunkerStatusAll();
}
private void SendPanicBunkerStatusAll()
{
var ev = new PanicBunkerChangedEvent(PanicBunker);
foreach (var admin in _adminManager.AllAdmins)
{
RaiseNetworkEvent(ev, admin);
}
}
/// <summary>
/// Erases a player from the round.
/// This removes them and any trace of them from the round, deleting their
/// chat messages and showing a popup to other players.
/// Their items are dropped on the ground.
/// </summary>
public void Erase(ICommonSession player)
{
var entity = player.AttachedEntity;
_chat.DeleteMessagesBy(player);
if (entity != null && !TerminatingOrDeleted(entity.Value))
{
if (TryComp(entity.Value, out TransformComponent? transform))
{
var coordinates = _transform.GetMoverCoordinates(entity.Value, transform);
var name = Identity.Entity(entity.Value, EntityManager);
_popup.PopupCoordinates(Loc.GetString("admin-erase-popup", ("user", name)), coordinates, PopupType.LargeCaution);
var filter = Filter.Pvs(coordinates, 1, EntityManager, _playerManager);
var audioParams = new AudioParams().WithVolume(3);
_audio.PlayStatic("/Audio/Effects/pop_high.ogg", filter, coordinates, true, audioParams);
}
foreach (var item in _inventory.GetHandOrInventoryEntities(entity.Value))
{
if (TryComp(item, out PdaComponent? pda) &&
TryComp(pda.ContainedId, out StationRecordKeyStorageComponent? keyStorage) &&
keyStorage.Key is { } key &&
_stationRecords.TryGetRecord(key, out GeneralStationRecord? record))
{
if (TryComp(entity, out DnaComponent? dna) &&
dna.DNA != record.DNA)
{
continue;
}
if (TryComp(entity, out FingerprintComponent? fingerPrint) &&
fingerPrint.Fingerprint != record.Fingerprint)
{
continue;
}
_stationRecords.RemoveRecord(key);
Del(item);
}
}
if (_inventory.TryGetContainerSlotEnumerator(entity.Value, out var enumerator))
{
while (enumerator.NextItem(out var item, out var slot))
{
if (_inventory.TryUnequip(entity.Value, entity.Value, slot.Name, true, true))
_physics.ApplyAngularImpulse(item, ThrowingSystem.ThrowAngularImpulse);
}
}
if (TryComp(entity.Value, out HandsComponent? hands))
{
foreach (var hand in _hands.EnumerateHands(entity.Value, hands))
{
_hands.TryDrop(entity.Value, hand, checkActionBlocker: false, doDropInteraction: false, handsComp: hands);
}
}
}
_minds.WipeMind(player);
QueueDel(entity);
_gameTicker.SpawnObserver(player);
}
}
}