mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +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()
|
||||
{
|
||||
short length = readNextShort();
|
||||
ushort length = (ushort)readNextShort();
|
||||
if (length > 0)
|
||||
{
|
||||
byte[] cache = new byte[length * 2];
|
||||
Receive(cache, 0, length * 2, SocketFlags.None);
|
||||
string result = ByteArrayToString(cache);
|
||||
string result = Encoding.BigEndianUnicode.GetString(cache);
|
||||
return result;
|
||||
}
|
||||
else return "";
|
||||
|
|
@ -485,21 +485,6 @@ namespace MinecraftClient
|
|||
}
|
||||
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 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)
|
||||
{
|
||||
username = ReverseString(username);
|
||||
//array
|
||||
byte[] data = new byte[10 + (username.Length * 2) + (host.Length * 2)];
|
||||
byte[] data = new byte[10 + (username.Length + host.Length) * 2];
|
||||
|
||||
//packet id
|
||||
data[0] = (byte)2;
|
||||
|
||||
//Protocol Version - Minecraft 1.3.1 & 1.3.2
|
||||
//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
|
||||
//Protocol Version
|
||||
data[1] = protocolversion;
|
||||
|
||||
//short len
|
||||
|
|
@ -619,9 +588,8 @@ namespace MinecraftClient
|
|||
sh.CopyTo(data, 2);
|
||||
|
||||
//username
|
||||
byte[] name = Encoding.Unicode.GetBytes(username);
|
||||
Array.Reverse(name);
|
||||
name.CopyTo(data, 4);
|
||||
byte[] bname = Encoding.BigEndianUnicode.GetBytes(username);
|
||||
bname.CopyTo(data, 4);
|
||||
|
||||
//short len
|
||||
sh = BitConverter.GetBytes((short)host.Length);
|
||||
|
|
@ -629,8 +597,7 @@ namespace MinecraftClient
|
|||
sh.CopyTo(data, 4 + (username.Length * 2));
|
||||
|
||||
//host
|
||||
byte[] bhost = Encoding.Unicode.GetBytes(host);
|
||||
Array.Reverse(bhost);
|
||||
byte[] bhost = Encoding.BigEndianUnicode.GetBytes(host);
|
||||
bhost.CopyTo(data, 6 + (username.Length * 2));
|
||||
|
||||
//port
|
||||
|
|
@ -667,7 +634,7 @@ namespace MinecraftClient
|
|||
Console.ForegroundColor = ConsoleColor.DarkGray;
|
||||
Console.WriteLine("Handshake sussessful. (Server ID: " + serverID + ')');
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
return StartEncryption(ReverseString(username), sessionID, token, serverID, PublicServerkey, SecretKey);
|
||||
return StartEncryption(username, sessionID, token, serverID, PublicServerkey, SecretKey);
|
||||
}
|
||||
}
|
||||
else return false;
|
||||
|
|
@ -769,9 +736,11 @@ namespace MinecraftClient
|
|||
}
|
||||
public bool SendChatMessage(string message)
|
||||
{
|
||||
if (String.IsNullOrEmpty(message))
|
||||
return true;
|
||||
|
||||
try
|
||||
{
|
||||
message = ReverseString(message);
|
||||
byte[] chat = new byte[3 + (message.Length * 2)];
|
||||
chat[0] = (byte)3;
|
||||
|
||||
|
|
@ -781,8 +750,7 @@ namespace MinecraftClient
|
|||
msglen.CopyTo(chat, 1);
|
||||
|
||||
byte[] msg;
|
||||
msg = Encoding.Unicode.GetBytes(message);
|
||||
Array.Reverse(msg);
|
||||
msg = Encoding.BigEndianUnicode.GetBytes(message);
|
||||
msg.CopyTo(chat, 3);
|
||||
|
||||
Send(chat);
|
||||
|
|
@ -792,9 +760,11 @@ namespace MinecraftClient
|
|||
}
|
||||
public void Disconnect(string message)
|
||||
{
|
||||
if (message == null)
|
||||
message = "";
|
||||
|
||||
try
|
||||
{
|
||||
message = ReverseString(message);
|
||||
byte[] reason = new byte[3 + (message.Length * 2)];
|
||||
reason[0] = (byte)0xff;
|
||||
|
||||
|
|
@ -804,8 +774,7 @@ namespace MinecraftClient
|
|||
msglen.CopyTo(reason, 1);
|
||||
|
||||
byte[] msg;
|
||||
msg = Encoding.Unicode.GetBytes(message);
|
||||
Array.Reverse(msg);
|
||||
msg = Encoding.BigEndianUnicode.GetBytes(message);
|
||||
msg.CopyTo(reason, 3);
|
||||
|
||||
Send(reason);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue