예제 #1
0
    public byte[] key = new byte[yw.YwEncrypt.LIMIT_KEY_LENGTH];    //加解密key

    public EncryptInfo(NetSocket.ByteArray bin)
    {
        // 跳过两个字节
        bin.Move(NetSocket.CSocketManager.headerLen);

        bin.Get_(out param);
        for (uint i = 0; i < yw.YwEncrypt.LIMIT_KEY_LENGTH; ++i)
        {
            bin.Get_(out key [i]);
        }
    }
예제 #2
0
        protected virtual int OnSplitPacket()
        {
            byte[]    recv_buf     = mRecvBuffer.ToArray();
            ByteArray total_buffer = new ByteArray(recv_buf);

            int header_size = _get_header_size();
            int read        = 0;
            int size_remain = recv_buf.Length;

            while (size_remain > header_size)                   // Recv data len must contain one header at least.
            {
                byte[]    cur_buf = total_buffer.GetRange(read, header_size);
                ByteArray packet  = new ByteArray(cur_buf);

                // Get header info.
                NetCoreHeader h = new NetCoreHeader();
                packet.Get_(out h.length);
                packet.Get_(out h.encrypt);

                // Get packet's len.
                int packet_len = _get_packet_total_len(h);

                if (packet_len <= size_remain)
                {
                    byte[] body = total_buffer.GetRange(read + _get_header_size(), h.length);

                    if (h.encrypt == 24)
                    {
                        ParseSinglePack(body);
                    }
                    else
                    {
                        ParseMutiPack(body);
                    }

                    size_remain -= packet_len;
                    read        += packet_len;
                }
                else
                {
                    // Wait for more data.
                    break;
                }
            }

            return(read);
        }
예제 #3
0
    public string data;     // = new byte[(int)twp.app.EDef.LIMIT_LOGIN_DATA_LENGTH];

    public RepLoginInfo(NetSocket.ByteArray bin)
    {
        bin.Move(NetSocket.CSocketManager.headerLen);

        int login_result_;

        bin.Get_(out login_result_);
        login_result = (twp.protocol.login.LoginResult)login_result_;

        int login_type_;

        bin.Get_(out login_type_);
        login_type = (twp.protocol.login.LoginType)login_type_;

        bin.Get_(out data_len);

        data = bin.GetStringData((int)data_len);
    }
예제 #4
0
        protected void ParseMutiPack(byte[] body)
        {
            ByteArray bin_buf = new ByteArray(body);

            byte num = 0;

            bin_buf.Get_(out num);

            for (int i = 0; i < num; i++)
            {
                ushort sinle_pack_len = 0;
                bin_buf.Get_(out sinle_pack_len);

                byte[] buf = new byte[sinle_pack_len];
                Array.Copy(bin_buf.GetByteArray_(sinle_pack_len), buf, sinle_pack_len);

                ParseSinglePack(buf);
            }

            /* C++ code.
             * bin_buf.get(num);
             *
             * for (int i=0; i<num; ++i)
             * {
             *      USHORT single_pack_len = 0;
             *      bin_buf.get(single_pack_len);
             *
             *      static std::vector<UCHAR> buf;
             *      buf.clear();
             *      buf.resize(single_pack_len);
             *
             *      bin_buf.read(&buf[0], single_pack_len);
             *
             *      ParseSinglePack(&buf[0], single_pack_len);
             * }
             */
        }