Server.Network.Packet.Compile C# (CSharp) Méthode

Compile() public méthode

public Compile ( bool compress, int &length ) : byte[]
compress bool
length int
Résultat byte[]
        public byte[] Compile( bool compress, out int length )
        {
            if ( m_CompiledBuffer == null )
            {
                if ( (m_State & State.Accessed) == 0 )
                {
                    m_State |= State.Accessed;
                }
                else
                {
                    if ( (m_State & State.Warned) == 0 )
                    {
                        m_State |= State.Warned;

                        try
                        {
                            using ( StreamWriter op = new StreamWriter( "net_opt.log", true ) )
                            {
                                op.WriteLine( "Redundant compile for packet {0}, use Acquire() and Release()", this.GetType() );
                                op.WriteLine( new System.Diagnostics.StackTrace() );
                            }
                        }
                        catch
                        {
                        }
                    }

                    m_CompiledBuffer = new byte[0];
                    m_CompiledLength = 0;

                    length = m_CompiledLength;
                    return m_CompiledBuffer;
                }

                InternalCompile( compress );
            }

            length = m_CompiledLength;
            return m_CompiledBuffer;
        }

Usage Example

Exemple #1
0
        public static Packet Compress(Packet p)
        {
            int length;
            byte[] source = p.Compile(false, out length);

            if (length > 100 && length < 60000)
            {
                byte[] dest = new byte[(int)(length * 1.001) + 10];
                int destSize = dest.Length;

                ZLibError error = Compression.Pack(dest, ref destSize, source, length, ZLibQuality.Default);

                if (error != ZLibError.Okay)
                {
                    Console.WriteLine("WARNING: Unable to compress admin packet, zlib error: {0}", error);
                    return p;
                }
                else
                {
                    return new AdminCompressedPacket(dest, destSize, length);
                }
            }
            else
            {
                return p;
            }
        }
All Usage Examples Of Server.Network.Packet::Compile