示例#1
0
            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;
            }
示例#2
0
 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;
 }