Skip to content

Commit

Permalink
Back to using ToArray again.
Browse files Browse the repository at this point in the history
  • Loading branch information
NiclasOlofsson committed Jul 23, 2016
1 parent a90ace2 commit 5b520dd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
6 changes: 1 addition & 5 deletions src/MiNET/MiNET/MiNetServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,11 +1086,7 @@ public void SendPackage(PlayerNetworkSession session, Package message)
SendDatagram(session, datagram);
}

TraceSend(message);

message.PutPool();

//Thread.Sleep(5); // Really important to slow down speed a bit
}

private void SendDatagram(PlayerNetworkSession session, Datagram datagram)
Expand Down Expand Up @@ -1167,7 +1163,7 @@ internal static void TraceReceive(Package message, int refNumber = 0)
Log.DebugFormat("> Receive: {0}: {1} (0x{0:x2}) #{2}", message.Id, message.GetType().Name, refNumber);
}

private static void TraceSend(Package message)
public static void TraceSend(Package message)
{
if (!Log.IsDebugEnabled) return;
//if (!Debugger.IsAttached) return;
Expand Down
10 changes: 5 additions & 5 deletions src/MiNET/MiNET/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1793,10 +1793,10 @@ private void SendChunksForKnownPosition()
}
}

private static MemoryStream CompressIntoStream(byte[] input, int offset, int length, CompressionLevel compressionLevel,
bool writeLen = false)
private static MemoryStream CompressIntoStream(byte[] input, int offset, int length, CompressionLevel compressionLevel, bool writeLen = false)
{
var stream = MiNetServer.MemoryStreamManager.GetStream();

stream.WriteByte(0x78);
switch (compressionLevel)
{
Expand Down Expand Up @@ -1830,13 +1830,13 @@ private static MemoryStream CompressIntoStream(byte[] input, int offset, int len
return stream;
}

public static McpeBatch CreateBatchPacket(byte[] input, int offset, int length, CompressionLevel compressionLevel,
bool writeLen = false)
public static McpeBatch CreateBatchPacket(byte[] input, int offset, int length, CompressionLevel compressionLevel, bool writeLen = false)
{
using (var stream = CompressIntoStream(input, offset, length, compressionLevel, writeLen))
{
var batch = McpeBatch.CreateObject();
batch.payload = new PrefixedArray(stream.GetBuffer(), (int)stream.Length);
//batch.payload = new PrefixedArray(stream.GetBuffer(), (int)stream.Length);
batch.payload = new PrefixedArray(stream.ToArray(), (int)stream.Length);
batch.Encode();
return batch;
}
Expand Down
2 changes: 2 additions & 0 deletions src/MiNET/MiNET/PlayerNetworkSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,8 @@ public void DetectLostConnection()

public void SendPackage(Package package)
{
MiNetServer.TraceSend(package);

if (package == null) return;

if (State == ConnectionState.Unconnected)
Expand Down

0 comments on commit 5b520dd

Please sign in to comment.