public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient, TaskInventoryItem taskItem)
        {
            // We must lock to avoid a race with a separate thread uploading the asset.
            lock (this)
            {
                m_asset.Name = taskItem.Name;
                m_asset.Description = taskItem.Description;
                m_asset.Type = (sbyte) taskItem.Type;
                taskItem.AssetID = m_asset.ID;

                if (m_uploadState == UploadState.Complete)
                {
                    CompleteTaskItemUpdate(taskItem);
                }
                else
                {
                    m_updateTaskItem = true;
                    m_updateTaskItemData = taskItem;
                }
            }
        }
        /// <summary>
        ///     Store the asset for the given task item when it has been uploaded.
        /// </summary>
        /// <param name="taskItem"></param>
        private void CompleteTaskItemUpdate(TaskInventoryItem taskItem)
        {
            //            MainConsole.Instance.DebugFormat(
            //                "[ASSET XFER UPLOADER]: Storing asset {0} for earlier task item update for {1} for {2}",
            //                m_asset.FullID, taskItem.Name, ourClient.Name);

            m_Scene.AssetService.Store(m_asset);

            m_transactions.RemoveXferUploader(m_transactionID);
        }
        public void RequestUpdateTaskInventoryItem(IClientAPI remoteClient,
            ISceneChildEntity part, UUID transactionID,
            TaskInventoryItem item)
        {
            AssetXferUploader uploader = RequestXferUploader(transactionID);

            uploader.RequestUpdateTaskInventoryItem(remoteClient, item);
        }
示例#4
0
        /// <summary>
        ///     Rez an object into the scene from a prim's inventory.
        /// </summary>
        /// <param name="sourcePart"></param>
        /// <param name="item"></param>
        /// <param name="pos"></param>
        /// <param name="rot"></param>
        /// <param name="vel"></param>
        /// <param name="param"></param>
        /// <param name="RezzedFrom"></param>
        /// <param name="RezObjectAtRoot"></param>
        /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful</returns>
        public ISceneEntity RezObject(
            ISceneChildEntity sourcePart, TaskInventoryItem item,
            Vector3 pos, Quaternion rot, Vector3 vel, int param, UUID RezzedFrom, bool RezObjectAtRoot)
        {
            if (item != null)
            {
                UUID ownerID = item.OwnerID;

                byte[] rezAsset = World.AssetService.GetData(item.AssetID.ToString());

                if (rezAsset != null)
                {
                    string xmlData = Utils.BytesToString(rezAsset);
                    ISceneEntity group = SceneEntitySerializer.SceneObjectSerializer.FromOriginalXmlFormat(xmlData,
                                                                                                           World);
                    if (group == null)
                        return null;

                    string reason;
                    if (!World.Permissions.CanRezObject(group.ChildrenEntities().Count, ownerID, pos, out reason))
                    {
                        World.GetScenePresence(ownerID)
                             .ControllingClient.SendAlertMessage("You do not have permission to rez objects here: " +
                                                                 reason);
                        return null;
                    }

                    List<ISceneChildEntity> partList = group.ChildrenEntities();
                    // we set it's position in world.
                    // llRezObject sets the whole group at the position, while llRezAtRoot rezzes the group based on the root prim's position
                    // See: http://lslwiki.net/lslwiki/wakka.php?wakka=llRezAtRoot
                    // Shorthand: llRezAtRoot rezzes the root prim of the group at the position
                    //            llRezObject rezzes the center of group at the position
                    if (RezObjectAtRoot)
                        //This sets it right...
                        group.AbsolutePosition = pos;
                    else
                    {
                        // center is on average of all positions
                        // less root prim position
                        Vector3 offset = partList.Aggregate(Vector3.Zero,
                                                            (current, child) => current + child.AbsolutePosition);

                        offset /= partList.Count;
                        offset -= group.AbsolutePosition;
                        offset += pos;
                        group.AbsolutePosition = offset;
                    }

                    ISceneChildEntity rootPart = group.GetChildPart(group.UUID);

                    // Since renaming the item in the inventory does not affect the name stored
                    // in the serialization, transfer the correct name from the inventory to the
                    // object itself before we rez.
                    rootPart.Name = item.Name;
                    rootPart.Description = item.Description;

                    group.SetGroup(sourcePart.GroupID, group.OwnerID, false);

                    if (rootPart.OwnerID != item.OwnerID)
                    {
                        if (World.Permissions.PropagatePermissions())
                        {
                            if ((item.CurrentPermissions & 8) != 0)
                            {
                                foreach (ISceneChildEntity part in partList)
                                {
                                    part.EveryoneMask = item.EveryonePermissions;
                                    part.NextOwnerMask = item.NextPermissions;
                                }
                            }
                            group.ApplyNextOwnerPermissions();
                        }
                    }

                    foreach (ISceneChildEntity part in partList)
                    {
                        if (part.OwnerID != item.OwnerID)
                        {
                            part.LastOwnerID = part.OwnerID;
                            part.OwnerID = item.OwnerID;
                            part.Inventory.ChangeInventoryOwner(item.OwnerID);
                        }
                        else if ((item.CurrentPermissions & 8) != 0) // Slam!
                        {
                            part.EveryoneMask = item.EveryonePermissions;
                            part.NextOwnerMask = item.NextPermissions;
                        }
                    }

                    rootPart.TrimPermissions();

                    if (group.RootChild.Shape.PCode == (byte)PCode.Prim)
                    {
                        group.ClearPartAttachmentData();
                    }

                    group.UpdateGroupRotationR(rot);

                    //group.ApplyPhysics(m_physicalPrim);
                    World.SceneGraph.AddPrimToScene(group);
                    if ((group.RootChild.Flags & PrimFlags.Physics) == PrimFlags.Physics)
                    {
                        group.RootChild.PhysActor.OnPhysicalRepresentationChanged += 
                            delegate {
                            float groupmass = group.GetMass();
                            //Apply the velocity to the object
                            //llApplyImpulse(new LSL_Vector(llvel.X * groupmass, llvel.Y * groupmass, llvel.Z * groupmass), 0);
                            // @Above: Err.... no. Read http://lslwiki.net/lslwiki/wakka.php?wakka=llRezObject
                            //    Notice the "Creates ("rezzes") object's inventory object centered at position pos (in region coordinates) with velocity vel"
                            //    This means SET the velocity to X, not just temperarily add it!
                            //   -- Revolution Smythe
                            llSetForce( new LSL_Vector(vel * groupmass), 0);
                            group.RootChild.PhysActor.ForceSetVelocity(vel * groupmass);
                            group.RootChild.PhysActor.Velocity = vel * groupmass;
                        };
                    }

                    group.CreateScriptInstances(param, true, StateSource.ScriptedRez, RezzedFrom, false);

                    if (!World.Permissions.BypassPermissions())
                    {
                        if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
                            sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
                    }

                    group.ScheduleGroupUpdate(PrimUpdateFlags.FullUpdate);

                    return rootPart.ParentEntity;
                }
            }

            return null;
        }
示例#5
0
        // This needs ThreatLevel high. It is an excellent griefer tool,
        // In a loop, it can cause asset bloat and DOS levels of asset
        // writes.
        //
        public void osMakeNotecard(string notecardName, LSL_List contents)
        {
            if (!ScriptProtection.CheckThreatLevel(ThreatLevel.High, "osMakeNotecard", m_host, "OSSL", m_itemID))
                return;

            // Create new asset
            AssetBase asset = new AssetBase(UUID.Random(), notecardName, AssetType.Notecard, m_host.OwnerID)
                                  {
                                      Description
                                          =
                                          "Script Generated Notecard"
                                  };
            string notecardData = String.Empty;

            for (int i = 0; i < contents.Length; i++)
            {
                notecardData += contents.GetLSLStringItem(i) + "\n";
            }

            int textLength = notecardData.Length;
            notecardData = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length "
                           + textLength.ToString(CultureInfo.InvariantCulture) + "\n" + notecardData + "}\n";

            asset.Data = Util.UTF8.GetBytes(notecardData);
            asset.ID = World.AssetService.Store(asset);

            // Create Task Entry
            TaskInventoryItem taskItem = new TaskInventoryItem();

            taskItem.ResetIDs(m_host.UUID);
            taskItem.ParentID = m_host.UUID;
            taskItem.CreationDate = (uint) Util.UnixTimeSinceEpoch();
            taskItem.Name = asset.Name;
            taskItem.Description = asset.Description;
            taskItem.Type = (int) AssetType.Notecard;
            taskItem.InvType = (int) InventoryType.Notecard;
            taskItem.OwnerID = m_host.OwnerID;
            taskItem.CreatorID = m_host.OwnerID;
            taskItem.BasePermissions = (uint) PermissionMask.All;
            taskItem.CurrentPermissions = (uint) PermissionMask.All;
            taskItem.EveryonePermissions = 0;
            taskItem.NextPermissions = (uint) PermissionMask.All;
            taskItem.GroupID = m_host.GroupID;
            taskItem.GroupPermissions = 0;
            taskItem.Flags = 0;
            taskItem.SalePrice = 0;
            taskItem.SaleType = 0;
            taskItem.PermsGranter = UUID.Zero;
            taskItem.PermsMask = 0;
            taskItem.AssetID = asset.ID;

            m_host.Inventory.AddInventoryItem(taskItem, false);
        }
        /// <summary>
        ///     Add an inventory item to a prim in this group.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="localID"></param>
        /// <param name="item"></param>
        /// <param name="copyItemID">The item UUID that should be used by the new item.</param>
        /// <returns></returns>
        public bool AddInventoryItem(IClientAPI remoteClient, uint localID,
            InventoryItemBase item, UUID copyItemID)
        {
            UUID newItemId = (copyItemID != UUID.Zero) ? copyItemID : item.ID;

            SceneObjectPart part = (SceneObjectPart) GetChildPart(localID);
            if (part != null)
            {
                TaskInventoryItem taskItem = new TaskInventoryItem
                                                 {
                                                     ItemID = newItemId,
                                                     AssetID = item.AssetID,
                                                     Name = item.Name,
                                                     Description = item.Description,
                                                     OwnerID = part.OwnerID,
                                                     CreatorID = item.CreatorIdAsUuid,
                                                     Type = item.AssetType,
                                                     InvType = item.InvType
                                                 };

                // Transfer ownership

                if (remoteClient != null &&
                    remoteClient.AgentId != part.OwnerID &&
                    m_scene.Permissions.PropagatePermissions())
                {
                    taskItem.BasePermissions = item.BasePermissions &
                                               item.NextPermissions;
                    taskItem.CurrentPermissions = item.CurrentPermissions &
                                                  item.NextPermissions;
                    taskItem.EveryonePermissions = item.EveryOnePermissions &
                                                   item.NextPermissions;
                    taskItem.GroupPermissions = item.GroupPermissions &
                                                item.NextPermissions;
                    taskItem.NextPermissions = item.NextPermissions;
                    // We're adding this to a prim we don't own. Force
                    // owner change
                    taskItem.CurrentPermissions |= 16; // Slam
                }
                else
                {
                    taskItem.BasePermissions = item.BasePermissions;
                    taskItem.CurrentPermissions = item.CurrentPermissions;
                    taskItem.EveryonePermissions = item.EveryOnePermissions;
                    taskItem.GroupPermissions = item.GroupPermissions;
                    taskItem.NextPermissions = item.NextPermissions;
                }

                taskItem.Flags = item.Flags;
                taskItem.SalePrice = item.SalePrice;
                taskItem.SaleType = item.SaleType;
                taskItem.CreationDate = (uint) item.CreationDate;

                bool addFromAllowedDrop = false;
                if (remoteClient != null)
                {
                    addFromAllowedDrop = remoteClient.AgentId != part.OwnerID;
                }

                part.Inventory.AddInventoryItem(taskItem, addFromAllowedDrop);

                return true;
            }
            MainConsole.Instance.ErrorFormat(
                "[PRIM INVENTORY]: " +
                "Couldn't find prim local ID {0} in group {1}, {2} to add inventory item ID {3}",
                localID, Name, UUID, newItemId);

            return false;
        }
        /// <summary>
        ///     Start a script which is in this prim's inventory.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="startParam"></param>
        /// <param name="postOnRez"></param>
        /// <param name="stateSource"></param>
        /// <returns></returns>
        public void CreateScriptInstance(TaskInventoryItem item, int startParam, bool postOnRez, StateSource stateSource)
        {
            // MainConsole.Instance.InfoFormat(
            //     "[PRIM INVENTORY]: " +
            //     "Starting script {0}, {1} in prim {2}, {3}",
            //     item.Name, item.ItemID, Name, UUID);

            if (!m_part.ParentGroup.Scene.Permissions.CanRunScript(item.ItemID, m_part.UUID, item.OwnerID))
                return;

            if (!m_part.ParentGroup.Scene.RegionInfo.RegionSettings.DisableScripts)
            {
                lock (m_itemsLock)
                {
                    m_items[item.ItemID].PermsMask = 0;
                    m_items[item.ItemID].PermsGranter = UUID.Zero;
                }

                bool SendUpdate = m_part.AddFlag(PrimFlags.Scripted);
                m_part.ParentGroup.Scene.EventManager.TriggerRezScripts(
                    m_part, new[] {item}, startParam, postOnRez, stateSource, UUID.Zero, false);
                if (SendUpdate)
                    m_part.ScheduleUpdate(PrimUpdateFlags.PrimFlags); //We only need to send a compressed
            }
            HasInventoryChanged = true;
            ResumeScript(item);
        }
        /// <summary>
        ///     Rez a script into a prim's inventory from another prim
        ///     This is used for the LSL function llRemoteLoadScriptPin and requires a valid pin to be used
        /// </summary>
        /// <param name="srcId">The UUID of the script that is going to be copied</param>
        /// <param name="srcPart">The prim that the script that is going to be copied from</param>
        /// <param name="destId">The UUID of the prim that the </param>
        /// <param name="pin">The ScriptAccessPin of the prim</param>
        /// <param name="running">Whether the script should be running when it is started</param>
        /// <param name="startParam">The start param to pass to the script</param>
        public void RezScript(UUID srcId, ISceneChildEntity srcPart, UUID destId, int pin, int running, int startParam)
        {
            TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);

            if (srcTaskItem == null)
            {
                MainConsole.Instance.ErrorFormat(
                    "[Prim inventory]: Could not find part {0} to insert script item {1} from {2} {3} in {4}",
                    destId, srcId, srcPart.Name, srcPart.UUID, Name);
                return;
            }

            ISceneChildEntity destPart = m_scene.GetSceneObjectPart(destId);

            if (destPart == null)
            {
                MainConsole.Instance.ErrorFormat(
                    "[Prim inventory]: Could not find script for ID {0}",
                    destId);
                return;
            }

            // Must own the object, and have modify rights
            if (srcPart.OwnerID != destPart.OwnerID)
            {
                // Group permissions
                if ((destPart.GroupID == UUID.Zero) || (destPart.GroupID != srcPart.GroupID) ||
                    ((destPart.GroupMask & (uint) PermissionMask.Modify) == 0))
                    return;
            }
            else
            {
                if ((destPart.OwnerMask & (uint) PermissionMask.Modify) == 0)
                    return;
            }

            if (destPart.ScriptAccessPin == 0 || destPart.ScriptAccessPin != pin)
            {
                MainConsole.Instance.WarnFormat(
                    "[Prim inventory]: Script in object {0} : {1}, attempted to load script {2} : {3} into object {4} : {5} with invalid pin {6}",
                    srcPart.Name, srcId, srcTaskItem.Name, srcTaskItem.ItemID, destPart.Name, destId, pin);
                // the LSL Wiki says we are supposed to shout on the DEBUG_CHANNEL -
                //   "Object: Task Object trying to illegally load script onto task Other_Object!"
                // How do we shout from in here?
                return;
            }

            TaskInventoryItem destTaskItem = new TaskInventoryItem
                                                 {
                                                     ItemID = UUID.Random(),
                                                     CreatorID = srcTaskItem.CreatorID,
                                                     CreatorData = srcTaskItem.CreatorData,
                                                     AssetID = srcTaskItem.AssetID,
                                                     GroupID = destPart.GroupID,
                                                     OwnerID = destPart.OwnerID,
                                                     ParentID = destPart.UUID,
                                                     ParentPartID = destPart.UUID,
                                                     BasePermissions = srcTaskItem.BasePermissions,
                                                     EveryonePermissions = srcTaskItem.EveryonePermissions,
                                                     GroupPermissions = srcTaskItem.GroupPermissions,
                                                     CurrentPermissions = srcTaskItem.CurrentPermissions,
                                                     NextPermissions = srcTaskItem.NextPermissions,
                                                     Flags = srcTaskItem.Flags,
                                                     SalePrice = srcTaskItem.SalePrice,
                                                     SaleType = srcTaskItem.SaleType
                                                 };


            if (destPart.OwnerID != srcPart.OwnerID)
            {
                if (m_scene.Permissions.PropagatePermissions())
                {
                    destTaskItem.CurrentPermissions = 
                        srcTaskItem.CurrentPermissions & srcTaskItem.NextPermissions;
                    destTaskItem.GroupPermissions = 
                        srcTaskItem.GroupPermissions & srcTaskItem.NextPermissions;
                    destTaskItem.EveryonePermissions = 
                        srcTaskItem.EveryonePermissions & srcTaskItem.NextPermissions;
                    destTaskItem.BasePermissions = 
                        srcTaskItem.BasePermissions & srcTaskItem.NextPermissions;
                    destTaskItem.CurrentPermissions |= 16; // Slam!
                }
            }

            destTaskItem.Description = srcTaskItem.Description;
            destTaskItem.Name = srcTaskItem.Name;
            destTaskItem.InvType = srcTaskItem.InvType;
            destTaskItem.Type = srcTaskItem.Type;

            destPart.Inventory.AddInventoryItemExclusive(destTaskItem, false);

            if (running > 0)
                destPart.Inventory.CreateScriptInstance(destTaskItem, startParam, false, StateSource.NewRez);

            IScenePresence avatar;
            if (m_scene.TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
                destPart.GetProperties(avatar.ControllingClient);
        }
 /// <summary>
 ///     Add an item to this prim's inventory.  If an item with the same name already exists, then an alternative
 ///     name is chosen.
 /// </summary>
 /// <param name="item"></param>
 /// <param name="allowedDrop"></param>
 public void AddInventoryItem(TaskInventoryItem item, bool allowedDrop)
 {
     AddInventoryItem(item.Name, item, allowedDrop);
 }
        /// <summary>
        ///     Add an item to this prim's inventory.  If an item with the same name already exists, it is replaced.
        /// </summary>
        /// <param name="item"></param>
        /// <param name="allowedDrop"></param>
        public void AddInventoryItemExclusive(TaskInventoryItem item, bool allowedDrop)
        {
            List<TaskInventoryItem> il = GetInventoryItems();

            foreach (TaskInventoryItem i in il)
            {
                if (i.Name == item.Name)
                {
                    if (i.InvType == (int) InventoryType.LSL)
                        RemoveScriptInstance(i.ItemID, false);

                    RemoveInventoryItem(i.ItemID);
                    break;
                }
            }

            AddInventoryItem(item.Name, item, allowedDrop);
        }
 private void ResumeScript(TaskInventoryItem item)
 {
     IScriptModule[] engines = m_part.ParentGroup.Scene.RequestModuleInterfaces<IScriptModule>();
     if (engines == null)
         return;
     foreach (IScriptModule engine in engines)
     {
         if (engine != null)
         {
             engine.ResumeScript(item.ItemID);
             if (item.OwnerChanged)
                 engine.PostScriptEvent(item.ItemID, m_part.UUID, "changed", new Object[] {(int) Changed.OWNER});
             item.OwnerChanged = false;
         }
     }
 }
        /// <summary>
        ///     Add an item to this prim's inventory.
        /// </summary>
        /// <param name="name">The name that the new item should have.</param>
        /// <param name="item">
        ///     The item itself.  The name within this structure is ignored in favour of the name
        ///     given in this method's arguments
        /// </param>
        /// <param name="allowedDrop">
        ///     Item was only added to inventory because AllowedDrop is set
        /// </param>
        protected void AddInventoryItem(string name, TaskInventoryItem item, bool allowedDrop)
        {
            name = FindAvailableInventoryName(name);
            if (name == String.Empty)
                return;

            item.ParentID = m_part.UUID;
            item.ParentPartID = m_part.UUID;
            item.Name = name;
            item.GroupID = m_part.GroupID;

            lock (m_itemsLock)
            {
                m_items.Add(item.ItemID, item);
            }

            m_part.TriggerScriptChangedEvent(allowedDrop ? Changed.ALLOWED_DROP : Changed.INVENTORY);

            m_inventorySerial++;
            //m_inventorySerial += 2;
            HasInventoryChanged = true;
        }
