1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161 |
- /*
- * Copyright (c) Contributors, http://opensimulator.org/
- * See CONTRIBUTORS.TXT for a full list of copyright holders.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * * Neither the name of the OpenSimulator Project nor the
- * names of its contributors may be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using System;
- using System.Collections.Generic;
- using System.Collections;
- using System.Reflection;
- using System.Text;
- using System.Timers;
- using OpenMetaverse;
- using OpenMetaverse.Packets;
- using log4net;
- using OpenSim.Framework;
- using OpenSim.Region.Framework;
- using OpenSim.Region.Framework.Interfaces;
- using OpenSim.Region.Framework.Scenes.Serialization;
- namespace OpenSim.Region.Framework.Scenes
- {
- public partial class Scene
- {
- private static readonly ILog m_log
- = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
- /// <summary>
- /// Allows asynchronous derezzing of objects from the scene into a client's inventory.
- /// </summary>
- protected AsyncSceneObjectGroupDeleter m_asyncSceneObjectDeleter;
- /// <summary>
- /// Start all the scripts in the scene which should be started.
- /// </summary>
- public void CreateScriptInstances()
- {
- m_log.Info("[PRIM INVENTORY]: Starting scripts in scene");
- foreach (EntityBase group in Entities)
- {
- if (group is SceneObjectGroup)
- {
- ((SceneObjectGroup) group).CreateScriptInstances(0, false, DefaultScriptEngine, 0);
- ((SceneObjectGroup) group).ResumeScripts();
- }
- }
- }
- public void AddUploadedInventoryItem(UUID agentID, InventoryItemBase item)
- {
- IMoneyModule money=RequestModuleInterface<IMoneyModule>();
- if (money != null)
- {
- money.ApplyUploadCharge(agentID, money.UploadCharge, "Asset upload");
- }
- AddInventoryItem(agentID, item);
- }
- public bool AddInventoryItemReturned(UUID AgentId, InventoryItemBase item)
- {
- if (InventoryService.AddItem(item))
- return true;
- else
- {
- m_log.WarnFormat(
- "[AGENT INVENTORY]: Unable to add item {1} to agent {2} inventory", item.Name, AgentId);
- return false;
- }
- }
- public void AddInventoryItem(UUID AgentID, InventoryItemBase item)
- {
- if (InventoryService.AddItem(item))
- {
- int userlevel = 0;
- if (Permissions.IsGod(AgentID))
- {
- userlevel = 1;
- }
- EventManager.TriggerOnNewInventoryItemUploadComplete(AgentID, item.AssetID, item.Name, userlevel);
- }
- else
- {
- m_log.WarnFormat(
- "[AGENT INVENTORY]: Agent {1} could not add item {2} {3}",
- AgentID, item.Name, item.ID);
- return;
- }
- }
- /// <summary>
- /// Add an inventory item to an avatar's inventory.
- /// </summary>
- /// <param name="remoteClient">The remote client controlling the avatar</param>
- /// <param name="item">The item. This structure contains all the item metadata, including the folder
- /// in which the item is to be placed.</param>
- public void AddInventoryItem(IClientAPI remoteClient, InventoryItemBase item)
- {
- AddInventoryItem(remoteClient.AgentId, item);
- remoteClient.SendInventoryItemCreateUpdate(item, 0);
- }
- /// <summary>
- /// <see>CapsUpdatedInventoryItemAsset(IClientAPI, UUID, byte[])</see>
- /// </summary>
- public UUID CapsUpdateInventoryItemAsset(UUID avatarId, UUID itemID, byte[] data)
- {
- ScenePresence avatar;
- if (TryGetScenePresence(avatarId, out avatar))
- {
- IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
- if (invAccess != null)
- return invAccess.CapsUpdateInventoryItemAsset(avatar.ControllingClient, itemID, data);
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: " +
- "Avatar {0} cannot be found to update its inventory item asset",
- avatarId);
- }
- return UUID.Zero;
- }
- /// <summary>
- /// Capability originating call to update the asset of a script in a prim's (task's) inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="primID">The prim which contains the item to update</param>
- /// <param name="isScriptRunning">Indicates whether the script to update is currently running</param>
- /// <param name="data"></param>
- public ArrayList CapsUpdateTaskInventoryScriptAsset(IClientAPI remoteClient, UUID itemId,
- UUID primId, bool isScriptRunning, byte[] data)
- {
- if (!Permissions.CanEditScript(itemId, primId, remoteClient.AgentId))
- {
- remoteClient.SendAgentAlertMessage("Insufficient permissions to edit script", false);
- return new ArrayList();
- }
- // Retrieve group
- SceneObjectPart part = GetSceneObjectPart(primId);
- SceneObjectGroup group = part.ParentGroup;
- if (null == group)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Prim inventory update requested for item ID {0} in prim ID {1} but this prim does not exist",
- itemId, primId);
- return new ArrayList();
- }
- // Retrieve item
- TaskInventoryItem item = group.GetInventoryItem(part.LocalId, itemId);
- if (null == item)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for caps script update "
- + " but the item does not exist in this inventory",
- itemId, part.Name, part.UUID);
- return new ArrayList();
- }
- AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)AssetType.LSLText, data, remoteClient.AgentId);
- AssetService.Store(asset);
- if (isScriptRunning)
- {
- part.Inventory.RemoveScriptInstance(item.ItemID, false);
- }
- // Update item with new asset
- item.AssetID = asset.FullID;
- if (group.UpdateInventoryItem(item))
- remoteClient.SendAgentAlertMessage("Script saved", false);
-
- part.GetProperties(remoteClient);
- // Trigger rerunning of script (use TriggerRezScript event, see RezScript)
- ArrayList errors = new ArrayList();
- if (isScriptRunning)
- {
- // Needs to determine which engine was running it and use that
- //
- part.Inventory.CreateScriptInstance(item.ItemID, 0, false, DefaultScriptEngine, 0);
- errors = part.Inventory.GetScriptErrors(item.ItemID);
- }
- else
- {
- remoteClient.SendAgentAlertMessage("Script saved", false);
- }
- part.ParentGroup.ResumeScripts();
- return errors;
- }
- /// <summary>
- /// <see>CapsUpdateTaskInventoryScriptAsset(IClientAPI, UUID, UUID, bool, byte[])</see>
- /// </summary>
- public ArrayList CapsUpdateTaskInventoryScriptAsset(UUID avatarId, UUID itemId,
- UUID primId, bool isScriptRunning, byte[] data)
- {
- ScenePresence avatar;
- if (TryGetScenePresence(avatarId, out avatar))
- {
- return CapsUpdateTaskInventoryScriptAsset(
- avatar.ControllingClient, itemId, primId, isScriptRunning, data);
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Avatar {0} cannot be found to update its prim item asset",
- avatarId);
- return new ArrayList();
- }
- }
- /// <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)
- {
- // This one will let people set next perms on items in agent
- // inventory. Rut-Roh. Whatever. Make this secure. Yeah.
- //
- // Passing something to another avatar or a an object will already
- InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
- item = InventoryService.GetItem(item);
- if (item != null)
- {
- if (UUID.Zero == transactionID)
- {
- item.Name = itemUpd.Name;
- item.Description = itemUpd.Description;
- item.NextPermissions = itemUpd.NextPermissions & item.BasePermissions;
- item.EveryOnePermissions = itemUpd.EveryOnePermissions & item.BasePermissions;
- item.GroupPermissions = itemUpd.GroupPermissions & item.BasePermissions;
- 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;
- InventoryService.UpdateItem(item);
- }
- else
- {
- IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
- if (agentTransactions != null)
- {
- agentTransactions.HandleItemUpdateFromTransaction(
- remoteClient, transactionID, item);
- }
- }
- }
- else
- {
- m_log.Error(
- "[AGENTINVENTORY]: Item ID " + itemID + " not found for an inventory item update.");
- }
- }
- /// <summary>
- /// Give an inventory item from one user to another
- /// </summary>
- /// <param name="recipientClient"></param>
- /// <param name="senderId">ID of the sender of the item</param>
- /// <param name="itemId"></param>
- public virtual void GiveInventoryItem(IClientAPI recipientClient, UUID senderId, UUID itemId)
- {
- InventoryItemBase itemCopy = GiveInventoryItem(recipientClient.AgentId, senderId, itemId);
- if (itemCopy != null)
- recipientClient.SendBulkUpdateInventory(itemCopy);
- }
- /// <summary>
- /// Give an inventory item from one user to another
- /// </summary>
- /// <param name="recipient"></param>
- /// <param name="senderId">ID of the sender of the item</param>
- /// <param name="itemId"></param>
- /// <returns>The inventory item copy given, null if the give was unsuccessful</returns>
- public virtual InventoryItemBase GiveInventoryItem(UUID recipient, UUID senderId, UUID itemId)
- {
- return GiveInventoryItem(recipient, senderId, itemId, UUID.Zero);
- }
- /// <summary>
- /// Give an inventory item from one user to another
- /// </summary>
- /// <param name="recipient"></param>
- /// <param name="senderId">ID of the sender of the item</param>
- /// <param name="itemId"></param>
- /// <param name="recipientFolderId">
- /// The id of the folder in which the copy item should go. If UUID.Zero then the item is placed in the most
- /// appropriate default folder.
- /// </param>
- /// <returns>
- /// The inventory item copy given, null if the give was unsuccessful
- /// </returns>
- public virtual InventoryItemBase GiveInventoryItem(
- UUID recipient, UUID senderId, UUID itemId, UUID recipientFolderId)
- {
- //Console.WriteLine("Scene.Inventory.cs: GiveInventoryItem");
- InventoryItemBase item = new InventoryItemBase(itemId, senderId);
- item = InventoryService.GetItem(item);
- if ((item != null) && (item.Owner == senderId))
- {
- if (!Permissions.BypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Transfer) == 0)
- return null;
- }
- // Insert a copy of the item into the recipient
- InventoryItemBase itemCopy = new InventoryItemBase();
- itemCopy.Owner = recipient;
- itemCopy.CreatorId = item.CreatorId;
- itemCopy.ID = UUID.Random();
- itemCopy.AssetID = item.AssetID;
- itemCopy.Description = item.Description;
- itemCopy.Name = item.Name;
- itemCopy.AssetType = item.AssetType;
- itemCopy.InvType = item.InvType;
- itemCopy.Folder = recipientFolderId;
- if (Permissions.PropagatePermissions() && recipient != senderId)
- {
- // Trying to do this right this time. This is evil. If
- // you believe in Good, go elsewhere. Vampires and other
- // evil creatores only beyond this point. You have been
- // warned.
- // We're going to mask a lot of things by the next perms
- // Tweak the next perms to be nicer to our data
- //
- // In this mask, all the bits we do NOT want to mess
- // with are set. These are:
- //
- // Transfer
- // Copy
- // Modufy
- uint permsMask = ~ ((uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer |
- (uint)PermissionMask.Modify);
- // Now, reduce the next perms to the mask bits
- // relevant to the operation
- uint nextPerms = permsMask | (item.NextPermissions &
- ((uint)PermissionMask.Copy |
- (uint)PermissionMask.Transfer |
- (uint)PermissionMask.Modify));
- // nextPerms now has all bits set, except for the actual
- // next permission bits.
- // This checks for no mod, no copy, no trans.
- // This indicates an error or messed up item. Do it like
- // SL and assume trans
- if (nextPerms == permsMask)
- nextPerms |= (uint)PermissionMask.Transfer;
- // Inventory owner perms are the logical AND of the
- // folded perms and the root prim perms, however, if
- // the root prim is mod, the inventory perms will be
- // mod. This happens on "take" and is of little concern
- // here, save for preventing escalation
- // This hack ensures that items previously permalocked
- // get unlocked when they're passed or rezzed
- uint basePerms = item.BasePermissions |
- (uint)PermissionMask.Move;
- uint ownerPerms = item.CurrentPermissions;
- // If this is an object, root prim perms may be more
- // permissive than folded perms. Use folded perms as
- // a mask
- if (item.InvType == (int)InventoryType.Object)
- {
- // Create a safe mask for the current perms
- uint foldedPerms = (item.CurrentPermissions & 7) << 13;
- foldedPerms |= permsMask;
- bool isRootMod = (item.CurrentPermissions &
- (uint)PermissionMask.Modify) != 0 ?
- true : false;
- // Mask the owner perms to the folded perms
- ownerPerms &= foldedPerms;
- basePerms &= foldedPerms;
- // If the root was mod, let the mask reflect that
- // We also need to adjust the base here, because
- // we should be able to edit in-inventory perms
- // for the root prim, if it's mod.
- if (isRootMod)
- {
- ownerPerms |= (uint)PermissionMask.Modify;
- basePerms |= (uint)PermissionMask.Modify;
- }
- }
- // These will be applied to the root prim at next rez.
- // The slam bit (bit 3) and folded permission (bits 0-2)
- // are preserved due to the above mangling
- ownerPerms &= nextPerms;
- // Mask the base permissions. This is a conservative
- // approach altering only the three main perms
- basePerms &= nextPerms;
- // Assign to the actual item. Make sure the slam bit is
- // set, if it wasn't set before.
- itemCopy.BasePermissions = basePerms;
- itemCopy.CurrentPermissions = ownerPerms | 16; // Slam
- itemCopy.NextPermissions = item.NextPermissions;
- // This preserves "everyone can move"
- itemCopy.EveryOnePermissions = item.EveryOnePermissions &
- nextPerms;
- // Intentionally killing "share with group" here, as
- // the recipient will not have the group this is
- // set to
- itemCopy.GroupPermissions = 0;
- }
- else
- {
- itemCopy.CurrentPermissions = item.CurrentPermissions;
- itemCopy.NextPermissions = item.NextPermissions;
- itemCopy.EveryOnePermissions = item.EveryOnePermissions & item.NextPermissions;
- itemCopy.GroupPermissions = item.GroupPermissions & item.NextPermissions;
- itemCopy.BasePermissions = item.BasePermissions;
- }
-
- if (itemCopy.Folder == UUID.Zero)
- {
- InventoryFolderBase folder = InventoryService.GetFolderForType(recipient, (AssetType)itemCopy.AssetType);
- if (folder != null)
- {
- itemCopy.Folder = folder.ID;
- }
- else
- {
- InventoryFolderBase root = InventoryService.GetRootFolder(recipient);
- if (root != null)
- itemCopy.Folder = root.ID;
- else
- return null; // No destination
- }
- }
- itemCopy.GroupID = UUID.Zero;
- itemCopy.GroupOwned = false;
- itemCopy.Flags = item.Flags;
- itemCopy.SalePrice = item.SalePrice;
- itemCopy.SaleType = item.SaleType;
- if (InventoryService.AddItem(itemCopy))
- {
- IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
- if (invAccess != null)
- invAccess.TransferInventoryAssets(itemCopy, senderId, recipient);
- }
- if (!Permissions.BypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- {
- List<UUID> items = new List<UUID>();
- items.Add(itemId);
- InventoryService.DeleteItems(senderId, items);
- }
- }
- return itemCopy;
- }
- else
- {
- m_log.WarnFormat("[AGENT INVENTORY]: Failed to find item {0} or item does not belong to giver ", itemId);
- return null;
- }
- }
- /// <summary>
- /// Give an entire inventory folder from one user to another. The entire contents (including all descendent
- /// folders) is given.
- /// </summary>
- /// <param name="recipientId"></param>
- /// <param name="senderId">ID of the sender of the item</param>
- /// <param name="folderId"></param>
- /// <param name="recipientParentFolderId">
- /// The id of the receipient folder in which the send folder should be placed. If UUID.Zero then the
- /// recipient folder is the root folder
- /// </param>
- /// <returns>
- /// The inventory folder copy given, null if the copy was unsuccessful
- /// </returns>
- public virtual InventoryFolderBase GiveInventoryFolder(
- UUID recipientId, UUID senderId, UUID folderId, UUID recipientParentFolderId)
- {
- //// Retrieve the folder from the sender
- InventoryFolderBase folder = InventoryService.GetFolder(new InventoryFolderBase(folderId));
- if (null == folder)
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Could not find inventory folder {0} to give", folderId);
- return null;
- }
- if (recipientParentFolderId == UUID.Zero)
- {
- InventoryFolderBase recipientRootFolder = InventoryService.GetRootFolder(recipientId);
- if (recipientRootFolder != null)
- recipientParentFolderId = recipientRootFolder.ID;
- else
- {
- m_log.WarnFormat("[AGENT INVENTORY]: Unable to find root folder for receiving agent");
- return null;
- }
- }
- UUID newFolderId = UUID.Random();
- InventoryFolderBase newFolder
- = new InventoryFolderBase(
- newFolderId, folder.Name, recipientId, folder.Type, recipientParentFolderId, folder.Version);
- InventoryService.AddFolder(newFolder);
- // Give all the subfolders
- InventoryCollection contents = InventoryService.GetFolderContent(senderId, folderId);
- foreach (InventoryFolderBase childFolder in contents.Folders)
- {
- GiveInventoryFolder(recipientId, senderId, childFolder.ID, newFolder.ID);
- }
- // Give all the items
- foreach (InventoryItemBase item in contents.Items)
- {
- GiveInventoryItem(recipientId, senderId, item.ID, newFolder.ID);
- }
- return newFolder;
- }
- public void CopyInventoryItem(IClientAPI remoteClient, uint callbackID, UUID oldAgentID, UUID oldItemID,
- UUID newFolderID, string newName)
- {
- m_log.DebugFormat(
- "[AGENT INVENTORY]: CopyInventoryItem received by {0} with oldAgentID {1}, oldItemID {2}, new FolderID {3}, newName {4}",
- remoteClient.AgentId, oldAgentID, oldItemID, newFolderID, newName);
- InventoryItemBase item = null;
- if (LibraryService != null && LibraryService.LibraryRootFolder != null)
- item = LibraryService.LibraryRootFolder.FindItem(oldItemID);
- if (item == null)
- {
- item = new InventoryItemBase(oldItemID, remoteClient.AgentId);
- item = InventoryService.GetItem(item);
- if (item == null)
- {
- m_log.Error("[AGENT INVENTORY]: Failed to find item " + oldItemID.ToString());
- return;
- }
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- return;
- }
- AssetBase asset = AssetService.Get(item.AssetID.ToString());
- if (asset != null)
- {
- if (newName != String.Empty)
- {
- asset.Name = newName;
- }
- else
- {
- newName = item.Name;
- }
- if (remoteClient.AgentId == oldAgentID)
- {
- CreateNewInventoryItem(
- remoteClient, item.CreatorId, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
- item.BasePermissions, item.CurrentPermissions, item.EveryOnePermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
- }
- else
- {
- CreateNewInventoryItem(
- remoteClient, item.CreatorId, newFolderID, newName, item.Flags, callbackID, asset, (sbyte)item.InvType,
- item.NextPermissions, item.NextPermissions, item.EveryOnePermissions & item.NextPermissions, item.NextPermissions, item.GroupPermissions, Util.UnixTimeSinceEpoch());
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[AGENT INVENTORY]: Could not copy item {0} since asset {1} could not be found",
- item.Name, item.AssetID);
- }
- }
- /// <summary>
- /// Create a new asset data structure.
- /// </summary>
- private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, UUID creatorID)
- {
- AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID.ToString());
- asset.Description = description;
- asset.Data = (data == null) ? new byte[1] : data;
- return asset;
- }
- /// <summary>
- /// Move an item within the agent's inventory.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="itemID"></param>
- /// <param name="length"></param>
- /// <param name="newName"></param>
- public void MoveInventoryItem(IClientAPI remoteClient, List<InventoryItemBase> items)
- {
- m_log.DebugFormat(
- "[AGENT INVENTORY]: Moving {0} items for user {1}", items.Count, remoteClient.AgentId);
- if (!InventoryService.MoveItems(remoteClient.AgentId, items))
- m_log.Warn("[AGENT INVENTORY]: Failed to move items for user " + remoteClient.AgentId);
- }
- /// <summary>
- /// Create a new inventory item.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="asset"></param>
- /// <param name="invType"></param>
- /// <param name="nextOwnerMask"></param>
- private void CreateNewInventoryItem(IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID,
- AssetBase asset, sbyte invType, uint nextOwnerMask, int creationDate)
- {
- CreateNewInventoryItem(
- remoteClient, creatorID, folderID, name, flags, callbackID, asset, invType,
- (uint)PermissionMask.All, (uint)PermissionMask.All, 0, nextOwnerMask, 0, creationDate);
- }
- /// <summary>
- /// Create a new Inventory Item
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="asset"></param>
- /// <param name="invType"></param>
- /// <param name="nextOwnerMask"></param>
- /// <param name="creationDate"></param>
- private void CreateNewInventoryItem(
- IClientAPI remoteClient, string creatorID, UUID folderID, string name, uint flags, uint callbackID, AssetBase asset, sbyte invType,
- uint baseMask, uint currentMask, uint everyoneMask, uint nextOwnerMask, uint groupMask, int creationDate)
- {
- InventoryItemBase item = new InventoryItemBase();
- item.Owner = remoteClient.AgentId;
- item.CreatorId = creatorID;
- item.ID = UUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = name;
- item.Flags = flags;
- item.AssetType = asset.Type;
- item.InvType = invType;
- item.Folder = folderID;
- item.CurrentPermissions = currentMask;
- item.NextPermissions = nextOwnerMask;
- item.EveryOnePermissions = everyoneMask;
- item.GroupPermissions = groupMask;
- item.BasePermissions = baseMask;
- item.CreationDate = creationDate;
- if (InventoryService.AddItem(item))
- remoteClient.SendInventoryItemCreateUpdate(item, callbackID);
- else
- {
- m_dialogModule.SendAlertToUser(remoteClient, "Failed to create item");
- m_log.WarnFormat(
- "Failed to add item for {0} in CreateNewInventoryItem!",
- remoteClient.Name);
- }
- }
- /// <summary>
- /// Create a new inventory item. Called when the client creates a new item directly within their
- /// inventory (e.g. by selecting a context inventory menu option).
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="transactionID"></param>
- /// <param name="folderID"></param>
- /// <param name="callbackID"></param>
- /// <param name="description"></param>
- /// <param name="name"></param>
- /// <param name="invType"></param>
- /// <param name="type"></param>
- /// <param name="wearableType"></param>
- /// <param name="nextOwnerMask"></param>
- public void CreateNewInventoryItem(IClientAPI remoteClient, UUID transactionID, UUID folderID,
- uint callbackID, string description, string name, sbyte invType,
- sbyte assetType,
- byte wearableType, uint nextOwnerMask, int creationDate)
- {
- m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item {0} in folder {1}", name, folderID);
- if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
- return;
- if (transactionID == UUID.Zero)
- {
- ScenePresence presence;
- if (TryGetScenePresence(remoteClient.AgentId, out presence))
- {
- byte[] data = null;
- if (invType == (sbyte)InventoryType.Landmark && presence != null)
- {
- Vector3 pos = presence.AbsolutePosition;
- string strdata = String.Format(
- "Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\n",
- presence.Scene.RegionInfo.RegionID,
- pos.X, pos.Y, pos.Z,
- presence.RegionHandle);
- data = Encoding.ASCII.GetBytes(strdata);
- }
- AssetBase asset = CreateAsset(name, description, assetType, data, remoteClient.AgentId);
- AssetService.Store(asset);
- CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, asset.Name, 0, callbackID, asset, invType, nextOwnerMask, creationDate);
- }
- else
- {
- m_log.ErrorFormat(
- "ScenePresence for agent uuid {0} unexpectedly not found in CreateNewInventoryItem",
- remoteClient.AgentId);
- }
- }
- else
- {
- IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
- if (agentTransactions != null)
- {
- agentTransactions.HandleItemCreationFromTransaction(
- remoteClient, transactionID, folderID, callbackID, description,
- name, invType, assetType, wearableType, nextOwnerMask);
- }
- }
- }
- private void HandleLinkInventoryItem(IClientAPI remoteClient, UUID transActionID, UUID folderID,
- uint callbackID, string description, string name,
- sbyte invType, sbyte type, UUID olditemID)
- {
- m_log.DebugFormat("[AGENT INVENTORY]: Received request to create inventory item link {0} in folder {1} pointing to {2}", name, folderID, olditemID);
- if (!Permissions.CanCreateUserInventory(invType, remoteClient.AgentId))
- return;
- ScenePresence presence;
- if (TryGetScenePresence(remoteClient.AgentId, out presence))
- {
- byte[] data = null;
- AssetBase asset = new AssetBase();
- asset.FullID = olditemID;
- asset.Type = type;
- asset.Name = name;
- asset.Description = description;
-
- CreateNewInventoryItem(remoteClient, remoteClient.AgentId.ToString(), folderID, name, 0, callbackID, asset, invType, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, (uint)PermissionMask.All, Util.UnixTimeSinceEpoch());
- }
- else
- {
- m_log.ErrorFormat(
- "ScenePresence for agent uuid {0} unexpectedly not found in HandleLinkInventoryItem",
- remoteClient.AgentId);
- }
- }
- /// <summary>
- /// Remove an inventory item for the client's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- private void RemoveInventoryItem(IClientAPI remoteClient, List<UUID> itemIDs)
- {
- //m_log.Debug("[SCENE INVENTORY]: user " + remoteClient.AgentId);
- InventoryService.DeleteItems(remoteClient.AgentId, itemIDs);
- }
- /// <summary>
- /// Removes an inventory folder. This packet is sent when the user
- /// right-clicks a folder that's already in trash and chooses "purge"
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- private void RemoveInventoryFolder(IClientAPI remoteClient, List<UUID> folderIDs)
- {
- m_log.DebugFormat("[SCENE INVENTORY]: RemoveInventoryFolders count {0}", folderIDs.Count);
- InventoryService.DeleteFolders(remoteClient.AgentId, folderIDs);
- }
- /// <summary>
- /// Send the details of a prim's inventory to the client.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="primLocalID"></param>
- public void RequestTaskInventory(IClientAPI remoteClient, uint primLocalID)
- {
- SceneObjectGroup group = GetGroupByPrim(primLocalID);
- if (group != null)
- {
- bool fileChange = group.GetPartInventoryFileName(remoteClient, primLocalID);
- if (fileChange)
- {
- if (XferManager != null)
- {
- group.RequestInventoryFile(remoteClient, primLocalID, XferManager);
- }
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Inventory requested of prim {0} which doesn't exist", primLocalID);
- }
- }
- /// <summary>
- /// Remove an item from a prim (task) inventory
- /// </summary>
- /// <param name="remoteClient">Unused at the moment but retained since the avatar ID might
- /// be necessary for a permissions check at some stage.</param>
- /// <param name="itemID"></param>
- /// <param name="localID"></param>
- public void RemoveTaskInventory(IClientAPI remoteClient, UUID itemID, uint localID)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- SceneObjectGroup group = part.ParentGroup;
- if (group != null)
- {
- TaskInventoryItem item = group.GetInventoryItem(localID, itemID);
- if (item == null)
- return;
- if (item.Type == 10)
- {
- part.RemoveScriptEvents(itemID);
- EventManager.TriggerRemoveScript(localID, itemID);
- }
-
- group.RemoveInventoryItem(localID, itemID);
- part.GetProperties(remoteClient);
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: " +
- "Removal of item {0} requested of prim {1} but this prim does not exist",
- itemID,
- localID);
- }
- }
- private InventoryItemBase CreateAgentInventoryItemFromTask(UUID destAgent, SceneObjectPart part, UUID itemId)
- {
- Console.WriteLine("CreateAgentInventoryItemFromTask");
- TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
- if (null == taskItem)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for creating an avatar"
- + " inventory item from a prim's inventory item "
- + " but the required item does not exist in the prim's inventory",
- itemId, part.Name, part.UUID);
- return null;
- }
- if ((destAgent != taskItem.OwnerID) && ((taskItem.CurrentPermissions & (uint)PermissionMask.Transfer) == 0))
- {
- return null;
- }
- InventoryItemBase agentItem = new InventoryItemBase();
- agentItem.ID = UUID.Random();
- agentItem.CreatorId = taskItem.CreatorID.ToString();
- agentItem.Owner = destAgent;
- agentItem.AssetID = taskItem.AssetID;
- agentItem.Description = taskItem.Description;
- agentItem.Name = taskItem.Name;
- agentItem.AssetType = taskItem.Type;
- agentItem.InvType = taskItem.InvType;
- agentItem.Flags = taskItem.Flags;
- if ((part.OwnerID != destAgent) && Permissions.PropagatePermissions())
- {
- agentItem.BasePermissions = taskItem.BasePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
- if (taskItem.InvType == (int)InventoryType.Object)
- agentItem.CurrentPermissions = agentItem.BasePermissions & (((taskItem.CurrentPermissions & 7) << 13) | (taskItem.CurrentPermissions & (uint)PermissionMask.Move));
- else
- agentItem.CurrentPermissions = agentItem.BasePermissions & taskItem.CurrentPermissions;
- agentItem.CurrentPermissions |= 16; // Slam
- agentItem.NextPermissions = taskItem.NextPermissions;
- agentItem.EveryOnePermissions = taskItem.EveryonePermissions & (taskItem.NextPermissions | (uint)PermissionMask.Move);
- agentItem.GroupPermissions = taskItem.GroupPermissions & taskItem.NextPermissions;
- }
- else
- {
- agentItem.BasePermissions = taskItem.BasePermissions;
- agentItem.CurrentPermissions = taskItem.CurrentPermissions;
- agentItem.NextPermissions = taskItem.NextPermissions;
- agentItem.EveryOnePermissions = taskItem.EveryonePermissions;
- agentItem.GroupPermissions = taskItem.GroupPermissions;
- }
- if (!Permissions.BypassPermissions())
- {
- if ((taskItem.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- part.Inventory.RemoveInventoryItem(itemId);
- }
- return agentItem;
- }
- /// <summary>
- /// Move the given item in the given prim to a folder in the client's inventory
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="part"></param>
- /// <param name="itemID"></param>
- public InventoryItemBase MoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, SceneObjectPart part, UUID itemId)
- {
- m_log.Info("Adding task inventory");
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(remoteClient.AgentId, part, itemId);
- if (agentItem == null)
- return null;
- agentItem.Folder = folderId;
- AddInventoryItem(remoteClient, agentItem);
- return agentItem;
- }
- /// <summary>
- /// <see>ClientMoveTaskInventoryItem</see>
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="primLocalID"></param>
- /// <param name="itemID"></param>
- public void ClientMoveTaskInventoryItem(IClientAPI remoteClient, UUID folderId, uint primLocalId, UUID itemId)
- {
- SceneObjectPart part = GetSceneObjectPart(primLocalId);
- if (null == part)
- {
- m_log.WarnFormat(
- "[PRIM INVENTORY]: " +
- "Move of inventory item {0} from prim with local id {1} failed because the prim could not be found",
- itemId, primLocalId);
- return;
- }
- TaskInventoryItem taskItem = part.Inventory.GetInventoryItem(itemId);
- if (null == taskItem)
- {
- m_log.WarnFormat("[PRIM INVENTORY]: Move of inventory item {0} from prim with local id {1} failed"
- + " because the inventory item could not be found",
- itemId, primLocalId);
- return;
- }
- // Only owner can copy
- if (remoteClient.AgentId != taskItem.OwnerID)
- return;
- MoveTaskInventoryItem(remoteClient, folderId, part, itemId);
- }
- /// <summary>
- /// <see>MoveTaskInventoryItem</see>
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="folderID"></param>
- /// <param name="part"></param>
- /// <param name="itemID"></param>
- public InventoryItemBase MoveTaskInventoryItem(UUID avatarId, UUID folderId, SceneObjectPart part, UUID itemId)
- {
- ScenePresence avatar;
- if (TryGetScenePresence(avatarId, out avatar))
- {
- return MoveTaskInventoryItem(avatar.ControllingClient, folderId, part, itemId);
- }
- else
- {
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(avatarId, part, itemId);
- if (agentItem == null)
- return null;
- agentItem.Folder = folderId;
- AddInventoryItem(avatarId, agentItem);
- return agentItem;
- }
- }
- /// <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 MoveTaskInventoryItem(UUID destId, SceneObjectPart part, UUID itemId)
- {
- TaskInventoryItem srcTaskItem = part.Inventory.GetInventoryItem(itemId);
- if (srcTaskItem == null)
- {
- m_log.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;
- }
- SceneObjectPart destPart = GetSceneObjectPart(destId);
- if (destPart == null)
- {
- m_log.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 && (part.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();
- destTaskItem.ItemID = UUID.Random();
- destTaskItem.CreatorID = srcTaskItem.CreatorID;
- destTaskItem.AssetID = srcTaskItem.AssetID;
- destTaskItem.GroupID = destPart.GroupID;
- destTaskItem.OwnerID = destPart.OwnerID;
- destTaskItem.ParentID = destPart.UUID;
- destTaskItem.ParentPartID = destPart.UUID;
- destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
- destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
- destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
- destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
- destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
- destTaskItem.Flags = srcTaskItem.Flags;
- if (destPart.OwnerID != part.OwnerID)
- {
- if (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);
- ScenePresence avatar;
- if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
- {
- destPart.GetProperties(avatar.ControllingClient);
- }
- }
- public UUID MoveTaskInventoryItems(UUID destID, string category, SceneObjectPart host, List<UUID> items)
- {
- InventoryFolderBase rootFolder = InventoryService.GetRootFolder(destID);
- UUID newFolderID = UUID.Random();
- InventoryFolderBase newFolder = new InventoryFolderBase(newFolderID, category, destID, -1, rootFolder.ID, rootFolder.Version);
- InventoryService.AddFolder(newFolder);
- foreach (UUID itemID in items)
- {
- InventoryItemBase agentItem = CreateAgentInventoryItemFromTask(destID, host, itemID);
- if (agentItem != null)
- {
- agentItem.Folder = newFolderID;
- AddInventoryItem(destID, agentItem);
- }
- }
- ScenePresence avatar = null;
- if (TryGetScenePresence(destID, out avatar))
- {
- //profile.SendInventoryDecendents(avatar.ControllingClient,
- // profile.RootFolder.ID, true, false);
- //profile.SendInventoryDecendents(avatar.ControllingClient,
- // newFolderID, false, true);
- SendInventoryUpdate(avatar.ControllingClient, rootFolder, true, false);
- SendInventoryUpdate(avatar.ControllingClient, newFolder, false, true);
- }
- return newFolderID;
- }
- private void SendInventoryUpdate(IClientAPI client, InventoryFolderBase folder, bool fetchFolders, bool fetchItems)
- {
- if (folder == null)
- return;
- // TODO: This code for looking in the folder for the library should be folded somewhere else
- // so that this class doesn't have to know the details (and so that multiple libraries, etc.
- // can be handled transparently).
- InventoryFolderImpl fold = null;
- if (LibraryService != null && LibraryService.LibraryRootFolder != null)
- {
- if ((fold = LibraryService.LibraryRootFolder.FindFolder(folder.ID)) != null)
- {
- client.SendInventoryFolderDetails(
- fold.Owner, folder.ID, fold.RequestListOfItems(),
- fold.RequestListOfFolders(), fold.Version, fetchFolders, fetchItems);
- return;
- }
- }
- // Fetch the folder contents
- InventoryCollection contents = InventoryService.GetFolderContent(client.AgentId, folder.ID);
- // Fetch the folder itself to get its current version
- InventoryFolderBase containingFolder = new InventoryFolderBase(folder.ID, client.AgentId);
- containingFolder = InventoryService.GetFolder(containingFolder);
- //m_log.DebugFormat("[AGENT INVENTORY]: Sending inventory folder contents ({0} nodes) for \"{1}\" to {2} {3}",
- // contents.Folders.Count + contents.Items.Count, containingFolder.Name, client.FirstName, client.LastName);
- if (containingFolder != null && containingFolder != null)
- client.SendInventoryFolderDetails(client.AgentId, folder.ID, contents.Items, contents.Folders, containingFolder.Version, fetchFolders, fetchItems);
- }
- /// <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>
- public void UpdateTaskInventory(IClientAPI remoteClient, UUID transactionID, TaskInventoryItem itemInfo,
- uint primLocalID)
- {
- UUID itemID = itemInfo.ItemID;
- // Find the prim we're dealing with
- SceneObjectPart part = 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 (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId)
- && (currentItem != null || !allowInventoryDrop))
- return;
- if (currentItem == null)
- {
- UUID copyID = UUID.Random();
- if (itemID != UUID.Zero)
- {
- InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
- item = InventoryService.GetItem(item);
- // Try library
- if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
- {
- item = LibraryService.LibraryRootFolder.FindItem(itemID);
- }
- // If we've found the item in the user's inventory or in the library
- if (item != null)
- {
- part.ParentGroup.AddInventoryItem(remoteClient, primLocalID, item, copyID);
- m_log.InfoFormat(
- "[PRIM INVENTORY]: Update with item {0} requested of prim {1} for {2}",
- item.Name, primLocalID, remoteClient.Name);
- part.GetProperties(remoteClient);
- if (!Permissions.BypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- {
- List<UUID> uuids = new List<UUID>();
- uuids.Add(itemID);
- RemoveInventoryItem(remoteClient, uuids);
- }
- }
- }
- else
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Could not find inventory item {0} to update for {1}!",
- itemID, remoteClient.Name);
- }
- }
- }
- else // Updating existing item with new perms etc
- {
- IAgentAssetTransactions agentTransactions = this.RequestModuleInterface<IAgentAssetTransactions>();
- if (agentTransactions != null)
- {
- agentTransactions.HandleTaskItemUpdateFromTransaction(
- remoteClient, part, transactionID, currentItem);
- }
- if (part.Inventory.UpdateInventoryItem(itemInfo))
- {
- if ((InventoryType)itemInfo.InvType == InventoryType.Notecard)
- remoteClient.SendAgentAlertMessage("Notecard saved", false);
- else if ((InventoryType)itemInfo.InvType == InventoryType.LSL)
- remoteClient.SendAgentAlertMessage("Script saved", false);
- else
- remoteClient.SendAgentAlertMessage("Item saved", false);
- part.GetProperties(remoteClient);
- }
- }
- }
- else
- {
- m_log.WarnFormat(
- "[PRIM INVENTORY]: " +
- "Update with item {0} requested of prim {1} for {2} but this prim does not exist",
- itemID, primLocalID, remoteClient.Name);
- }
- }
- /// <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="itemID"> </param>
- /// <param name="localID"></param>
- public 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
- {
- InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
- item = InventoryService.GetItem(item);
- // Try library
- // XXX clumsy, possibly should be one call
- if (null == item && LibraryService != null && LibraryService.LibraryRootFolder != null)
- {
- item = LibraryService.LibraryRootFolder.FindItem(itemID);
- }
- if (item != null)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (part != null)
- {
- if (!Permissions.CanEditObjectInventory(part.UUID, remoteClient.AgentId))
- return;
- part.ParentGroup.AddInventoryItem(remoteClient, localID, item, copyID);
- // TODO: switch to posting on_rez here when scripts
- // have state in inventory
- part.Inventory.CreateScriptInstance(copyID, 0, false, DefaultScriptEngine, 0);
- // m_log.InfoFormat("[PRIMINVENTORY]: " +
- // "Rezzed script {0} into prim local ID {1} for user {2}",
- // item.inventoryName, localID, remoteClient.Name);
- part.GetProperties(remoteClient);
- part.ParentGroup.ResumeScripts();
- }
- else
- {
- m_log.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
- {
- m_log.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
- {
- SceneObjectPart part = GetSceneObjectPart(itemBase.Folder);
- if (part == null)
- return;
- if (part.OwnerID != remoteClient.AgentId)
- {
- // Group permissions
- if ((part.GroupID == UUID.Zero) || (remoteClient.GetGroupPowers(part.GroupID) == 0) || ((part.GroupMask & (uint)PermissionMask.Modify) == 0))
- return;
- } else {
- if ((part.OwnerMask & (uint)PermissionMask.Modify) == 0)
- return;
- }
- if (!Permissions.CanCreateObjectInventory(
- itemBase.InvType, part.UUID, remoteClient.AgentId))
- return;
- AssetBase asset = CreateAsset(itemBase.Name, itemBase.Description, (sbyte)itemBase.AssetType,
- Encoding.ASCII.GetBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"),
- remoteClient.AgentId);
- 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.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.FullID;
- part.Inventory.AddInventoryItem(taskItem, false);
- part.GetProperties(remoteClient);
- part.Inventory.CreateScriptInstance(taskItem, 0, false, DefaultScriptEngine, 0);
- part.ParentGroup.ResumeScripts();
- }
- }
- /// <summary>
- /// Rez a script into a prim's inventory from another prim
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"> </param>
- /// <param name="localID"></param>
- public void RezScript(UUID srcId, SceneObjectPart srcPart, UUID destId, int pin, int running, int start_param)
- {
- TaskInventoryItem srcTaskItem = srcPart.Inventory.GetInventoryItem(srcId);
- if (srcTaskItem == null)
- {
- m_log.ErrorFormat(
- "[PRIM INVENTORY]: Tried to retrieve item ID {0} from prim {1}, {2} for rezzing a script but the "
- + " item does not exist in this inventory",
- srcId, srcPart.Name, srcPart.UUID);
- return;
- }
- SceneObjectPart destPart = GetSceneObjectPart(destId);
- if (destPart == null)
- {
- m_log.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 != pin)
- {
- m_log.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();
- destTaskItem.ItemID = UUID.Random();
- destTaskItem.CreatorID = srcTaskItem.CreatorID;
- destTaskItem.AssetID = srcTaskItem.AssetID;
- destTaskItem.GroupID = destPart.GroupID;
- destTaskItem.OwnerID = destPart.OwnerID;
- destTaskItem.ParentID = destPart.UUID;
- destTaskItem.ParentPartID = destPart.UUID;
- destTaskItem.BasePermissions = srcTaskItem.BasePermissions;
- destTaskItem.EveryonePermissions = srcTaskItem.EveryonePermissions;
- destTaskItem.GroupPermissions = srcTaskItem.GroupPermissions;
- destTaskItem.CurrentPermissions = srcTaskItem.CurrentPermissions;
- destTaskItem.NextPermissions = srcTaskItem.NextPermissions;
- destTaskItem.Flags = srcTaskItem.Flags;
- if (destPart.OwnerID != srcPart.OwnerID)
- {
- if (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, start_param, false, DefaultScriptEngine, 0);
- }
- destPart.ParentGroup.ResumeScripts();
- ScenePresence avatar;
- if (TryGetScenePresence(srcTaskItem.OwnerID, out avatar))
- {
- destPart.GetProperties(avatar.ControllingClient);
- }
- }
- /// <summary>
- /// Called when one or more objects are removed from the environment into inventory.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="localID"></param>
- /// <param name="groupID"></param>
- /// <param name="action"></param>
- /// <param name="destinationID"></param>
- public virtual void DeRezObject(IClientAPI remoteClient, List<uint> localIDs,
- UUID groupID, DeRezAction action, UUID destinationID)
- {
- foreach (uint localID in localIDs)
- {
- DeRezObject(remoteClient, localID, groupID, action, destinationID);
- }
- }
- /// <summary>
- /// Called when an object is removed from the environment into inventory.
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="localID"></param>
- /// <param name="groupID"></param>
- /// <param name="action"></param>
- /// <param name="destinationID"></param>
- public virtual void DeRezObject(IClientAPI remoteClient, uint localID,
- UUID groupID, DeRezAction action, UUID destinationID)
- {
- DeRezObjects(remoteClient, new List<uint>() { localID} , groupID, action, destinationID);
- }
- public virtual void DeRezObjects(IClientAPI remoteClient, List<uint> localIDs,
- UUID groupID, DeRezAction action, UUID destinationID)
- {
- // First, see of we can perform the requested action and
- // build a list of eligible objects
- List<uint> deleteIDs = new List<uint>();
- List<SceneObjectGroup> deleteGroups = new List<SceneObjectGroup>();
- // Start with true for both, then remove the flags if objects
- // that we can't derez are part of the selection
- bool permissionToTake = true;
- bool permissionToTakeCopy = true;
- bool permissionToDelete = true;
- foreach (uint localID in localIDs)
- {
- // Invalid id
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (part == null)
- continue;
- // Already deleted by someone else
- if (part.ParentGroup == null || part.ParentGroup.IsDeleted)
- continue;
- // Can't delete child prims
- if (part != part.ParentGroup.RootPart)
- continue;
- SceneObjectGroup grp = part.ParentGroup;
- deleteIDs.Add(localID);
- deleteGroups.Add(grp);
- // Force a database backup/update on this SceneObjectGroup
- // So that we know the database is upto date,
- // for when deleting the object from it
- ForceSceneObjectBackup(grp);
- if (remoteClient == null)
- {
- // Autoreturn has a null client. Nothing else does. So
- // allow only returns
- if (action != DeRezAction.Return)
- return;
- permissionToTakeCopy = false;
- }
- else
- {
- if (!Permissions.CanTakeCopyObject(grp.UUID, remoteClient.AgentId))
- permissionToTakeCopy = false;
- if (!Permissions.CanTakeObject(grp.UUID, remoteClient.AgentId))
- permissionToTake = false;
- if (!Permissions.CanDeleteObject(grp.UUID, remoteClient.AgentId))
- permissionToDelete = false;
- }
- }
- // Handle god perms
- if ((remoteClient != null) && Permissions.IsGod(remoteClient.AgentId))
- {
- permissionToTake = true;
- permissionToTakeCopy = true;
- permissionToDelete = true;
- }
- // If we're re-saving, we don't even want to delete
- if (action == DeRezAction.SaveToExistingUserInventoryItem)
- permissionToDelete = false;
- // if we want to take a copy, we also don't want to delete
- // Note: after this point, the permissionToTakeCopy flag
- // becomes irrelevant. It already includes the permissionToTake
- // permission and after excluding no copy items here, we can
- // just use that.
- if (action == DeRezAction.TakeCopy)
- {
- // If we don't have permission, stop right here
- if (!permissionToTakeCopy)
- return;
- permissionToTake = true;
- // Don't delete
- permissionToDelete = false;
- }
- if (action == DeRezAction.Return)
- {
- if (remoteClient != null)
- {
- if (Permissions.CanReturnObjects(
- null,
- remoteClient.AgentId,
- deleteGroups))
- {
- permissionToTake = true;
- permissionToDelete = true;
- foreach (SceneObjectGroup g in deleteGroups)
- {
- AddReturn(g.OwnerID, g.Name, g.AbsolutePosition, "parcel owner return");
- }
- }
- }
- else // Auto return passes through here with null agent
- {
- permissionToTake = true;
- permissionToDelete = true;
- }
- }
- if (permissionToTake)
- {
- m_asyncSceneObjectDeleter.DeleteToInventory(
- action, destinationID, deleteGroups, remoteClient,
- permissionToDelete);
- }
- else if (permissionToDelete)
- {
- foreach (SceneObjectGroup g in deleteGroups)
- DeleteSceneObject(g, false);
- }
- }
- public void UpdateKnownItem(IClientAPI remoteClient, SceneObjectGroup grp, UUID itemID, UUID agentID)
- {
- SceneObjectGroup objectGroup = grp;
- if (objectGroup != null)
- {
- if (!grp.HasGroupChanged)
- {
- m_log.InfoFormat("[ATTACHMENT]: Save request for {0} which is unchanged", grp.UUID);
- return;
- }
- m_log.InfoFormat(
- "[ATTACHMENT]: Updating asset for attachment {0}, attachpoint {1}",
- grp.UUID, grp.GetAttachmentPoint());
- string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(objectGroup);
- InventoryItemBase item = new InventoryItemBase(itemID, remoteClient.AgentId);
- item = InventoryService.GetItem(item);
- if (item != null)
- {
- AssetBase asset = CreateAsset(
- objectGroup.GetPartName(objectGroup.LocalId),
- objectGroup.GetPartDescription(objectGroup.LocalId),
- (sbyte)AssetType.Object,
- Utils.StringToBytes(sceneObjectXml),
- remoteClient.AgentId);
- AssetService.Store(asset);
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- InventoryService.UpdateItem(item);
- // this gets called when the agent loggs off!
- if (remoteClient != null)
- {
- remoteClient.SendInventoryItemCreateUpdate(item, 0);
- }
- }
- }
- }
- public UUID attachObjectAssetStore(IClientAPI remoteClient, SceneObjectGroup grp, UUID AgentId, out UUID itemID)
- {
- itemID = UUID.Zero;
- if (grp != null)
- {
- Vector3 inventoryStoredPosition = new Vector3
- (((grp.AbsolutePosition.X > (int)Constants.RegionSize)
- ? 250
- : grp.AbsolutePosition.X)
- ,
- (grp.AbsolutePosition.X > (int)Constants.RegionSize)
- ? 250
- : grp.AbsolutePosition.X,
- grp.AbsolutePosition.Z);
- Vector3 originalPosition = grp.AbsolutePosition;
- grp.AbsolutePosition = inventoryStoredPosition;
- string sceneObjectXml = SceneObjectSerializer.ToOriginalXmlFormat(grp);
- grp.AbsolutePosition = originalPosition;
- AssetBase asset = CreateAsset(
- grp.GetPartName(grp.LocalId),
- grp.GetPartDescription(grp.LocalId),
- (sbyte)AssetType.Object,
- Utils.StringToBytes(sceneObjectXml),
- remoteClient.AgentId);
- AssetService.Store(asset);
- InventoryItemBase item = new InventoryItemBase();
- item.CreatorId = grp.RootPart.CreatorID.ToString();
- item.Owner = remoteClient.AgentId;
- item.ID = UUID.Random();
- item.AssetID = asset.FullID;
- item.Description = asset.Description;
- item.Name = asset.Name;
- item.AssetType = asset.Type;
- item.InvType = (int)InventoryType.Object;
- InventoryFolderBase folder = InventoryService.GetFolderForType(remoteClient.AgentId, AssetType.Object);
- if (folder != null)
- item.Folder = folder.ID;
- else // oopsies
- item.Folder = UUID.Zero;
- if ((remoteClient.AgentId != grp.RootPart.OwnerID) && Permissions.PropagatePermissions())
- {
- item.BasePermissions = grp.RootPart.NextOwnerMask;
- item.CurrentPermissions = grp.RootPart.NextOwnerMask;
- item.NextPermissions = grp.RootPart.NextOwnerMask;
- item.EveryOnePermissions = grp.RootPart.EveryoneMask & grp.RootPart.NextOwnerMask;
- item.GroupPermissions = grp.RootPart.GroupMask & grp.RootPart.NextOwnerMask;
- }
- else
- {
- item.BasePermissions = grp.RootPart.BaseMask;
- item.CurrentPermissions = grp.RootPart.OwnerMask;
- item.NextPermissions = grp.RootPart.NextOwnerMask;
- item.EveryOnePermissions = grp.RootPart.EveryoneMask;
- item.GroupPermissions = grp.RootPart.GroupMask;
- }
- item.CreationDate = Util.UnixTimeSinceEpoch();
- // sets itemID so client can show item as 'attached' in inventory
- grp.SetFromItemID(item.ID);
- if (InventoryService.AddItem(item))
- remoteClient.SendInventoryItemCreateUpdate(item, 0);
- else
- m_dialogModule.SendAlertToUser(remoteClient, "Operation failed");
- itemID = item.ID;
- return item.AssetID;
- }
- return UUID.Zero;
- }
- /// <summary>
- /// Event Handler Rez an object into a scene
- /// Calls the non-void event handler
- /// </summary>
- /// <param name="remoteClient"></param>
- /// <param name="itemID"></param>
- /// <param name="RayEnd"></param>
- /// <param name="RayStart"></param>
- /// <param name="RayTargetID"></param>
- /// <param name="BypassRayCast"></param>
- /// <param name="RayEndIsIntersection"></param>
- /// <param name="EveryoneMask"></param>
- /// <param name="GroupMask"></param>
- /// <param name="RezSelected"></param>
- /// <param name="RemoveItem"></param>
- /// <param name="fromTaskID"></param>
- public virtual void RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart,
- UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection,
- bool RezSelected, bool RemoveItem, UUID fromTaskID)
- {
- IInventoryAccessModule invAccess = RequestModuleInterface<IInventoryAccessModule>();
- if (invAccess != null)
- invAccess.RezObject(
- remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
- RezSelected, RemoveItem, fromTaskID, false);
- }
- /// <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>
- /// <returns>The SceneObjectGroup rezzed or null if rez was unsuccessful</returns>
- public virtual SceneObjectGroup RezObject(
- SceneObjectPart sourcePart, TaskInventoryItem item,
- Vector3 pos, Quaternion rot, Vector3 vel, int param)
- {
- // Rez object
- if (item != null)
- {
- UUID ownerID = item.OwnerID;
- AssetBase rezAsset = AssetService.Get(item.AssetID.ToString());
- if (rezAsset != null)
- {
- string xmlData = Utils.BytesToString(rezAsset.Data);
- SceneObjectGroup group = SceneObjectSerializer.FromOriginalXmlFormat(xmlData);
- if (!Permissions.CanRezObject(group.Children.Count, ownerID, pos))
- {
- return null;
- }
- group.ResetIDs();
- AddNewSceneObject(group, true);
- // we set it's position in world.
- group.AbsolutePosition = pos;
- SceneObjectPart 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<SceneObjectPart> partList = new List<SceneObjectPart>(group.Children.Values);
- group.SetGroup(sourcePart.GroupID, null);
- if ((rootPart.OwnerID != item.OwnerID) || (item.CurrentPermissions & 16) != 0)
- {
- if (Permissions.PropagatePermissions())
- {
- foreach (SceneObjectPart part in partList)
- {
- part.EveryoneMask = item.EveryonePermissions;
- part.NextOwnerMask = item.NextPermissions;
- }
- group.ApplyNextOwnerPermissions();
- }
- }
- foreach (SceneObjectPart 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();
-
- if (group.RootPart.Shape.PCode == (byte)PCode.Prim)
- {
- group.ClearPartAttachmentData();
- }
-
- group.UpdateGroupRotationR(rot);
-
- //group.ApplyPhysics(m_physicalPrim);
- if (group.RootPart.PhysActor != null && group.RootPart.PhysActor.IsPhysical && vel != Vector3.Zero)
- {
- group.RootPart.ApplyImpulse((vel * group.GetMass()), false);
- group.Velocity = vel;
- rootPart.ScheduleFullUpdate();
- }
- group.CreateScriptInstances(param, true, DefaultScriptEngine, 2);
- rootPart.ScheduleFullUpdate();
- if (!Permissions.BypassPermissions())
- {
- if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0)
- sourcePart.Inventory.RemoveInventoryItem(item.ItemID);
- }
- return rootPart.ParentGroup;
- }
- }
- return null;
- }
- public virtual bool returnObjects(SceneObjectGroup[] returnobjects, UUID AgentId)
- {
- foreach (SceneObjectGroup grp in returnobjects)
- {
- AddReturn(grp.OwnerID, grp.Name, grp.AbsolutePosition, "parcel owner return");
- DeRezObject(null, grp.RootPart.LocalId,
- grp.RootPart.GroupID, DeRezAction.Return, UUID.Zero);
- }
- return true;
- }
- public void SetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID, bool running)
- {
- SceneObjectPart part = GetSceneObjectPart(objectID);
- if (part == null)
- return;
- if (running)
- EventManager.TriggerStartScript(part.LocalId, itemID);
- else
- EventManager.TriggerStopScript(part.LocalId, itemID);
- }
- public void GetScriptRunning(IClientAPI controllingClient, UUID objectID, UUID itemID)
- {
- EventManager.TriggerGetScriptRunning(controllingClient, objectID, itemID);
- }
- void ObjectOwner(IClientAPI remoteClient, UUID ownerID, UUID groupID, List<uint> localIDs)
- {
- if (!Permissions.IsGod(remoteClient.AgentId))
- {
- if (ownerID != UUID.Zero)
- return;
-
- if (!Permissions.CanDeedObject(remoteClient.AgentId, groupID))
- return;
- }
- List<SceneObjectGroup> groups = new List<SceneObjectGroup>();
- foreach (uint localID in localIDs)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (!groups.Contains(part.ParentGroup))
- groups.Add(part.ParentGroup);
- }
- foreach (SceneObjectGroup sog in groups)
- {
- if (ownerID != UUID.Zero)
- {
- sog.SetOwnerId(ownerID);
- sog.SetGroup(groupID, remoteClient);
- sog.ScheduleGroupForFullUpdate();
- foreach (SceneObjectPart child in sog.Children.Values)
- child.Inventory.ChangeInventoryOwner(ownerID);
- }
- else
- {
- if (!Permissions.CanEditObject(sog.UUID, remoteClient.AgentId))
- continue;
- if (sog.GroupID != groupID)
- continue;
- foreach (SceneObjectPart child in sog.Children.Values)
- {
- child.LastOwnerID = child.OwnerID;
- child.Inventory.ChangeInventoryOwner(groupID);
- }
- sog.SetOwnerId(groupID);
- sog.ApplyNextOwnerPermissions();
- }
-
- }
- foreach (uint localID in localIDs)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- part.GetProperties(remoteClient);
- }
- }
- public void DelinkObjects(List<uint> primIds, IClientAPI client)
- {
- List<SceneObjectPart> parts = new List<SceneObjectPart>();
- foreach (uint localID in primIds)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (part == null)
- continue;
- if (Permissions.CanDelinkObject(client.AgentId, part.ParentGroup.RootPart.UUID))
- parts.Add(part);
- }
- m_sceneGraph.DelinkObjects(parts);
- }
- public void LinkObjects(IClientAPI client, uint parentPrimId, List<uint> childPrimIds)
- {
- List<UUID> owners = new List<UUID>();
- List<SceneObjectPart> children = new List<SceneObjectPart>();
- SceneObjectPart root = GetSceneObjectPart(parentPrimId);
- if (root == null)
- {
- m_log.DebugFormat("[LINK]: Can't find linkset root prim {0{", parentPrimId);
- return;
- }
- if (!Permissions.CanLinkObject(client.AgentId, root.ParentGroup.RootPart.UUID))
- {
- m_log.DebugFormat("[LINK]: Refusing link. No permissions on root prim");
- return;
- }
- foreach (uint localID in childPrimIds)
- {
- SceneObjectPart part = GetSceneObjectPart(localID);
- if (part == null)
- continue;
- if (!owners.Contains(part.OwnerID))
- owners.Add(part.OwnerID);
- if (Permissions.CanLinkObject(client.AgentId, part.ParentGroup.RootPart.UUID))
- children.Add(part);
- }
- // Must be all one owner
- //
- if (owners.Count > 1)
- {
- m_log.DebugFormat("[LINK]: Refusing link. Too many owners");
- return;
- }
- if (children.Count == 0)
- {
- m_log.DebugFormat("[LINK]: Refusing link. No permissions to link any of the children");
- return;
- }
- m_sceneGraph.LinkObjects(root, children);
- }
- }
- }
|