From 7b19a1137fc9c4ac79140ba97daad68358684858 Mon Sep 17 00:00:00 2001 From: Milutinke Date: Mon, 24 Oct 2022 22:52:49 +0200 Subject: [PATCH] Added a Debug mode setting to the Websocket chat bot. --- MinecraftClient/ChatBots/WebSocketBot.cs | 8 ++++++-- MinecraftClient/Resources/lang/en.ini | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/ChatBots/WebSocketBot.cs b/MinecraftClient/ChatBots/WebSocketBot.cs index 6ef934c9..fb43fc5a 100644 --- a/MinecraftClient/ChatBots/WebSocketBot.cs +++ b/MinecraftClient/ChatBots/WebSocketBot.cs @@ -185,6 +185,9 @@ namespace MinecraftClient.ChatBots [TomlInlineComment("$config.ChatBot.WebSocketBot.Password$")] public string? Password = "wspass12345"; + + [TomlInlineComment("$config.ChatBot.WebSocketBot.DebugMode$")] + public bool DebugMode = false; } public WebSocketBot() @@ -266,7 +269,8 @@ namespace MinecraftClient.ChatBots { try { - LogDebugToConsole("\n\n\tGot command\n\n\t" + message + "\n\n"); + if (Config.DebugMode) + LogDebugToConsole("\n\n\tGot command\n\n\t" + message + "\n\n"); WsChatBotCommand cmd = JsonConvert.DeserializeObject(message)!; WsCommandResponder responder = new WsCommandResponder(this, session, cmd.Command, cmd.RequestId); @@ -1119,7 +1123,7 @@ namespace MinecraftClient.ChatBots { session.SendToClient("{\"event\": \"" + type + "\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\"" + Json.EscapeString(data) + "\"") + "}"); - if (!(type.Contains("Entity") || type.Equals("OnTimeUpdate") || type.Equals("OnServerTpsUpdate"))) + if (!(type.Contains("Entity") || type.Equals("OnTimeUpdate") || type.Equals("OnServerTpsUpdate")) && Config.DebugMode) LogDebugToConsole( "\n\n\tSending:\n\n\t{\"event\": \"" + type + "\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\"" diff --git a/MinecraftClient/Resources/lang/en.ini b/MinecraftClient/Resources/lang/en.ini index b4d2d2c5..de943033 100644 --- a/MinecraftClient/Resources/lang/en.ini +++ b/MinecraftClient/Resources/lang/en.ini @@ -1047,3 +1047,4 @@ config.ChatBot.WebSocketBot=Remotely control the client using Web Sockets.\n# Th config.ChatBot.WebSocketBot.Ip=The IP address that Websocket server will be bounded to. config.ChatBot.WebSocketBot.Port=The Port that Websocket server will be bounded to. config.ChatBot.WebSocketBot.Password=A password that will be used to authenticate on thw Websocket server (It is recommended to change the default password and to set a strong one). +config.ChatBot.WebSocketBot.DebugMode=If enabled the chat bot will print what is it recieving and sending when the "DebugMessages" are enabled in "Logging" section. This is useful when making your own library or trying to figure what is wrong with an existing one. \ No newline at end of file