mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added TAB autocomplete
Now handles TAB keypresses and ask the server for an autocompletion, just like a vanilla client does.
This commit is contained in:
parent
d1770ebb02
commit
88105d30ad
3 changed files with 53 additions and 2 deletions
|
|
@ -11,7 +11,7 @@ namespace MinecraftClient
|
|||
/// The class containing all the core functions needed to communicate with a Minecraft server.
|
||||
/// </summary>
|
||||
|
||||
public class MinecraftCom
|
||||
public class MinecraftCom : IAutoComplete
|
||||
{
|
||||
#region Login to Minecraft.net, Obtaining a session ID
|
||||
|
||||
|
|
@ -257,7 +257,7 @@ namespace MinecraftClient
|
|||
break;
|
||||
case 0xC9: readNextString(); readData(3); break;
|
||||
case 0xCA: if (protocolversion >= 72) { readData(9); } else readData(3); break;
|
||||
case 0xCB: readNextString(); break;
|
||||
case 0xCB: autocomplete_result = readNextString(); autocomplete_received = true; break;
|
||||
case 0xCC: readNextString(); readData(4); break;
|
||||
case 0xCD: readData(1); break;
|
||||
case 0xCE: if (protocolversion > 51) { readNextString(); readNextString(); readData(1); } break;
|
||||
|
|
@ -484,6 +484,30 @@ namespace MinecraftClient
|
|||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
}
|
||||
|
||||
private bool autocomplete_received = false;
|
||||
private string autocomplete_result = "";
|
||||
public string AutoComplete(string behindcursor)
|
||||
{
|
||||
if (String.IsNullOrEmpty(behindcursor))
|
||||
return "";
|
||||
|
||||
byte[] autocomplete = new byte[3 + (behindcursor.Length * 2)];
|
||||
autocomplete[0] = 0xCB;
|
||||
byte[] msglen = BitConverter.GetBytes((short)behindcursor.Length);
|
||||
Array.Reverse(msglen); msglen.CopyTo(autocomplete, 1);
|
||||
byte[] msg = Encoding.BigEndianUnicode.GetBytes(behindcursor);
|
||||
msg.CopyTo(autocomplete, 3);
|
||||
|
||||
autocomplete_received = false;
|
||||
autocomplete_result = behindcursor;
|
||||
Send(autocomplete);
|
||||
|
||||
int wait_left = 50; //do not wait more than 5 seconds (50 * 100 ms)
|
||||
while (wait_left > 0 && !autocomplete_received) { System.Threading.Thread.Sleep(100); wait_left--; }
|
||||
string[] results = autocomplete_result.Split((char)0x00);
|
||||
return results[0];
|
||||
}
|
||||
|
||||
public void setVersion(byte ver) { protocolversion = ver; }
|
||||
public void setClient(TcpClient n) { c = n; }
|
||||
private void setEncryptedClient(Crypto.AesStream n) { s = n; encrypted = true; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue