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
This commit is contained in:
@@ -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<string> MutedPlayers = new HashSet<string>();
|
||||
|
||||
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<int> _recipientEntityIds)
|
||||
static void Prefix(ClientInfo _cInfo, string _msg, ref List<int> _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<int>();
|
||||
}
|
||||
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<int>();
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user