public PacketReader(ServerHeader header, byte[] buffer) : base(new MemoryStream(buffer)) { Header = header; }
public PacketReader(ServerHeader header) : this(header, new byte[] { }) { }
private void ReceiveHeader(IAsyncResult ar) { if (IsClientConnected()) { int bytesReceived = tcpClient.Client.EndReceive(ar); if (bytesReceived != 0) { Interlocked.Add(ref transferred, bytesReceived); Interlocked.Add(ref received, bytesReceived); if (bytesReceived == remaining) { AuthenticationCrypto.Decrypt(Buffer, 1, Buffer.Length - 1); ServerHeader header = new ServerHeader(Buffer); if (header.Size > 0) { index = 0; remaining = header.Size; Buffer = new byte[header.Size]; tcpClient.Client.BeginReceive(Buffer, index, remaining, SocketFlags.None, new AsyncCallback(ReceivePayload), header); } else { HandleIncoming(new PacketReader(header)); Start(); } } else { index += bytesReceived; remaining -= bytesReceived; tcpClient.Client.BeginReceive(Buffer, index, remaining, SocketFlags.None, new AsyncCallback(ReceiveHeader), null); } } } }