diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 105cd540..3bc881a6 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -235,6 +235,28 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient } } } + + /// + /// 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 e887b96c..55eaf496 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -163,6 +163,7 @@ namespace MinecraftClient 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 64c63e99..52916423 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -27,7 +27,7 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient 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 @@ namespace MinecraftClient + "[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 @@ namespace MinecraftClient + "\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; } }