diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 4da3f2963a..8260fcb686 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 { @@ -9,7 +10,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. /// /// @@ -235,6 +246,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.Script(filename, playername)); + } + #endregion } @@ -355,7 +388,6 @@ public class Pendu : ChatBot private bool[] discovered; private string word = ""; private string letters = ""; - private string[] owners; private bool English; /// @@ -368,11 +400,6 @@ public Pendu(bool english) English = english; } - public override void Initialize() - { - owners = getowners(); - } - public override void Update() { if (running) @@ -398,7 +425,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 +522,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 @@ -598,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 { @@ -830,78 +842,69 @@ 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 - /// 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]; private int sleepticks = 10; private int sleepticks_interval = 10; private int nextline = 0; - public Scripting(string filename) + private string owner; + + public Script(string filename) { file = filename; } - public override void Initialize() + public Script(string filename, string ownername) + :this(filename) + { + if (ownername != "") + owner = ownername; + } + + 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 } } @@ -942,6 +945,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; @@ -958,5 +968,200 @@ 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 + /// + + 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 "connect": + if (command.Length >= 9) + { + Settings.ServerIP = command.Substring(8); + ReconnectToTheServer(); + } + 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 "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, connect."); + break; + default: + SendPrivateMessage(sender, "Unknown command '" + cmd_name + "'. Use 'help' for help."); + break; + } + } + } + } } } diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index 25bbaccee2..86059ebc5a 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,8 @@ public static string ReadLine() } break; default: - AddChar(k.KeyChar); + if (k.KeyChar != 0) + AddChar(k.KeyChar); break; } } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 8365e6478a..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) @@ -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 != "") { @@ -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 e31e493d95..f3e07fcf51 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(); } @@ -174,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 } @@ -302,6 +311,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[] { '§' }); @@ -450,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); @@ -580,9 +594,15 @@ public void Disconnect(string message) catch (SocketException) { } catch (System.IO.IOException) { } catch (NullReferenceException) { } + catch (ObjectDisposedException) { } + + foreach (ChatBot bot in bots) + 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(); 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 a35c723620..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") @@ -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 - } - } - } } } } @@ -228,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+) @@ -241,14 +156,14 @@ 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.xAuth_Enabled) { handler.BotLoad(new Bots.xAuth(Settings.xAuth_Password)); } - if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); } + 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.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.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 if (Settings.SingleCommand != "") @@ -277,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 6c82bc09ca..fb0324061f 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -27,8 +27,9 @@ 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(); public static string Language = "en_GB"; + public static bool chatTimeStamps = false; //AntiAFK Settings public static bool AntiAFK_Enabled = false; @@ -43,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"; @@ -63,16 +65,14 @@ 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 = ""; + //Script Scheduler Settings + public static bool ScriptScheduler_Enabled = false; + public static string ScriptScheduler_TasksFile = "tasks.ini"; - //Scripting 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, ScriptScheduler, RemoteControl }; /// /// Load settings from the give INI file @@ -102,7 +102,8 @@ 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 "scriptscheduler": pMode = ParseMode.ScriptScheduler; break; + case "remotecontrol": pMode = ParseMode.RemoteControl; break; default: pMode = ParseMode.Default; break; } } @@ -122,8 +123,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 "timestamps": chatTimeStamps = str2bool(argValue); break; + case "botowners": + Bots_Owners.Clear(); + foreach (string name in argValue.ToLower().Replace(" ", "").Split(',')) + Bots_Owners.Add(name); + break; } break; @@ -133,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; @@ -175,11 +182,18 @@ public static void LoadSettings(string settingsfile) } break; - case ParseMode.Scripting: + case ParseMode.ScriptScheduler: switch (argName.ToLower()) { - case "enabled": Scripting_Enabled = str2bool(argValue); break; - case "scriptfile": Scripting_ScriptFile = argValue; break; + case "enabled": ScriptScheduler_Enabled = str2bool(argValue); break; + case "tasksfile": ScriptScheduler_TasksFile = argValue; break; + } + break; + + case ParseMode.RemoteControl: + switch (argName.ToLower()) + { + case "enabled": RemoteCtrl_Enabled = str2bool(argValue); break; } break; } @@ -205,7 +219,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" @@ -213,8 +227,9 @@ 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" + + "timestamps=false\r\n" + "\r\n" + "#Bot Settings\r\n" + "\r\n" @@ -222,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" @@ -246,9 +262,12 @@ public static void WriteDefaultSettings(string settingsfile) + "wordsfile=hangman-en.txt\r\n" + "fichiermots=hangman-fr.txt\r\n" + "\r\n" - + "[Scripting]\r\n" + + "[ScriptScheduler]\r\n" + "enabled=false\r\n" - + "scriptfile=testscript.txt\r\n", Encoding.UTF8); + + "tasksfile=tasks.ini\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; } } 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