示例#13
0
        /// <summary>
        ///     Start multiple scripts in the object
        /// </summary>
        /// <param name="part"></param>
        /// <param name="items"></param>
        /// <param name="startParam"></param>
        /// <param name="postOnRez"></param>
        /// <param name="stateSource"></param>
        /// <param name="rezzedFrom"></param>
        /// <param name="clearStateSaves"></param>
        public void rez_scripts(ISceneChildEntity part, TaskInventoryItem[] items,
                                int startParam, bool postOnRez, StateSource stateSource, UUID rezzedFrom,
                                bool clearStateSaves)
        {
            List<LUStruct> ItemsToStart =
                items.Select(
                    item =>
                    m_scriptEngine.StartScript(part, item.ItemID, startParam, postOnRez, stateSource, rezzedFrom,
                                               clearStateSaves))
                     .Where(itemToQueue => itemToQueue.Action != LUType.Unknown)
                     .ToList();

			if (ItemsToStart.Count != 0)
                m_scriptEngine.MaintenanceThread.AddScriptChange(ItemsToStart.ToArray(), LoadPriority.FirstStart);
        }
        /// <summary>
        ///     Update an item in a prim (task) inventory.
        ///     This method does not handle scripts, <see>RezScript(IClientAPI, UUID, unit)</see>
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="itemInfo"></param>
        /// <param name="primLocalID"></param>
        protected void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
                                           uint primLocalID)
        {
            UUID itemID = itemInfo.ItemID;

            // Find the prim we're dealing with
            ISceneChildEntity part = m_scene.GetSceneObjectPart(primLocalID);

            if (part != null)
            {
                TaskInventoryItem currentItem = part.Inventory.GetInventoryItem(itemID);
                bool allowInventoryDrop = (part.GetEffectiveObjectFlags()
                                           & (uint) PrimFlags.AllowInventoryDrop) != 0;

                // Explicity allow anyone to add to the inventory if the
                // AllowInventoryDrop flag has been set. Don't however let
                // them update an item unless they pass the external checks
                //
                if (!m_scene.Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
                    && (currentItem != null || !allowInventoryDrop))
                    return;

                if (currentItem == null)
                {
                    UUID copyID = UUID.Random();
                    if (itemID != UUID.Zero)
                    {
                        InventoryItemBase item = m_scene.InventoryService.GetItem(remoteClient.AgentId, itemID);

                        // If we've found the item in the user's inventory or in the library
                        if (item != null)
                        {
                            part.ParentEntity.AddInventoryItem(remoteClient, primLocalID, item, copyID);
                            MainConsole.Instance.InfoFormat(
                                "[Prim inventory]: Update with item {0} requested of prim {1} for {2}",
                                item.Name, primLocalID, remoteClient.Name);
                            part.GetProperties(remoteClient);
                            if (!m_scene.Permissions.BypassPermissions())
                            {
                                if ((item.CurrentPermissions & (uint) PermissionMask.Copy) == 0)
                                {
                                    List<UUID> uuids = new List<UUID> {itemID};
                                    RemoveInventoryItem(remoteClient, uuids);
                                }
                            }
                        }
                        else
                        {
                            MainConsole.Instance.ErrorFormat(
                                "[Prim inventory]: Could not find inventory item {0} to update for {1}!",
                                itemID, remoteClient.Name);
                        }
                    }
                }
                else // Updating existing item with new perms etc
                {
                    // Base ALWAYS has move
                    currentItem.BasePermissions |= (uint) PermissionMask.Move;

                    // Check if we're allowed to mess with permissions
                    if (!m_scene.Permissions.IsGod(remoteClient.AgentId)) // Not a god
                    {
                        if (remoteClient.AgentId != part.OwnerID) // Not owner
                        {
                            // Friends and group members can't change any perms
                            itemInfo.BasePermissions = currentItem.BasePermissions;
                            itemInfo.EveryonePermissions = currentItem.EveryonePermissions;
                            itemInfo.GroupPermissions = currentItem.GroupPermissions;
                            itemInfo.NextPermissions = currentItem.NextPermissions;
                            itemInfo.CurrentPermissions = currentItem.CurrentPermissions;
                        }
                        else
                        {
                            // Owner can't change base, and can change other
                            // only up to base
                            itemInfo.BasePermissions = currentItem.BasePermissions;
                            itemInfo.EveryonePermissions &= currentItem.BasePermissions;
                            itemInfo.GroupPermissions &= currentItem.BasePermissions;
                            itemInfo.CurrentPermissions &= currentItem.BasePermissions;
                            itemInfo.NextPermissions &= currentItem.BasePermissions;
                        }
                    }

                    // Next ALWAYS has move
                    itemInfo.NextPermissions |= (uint) PermissionMask.Move;

                    if (part.Inventory.UpdateInventoryItem(itemInfo))
                    {
                        part.GetProperties(remoteClient);
                    }
                }
            }
            else
            {
                MainConsole.Instance.WarnFormat(
                    "[Prim inventory]: Update with item {0} requested of prim {1} for {2} but this prim does not exist",
                    itemID, primLocalID, remoteClient.Name);
            }
        }
        public ISceneEntity GetRezReadySceneObject(TaskInventoryItem item)
        {
            byte[] rezAsset = m_part.ParentGroup.Scene.AssetService.GetData(item.AssetID.ToString());

            if (null == rezAsset)
            {
                MainConsole.Instance.WarnFormat(
                    "[PRIM INVENTORY]: Could not find asset {0} for inventory item {1} in {2}",
                    item.AssetID, item.Name, m_part.Name);
                return null;
            }

            string xmlData = Utils.BytesToString(rezAsset);
            ISceneEntity group = SceneEntitySerializer.SceneObjectSerializer.FromOriginalXmlFormat(xmlData,
                                                                                                   m_part.ParentGroup
                                                                                                         .Scene);
            if (group == null)
                return null;

            group.IsDeleted = false;
            foreach (ISceneChildEntity part in group.ChildrenEntities())
            {
                part.IsLoading = false;
            }
            //Reset IDs, etc
            m_part.ParentGroup.Scene.SceneGraph.PrepPrimForAdditionToScene(group);

            ISceneChildEntity rootPart = group.GetChildPart(group.UUID);

            // Since renaming the item in the inventory does not affect the name stored
            // in the serialization, transfer the correct name from the inventory to the
            // object itself before we rez.
            rootPart.Name = item.Name;
            rootPart.Description = item.Description;

            List<ISceneChildEntity> partList = group.ChildrenEntities();

            group.SetGroup(m_part.GroupID, group.OwnerID, false);

            if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
            {
                if (m_part.ParentGroup.Scene.Permissions.PropagatePermissions())
                {
                    foreach (ISceneChildEntity part in partList)
                    {
                        part.EveryoneMask = item.EveryonePermissions;
                        part.NextOwnerMask = item.NextPermissions;
                    }

                    group.ApplyNextOwnerPermissions();
                }
            }

            foreach (ISceneChildEntity part in partList)
            {
                if ((part.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
                {
                    part.LastOwnerID = part.OwnerID;
                    part.OwnerID = item.OwnerID;
                    part.Inventory.ChangeInventoryOwner(item.OwnerID);
                }

                part.EveryoneMask = item.EveryonePermissions;
                part.NextOwnerMask = item.NextPermissions;
            }

            rootPart.TrimPermissions();

            return group;
        }
        /// <summary>
        ///     Rez a script into a prim's inventory, either ex nihilo or from an existing avatar inventory
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="transactionID"></param>
        /// <param name="localID"></param>
        /// <param name="itemBase"></param>
        protected void RezScript(IClientAPI remoteClient, InventoryItemBase itemBase, UUID transactionID, uint localID)
        {
            UUID itemID = itemBase.ID;
            UUID copyID = UUID.Random();

            if (itemID != UUID.Zero) // transferred from an avatar inventory to the prim's inventory
            {
                //Might be a library item, use UUID.Zero
                InventoryItemBase item = m_scene.InventoryService.GetItem(UUID.Zero, itemID);

                if (item != null)
                {
                    ISceneChildEntity part = m_scene.GetSceneObjectPart(localID);
                    if (part != null)
                    {
                        if (!m_scene.Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
                            return;

                        part.ParentEntity.AddInventoryItem(remoteClient, localID, item, copyID);
                        part.Inventory.CreateScriptInstance(copyID, 0, false, 0);

                        //                        MainConsole.Instance.InfoFormat("[PRIMINVENTORY]: " +
                        //                                         "Rezzed script {0} into prim local ID {1} for user {2}",
                        //                                         item.inventoryName, localID, remoteClient.Name);
                        part.GetProperties(remoteClient);
                    }
                    else
                    {
                        MainConsole.Instance.ErrorFormat(
                            "[Prim inventory]: Could not rez script {0} into prim local ID {1} for user {2}"
                            + " because the prim could not be found in the region!",
                            item.Name, localID, remoteClient.Name);
                    }
                }
                else
                {
                    MainConsole.Instance.ErrorFormat(
                        "[Prim inventory]: Could not find script inventory item {0} to rez for {1}!",
                        itemID, remoteClient.Name);
                }
            }
            else // script has been rezzed directly into a prim's inventory
            {
                ISceneChildEntity part = m_scene.GetSceneObjectPart(itemBase.Folder);
                if (part == null)
                    return;

                if (!m_scene.Permissions.CanCreateObjectInventory(
                    itemBase.InvType, part.UUID, remoteClient.AgentId))
                    return;

                AssetBase asset = new AssetBase(UUID.Random(), itemBase.Name, (AssetType) itemBase.AssetType,
                                                remoteClient.AgentId)
                                      {
                                          Description = itemBase.Description,
                                          Data = Encoding.ASCII.GetBytes(DefaultLSLScript)
                                      };
                asset.ID = m_scene.AssetService.Store(asset);

                TaskInventoryItem taskItem = new TaskInventoryItem();

                taskItem.ResetIDs(itemBase.Folder);
                taskItem.ParentID = itemBase.Folder;
                taskItem.CreationDate = (uint) itemBase.CreationDate;
                taskItem.Name = itemBase.Name;
                taskItem.Description = itemBase.Description;
                taskItem.Type = itemBase.AssetType;
                taskItem.InvType = itemBase.InvType;
                taskItem.OwnerID = itemBase.Owner;
                taskItem.CreatorID = itemBase.CreatorIdAsUuid;
                taskItem.CreatorData = itemBase.CreatorData;
                taskItem.BasePermissions = itemBase.BasePermissions;
                taskItem.CurrentPermissions = itemBase.CurrentPermissions;
                taskItem.EveryonePermissions = itemBase.EveryOnePermissions;
                taskItem.GroupPermissions = itemBase.GroupPermissions;
                taskItem.NextPermissions = itemBase.NextPermissions;
                taskItem.GroupID = itemBase.GroupID;
                taskItem.GroupPermissions = 0;
                taskItem.Flags = itemBase.Flags;
                taskItem.PermsGranter = UUID.Zero;
                taskItem.PermsMask = 0;
                taskItem.AssetID = asset.ID;
                taskItem.SalePrice = itemBase.SalePrice;
                taskItem.SaleType = itemBase.SaleType;

                part.Inventory.AddInventoryItem(taskItem, false);
                part.GetProperties(remoteClient);

                part.Inventory.CreateScriptInstance(taskItem, 0, false, StateSource.NewRez);
            }
        }
 /// <summary>
 ///     Update an existing inventory item.
 /// </summary>
 /// <param name="item">
 ///     The updated item.  An item with the same id must already exist
 ///     in this prim's inventory.
 /// </param>
 /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
 public bool UpdateInventoryItem(TaskInventoryItem item)
 {
     return UpdateInventoryItem(item, true);
 }
        /// <summary>
        ///     Copy a task (prim) inventory item to another task (prim)
        /// </summary>
        /// <param name="destId"></param>
        /// <param name="part"></param>
        /// <param name="itemId"></param>
        public void MoveTaskInventoryItemToObject(UUID destId, ISceneChildEntity part, UUID itemId)
        {
            TaskInventoryItem srcTaskItem = part.Inventory.GetInventoryItem(itemId);

            if (srcTaskItem == null)
            {
                MainConsole.Instance.ErrorFormat(
                    "[Prim inventory]: Tried to retrieve item ID {0} from prim {1}, {2} for moving"
                    + " but the item does not exist in this inventory",
                    itemId, part.Name, part.UUID);

                return;
            }

            ISceneChildEntity destPart = m_scene.GetSceneObjectPart(destId);

            if (destPart == null)
            {
                MainConsole.Instance.ErrorFormat("[Prim inventory]: Could not find prim for ID {0}", destId);
                return;
            }

            // Can't transfer this
            //
            if ((part.OwnerID != destPart.OwnerID) &&
                ((srcTaskItem.CurrentPermissions & (uint) PermissionMask.Transfer) == 0))
                return;

            if (part.OwnerID != destPart.OwnerID &&
                (destPart.GetEffectiveObjectFlags() & (uint) PrimFlags.AllowInventoryDrop) == 0)
            {
                // object cannot copy items to an object owned by a different owner
                // unless llAllowInventoryDrop has been called

                return;
            }

            // must have both move and modify permission to put an item in an object
            if ((part.OwnerMask & ((uint) PermissionMask.Move | (uint) PermissionMask.Modify)) == 0)
            {
                return;
            }

            TaskInventoryItem destTaskItem = new TaskInventoryItem
                                                 {
                                                     ItemID = UUID.Random(),
                                                     CreatorID = srcTaskItem.CreatorID,
                                                     CreatorData = srcTaskItem.CreatorData,
                                                     AssetID = srcTaskItem.AssetID,
                                                     GroupID = destPart.GroupID,
                                                     OwnerID = destPart.OwnerID,
                                                     ParentID = destPart.UUID,
                                                     ParentPartID = destPart.UUID,
                                                     BasePermissions = srcTaskItem.BasePermissions,
                                                     EveryonePermissions = srcTaskItem.EveryonePermissions,
                                                     GroupPermissions = srcTaskItem.GroupPermissions,
                                                     CurrentPermissions = srcTaskItem.CurrentPermissions,
                                                     NextPermissions = srcTaskItem.NextPermissions,
                                                     Flags = srcTaskItem.Flags,
                                                     SalePrice = srcTaskItem.SalePrice,
                                                     SaleType = srcTaskItem.SaleType
                                                 };


            if (destPart.OwnerID != part.OwnerID)
            {
                if (m_scene.Permissions.PropagatePermissions())
                {
                    destTaskItem.CurrentPermissions = 
                        srcTaskItem.CurrentPermissions & (srcTaskItem.NextPermissions | (uint) PermissionMask.Move);
                    destTaskItem.GroupPermissions = 
                        srcTaskItem.GroupPermissions & (srcTaskItem.NextPermissions | (uint) PermissionMask.Move);
                    destTaskItem.EveryonePermissions = 
                        srcTaskItem.EveryonePermissions & (srcTaskItem.NextPermissions | (uint) PermissionMask.Move);
                    destTaskItem.BasePermissions = 
                        srcTaskItem.BasePermissions & (srcTaskItem.NextPermissions | (uint) PermissionMask.Move);
                    destTaskItem.CurrentPermissions |= 16; // Slam!
                }
            }

            destTaskItem.Description = srcTaskItem.Description;
            destTaskItem.Name = srcTaskItem.Name;
            destTaskItem.InvType = srcTaskItem.InvType;
            destTaskItem.Type = srcTaskItem.Type;

            destPart.Inventory.AddInventoryItem(destTaskItem, part.OwnerID != destPart.OwnerID);

            if ((srcTaskItem.CurrentPermissions & (uint) PermissionMask.Copy) == 0)
                part.Inventory.RemoveInventoryItem(itemId);

            IScenePresence avatar;

            if (m_scene.TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
                destPart.GetProperties(avatar.ControllingClient);
        }
        public bool UpdateInventoryItem(TaskInventoryItem item, bool fireScriptEvents)
        {
            TaskInventoryItem it = GetInventoryItem(item.ItemID);
            if (it != null)
            {
                item.ParentID = m_part.UUID;
                item.ParentPartID = m_part.UUID;
                item.Flags = m_items[item.ItemID].Flags;

                // If group permissions have been set on, check that the groupID is up to date in case it has
                // changed since permissions were last set.
                if (item.GroupPermissions != (uint) PermissionMask.None)
                    item.GroupID = m_part.GroupID;

                if (item.AssetID == UUID.Zero)
                    item.AssetID = it.AssetID;

                lock (m_itemsLock)
                {
                    m_items[item.ItemID] = item;
                    m_inventorySerial++;
                }

                if (fireScriptEvents)
                    m_part.TriggerScriptChangedEvent(Changed.INVENTORY);

                HasInventoryChanged = true;
                return true;
            }
            MainConsole.Instance.ErrorFormat(
                "[PRIM INVENTORY]: " +
                "Tried to retrieve item ID {0} from prim {1}, {2} at {3} in {4} but the item does not exist in this inventory",
                item.ItemID, m_part.Name, m_part.UUID,
                m_part.AbsolutePosition, m_part.ParentGroup.Scene.RegionInfo.RegionName);
            return false;
        }
        /// <summary>
        ///     Update an existing inventory item.
        /// </summary>
        /// <param name="item">
        ///     The updated item.  An item with the same id must already exist
        ///     in this prim's inventory
        /// </param>
        /// <returns>false if the item did not exist, true if the update occurred successfully</returns>
        public bool UpdateInventoryItem(TaskInventoryItem item)
        {
            SceneObjectPart part = (SceneObjectPart) GetChildPart(item.ParentPartID);
            if (part != null)
            {
                part.Inventory.UpdateInventoryItem(item);

                return true;
            }
            MainConsole.Instance.ErrorFormat(
                "[PRIM INVENTORY]: " +
                "Couldn't find prim ID {0} to update item {1}, {2}",
                item.ParentPartID, item.Name, item.ItemID);

            return false;
        }
示例#21
0
        /// <summary>
        /// Save a notecard to prim inventory.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description">Description of notecard</param>
        /// <param name="notecardData"></param>
        /// <param name="forceSameName">
        /// If true, then if an item exists with the same name, it is replaced.
        /// If false, then a new item is created witha slightly different name (e.g. name 1)
        /// </param>
        /// <returns>Prim inventory item created.</returns>
        protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName)
        {
            // Create new asset
            AssetBase asset = new AssetBase(UUID.Random(), name, AssetType.Notecard, m_host.OwnerID);
            asset.Description = description;

            byte[] a;
            byte[] b;
            byte[] c;

            b = Util.UTF8.GetBytes(data);

            a = Util.UTF8.GetBytes(
                "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " + b.Length + "\n");

            c = Util.UTF8.GetBytes("}");

            byte[] d = new byte[a.Length + b.Length + c.Length];
            Buffer.BlockCopy(a, 0, d, 0, a.Length);
            Buffer.BlockCopy(b, 0, d, a.Length, b.Length);
            Buffer.BlockCopy(c, 0, d, a.Length + b.Length, c.Length);

            asset.Data = d;
            World.AssetService.Store(asset);

            // Create Task Entry
            TaskInventoryItem taskItem = new TaskInventoryItem();

            taskItem.ResetIDs(m_host.UUID);
            taskItem.ParentID = m_host.UUID;
            taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch();
            taskItem.Name = asset.Name;
            taskItem.Description = asset.Description;
            taskItem.Type = (int)AssetType.Notecard;
            taskItem.InvType = (int)InventoryType.Notecard;
            taskItem.OwnerID = m_host.OwnerID;
            taskItem.CreatorID = m_host.OwnerID;
            taskItem.BasePermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
            taskItem.CurrentPermissions = (uint)PermissionMask.All | (uint)PermissionMask.Export;
            taskItem.EveryonePermissions = 0;
            taskItem.NextPermissions = (uint)PermissionMask.All;
            taskItem.GroupID = m_host.GroupID;
            taskItem.GroupPermissions = 0;
            taskItem.Flags = 0;
            taskItem.PermsGranter = UUID.Zero;
            taskItem.PermsMask = 0;
            taskItem.AssetID = asset.ID;

            if (forceSameName)
                m_host.Inventory.AddInventoryItemExclusive(taskItem, false);
            else
                m_host.Inventory.AddInventoryItem(taskItem, false);

            return taskItem;
        }
示例#22
0
 public void TriggerRezScripts(ISceneChildEntity part, TaskInventoryItem[] taskInventoryItem, int startParam,
     bool postOnRez, StateSource stateSource, UUID rezzedFrom, bool clearStateSaves)
 {
     NewRezScripts handlerRezScripts = OnRezScripts;
     if (handlerRezScripts != null)
     {
         foreach (NewRezScripts d in handlerRezScripts.GetInvocationList())
         {
             try
             {
                 d(part, taskInventoryItem, startParam, postOnRez, stateSource, rezzedFrom, clearStateSaves);
             }
             catch (Exception e)
             {
                 MainConsole.Instance.ErrorFormat(
                     "[EVENT MANAGER]: Delegate for TriggerRezScript failed - continuing.  {0} {1}",
                     e, e.StackTrace);
             }
         }
     }
 }
        /// <summary>
        ///     Update a task inventory item with data that has been received through a transaction.
        ///     This is currently called when, for instance, a notecard in a prim is saved.  The data is sent
        ///     up through a single AssetUploadRequest.  A subsequent UpdateTaskInventory then references the transaction
        ///     and comes through this method.
        /// </summary>
        /// <param name="remoteClient"></param>
        /// <param name="part"></param>
        /// <param name="transactionID"></param>
        /// <param name="item"></param>
        public void HandleTaskItemUpdateFromTransaction(
            IClientAPI remoteClient, ISceneChildEntity part, UUID transactionID, TaskInventoryItem item)
        {
            //            MainConsole.Instance.DebugFormat(
            //                "[TRANSACTIONS MANAGER] Called HandleTaskItemUpdateFromTransaction with item {0}",
            //                item.Name);

            AgentAssetTransactions transactions = GetUserTransactions(remoteClient.AgentId);

            IMonitorModule monitorModule = m_scene.RequestModuleInterface<IMonitorModule>();
            if (monitorModule != null)
            {
                INetworkMonitor networkMonitor = monitorModule.GetMonitor<INetworkMonitor>(m_scene);
                networkMonitor.AddPendingUploads(1);
            }

            transactions.RequestUpdateTaskInventoryItem(remoteClient, part, transactionID, item);
        }