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 }
/// <summary> /// Update an item which is either already in the client's inventory or is within /// a transaction /// </summary> /// <param name="remoteClient"></param> /// <param name="transactionID">The transaction ID. If this is UUID.Zero we will /// assume that we are not in a transaction</param> /// <param name="itemID">The ID of the updated item</param> /// <param name="name">The name of the updated item</param> /// <param name="description">The description of the updated item</param> /// <param name="nextOwnerMask">The permissions of the updated item</param> /* public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID, UUID itemID, string name, string description, uint nextOwnerMask)*/ public void UpdateInventoryItemAsset(IClientAPI remoteClient, UUID transactionID, UUID itemID, InventoryItemBase itemUpd) { CachedUserInfo userInfo = CommsManager.UserService.GetUserDetails(remoteClient.AgentId); if (userInfo == null) { m_log.Error("[AGENT INVENTORY]: Agent ID " + remoteClient.AgentId + " inventory not found for item update."); return; } InventoryItemBase item = userInfo.FindItem(itemID); if (item == null) { m_log.Error("[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update."); return; } //make sure we actually OWN the item if (item.Owner != remoteClient.AgentId) { m_log.ErrorFormat("[AGENT INVENTORY]: User {0} does not own item {1}, not updating", remoteClient.AgentId, itemID); remoteClient.SendInventoryItemDetails(item.Owner, item); return; } // Update the item with the changes passed to us from the viewer item.Name = itemUpd.Name; item.Description = itemUpd.Description; // Limit perms updates to base permissions (0 means no change?) if (itemUpd.EveryOnePermissions == 0) itemUpd.EveryOnePermissions = item.EveryOnePermissions; else itemUpd.EveryOnePermissions &= item.BasePermissions; if (itemUpd.GroupPermissions == 0) itemUpd.GroupPermissions &= item.GroupPermissions; else itemUpd.GroupPermissions &= item.BasePermissions; if (itemUpd.NextPermissions == 0) itemUpd.NextPermissions &= item.NextPermissions; else itemUpd.NextPermissions &= item.BasePermissions; // Check for permissions changes if (ChangingInventoryItemPerms(item, itemUpd)) { if (InventoryItemIsAttached(remoteClient, itemID)) { remoteClient.SendAlertMessage("To change an attachment's permissions, you must first drop it or detach it."); remoteClient.SendInventoryItemDetails(item.Owner, item); return; } if (!MatchInventoryRootPartStoredOwner(item, 0, item.Owner)) { // This item has been recently transferred between users, and not rezzed. // We cannot allow permissions changes in this state. Rezzing it fixes it. // See http://inworldz.com/mantis/view.php?id=1664 remoteClient.SendAlertMessage("You cannot change the Next Owner permissions on this item until it has been rezzed in-world by you at least once."); InformClientOfInvChange(remoteClient, item); return; } // Perform the actual permissions update now. item.EveryOnePermissions = itemUpd.EveryOnePermissions; item.GroupPermissions = itemUpd.GroupPermissions; item.NextPermissions = itemUpd.NextPermissions; if (item.InvType == (int)InventoryType.Object) { item.CurrentPermissions |= ScenePermBits.SLAM; // Slam! item.Flags |= (uint)InventoryItemFlags.ObjectSlamPerm; // Tell the viewer we are going to slam this } } item.GroupID = itemUpd.GroupID; item.GroupOwned = itemUpd.GroupOwned; item.CreationDate = itemUpd.CreationDate; // The client sends zero if its newly created? if (itemUpd.CreationDate == 0) item.CreationDate = Util.UnixTimeSinceEpoch(); else item.CreationDate = itemUpd.CreationDate; // TODO: Check if folder changed and move item //item.NextPermissions = itemUpd.Folder; item.InvType = itemUpd.InvType; item.SalePrice = itemUpd.SalePrice; item.SaleType = itemUpd.SaleType; item.Flags = itemUpd.Flags; // Check if the viewer has passed us a transaction to use if (UUID.Zero != transactionID) { IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>(); if (agentTransactions != null) if (agentTransactions.HandleItemUpdateFromTransaction(remoteClient, transactionID, item)) return; // great, this one has been handled (as a transaction update) } remoteClient.HandleWithInventoryWriteThread(() => { // Otherwise fall through and do a normal inventory update userInfo.UpdateItem(item); remoteClient.SendInventoryItemDetails(item.Owner, item); }); }
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.UserProfileCacheService.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 }