From c7b93dc0a84b8d0fe2768d18cfa4343c6fdffeb7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 23 Nov 2025 20:34:29 +0000 Subject: [PATCH] Add mute/unmute functionality for chat - /bot mute {id} - mutes player by EntityID, SteamID, or name - /bot unmute {id} - unmutes player - Muted players' messages blocked in-game but visible in telnet - All /bot commands only visible in telnet --- Harmony/CHRANIBotTNG.cs | 63 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/Harmony/CHRANIBotTNG.cs b/Harmony/CHRANIBotTNG.cs index f630012..65e717b 100644 --- a/Harmony/CHRANIBotTNG.cs +++ b/Harmony/CHRANIBotTNG.cs @@ -2,9 +2,12 @@ using HarmonyLib; using System.Reflection; using System; using System.Collections.Generic; +using System.Linq; public class CHRANIBotTNG : IModApi { + public static HashSet MutedPlayers = new HashSet(); + public void InitMod(Mod _modInstance) { Console.WriteLine("[CHRANIBotTNG] Loading"); @@ -17,11 +20,50 @@ public class CHRANIBotTNG : IModApi [HarmonyPatch(typeof(GameManager), "ChatMessageServer")] public class ChatMessagePatch { - static void Prefix(string _msg, ref List _recipientEntityIds) + static void Prefix(ClientInfo _cInfo, string _msg, ref List _recipientEntityIds) { + // Handle /bot commands if (_msg != null && _msg.StartsWith("/bot ")) { - // Clear recipients so no players see it in-game, but server still logs it + string[] parts = _msg.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + if (parts.Length >= 3 && parts[1].ToLower() == "mute") + { + string targetId = parts[2]; + CHRANIBotTNG.MutedPlayers.Add(targetId); + Console.WriteLine($"[CHRANIBotTNG] Muted player: {targetId}"); + } + else if (parts.Length >= 3 && parts[1].ToLower() == "unmute") + { + string targetId = parts[2]; + if (CHRANIBotTNG.MutedPlayers.Remove(targetId)) + { + Console.WriteLine($"[CHRANIBotTNG] Unmuted player: {targetId}"); + } + else + { + Console.WriteLine($"[CHRANIBotTNG] Player was not muted: {targetId}"); + } + } + + // Clear recipients so no players see /bot commands in-game + if (_recipientEntityIds == null) + { + _recipientEntityIds = new List(); + } + else + { + _recipientEntityIds.Clear(); + } + return; + } + + // Check if sender is muted + if (_cInfo != null && IsPlayerMuted(_cInfo)) + { + Console.WriteLine($"[CHRANIBotTNG] Blocked message from muted player: {_cInfo.playerName}"); + + // Clear recipients so no players see the message if (_recipientEntityIds == null) { _recipientEntityIds = new List(); @@ -32,4 +74,21 @@ public class ChatMessagePatch } } } + + static bool IsPlayerMuted(ClientInfo _cInfo) + { + // Check EntityID + if (CHRANIBotTNG.MutedPlayers.Contains(_cInfo.entityId.ToString())) + return true; + + // Check player name + if (CHRANIBotTNG.MutedPlayers.Contains(_cInfo.playerName)) + return true; + + // Check SteamID (InternalId) + if (_cInfo.InternalId != null && CHRANIBotTNG.MutedPlayers.Contains(_cInfo.InternalId.ReadablePlatformUserIdentifier)) + return true; + + return false; + } } \ No newline at end of file