diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..eb874f6b91 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/MinecraftClient.v11.suo \ No newline at end of file diff --git a/MinecraftClient/.gitignore b/MinecraftClient/.gitignore new file mode 100644 index 0000000000..4ded7c4c7a --- /dev/null +++ b/MinecraftClient/.gitignore @@ -0,0 +1,2 @@ +/bin/ +/obj/ diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index e9187c18cd..234acbe01b 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -486,14 +486,14 @@ private void start() private string chooseword() { - if (System.IO.File.Exists(English ? "words.txt" : "mots.txt")) + if (System.IO.File.Exists(English ? "config/hangman-words.txt" : "config/pendu-mots.txt")) { string[] dico = System.IO.File.ReadAllLines(English ? "words.txt" : "mots.txt"); return dico[new Random().Next(dico.Length)]; } else { - LogToConsole(English ? "Cannot find words.txt !" : "Fichier mots.txt introuvable !"); + LogToConsole(English ? "Cannot find words.txt in config directory !" : "Fichier mots.txt introuvable dans config/hangman dossier!"); return English ? "WORDSAREMISSING" : "DICOMANQUANT"; } } @@ -502,14 +502,14 @@ private string[] getowners() { List owners = new List(); owners.Add("CONSOLE"); - if (System.IO.File.Exists("bot-owners.txt")) + if (System.IO.File.Exists("config/bot-owners.txt")) { - foreach (string s in System.IO.File.ReadAllLines("bot-owners.txt")) + foreach (string s in System.IO.File.ReadAllLines("config/bot-owners.txt")) { owners.Add(s.ToUpper()); } } - else LogToConsole(English ? "Cannot find bot-owners.txt !" : "Fichier bot-owners.txt introuvable !"); + else LogToConsole(English ? "Cannot find bot-owners.txt in config folder!" : "Fichier bot-owners.txt introuvable dans config!"); return owners.ToArray(); } @@ -552,39 +552,39 @@ private bool winner public class Alerts : ChatBot { - private string[] dictionnary = new string[0]; + private string[] dictionary = new string[0]; private string[] excludelist = new string[0]; public override void Initialize() { - if (System.IO.File.Exists("alerts.txt")) + if (System.IO.File.Exists("config/alerts.txt")) { - dictionnary = System.IO.File.ReadAllLines("alerts.txt"); + dictionary = System.IO.File.ReadAllLines("config/alerts.txt"); - for (int i = 0; i < dictionnary.Length; i++) + for (int i = 0; i < dictionary.Length; i++) { - dictionnary[i] = dictionnary[i].ToLower(); + dictionary[i] = dictionary[i].ToLower(); } } - else LogToConsole("Cannot find alerts.txt !"); + else LogToConsole("Cannot find alerts.txt in the config folder!"); - if (System.IO.File.Exists("alerts-exclude.txt")) + if (System.IO.File.Exists("config/alerts-exclude.txt")) { - excludelist = System.IO.File.ReadAllLines("alerts-exclude.txt"); + excludelist = System.IO.File.ReadAllLines("config/alerts-exclude.txt"); for (int i = 0; i < excludelist.Length; i++) { excludelist[i] = excludelist[i].ToLower(); } } - else LogToConsole("Cannot find alerts-exclude.txt !"); + else LogToConsole("Cannot find alerts-exclude.txt in the config folder!"); } public override void GetText(string text) { text = getVerbatim(text); string comp = text.ToLower(); - foreach (string alert in dictionnary) + foreach (string alert in dictionary) { if (comp.Contains(alert)) { @@ -764,7 +764,7 @@ private void save(string tosave) public class AutoRelog : ChatBot { - private string[] dictionnary = new string[0]; + private string[] dictionary = new string[0]; private int attempts; private int delay; @@ -786,23 +786,23 @@ public AutoRelog(int DelayBeforeRelog, int retries) public override void Initialize() { McTcpClient.AttemptsLeft = attempts; - if (System.IO.File.Exists("kickmessages.txt")) + if (System.IO.File.Exists("config/kickmessages.txt")) { - dictionnary = System.IO.File.ReadAllLines("kickmessages.txt"); + dictionary = System.IO.File.ReadAllLines("config/kickmessages.txt"); - for (int i = 0; i < dictionnary.Length; i++) + for (int i = 0; i < dictionary.Length; i++) { - dictionnary[i] = dictionnary[i].ToLower(); + dictionary[i] = dictionary[i].ToLower(); } } - else LogToConsole("Cannot find kickmessages.txt !"); + else LogToConsole("Cannot find kickmessages.txt in the config directory!"); } public override bool OnDisconnect(DisconnectReason reason, string message) { message = getVerbatim(message); string comp = message.ToLower(); - foreach (string msg in dictionnary) + foreach (string msg in dictionary) { if (comp.Contains(msg)) { @@ -841,5 +841,71 @@ public override void Update() } } } + + /// + /// 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.B_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 b0d07e3f84..a8c7e6d021 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 @@ public JSONData(DataType datatype) 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 @@ private static string JSONData2String(JSONData data) 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 e31f280e98..3cdebfa22b 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -141,7 +141,7 @@ private void StartClient(string user, string sessionID, string server_port, bool 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 @@ private void StartTalk() { 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 b/MinecraftClient/MinecraftClient.csproj index b1b033e61d..00eea43f44 100644 --- a/MinecraftClient/MinecraftClient.csproj +++ b/MinecraftClient/MinecraftClient.csproj @@ -52,6 +52,13 @@ false + + resources\appicon.ico + + + MinecraftClient.Program + + False @@ -110,11 +117,12 @@ - - - - - + + + + + +