Esempio n. 1
0
        public virtual void SendTCPRaw(PacketOut packet)
        {
            if (!packet.Finalized)
            {
                packet.WritePacketLength();
            }

            SendAsynchronousTCP2((byte[])packet.GetBuffer().Clone());
        }
Esempio n. 2
0
        /// <summary>Copies the packet into the thread-local TCP send buffer, encrypting it if required. </summary>
        /// <param name="packet">A network packet.</param>
        /// <param name="destOffset">The offset to copy this packet to in the local send buffer.</param>
        /// <returns>The number of bytes to send, or 0 if encryption failed.</returns>
        public int EncryptAndBuffer(PacketOut packet, int destOffset)
        {
            int packetLength = (int)packet.Length;

            if (packetLength > 65535)
            {
                Log.Error("EncryptAndBuffer", "Packet length is greater than send buffer size!");
                return(0);
            }

            // Create a copy of the bytes to be encrypted
            Buffer.BlockCopy(packet.GetBuffer(), 0, TLSendBuffer.Value, destOffset, packetLength);

            if (m_crypts.Count > 0)
            {
                // Figure out the size of the header
                int headerPos = 0;
                headerPos += PacketOut.SizeLen;
                if (PacketOut.OpcodeInLen)
                {
                    headerPos += packet.OpcodeLen;
                }

                try
                {
                    // Encrypt the copy in-place, skipping the header bytes
                    foreach (KeyValuePair <ICryptHandler, CryptKey[]> cryptEntry in m_crypts)
                    {
                        cryptEntry.Key.Crypt(cryptEntry.Value[0], TLSendBuffer.Value, destOffset + headerPos, packetLength - headerPos);
                    }
                }
                catch (Exception e)
                {
                    Log.Error("BaseClient", "Crypt Error : " + e);
                    return(0);
                }
            }

            return(packetLength);
        }
Esempio n. 3
0
 public void SendTCPRaw(PacketOut packet)
 {
     SendTCP((byte[])packet.GetBuffer().Clone());
 }