From 25bf5a8ca929909c1102e8c8e3a5c2455b822509 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 2 Apr 2014 19:01:10 +0200 Subject: [PATCH 01/13] Catch ObjectDisposedException while reconnecting Seems also related to issue #19. --- MinecraftClient/MinecraftCom.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index e31e493d95..66e2cd66aa 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -580,6 +580,7 @@ public void Disconnect(string message) catch (SocketException) { } catch (System.IO.IOException) { } catch (NullReferenceException) { } + catch (ObjectDisposedException) { } } private List bots = new List(); From a4816403062c1d04f67c08dc295a623489d38a11 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 2 Apr 2014 22:53:46 +0200 Subject: [PATCH 02/13] Remove legacy command-line args & xauth bot - Use scripting instead of xauth bot - Use ini files instead of bot:botname args --- MinecraftClient/Bots.cs | 25 ----------- MinecraftClient/Program.cs | 86 ------------------------------------- MinecraftClient/Settings.cs | 4 -- 3 files changed, 115 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 4da3f2963a..dfd1ecc4d1 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -830,31 +830,6 @@ public override bool OnDisconnect(DisconnectReason reason, string message) } } - /// - /// Automatically send login command on servers usign the xAuth plugin - /// - - public class xAuth : ChatBot - { - private string password; - private int countdown = 50; - - public xAuth(string pass) - { - password = pass; - } - - public override void Update() - { - countdown--; - if (countdown == 0) - { - SendText("/login " + password); - UnloadBot(); //This bot is no more needed. - } - } - } - /// /// Runs a list of commands /// Usage: bot:scripting:filename diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index a35c723620..e887b96c3c 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -65,91 +65,6 @@ static void Main(string[] args) { Settings.SingleCommand = args[3]; } - - //Use bots? (will disable single command) - for (int i = 3; i < args.Length; i++) - { - if (args[i].Length > 4 && args[i].Substring(0, 4).ToLower() == "bot:") - { - Settings.SingleCommand = ""; - string[] botargs = args[i].ToLower().Split(':'); - switch (botargs[1]) - { - #region Process bots settings - case "antiafk": - Settings.AntiAFK_Enabled = true; - if (botargs.Length > 2) - { - try { Settings.AntiAFK_Delay = Convert.ToInt32(botargs[2]); } - catch (FormatException) { } - } break; - - case "pendu": - Settings.Hangman_Enabled = true; - Settings.Hangman_English = false; - break; - - case "hangman": - Settings.Hangman_Enabled = true; - Settings.Hangman_English = true; - break; - - case "alerts": - Settings.Alerts_Enabled = true; - break; - - case "log": - Settings.ChatLog_Enabled = true; - Settings.ChatLog_DateTime = true; - Settings.ChatLog_File = "chat-" + Settings.ServerIP.Replace(':', '-') + ".log"; - if (botargs.Length > 2) - { - Settings.ChatLog_DateTime = Settings.str2bool(botargs[2]); - if (botargs.Length > 3) - { - Settings.ChatLog_Filter = Bots.ChatLog.str2filter(botargs[3]); - if (botargs.Length > 4 && botargs[4] != "") { Settings.ChatLog_File = botargs[4]; } - } - } break; - - case "logplayerlist": - Settings.PlayerLog_File = "connected-" + Settings.ServerIP.Replace(':', '-') + ".log"; - if (botargs.Length > 2) - { - try { Settings.PlayerLog_Delay = Convert.ToInt32(botargs[2]); } - catch (FormatException) { } - } break; - - case "autorelog": - if (botargs.Length > 2) - { - try { Settings.AutoRelog_Delay = Convert.ToInt32(botargs[2]); } - catch (FormatException) { } - if (botargs.Length > 3) - { - try { Settings.AutoRelog_Retries = Convert.ToInt32(botargs[3]); } - catch (FormatException) { } - } - } break; - - case "xauth": - if (botargs.Length > 2) - { - Settings.xAuth_Enabled = true; - Settings.xAuth_Password = botargs[2]; - } break; - - case "scripting": - if (botargs.Length > 2) - { - Settings.Scripting_Enabled = true; - Settings.Scripting_ScriptFile = botargs[2]; - } break; - - #endregion - } - } - } } } } @@ -247,7 +162,6 @@ private static void InitializeClient() 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.xAuth_Enabled) { handler.BotLoad(new Bots.xAuth(Settings.xAuth_Password)); } if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); } //Start the main TCP client diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 6c82bc09ca..126075ab7e 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -63,10 +63,6 @@ public static class Settings public static int AutoRelog_Retries = 3; public static string AutoRelog_KickMessagesFile = "kickmessages.txt"; - //xAuth Settings - public static bool xAuth_Enabled = false; - public static string xAuth_Password = ""; - //Scripting Settings public static bool Scripting_Enabled = false; public static string Scripting_ScriptFile = "script.txt"; From fc281889c6c589fed83bee6ad47128df7ddd2ac2 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 2 Apr 2014 23:25:28 +0200 Subject: [PATCH 03/13] Move bot owners to ini settings - Bot owners now specified directly in the INI file - Owners list is now in Settings.cs and not in Hangman bot - Allow other bots to access owner list --- MinecraftClient/Bots.cs | 23 +---------------------- MinecraftClient/Settings.cs | 11 ++++++++--- 2 files changed, 9 insertions(+), 25 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index dfd1ecc4d1..105cd54028 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -355,7 +355,6 @@ public class Pendu : ChatBot private bool[] discovered; private string word = ""; private string letters = ""; - private string[] owners; private bool English; /// @@ -368,11 +367,6 @@ public Pendu(bool english) English = english; } - public override void Initialize() - { - owners = getowners(); - } - public override void Update() { if (running) @@ -398,7 +392,7 @@ public override void GetText(string text) if (isPrivateMessage(text, ref message, ref username)) { - if (owners.Contains(username.ToUpper())) + if (Settings.Bots_Owners.Contains(username.ToLower())) { switch (message) { @@ -495,21 +489,6 @@ private string chooseword() } } - private string[] getowners() - { - List owners = new List(); - owners.Add("CONSOLE"); - if (System.IO.File.Exists(Settings.Bots_OwnersFile)) - { - foreach (string s in System.IO.File.ReadAllLines(Settings.Bots_OwnersFile)) - { - owners.Add(s.ToUpper()); - } - } - else LogToConsole(English ? "File not found: " + Settings.Bots_OwnersFile : "Fichier introuvable : " + Settings.Bots_OwnersFile); - return owners.ToArray(); - } - private string word_cached { get diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 126075ab7e..64c63e995d 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -27,7 +27,7 @@ public static class Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json"; public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; - public static string Bots_OwnersFile = "bot-owners.txt"; + public static List Bots_Owners = new List(new string[] { "console" }); public static string Language = "en_GB"; //AntiAFK Settings @@ -118,8 +118,13 @@ public static void LoadSettings(string settingsfile) case "serverip": ServerIP = argValue; break; case "singlecommand": SingleCommand = argValue; break; case "language": Language = argValue; break; - case "botownersfile": Bots_OwnersFile = argValue; break; case "consoletitle": ConsoleTitle = argValue; break; + case "botowners": + Bots_Owners.Clear(); + Bots_Owners.Add("console"); + foreach (string name in argValue.ToLower().Replace(" ", "").Split(',')) + Bots_Owners.Add(name); + break; } break; @@ -209,7 +214,7 @@ public static void WriteDefaultSettings(string settingsfile) + "#Advanced settings\r\n" + "\r\n" + "language=en_GB\r\n" - + "botownersfile=bot-owners.txt\r\n" + + "botowners=Player1,Player2,Player3\r\n" + "consoletitle=%username% - Minecraft Console Client\r\n" + "\r\n" + "#Bot Settings\r\n" From d972378f0e853646b32479f57628cdde91c8fc09 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 3 Apr 2014 00:17:47 +0200 Subject: [PATCH 04/13] Added remote control bot A bot that can perform operations using /tell commands! Available commands: exit, reco, script, send. Closes #7 :) --- MinecraftClient/Bots.cs | 88 +++++++++++++++++++++++++++++++++++++ MinecraftClient/Program.cs | 1 + MinecraftClient/Settings.cs | 22 +++++++--- 3 files changed, 106 insertions(+), 5 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 105cd54028..3bc881a64b 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -235,6 +235,28 @@ protected void UnloadBot() handler.BotUnLoad(this); } + /// + /// Send a private message to a player + /// + /// Player name + /// Message + + protected void SendPrivateMessage(string player, string message) + { + SendText("/tell " + player + ' ' + message); + } + + /// + /// Run a script from a file using a Scripting bot + /// + /// File name + /// Player name to send error messages, if applicable + + protected void RunScript(string filename, string playername = "") + { + handler.BotLoad(new Bots.Scripting(filename, playername)); + } + #endregion } @@ -822,11 +844,20 @@ public class Scripting : ChatBot private int sleepticks = 10; private int sleepticks_interval = 10; private int nextline = 0; + private string owner; + public Scripting(string filename) { file = filename; } + public Scripting(string filename, string ownername) + :this(filename) + { + if (ownername != "") + owner = ownername; + } + public override void Initialize() { //Load the given file from the startup parameters @@ -856,8 +887,12 @@ public override void Initialize() if (!file_found) { LogToConsole("File not found: '" + file + "'"); + if (owner != null) + SendPrivateMessage(owner, "File not found: '" + file + "'"); UnloadBot(); //No need to keep the bot active } + else if (owner != null) + SendPrivateMessage(owner, "Script '" + file + "' loaded."); } public override void Update() @@ -912,5 +947,58 @@ public override void Update() } } } + + /// + /// Allow to perform operations using whispers to the bot + /// + + public class RemoteControl : ChatBot + { + public override void GetText(string text) + { + text = getVerbatim(text); + string command = "", sender = ""; + if (isPrivateMessage(text, ref command, ref sender) && Settings.Bots_Owners.Contains(sender.ToLower())) + { + string cmd_name = command.Split(' ')[0]; + switch (cmd_name.ToLower()) + { + case "exit": + DisconnectAndExit(); + break; + case "reco": + ReconnectToTheServer(); + break; + case "script": + if (command.Length >= 8) + RunScript(command.Substring(7), sender); + break; + case "send": + if (command.Length >= 6) + SendText(command.Substring(5)); + break; + case "help": + if (command.Length >= 6) + { + string help_cmd_name = command.Substring(5).ToLower(); + switch (help_cmd_name) + { + case "exit": SendPrivateMessage(sender, "exit: disconnect from the server."); break; + case "reco": SendPrivateMessage(sender, "reco: restart and reconnct to the server."); break; + case "script": SendPrivateMessage(sender, "script : run a script file."); break; + case "send": SendPrivateMessage(sender, "send : send a chat message or command."); break; + case "help": SendPrivateMessage(sender, "help : show brief help about a command."); break; + default: SendPrivateMessage(sender, "help: unknown command '" + help_cmd_name + "'."); break; + } + } + else SendPrivateMessage(sender, "help . Available commands: exit, reco, script, send."); + break; + default: + SendPrivateMessage(sender, "Unknown command '" + cmd_name + "'. Use 'help' for help."); + break; + } + } + } + } } } diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index e887b96c3c..55eaf4967a 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -163,6 +163,7 @@ private static void InitializeClient() 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.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); } + if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); } //Start the main TCP client if (Settings.SingleCommand != "") diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 64c63e995d..52916423e3 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -27,7 +27,7 @@ public static class Settings public static string TranslationsFile_FromMCDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\assets\objects\9e\9e2fdc43fc1c7024ff5922b998fadb2971a64ee0"; //MC 1.7.4 en_GB.lang public static string TranslationsFile_Website_Index = "https://s3.amazonaws.com/Minecraft.Download/indexes/1.7.4.json"; public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; - public static List Bots_Owners = new List(new string[] { "console" }); + public static List Bots_Owners = new List(); public static string Language = "en_GB"; //AntiAFK Settings @@ -67,8 +67,10 @@ public static class Settings public static bool Scripting_Enabled = false; public static string Scripting_ScriptFile = "script.txt"; + //Remote Control + public static bool RemoteCtrl_Enabled = false; - private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, Scripting }; + private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, Scripting, RemoteControl }; /// /// Load settings from the give INI file @@ -99,6 +101,7 @@ public static void LoadSettings(string settingsfile) case "hangman": pMode = ParseMode.Hangman; break; case "main": pMode = ParseMode.Main; break; case "scripting": pMode = ParseMode.Scripting; break; + case "remotecontrol": pMode = ParseMode.RemoteControl; break; default: pMode = ParseMode.Default; break; } } @@ -121,7 +124,6 @@ public static void LoadSettings(string settingsfile) case "consoletitle": ConsoleTitle = argValue; break; case "botowners": Bots_Owners.Clear(); - Bots_Owners.Add("console"); foreach (string name in argValue.ToLower().Replace(" ", "").Split(',')) Bots_Owners.Add(name); break; @@ -183,6 +185,13 @@ public static void LoadSettings(string settingsfile) case "scriptfile": Scripting_ScriptFile = argValue; break; } break; + + case ParseMode.RemoteControl: + switch (argName.ToLower()) + { + case "enabled": RemoteCtrl_Enabled = str2bool(argValue); break; + } + break; } } } @@ -206,7 +215,7 @@ public static void WriteDefaultSettings(string settingsfile) + "[Main]\r\n" + "\r\n" + "#General settings\r\n" - + "#leave blank = prompt user on startup\r\n" + + "#leave blank to prompt user on startup\r\n" + "#Use \"-\" as password for offline mode\r\n" + "\r\n" + "login=\r\npassword=\r\nserverip=\r\n" @@ -249,7 +258,10 @@ public static void WriteDefaultSettings(string settingsfile) + "\r\n" + "[Scripting]\r\n" + "enabled=false\r\n" - + "scriptfile=testscript.txt\r\n", Encoding.UTF8); + + "scriptfile=testscript.txt\r\n" + + "\r\n" + + "[RemoteControl]\r\n" + + "enabled=false\r\n", Encoding.UTF8); } public static int str2int(string str) { try { return Convert.ToInt32(str); } catch { return 0; } } From 26def01daeb1c27348b3f04b532829b8730cd2bf Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 3 Apr 2014 19:29:13 +0200 Subject: [PATCH 05/13] Added 'connect' remote control command - Causes the bot to connect to the specified server - Idea from TorchRJ_ --- MinecraftClient/Bots.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 3bc881a64b..dea680f31c 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -977,6 +977,13 @@ public override void GetText(string text) if (command.Length >= 6) SendText(command.Substring(5)); break; + case "connect": + if (command.Length >= 9) + { + Settings.ServerIP = command.Substring(8); + ReconnectToTheServer(); + } + break; case "help": if (command.Length >= 6) { @@ -987,11 +994,12 @@ public override void GetText(string text) case "reco": SendPrivateMessage(sender, "reco: restart and reconnct to the server."); break; case "script": SendPrivateMessage(sender, "script : run a script file."); break; case "send": SendPrivateMessage(sender, "send : send a chat message or command."); break; + case "connect": SendPrivateMessage(sender, "connect : connect to the specified server."); break; case "help": SendPrivateMessage(sender, "help : show brief help about a command."); break; default: SendPrivateMessage(sender, "help: unknown command '" + help_cmd_name + "'."); break; } } - else SendPrivateMessage(sender, "help . Available commands: exit, reco, script, send."); + else SendPrivateMessage(sender, "help . Available commands: exit, reco, script, send, connect."); break; default: SendPrivateMessage(sender, "Unknown command '" + cmd_name + "'. Use 'help' for help."); From cd2fe152e6501a56a6b2be22414a0b5782a197c5 Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 9 Apr 2014 18:52:17 +0200 Subject: [PATCH 06/13] Added chat timestamps feature Idea from LehmusFIN --- MinecraftClient/MinecraftCom.cs | 5 +++++ MinecraftClient/Settings.cs | 3 +++ 2 files changed, 8 insertions(+) diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index 66e2cd66aa..26598bf916 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -302,6 +302,11 @@ private static void printstring(string str, bool acceptnewlines) { if (!String.IsNullOrEmpty(str)) { + if (Settings.chatTimeStamps) + { + int hour = DateTime.Now.Hour, minute = DateTime.Now.Minute, second = DateTime.Now.Second; + ConsoleIO.Write(hour.ToString("00") + ':' + minute.ToString("00") + ':' + second.ToString("00") + ' '); + } if (!acceptnewlines) { str = str.Replace('\n', ' '); } if (ConsoleIO.basicIO) { ConsoleIO.WriteLine(str); return; } string[] subs = str.Split(new char[] { '§' }); diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 52916423e3..dad3ecb563 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -29,6 +29,7 @@ public static class Settings public static string TranslationsFile_Website_Download = "http://resources.download.minecraft.net"; public static List Bots_Owners = new List(); public static string Language = "en_GB"; + public static bool chatTimeStamps = false; //AntiAFK Settings public static bool AntiAFK_Enabled = false; @@ -122,6 +123,7 @@ public static void LoadSettings(string settingsfile) case "singlecommand": SingleCommand = argValue; break; case "language": Language = argValue; break; case "consoletitle": ConsoleTitle = argValue; break; + case "timestamps": chatTimeStamps = str2bool(argValue); break; case "botowners": Bots_Owners.Clear(); foreach (string name in argValue.ToLower().Replace(" ", "").Split(',')) @@ -225,6 +227,7 @@ public static void WriteDefaultSettings(string settingsfile) + "language=en_GB\r\n" + "botowners=Player1,Player2,Player3\r\n" + "consoletitle=%username% - Minecraft Console Client\r\n" + + "timestamps=false\r\n" + "\r\n" + "#Bot Settings\r\n" + "\r\n" From b0e4e993ce19dd372c39955e516d697131514d87 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 10 Apr 2014 16:13:30 +0200 Subject: [PATCH 07/13] Hold on scripts when reconnecting + login 503 - Added "connect" command in scripts (idea from TorchRJ_) - Handle 503 service unavailable error for Minecraft logins - Renamed [Scripting] into [StartupScript] (more explicit) - Startup Script only runs once even using /reco but ... - Scripts are now kept and resumed when (re)connecting --- MinecraftClient/Bots.cs | 7 +++++++ MinecraftClient/MinecraftCom.cs | 16 +++++++++++++++- MinecraftClient/Program.cs | 3 ++- MinecraftClient/Settings.cs | 14 +++++++------- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index dea680f31c..e4b392a7d2 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -931,6 +931,13 @@ public override void Update() case "exit": //Exit bot & stay connected to the server UnloadBot(); break; + case "connect": + if (instruction_line.Length >= 9) + { + Settings.ServerIP = instruction_line.Substring(8); + ReconnectToTheServer(); + } + break; default: sleepticks = 0; Update(); //Unknown command : process next line immediately break; diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index 26598bf916..a275be792e 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -15,7 +15,7 @@ public class MinecraftCom : IAutoComplete { #region Login to Minecraft.net and get a new session ID - public enum LoginResult { OtherError, SSLError, Success, WrongPassword, Blocked, AccountMigrated, NotPremium }; + public enum LoginResult { OtherError, ServiceUnavailable, SSLError, Success, WrongPassword, Blocked, AccountMigrated, NotPremium }; /// /// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme. @@ -66,6 +66,10 @@ public static LoginResult GetLogin(ref string user, string pass, ref string acce else return LoginResult.WrongPassword; } } + else if ((int)response.StatusCode == 503) + { + return LoginResult.ServiceUnavailable; + } else return LoginResult.Blocked; } else if (e.Status == WebExceptionStatus.SendFailure) @@ -110,6 +114,11 @@ public static bool SessionCheck(string uuid, string accesstoken, string serverha bool encrypted = false; int protocolversion; + public MinecraftCom() + { + foreach (ChatBot bot in scripts_on_hold) { bots.Add(bot); } + scripts_on_hold.Clear(); + } public bool Update() { for (int i = 0; i < bots.Count; i++) { bots[i].Update(); } @@ -586,9 +595,14 @@ public void Disconnect(string message) catch (System.IO.IOException) { } catch (NullReferenceException) { } catch (ObjectDisposedException) { } + + foreach (ChatBot bot in bots) + if (bot is Bots.Scripting) + scripts_on_hold.Add((Bots.Scripting)bot); } private List bots = 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 55eaf4967a..80c36c2c9f 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -162,7 +162,7 @@ private static void InitializeClient() 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.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); } + if (Settings.StartupScript_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); } //Start the main TCP client @@ -192,6 +192,7 @@ private static void InitializeClient() { case MinecraftCom.LoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break; case MinecraftCom.LoginResult.Blocked: Console.WriteLine("Too many failed logins. Please try again later."); break; + case MinecraftCom.LoginResult.ServiceUnavailable: Console.WriteLine("Login servers are unavailable. Please try again later."); break; case MinecraftCom.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break; case MinecraftCom.LoginResult.NotPremium: Console.WriteLine("User not premium."); break; case MinecraftCom.LoginResult.OtherError: Console.WriteLine("Network error."); break; diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index dad3ecb563..e693f330e7 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -64,9 +64,9 @@ public static class Settings public static int AutoRelog_Retries = 3; public static string AutoRelog_KickMessagesFile = "kickmessages.txt"; - //Scripting Settings - public static bool Scripting_Enabled = false; - public static string Scripting_ScriptFile = "script.txt"; + //Startup Script Settings + public static bool StartupScript_Enabled = false; + public static string StartupScript_ScriptFile = "script.txt"; //Remote Control public static bool RemoteCtrl_Enabled = false; @@ -101,7 +101,7 @@ public static void LoadSettings(string settingsfile) case "chatlog": pMode = ParseMode.ChatLog; break; case "hangman": pMode = ParseMode.Hangman; break; case "main": pMode = ParseMode.Main; break; - case "scripting": pMode = ParseMode.Scripting; break; + case "startupscript": pMode = ParseMode.Scripting; break; case "remotecontrol": pMode = ParseMode.RemoteControl; break; default: pMode = ParseMode.Default; break; } @@ -183,8 +183,8 @@ public static void LoadSettings(string settingsfile) case ParseMode.Scripting: switch (argName.ToLower()) { - case "enabled": Scripting_Enabled = str2bool(argValue); break; - case "scriptfile": Scripting_ScriptFile = argValue; break; + case "enabled": StartupScript_Enabled = str2bool(argValue); break; + case "scriptfile": StartupScript_ScriptFile = argValue; break; } break; @@ -259,7 +259,7 @@ public static void WriteDefaultSettings(string settingsfile) + "wordsfile=hangman-en.txt\r\n" + "fichiermots=hangman-fr.txt\r\n" + "\r\n" - + "[Scripting]\r\n" + + "[StartupScript]\r\n" + "enabled=false\r\n" + "scriptfile=testscript.txt\r\n" + "\r\n" From a543620a80cee7b559ee333fcc591cd1f67d52e1 Mon Sep 17 00:00:00 2001 From: ORelio Date: Thu, 10 Apr 2014 19:55:16 +0200 Subject: [PATCH 08/13] 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 e4b392a7d2..44769dbd9d 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -254,7 +254,7 @@ protected void SendPrivateMessage(string player, string message) 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 @@ public override bool OnDisconnect(DisconnectReason reason, string message) /// /// 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 @@ public class Scripting : ChatBot 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 25bbaccee2..78b2c0b228 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -60,8 +60,11 @@ public static string ReadPassword() break; default: - Console.Write('*'); - password += k.KeyChar; + if (k.KeyChar != 0) + { + Console.Write('*'); + password += k.KeyChar; + } break; } } @@ -159,7 +162,15 @@ public static string ReadLine() } 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 8365e6478a..d70ccac484 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -175,7 +175,7 @@ private void StartTalk() } 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 a275be792e..c400af279f 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -597,12 +597,12 @@ public void Disconnect(string message) 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 80c36c2c9f..0220bd8192 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -162,7 +162,7 @@ private static void InitializeClient() 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 From 09bff17fc2e97e1e5846c58cc2234e4744be9f4e Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 4 May 2014 11:25:51 +0200 Subject: [PATCH 09/13] Allow AutoRelog to relog on server login failed - Add some explanations for adding a custom bot in the app - Remove debug code in ConsoleIO (see previous commit) --- MinecraftClient/Bots.cs | 12 +++++++++++- MinecraftClient/ConsoleIO.cs | 7 ------- MinecraftClient/McTcpClient.cs | 4 ++-- MinecraftClient/MinecraftCom.cs | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 44769dbd9d..3739f479c6 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -9,7 +9,17 @@ namespace MinecraftClient /// Welcome to the Bot API file ! /// The virtual class "ChatBot" contains anything you need for creating chat bots /// Inherit from this class while adding your bot class to the namespace "Bots", below. - /// Once your bot is created, simply edit the switch in Program.cs to add the corresponding command-line argument! + /// Once your bot is created, read the explanations below to start using it in the MinecraftClient app. + /// + /// Pieces of code to add in other parts of the program for your bot. Line numbers are approximative. + /// Program.cs:166 | if (Settings.YourBot_Enabled){ handler.BotLoad(new Bots.YourBot()); } + /// Settings.cs:73 | public static bool YourBot_Enabled = false; + /// Settings.cs:74 | private enum ParseMode { /* [...] */, YourBot }; + /// Settings.cs:106| case "yourbot": pMode = ParseMode.YourBot; break; + /// Settings.cs:197| case ParseMode.YourBot: switch (argName.ToLower()) { case "enabled": YourBot_Enabled = str2bool(argValue); break; } break; + /// Settings.cs:267| + "[YourBot]\r\n" + "enabled=false\r\n" + /// Here your are. Now you will have a setting in MinecraftClient.ini for enabling your brand new bot. + /// Delete MinecraftClient.ini to re-generate it or add the lines [YourBot] and enabled=true to the existing one. /// /// diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index 78b2c0b228..86059ebc5a 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -164,13 +164,6 @@ public static string ReadLine() default: 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 d70ccac484..6f1a3adfda 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -119,7 +119,7 @@ private void StartClient(string user, string uuid, string sessionID, string serv else { Console.WriteLine("Login failed."); - if (!singlecommand) { Program.ReadLineReconnect(); } + if (!singlecommand && !handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, "Login failed.")) { Program.ReadLineReconnect(); } } } catch (SocketException) @@ -235,7 +235,7 @@ private void Updater() if (!handler.HasBeenKicked) { ConsoleIO.WriteLine("Connection has been lost."); - if (!handler.OnConnectionLost() && !Program.ReadLineReconnect()) { t_sender.Abort(); } + if (!handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost.") && !Program.ReadLineReconnect()) { t_sender.Abort(); } } else if (Program.ReadLineReconnect()) { t_sender.Abort(); } } diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index c400af279f..0cf791124d 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -183,14 +183,14 @@ public void DebugDump() System.IO.File.WriteAllText("debug.txt", dump); System.Diagnostics.Process.Start("debug.txt"); } - public bool OnConnectionLost() + public bool OnConnectionLost(ChatBot.DisconnectReason reason, string reason_message) { if (!connectionlost) { connectionlost = true; for (int i = 0; i < bots.Count; i++) { - if (bots[i].OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost.")) + if (bots[i].OnDisconnect(reason, reason_message)) { return true; //The client is about to restart } From 3c84c5813e3f5683694fc1200a85d79178a7e137 Mon Sep 17 00:00:00 2001 From: ORelio Date: Tue, 6 May 2014 15:43:50 +0200 Subject: [PATCH 10/13] Mark 1.7.8+ as supported 1.7.8 can be supported without any change. Fix login in MinecraftCom using hardcoded value instead of version --- MinecraftClient/MinecraftCom.cs | 2 +- MinecraftClient/Program.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index 0cf791124d..f3e07fcf51 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -464,7 +464,7 @@ public static bool GetServerInfo(string serverIP, ref int protocolversion, ref s public bool Login(string username, string uuid, string sessionID, string host, int port) { byte[] packet_id = getVarInt(0); - byte[] protocol_version = getVarInt(4); + byte[] protocol_version = getVarInt(protocolversion); byte[] server_adress_val = Encoding.UTF8.GetBytes(host); byte[] server_adress_len = getVarInt(server_adress_val.Length); byte[] server_port = BitConverter.GetBytes((ushort)port); Array.Reverse(server_port); diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 0220bd8192..558aff9259 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -143,7 +143,7 @@ private static void InitializeClient() if (MinecraftCom.GetServerInfo(Settings.ServerIP, ref protocolversion, ref version)) { //Supported protocol version ? - int[] supportedVersions = { 4 }; + int[] supportedVersions = { 4, 5 }; if (Array.IndexOf(supportedVersions, protocolversion) > -1) { //Load translations (Minecraft 1.6+) From 22c47e99c25417680a3aa8cab02ecdd34139b096 Mon Sep 17 00:00:00 2001 From: ORelio Date: Tue, 6 May 2014 22:41:14 +0200 Subject: [PATCH 11/13] Add ScriptScheduler bot - Allow to launch script on various events - Removed startup script, now part of ScriptScheduler - ScriptScheduler is configured using its own INI file - Can launch scripts on first login, login and/or specific time --- MinecraftClient/Bots.cs | 172 ++++++++++++++++++++++++++++++++---- MinecraftClient/Program.cs | 17 ++-- MinecraftClient/Settings.cs | 18 ++-- 3 files changed, 176 insertions(+), 31 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 3739f479c6..afb7af4649 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Globalization; namespace MinecraftClient { @@ -866,41 +867,46 @@ public Script(string filename, string ownername) owner = ownername; } - public override void Initialize() + public static bool lookForScript(ref string filename) { - //Load the given file from the startup parameters //Automatically look in subfolders and try to add ".txt" file extension string[] files = new string[] { - file, - file + ".txt", - "scripts\\" + file, - "scripts\\" + file + ".txt", - "config\\" + file, - "config\\" + file + ".txt", + filename, + filename + ".txt", + "scripts\\" + filename, + "scripts\\" + filename + ".txt", + "config\\" + filename, + "config\\" + filename + ".txt", }; - bool file_found = false; - foreach (string possible_file in files) { if (System.IO.File.Exists(possible_file)) { - lines = System.IO.File.ReadAllLines(possible_file); - file_found = true; - break; + filename = possible_file; + return true; } } - if (!file_found) + return false; + } + + public override void Initialize() + { + //Load the given file from the startup parameters + if (lookForScript(ref file)) + { + lines = System.IO.File.ReadAllLines(file); + if (owner != null) { SendPrivateMessage(owner, "Script '" + file + "' loaded."); } + } + else { LogToConsole("File not found: '" + file + "'"); if (owner != null) SendPrivateMessage(owner, "File not found: '" + file + "'"); UnloadBot(); //No need to keep the bot active } - else if (owner != null) - SendPrivateMessage(owner, "Script '" + file + "' loaded."); } public override void Update() @@ -963,6 +969,140 @@ public override void Update() } } + /// + /// Trigger scripts on specific events + /// + + public class ScriptScheduler : ChatBot + { + private class TaskDesc + { + public string script_file = null; + public bool triggerOnFirstLogin = false; + public bool triggerOnLogin = false; + public bool triggerOnTime = false; + public List triggerOnTime_Times = new List(); + public bool alreadyTriggered = false; + } + + private static bool firstlogin_done = false; + + private string tasksfile; + private bool serverlogin_done; + private List tasks = new List(); + private int verifytasks_timeleft = 10; + private int verifytasks_delay = 10; + + public ScriptScheduler(string tasksfile) + { + this.tasksfile = tasksfile; + serverlogin_done = false; + } + + public override void Initialize() + { + //Load the given file from the startup parameters + if (System.IO.File.Exists(tasksfile)) + { + TaskDesc current_task = null; + String[] lines = System.IO.File.ReadAllLines(tasksfile); + foreach (string lineRAW in lines) + { + string line = lineRAW.Split('#')[0].Trim(); + if (line.Length > 0) + { + if (line[0] == '[' && line[line.Length - 1] == ']') + { + switch (line.Substring(1, line.Length - 2).ToLower()) + { + case "task": + checkAddTask(current_task); + current_task = new TaskDesc(); //Create a blank task + break; + } + } + else if (current_task != null) + { + string argName = line.Split('=')[0]; + if (line.Length > (argName.Length + 1)) + { + string argValue = line.Substring(argName.Length + 1); + switch (argName.ToLower()) + { + case "triggeronfirstlogin": current_task.triggerOnFirstLogin = Settings.str2bool(argValue); break; + case "triggeronlogin": current_task.triggerOnLogin = Settings.str2bool(argValue); break; + case "triggerontime": current_task.triggerOnTime = Settings.str2bool(argValue); break; + case "timevalue": try { current_task.triggerOnTime_Times.Add(DateTime.ParseExact(argValue, "HH:mm", CultureInfo.InvariantCulture)); } catch { } break; + case "script": current_task.script_file = argValue; break; + } + } + } + } + } + checkAddTask(current_task); + } + else + { + LogToConsole("File not found: '" + tasksfile + "'"); + UnloadBot(); //No need to keep the bot active + } + } + + private void checkAddTask(TaskDesc current_task) + { + if (current_task != null) + { + //Check if we built a valid task before adding it + if (current_task.script_file != null && Script.lookForScript(ref current_task.script_file) //Check if file exists + && (current_task.triggerOnLogin || (current_task.triggerOnTime && current_task.triggerOnTime_Times.Count > 0))) //Look for a valid trigger + { + tasks.Add(current_task); + } + } + } + + public override void Update() + { + if (verifytasks_timeleft <= 0) + { + verifytasks_timeleft = verifytasks_delay; + if (serverlogin_done) + { + foreach (TaskDesc task in tasks) + { + if (task.triggerOnTime) + { + foreach (DateTime time in task.triggerOnTime_Times) + { + if (time.Hour == DateTime.Now.Hour && time.Minute == DateTime.Now.Minute) + { + if (!task.alreadyTriggered) + { + task.alreadyTriggered = true; + RunScript(task.script_file); + } + } + } + } + else task.alreadyTriggered = false; + } + } + else + { + foreach (TaskDesc task in tasks) + { + if (task.triggerOnLogin || (firstlogin_done == false && task.triggerOnFirstLogin)) + RunScript(task.script_file); + } + + firstlogin_done = true; + serverlogin_done = true; + } + } + else verifytasks_timeleft--; + } + } + /// /// Allow to perform operations using whispers to the bot /// diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 558aff9259..0a0f824020 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -156,14 +156,15 @@ private static void InitializeClient() handler.setVersion(protocolversion); //Load & initialize bots if needed - if (Settings.AntiAFK_Enabled) { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); } - if (Settings.Hangman_Enabled) { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); } - if (Settings.Alerts_Enabled) { handler.BotLoad(new Bots.Alerts()); } - 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.Script(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } - if (Settings.RemoteCtrl_Enabled){ handler.BotLoad(new Bots.RemoteControl()); } + if (Settings.AntiAFK_Enabled) { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); } + if (Settings.Hangman_Enabled) { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); } + if (Settings.Alerts_Enabled) { handler.BotLoad(new Bots.Alerts()); } + 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.Script(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } + if (Settings.ScriptScheduler_Enabled) { handler.BotLoad(new Bots.ScriptScheduler(Settings.ScriptScheduler_TasksFile)); } + if (Settings.RemoteCtrl_Enabled) { handler.BotLoad(new Bots.RemoteControl()); } //Start the main TCP client if (Settings.SingleCommand != "") diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index e693f330e7..e0061b16aa 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -68,10 +68,14 @@ public static class Settings public static bool StartupScript_Enabled = false; public static string StartupScript_ScriptFile = "script.txt"; + //Script Scheduler Settings + public static bool ScriptScheduler_Enabled = false; + public static string ScriptScheduler_TasksFile = "tasks.ini"; + //Remote Control public static bool RemoteCtrl_Enabled = false; - private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, Scripting, RemoteControl }; + private enum ParseMode { Default, Main, AntiAFK, Hangman, Alerts, ChatLog, AutoRelog, ScriptScheduler, RemoteControl }; /// /// Load settings from the give INI file @@ -101,7 +105,7 @@ public static void LoadSettings(string settingsfile) case "chatlog": pMode = ParseMode.ChatLog; break; case "hangman": pMode = ParseMode.Hangman; break; case "main": pMode = ParseMode.Main; break; - case "startupscript": pMode = ParseMode.Scripting; break; + case "scriptscheduler": pMode = ParseMode.ScriptScheduler; break; case "remotecontrol": pMode = ParseMode.RemoteControl; break; default: pMode = ParseMode.Default; break; } @@ -180,11 +184,11 @@ public static void LoadSettings(string settingsfile) } break; - case ParseMode.Scripting: + case ParseMode.ScriptScheduler: switch (argName.ToLower()) { - case "enabled": StartupScript_Enabled = str2bool(argValue); break; - case "scriptfile": StartupScript_ScriptFile = argValue; break; + case "enabled": ScriptScheduler_Enabled = str2bool(argValue); break; + case "tasksfile": ScriptScheduler_TasksFile = argValue; break; } break; @@ -259,9 +263,9 @@ public static void WriteDefaultSettings(string settingsfile) + "wordsfile=hangman-en.txt\r\n" + "fichiermots=hangman-fr.txt\r\n" + "\r\n" - + "[StartupScript]\r\n" + + "[ScriptScheduler]\r\n" + "enabled=false\r\n" - + "scriptfile=testscript.txt\r\n" + + "tasksfile=tasks.ini\r\n" + "\r\n" + "[RemoteControl]\r\n" + "enabled=false\r\n", Encoding.UTF8); From 49a2d2b681af8231512ba408f8d3eb1955435165 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sat, 10 May 2014 21:03:03 +0200 Subject: [PATCH 12/13] Add support for %username% on log & task files - Allows to use different files depending on the username - Also, added a setting for disabling "beep" sound in Alerts bot --- MinecraftClient/Bots.cs | 2 +- MinecraftClient/Program.cs | 7 +++---- MinecraftClient/Settings.cs | 7 +++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index afb7af4649..8260fcb686 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -610,7 +610,7 @@ public override void GetText(string text) if (ok) { - Console.Beep(); //Text found ! + if (Settings.Alerts_Beep_Enabled) { Console.Beep(); } //Text found ! if (ConsoleIO.basicIO) { ConsoleIO.WriteLine(comp.Replace(alert, "§c" + alert + "§r")); } else { diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 0a0f824020..2328d50701 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -159,11 +159,10 @@ private static void InitializeClient() if (Settings.AntiAFK_Enabled) { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); } if (Settings.Hangman_Enabled) { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); } if (Settings.Alerts_Enabled) { handler.BotLoad(new Bots.Alerts()); } - 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.ChatLog_Enabled) { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File.Replace("%username%", Settings.Username), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); } + if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File.Replace("%username%", Settings.Username))); } if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); } - if (Settings.StartupScript_Enabled) { handler.BotLoad(new Bots.Script(Settings.StartupScript_ScriptFile)); Settings.StartupScript_Enabled = false; } - if (Settings.ScriptScheduler_Enabled) { handler.BotLoad(new Bots.ScriptScheduler(Settings.ScriptScheduler_TasksFile)); } + if (Settings.ScriptScheduler_Enabled) { handler.BotLoad(new Bots.ScriptScheduler(Settings.ScriptScheduler_TasksFile.Replace("%username%", Settings.Username))); } if (Settings.RemoteCtrl_Enabled) { handler.BotLoad(new Bots.RemoteControl()); } //Start the main TCP client diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index e0061b16aa..fb0324061f 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -44,6 +44,7 @@ public static class Settings //Alerts Settings public static bool Alerts_Enabled = false; + public static bool Alerts_Beep_Enabled = true; public static string Alerts_MatchesFile = "alerts.txt"; public static string Alerts_ExcludesFile = "alerts-exclude.txt"; @@ -64,10 +65,6 @@ public static class Settings public static int AutoRelog_Retries = 3; public static string AutoRelog_KickMessagesFile = "kickmessages.txt"; - //Startup Script Settings - public static bool StartupScript_Enabled = false; - public static string StartupScript_ScriptFile = "script.txt"; - //Script Scheduler Settings public static bool ScriptScheduler_Enabled = false; public static string ScriptScheduler_TasksFile = "tasks.ini"; @@ -142,6 +139,7 @@ public static void LoadSettings(string settingsfile) case "enabled": Alerts_Enabled = str2bool(argValue); break; case "alertsfile": Alerts_MatchesFile = argValue; break; case "excludesfile": Alerts_ExcludesFile = argValue; break; + case "beeponalert": Alerts_Beep_Enabled = str2bool(argValue); break; } break; @@ -239,6 +237,7 @@ public static void WriteDefaultSettings(string settingsfile) + "enabled=false\r\n" + "alertsfile=alerts.txt\r\n" + "excludesfile=alerts-exclude.txt\r\n" + + "beeponalert=true\r\n" + "\r\n" + "[AntiAFK]\r\n" + "enabled=false\r\n" From 879c124d6ac6444bc9e8c383658a8ddd73da5a4b Mon Sep 17 00:00:00 2001 From: ORelio Date: Wed, 14 May 2014 21:39:26 +0200 Subject: [PATCH 13/13] Last changes for 1.7.3 release Change config files. Change version number. --- MinecraftClient/Program.cs | 4 +-- MinecraftClient/config/bot-owners.txt | 2 -- .../{hangman-words.txt => hangman-en.txt} | 2 +- .../{hangman-mots.txt => hangman-fr.txt} | 0 MinecraftClient/config/sample-script.txt | 13 +++++++ MinecraftClient/config/sample-tasks.ini | 34 +++++++++++++++++++ MinecraftClient/config/testscript.txt | 4 --- 7 files changed, 50 insertions(+), 9 deletions(-) delete mode 100644 MinecraftClient/config/bot-owners.txt rename MinecraftClient/config/{hangman-words.txt => hangman-en.txt} (99%) rename MinecraftClient/config/{hangman-mots.txt => hangman-fr.txt} (100%) create mode 100644 MinecraftClient/config/sample-script.txt create mode 100644 MinecraftClient/config/sample-tasks.ini delete mode 100644 MinecraftClient/config/testscript.txt diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 2328d50701..03d511c687 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -15,7 +15,7 @@ class Program { private static McTcpClient Client; public static string[] startupargs; - public const string Version = "1.7.2"; + public const string Version = "1.7.3"; /// /// The main entry point of Minecraft Console Client @@ -23,7 +23,7 @@ class Program static void Main(string[] args) { - Console.WriteLine("Console Client for MC 1.7.2 to 1.7.5 - v" + Version + " - By ORelio & Contributors"); + Console.WriteLine("Console Client for MC 1.7.2 to 1.7.9 - v" + Version + " - By ORelio & Contributors"); //Basic Input/Output ? if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") diff --git a/MinecraftClient/config/bot-owners.txt b/MinecraftClient/config/bot-owners.txt deleted file mode 100644 index 0aa670833a..0000000000 --- a/MinecraftClient/config/bot-owners.txt +++ /dev/null @@ -1,2 +0,0 @@ -ORelio -PutYourNameHere \ No newline at end of file diff --git a/MinecraftClient/config/hangman-words.txt b/MinecraftClient/config/hangman-en.txt similarity index 99% rename from MinecraftClient/config/hangman-words.txt rename to MinecraftClient/config/hangman-en.txt index 6baa9bc1de..8b63285d7d 100644 --- a/MinecraftClient/config/hangman-words.txt +++ b/MinecraftClient/config/hangman-en.txt @@ -20,7 +20,7 @@ CHURCH OFFICE APRICOT PLANISPHERE -WORLDWIDE +WORLD MAP FISHING CASE SADDLE diff --git a/MinecraftClient/config/hangman-mots.txt b/MinecraftClient/config/hangman-fr.txt similarity index 100% rename from MinecraftClient/config/hangman-mots.txt rename to MinecraftClient/config/hangman-fr.txt diff --git a/MinecraftClient/config/sample-script.txt b/MinecraftClient/config/sample-script.txt new file mode 100644 index 0000000000..314fe6d85c --- /dev/null +++ b/MinecraftClient/config/sample-script.txt @@ -0,0 +1,13 @@ +# This is a sample script for Minecraft Console Client +# Any line beginning with "#" is ignored and treated as a comment. +# Allowed instructions: send, wait, disconnect, exit +# send : send a message or a command to the server +# wait