Ejemplo n.º 1
0
        /// <summary>
        /// Request an asset download through the almost deprecated Xfer system
        /// </summary>
        /// <param name="filename">Filename of the asset to request</param>
        /// <param name="deleteOnCompletion">Whether or not to delete the asset
        /// off the server after it is retrieved</param>
        /// <param name="useBigPackets">Use large transfer packets or not</param>
        /// <param name="vFileID">UUID of the file to request, if filename is
        /// left empty</param>
        /// <param name="vFileType">Asset type of <code>vFileID</code>, or
        /// <code>AssetType.Unknown</code> if filename is not empty</param>
        /// <param name="fromCache">Sets the FilePath in the request to Cache
        /// (4) if true, otherwise Unknown (0) is used</param>
        /// <returns></returns>
        public ulong RequestAssetXfer(string filename, bool deleteOnCompletion, bool useBigPackets, UUID vFileID, AssetType vFileType,
            bool fromCache)
        {
            UUID uuid = UUID.Random();
            ulong id = uuid.GetULong();

            XferDownload transfer = new XferDownload();
            transfer.XferID = id;
            transfer.ID = new UUID(id); // Our dictionary tracks transfers with UUIDs, so convert the ulong back
            transfer.Filename = filename;
            transfer.VFileID = vFileID;
            transfer.AssetType = vFileType;

            // Add this transfer to the dictionary
            lock (Transfers) Transfers[transfer.ID] = transfer;

            RequestXferPacket request = new RequestXferPacket();
            request.XferID.ID = id;
            request.XferID.Filename = Utils.StringToBytes(filename);
            request.XferID.FilePath = fromCache ? (byte)4 : (byte)0;
            request.XferID.DeleteOnCompletion = deleteOnCompletion;
            request.XferID.UseBigPackets = useBigPackets;
            request.XferID.VFileID = vFileID;
            request.XferID.VFileType = (short)vFileType;

            Client.Network.SendPacket(request);

            return id;
        }
Ejemplo n.º 2
0
 public XferReceivedEventArgs(XferDownload xfer)
 {
     this.m_Xfer = xfer;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle the reply to the OnXferReceived event
        /// </summary>
        /// <param name="xfer"></param>
        private void Assets_OnXferReceived(XferDownload xfer)
        {
            if (xfer.Success)
            {
                // set the result message
                result.AppendFormat("Terrain file {0} ({1} bytes) downloaded successfully, written to {2}", xfer.Filename, xfer.Size, fileName);

                // write the file to disk
                FileStream stream = new FileStream(fileName, FileMode.Create);
                BinaryWriter w = new BinaryWriter(stream);
                w.Write(xfer.AssetData);
                w.Close();

                // tell the application we've gotten the file
                xferTimeout.Set();

            }
        }
Ejemplo n.º 4
0
        private void RequestXferHandler(Packet packet, LLAgent agent)
        {
            RequestXferPacket request = (RequestXferPacket)packet;

            string filename = Utils.BytesToString(request.XferID.Filename);

            UUID taskInventoryID;
            if (filename.StartsWith("inventory_") && filename.EndsWith(".tmp") && UUID.TryParse(filename.Substring(10, 36), out taskInventoryID))
            {
                // This is a request for a task inventory listing, which we generate on demand
                ISceneEntity entity;
                if (m_scene.TryGetEntity(taskInventoryID, out entity) && entity is LLPrimitive)
                {
                    LLPrimitive prim = (LLPrimitive)entity;
                    byte[] assetData = Encoding.UTF8.GetBytes(prim.Inventory.GetTaskInventoryAsset());

                    SendXferPacketPacket xfer = new SendXferPacketPacket();
                    xfer.XferID.ID = request.XferID.ID;

                    if (assetData.Length < 1000)
                    {
                        xfer.XferID.Packet = 0 | LAST_PACKET_MARKER;
                        xfer.DataPacket.Data = new byte[assetData.Length + 4];
                        Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
                        Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, assetData.Length);

                        m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
                        m_log.Debug("Completed single packet xfer download of " + filename);
                    }
                    else
                    {
                        xfer.XferID.Packet = 0;
                        xfer.DataPacket.Data = new byte[1000 + 4];
                        Utils.IntToBytes(assetData.Length, xfer.DataPacket.Data, 0);
                        Buffer.BlockCopy(assetData, 0, xfer.DataPacket.Data, 4, 1000);

                        // We don't need the entire XferDownload class, just the asset data and the current packet number
                        XferDownload download = new XferDownload();
                        download.AssetData = assetData;
                        download.PacketNum = 1;
                        download.Filename = filename;
                        lock (currentDownloads)
                            currentDownloads[request.XferID.ID] = download;

                        m_udp.SendPacket(agent, xfer, ThrottleCategory.Asset, false);
                    }
                }
                else
                {
                    m_log.Warn("Could not find primitive " + taskInventoryID);
                }
            }
            else
            {
                m_log.Warn("Got a RequestXfer for an unknown file: " + filename);
            }
        }
Ejemplo n.º 5
0
 private UUID GetAssetID(XferDownload xferDownload)
 {
     //@todo
     throw new NotImplementedException();
 }