]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix suicide logs (#31661)
authornikthechampiongr <32041239+nikthechampiongr@users.noreply.github.com>
Sat, 31 Aug 2024 08:26:52 +0000 (08:26 +0000)
committerGitHub <noreply@github.com>
Sat, 31 Aug 2024 08:26:52 +0000 (18:26 +1000)
Make suicide logs include the username, as well as the character(where possible)

Content.Server/Chat/SuicideSystem.cs
Content.Server/Ghost/GhostSystem.cs

index 69d87472fb24d2185916c04e2251a326c347a729..4eda532385409588cf39d035a36b8852c6b23c1e 100644 (file)
@@ -46,7 +46,15 @@ public sealed class SuicideSystem : EntitySystem
         if (!TryComp<MobStateComponent>(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<ActorComponent>(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 sealed class SuicideSystem : EntitySystem
         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;
     }
 
index b045214329757005252ca0d1e9592651bd452909..945b0ff998a1fb8b7d79d5d7d497e09dc98b982e 100644 (file)
@@ -571,14 +571,14 @@ namespace Content.Server.Ghost
                 }
             }
 
+            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;
         }
     }