From a543620a80cee7b559ee333fcc591cd1f67d52e1 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 10 Apr 2014 19:55:16 +0200 Subject: [PATCH] Fix null characters in chat prompt (old bug) Sometimes null characters were inserted in chat prompt Rename "Scripting" bot into "Script" bot. --- MinecraftClient/Bots.cs | 10 ++++------ MinecraftClient/ConsoleIO.cs | 17 ++++++++++++++--- MinecraftClient/McTcpClient.cs | 2 +- MinecraftClient/MinecraftCom.cs | 6 +++--- MinecraftClient/Program.cs | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index e4b392a7..44769dbd 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -254,7 +254,7 @@ namespace MinecraftClient protected void RunScript(string filename, string playername = "") { - handler.BotLoad(new Bots.Scripting(filename, playername)); + handler.BotLoad(new Bots.Script(filename, playername)); } #endregion @@ -833,11 +833,9 @@ namespace MinecraftClient /// /// Runs a list of commands - /// Usage: bot:scripting:filename - /// Script must be placed in the config directory /// - public class Scripting : ChatBot + public class Script : ChatBot { private string file; private string[] lines = new string[0]; @@ -846,12 +844,12 @@ namespace MinecraftClient private int nextline = 0; private string owner; - public Scripting(string filename) + public Script(string filename) { file = filename; } - public Scripting(string filename, string ownername) + public Script(string filename, string ownername) :this(filename) { if (ownername != "") diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index 25bbacce..78b2c0b2 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -60,8 +60,11 @@ namespace MinecraftClient break; default: - Console.Write('*'); - password += k.KeyChar; + if (k.KeyChar != 0) + { + Console.Write('*'); + password += k.KeyChar; + } break; } } @@ -159,7 +162,15 @@ namespace MinecraftClient } break; default: - AddChar(k.KeyChar); + if (k.KeyChar != 0) + AddChar(k.KeyChar); + /* + reading_lock = false; + WriteLine("CHAR: " + ((int)k.KeyChar)); + if (!System.IO.File.Exists("debug-chars.txt")) { System.IO.File.Create("debug-chars.txt"); } + System.IO.File.AppendAllText("debug-chars.txt", "'" + k.KeyChar + "' " + ((int)k.KeyChar) + "\r\n"); + reading_lock = true; + */ break; } } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 8365e647..d70ccac4 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -175,7 +175,7 @@ namespace MinecraftClient } else if (text.ToLower().StartsWith("/script ")) { - handler.BotLoad(new Bots.Scripting(text.Substring(8))); + handler.BotLoad(new Bots.Script(text.Substring(8))); } else if (text != "") { diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index a275be79..c400af27 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -597,12 +597,12 @@ namespace MinecraftClient catch (ObjectDisposedException) { } foreach (ChatBot bot in bots) - if (bot is Bots.Scripting) - scripts_on_hold.Add((Bots.Scripting)bot); + if (bot is Bots.Script) + scripts_on_hold.Add((Bots.Script)bot); } private List bots = new List(); - private static List scripts_on_hold = new List(); + private static List scripts_on_hold = new List(); public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; } public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); } public void BotClear() { bots.Clear(); } diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 80c36c2c..0220bd81 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -162,7 +162,7 @@ namespace MinecraftClient if (Settings.ChatLog_Enabled) { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File, Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); } if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File)); } if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); } - if (Settings.StartupScript_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } + if (Settings.StartupScript_Enabled) { handler.BotLoad(new Bots.Script(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); } //Start the main TCP client