mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
First attempt of MC 1.7 Server Ping ping packet
Currently not working, see MinecraftCom.cs & comment "STUCK HERE"
This commit is contained in:
parent
6beb5588ce
commit
5fb54882ca
2 changed files with 69 additions and 36 deletions
|
|
@ -299,12 +299,12 @@ namespace MinecraftClient
|
|||
}
|
||||
private string readNextString()
|
||||
{
|
||||
ushort length = (ushort)readNextShort();
|
||||
int length = readNextVarInt();
|
||||
if (length > 0)
|
||||
{
|
||||
byte[] cache = new byte[length * 2];
|
||||
Receive(cache, 0, length * 2, SocketFlags.None);
|
||||
string result = Encoding.BigEndianUnicode.GetString(cache);
|
||||
byte[] cache = new byte[length];
|
||||
Receive(cache, 0, length, SocketFlags.None);
|
||||
string result = Encoding.UTF8.GetString(cache);
|
||||
return result;
|
||||
}
|
||||
else return "";
|
||||
|
|
@ -450,6 +450,36 @@ namespace MinecraftClient
|
|||
readData(datalen);
|
||||
readData(12 * (chunkcount));
|
||||
}
|
||||
private int readNextVarInt()
|
||||
{
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (true)
|
||||
{
|
||||
int k = readNextByte();
|
||||
i |= (k & 0x7F) << j++ * 7;
|
||||
if (j > 5) throw new OverflowException("VarInt too big");
|
||||
if ((k & 0x80) != 128) break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
private static byte[] getVarInt(int paramInt)
|
||||
{
|
||||
List<byte> bytes = new List<byte>();
|
||||
while ((paramInt & -128) != 0)
|
||||
{
|
||||
bytes.Add((byte)(paramInt & 127 | 128));
|
||||
paramInt = (int)(((uint)paramInt) >> 7);
|
||||
}
|
||||
return bytes.ToArray();
|
||||
}
|
||||
private static byte[] concatBytes(params byte[][] bytes)
|
||||
{
|
||||
List<byte> result = new List<byte>();
|
||||
foreach (byte[] array in bytes)
|
||||
result.AddRange(array);
|
||||
return result.ToArray();
|
||||
}
|
||||
|
||||
private static void setcolor(char c)
|
||||
{
|
||||
|
|
@ -565,40 +595,43 @@ namespace MinecraftClient
|
|||
}
|
||||
|
||||
TcpClient tcp = new TcpClient(host, port);
|
||||
byte[] ping = new byte[2] { 0xfe, 0x01 };
|
||||
tcp.Client.Send(ping, SocketFlags.None);
|
||||
|
||||
tcp.Client.Receive(ping, 0, 1, SocketFlags.None);
|
||||
if (ping[0] == 0xff)
|
||||
{
|
||||
byte[] packet_id = getVarInt(0);
|
||||
byte[] protocol_version = getVarInt(4);
|
||||
byte[] server_adress_val = Encoding.UTF8.GetBytes(host);
|
||||
byte[] server_adress_len = getVarInt(server_adress_val.Length);
|
||||
byte[] server_port = BitConverter.GetBytes((ushort)port); Array.Reverse(server_port);
|
||||
byte[] next_state = getVarInt(1);
|
||||
byte[] packet = concatBytes(packet_id, protocol_version, server_adress_len, server_adress_val, server_port, next_state);
|
||||
byte[] tosend = concatBytes(getVarInt(packet.Length), packet);
|
||||
|
||||
tcp.Client.Send(tosend, SocketFlags.None);
|
||||
|
||||
byte[] status_request = getVarInt(0);
|
||||
byte[] request_packet = concatBytes(getVarInt(status_request.Length), status_request);
|
||||
|
||||
tcp.Client.Send(request_packet, SocketFlags.None);
|
||||
|
||||
MinecraftCom ComTmp = new MinecraftCom();
|
||||
ComTmp.setClient(tcp);
|
||||
if (ComTmp.readNextVarInt() > 0) //Read Response length //<- STUCK HERE (NO ANSWER FROM SERVER)
|
||||
{
|
||||
if (ComTmp.readNextVarInt() == 0x00) //Read Packet ID
|
||||
{
|
||||
string result = ComTmp.readNextString();
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
//Console.WriteLine(result.Replace((char)0x00, ' '));
|
||||
if (result.Length > 2 && result[0] == '§' && result[1] == '1')
|
||||
{
|
||||
string[] tmp = result.Split((char)0x00);
|
||||
protocolversion = (byte)Int16.Parse(tmp[1]);
|
||||
version = tmp[2];
|
||||
}
|
||||
else
|
||||
{
|
||||
protocolversion = (byte)39;
|
||||
version = "B1.8.1 - 1.3.2";
|
||||
}
|
||||
Console.WriteLine("Server version : MC " + version + " (protocol v" + protocolversion + ").");
|
||||
Console.WriteLine(result);
|
||||
//Console.WriteLine("Server version : MC " + version + " (protocol v" + protocolversion + ").");*/
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
return true;
|
||||
//return true;
|
||||
return false; //MC 1.7+ not supported
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.WriteLine("Unexpected answer from the server (is that a Minecraft server ?)");
|
||||
Console.WriteLine("Unexpected answer from the server (is that a MC 1.7+ server ?)");
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ namespace MinecraftClient
|
|||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Console Client for MC 1.4.6 to 1.6.4 - v" + Version + " - By ORelio & Contributors");
|
||||
Console.WriteLine("Console Client for MC 1.7.2 - v" + Version + " - By ORelio & Contributors");
|
||||
|
||||
//Basic Input/Output ?
|
||||
if (args.Length >= 1 && args[args.Length - 1] == "BasicIO")
|
||||
|
|
@ -211,11 +211,11 @@ namespace MinecraftClient
|
|||
if (MinecraftCom.GetServerInfo(Settings.ServerIP, ref protocolversion, ref version))
|
||||
{
|
||||
//Supported protocol version ?
|
||||
int[] supportedVersions = { 51, 60, 61, 72, 73, 74, 78 };
|
||||
int[] supportedVersions = { 4 };
|
||||
if (Array.IndexOf(supportedVersions, protocolversion) > -1)
|
||||
{
|
||||
//Minecraft 1.6+ ? Load translations
|
||||
if (protocolversion >= 72) { ChatParser.InitTranslations(); }
|
||||
//Load translations (Minecraft 1.6+)
|
||||
ChatParser.InitTranslations();
|
||||
|
||||
//Will handle the connection for this client
|
||||
Console.WriteLine("Version is supported.");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue