Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions MinecraftClient/MinecraftCom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,12 @@ private void readData(int offset)
}
private string readNextString()
{
short lenght = readNextShort();
ushort lenght = (ushort)readNextShort();
if (lenght > 0)
{
byte[] cache = new byte[lenght * 2];
Receive(cache, 0, lenght * 2, SocketFlags.None);
string result = ByteArrayToString(cache);
string result = Encoding.BigEndianUnicode.GetString(cache);
return result;
}
else return "";
Expand Down Expand Up @@ -485,21 +485,6 @@ private void printstring(string str, bool acceptnewlines)
}
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; }
Expand Down Expand Up @@ -588,7 +573,6 @@ public static bool GetServerInfo(string serverIP, ref byte protocolversion, ref
}
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)];

Expand Down Expand Up @@ -619,8 +603,7 @@ public bool Handshake(string username, string sessionID, ref string serverID, re
sh.CopyTo(data, 2);

//username
byte[] name = Encoding.Unicode.GetBytes(username);
Array.Reverse(name);
byte[] name = Encoding.BigEndianUnicode.GetBytes(username);
name.CopyTo(data, 4);

//short len
Expand All @@ -629,8 +612,7 @@ public bool Handshake(string username, string sessionID, ref string serverID, re
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
Expand Down Expand Up @@ -667,7 +649,8 @@ public bool Handshake(string username, string sessionID, ref string serverID, re
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;
Expand Down Expand Up @@ -771,7 +754,6 @@ public bool SendChatMessage(string message)
{
try
{
message = ReverseString(message);
byte[] chat = new byte[3 + (message.Length * 2)];
chat[0] = (byte)3;

Expand All @@ -781,8 +763,7 @@ public bool SendChatMessage(string message)
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);
Expand All @@ -794,7 +775,6 @@ public void Disconnect(string message)
{
try
{
message = ReverseString(message);
byte[] reason = new byte[3 + (message.Length * 2)];
reason[0] = (byte)0xff;

Expand All @@ -804,8 +784,7 @@ public void Disconnect(string message)
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);
Expand Down