예제 #1
0
    public void FlushQueuedSendPackets(BasePacketConnectionTypes header = BasePacketConnectionTypes.Zone)
    {
        if (!socket.Connected)
        {
            return;
        }

        while (sendPacketQueue.Count > 0)
        {
            BasePacket packet = BasePacket.CreatePacket(sendPacketQueue, PacketProcessor.isAuthenticated, false);
            packet.header.connectionType = (ushort)header;

            try
            {
                socket.Send(packet.GetPacketBytes());
                sendPacketQueue.Clear();
            }
            catch (Exception e)
            {
                Console.WriteLine("Weird case, socket was d/ced: {0}", e);
            }
        }
    }
예제 #2
0
        /// <summary>
        /// Default BasePacketConnectionType = zone
        /// </summary>
        /// <param name="subpackets"></param>
        /// <param name="isAuthed"></param>
        /// <param name="isEncrypted"></param>
        /// <returns></returns>
        public static BasePacket CreatePacket(List <SubPacket> subpackets, bool isAuthed, bool isEncrypted, BasePacketConnectionTypes connectionType = BasePacketConnectionTypes.Zone)
        {
            //Create Header
            BasePacketHeader header = new BasePacketHeader();

            byte[] data = null;

            header.isAuthenticated = isAuthed ? (byte)1 : (byte)0;
            header.isEncrypted     = isEncrypted ? (byte)1 : (byte)0;
            header.numSubpackets   = (ushort)subpackets.Count;
            header.packetSize      = BASEPACKET_SIZE;
            header.timestamp       = Utils.MilisUnixTimeStampUTC();
            header.connectionType  = (ushort)connectionType;

            //Get packet size
            foreach (SubPacket subpacket in subpackets)
            {
                header.packetSize += subpacket.header.subpacketSize;
            }

            data = new byte[header.packetSize - 0x10];

            //Add Subpackets
            int offset = 0;

            foreach (SubPacket subpacket in subpackets)
            {
                byte[] subpacketData = subpacket.getBytes();
                Array.Copy(subpacketData, 0, data, offset, subpacketData.Length);
                offset += (ushort)subpacketData.Length;
            }

            Debug.Assert(data != null && offset == data.Length && header.packetSize == 0x10 + offset);

            BasePacket packet = new BasePacket(header, data);

            return(packet);
        }