public void HandleXfer(ulong xferID, uint packetID, byte[] data)
        {
            AssetXferUploader foundUploader = null;

            lock (XferUploaders)
            {
                foreach (AssetXferUploader uploader in XferUploaders.Values)
                {
//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
//                        uploader.XferID);

                    if (uploader.XferID == xferID)
                    {
                        foundUploader = uploader;
                        break;
                    }
                }
            }

            if (foundUploader != null)
            {
//                m_log.DebugFormat(
//                    "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
//                    xferID, packetID, data.Length);

                foundUploader.HandleXferPacket(xferID, packetID, data);
            }
            else
            {
                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
                    xferID, packetID, data.Length);
            }
        }
Esempio n. 2
0
        public void RequestUpdateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestUpdateInventoryItem(remoteClient, item);
        }
        /// <summary>
        /// Request that a client (agent) begin an asset transfer.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="assetID"></param>
        /// <param name="transaction"></param>
        /// <param name="type"></param>
        /// <param name="data"></param></param>
        /// <param name="tempFile"></param>
        public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
                                           byte[] data, bool storeLocal, bool tempFile)
        {
            //m_log.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);
            if (((AssetType)type == AssetType.Texture ||
                 (AssetType)type == AssetType.Sound ||
                 (AssetType)type == AssetType.TextureTGA ||
                 (AssetType)type == AssetType.Animation) &&
                tempFile == false)
            {
                Scene        scene = (Scene)remoteClient.Scene;
                IMoneyModule mm    = scene.RequestModuleInterface <IMoneyModule>();

                if (mm != null)
                {
                    if (!mm.UploadCovered(remoteClient))
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
                        return;
                    }
                }
            }

            //m_log.Debug("asset upload of " + assetID);
            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);

            AssetXferUploader uploader = transactions.RequestXferUploader(transaction);

            if (uploader != null)
            {
                uploader.Initialise(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
            }
        }
Esempio n. 4
0
        public void RequestCreateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, UUID folderID, uint callbackID,
                                               string description, string name, sbyte invType,
                                               sbyte type, byte wearableType, uint nextOwnerMask)
        {
            AssetXferUploader uploader = null;

            lock (XferUploaders)
            {
                if (XferUploaders.ContainsKey(transactionID))
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            if (uploader != null)
            {
                uploader.RequestCreateInventoryItem(
                    remoteClient, transactionID, folderID,
                    callbackID, description, name, invType, type,
                    wearableType, nextOwnerMask);
            }
            else
            {
                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to create inventory item {1} from {2}",
                    transactionID, name, remoteClient.Name);
            }
        }
Esempio n. 5
0
        public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
                                                   SceneObjectPart part, UUID transactionID,
                                                   TaskInventoryItem item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
        }
Esempio n. 6
0
        public void RequestCreateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, UUID folderID, uint callbackID,
                                               string description, string name, sbyte invType,
                                               sbyte type, byte wearableType, uint nextOwnerMask)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestCreateInventoryItem(
                remoteClient, folderID, callbackID,
                description, name, invType, type, wearableType, nextOwnerMask);
        }
 private AssetXferUploader GetTransactionUploader(UUID transactionID)
 {
     lock (XferUploaders)
     {
         AssetXferUploader value = null;
         if (XferUploaders.TryGetValue(transactionID, out value))
         {
             return(value);
         }
     }
     return(null);
 }
