Beispiel #1
0
        public void PacketReceived(IAsyncResult result)
        {
            mysocket.EndReceive(result);
            StateObject newstate = (StateObject)result.AsyncState;
            ArrayList incomingpackets = new ArrayList();
            incomingpackets.AddRange(newstate.buffer);
            byte[] outbuffer;
            // store incoming packet in an arraylist
            // decompress it etc, then xfer to byte[] and remove from list
            // repeat
            while (incomingpackets.Count > 0)
            {

                if (bDecompress)
                {

                    HuffmanDecompression huff = new HuffmanDecompression();

                    outbuffer = new byte[incomingpackets.Count];
                    huffmanobject myhuf = new huffmanobject();
                        myhuf.buffer = (byte[])incomingpackets.ToArray(typeof(byte));
                        myhuf.src_size = incomingpackets.Count;
                        myhuf.out_size = 0;

                        //myhuf.output = BinaryNode.Decompress(myhuf.buffer);
                    myhuf = BinaryNode.drkDecompress(myhuf);
                    outbuffer = myhuf.output;
                    //myhuf.out_size = outbuffer.Length;

                    if (outbuffer.Length < 1) { incomingpackets.Clear(); break; }
                    if (myhuf.buffer.Length > outbuffer.Length)
                    {
                        if (bDebug) { display("consuming: " + myhuf.out_size + " bytes"); }
                        for (int x = 0; x < (myhuf.out_size + 1); x++) { incomingpackets.RemoveAt(0); } // removes it from queue
                    }else {
                        incomingpackets.Clear();
                    }

                }
                    else
                    {
                        // Wipe the buffer as pre decompression packets dont stack up.
                        outbuffer = newstate.buffer;
                        incomingpackets.Clear();
                    }

                if (bTwofishcrypt)
                {
                    Twofish.serverDecrypt(ref outbuffer, outbuffer.Length);
                    display("Decrypting incoming");
                }

                    handlePackets(outbuffer);
                }
        }
Beispiel #2
0
        public void PacketReceived(IAsyncResult result)
        {
            mysocket.EndReceive(result);
            StateObject newstate        = (StateObject)result.AsyncState;
            ArrayList   incomingpackets = new ArrayList();

            incomingpackets.AddRange(newstate.buffer);
            byte[] outbuffer;
            // store incoming packet in an arraylist
            // decompress it etc, then xfer to byte[] and remove from list
            // repeat
            while (incomingpackets.Count > 0)
            {
                if (bDecompress)
                {
                    HuffmanDecompression huff = new HuffmanDecompression();

                    outbuffer = new byte[incomingpackets.Count];
                    huffmanobject myhuf = new huffmanobject();
                    myhuf.buffer   = (byte[])incomingpackets.ToArray(typeof(byte));
                    myhuf.src_size = incomingpackets.Count;
                    myhuf.out_size = 0;

                    //myhuf.output = BinaryNode.Decompress(myhuf.buffer);
                    myhuf     = BinaryNode.drkDecompress(myhuf);
                    outbuffer = myhuf.output;
                    //myhuf.out_size = outbuffer.Length;

                    if (outbuffer.Length < 1)
                    {
                        incomingpackets.Clear(); break;
                    }
                    if (myhuf.buffer.Length > outbuffer.Length)
                    {
                        if (bDebug)
                        {
                            display("consuming: " + myhuf.out_size + " bytes");
                        }
                        for (int x = 0; x < (myhuf.out_size + 1); x++)
                        {
                            incomingpackets.RemoveAt(0);
                        }                                                                               // removes it from queue
                    }
                    else
                    {
                        incomingpackets.Clear();
                    }
                }
                else
                {
                    // Wipe the buffer as pre decompression packets dont stack up.
                    outbuffer = newstate.buffer;
                    incomingpackets.Clear();
                }

                if (bTwofishcrypt)
                {
                    Twofish.serverDecrypt(ref outbuffer, outbuffer.Length);
                    display("Decrypting incoming");
                }

                handlePackets(outbuffer);
            }
        }