From 373fb71632655be31ec223487a31ecc11a4ba3b4 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 00:30:42 +0000 Subject: [PATCH] [patch] Leave a bot alone when its BotNames entry is null RenameFor trimmed every configured value before looking up the bot's own key, so one "Rock": null entry threw for every bot and turned off bot persona tracking. A null target now means the same as a blank one. Fixes ktsu-dev/CounterStrikeProgression#66 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017vfJW3f2Szc4ZLoCTbPhuX --- CounterStrikeProgression.Core/Players/BotNames.cs | 5 ++++- CounterStrikeProgression.Test/BotNameTests.cs | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CounterStrikeProgression.Core/Players/BotNames.cs b/CounterStrikeProgression.Core/Players/BotNames.cs index 7ff3be6..7091750 100644 --- a/CounterStrikeProgression.Core/Players/BotNames.cs +++ b/CounterStrikeProgression.Core/Players/BotNames.cs @@ -27,7 +27,10 @@ internal static class BotNames } string trimmed = current.Trim(); - if (names.Values.Any(given => string.Equals(given.Trim(), trimmed, StringComparison.OrdinalIgnoreCase))) + + // A null value is read from config as readily as a blank one ("Rock": null), and means the same: + // leave that bot alone. It must not stop every other bot from being renamed. + if (names.Values.Any(given => string.Equals(given?.Trim(), trimmed, StringComparison.OrdinalIgnoreCase))) { return null; } diff --git a/CounterStrikeProgression.Test/BotNameTests.cs b/CounterStrikeProgression.Test/BotNameTests.cs index fc32314..9ea740c 100644 --- a/CounterStrikeProgression.Test/BotNameTests.cs +++ b/CounterStrikeProgression.Test/BotNameTests.cs @@ -42,4 +42,12 @@ public void RenameFor_LeavesABlankNameAlone() => [TestMethod] public void RenameFor_IgnoresABlankTarget() => Assert.IsNull(BotNames.RenameFor(new Dictionary { ["Rock"] = " " }, "Rock")); + + [TestMethod] + public void RenameFor_ANullTarget_StillRenamesTheOtherBots() => + Assert.AreEqual("Muhlik", BotNames.RenameFor(new Dictionary { ["Rock"] = null!, ["Bob"] = "Muhlik" }, "Bob")); + + [TestMethod] + public void RenameFor_IgnoresANullTarget() => + Assert.IsNull(BotNames.RenameFor(new Dictionary { ["Rock"] = null!, ["Bob"] = "Muhlik" }, "Rock")); }