Fix network reading incomplete strings

Very long strings are partially read using a single read. Added a loop.
Fixed version number and year in assembly infos.
This commit is contained in:
ORelio 2014-05-15 18:36:01 +02:00
parent 879c124d6a
commit 99e25982c9
2 changed files with 13 additions and 9 deletions

View file

@ -218,8 +218,7 @@ namespace MinecraftClient
{
byte[] cache = new byte[length];
Receive(cache, 0, length, SocketFlags.None);
string result = Encoding.UTF8.GetString(cache);
return result;
return Encoding.UTF8.GetString(cache);
}
else return "";
}
@ -363,11 +362,15 @@ namespace MinecraftClient
private void setEncryptedClient(Crypto.IAesStream n) { s = n; encrypted = true; }
private void Receive(byte[] buffer, int start, int offset, SocketFlags f)
{
if (encrypted)
int read = 0;
while (read < offset)
{
s.Read(buffer, start, offset);
if (encrypted)
{
read += s.Read(buffer, start + read, offset - read);
}
else read += c.Client.Receive(buffer, start + read, offset - read, f);
}
else c.Client.Receive(buffer, start, offset, f);
}
private void Send(byte[] buffer)
{
@ -400,6 +403,7 @@ namespace MinecraftClient
}
TcpClient tcp = new TcpClient(host, port);
tcp.ReceiveBufferSize = 1024 * 1024;
byte[] packet_id = getVarInt(0);
byte[] protocol_version = getVarInt(4);

View file

@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MinecraftClient")]
[assembly: AssemblyCopyright("Copyright © ORelio 2012-2013")]
[assembly: AssemblyCopyright("Copyright © ORelio 2012-2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.1")]
[assembly: AssemblyFileVersion("1.6.1")]
[assembly: AssemblyVersion("1.7.3")]
[assembly: AssemblyFileVersion("1.7.3")]