Esempio n. 8
0
        public void HandleXfer(ulong xferID, uint packetID, byte[] data)
        {
            AssetXferUploader foundUploader = null;

            try
            {
                XferUploaders.ForEach(delegate(AssetXferUploader uploader)
                {
                    //                    m_log.DebugFormat(
                    //                        "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
                    //                        uploader.XferID);

                    if (uploader.XferID == xferID)
                    {
                        throw new ThreadedClasses.ReturnValueException <AssetXferUploader>(uploader);
                    }
                });
                foundUploader = null;
            }
            catch (ThreadedClasses.ReturnValueException <AssetXferUploader> e)
            {
                foundUploader = e.Value;
            }


            if (foundUploader != null)
            {
//                m_log.DebugFormat(
//                    "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
//                    xferID, packetID, data.Length);

                foundUploader.HandleXferPacket(xferID, packetID, data);
            }
            else
            {
                // Check if the xfer is a terrain xfer
                IEstateModule estateModule = m_Scene.RequestModuleInterface <IEstateModule>();
                if (estateModule != null)
                {
                    if (estateModule.IsTerrainXfer(xferID))
                    {
                        return;
                    }
                }

                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
                    xferID, packetID, data.Length);
            }
        }
        public void HandleXfer(ulong xferID, uint packetID, byte[] data)
        {
            AssetXferUploader foundUploader = null;

            m_UploaderRwLock.AcquireReaderLock(-1);
            try
            {
                foreach (AssetXferUploader uploader in XferUploaders.Values)
                {
                    //                    m_log.DebugFormat(
                    //                        "[AGENT ASSETS TRANSACTIONS]: In HandleXfer, inspect xfer upload with xfer id {0}",
                    //                        uploader.XferID);

                    if (uploader.XferID == xferID)
                    {
                        foundUploader = uploader;
                        break;
                    }
                }
            }
            finally
            {
                m_UploaderRwLock.ReleaseReaderLock();
            }

            if (foundUploader != null)
            {
                //                m_log.DebugFormat(
                //                    "[AGENT ASSETS TRANSACTIONS]: Found xfer uploader for xfer id {0}, packet id {1}, data length {2}",
                //                    xferID, packetID, data.Length);

                foundUploader.HandleXferPacket(xferID, packetID, data);
            }
            else
            {
                // Check if the xfer is a terrain xfer
                IEstateModule estateModule = m_Scene.RequestModuleInterface <IEstateModule>();
                if (estateModule != null)
                {
                    if (estateModule.IsTerrainXfer(xferID))
                    {
                        return;
                    }
                }

                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader for xfer id {0}, packet id {1}, data length {2}",
                    xferID, packetID, data.Length);
            }
        }
Esempio n. 10
0
        public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
                                                   SceneObjectPart part, UUID transactionID,
                                                   TaskInventoryItem item)
        {
            AssetXferUploader uploader = null;

            lock (XferUploaders)
            {
                if (XferUploaders.ContainsKey(transactionID))
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            if (uploader != null)
            {
                AssetBase asset = GetTransactionAsset(transactionID);

                // Only legacy viewers use this, and they prefer CAPS, which
                // we have, so this really never runs.
                // Allow it, but only for "safe" types.
                if ((InventoryType)item.InvType != InventoryType.Notecard &&
                    (InventoryType)item.InvType != InventoryType.LSL)
                {
                    return;
                }

                if (asset != null)
                {
//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: Updating item {0} in {1} for transaction {2}",
//                        item.Name, part.Name, transactionID);

                    asset.FullID      = UUID.Random();
                    asset.Name        = item.Name;
                    asset.Description = item.Description;
                    asset.Type        = (sbyte)item.Type;
                    item.AssetID      = asset.FullID;

                    m_Scene.AssetService.Store(asset);
                }
            }
            else
            {
                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to update task inventory item {1} in {2}",
                    transactionID, item.Name, part.Name);
            }
        }
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            if (!XferUploaders.ContainsKey(transactionID))
            {
                AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);

                lock (XferUploaders)
                {
                    XferUploaders.Add(transactionID, uploader);
                }

                return(uploader);
            }
            return(null);
        }
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            if (!XferUploaders.ContainsKey(transactionID))
            {
                AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);

                lock (XferUploaders)
                {
                    XferUploaders.Add(transactionID, uploader);
                }

                return uploader;
            }
            return null;
        }
        public bool RequestUpdateTaskInventoryItem(
            IClientAPI remoteClient, SceneObjectPart part, UUID transactionID, TaskInventoryItem item)
        {
            AssetXferUploader uploader = GetTransactionUploader(transactionID);

            if (uploader == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Transaction {0} NOT FOUND (duplicate removed?) for inventory item update {1}", transactionID, item.Name);
                return(false);
            }

            // This may complete now if upload complete, or later when the upload completes.
            uploader.TriggerWhenUploadComplete(delegate(AssetBase asset)
            {
                // This upload transaction is complete.
                XferUploaders.Remove(transactionID);

                if (asset == null)
                {
                    return;         // UpdateItem() not called
                }
                m_log.DebugFormat(
                    "[ASSET TRANSACTIONS]: Updating task item {0} in {1} with asset in transaction {2}",
                    item.Name, part.Name, transactionID);

                asset.Name        = item.Name;
                asset.Description = item.Description;
                asset.Type        = (sbyte)item.Type;

                try
                {
                    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());
                    if (part.Inventory.UpdateTaskInventoryItemAsset(part.UUID, item.ItemID, asset.FullID))
                    {
                        part.GetProperties(remoteClient);
                    }
                }
                catch (AssetServerException e)
                {
                    remoteClient.SendAgentAlertMessage("Unable to upload asset. Please try again later.", false);

                    m_log.ErrorFormat("[ASSET TRANSACTIONS] Unable to update task item due to asset server error {0}", e);
                }
            });

            // We at least found an uploader with that transaction ID.
            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// Get an uploaded asset. If the data is successfully retrieved,
        /// the transaction will be removed.
        /// </summary>
        /// <param name="transactionID"></param>
        /// <returns>The asset if the upload has completed, null if it has not.</returns>
        private AssetBase GetTransactionAsset(UUID transactionID)
        {
            lock (XferUploaders)
            {
                if (XferUploaders.ContainsKey(transactionID))
                {
                    AssetXferUploader uploader = XferUploaders[transactionID];
                    AssetBase         asset    = uploader.GetAssetData();
                    RemoveXferUploader(transactionID);

                    return(asset);
                }
            }

            return(null);
        }
