mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
Manually add changes from pull #8
Changes could not be merged automatically due to a conflic. https://github.com/ORelio/Minecraft-Console-Client/pull/8 So I re-do the changes manually and close the original pull request.
This commit is contained in:
parent
1ca38195bc
commit
de50e07f54
1 changed files with 16 additions and 47 deletions
|
|
@ -283,12 +283,12 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
private string readNextString()
|
private string readNextString()
|
||||||
{
|
{
|
||||||
short length = readNextShort();
|
ushort length = (ushort)readNextShort();
|
||||||
if (length > 0)
|
if (length > 0)
|
||||||
{
|
{
|
||||||
byte[] cache = new byte[length * 2];
|
byte[] cache = new byte[length * 2];
|
||||||
Receive(cache, 0, length * 2, SocketFlags.None);
|
Receive(cache, 0, length * 2, SocketFlags.None);
|
||||||
string result = ByteArrayToString(cache);
|
string result = Encoding.BigEndianUnicode.GetString(cache);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
else return "";
|
else return "";
|
||||||
|
|
@ -485,21 +485,6 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
}
|
}
|
||||||
private string ReverseString(string a)
|
|
||||||
{
|
|
||||||
char[] tmp = a.ToCharArray();
|
|
||||||
Array.Reverse(tmp);
|
|
||||||
return new string(tmp);
|
|
||||||
}
|
|
||||||
private string ByteArrayToString(byte[] ba)
|
|
||||||
{
|
|
||||||
string conv = "";
|
|
||||||
for (int i = 1; i < ba.Length; i += 2)
|
|
||||||
{
|
|
||||||
conv += (char)ba[i];
|
|
||||||
}
|
|
||||||
return conv;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVersion(byte ver) { protocolversion = ver; }
|
public void setVersion(byte ver) { protocolversion = ver; }
|
||||||
public void setClient(TcpClient n) { c = n; }
|
public void setClient(TcpClient n) { c = n; }
|
||||||
|
|
@ -588,29 +573,13 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
public bool Handshake(string username, string sessionID, ref string serverID, ref byte[] token, string host, int port)
|
public bool Handshake(string username, string sessionID, ref string serverID, ref byte[] token, string host, int port)
|
||||||
{
|
{
|
||||||
username = ReverseString(username);
|
|
||||||
//array
|
//array
|
||||||
byte[] data = new byte[10 + (username.Length * 2) + (host.Length * 2)];
|
byte[] data = new byte[10 + (username.Length + host.Length) * 2];
|
||||||
|
|
||||||
//packet id
|
//packet id
|
||||||
data[0] = (byte)2;
|
data[0] = (byte)2;
|
||||||
|
|
||||||
//Protocol Version - Minecraft 1.3.1 & 1.3.2
|
//Protocol Version
|
||||||
//data[1] = (byte)39;
|
|
||||||
|
|
||||||
//Protocol Version - Minecraft 1.4.2
|
|
||||||
//data[1] = (byte)47;
|
|
||||||
|
|
||||||
//Protocol Version - Minecraft 1.4.4
|
|
||||||
//data[1] = (byte)49;
|
|
||||||
|
|
||||||
//Protocol Version - Minecraft 1.4.6 & 1.4.7
|
|
||||||
//data[1] = (byte)51;
|
|
||||||
|
|
||||||
//Protocol Version - Minecraft 1.5.0
|
|
||||||
//data[1] = (byte)60;
|
|
||||||
|
|
||||||
//Protocol Version - Custom
|
|
||||||
data[1] = protocolversion;
|
data[1] = protocolversion;
|
||||||
|
|
||||||
//short len
|
//short len
|
||||||
|
|
@ -619,9 +588,8 @@ namespace MinecraftClient
|
||||||
sh.CopyTo(data, 2);
|
sh.CopyTo(data, 2);
|
||||||
|
|
||||||
//username
|
//username
|
||||||
byte[] name = Encoding.Unicode.GetBytes(username);
|
byte[] bname = Encoding.BigEndianUnicode.GetBytes(username);
|
||||||
Array.Reverse(name);
|
bname.CopyTo(data, 4);
|
||||||
name.CopyTo(data, 4);
|
|
||||||
|
|
||||||
//short len
|
//short len
|
||||||
sh = BitConverter.GetBytes((short)host.Length);
|
sh = BitConverter.GetBytes((short)host.Length);
|
||||||
|
|
@ -629,8 +597,7 @@ namespace MinecraftClient
|
||||||
sh.CopyTo(data, 4 + (username.Length * 2));
|
sh.CopyTo(data, 4 + (username.Length * 2));
|
||||||
|
|
||||||
//host
|
//host
|
||||||
byte[] bhost = Encoding.Unicode.GetBytes(host);
|
byte[] bhost = Encoding.BigEndianUnicode.GetBytes(host);
|
||||||
Array.Reverse(bhost);
|
|
||||||
bhost.CopyTo(data, 6 + (username.Length * 2));
|
bhost.CopyTo(data, 6 + (username.Length * 2));
|
||||||
|
|
||||||
//port
|
//port
|
||||||
|
|
@ -667,7 +634,7 @@ namespace MinecraftClient
|
||||||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||||
Console.WriteLine("Handshake sussessful. (Server ID: " + serverID + ')');
|
Console.WriteLine("Handshake sussessful. (Server ID: " + serverID + ')');
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
return StartEncryption(ReverseString(username), sessionID, token, serverID, PublicServerkey, SecretKey);
|
return StartEncryption(username, sessionID, token, serverID, PublicServerkey, SecretKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else return false;
|
else return false;
|
||||||
|
|
@ -769,9 +736,11 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
public bool SendChatMessage(string message)
|
public bool SendChatMessage(string message)
|
||||||
{
|
{
|
||||||
|
if (String.IsNullOrEmpty(message))
|
||||||
|
return true;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
message = ReverseString(message);
|
|
||||||
byte[] chat = new byte[3 + (message.Length * 2)];
|
byte[] chat = new byte[3 + (message.Length * 2)];
|
||||||
chat[0] = (byte)3;
|
chat[0] = (byte)3;
|
||||||
|
|
||||||
|
|
@ -781,8 +750,7 @@ namespace MinecraftClient
|
||||||
msglen.CopyTo(chat, 1);
|
msglen.CopyTo(chat, 1);
|
||||||
|
|
||||||
byte[] msg;
|
byte[] msg;
|
||||||
msg = Encoding.Unicode.GetBytes(message);
|
msg = Encoding.BigEndianUnicode.GetBytes(message);
|
||||||
Array.Reverse(msg);
|
|
||||||
msg.CopyTo(chat, 3);
|
msg.CopyTo(chat, 3);
|
||||||
|
|
||||||
Send(chat);
|
Send(chat);
|
||||||
|
|
@ -792,9 +760,11 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
public void Disconnect(string message)
|
public void Disconnect(string message)
|
||||||
{
|
{
|
||||||
|
if (message == null)
|
||||||
|
message = "";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
message = ReverseString(message);
|
|
||||||
byte[] reason = new byte[3 + (message.Length * 2)];
|
byte[] reason = new byte[3 + (message.Length * 2)];
|
||||||
reason[0] = (byte)0xff;
|
reason[0] = (byte)0xff;
|
||||||
|
|
||||||
|
|
@ -804,8 +774,7 @@ namespace MinecraftClient
|
||||||
msglen.CopyTo(reason, 1);
|
msglen.CopyTo(reason, 1);
|
||||||
|
|
||||||
byte[] msg;
|
byte[] msg;
|
||||||
msg = Encoding.Unicode.GetBytes(message);
|
msg = Encoding.BigEndianUnicode.GetBytes(message);
|
||||||
Array.Reverse(msg);
|
|
||||||
msg.CopyTo(reason, 3);
|
msg.CopyTo(reason, 3);
|
||||||
|
|
||||||
Send(reason);
|
Send(reason);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue