diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 53a3ebec..4cb0ad87 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -845,11 +845,65 @@ namespace MinecraftClient /// /// Runs a list of commands /// Usage: bot:scripting:filename + /// Script must be placed in the config directory /// public class scripting : ChatBot { + private string file; + private string[] lines = new string[0]; + public scripting(string filename) + { + file = filename; + } + public override void Initialize() + { + // Loads the given file from the startup parameters + if (System.IO.File.Exists("config/" + file)) + { + lines = System.IO.File.ReadAllLines("config/" + file); // Load the given bot text file (containing commands) + for (int i = 0; i < lines.Length; i++) // Parse through each line of the bot text file + { + System.Threading.Thread.Sleep(100); + + string this_line = lines[i].Trim(); // Removes all whitespaces at start and end of current line + + if (this_line.Length == 0) { + // Skip a completely empty line + } + else if (this_line.Trim().StartsWith("//")) + { + Console.ForegroundColor = ConsoleColor.DarkGray; + Console.WriteLine("BOT:" + this_line); + Console.ForegroundColor = ConsoleColor.Gray; + // Don't do anything for a comment line, denoted by '//' + } + else if (this_line.StartsWith("send ")) + { + Console.ForegroundColor = ConsoleColor.Gray; + SendText((lines[i].Trim().Substring(5, lines[i].Length - 5))); + // Send the command + } + else if (this_line.StartsWith("wait ")) + { + Console.ForegroundColor = ConsoleColor.DarkGray; + Console.WriteLine("BOT:Pausing for " + Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100 + "ms..."); + Console.ForegroundColor = ConsoleColor.Gray; + System.Threading.Thread.Sleep(Convert.ToInt32(lines[i].Substring(5, lines[i].Length - 5)) * 100); + // Do a wait (given in milliseconds) + } + else if (this_line.StartsWith("exit")) { + //Program.Client.Disconnect(); + } // Optional exit only if called in bot text file, + } + UnloadBot(); // Otherwise continue operation of Client to normal (non-bot) usage + } + else + { + Console.WriteLine(file + " not found! Please make sure that the file is located in the config directory."); + } + } } } } diff --git a/MinecraftClient/ChatParser.cs b/MinecraftClient/ChatParser.cs index b0d07e3f..a8c7e6d0 100644 --- a/MinecraftClient/ChatParser.cs +++ b/MinecraftClient/ChatParser.cs @@ -8,7 +8,7 @@ namespace MinecraftClient /// /// This class parses JSON chat data from MC 1.6+ and returns the appropriate string to be printed. /// - + static class ChatParser { /// @@ -54,11 +54,11 @@ namespace MinecraftClient private static string color2tag(string colorname) { - switch(colorname.ToLower()) + switch (colorname.ToLower()) { case "black": return "§0"; case "dark_blue": return "§1"; - case "dark_green" : return "§2"; + case "dark_green": return "§2"; case "dark_cyan": return "§3"; case "dark_cyanred": return "§4"; case "dark_magenta": return "§5"; @@ -278,7 +278,7 @@ namespace MinecraftClient return colorcode + TranslateString(JSONData2String(data.Properties["translate"]), using_data) + colorcode; } else return ""; - + case JSONData.DataType.Array: string result = ""; foreach (JSONData item in data.DataArray) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index e31f280e..3cdebfa2 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -141,7 +141,7 @@ namespace MinecraftClient ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)..."); Thread.Sleep(5000); AttemptsLeft--; Program.Restart(); } - else if (!singlecommand){ Console.ReadLine(); } + else if (!singlecommand) { Console.ReadLine(); } } } @@ -156,6 +156,11 @@ namespace MinecraftClient { while (client.Client.Connected) { + if (Program.scripting_enabled) + { + handler.BotLoad(new Bots.scripting(Program.scripting_param)); + Program.scripting_enabled = false; + } text = ConsoleIO.ReadLine(); if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; } while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); } diff --git a/MinecraftClient/MinecraftClient.csproj.user b/MinecraftClient/MinecraftClient.csproj.user index 1aaa11ad..40f6ad1f 100644 --- a/MinecraftClient/MinecraftClient.csproj.user +++ b/MinecraftClient/MinecraftClient.csproj.user @@ -1,8 +1,7 @@  - - + user - 127.0.0.1 bot:scripting publish\ diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index 8e6affa7..44112f4d 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -16,7 +16,7 @@ namespace MinecraftClient #region Login to Minecraft.net, Obtaining a session ID public enum LoginResult { Error, Success, WrongPassword, Blocked, AccountMigrated, NotPremium }; - + /// /// Allows to login to a premium Minecraft account, and retrieve the session ID. /// @@ -31,7 +31,8 @@ namespace MinecraftClient { Console.ForegroundColor = ConsoleColor.DarkGray; WebClient wClient = new WebClient(); - Console.WriteLine("https://login.minecraft.net/?user=" + user + "&password=<******>&version=13"); + string str_len = new String('*', pass.Length); + Console.WriteLine("https://login.minecraft.net/?user=" + user + "&password=<" + str_len + ">&version=13"); string result = wClient.DownloadString("https://login.minecraft.net/?user=" + user + "&password=" + pass + "&version=13"); outdata = result; Console.WriteLine(result); @@ -133,7 +134,7 @@ namespace MinecraftClient //If the client gets out of sync, check the last green packet processing code. //if (result == ProcessResult.OK) { printstring("§a0x" + id.ToString("X"), false); } //else { printstring("§c0x" + id.ToString("X"), false); } - + if (result == ProcessResult.ConnectionLost) { return false; diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 73431430..4eb5a02c 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -13,6 +13,10 @@ namespace MinecraftClient class Program { + // Scripting Bot Parameters - bearbear12345 + public static bool scripting_enabled; + public static string scripting_param; + // End Scripting Bot Parameters private static McTcpClient Client; private static string loginusername = ""; private static string user = ""; @@ -50,17 +54,20 @@ namespace MinecraftClient //Asking the user to type in missing data such as Username and Password - if (user == "") { + if (user == "") + { Console.Write("Username : "); user = Console.ReadLine(); } - if (pass == "") { + if (pass == "") + { Console.Write("Password : "); pass = Console.ReadLine(); //Hide the password Console.CursorTop--; - Console.Write("Password : <******>"); + string str_len = new String('*', pass.Length); + Console.Write("Password : <" + str_len + ">"); for (int i = 19; i < Console.BufferWidth; i++) { Console.Write(' '); } } @@ -78,6 +85,7 @@ namespace MinecraftClient private static void InitializeClient() { + MinecraftCom.LoginResult result; string logindata = ""; @@ -199,12 +207,24 @@ namespace MinecraftClient case "xauth": if (botargs.Length > 2) { handler.BotLoad(new Bots.xAuth(botargs[2])); } break; + case "scripting": + if (botargs.Length > 2) + { + scripting_enabled = true; + scripting_param = botargs[2]; + //handler.BotLoad(new Bots.scripting(botargs[2])); + } + else + { + scripting_enabled = true; + scripting_param = "scripting.txt"; + //Launches later on after connected in MinecraftCom.cs + } + break; } - command = ""; } } - //Start the main TCP client if (command != "") { diff --git a/MinecraftClient/resources/appicon.ico b/MinecraftClient/resources/appicon.ico index 5acb0dc9..d3009de9 100644 Binary files a/MinecraftClient/resources/appicon.ico and b/MinecraftClient/resources/appicon.ico differ