From 84b8b9da2a9203808bb2d9b3a3496fd5c5414063 Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 18 Aug 2013 18:26:20 +0200 Subject: [PATCH] GUI API for tab-complete Allow the GUI to pass a request to the console client, not to the server. Any string starting with a null character is handled by the console: Command is: \0commandname\0commandarg Output from console: \0commandname\0result eg. \0autocomplete\0/he -> \0autocomplete\0/help Currently, only "autocomplete" command is implemented. --- MinecraftClient/McTcpClient.cs | 59 +++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index b7676310..e009f35a 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -157,31 +157,46 @@ namespace MinecraftClient while (client.Client.Connected) { text = ConsoleIO.ReadLine(); - if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; } - while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); } - if (text != "") + if (ConsoleIO.basicIO && text.Length > 0 && text[0] == (char)0x00) { - //Message is too long - if (text.Length > 100) + //Process a request from the GUI + string[] command = text.Substring(1).Split((char)0x00); + switch (command[0].ToLower()) { - if (text[0] == '/') - { - //Send the first 100 chars of the command - text = text.Substring(0, 100); - handler.SendChatMessage(text); - } - else - { - //Send the message splitted in sereval messages - while (text.Length > 100) - { - handler.SendChatMessage(text.Substring(0, 100)); - text = text.Substring(100, text.Length - 100); - } - handler.SendChatMessage(text); - } + case "autocomplete": + if (command.Length > 1) { ConsoleIO.WriteLine((char)0x00 + "autocomplete" + (char)0x00 + handler.AutoComplete(command[1])); } + else Console.WriteLine((char)0x00 + "autocomplete" + (char)0x00); + break; + } + } + else + { + if (text == "/quit" || text == "/reco" || text == "/reconnect") { break; } + while (text.Length > 0 && text[0] == ' ') { text = text.Substring(1); } + if (text != "") + { + //Message is too long + if (text.Length > 100) + { + if (text[0] == '/') + { + //Send the first 100 chars of the command + text = text.Substring(0, 100); + handler.SendChatMessage(text); + } + else + { + //Send the message splitted in sereval messages + while (text.Length > 100) + { + handler.SendChatMessage(text.Substring(0, 100)); + text = text.Substring(100, text.Length - 100); + } + handler.SendChatMessage(text); + } + } + else handler.SendChatMessage(text); } - else handler.SendChatMessage(text); } }