public void EnsureCapacity(ushort length) { this.m_Stream = new PacketWriter2(length); this.m_Stream.Write(length); this.m_Stream.Write((ushort)0); this.m_Stream.Write(this.m_PacketID); }
private void InternalCompile(Client state, bool encrypt) { if (state == null) { LogConsole.Show(LogType.DEBUG, "Null NetState passed in Network.Packet.Compile()"); } if (this.m_Length == 0) { long num = this.m_Stream.Length; this.m_Stream.Seek(0L, SeekOrigin.Begin); this.m_Stream.Write((ushort)num); } else if (this.m_Stream.Length != this.m_Length) { LogConsole.Show(LogType.DEBUG, "Packet {0:X2}: Bad packet length, Expected {1} , Stream {2}", new object[] { this.m_PacketID, this.m_Length, this.m_Stream.Length }); } MemoryStream underlyingStream = this.m_Stream.UnderlyingStream; this.m_FinalBuffer = underlyingStream.GetBuffer(); int length = (int)underlyingStream.Length; if (!encrypt) { ControlCode sendControlCode = new ControlCode(true); if (state.FirstPacketSent) { sendControlCode.Update(length - 4); } this.m_Stream.Seek(2L, SeekOrigin.Begin); this.m_Stream.Write(sendControlCode.Value); } if (this.m_FinalBuffer != null) { byte[] finalBuffer = this.m_FinalBuffer; this.m_FinalBuffer = new byte[length]; Buffer.BlockCopy(finalBuffer, 0, this.m_FinalBuffer, 0, length); } this.m_Stream = null; }
public static PacketWriter2 CreateInstance(int capacity) { PacketWriter2 writer = null; lock (m_Pool) { if (m_Pool.Count > 0) { writer = (PacketWriter2)m_Pool.Pop(); if (writer != null) { writer.m_Capacity = capacity; writer.m_Stream.SetLength(0L); } } } if (writer == null) { writer = new PacketWriter2(capacity); } return(writer); }
public static PacketWriter2 CreateInstance(int capacity) { PacketWriter2 writer = null; lock (m_Pool) { if (m_Pool.Count > 0) { writer = (PacketWriter2)m_Pool.Pop(); if (writer != null) { writer.m_Capacity = capacity; writer.m_Stream.SetLength(0L); } } } if (writer == null) { writer = new PacketWriter2(capacity); } return writer; }