From bdf37e427c2933561e0c25669b4c836da49e224a Mon Sep 17 00:00:00 2001 From: CarbonNeuron Date: Fri, 1 May 2020 09:26:51 -0500 Subject: [PATCH 1/2] Add some features of command logging --- MinecraftClient/Commands/Sneak.cs | 1 + MinecraftClient/McTcpClient.cs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/MinecraftClient/Commands/Sneak.cs b/MinecraftClient/Commands/Sneak.cs index ada8b00b..8c8240b7 100644 --- a/MinecraftClient/Commands/Sneak.cs +++ b/MinecraftClient/Commands/Sneak.cs @@ -13,6 +13,7 @@ namespace MinecraftClient.Commands public override string Run(McTcpClient handler, string command, Dictionary localVars) { + Console.WriteLine(command); if (sneaking) { var result = handler.sendEntityAction(Protocol.ActionType.StopSneaking); diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 5651761a..8234133b 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -325,6 +325,7 @@ namespace MinecraftClient } while (true); } + /// /// Perform an internal MCC command (not a server command, use SendText() instead for that!) @@ -335,6 +336,7 @@ namespace MinecraftClient /// TRUE if the command was indeed an internal MCC command public bool PerformInternalCommand(string command, ref string response_msg, Dictionary localVars = null) { + /* Load commands from the 'Commands' namespace */ if (cmds.Count == 0) @@ -383,12 +385,28 @@ namespace MinecraftClient else if (cmds.ContainsKey(command_name)) { response_msg = cmds[command_name].Run(this, command, localVars); + foreach (ChatBot bot in bots.ToArray()) + { + try + { + bot.OnInternalCommand(command_name, response_msg); + } + catch (Exception e) + { + if (!(e is ThreadAbortException)) + { + ConsoleIO.WriteLogLine("OnInternalCommand: Got error from " + bot.ToString() + ": " + e.ToString()); + } + else throw; //ThreadAbortException should not be caught + } + } } else { response_msg = "Unknown command '" + command_name + "'. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' for help."; return false; } + return true; } From 06ea43f6c01c2d26bc3376a56596de565bddbf98 Mon Sep 17 00:00:00 2001 From: CarbonNeuron Date: Fri, 1 May 2020 09:37:15 -0500 Subject: [PATCH 2/2] Add Internal command logging. --- MinecraftClient/ChatBot.cs | 2 ++ MinecraftClient/ChatBots/ChatLog.cs | 18 +++++++++++++++++- MinecraftClient/McTcpClient.cs | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 538b91c2..22990942 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -156,6 +156,8 @@ namespace MinecraftClient /// Entity with updated location public virtual void OnEntityMove(Mapping.Entity entity) { } + public virtual void OnInternalCommand(string commandName,string commandParams, string Result) { } + /// /// Called when an entity spawned nearby /// diff --git a/MinecraftClient/ChatBots/ChatLog.cs b/MinecraftClient/ChatBots/ChatLog.cs index 38faec79..6ec8900f 100644 --- a/MinecraftClient/ChatBots/ChatLog.cs +++ b/MinecraftClient/ChatBots/ChatLog.cs @@ -12,11 +12,12 @@ namespace MinecraftClient.ChatBots public class ChatLog : ChatBot { - public enum MessageFilter { AllText, AllMessages, OnlyChat, OnlyWhispers }; + public enum MessageFilter { AllText, AllMessages, OnlyChat, OnlyWhispers, OnlyInternal }; private bool dateandtime; private bool saveOther = true; private bool saveChat = true; private bool savePrivate = true; + private bool saveInternal = true; private string logfile; /// @@ -52,6 +53,12 @@ namespace MinecraftClient.ChatBots savePrivate = true; saveChat = false; break; + case MessageFilter.OnlyInternal: + saveOther = false; + savePrivate = false; + saveChat = false; + saveInternal = true; + break; } if (String.IsNullOrEmpty(file) || file.IndexOfAny(Path.GetInvalidPathChars()) >= 0) { @@ -68,6 +75,7 @@ namespace MinecraftClient.ChatBots case "messages": return MessageFilter.AllMessages; case "chat": return MessageFilter.OnlyChat; case "private": return MessageFilter.OnlyWhispers; + case "internal": return MessageFilter.OnlyInternal; default: return MessageFilter.AllText; } } @@ -92,6 +100,14 @@ namespace MinecraftClient.ChatBots } } + public override void OnInternalCommand(string commandName,string commandParams, string Result) + { + if (saveInternal) + { + save($"Internal {commandName}({commandParams}): {Result}"); + } + } + private void save(string tosave) { if (dateandtime) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 8234133b..559d48ea 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -389,7 +389,7 @@ namespace MinecraftClient { try { - bot.OnInternalCommand(command_name, response_msg); + bot.OnInternalCommand(command_name, string.Join(" ",Command.getArgs(command)),response_msg); } catch (Exception e) {