2025-11-23 20:23:53 +01:00
|
|
|
using HarmonyLib;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System;
|
2025-11-23 19:39:06 +00:00
|
|
|
using System.Collections.Generic;
|
2025-11-23 20:34:29 +00:00
|
|
|
using System.Linq;
|
2025-11-23 20:23:53 +01:00
|
|
|
|
|
|
|
|
public class CHRANIBotTNG : IModApi
|
|
|
|
|
{
|
2025-11-23 20:34:29 +00:00
|
|
|
public static HashSet<string> MutedPlayers = new HashSet<string>();
|
|
|
|
|
|
2025-11-23 20:23:53 +01:00
|
|
|
public void InitMod(Mod _modInstance)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("[CHRANIBotTNG] Loading");
|
2025-11-23 19:39:06 +00:00
|
|
|
var harmony = new Harmony("com.chranibottng.mod");
|
|
|
|
|
harmony.PatchAll(Assembly.GetExecutingAssembly());
|
|
|
|
|
Console.WriteLine("[CHRANIBotTNG] Loaded");
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-11-23 20:23:53 +01:00
|
|
|
|
2025-11-23 19:39:06 +00:00
|
|
|
[HarmonyPatch(typeof(GameManager), "ChatMessageServer")]
|
|
|
|
|
public class ChatMessagePatch
|
|
|
|
|
{
|
2025-11-23 20:34:29 +00:00
|
|
|
static void Prefix(ClientInfo _cInfo, string _msg, ref List<int> _recipientEntityIds)
|
2025-11-23 19:39:06 +00:00
|
|
|
{
|
2025-11-23 20:34:29 +00:00
|
|
|
// Handle /bot commands
|
2025-11-23 19:39:06 +00:00
|
|
|
if (_msg != null && _msg.StartsWith("/bot "))
|
2025-11-23 20:23:53 +01:00
|
|
|
{
|
2025-11-23 20:34:29 +00:00
|
|
|
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
|
2025-11-23 19:54:53 +00:00
|
|
|
if (_recipientEntityIds == null)
|
|
|
|
|
{
|
|
|
|
|
_recipientEntityIds = new List<int>();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_recipientEntityIds.Clear();
|
|
|
|
|
}
|
2025-11-23 20:34:29 +00:00
|
|
|
return;
|
2025-11-23 20:23:53 +01:00
|
|
|
}
|
2025-11-23 20:34:29 +00:00
|
|
|
|
|
|
|
|
// 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>();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_recipientEntityIds.Clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2025-11-23 20:23:53 +01:00
|
|
|
}
|
|
|
|
|
}
|