Esempio n. 15
0
        /// <summary>
        /// Request that a client (agent) begin an asset transfer.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="assetID"></param>
        /// <param name="transactionID"></param>
        /// <param name="type"></param>
        /// <param name="data"></param></param>
        /// <param name="tempFile"></param>
        public void HandleUDPUploadRequest(IClientAPI remoteClient,
                                           UUID assetID, UUID transactionID, sbyte type, byte[] data,
                                           bool storeLocal, bool tempFile)
        {
//            m_log.DebugFormat(
//                "[ASSET TRANSACTION MODULE]: HandleUDPUploadRequest - assetID: {0}, transaction {1}, type {2}, storeLocal {3}, tempFile {4}, data.Length {5}",
//                assetID, transactionID, type, storeLocal, tempFile, data.Length);

            if (((AssetType)type == AssetType.Texture ||
                 (AssetType)type == AssetType.Sound ||
                 (AssetType)type == AssetType.TextureTGA ||
                 (AssetType)type == AssetType.Animation) &&
                tempFile == false)
            {
                ScenePresence avatar = null;
                Scene         scene  = (Scene)remoteClient.Scene;
                scene.TryGetScenePresence(remoteClient.AgentId, out avatar);

                // check user level
                if (avatar != null)
                {
                    if (avatar.UserLevel < m_levelUpload)
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
                        return;
                    }
                }

                // check funds
                IMoneyModule mm = scene.RequestModuleInterface <IMoneyModule>();

                if (mm != null)
                {
                    if (!mm.UploadCovered(remoteClient.AgentId, mm.UploadCharge))
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
                        return;
                    }
                }
            }

            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
            AssetXferUploader      uploader     = transactions.RequestXferUploader(transactionID);

            uploader.StartUpload(remoteClient, assetID, transactionID, type, data, storeLocal, tempFile);
        }
        /// <summary>
        /// Get an uploaded asset.  If the data is successfully retrieved, the transaction will be removed.
        /// </summary>
        /// <param name="transactionID"></param>
        /// <returns>The asset if the upload has completed, null if it has not.</returns>
        public AssetBase GetTransactionAsset(UUID transactionID)
        {
            if (XferUploaders.ContainsKey(transactionID))
            {
                AssetXferUploader uploader = XferUploaders[transactionID];
                AssetBase         asset    = uploader.GetAssetData();

                lock (XferUploaders)
                {
                    XferUploaders.Remove(transactionID);
                }

                return(asset);
            }

            return(null);
        }
        public void RequestCreateInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
                                               uint callbackID, string description, string name, sbyte invType,
                                               sbyte type, byte wearableType, uint nextOwnerMask)
        {
            AssetXferUploader uploader = null;

            lock (XferUploaders)
            {
                XferUploaders.TryGetValue(transactionID, out uploader);
            }

            if (uploader != null)
            {
                uploader.RequestCreateInventoryItem(remoteClient, transactionID, folderID,
                                                    callbackID, description, name, invType, type,
                                                    wearableType, nextOwnerMask);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Request that a client (agent) begin an asset transfer.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="assetID"></param>
        /// <param name="transaction"></param>
        /// <param name="type"></param>
        /// <param name="data"></param></param>
        /// <param name="tempFile"></param>
        public void HandleUDPUploadRequest(IClientAPI remoteClient,
                                           UUID assetID, UUID transaction, sbyte type, byte[] data,
                                           bool storeLocal, bool tempFile)
        {
//            m_log.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);

            if (((AssetType)type == AssetType.Texture ||
                 (AssetType)type == AssetType.Sound ||
                 (AssetType)type == AssetType.TextureTGA ||
                 (AssetType)type == AssetType.Animation) &&
                tempFile == false)
            {
                ScenePresence avatar = null;
                Scene         scene  = (Scene)remoteClient.Scene;
                scene.TryGetScenePresence(remoteClient.AgentId, out avatar);

                // check user level
                if (avatar != null)
                {
                    if (avatar.UserLevel < m_levelUpload)
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient permissions.", false);
                        return;
                    }
                }

                // check funds
                IMoneyModule mm = scene.RequestModuleInterface <IMoneyModule>();

                if (mm != null)
                {
                    if (!mm.UploadCovered(remoteClient.AgentId, mm.UploadCharge))
                    {
                        remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
                        return;
                    }
                }
            }

            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
            AssetXferUploader      uploader     = transactions.RequestXferUploader(transaction);

            uploader.StartUpload(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
        }
 public AssetXferUploader RequestXferUploader(UUID transactionID)
 {
     lock (XferUploaders)
     {
         if (!XferUploaders.ContainsKey(transactionID))
         {
             AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
             if (uploader != null)
             {
                 XferUploaders.Add(transactionID, uploader);
                 if (cleanupTimer == null)
                 {
                     cleanupTimer = new Timer(CleanupCallback, null, 0, 60000); // once per minute
                 }
             }
             return(uploader);
         }
         return(null);
     }
 }
Esempio n. 20
0
        public void RequestUpdateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            // Here we need to get the old asset to extract the
            // texture UUIDs if it's a wearable.
            if (item.AssetType == (int)AssetType.Bodypart ||
                item.AssetType == (int)AssetType.Clothing ||
                item.AssetType == (int)CustomAssetType.AnimationSet)
            {
                AssetBase oldAsset = m_Scene.AssetService.Get(item.AssetID.ToString());
                if (oldAsset != null)
                {
                    uploader.SetOldData(oldAsset.Data);
                }
            }

            uploader.RequestUpdateInventoryItem(remoteClient, item);
        }
Esempio n. 21
0
        /// <summary>
        /// Return a xfer uploader if one does not already exist.
        /// </summary>
        /// <param name="transactionID"></param>
        /// <param name="assetID">
        /// We must transfer the new asset ID into the uploader on creation, otherwise
        /// we can see race conditions with other threads which can retrieve an item before it is updated with the new
        /// asset id.
        /// </param>
        /// <returns>
        /// The xfer uploader requested.  Null if one is already in existence.
        /// FIXME: This is a bizarre thing to do, and is probably meant to signal an error condition if multiple
        /// transfers are made.  Needs to be corrected.
        /// </returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID, UUID assetID)
        {
            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    AssetXferUploader uploader = new AssetXferUploader(this, m_Scene, assetID, m_dumpAssetsToFile);

//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);

                    return uploader;
                }
            }

            m_log.WarnFormat("[AGENT ASSETS TRANSACTIONS]: Ignoring request for asset xfer uploader {0} since it already exists", transactionID);

            return null;
        }
