From 134f86e8d5c414409631b25b8c6f0ee45fbd8631 Mon Sep 17 00:00:00 2001 From: David Walter Seikel Date: Thu, 3 Nov 2016 21:44:39 +1000 Subject: Initial update to OpenSim 0.8.2.1 source code. --- .../Framework/InventoryAccess/HGAssetMapper.cs | 224 +++++++------ .../InventoryAccess/HGInventoryAccessModule.cs | 198 ++++++++++-- .../InventoryAccess/InventoryAccessModule.cs | 359 ++++++++++++--------- .../InventoryAccess/Tests/HGAssetMapperTests.cs | 146 +++++++++ .../Tests/InventoryAccessModuleTests.cs | 7 +- 5 files changed, 639 insertions(+), 295 deletions(-) create mode 100644 OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs (limited to 'OpenSim/Region/CoreModules/Framework/InventoryAccess') diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs index 7871eda..f54298c 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGAssetMapper.cs @@ -35,6 +35,7 @@ using System.Xml; using log4net; using OpenMetaverse; using OpenSim.Framework; +using OpenSim.Framework.Serialization.External; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; @@ -73,6 +74,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess private AssetMetadata FetchMetadata(string url, UUID assetID) { + if (string.IsNullOrEmpty(url)) + return null; + if (!url.EndsWith("/") && !url.EndsWith("=")) url = url + "/"; @@ -92,6 +96,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); if (asset == null) { + if (string.IsNullOrEmpty(url)) + return null; + if (!url.EndsWith("/") && !url.EndsWith("=")) url = url + "/"; @@ -109,45 +116,47 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess public bool PostAsset(string url, AssetBase asset) { - if (asset != null) - { - if (!url.EndsWith("/") && !url.EndsWith("=")) - url = url + "/"; + if (string.IsNullOrEmpty(url)) + return false; - bool success = true; - // See long comment in AssetCache.AddAsset - if (!asset.Temporary || asset.Local) - { - // We need to copy the asset into a new asset, because - // we need to set its ID to be URL+UUID, so that the - // HGAssetService dispatches it to the remote grid. - // It's not pretty, but the best that can be done while - // not having a global naming infrastructure - AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type, asset.Metadata.CreatorID); - Copy(asset, asset1); - asset1.ID = url + asset.ID; - - AdjustIdentifiers(asset1.Metadata); - if (asset1.Metadata.Type == (sbyte)AssetType.Object) - asset1.Data = AdjustIdentifiers(asset.Data); - else - asset1.Data = asset.Data; + if (!url.EndsWith("/") && !url.EndsWith("=")) + url = url + "/"; - string id = m_scene.AssetService.Store(asset1); - if (id == string.Empty) - { - m_log.DebugFormat("[HG ASSET MAPPER]: Asset server {0} did not accept {1}", url, asset.ID); - success = false; - } - else - m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); - } - return success; + if (asset == null) + { + m_log.Warn("[HG ASSET MAPPER]: Tried to post asset to remote server, but asset not in local cache."); + return false; } + + // See long comment in AssetCache.AddAsset + if (asset.Temporary || asset.Local) + return true; + + // We need to copy the asset into a new asset, because + // we need to set its ID to be URL+UUID, so that the + // HGAssetService dispatches it to the remote grid. + // It's not pretty, but the best that can be done while + // not having a global naming infrastructure + AssetBase asset1 = new AssetBase(asset.FullID, asset.Name, asset.Type, asset.Metadata.CreatorID); + Copy(asset, asset1); + asset1.ID = url + asset.ID; + + AdjustIdentifiers(asset1.Metadata); + if (asset1.Metadata.Type == (sbyte)AssetType.Object) + asset1.Data = AdjustIdentifiers(asset.Data); else - m_log.Warn("[HG ASSET MAPPER]: Tried to post asset to remote server, but asset not in local cache."); + asset1.Data = asset.Data; - return false; + string id = m_scene.AssetService.Store(asset1); + if (String.IsNullOrEmpty(id)) + { + m_log.DebugFormat("[HG ASSET MAPPER]: Asset server {0} did not accept {1}", url, asset.ID); + return false; + } + else { + m_log.DebugFormat("[HG ASSET MAPPER]: Posted copy of asset {0} from local asset server to {1}", asset1.ID, url); + return true; + } } private void Copy(AssetBase from, AssetBase to) @@ -165,7 +174,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess private void AdjustIdentifiers(AssetMetadata meta) { - if (meta.CreatorID != null && meta.CreatorID != string.Empty) + if (!string.IsNullOrEmpty(meta.CreatorID)) { UUID uuid = UUID.Zero; UUID.TryParse(meta.CreatorID, out uuid); @@ -181,49 +190,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return Utils.StringToBytes(RewriteSOP(xml)); } - protected string RewriteSOP(string xml) + protected string RewriteSOP(string xmlData) { - XmlDocument doc = new XmlDocument(); - doc.LoadXml(xml); - XmlNodeList sops = doc.GetElementsByTagName("SceneObjectPart"); - - foreach (XmlNode sop in sops) - { - UserAccount creator = null; - bool hasCreatorData = false; - XmlNodeList nodes = sop.ChildNodes; - foreach (XmlNode node in nodes) - { - if (node.Name == "CreatorID") - { - UUID uuid = UUID.Zero; - UUID.TryParse(node.InnerText, out uuid); - creator = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, uuid); - } - if (node.Name == "CreatorData" && node.InnerText != null && node.InnerText != string.Empty) - hasCreatorData = true; - - //if (node.Name == "OwnerID") - //{ - // UserAccount owner = GetUser(node.InnerText); - // if (owner != null) - // node.InnerText = m_ProfileServiceURL + "/" + node.InnerText + "/" + owner.FirstName + " " + owner.LastName; - //} - } - - if (!hasCreatorData && creator != null) - { - XmlElement creatorData = doc.CreateElement("CreatorData"); - creatorData.InnerText = m_HomeURI + ";" + creator.FirstName + " " + creator.LastName; - sop.AppendChild(creatorData); - } - } - - using (StringWriter wr = new StringWriter()) - { - doc.Save(wr); - return wr.ToString(); - } +// Console.WriteLine("Input XML [{0}]", xmlData); + return ExternalRepresentationUtils.RewriteSOP(xmlData, m_scene.Name, m_HomeURI, m_scene.UserAccountService, m_scene.RegionInfo.ScopeID); } @@ -251,12 +221,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // The act of gathering UUIDs downloads some assets from the remote server // but not all... - Dictionary ids = new Dictionary(); HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, userAssetURL); - uuidGatherer.GatherAssetUuids(assetID, (AssetType)meta.Type, ids); - m_log.DebugFormat("[HG ASSET MAPPER]: Preparing to get {0} assets", ids.Count); + uuidGatherer.AddForInspection(assetID); + uuidGatherer.GatherAll(); + + m_log.DebugFormat("[HG ASSET MAPPER]: Preparing to get {0} assets", uuidGatherer.GatheredUuids.Count); bool success = true; - foreach (UUID uuid in ids.Keys) + foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys) if (FetchAsset(userAssetURL, uuid) == null) success = false; @@ -267,39 +238,92 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_log.DebugFormat("[HG ASSET MAPPER]: Successfully got item {0} from asset server {1}", assetID, userAssetURL); } - public void Post(UUID assetID, UUID ownerID, string userAssetURL) { - // Post the item from the local AssetCache onto the remote asset server - // and place an entry in m_assetMap + m_log.DebugFormat("[HG ASSET MAPPER]: Starting to send asset {0} with children to asset server {1}", assetID, userAssetURL); + + // Find all the embedded assets - m_log.Debug("[HG ASSET MAPPER]: Posting object " + assetID + " to asset server " + userAssetURL); AssetBase asset = m_scene.AssetService.Get(assetID.ToString()); - if (asset != null) + if (asset == null) + { + m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID); + return; + } + + HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty); + uuidGatherer.AddForInspection(asset.FullID); + uuidGatherer.GatherAll(); + + // Check which assets already exist in the destination server + + string url = userAssetURL; + if (!url.EndsWith("/") && !url.EndsWith("=")) + url = url + "/"; + + string[] remoteAssetIDs = new string[uuidGatherer.GatheredUuids.Count]; + int i = 0; + foreach (UUID id in uuidGatherer.GatheredUuids.Keys) + remoteAssetIDs[i++] = url + id.ToString(); + + bool[] exist = m_scene.AssetService.AssetsExist(remoteAssetIDs); + + var existSet = new HashSet(); + i = 0; + foreach (UUID id in uuidGatherer.GatheredUuids.Keys) + { + if (exist[i]) + existSet.Add(id.ToString()); + ++i; + } + + // Send only those assets which don't already exist in the destination server + + bool success = true; + + foreach (UUID uuid in uuidGatherer.GatheredUuids.Keys) { - Dictionary ids = new Dictionary(); - HGUuidGatherer uuidGatherer = new HGUuidGatherer(m_scene.AssetService, string.Empty); - uuidGatherer.GatherAssetUuids(asset.FullID, (AssetType)asset.Type, ids); - bool success = false; - foreach (UUID uuid in ids.Keys) + if (!existSet.Contains(uuid.ToString())) { asset = m_scene.AssetService.Get(uuid.ToString()); if (asset == null) + { m_log.DebugFormat("[HG ASSET MAPPER]: Could not find asset {0}", uuid); + } else - success = PostAsset(userAssetURL, asset); + { + try + { + success &= PostAsset(userAssetURL, asset); + } + catch (Exception e) + { + m_log.Error( + string.Format( + "[HG ASSET MAPPER]: Failed to post asset {0} (type {1}, length {2}) referenced from {3} to {4} with exception ", + asset.ID, asset.Type, asset.Data.Length, assetID, userAssetURL), + e); + + // For debugging purposes for now we will continue to throw the exception up the stack as was already happening. However, after + // debugging we may want to simply report the failure if we can tell this is due to a failure + // with a particular asset and not a destination network failure where all asset posts will fail (and + // generate large amounts of log spam). + throw e; + } + } } - - // maybe all pieces got there... - if (!success) - m_log.DebugFormat("[HG ASSET MAPPER]: Problems posting item {0} to asset server {1}", assetID, userAssetURL); else - m_log.DebugFormat("[HG ASSET MAPPER]: Successfully posted item {0} to asset server {1}", assetID, userAssetURL); - + { + m_log.DebugFormat( + "[HG ASSET MAPPER]: Didn't post asset {0} referenced from {1} because it already exists in asset server {2}", + uuid, assetID, userAssetURL); + } } - else - m_log.DebugFormat("[HG ASSET MAPPER]: Something wrong with asset {0}, it could not be found", assetID); + if (!success) + m_log.DebugFormat("[HG ASSET MAPPER]: Problems sending asset {0} with children to asset server {1}", assetID, userAssetURL); + else + m_log.DebugFormat("[HG ASSET MAPPER]: Successfully sent asset {0} with children to asset server {1}", assetID, userAssetURL); } #endregion diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs index 964efda..582b267 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/HGInventoryAccessModule.cs @@ -62,6 +62,17 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess private string m_ThisGatekeeper; private bool m_RestrictInventoryAccessAbroad; + private bool m_bypassPermissions = true; + + // This simple check makes it possible to support grids in which all the simulators + // share all central services of the Robust server EXCEPT assets. In other words, + // grids where the simulators' assets are kept in one DB and the users' inventory assets + // are kept on another. When users rez items from inventory or take objects from world, + // an HG-like asset copy takes place between the 2 servers, the world asset server and + // the user's asset server. + private bool m_CheckSeparateAssets = false; + private string m_LocalAssetsURL = string.Empty; + // private bool m_Initialized = false; #region INonSharedRegionModule @@ -88,16 +99,26 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess IConfig thisModuleConfig = source.Configs["HGInventoryAccessModule"]; if (thisModuleConfig != null) { - // legacy configuration [obsolete] - m_HomeURI = thisModuleConfig.GetString("ProfileServerURI", string.Empty); - // preferred - m_HomeURI = thisModuleConfig.GetString("HomeURI", m_HomeURI); + m_HomeURI = Util.GetConfigVarFromSections(source, "HomeURI", + new string[] { "Startup", "Hypergrid", "HGInventoryAccessModule" }, String.Empty); + m_ThisGatekeeper = Util.GetConfigVarFromSections(source, "GatekeeperURI", + new string[] { "Startup", "Hypergrid", "HGInventoryAccessModule" }, String.Empty); + // Legacy. Renove soon! + m_ThisGatekeeper = thisModuleConfig.GetString("Gatekeeper", m_ThisGatekeeper); + m_OutboundPermission = thisModuleConfig.GetBoolean("OutboundPermission", true); - m_ThisGatekeeper = thisModuleConfig.GetString("Gatekeeper", string.Empty); m_RestrictInventoryAccessAbroad = thisModuleConfig.GetBoolean("RestrictInventoryAccessAbroad", true); + m_CheckSeparateAssets = thisModuleConfig.GetBoolean("CheckSeparateAssets", false); + m_LocalAssetsURL = thisModuleConfig.GetString("RegionHGAssetServerURI", string.Empty); + m_LocalAssetsURL = m_LocalAssetsURL.Trim(new char[] { '/' }); + } else m_log.Warn("[HG INVENTORY ACCESS MODULE]: HGInventoryAccessModule configs not found. ProfileServerURI not set!"); + + m_bypassPermissions = !Util.GetConfigVarFromSections(source, "serverside_object_permissions", + new string[] { "Startup", "Permissions" }, true); + } } } @@ -109,9 +130,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess base.AddRegion(scene); m_assMapper = new HGAssetMapper(scene, m_HomeURI); - scene.EventManager.OnNewInventoryItemUploadComplete += UploadInventoryItem; + scene.EventManager.OnNewInventoryItemUploadComplete += PostInventoryAsset; scene.EventManager.OnTeleportStart += TeleportStart; scene.EventManager.OnTeleportFail += TeleportFail; + + // We're fgoing to enforce some stricter permissions if Outbound is false + scene.Permissions.OnTakeObject += CanTakeObject; + scene.Permissions.OnTakeCopyObject += CanTakeObject; + scene.Permissions.OnTransferUserInventory += OnTransferUserInventory; } #endregion @@ -133,7 +159,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess if (sp is ScenePresence) { AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId); - if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) + if (aCircuit != null && (aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) { if (m_RestrictInventoryAccessAbroad) { @@ -183,8 +209,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } } - public void UploadInventoryItem(UUID avatarID, UUID assetID, string name, int userlevel) + public void PostInventoryAsset(UUID avatarID, AssetType type, UUID assetID, string name, int userlevel) { + if (type == AssetType.Link) + return; + string userAssetServer = string.Empty; if (IsForeignUser(avatarID, out userAssetServer) && userAssetServer != string.Empty && m_OutboundPermission) { @@ -219,18 +248,32 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data); - UploadInventoryItem(remoteClient.AgentId, newAssetID, "", 0); + PostInventoryAsset(remoteClient.AgentId, AssetType.Unknown, newAssetID, "", 0); return newAssetID; } + /// + /// UpdateInventoryItemAsset + /// + public override bool UpdateInventoryItemAsset(UUID ownerID, InventoryItemBase item, AssetBase asset) + { + if (base.UpdateInventoryItemAsset(ownerID, item, asset)) + { + PostInventoryAsset(ownerID, (AssetType)asset.Type, asset.FullID, asset.Name, 0); + return true; + } + + return false; + } + /// /// Used in DeleteToInventory /// protected override void ExportAsset(UUID agentID, UUID assetID) { if (!assetID.Equals(UUID.Zero)) - UploadInventoryItem(agentID, assetID, "", 0); + PostInventoryAsset(agentID, AssetType.Unknown, assetID, "", 0); else m_log.Debug("[HGScene]: Scene.Inventory did not create asset"); } @@ -242,7 +285,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment) { - m_log.DebugFormat("[HGScene] RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID); + m_log.DebugFormat("[HGScene]: RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID); //if (fromTaskID.Equals(UUID.Zero)) //{ @@ -268,50 +311,98 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess SceneObjectGroup sog = base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection, RezSelected, RemoveItem, fromTaskID, attachment); - if (sog == null) - remoteClient.SendAgentAlertMessage("Unable to rez: problem accessing inventory or locating assets", false); - return sog; } public override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver) { - string userAssetServer = string.Empty; - if (IsForeignUser(sender, out userAssetServer) && userAssetServer != string.Empty) - m_assMapper.Get(item.AssetID, sender, userAssetServer); + string senderAssetServer = string.Empty; + string receiverAssetServer = string.Empty; + bool isForeignSender, isForeignReceiver; + isForeignSender = IsForeignUser(sender, out senderAssetServer); + isForeignReceiver = IsForeignUser(receiver, out receiverAssetServer); + + // They're both local. Nothing to do. + if (!isForeignSender && !isForeignReceiver) + return; + + // At least one of them is foreign. + // If both users have the same asset server, no need to transfer the asset + if (senderAssetServer.Equals(receiverAssetServer)) + { + m_log.DebugFormat("[HGScene]: Asset transfer between foreign users, but they have the same server. No transfer."); + return; + } + + if (isForeignSender && senderAssetServer != string.Empty) + m_assMapper.Get(item.AssetID, sender, senderAssetServer); - if (IsForeignUser(receiver, out userAssetServer) && userAssetServer != string.Empty && m_OutboundPermission) - m_assMapper.Post(item.AssetID, receiver, userAssetServer); + if (isForeignReceiver && receiverAssetServer != string.Empty && m_OutboundPermission) + m_assMapper.Post(item.AssetID, receiver, receiverAssetServer); } public override bool IsForeignUser(UUID userID, out string assetServerURL) { assetServerURL = string.Empty; - if (UserManagementModule != null && !UserManagementModule.IsLocalGridUser(userID)) - { // foreign - ScenePresence sp = null; - if (m_Scene.TryGetScenePresence(userID, out sp)) + if (UserManagementModule != null) + { + if (!m_CheckSeparateAssets) { - AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); - if (aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) - { - assetServerURL = aCircuit.ServiceURLs["AssetServerURI"].ToString(); - assetServerURL = assetServerURL.Trim(new char[] { '/' }); + if (!UserManagementModule.IsLocalGridUser(userID)) + { // foreign + ScenePresence sp = null; + if (m_Scene.TryGetScenePresence(userID, out sp)) + { + AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode); + if (aCircuit != null && aCircuit.ServiceURLs != null && aCircuit.ServiceURLs.ContainsKey("AssetServerURI")) + { + assetServerURL = aCircuit.ServiceURLs["AssetServerURI"].ToString(); + assetServerURL = assetServerURL.Trim(new char[] { '/' }); + } + } + else + { + assetServerURL = UserManagementModule.GetUserServerURL(userID, "AssetServerURI"); + assetServerURL = assetServerURL.Trim(new char[] { '/' }); + } + return true; } } else { - assetServerURL = UserManagementModule.GetUserServerURL(userID, "AssetServerURI"); - assetServerURL = assetServerURL.Trim(new char[] { '/' }); + if (IsLocalInventoryAssetsUser(userID, out assetServerURL)) + { + m_log.DebugFormat("[HGScene]: user {0} has local assets {1}", userID, assetServerURL); + return false; + } + else + { + m_log.DebugFormat("[HGScene]: user {0} has foreign assets {1}", userID, assetServerURL); + return true; + } } - return true; } - return false; } + private bool IsLocalInventoryAssetsUser(UUID uuid, out string assetsURL) + { + assetsURL = UserManagementModule.GetUserServerURL(uuid, "AssetServerURI"); + if (assetsURL == string.Empty) + { + AgentCircuitData agent = m_Scene.AuthenticateHandler.GetAgentCircuitData(uuid); + if (agent != null) + { + assetsURL = agent.ServiceURLs["AssetServerURI"].ToString(); + assetsURL = assetsURL.Trim(new char[] { '/' }); + } + } + return m_LocalAssetsURL.Equals(assetsURL); + } + + protected override InventoryItemBase GetItem(UUID agentID, UUID itemID) { InventoryItemBase item = base.GetItem(agentID, itemID); @@ -346,7 +437,15 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess InventoryFolderBase root = m_Scene.InventoryService.GetRootFolder(client.AgentId); InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID); - inv.SendBulkUpdateInventory(content.Folders.ToArray(), content.Items.ToArray()); + List keep = new List(); + + foreach (InventoryFolderBase f in content.Folders) + { + if (f.Name != "My Suitcase" && f.Name != "Current Outfit") + keep.Add(f); + } + + inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray()); } } } @@ -379,7 +478,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess foreach (InventoryFolderBase f in content.Folders) { - if (f.Name != "My Suitcase") + if (f.Name != "My Suitcase" && f.Name != "Current Outfit") { f.Name = f.Name + " (Unavailable)"; keep.Add(f); @@ -404,5 +503,36 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } #endregion + + #region Permissions + + private bool CanTakeObject(UUID objectID, UUID stealer, Scene scene) + { + if (m_bypassPermissions) return true; + + if (!m_OutboundPermission && !UserManagementModule.IsLocalGridUser(stealer)) + { + SceneObjectGroup sog = null; + if (m_Scene.TryGetSceneObjectGroup(objectID, out sog) && sog.OwnerID == stealer) + return true; + + return false; + } + + return true; + } + + private bool OnTransferUserInventory(UUID itemID, UUID userID, UUID recipientID) + { + if (m_bypassPermissions) return true; + + if (!m_OutboundPermission && !UserManagementModule.IsLocalGridUser(recipientID)) + return false; + + return true; + } + + + #endregion } } \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index 8b7c16e..5a9efb8 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -47,6 +47,7 @@ using OpenMetaverse; using log4net; using Nini.Config; using Mono.Addins; +using PermissionMask = OpenSim.Framework.PermissionMask; namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { @@ -202,7 +203,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_Scene.AssetService.Store(asset); m_Scene.CreateNewInventoryItem( remoteClient, remoteClient.AgentId.ToString(), string.Empty, folderID, - name, description, 0, callbackID, asset, invType, nextOwnerMask, creationDate); + name, description, 0, callbackID, asset.FullID, asset.Type, invType, nextOwnerMask, creationDate); } else { @@ -259,7 +260,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return UUID.Zero; } - remoteClient.SendAgentAlertMessage("Notecard saved", false); + remoteClient.SendAlertMessage("Notecard saved"); } else if ((InventoryType)item.InvType == InventoryType.LSL) { @@ -269,7 +270,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return UUID.Zero; } - remoteClient.SendAgentAlertMessage("Script saved", false); + remoteClient.SendAlertMessage("Script saved"); } AssetBase asset = @@ -291,7 +292,34 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return UUID.Zero; } - + + public virtual bool UpdateInventoryItemAsset(UUID ownerID, InventoryItemBase item, AssetBase asset) + { + if (item != null && item.Owner == ownerID && asset != null) + { +// m_log.DebugFormat( +// "[INVENTORY ACCESS MODULE]: Updating item {0} {1} with new asset {2}", +// item.Name, item.ID, asset.ID); + + item.AssetID = asset.FullID; + item.Description = asset.Description; + item.Name = asset.Name; + item.AssetType = asset.Type; + item.InvType = (int)InventoryType.Object; + + m_Scene.AssetService.Store(asset); + m_Scene.InventoryService.UpdateItem(item); + + return true; + } + else + { + m_log.ErrorFormat("[INVENTORY ACCESS MODULE]: Given invalid item for inventory update: {0}", + (item == null || asset == null? "null item or asset" : "wrong owner")); + return false; + } + } + public virtual List CopyToInventory( DeRezAction action, UUID folderID, List objectGroups, IClientAPI remoteClient, bool asAttachment) @@ -352,23 +380,32 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess bool asAttachment) { CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); - Dictionary originalPositions = new Dictionary(); +// Dictionary originalPositions = new Dictionary(); + + Dictionary group2Keyframe = new Dictionary(); foreach (SceneObjectGroup objectGroup in objlist) { - Vector3 inventoryStoredPosition = new Vector3 - (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize) - ? 250 - : objectGroup.AbsolutePosition.X) - , - (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize) - ? 250 - : objectGroup.AbsolutePosition.Y, - objectGroup.AbsolutePosition.Z); - - originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; + if (objectGroup.RootPart.KeyframeMotion != null) + { + objectGroup.RootPart.KeyframeMotion.Pause(); + group2Keyframe.Add(objectGroup, objectGroup.RootPart.KeyframeMotion); + objectGroup.RootPart.KeyframeMotion = null; + } - objectGroup.AbsolutePosition = inventoryStoredPosition; +// Vector3 inventoryStoredPosition = new Vector3 +// (((objectGroup.AbsolutePosition.X > (int)Constants.RegionSize) +// ? 250 +// : objectGroup.AbsolutePosition.X) +// , +// (objectGroup.AbsolutePosition.Y > (int)Constants.RegionSize) +// ? 250 +// : objectGroup.AbsolutePosition.Y, +// objectGroup.AbsolutePosition.Z); +// +// originalPositions[objectGroup.UUID] = objectGroup.AbsolutePosition; +// +// objectGroup.AbsolutePosition = inventoryStoredPosition; // Make sure all bits but the ones we want are clear // on take. @@ -377,7 +414,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess objectGroup.RootPart.NextOwnerMask &= ((uint)PermissionMask.Copy | (uint)PermissionMask.Transfer | - (uint)PermissionMask.Modify); + (uint)PermissionMask.Modify | + (uint)PermissionMask.Export); objectGroup.RootPart.NextOwnerMask |= (uint)PermissionMask.Move; @@ -395,9 +433,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess else itemXml = SceneObjectSerializer.ToOriginalXmlFormat(objlist[0], !asAttachment); - // Restore the position of each group now that it has been stored to inventory. - foreach (SceneObjectGroup objectGroup in objlist) - objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; +// // Restore the position of each group now that it has been stored to inventory. +// foreach (SceneObjectGroup objectGroup in objlist) +// objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); @@ -407,17 +445,28 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess if (item == null) return null; + + item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); + item.CreatorData = objlist[0].RootPart.CreatorData; - // Can't know creator is the same, so null it in inventory if (objlist.Count > 1) { - item.CreatorId = UUID.Zero.ToString(); item.Flags = (uint)InventoryItemFlags.ObjectHasMultipleItems; + + // If the objects have different creators then don't specify a creator at all + foreach (SceneObjectGroup objectGroup in objlist) + { + if ((objectGroup.RootPart.CreatorID.ToString() != item.CreatorId) + || (objectGroup.RootPart.CreatorData.ToString() != item.CreatorData)) + { + item.CreatorId = UUID.Zero.ToString(); + item.CreatorData = string.Empty; + break; + } + } } else { - item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); - item.CreatorData = objlist[0].RootPart.CreatorData; item.SaleType = objlist[0].RootPart.ObjectSaleType; item.SalePrice = objlist[0].RootPart.SalePrice; } @@ -438,13 +487,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } else { - AddPermissions(item, objlist[0], objlist, remoteClient); - item.CreationDate = Util.UnixTimeSinceEpoch(); item.Description = asset.Description; item.Name = asset.Name; item.AssetType = asset.Type; + AddPermissions(item, objlist[0], objlist, remoteClient); + m_Scene.AddInventoryItem(item); if (remoteClient != null && item.Owner == remoteClient.AgentId) @@ -461,6 +510,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } } + // Restore KeyframeMotion + foreach (SceneObjectGroup objectGroup in group2Keyframe.Keys) + { + objectGroup.RootPart.KeyframeMotion = group2Keyframe[objectGroup]; + objectGroup.RootPart.KeyframeMotion.Start(); + } + // This is a hook to do some per-asset post-processing for subclasses that need that if (remoteClient != null) ExportAsset(remoteClient.AgentId, asset.FullID); @@ -485,49 +541,65 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess InventoryItemBase item, SceneObjectGroup so, List objsForEffectivePermissions, IClientAPI remoteClient) { - uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move) | 7; + uint effectivePerms = (uint)(PermissionMask.Copy | PermissionMask.Transfer | PermissionMask.Modify | PermissionMask.Move | PermissionMask.Export) | 7; + uint allObjectsNextOwnerPerms = 0x7fffffff; + uint allObjectsEveryOnePerms = 0x7fffffff; + uint allObjectsGroupPerms = 0x7fffffff; + foreach (SceneObjectGroup grp in objsForEffectivePermissions) + { effectivePerms &= grp.GetEffectivePermissions(); + allObjectsNextOwnerPerms &= grp.RootPart.NextOwnerMask; + allObjectsEveryOnePerms &= grp.RootPart.EveryoneMask; + allObjectsGroupPerms &= grp.RootPart.GroupMask; + } effectivePerms |= (uint)PermissionMask.Move; + //PermissionsUtil.LogPermissions(item.Name, "Before AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions); + if (remoteClient != null && (remoteClient.AgentId != so.RootPart.OwnerID) && m_Scene.Permissions.PropagatePermissions()) { + // Changing ownership, so apply the "Next Owner" permissions to all of the + // inventory item's permissions. + uint perms = effectivePerms; - uint nextPerms = (perms & 7) << 13; - if ((nextPerms & (uint)PermissionMask.Copy) == 0) - perms &= ~(uint)PermissionMask.Copy; - if ((nextPerms & (uint)PermissionMask.Transfer) == 0) - perms &= ~(uint)PermissionMask.Transfer; - if ((nextPerms & (uint)PermissionMask.Modify) == 0) - perms &= ~(uint)PermissionMask.Modify; - - item.BasePermissions = perms & so.RootPart.NextOwnerMask; + PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref perms); + + item.BasePermissions = perms & allObjectsNextOwnerPerms; item.CurrentPermissions = item.BasePermissions; - item.NextPermissions = perms & so.RootPart.NextOwnerMask; - item.EveryOnePermissions = so.RootPart.EveryoneMask & so.RootPart.NextOwnerMask; - item.GroupPermissions = so.RootPart.GroupMask & so.RootPart.NextOwnerMask; + item.NextPermissions = perms & allObjectsNextOwnerPerms; + item.EveryOnePermissions = allObjectsEveryOnePerms & allObjectsNextOwnerPerms; + item.GroupPermissions = allObjectsGroupPerms & allObjectsNextOwnerPerms; - // Magic number badness. Maybe this deserves an enum. - // bit 4 (16) is the "Slam" bit, it means treat as passed - // and apply next owner perms on rez - item.CurrentPermissions |= 16; // Slam! + // apply next owner perms on rez + item.CurrentPermissions |= SceneObjectGroup.SLAM; } else { + // Not changing ownership. + // In this case we apply the permissions in the object's items ONLY to the inventory + // item's "Next Owner" permissions, but NOT to its "Current", "Base", etc. permissions. + // E.g., if the object contains a No-Transfer item then the item's "Next Owner" + // permissions are also No-Transfer. + PermissionsUtil.ApplyFoldedPermissions(effectivePerms, ref allObjectsNextOwnerPerms); + item.BasePermissions = effectivePerms; item.CurrentPermissions = effectivePerms; - item.NextPermissions = so.RootPart.NextOwnerMask & effectivePerms; - item.EveryOnePermissions = so.RootPart.EveryoneMask & effectivePerms; - item.GroupPermissions = so.RootPart.GroupMask & effectivePerms; + item.NextPermissions = allObjectsNextOwnerPerms & effectivePerms; + item.EveryOnePermissions = allObjectsEveryOnePerms & effectivePerms; + item.GroupPermissions = allObjectsGroupPerms & effectivePerms; item.CurrentPermissions &= ((uint)PermissionMask.Copy | (uint)PermissionMask.Transfer | (uint)PermissionMask.Modify | (uint)PermissionMask.Move | + (uint)PermissionMask.Export | 7); // Preserve folded permissions - } - + } + + //PermissionsUtil.LogPermissions(item.Name, "After AddPermissions", item.BasePermissions, item.CurrentPermissions, item.NextPermissions); + return item; } @@ -542,6 +614,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess protected InventoryItemBase CreateItemForObject( DeRezAction action, IClientAPI remoteClient, SceneObjectGroup so, UUID folderID) { +// m_log.DebugFormat( +// "[BASIC INVENTORY ACCESS MODULE]: Creating item for object {0} {1} for folder {2}, action {3}", +// so.Name, so.UUID, folderID, action); +// // Get the user info of the item destination // UUID userID = UUID.Zero; @@ -619,18 +695,18 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess if (remoteClient == null || so.OwnerID != remoteClient.AgentId) { - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } else { - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Trash); } } else if (action == DeRezAction.Return) { // Dump to lost + found unconditionally // - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } if (folderID == UUID.Zero && folder == null) @@ -639,21 +715,22 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { // Deletes go to trash by default // - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.TrashFolder); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Trash); } else { - if (remoteClient == null || so.OwnerID != remoteClient.AgentId) + if (remoteClient == null || so.RootPart.OwnerID != remoteClient.AgentId) { // Taking copy of another person's item. Take to // Objects folder. - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.Object); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object); + so.FromFolderID = UUID.Zero; } else { // Catch all. Use lost & found // - folder = m_Scene.InventoryService.GetFolderForType(userID, AssetType.LostAndFoundFolder); + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } } } @@ -663,10 +740,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // if (action == DeRezAction.Take || action == DeRezAction.TakeCopy) { - if (so.FromFolderID != UUID.Zero && userID == remoteClient.AgentId) + if (so.FromFolderID != UUID.Zero && so.RootPart.OwnerID == remoteClient.AgentId) { InventoryFolderBase f = new InventoryFolderBase(so.FromFolderID, userID); folder = m_Scene.InventoryService.GetFolder(f); + + if(folder.Type == 14 || folder.Type == 16) + { + // folder.Type = 6; + folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object); + } } } @@ -722,7 +805,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment) { - AssetBase rezAsset = m_Scene.AssetService.Get(assetID.ToString()); + AssetBase rezAsset = m_Scene.AssetService.Get(assetID.ToString()); if (rezAsset == null) { @@ -731,12 +814,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_log.WarnFormat( "[InventoryAccessModule]: Could not find asset {0} for item {1} {2} for {3} in RezObject()", assetID, item.Name, item.ID, remoteClient.Name); + remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: could not find asset {0} for item {1}.", assetID, item.Name), false); } else { m_log.WarnFormat( "[INVENTORY ACCESS MODULE]: Could not find asset {0} for {1} in RezObject()", assetID, remoteClient.Name); + remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: could not find asset {0}.", assetID), false); } return null; @@ -744,67 +829,34 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess SceneObjectGroup group = null; - string xmlData = Utils.BytesToString(rezAsset.Data); - List objlist = new List(); - List veclist = new List(); + List objlist; + List veclist; + Vector3 bbox; + float offsetHeight; byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0); Vector3 pos; - XmlDocument doc = new XmlDocument(); - doc.LoadXml(xmlData); - XmlElement e = (XmlElement)doc.SelectSingleNode("/CoalescedObject"); - if (e == null || attachment) // Single - { - SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(xmlData); - - objlist.Add(g); - veclist.Add(new Vector3(0, 0, 0)); + bool single + = m_Scene.GetObjectsToRez( + rezAsset.Data, attachment, out objlist, out veclist, out bbox, out offsetHeight); - float offsetHeight = 0; + if (single) + { pos = m_Scene.GetNewRezLocation( RayStart, RayEnd, RayTargetID, Quaternion.Identity, - BypassRayCast, bRayEndIsIntersection, true, g.GetAxisAlignedBoundingBox(out offsetHeight), false); + BypassRayCast, bRayEndIsIntersection, true, bbox, false); pos.Z += offsetHeight; } else { - XmlElement coll = (XmlElement)e; - float bx = Convert.ToSingle(coll.GetAttribute("x")); - float by = Convert.ToSingle(coll.GetAttribute("y")); - float bz = Convert.ToSingle(coll.GetAttribute("z")); - Vector3 bbox = new Vector3(bx, by, bz); - pos = m_Scene.GetNewRezLocation(RayStart, RayEnd, RayTargetID, Quaternion.Identity, BypassRayCast, bRayEndIsIntersection, true, bbox, false); - pos -= bbox / 2; - - XmlNodeList groups = e.SelectNodes("SceneObjectGroup"); - foreach (XmlNode n in groups) - { - SceneObjectGroup g = SceneObjectSerializer.FromOriginalXmlFormat(n.OuterXml); - - objlist.Add(g); - XmlElement el = (XmlElement)n; - - string rawX = el.GetAttribute("offsetx"); - string rawY = el.GetAttribute("offsety"); - string rawZ = el.GetAttribute("offsetz"); -// -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Converting coalesced object {0} offset <{1}, {2}, {3}>", -// g.Name, rawX, rawY, rawZ); - - float x = Convert.ToSingle(rawX); - float y = Convert.ToSingle(rawY); - float z = Convert.ToSingle(rawZ); - veclist.Add(new Vector3(x, y, z)); - } } - if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, attachment)) + if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment)) return null; for (int i = 0; i < objlist.Count; i++) @@ -823,11 +875,23 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess m_log.Debug("[INVENTORY ACCESS MODULE]: Object has UUID.Zero! Position 3"); } - foreach (SceneObjectPart part in group.Parts) + // if this was previously an attachment and is now being rezzed, + // save the old attachment info. + if (group.IsAttachment == false && group.RootPart.Shape.State != 0) { - // Make the rezzer the owner, as this is not necessarily set correctly in the serialized asset. - part.LastOwnerID = part.OwnerID; - part.OwnerID = remoteClient.AgentId; + group.RootPart.AttachedPos = group.AbsolutePosition; + group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; + } + + if (item == null) + { + // Change ownership. Normally this is done in DoPreRezWhenFromItem(), but in this case we must do it here. + foreach (SceneObjectPart part in group.Parts) + { + // Make the rezzer the owner, as this is not necessarily set correctly in the serialized asset. + part.LastOwnerID = part.OwnerID; + part.OwnerID = remoteClient.AgentId; + } } if (!attachment) @@ -855,7 +919,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // one full update during the attachment // process causes some clients to fail to display the // attachment properly. - m_Scene.AddNewSceneObject(group, true, false); + m_Scene.AddNewSceneObject(group, !attachment, false); // if attachment we set it's asset id so object updates // can reflect that, if not, we set it's position in world. @@ -902,10 +966,15 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess /// /// /// + /// + /// List of vector position adjustments for a coalesced objects. For ordinary objects + /// this list will contain just Vector3.Zero. The order of adjustments must match the order of objlist + /// /// /// true if we can processed with rezzing, false if we need to abort private bool DoPreRezWhenFromItem( - IClientAPI remoteClient, InventoryItemBase item, List objlist, Vector3 pos, bool isAttachment) + IClientAPI remoteClient, InventoryItemBase item, List objlist, + Vector3 pos, List veclist, bool isAttachment) { UUID fromUserInventoryItemId = UUID.Zero; @@ -928,28 +997,29 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } } - int primcount = 0; - foreach (SceneObjectGroup g in objlist) - primcount += g.PrimCount; - - if (!m_Scene.Permissions.CanRezObject( - primcount, remoteClient.AgentId, pos) - && !isAttachment) + for (int i = 0; i < objlist.Count; i++) { - // The client operates in no fail mode. It will - // have already removed the item from the folder - // if it's no copy. - // Put it back if it's not an attachment - // - if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!isAttachment)) - remoteClient.SendBulkUpdateInventory(item); + SceneObjectGroup g = objlist[i]; - ILandObject land = m_Scene.LandChannel.GetLandObject(pos.X, pos.Y); - remoteClient.SendAlertMessage(string.Format( - "Can't rez object '{0}' at <{1:F3}, {2:F3}, {3:F3}> on parcel '{4}' in region {5}.", - item.Name, pos.X, pos.Y, pos.Z, land != null ? land.LandData.Name : "Unknown", m_Scene.RegionInfo.RegionName)); + if (!m_Scene.Permissions.CanRezObject( + g.PrimCount, remoteClient.AgentId, pos + veclist[i]) + && !isAttachment) + { + // The client operates in no fail mode. It will + // have already removed the item from the folder + // if it's no copy. + // Put it back if it's not an attachment + // + if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!isAttachment)) + remoteClient.SendBulkUpdateInventory(item); - return false; + ILandObject land = m_Scene.LandChannel.GetLandObject(pos.X, pos.Y); + remoteClient.SendAlertMessage(string.Format( + "Can't rez object '{0}' at <{1:F3}, {2:F3}, {3:F3}> on parcel '{4}' in region {5}.", + item.Name, pos.X, pos.Y, pos.Z, land != null ? land.LandData.Name : "Unknown", m_Scene.Name)); + + return false; + } } for (int i = 0; i < objlist.Count; i++) @@ -977,44 +1047,19 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", // rootPart.OwnerID, item.Owner, item.CurrentPermissions); - if ((rootPart.OwnerID != item.Owner) || - (item.CurrentPermissions & 16) != 0) + if ((rootPart.OwnerID != item.Owner) || (item.CurrentPermissions & SceneObjectGroup.SLAM) != 0) { //Need to kill the for sale here rootPart.ObjectSaleType = 0; rootPart.SalePrice = 10; - - if (m_Scene.Permissions.PropagatePermissions()) - { - foreach (SceneObjectPart part in so.Parts) - { - if ((item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) - { - part.EveryoneMask = item.EveryOnePermissions; - part.NextOwnerMask = item.NextPermissions; - } - part.GroupMask = 0; // DO NOT propagate here - } - - so.ApplyNextOwnerPermissions(); - } } - + foreach (SceneObjectPart part in so.Parts) { part.FromUserInventoryItemID = fromUserInventoryItemId; - - if ((part.OwnerID != item.Owner) || - (item.CurrentPermissions & 16) != 0) - { - part.Inventory.ChangeInventoryOwner(item.Owner); - part.GroupMask = 0; // DO NOT propagate here - } - - part.EveryoneMask = item.EveryOnePermissions; - part.NextOwnerMask = item.NextPermissions; + part.ApplyPermissionsOnRez(item, true, m_Scene); } - + rootPart.TrimPermissions(); if (isAttachment) @@ -1150,4 +1195,4 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess #endregion } -} \ No newline at end of file +} diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs new file mode 100644 index 0000000..007ff63 --- /dev/null +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/HGAssetMapperTests.cs @@ -0,0 +1,146 @@ +/* + * 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.Threading; +using System.Xml; +using Nini.Config; +using NUnit.Framework; +using OpenMetaverse; +using OpenSim.Framework; +using OpenSim.Region.CoreModules.Framework.InventoryAccess; +using OpenSim.Region.Framework.Scenes; +using OpenSim.Region.ScriptEngine.XEngine; +using OpenSim.Services.Interfaces; +using OpenSim.Tests.Common; + +namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests +{ + [TestFixture] + public class HGAssetMapperTests : OpenSimTestCase + { + [Test] + public void TestPostAssetRewrite() + { + TestHelpers.InMethod(); +// TestHelpers.EnableLogging(); + + XEngine xengine = new OpenSim.Region.ScriptEngine.XEngine.XEngine(); + xengine.DebugLevel = 1; + + IniConfigSource configSource = new IniConfigSource(); + + IConfig startupConfig = configSource.AddConfig("Startup"); + startupConfig.Set("DefaultScriptEngine", "XEngine"); + + IConfig xEngineConfig = configSource.AddConfig("XEngine"); + xEngineConfig.Set("Enabled", "true"); + xEngineConfig.Set("StartDelay", "0"); + xEngineConfig.Set("AppDomainLoading", "false"); + + string homeUrl = "http://hg.HomeTestPostAssetRewriteGrid.com"; + string foreignUrl = "http://hg.ForeignTestPostAssetRewriteGrid.com"; + int soIdTail = 0x1; + UUID assetId = TestHelpers.ParseTail(0x10); + UUID userId = TestHelpers.ParseTail(0x100); + UUID sceneId = TestHelpers.ParseTail(0x1000); + string userFirstName = "TestPostAsset"; + string userLastName = "Rewrite"; + int soPartsCount = 3; + + Scene scene = new SceneHelpers().SetupScene("TestPostAssetRewriteScene", sceneId, 1000, 1000, configSource); + SceneHelpers.SetupSceneModules(scene, configSource, xengine); + scene.StartScripts(); + + HGAssetMapper hgam = new HGAssetMapper(scene, homeUrl); + UserAccount ua + = UserAccountHelpers.CreateUserWithInventory(scene, userFirstName, userLastName, userId, "password"); + + SceneObjectGroup so = SceneHelpers.AddSceneObject(scene, soPartsCount, ua.PrincipalID, "part", soIdTail); + RezScript( + scene, so.UUID, "default { state_entry() { llSay(0, \"Hello World\"); } }", "item1", ua.PrincipalID); + + AssetBase asset = AssetHelpers.CreateAsset(assetId, so); + asset.CreatorID = foreignUrl; + hgam.PostAsset(foreignUrl, asset); + + // Check transformed asset. + AssetBase ncAssetGet = scene.AssetService.Get(assetId.ToString()); + Assert.AreEqual(foreignUrl, ncAssetGet.CreatorID); + string xmlData = Utils.BytesToString(ncAssetGet.Data); + XmlDocument ncAssetGetXmlDoc = new XmlDocument(); + ncAssetGetXmlDoc.LoadXml(xmlData); + +// Console.WriteLine(ncAssetGetXmlDoc.OuterXml); + + XmlNodeList creatorDataNodes = ncAssetGetXmlDoc.GetElementsByTagName("CreatorData"); + + Assert.AreEqual(soPartsCount, creatorDataNodes.Count); + //Console.WriteLine("creatorDataNodes {0}", creatorDataNodes.Count); + + foreach (XmlNode creatorDataNode in creatorDataNodes) + { + Assert.AreEqual( + string.Format("{0};{1} {2}", homeUrl, ua.FirstName, ua.LastName), creatorDataNode.InnerText); + } + + // Check that saved script nodes have attributes + XmlNodeList savedScriptStateNodes = ncAssetGetXmlDoc.GetElementsByTagName("SavedScriptState"); + + Assert.AreEqual(1, savedScriptStateNodes.Count); + Assert.AreEqual(1, savedScriptStateNodes[0].Attributes.Count); + XmlNode uuidAttribute = savedScriptStateNodes[0].Attributes.GetNamedItem("UUID"); + Assert.NotNull(uuidAttribute); + // XXX: To check the actual UUID attribute we would have to do some work to retreive the UUID of the task + // item created earlier. + } + + private void RezScript(Scene scene, UUID soId, string script, string itemName, UUID userId) + { + InventoryItemBase itemTemplate = new InventoryItemBase(); + // itemTemplate.ID = itemId; + itemTemplate.Name = itemName; + itemTemplate.Folder = soId; + itemTemplate.InvType = (int)InventoryType.LSL; + + // XXX: Ultimately it would be better to be able to directly manipulate the script engine to rez a script + // immediately for tests rather than chunter through it's threaded mechanisms. + AutoResetEvent chatEvent = new AutoResetEvent(false); + + scene.EventManager.OnChatFromWorld += (s, c) => + { +// Console.WriteLine("Got chat [{0}]", c.Message); + chatEvent.Set(); + }; + + scene.RezNewScript(userId, itemTemplate, script); + +// Console.WriteLine("HERE"); + Assert.IsTrue(chatEvent.WaitOne(60000), "Chat event in HGAssetMapperTests.RezScript not received"); + } + } +} \ No newline at end of file diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs index ac25a93..1d91165 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/Tests/InventoryAccessModuleTests.cs @@ -37,14 +37,12 @@ using OpenSim.Data; using OpenSim.Framework; using OpenSim.Framework.Serialization; using OpenSim.Framework.Serialization.External; -using OpenSim.Framework.Communications; using OpenSim.Region.CoreModules.Avatar.Inventory.Archiver; using OpenSim.Region.CoreModules.Framework.InventoryAccess; using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; using OpenSim.Services.Interfaces; using OpenSim.Tests.Common; -using OpenSim.Tests.Common.Mock; namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests { @@ -109,8 +107,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; InventoryFolderBase objsFolder - = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; + = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, m_userId, "Objects")[0]; item1.Folder = objsFolder.ID; + item1.Flags |= (uint)InventoryItemFlags.ObjectHasMultipleItems; m_scene.AddInventoryItem(item1); SceneObjectGroup so @@ -159,7 +158,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess.Tests item1.AssetID = asset1.FullID; item1.ID = item1Id; InventoryFolderBase objsFolder - = InventoryArchiveUtils.FindFolderByPath(m_scene.InventoryService, m_userId, "Objects")[0]; + = InventoryArchiveUtils.FindFoldersByPath(m_scene.InventoryService, m_userId, "Objects")[0]; item1.Folder = objsFolder.ID; m_scene.AddInventoryItem(item1); -- cgit v1.1