From 6997ca85c95b7f89a97c88c02a93713001c6f9d4 Mon Sep 17 00:00:00 2001 From: nikthechampiongr Date: Sat, 31 Aug 2024 01:59:15 +0300 Subject: [PATCH] Make suicide logs include the username, as well as the character(where possible) --- Content.Server/Chat/SuicideSystem.cs | 19 +++++++++++++++++-- Content.Server/Ghost/GhostSystem.cs | 6 +++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Content.Server/Chat/SuicideSystem.cs b/Content.Server/Chat/SuicideSystem.cs index 69d87472fb24d2..4eda5323854095 100644 --- a/Content.Server/Chat/SuicideSystem.cs +++ b/Content.Server/Chat/SuicideSystem.cs @@ -46,7 +46,15 @@ public bool Suicide(EntityUid victim) if (!TryComp(victim, out var mobState) || _mobState.IsDead(victim, mobState)) return false; + _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(victim):player} is attempting to suicide"); + + ICommonSession? session = null; + + if (TryComp(victim, out var actor)) + session = actor.PlayerSession; + var suicideGhostEvent = new SuicideGhostEvent(victim); + RaiseLocalEvent(victim, suicideGhostEvent); // Suicide is considered a fail if the user wasn't able to ghost @@ -54,11 +62,18 @@ public bool Suicide(EntityUid victim) if (!suicideGhostEvent.Handled || _tagSystem.HasTag(victim, "CannotSuicide")) return false; - _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(victim):player} is attempting to suicide"); var suicideEvent = new SuicideEvent(victim); RaiseLocalEvent(victim, suicideEvent); - _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(victim):player} suicided."); + // Since the player is already dead the log will not contain their username. + if (session != null) + { + _adminLogger.Add(LogType.Mind, $"{session:player} suicided."); + } + else + { + _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(victim):player} suicided."); + } return true; } diff --git a/Content.Server/Ghost/GhostSystem.cs b/Content.Server/Ghost/GhostSystem.cs index b0452143297570..945b0ff998a1fb 100644 --- a/Content.Server/Ghost/GhostSystem.cs +++ b/Content.Server/Ghost/GhostSystem.cs @@ -571,14 +571,14 @@ public bool OnGhostAttempt(EntityUid mindId, bool canReturnGlobal, bool viaComma } } + if (playerEntity != null) + _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(playerEntity.Value):player} ghosted{(!canReturn ? " (non-returnable)" : "")}"); + var ghost = SpawnGhost((mindId, mind), position, canReturn); if (ghost == null) return false; - if (playerEntity != null) - _adminLogger.Add(LogType.Mind, $"{EntityManager.ToPrettyString(playerEntity.Value):player} ghosted{(!canReturn ? " (non-returnable)" : "")}"); - return true; } }