Esempio n. 22
0
        /// <summary>
        /// Return a xfer uploader if one does not already exist.
        /// </summary>
        /// <param name="transactionID"></param>
        /// <param name="assetID">
        /// We must transfer the new asset ID into the uploader on creation, otherwise
        /// we can see race conditions with other threads which can retrieve an item before it is updated with the new
        /// asset id.
        /// </param>
        /// <returns>
        /// The xfer uploader requested.  Null if one is already in existence.
        /// FIXME: This is a bizarre thing to do, and is probably meant to signal an error condition if multiple
        /// transfers are made.  Needs to be corrected.
        /// </returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID, UUID assetID)
        {
            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    AssetXferUploader uploader = new AssetXferUploader(this, m_Scene, assetID, m_dumpAssetsToFile);

//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);

                    return(uploader);
                }
            }

            m_log.WarnFormat("[AGENT ASSETS TRANSACTIONS]: Ignoring request for asset xfer uploader {0} since it already exists", transactionID);

            return(null);
        }
Esempio n. 23
0
        /// <summary>
        /// Return the xfer uploader for the given transaction.
        /// </summary>
        /// <remarks>
        /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
        /// uploader is returned.
        /// </remarks>
        /// <param name="transactionID"></param>
        /// <returns>The asset xfer uploader</returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            AssetXferUploader uploader;

            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);

