Esempio n. 1
0
        public override void OnPacket(byte[] packetData)
        {
            try
            {
                InPacket      iPacket = new InPacket(packetData, _CryptoHandler);
                PayloadReader pReader = new PayloadReader(iPacket.Payload);

                CenterOpcodes opcode = (CenterOpcodes)pReader.Id;

                bool isCompressed = pReader.CompressionFlag;

                if (isCompressed)
                {
                    Log.Packet("Pacote comprimido recebido: 0x{0:X2} ({1})", (int)opcode, opcode.ToString());
                }
                else
                {
                    Log.Packet("Opcode: 0x{0:X2} ({1})", (int)opcode, opcode.ToString());
                }

                switch (opcode)
                {
                case CenterOpcodes.HEART_BIT_NOT:
                    OnHeartBeatNot();
                    break;

                case CenterOpcodes.ENU_VERIFY_ACCOUNT_REQ:
                    MyUser.OnLogin(this, iPacket);
                    break;

                case CenterOpcodes.ENU_GUIDE_BOOK_LIST_REQ:
                    MyUser.OnGuideBookList(this);
                    break;

                case CenterOpcodes.ENU_CLIENT_CONTENTS_FIRST_INIT_INFO_REQ:
                    MyLoading.NotifyContentInfo(this);
                    break;

                case CenterOpcodes.ENU_CLIENT_PING_CONFIG_REQ:
                    OnClientPingConfig();
                    break;

                case CenterOpcodes.ENU_SHAFILENAME_LIST_REQ:
                    MyLoading.NotifySHAFile(this);
                    break;

                default:
                    Log.Warn("Pacote indefinido recebido. Opcode: {0:X} ({1})", (int)opcode, opcode.ToString());
                    Log.Hex("Payload:", iPacket.Payload);
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Builds a payload from the current content's data.
        /// </summary>
        /// <param name="id">The packet's id.</param>
        /// <returns>A new payload.</returns>
        public byte[] GetPayload(CenterOpcodes oId)
        {
            short id = (short)oId;

            byte[] packetId        = BigEndian.GetBytes(id);
            byte[] size            = BigEndian.GetBytes(Data.Length);
            byte[] compressionFlag = { 0 }; // false
            byte[] padding         = { 0, 0, 0 };

            return(Sequence.Concat(packetId, size, compressionFlag, Data, padding));
        }
Esempio n. 3
0
        public override void OnPacket(InPacket iPacket)
        {
            try
            {
                iPacket.Decrypt(CRYPT_KEY);

                CenterOpcodes uOpcode    = (CenterOpcodes)iPacket.ReadShort();
                int           uSize      = iPacket.ReadInt();
                bool          isCompress = iPacket.ReadBool();
                int           cSize      = 0;
                if (isCompress == true)
                {
                    cSize = iPacket.ReadInt();
                    LogFactory.GetLog("Main").LogInfo("Pacote comprimido {0}({1})", (int)uOpcode, uOpcode.ToString());
                }
                else
                {
                    LogFactory.GetLog("Main").LogInfo("Packet {0}({1})", (int)uOpcode, uOpcode.ToString());
                }

                LogFactory.GetLog("Main").LogHex("Pacote", iPacket.ToArray());

                switch (uOpcode)
                {
                case CenterOpcodes.HEART_BIT_NOT:
                    OnHeartBeatNot();
                    break;

                case CenterOpcodes.ENU_CLIENT_CONTENTS_FIRST_INIT_INFO_REQ:
                    MyLoading.NotifyContentInfo(this);
                    break;

                case CenterOpcodes.ENU_VERIFY_ACCOUNT_REQ:
                    MyUser.OnLogin(this, iPacket);
                    break;

                default:
                {
                    LogFactory.GetLog("Main").LogWarning("Pacote indefinido foi recebida. Opcode: {0}({1})", (int)uOpcode, uOpcode.ToString());
                    LogFactory.GetLog("Main").LogHex("Pacote", iPacket.ToArray());
                    break;
                }
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLog("Main").LogError(e.ToString());
                Close();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Builds a compressed payload from the current content's data.
        /// </summary>
        /// <param name="id">The packet's id.</param>
        /// <returns>A new compressed payload.</returns>
        public byte[] GetCompressedPayload(CenterOpcodes oId)
        {
            short id = (short)oId;

            byte[] compressedData = ZLib.CompressData(Data);

            byte[] packetId         = BigEndian.GetBytes(id);
            byte[] size             = BigEndian.GetBytes(compressedData.Length + 4);
            byte[] compressionFlag  = { 1 }; // true
            byte[] decompressedSize = LittleEndian.GetBytes(Data.Length);
            byte[] padding          = { 0, 0, 0 };

            return(Sequence.Concat(packetId, size, compressionFlag, decompressedSize, compressedData, padding));
        }
Esempio n. 5
0
 public OutPacket(CenterOpcodes nOpcode)
 {
     Opcode = (int)nOpcode;
 }
Esempio n. 6
0
        public override void OnPacket(InPacket iPacket)
        {
            try
            {
                iPacket.Decrypt(CRYPT_KEY);

                CenterOpcodes uOpcode    = (CenterOpcodes)iPacket.ReadShort();
                int           uSize      = iPacket.ReadInt();
                bool          isCompress = iPacket.ReadBool();
                int           cSize      = 0;
                if (isCompress == true)
                {
                    cSize = iPacket.ReadInt();
                    LogFactory.GetLog("Main").LogWarning("Recebido Pacote Compress  {0}({1})", (int)uOpcode, uOpcode.ToString());
                }
                else
                {
                    LogFactory.GetLog("Main").LogInfo("Pacote Recebido {0}({1})", (int)uOpcode, uOpcode.ToString());
                }

                LogFactory.GetLog("Main").LogHex(uOpcode + ": ", iPacket.ToArray());

                switch (uOpcode)
                {
                case CenterOpcodes.HEART_BIT_NOT:
                    OnHeartBeatNot();
                    break;

                case CenterOpcodes.ENU_CLIENT_CONTENTS_FIRST_INIT_INFO_REQ:
                    MyLoading.NotifyContentInfo(this, iPacket);
                    break;

                case CenterOpcodes.ENU_SHAFILENAME_LIST_REQ:
                    MyLoading.NotifySHAFile(this, iPacket);
                    break;

                case CenterOpcodes.ENU_VERIFY_ACCOUNT_REQ:
                    MyUser.OnLogin(this, iPacket);
                    break;

                case CenterOpcodes.ENU_CLIENT_PING_CONFIG_REQ:
                    OnClientPingConfig();
                    break;

                case CenterOpcodes.ENU_GUIDE_BOOK_LIST_REQ:
                    MyUser.OnGuideBookList(this);
                    break;

                default:
                {
                    LogFactory.GetLog("Main").LogWarning("Pacote Desconhecido Recebido. Opcode: {0}({1})", (int)uOpcode, uOpcode.ToString());
                    LogFactory.GetLog("Main").LogHex("Pacote", iPacket.ToArray());
                    break;
                }
                }
            }
            catch (Exception e)
            {
                LogFactory.GetLog("Main").LogError(e.ToString());
                Close();
            }
        }