Exemplo n.º 1
0
        // Envoi un packet
        public void SendPacket(PacketOut packet)
        {
            //Fix the packet size
            packet.WritePacketLength();
            packet = Crypt(packet);

            //Get the packet buffer
            byte[] buf = packet.ToArray();             //packet.WritePacketLength sets the Capacity

            //Send the buffer
            SendTCP(buf);

            packet.Dispose();
        }
Exemplo n.º 2
0
        public void SendTCPCuted(PacketOut Out)
        {

            long PSize = Out.Length - Out.OpcodeLen - PacketOut.SizeLen; // Size = Size-len-opcode

            byte[] Packet = new byte[PSize];
            Out.Position = Out.OpcodeLen + PacketOut.SizeLen;
            Out.Read(Packet, 0, (int)(PSize));

            List<byte> Header = new List<byte>(5);
            int itemcount = 1;
            while (PSize > 0x7f)
            {
                Header.Add((byte)((byte)(PSize) | 0x80));
                PSize >>= 7;
                itemcount++;
                if (itemcount >= Header.Capacity + 10)
                    Header.Capacity += 10;
            }

            Header.Add((byte)(PSize));
            Header.Add((byte)(Out.Opcode));

            Log.Tcp("Header", Header.ToArray(), 0, Header.Count);
            Log.Tcp("Packet", Packet, 0, Packet.Length);

            Log.Dump("Header", Header.ToArray(), 0, Header.Count);
            Log.Dump("Packet", Packet, 0, Packet.Length);

            SendTCP(Header.ToArray());
            SendTCP(Packet);

            Out.Dispose();
        }
Exemplo n.º 3
0
        public PacketOut Crypt(PacketOut packet)
        {
            if (m_crypts.Count <= 0)
            {
                return(packet);
            }

            byte[] Packet = packet.ToArray();

            Log.Tcp("SendTCP", Packet, 0, (int)Packet.Length);

            int Hpos = 0;

            Hpos += PacketOut.SizeLen;
            if (PacketOut.OpcodeInLen)
            {
                Hpos += packet.OpcodeLen;
            }

            byte[] Header  = new byte[Hpos];
            byte[] ToCrypt = new byte[(packet.Length - Hpos)];
            int    i;

            for (i = 0; i < Hpos; ++i)
            {
                Header[i] = Packet[i];
            }

            for (i = Hpos; i < Packet.Length; ++i)
            {
                ToCrypt[i - Hpos] = Packet[i];
            }

            try
            {
                foreach (KeyValuePair <ICryptHandler, CryptKey[]> Entry in m_crypts)
                {
                    ToCrypt = Entry.Key.Crypt(Entry.Value[0], ToCrypt);
                }
            }
            catch (Exception e)
            {
                Log.Error("BaseClient", "Crypt Error : " + e.ToString());
                return(packet);
            }

            PacketOut Out = new PacketOut((byte)0);

            Out.Opcode    = packet.Opcode;
            Out.OpcodeLen = packet.OpcodeLen;
            Out.Position  = 0;
            Out.SetLength(0);

            byte[] Total = new byte[Header.Length + ToCrypt.Length];

            for (i = 0; i < Total.Length; ++i)
            {
                if (i < Header.Length)
                {
                    Total[i] = Header[i];
                }
                else
                {
                    Total[i] = ToCrypt[i - Header.Length];
                }
            }

            Out.Write(Total, 0, Total.Length);

            packet.Dispose();
            return(Out);
        }