//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);
                }
                else
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            return uploader;
        }
        private void CleanupCallback(object state)
        {
            lock (XferUploaders)
            {
                List <UUID> expiredUploaders = new List <UUID>();

                foreach (KeyValuePair <UUID, AssetXferUploader> kvp in XferUploaders)
                {
                    AssetXferUploader uploader = kvp.Value;
                    if ((DateTime.Now - uploader.LastAccess).TotalMinutes > 10)
                    {
                        UUID transactionID = kvp.Key;
                        expiredUploaders.Add(transactionID);
                        m_log.WarnFormat("[ASSET TRANSACTIONS]: Timeout on asset upload for transaction {0}", transactionID);
                    }
                }

                foreach (UUID transactionID in expiredUploaders)
                {
                    XferUploaders.Remove(transactionID);
                }
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Return the xfer uploader for the given transaction.
        /// </summary>
        /// <remarks>
        /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
        /// uploader is returned.
        /// </remarks>
        /// <param name="transactionID"></param>
        /// <returns>The asset xfer uploader</returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            AssetXferUploader uploader;

            lock (XferUploaders)
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);

//                    m_log.DebugFormat(
//                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                    XferUploaders.Add(transactionID, uploader);
                }
                else
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            return(uploader);
        }
        /// <summary>
        /// Return the xfer uploader for the given transaction.
        /// </summary>
        /// <remarks>
        /// If an uploader does not already exist for this transaction then it is created, otherwise the existing
        /// uploader is returned.
        /// </remarks>
        /// <param name="transactionID"></param>
        /// <returns>The asset xfer uploader</returns>
        public AssetXferUploader RequestXferUploader(UUID transactionID)
        {
            AssetXferUploader uploader;

            m_UploaderRwLock.AcquireReaderLock(-1);
            try
            {
                if (!XferUploaders.ContainsKey(transactionID))
                {
                    LockCookie lc = m_UploaderRwLock.UpgradeToWriterLock(-1);
                    try
                    {
                        uploader = new AssetXferUploader(this, m_Scene, transactionID, m_dumpAssetsToFile);

                        //                    m_log.DebugFormat(
                        //                        "[AGENT ASSETS TRANSACTIONS]: Adding asset xfer uploader {0} since it didn't previously exist", transactionID);

                        XferUploaders.Add(transactionID, uploader);
                    }
                    finally
                    {
                        m_UploaderRwLock.DowngradeFromWriterLock(ref lc);
                    }
                }
                else
                {
                    uploader = XferUploaders[transactionID];
                }
            }
            finally
            {
                m_UploaderRwLock.ReleaseReaderLock();
            }

            return(uploader);
        }
Esempio n. 27
0
        public void RequestUpdateInventoryItem(IClientAPI remoteClient,
                                               UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = null;

            lock (XferUploaders)
            {
                if (XferUploaders.ContainsKey(transactionID))
                {
                    uploader = XferUploaders[transactionID];
                }
            }

            if (uploader != null)
            {
                uploader.RequestUpdateInventoryItem(remoteClient, transactionID, item);
            }
            else
            {
                m_log.ErrorFormat(
                    "[AGENT ASSET TRANSACTIONS]: Could not find uploader with transaction ID {0} when handling request to update inventory item {1} for {2}",
                    transactionID, item.Name, remoteClient.Name);
            }
        }
        /// <summary>
        /// Request that a client (agent) begin an asset transfer.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="assetID"></param>
        /// <param name="transaction"></param>
        /// <param name="type"></param>
        /// <param name="data"></param></param>
        /// <param name="tempFile"></param>
        public void HandleUDPUploadRequest(IClientAPI remoteClient, UUID assetID, UUID transaction, sbyte type,
                                           byte[] data, bool storeLocal, bool tempFile)
        {
//            m_log.Debug("HandleUDPUploadRequest - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);
            Scene        scene = (Scene)remoteClient.Scene;
            IMoneyModule mm    = scene.RequestModuleInterface <IMoneyModule>();

            if (mm == null)
            {
                remoteClient.SendAgentAlertMessage("Server configuration error - cannot upload asset.", false);
                return;
            }

            if (mm.UploadChargeApplies((AssetType)type) && !tempFile)
            {
                if (!mm.UploadCovered(remoteClient.AgentId))
                {
                    remoteClient.SendAgentAlertMessage("Unable to upload asset. Insufficient funds.", false);
                    return;
                }
            }

            //m_log.Debug("asset upload of " + assetID);
            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);
            AssetXferUploader      uploader     = transactions.RequestXferUploader(transaction);

            if (uploader == null)
            {
                remoteClient.SendAgentAlertMessage("Server error uploading asset. Could not allocate uploader.", false);
                return;
            }
