Esempio n. 1
0
    bool CreateChunkCmdData(DownloadData dd, DownChunkData dcd)
    {
        MultiFileDownData mfdd   = (MultiFileDownData)dd.Data;
        DownResData       curDrd = mfdd.FileList[dcd.FileIdx];

        try
        {
            //1.封装命令
            if (dd.Type == DownloadType.DOWNLOAD_CHECK_VER)
            {
                NetCmdCheckVer cmd = new NetCmdCheckVer();
                cmd.SetCmdType(NetCmdType.CMD_EXTRA_CHECK_VER);
                cmd.Version      = ServerSetting.ClientVer;
                cmd.Plateform    = (byte)RuntimeInfo.GetPlatform();
                cmd.ScreenWidth  = (ushort)Resolution.GetScreenWidth();
                cmd.ScreenHeight = (ushort)Resolution.GetScreenHeight();
                cmd.FileName     = System.Text.Encoding.ASCII.GetBytes(curDrd.ResUrl);
                cmd.Length       = (ushort)mfdd.FileList[0].ResUrl.Length;
                SetPcakgeMac(cmd, m_PackageName, m_MacAddress);
                dcd.SendCmdData = NetCmdHelper.CmdToBytes <NetCmdCheckVer>(cmd, 0);
            }
            else
            {
                byte[] data1    = System.BitConverter.GetBytes(dcd.Offset);
                byte[] data2    = System.BitConverter.GetBytes(dcd.Length);
                byte[] dataUrl  = System.Text.Encoding.ASCII.GetBytes(curDrd.ResUrl);
                byte[] sendData = new byte[data1.Length + data2.Length + dataUrl.Length + 1];
                System.Array.Copy(data1, 0, sendData, 0, 4);
                System.Array.Copy(data2, 0, sendData, 4, 4);
                System.Array.Copy(dataUrl, 0, sendData, 8, dataUrl.Length);

                NetCmdFileRequest ncf = new NetCmdFileRequest();
                ncf.FileName = sendData;
                ncf.Count    = (ushort)(mfdd.FileList.Count | ((int)dcd.XOR << 15)); //高位是1表示要异或
                ncf.Length   = (ushort)sendData.Length;
                ncf.SetCmdType(NetCmdType.CMD_EXTRA_FILE_EX);
                dcd.SendCmdData = NetCmdHelper.CmdToBytes <NetCmdFileRequest>(ncf, 0);
            }
        }
        catch (System.Exception e)
        {
            throw new System.Exception("CreateChunkCmdData Err:" + e.ToString());
            return(false);
        }
        return(true);
    }
Esempio n. 2
0
    void SetPcakgeMac(NetCmdCheckVer cmd, string package, string macaddr)
    {
        byte[] parr = System.Text.Encoding.ASCII.GetBytes(package);
        byte[] pmac = System.Text.Encoding.ASCII.GetBytes(macaddr);

        cmd.Package    = new byte[48];
        cmd.MacAddress = new byte[48];

        int minarr = Mathf.Min(parr.Length, cmd.Package.Length);
        int idx    = 0;

        for (; idx < minarr; ++idx)
        {
            cmd.Package[idx] = parr[idx];
        }

        minarr = Mathf.Min(pmac.Length, cmd.MacAddress.Length);
        idx    = 0;
        for (; idx < minarr; ++idx)
        {
            cmd.MacAddress[idx] = pmac[idx];
        }
    }