//            m_log.Debug("HandleUDPUploadRequest(Initialize) - assetID: " + assetID.ToString() + " transaction: " + transaction.ToString() + " type: " + type.ToString() + " storelocal: " + storeLocal + " tempFile: " + tempFile);

            // Okay, start the upload.
            uploader.Initialize(remoteClient, assetID, transaction, type, data, storeLocal, tempFile);
        }
        public bool RequestUpdateInventoryItem(IClientAPI remoteClient, UUID transactionID, InventoryItemBase item)
        {
            AssetXferUploader uploader = GetTransactionUploader(transactionID);

            if (uploader == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Transaction {0} NOT FOUND (duplicate removed?) for inventory item update {1}", transactionID, item.Name);
                return(false);
            }

            CachedUserInfo userInfo = Manager.MyScene.CommsManager.UserService.GetUserDetails(remoteClient.AgentId);

            if (userInfo == null)
            {
                m_log.WarnFormat("[ASSET TRANSACTIONS]: Could not find user {0} for transaction {1} for inventory update {2}",
                                 remoteClient.AgentId, transactionID, item.Name);
                return(false);
            }

            // This may complete now if upload complete, or later when the upload completes.
            uploader.TriggerWhenUploadComplete(delegate(AssetBase asset)
            {
                // This upload transaction is complete.
                XferUploaders.Remove(transactionID);

                UUID assetID = UUID.Combine(transactionID, remoteClient.SecureSessionId);
                if (asset == null || asset.FullID != assetID)
                {
                    m_log.ErrorFormat("[ASSETS]: RequestUpdateInventoryItem wrong asset ID or not found {0}", asset == null ? "null" : asset.FullID.ToString());
                    return;
                }

                // Assets never get updated, new ones get created
                UUID oldID        = asset.FullID;
                asset.FullID      = UUID.Random();
                asset.Name        = item.Name;
                asset.Description = item.Description;
                asset.Type        = (sbyte)item.AssetType;

                try
                {
                    m_log.DebugFormat("[ASSETS]: RequestUpdateInventoryItem for transaction {0}, new asset {1} -> {2}", transactionID, oldID, asset.FullID);
                    Manager.MyScene.CommsManager.AssetCache.AddAsset(asset, AssetRequestInfo.GenericNetRequest());
                }
                catch (AssetServerException e)
                {
                    remoteClient.SendAgentAlertMessage("Unable to upload asset. Please try again later.", false);
                    m_log.ErrorFormat("[ASSET TRANSACTIONS] Creation of asset failed {0}", e);
                    return;
                }

                item.AssetID = asset.FullID;

                //wait for completion of the write to avoid reversion
                ManualResetEventSlim waitEvent = new ManualResetEventSlim();

                remoteClient.HandleWithInventoryWriteThread(() =>
                {
                    // Update the asset ID
                    userInfo.UpdateItem(item);
                    waitEvent.Set();
                });

                waitEvent.Wait();
                waitEvent.Dispose();
            });

            return(true);    // userInfo item was updated
        }
 public AssetXferUploader RequestXferUploader(UUID transactionID)
 {
     lock (XferUploaders)
     {
         if (!XferUploaders.ContainsKey(transactionID))
         {
             AssetXferUploader uploader = new AssetXferUploader(this, m_dumpAssetsToFile);
             if (uploader != null)
             {
                 XferUploaders.Add(transactionID, uploader);
                 if (cleanupTimer == null)
                     cleanupTimer = new Timer(CleanupCallback, null, 0, 60000); // once per minute
             }
             return uploader;
         }
         return null;
     }
 }