diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index c21ce5961c..bc0bf3c30f 100755 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -168,9 +168,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private void HandleDebugAttachmentsLog(string module, string[] args) { - int debugLevel; - - if (!(args.Length == 4 && int.TryParse(args[3], out debugLevel))) + if (!(args.Length == 4 && int.TryParse(args[3], out int debugLevel))) { MainConsole.Instance.Output("Usage: debug attachments log [0|1]"); } @@ -372,7 +370,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments int i = 0; for (int indx = 0; indx < ad.AttachmentObjects.Count; ++indx) { - if(ad.AttachmentObjects[indx] is SceneObjectGroup sog) + if(ad.AttachmentObjects[indx] is SceneObjectGroup sog && sog.OwnerID.Equals(sp.UUID)) { sog.LocalId = 0; sog.RootPart.ClearUpdateSchedule(); @@ -449,42 +447,84 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments List attachments = sp.Appearance.GetAttachments(); - // Let's get all items at once, so they get cached - UUID[] items = new UUID[attachments.Count]; - for (int i = 0; i < attachments.Count; ++i) - items[i] = attachments[i].ItemID; - - m_scene.InventoryService.GetMultipleItems(sp.UUID, items); - - for (int indx = 0; indx < attachments.Count; ++indx) + if(sp.IsNPC) { - AvatarAttachment attach = attachments[indx]; - uint attachmentPt = (uint)attach.AttachPoint; - - //m_log.DebugFormat( - // "[ATTACHMENTS MODULE]: Doing initial rez of attachment with itemID {0}, assetID {1}, point {2} for {3} in {4}", - // attach.ItemID, attach.AssetID, p, sp.Name, m_scene.RegionInfo.RegionName); - - try + for (int indx = 0; indx < attachments.Count; ++indx) { - XmlDocument d = null; - if (itemData.TryGetValue(attach.ItemID, out string xmlData)) + AvatarAttachment attach = attachments[indx]; + if(attach.AssetID.IsZero()) + continue; + uint attachmentPt = (uint)attach.AttachPoint; + + //m_log.DebugFormat( + // "[ATTACHMENTS MODULE]: Doing initial rez of attachment with itemID {0}, assetID {1}, point {2} for {3} in {4}", + // attach.ItemID, attach.AssetID, p, sp.Name, m_scene.RegionInfo.RegionName); + + try { - d = new XmlDocument(); - d.LoadXml(xmlData); - m_log.Info($"[ATTACHMENT]: Found saved state for item {attach.ItemID}, loading it"); - } + XmlDocument d = null; + if (itemData.TryGetValue(attach.ItemID, out string xmlData)) + { + d = new XmlDocument(); + d.LoadXml(xmlData); + m_log.Info($"[ATTACHMENT]: Found saved state for item {attach.ItemID}, loading it"); + } - // If we're an NPC then skip all the item checks and manipulations since we don't have an - // inventory right now. - RezSingleAttachmentFromInventoryInternal( - sp, sp.PresenceType == PresenceType.Npc ? UUID.Zero : attach.ItemID, attach.AssetID, attachmentPt, true, d); + // If we're an NPC then skip all the item checks and manipulations since we don't have an + // inventory right now. + RezSingleAttachmentFromInventoryInternal(sp, UUID.Zero, attach.AssetID, attachmentPt, true, d); + } + catch (Exception e) + { + UUID agentId = (sp.ControllingClient is null) ? UUID.Zero : sp.ControllingClient.AgentId; + m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}", + attach.ItemID, attach.AssetID, attachmentPt, agentId, e.Message, e.StackTrace); + } } - catch (Exception e) + } + else + { + // Let's get all items at once, so they get cached + UUID[] items = new UUID[attachments.Count]; + for (int i = 0; i < attachments.Count; ++i) + items[i] = attachments[i].ItemID; + + InventoryItemBase[] attItems = m_scene.InventoryService.GetMultipleItems(sp.UUID, items); + if(attItems is null) + return; + + for (int indx = 0; indx < attachments.Count; ++indx) { - UUID agentId = (sp.ControllingClient == null) ? UUID.Zero : sp.ControllingClient.AgentId; - m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}", - attach.ItemID, attach.AssetID, attachmentPt, agentId, e.Message, e.StackTrace); + InventoryItemBase attItem = attItems[indx]; + if (attItem is null || attItem.Owner != sp.UUID) + continue; + AvatarAttachment attach = attachments[indx]; + uint attachmentPt = (uint)attach.AttachPoint; + + //m_log.DebugFormat( + // "[ATTACHMENTS MODULE]: Doing initial rez of attachment with itemID {0}, assetID {1}, point {2} for {3} in {4}", + // attach.ItemID, attach.AssetID, p, sp.Name, m_scene.RegionInfo.RegionName); + + try + { + XmlDocument d = null; + if (itemData.TryGetValue(attach.ItemID, out string xmlData)) + { + d = new XmlDocument(); + d.LoadXml(xmlData); + m_log.Info($"[ATTACHMENT]: Found saved state for item {attach.ItemID}, loading it"); + } + + // If we're an NPC then skip all the item checks and manipulations since we don't have an + // inventory right now. + RezSingleAttachmentFromInventoryInternal(sp, attach.ItemID, attach.AssetID, attachmentPt, true, d); + } + catch (Exception e) + { + UUID agentId = (sp.ControllingClient is null) ? UUID.Zero : sp.ControllingClient.AgentId; + m_log.ErrorFormat("[ATTACHMENTS MODULE]: Unable to rez attachment with itemID {0}, assetID {1}, point {2} for {3}: {4}\n{5}", + attach.ItemID, attach.AssetID, attachmentPt, agentId, e.Message, e.StackTrace); + } } } } diff --git a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs index c7544a37fa..9bb52ca6b1 100644 --- a/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs +++ b/OpenSim/Region/CoreModules/Framework/InventoryAccess/InventoryAccessModule.cs @@ -36,8 +36,6 @@ using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes.Serialization; using OpenSim.Services.Interfaces; -using GridRegion = OpenSim.Services.Interfaces.GridRegion; - using OpenMetaverse; using log4net; using Nini.Config; @@ -60,8 +58,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { get { - if (m_UserManagement == null) - m_UserManagement = m_Scene.RequestModuleInterface(); + m_UserManagement ??= m_Scene.RequestModuleInterface(); return m_UserManagement; } } @@ -83,16 +80,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess public virtual void Initialise(IConfigSource source) { IConfig moduleConfig = source.Configs["Modules"]; - if (moduleConfig != null) + if (moduleConfig is not null) { - string name = moduleConfig.GetString("InventoryAccessModule", ""); + string name = moduleConfig.GetString("InventoryAccessModule", string.Empty); if (name == Name) { m_Enabled = true; InitialiseCommon(source); - m_log.InfoFormat("[INVENTORY ACCESS MODULE]: {0} enabled.", Name); + m_log.Info($"[INVENTORY ACCESS MODULE]: {Name} enabled."); } } } @@ -104,12 +101,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess protected virtual void InitialiseCommon(IConfigSource source) { IConfig inventoryConfig = source.Configs["Inventory"]; - - if (inventoryConfig != null) - CoalesceMultipleObjectsToInventory - = inventoryConfig.GetBoolean("CoalesceMultipleObjectsToInventory", true); - else - CoalesceMultipleObjectsToInventory = true; + CoalesceMultipleObjectsToInventory = inventoryConfig is null || inventoryConfig.GetBoolean("CoalesceMultipleObjectsToInventory", true); } public virtual void PostInitialise() @@ -122,8 +114,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return; m_Scene = scene; - if (m_thisGridInfo == null) - m_thisGridInfo = scene.SceneGridInfo; + m_thisGridInfo ??= scene.SceneGridInfo; scene.RegisterModuleInterface(this); scene.EventManager.OnNewClient += OnNewClient; @@ -156,7 +147,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess #endregion - //private readonly byte[] DEFAULTSCRIPT = osUTF8.GetASCIIBytes("default\n{\n state_entry()\n {\n llSay(0, \"Script running\");\n }\n}"); #region Inventory Access /// @@ -186,24 +176,24 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess InventoryFolderBase folder = m_Scene.InventoryService.GetFolder(remoteClient.AgentId, folderID); - if (folder == null && Enum.IsDefined(typeof(FolderType), (sbyte)invType)) + if (folder is null && Enum.IsDefined(typeof(FolderType), invType)) { folder = m_Scene.InventoryService.GetFolderForType(remoteClient.AgentId, (FolderType)invType); - if (folder != null) + if (folder is not null) m_log.DebugFormat("[INVENTORY ACCESS MODULE]: Requested folder not found but found folder for type {0}", invType); } - if (folder == null || folder.Owner != remoteClient.AgentId) + if (folder is null || folder.Owner.NotEqual(remoteClient.AgentId)) return; - if (!transactionID.IsZero() && assetType != (byte)AssetType.Settings) + if (transactionID.IsNotZero() && assetType != (byte)AssetType.Settings) { IAgentAssetTransactions agentTransactions = m_Scene.AgentTransactionsModule; - if (agentTransactions != null) + if (agentTransactions is not null) { if (agentTransactions.HandleItemCreationFromTransaction( - remoteClient, transactionID, folderID, callbackID, description, - name, invType, assetType, subType, nextOwnerMask)) + remoteClient, transactionID, folderID, callbackID, description, + name, invType, assetType, subType, nextOwnerMask)) return; } } @@ -214,7 +204,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess uint groupmask = 0; uint flags = 0; - if (invType == (sbyte)InventoryType.Landmark && presence != null) + if (invType == (sbyte)InventoryType.Landmark && presence is not null) { string strdata = GenerateLandmark(presence, out string prefix, out string suffix); byte[] data = osUTF8.GetASCIIBytes(strdata); @@ -239,7 +229,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { flags = subType; IEnvironmentModule envModule = m_Scene.RequestModuleInterface(); - if(envModule == null) + if(envModule is null) return; UUID assetID = envModule.GetDefaultAsset(subType); if(assetID.IsZero()) @@ -322,14 +312,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { InventoryItemBase item = m_Scene.InventoryService.GetItem(remoteClient.AgentId, itemID); - if (item == null) + if (item is null) { m_log.ErrorFormat( "[INVENTORY ACCESS MODULE]: Could not find item {0} for caps inventory update", itemID); return UUID.Zero; } - if (item.Owner != remoteClient.AgentId) + if (item.Owner.NotEqual(remoteClient.AgentId)) return UUID.Zero; InventoryType itemType = (InventoryType)item.InvType; @@ -359,7 +349,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } case (InventoryType)CustomInventoryType.AnimationSet: { - AnimationSet animSet = new AnimationSet(data); + AnimationSet animSet = new(data); uint res = animSet.Validate(x => { const int required = (int)(PermissionMask.Transfer | PermissionMask.Copy); int perms = m_Scene.InventoryService.GetAssetPermissions(remoteClient.AgentId, x); @@ -410,8 +400,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } } - AssetBase asset = - CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data, remoteClient.AgentId.ToString()); + AssetBase asset = CreateAsset(item.Name, item.Description, (sbyte)item.AssetType, data, remoteClient.AgentId.ToString()); item.AssetID = asset.FullID; m_Scene.AssetService.Store(asset); @@ -423,7 +412,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess public virtual bool UpdateInventoryItemAsset(UUID ownerID, InventoryItemBase item, AssetBase asset) { - if (item is not null && item.Owner.Equals(ownerID) && asset is not null) + if (item is not null && asset is not null && item.Owner.Equals(ownerID)) { //m_log.DebugFormat( // "[INVENTORY ACCESS MODULE]: Updating item {0} {1} with new asset {2}", @@ -445,9 +434,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess DeRezAction action, UUID folderID, List objectGroups, IClientAPI remoteClient, bool asAttachment) { - List copiedItems = new List(); - - Dictionary> bundlesToCopy = new Dictionary>(); + Dictionary> bundlesToCopy = new(); if (CoalesceMultipleObjectsToInventory) { @@ -456,10 +443,12 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // reasons. foreach (SceneObjectGroup g in objectGroups) { - if (!bundlesToCopy.ContainsKey(g.OwnerID)) - bundlesToCopy[g.OwnerID] = new List(); - - bundlesToCopy[g.OwnerID].Add(g); + if (!bundlesToCopy.TryGetValue(g.OwnerID, out List lst)) + { + lst = new(); + bundlesToCopy[g.OwnerID] = lst; + } + lst.Add(g); } } else @@ -467,18 +456,17 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // If we don't want to coalesce then put every object in its own bundle. foreach (SceneObjectGroup g in objectGroups) { - List bundle = new List(); - bundle.Add(g); - bundlesToCopy[g.UUID] = bundle; + bundlesToCopy[g.UUID] = new List(){ g }; } } -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Copying {0} object bundles to folder {1} action {2} for {3}", -// bundlesToCopy.Count, folderID, action, remoteClient.Name); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Copying {0} object bundles to folder {1} action {2} for {3}", + // bundlesToCopy.Count, folderID, action, remoteClient.Name); // Each iteration is really a separate asset being created, // with distinct destinations as well. + List copiedItems = new(); foreach (List bundle in bundlesToCopy.Values) copiedItems.Add(CopyBundleToInventory(action, folderID, bundle, remoteClient, asAttachment)); @@ -500,23 +488,21 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess DeRezAction action, UUID folderID, List objlist, IClientAPI remoteClient, bool asAttachment) { - CoalescedSceneObjects coa = new CoalescedSceneObjects(UUID.Zero); - Dictionary originalPositions = new Dictionary(); - Dictionary originalRotations = new Dictionary(); + CoalescedSceneObjects coa = new(UUID.Zero); + Dictionary originalPositions = new(); + Dictionary originalRotations = new(); // this possible is not needed if keyframes are saved -// Dictionary originalKeyframes = new Dictionary(); + //Dictionary originalKeyframes = new Dictionary(); foreach (SceneObjectGroup objectGroup in objlist) { - if (objectGroup.RootPart.KeyframeMotion != null) - { - objectGroup.RootPart.KeyframeMotion.Suspend(); - } + objectGroup.RootPart.KeyframeMotion?.Suspend(); + objectGroup.RootPart.SetForce(Vector3.Zero); objectGroup.RootPart.SetAngularImpulse(Vector3.Zero, false); -// originalKeyframes[objectGroup.UUID] = objectGroup.RootPart.KeyframeMotion; -// objectGroup.RootPart.KeyframeMotion = null; + //originalKeyframes[objectGroup.UUID] = objectGroup.RootPart.KeyframeMotion; + //objectGroup.RootPart.KeyframeMotion = null; Vector3 inventoryStoredPosition = objectGroup.AbsolutePosition; originalPositions[objectGroup.UUID] = inventoryStoredPosition; @@ -567,18 +553,17 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { objectGroup.AbsolutePosition = originalPositions[objectGroup.UUID]; objectGroup.RootPart.RotationOffset = originalRotations[objectGroup.UUID]; -// objectGroup.RootPart.KeyframeMotion = originalKeyframes[objectGroup.UUID]; - if (objectGroup.RootPart.KeyframeMotion != null) - objectGroup.RootPart.KeyframeMotion.Resume(); + //objectGroup.RootPart.KeyframeMotion = originalKeyframes[objectGroup.UUID]; + objectGroup.RootPart.KeyframeMotion?.Resume(); } InventoryItemBase item = CreateItemForObject(action, remoteClient, objlist[0], folderID); -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Created item is {0}", -// item != null ? item.ID.ToString() : "NULL"); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Created item is {0}", + // item != null ? item.ID.ToString() : "NULL"); - if (item == null) + if (item is null) return null; item.CreatorId = objlist[0].RootPart.CreatorID.ToString(); @@ -643,18 +628,15 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess else { ScenePresence notifyUser = m_Scene.GetScenePresence(item.Owner); - if (notifyUser != null) - { - notifyUser.ControllingClient.SendInventoryItemCreateUpdate(item, 0); - } + notifyUser?.ControllingClient.SendInventoryItemCreateUpdate(item, 0); } } -/* this is already done under m_Scene.AddInventoryItem(item) that triggers TriggerOnNewInventoryItemUploadComplete calling HG + /* this is already done under m_Scene.AddInventoryItem(item) that triggers TriggerOnNewInventoryItemUploadComplete calling HG // This is a hook to do some per-asset post-processing for subclasses that need that if (remoteClient != null && action != DeRezAction.Delete) ExportAsset(remoteClient.AgentId, asset.FullID); -*/ + */ return item; } @@ -682,7 +664,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess effectivePerms &= grp.CurrentAndFoldedNextPermissions(); } - if (remoteClient != null && (remoteClient.AgentId != so.RootPart.OwnerID) && m_Scene.Permissions.PropagatePermissions()) + if (remoteClient is not null && (remoteClient.AgentId.NotEqual(so.RootPart.OwnerID)) && m_Scene.Permissions.PropagatePermissions()) { // apply parts inventory items next owner PermissionsUtil.ApplyNoModFoldedPermissions(effectivePerms, ref effectivePerms); @@ -731,30 +713,30 @@ 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); -// + //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; + + UUID userID; if (action == DeRezAction.Take || action == DeRezAction.TakeCopy || action == DeRezAction.SaveToExistingUserInventoryItem) { // Take or take copy require a taker // Saving changes requires a local user - // - if (remoteClient == null) + + if (remoteClient is null) return null; userID = remoteClient.AgentId; -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is {1} {2}", -// action, remoteClient.Name, userID); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is {1} {2}", + // action, remoteClient.Name, userID); } - else if (so.RootPart.OwnerID == so.RootPart.GroupID) + else if (so.RootPart.OwnerID.Equals(so.RootPart.GroupID)) { // Group owned objects go to the last owner before the object was transferred. userID = so.RootPart.LastOwnerID; @@ -765,9 +747,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // userID = so.RootPart.OwnerID; -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is object owner {1}", -// action, userID); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Target of {0} in CreateItemForObject() is object owner {1}", + // action, userID); } if (userID.IsZero()) // Can't proceed @@ -775,7 +757,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return null; } - InventoryItemBase item = null; + InventoryItemBase item; if (DeRezAction.SaveToExistingUserInventoryItem == action) { item = m_Scene.InventoryService.GetItem(userID, so.RootPart.FromUserInventoryItemID); @@ -783,13 +765,10 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess //item = userInfo.RootFolder.FindItem( // objectGroup.RootPart.FromUserInventoryItemID); - if (item == null) + if (item is null) { - m_log.DebugFormat( - "[INVENTORY ACCESS MODULE]: Object {0} {1} scheduled for save to inventory has already been deleted.", - so.Name, so.UUID); - - return null; + m_log.Debug( + $"[INVENTORY ACCESS MODULE]: Object {so.Name} {so.UUID} scheduled for save to inventory has already been deleted."); } return item; } @@ -807,8 +786,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { // Deleting someone else's item // - if (remoteClient == null || - so.OwnerID != remoteClient.AgentId) + if (remoteClient is null || so.OwnerID.NotEqual(remoteClient.AgentId)) { folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } @@ -820,21 +798,19 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess else if (action == DeRezAction.Return) { // Dump to lost + found unconditionally - // folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } - if (folderID.IsZero() && folder == null) + if (folderID.IsZero() && folder is null) { if (action == DeRezAction.Delete) { // Deletes go to trash by default - // folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Trash); } else { - if (remoteClient == null || so.RootPart.OwnerID != remoteClient.AgentId) + if (remoteClient is null || so.RootPart.OwnerID.NotEqual(remoteClient.AgentId)) { // Taking copy of another person's item. Take to // Objects folder. @@ -844,7 +820,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess else { // Catch all. Use lost & found - // folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.LostAndFound); } } @@ -860,7 +835,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { folder = m_Scene.InventoryService.GetFolder(userID, so.FromFolderID); - if(folder == null || folder.Type == (int)FolderType.Trash || folder.Type == (int)FolderType.LostAndFound) + if(folder is null || folder.Type == (int)FolderType.Trash || folder.Type == (int)FolderType.LostAndFound) { folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object); } @@ -870,9 +845,9 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess while(true) { parent = m_Scene.InventoryService.GetFolder(userID, parent.ParentID); - if (parent != null && (parent.ParentID.IsZero() || parent.ID.Equals(parent.ParentID))) + if (parent is not null && (parent.ParentID.IsZero() || parent.ID.Equals(parent.ParentID))) break; - if (parent == null || parent.Type == (int)FolderType.Trash || parent.Type == (int)FolderType.LostAndFound) + if (parent is null || parent.Type == (int)FolderType.Trash || parent.Type == (int)FolderType.LostAndFound) { folder = m_Scene.InventoryService.GetFolderForType(userID, FolderType.Object); break; @@ -882,22 +857,24 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess } } - if (folder == null) // None of the above + if (folder is null) // None of the above { folder = new InventoryFolderBase(folderID); - if (folder == null) // Nowhere to put it + if (folder is null) // Nowhere to put it { return null; } } - item = new InventoryItemBase(); - item.ID = UUID.Random(); - item.InvType = (int)InventoryType.Object; - item.Folder = folder.ID; - item.Owner = userID; - item.CreationDate = Util.UnixTimeSinceEpoch(); + item = new InventoryItemBase + { + ID = UUID.Random(), + InvType = (int)InventoryType.Object, + Folder = folder.ID, + Owner = userID, + CreationDate = Util.UnixTimeSinceEpoch() + }; return item; } @@ -961,45 +938,37 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return null; AssetBase rezAsset = m_Scene.AssetService.Get(assetID.ToString()); - if (rezAsset == null) + if (rezAsset is null) { - if (item != null) + if (item is not null) { - 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); + m_log.Warn( + $"[InventoryAccessModule]: Could not find asset {assetID} for item {item.Name} {item.ID} for {remoteClient.Name} in RezObject()"); + remoteClient.SendAgentAlertMessage($"Unable to rez: could not find asset {assetID} for item {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); + m_log.Warn($"[INVENTORY ACCESS MODULE]: Could not find asset {assetID} for {remoteClient.Name} in RezObject()"); + remoteClient.SendAgentAlertMessage($"Unable to rez: could not find asset {assetID}", false); } return null; } - if(rezAsset.Data == null || rezAsset.Data.Length == 0) + if(rezAsset.Data is null || rezAsset.Data.Length == 0) { - m_log.WarnFormat( - "[INVENTORY ACCESS MODULE]: missing data in asset {0} to RezObject()", - assetID, remoteClient.Name); - remoteClient.SendAgentAlertMessage(string.Format("Unable to rez: missing data in asset {0} ", assetID), false); + m_log.Warn($"[INVENTORY ACCESS MODULE]: missing data in asset {assetID} to RezObject()"); + remoteClient.SendAgentAlertMessage($"Unable to rez: missing data in asset {assetID}", false); return null; } SceneObjectGroup group = null; - List objlist; - List veclist; - Vector3 bbox; - float offsetHeight; byte bRayEndIsIntersection = (byte)(RayEndIsIntersection ? 1 : 0); Vector3 pos; bool single = m_Scene.GetObjectsToRez( - rezAsset.Data, attachment, out objlist, out veclist, out bbox, out offsetHeight); + rezAsset.Data, attachment, out List objlist, + out List veclist, out Vector3 bbox, out float offsetHeight); pos = m_Scene.GetNewRezLocation(RayStart, RayEnd, RayTargetID, Quaternion.Identity, @@ -1016,7 +985,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { foreach (SceneObjectGroup g in objlist) { - if(g.RootPart.Shape != null) + if(g.RootPart.Shape is not null) { PCode code = (PCode)g.RootPart.Shape.PCode; if(code == PCode.Grass || code == PCode.NewTree || code == PCode.Tree) @@ -1035,16 +1004,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess primcount += g.PrimCount; } - if (!m_Scene.Permissions.CanRezObject( - primcount, remoteClient.AgentId, pos) - && !attachment) + if (!m_Scene.Permissions.CanRezObject(primcount, remoteClient.AgentId, pos) && !attachment) { // 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 != null) + if (item is not null) { if (((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) && (!attachment)) remoteClient.SendBulkUpdateInventory(item); @@ -1052,7 +1019,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess return null; } - if (item != null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment)) + if (item is not null && !DoPreRezWhenFromItem(remoteClient, item, objlist, pos, veclist, attachment)) return null; for (int i = 0; i < objlist.Count; i++) @@ -1060,13 +1027,13 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess group = objlist[i]; SceneObjectPart rootPart = group.RootPart; -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", -// group.Name, group.LocalId, group.UUID, -// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, -// remoteClient.Name); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Preparing to rez {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", + // group.Name, group.LocalId, group.UUID, + // group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, + // remoteClient.Name); -// Vector3 storedPosition = group.AbsolutePosition; + //Vector3 storedPosition = group.AbsolutePosition; if (group.UUID.IsZero()) { m_log.Debug("[INVENTORY ACCESS MODULE]: Object has UUID.Zero! Position 3"); @@ -1080,15 +1047,20 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess group.RootPart.Shape.LastAttachPoint = (byte)group.AttachmentPoint; } - if (item == null) + if (item is 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; - part.RezzerID = remoteClient.AgentId; + if(part.OwnerID.NotEqual(remoteClient.AgentId)) + { + if(part.OwnerID.NotEqual(part.GroupID)) + part.LastOwnerID = part.OwnerID; + part.OwnerID = remoteClient.AgentId; + part.RezzerID = remoteClient.AgentId; + part.Inventory.ChangeInventoryOwner(remoteClient.AgentId); + } } } @@ -1132,17 +1104,16 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess else m_Scene.AddNewSceneObject(group, true, false); - -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: Rezzed {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", -// group.Name, group.LocalId, group.UUID, -// group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, -// remoteClient.Name); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: Rezzed {0} {1} {2} ownermask={3:X} nextownermask={4:X} groupmask={5:X} everyonemask={6:X} for {7}", + // group.Name, group.LocalId, group.UUID, + // group.RootPart.OwnerMask, group.RootPart.NextOwnerMask, group.RootPart.GroupMask, group.RootPart.EveryoneMask, + // remoteClient.Name); } -// group.SetGroup(remoteClient.ActiveGroupId, remoteClient); + //group.SetGroup(remoteClient.ActiveGroupId, remoteClient); - if (item != null) + if (item is not null) DoPostRezWhenFromItem(item, attachment); return group; @@ -1171,8 +1142,8 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess // item that it came from. This allows us to enable 'save object to inventory' if (!m_Scene.Permissions.BypassPermissions()) { - if ((item.CurrentPermissions & (uint)PermissionMask.Copy) - == (uint)PermissionMask.Copy && (item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) + if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy && + (item.Flags & (uint)InventoryItemFlags.ObjectHasMultipleItems) == 0) { fromUserInventoryItemId = item.ID; } @@ -1238,11 +1209,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess so.FromFolderID = item.Folder; -// m_log.DebugFormat( -// "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", -// rootPart.OwnerID, item.Owner, item.CurrentPermissions); + //m_log.DebugFormat( + // "[INVENTORY ACCESS MODULE]: rootPart.OwnedID {0}, item.Owner {1}, item.CurrentPermissions {2:X}", + // rootPart.OwnerID, item.Owner, item.CurrentPermissions); - if ((rootPart.OwnerID != item.Owner) || + if ((rootPart.OwnerID.NotEqual(item.Owner)) || (item.CurrentPermissions & (uint)PermissionMask.Slam) != 0 || (item.Flags & (uint)InventoryItemFlags.ObjectSlamPerm) != 0) { @@ -1255,7 +1226,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess foreach (SceneObjectPart part in so.Parts) { part.GroupMask = 0; // DO NOT propagate here - if( part.OwnerID != part.GroupID) + if( part.OwnerID.NotEqual(part.GroupID)) part.LastOwnerID = part.OwnerID; part.OwnerID = item.Owner; part.RezzerID = item.Owner; @@ -1294,7 +1265,6 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess part.NextOwnerMask = item.NextPermissions & part.BaseMask; } } - } } else @@ -1331,17 +1301,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { if (!m_Scene.Permissions.BypassPermissions()) { - if ((item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) + if (!isAttachment && (item.CurrentPermissions & (uint)PermissionMask.Copy) == 0) { // If this is done on attachments, no // copy ones will be lost, so avoid it - // - if (!isAttachment) - { - List uuids = new List(); - uuids.Add(item.ID); - m_Scene.InventoryService.DeleteItems(item.Owner, uuids); - } + m_Scene.InventoryService.DeleteItems(item.Owner, new List(){ item.ID }); } } } @@ -1361,14 +1325,14 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess { InventoryItemBase assetRequestItem = GetItem(remoteClient.AgentId, itemID); - if (assetRequestItem == null) + if (assetRequestItem is null) { ILibraryService lib = m_Scene.RequestModuleInterface(); - if (lib != null) + if (lib is not null) assetRequestItem = lib.LibraryRootFolder.FindItem(itemID); - if (assetRequestItem == null) + if (assetRequestItem is null) return false; } @@ -1427,9 +1391,11 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess /// private AssetBase CreateAsset(string name, string description, sbyte assetType, byte[] data, string creatorID) { - AssetBase asset = new AssetBase(UUID.Random(), name, assetType, creatorID); - asset.Description = description; - asset.Data = (data == null) ? new byte[1] : data; + AssetBase asset = new(UUID.Random(), name, assetType, creatorID) + { + Description = description, + Data = data ?? (new byte[1]) + }; return asset; } @@ -1439,7 +1405,7 @@ namespace OpenSim.Region.CoreModules.Framework.InventoryAccess IInventoryService invService = m_Scene.RequestModuleInterface(); InventoryItemBase item = invService.GetItem(agentID, itemID); - if (item != null && item.CreatorData != null && item.CreatorData != string.Empty) + if (item is not null && !string.IsNullOrEmpty(item.CreatorData)) UserManagementModule.AddCreatorUser(item.CreatorIdAsUuid, item.CreatorData); return item; diff --git a/OpenSim/Region/Framework/Scenes/Scene.cs b/OpenSim/Region/Framework/Scenes/Scene.cs index 7ca0129e18..5767475076 100755 --- a/OpenSim/Region/Framework/Scenes/Scene.cs +++ b/OpenSim/Region/Framework/Scenes/Scene.cs @@ -4034,9 +4034,7 @@ namespace OpenSim.Region.Framework.Scenes if (sp is not null && !sp.IsDeleted && sp.IsChildAgent && (sp.LifecycleState == ScenePresenceState.Running || sp.LifecycleState == ScenePresenceState.PreRemove)) { - m_log.DebugFormat( - "[SCENE]: Reusing existing child scene presence for {0}, state {1} in {2}", - sp.Name, sp.LifecycleState, Name); + m_log.Debug($"[SCENE]: Reusing existing child scene presence for {sp.Name}, state {sp.LifecycleState} in {Name}"); // In the case where, for example, an A B C D region layout, an avatar may // teleport from A -> D, but then -> C before A has asked B to close its old child agent. When C @@ -4064,17 +4062,14 @@ namespace OpenSim.Region.Framework.Scenes if (EntityTransferModule.IsInTransit(sp.UUID)) { sp.DoNotCloseAfterTeleport = true; - - m_log.DebugFormat( - "[SCENE]: Set DoNotCloseAfterTeleport for child scene presence {0} in {1} because this region will attempt end-of-teleport close from a previous close.", - sp.Name, Name); + m_log.Debug($"[SCENE]: Set DoNotCloseAfterTeleport for child scene presence {sp.Name} in {Name} because this region will attempt end-of-teleport close from a previous close."); } } } // Need to poll here in case we are currently deleting an sp. Letting threads run over each other will // allow unpredictable things to happen. - if (sp is not null) + if (sp is not null && sp.LifecycleState == ScenePresenceState.Removing) { const int polls = 10; const int pollInterval = 1000; diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index feab111226..75a1e0d057 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -192,10 +192,10 @@ namespace OpenSim.Region.Framework.Scenes { // needs more exclusion ? return(Backup && !IsTemporary && !inTransit && !UsesPhysics && !IsSelected && !IsAttachmentCheckFull() && - !RootPart.Shape.MeshFlagEntry && // animations are not sent correctly for now - RootPart.KeyframeMotion is null && - (DateTime.UtcNow.Ticks - timeLastChanged > 3000000000) //&& //3000000000 is 5min - //(DateTime.UtcNow.Ticks - timeLastChanged > 36000000000) //&& //36000000000 is one hour + !RootPart.Shape.MeshFlagEntry && // animations are not sent correctly for now + RootPart.KeyframeMotion is null && + (DateTime.UtcNow.Ticks - timeLastChanged > 3000000000) //&& //3000000000 is 5min + //(DateTime.UtcNow.Ticks - timeLastChanged > 36000000000) //&& //36000000000 is one hour ); } } @@ -251,8 +251,8 @@ namespace OpenSim.Region.Framework.Scenes } m_hasGroupChanged = value; -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: HasGroupChanged set to {0} for {1} {2}", m_hasGroupChanged, Name, LocalId); } get { return m_hasGroupChanged; } @@ -416,15 +416,15 @@ namespace OpenSim.Region.Framework.Scenes /// public bool Backup { get; private set; } - protected MapAndArray m_parts = new MapAndArray(); + protected MapAndArray m_parts = new(); protected ulong m_regionHandle; protected SceneObjectPart m_rootPart; // private Dictionary m_scriptEvents = new Dictionary(); - private Dictionary m_targets = new Dictionary(); - private Dictionary m_rotTargets = new Dictionary(); - private Dictionary> m_targetsByScript = new Dictionary>(); + private Dictionary m_targets = new(); + private Dictionary m_rotTargets = new(); + private Dictionary> m_targetsByScript = new(); public Dictionary AtTargets { @@ -480,15 +480,13 @@ namespace OpenSim.Region.Framework.Scenes get { return m_parts.Count; } } -// protected Quaternion m_rotation = Quaternion.Identity; -// -// public virtual Quaternion Rotation -// { -// get { return m_rotation; } -// set { -// m_rotation = value; -// } -// } + //protected Quaternion m_rotation = Quaternion.Identity; + + //public virtual Quaternion Rotation + //{ + // get { return m_rotation; } + // set { m_rotation = value; } + //} public Quaternion GroupRotation { @@ -499,8 +497,6 @@ namespace OpenSim.Region.Framework.Scenes { get { - Vector3 finalScale = new Vector3(); - SceneObjectPart[] parts = m_parts.GetArray(); SceneObjectPart part; Vector3 partscale; @@ -537,11 +533,11 @@ namespace OpenSim.Region.Framework.Scenes maxScaleZ = ftmp; } - finalScale.X = (minScaleX > maxScaleX) ? minScaleX : maxScaleX; - finalScale.Y = (minScaleY > maxScaleY) ? minScaleY : maxScaleY; - finalScale.Z = (minScaleZ > maxScaleZ) ? minScaleZ : maxScaleZ; + partscale.X = (minScaleX > maxScaleX) ? minScaleX : maxScaleX; + partscale.Y = (minScaleY > maxScaleY) ? minScaleY : maxScaleY; + partscale.Z = (minScaleZ > maxScaleZ) ? minScaleZ : maxScaleZ; - return finalScale; + return partscale; } } @@ -728,7 +724,7 @@ namespace OpenSim.Region.Framework.Scenes // We remove the object here try { - List localIDs = new List(){root.LocalId}; + List localIDs = new(){root.LocalId}; sogScene.AddReturn(sog.OwnerID, sog.Name, sog.AbsolutePosition, "Returned at region cross"); sogScene.DeRezObjects(null, localIDs, UUID.Zero, DeRezAction.Return, UUID.Zero, false); @@ -741,14 +737,12 @@ namespace OpenSim.Region.Framework.Scenes } } -// if(!m_scene.IsRunning) -// return sog; + //if(!m_scene.IsRunning) + // return sog; - if (root.KeyframeMotion is not null) - root.KeyframeMotion.StartCrossingCheck(); + root.KeyframeMotion?.StartCrossingCheck(); - if(root.PhysActor is not null) - root.PhysActor.CrossingStart(); + root.PhysActor?.CrossingStart(); IEntityTransferModule entityTransfer = sogScene.RequestModuleInterface(); @@ -769,8 +763,8 @@ namespace OpenSim.Region.Framework.Scenes return sog; } - string reason = String.Empty; - EntityTransferContext ctx = new EntityTransferContext(); + string reason = string.Empty; + EntityTransferContext ctx = new(); Vector3 curPos = root.GroupPosition; foreach (ScenePresence av in sog.m_sittingAvatars) @@ -798,20 +792,20 @@ namespace OpenSim.Region.Framework.Scenes // We unparent the SP quietly so that it won't // be made to stand up - List avsToCross = new List(); - List avsToCrossFar = new List(); + List avsToCross = new(); + List avsToCrossFar = new(); ulong destHandle = destination.RegionHandle; List sittingAvatars = GetSittingAvatars(); foreach (ScenePresence av in sittingAvatars) { byte cflags = 1; - avtocrossInfo avinfo = new avtocrossInfo(); + avtocrossInfo avinfo = new(); SceneObjectPart parentPart = sogScene.GetSceneObjectPart(av.ParentID); if (parentPart is not null) { av.ParentUUID = parentPart.UUID; - if(parentPart.SitTargetAvatar == av.UUID) + if(parentPart.SitTargetAvatar.Equals(av.UUID)) cflags = 7; // low 3 bits set else cflags = 3; @@ -1013,7 +1007,6 @@ namespace OpenSim.Region.Framework.Scenes rootp.Stop(); SceneObjectPart[] parts = sog.m_parts.GetArray(); - foreach (SceneObjectPart part in parts) { if (part != rootp) @@ -1151,7 +1144,7 @@ namespace OpenSim.Region.Framework.Scenes return -1; } - TeleportObjectData tdata = new TeleportObjectData() + TeleportObjectData tdata = new() { flags = flags, vel = vel, @@ -1228,13 +1221,9 @@ namespace OpenSim.Region.Framework.Scenes public string Text { - get { - string returnstr = m_rootPart.Text; - if (returnstr.Length > 255) - { - returnstr = returnstr.Substring(0, 255); - } - return returnstr; + get + { + return m_rootPart.Text.Length > 255 ? m_rootPart.Text[..255] : m_rootPart.Text; } set { m_rootPart.Text = value; } } @@ -1291,8 +1280,8 @@ namespace OpenSim.Region.Framework.Scenes if (partSelect) { IsSelected = partSelect; -// if (!IsAttachment) -// ScheduleGroupForFullUpdate(); + //if (!IsAttachment) + // ScheduleGroupForFullUpdate(); } else { @@ -1309,10 +1298,10 @@ namespace OpenSim.Region.Framework.Scenes return; } IsSelected = partSelect; -// if (!IsAttachment) -// { -// ScheduleGroupForFullUpdate(); -// } + //if (!IsAttachment) + //{ + // ScheduleGroupForFullUpdate(); + //} } } @@ -1374,16 +1363,10 @@ namespace OpenSim.Region.Framework.Scenes /// No avatar should appear more than once in this list. /// Do not manipulate this list directly - use the Add/Remove sitting avatar methods on SceneObjectPart. /// - protected internal List m_sittingAvatars = new List(); + protected internal List m_sittingAvatars = new(); #endregion -// ~SceneObjectGroup() -// { -// //m_log.DebugFormat("[SCENE OBJECT GROUP]: Destructor called for {0}, local id {1}", Name, LocalId); -// Console.WriteLine("Destructor called for {0}, local id {1}", Name, LocalId); -// } - #region Constructors /// @@ -1465,7 +1448,7 @@ namespace OpenSim.Region.Framework.Scenes { if (node.Attributes["UUID"] is not null) { - UUID itemid = new UUID(node.Attributes["UUID"].Value); + UUID itemid = new(node.Attributes["UUID"].Value); if (itemid.IsNotZero()) m_savedScriptState[itemid] = node.InnerXml; } @@ -1475,7 +1458,7 @@ namespace OpenSim.Region.Framework.Scenes public void LoadScriptState(XmlReader reader) { -// m_log.DebugFormat("[SCENE OBJECT GROUP]: Looking for script state for {0}", Name); + //m_log.DebugFormat("[SCENE OBJECT GROUP]: Looking for script state for {0}", Name); while (true) { @@ -1493,8 +1476,7 @@ namespace OpenSim.Region.Framework.Scenes if (!string.IsNullOrEmpty(uuid)) { //m_log.DebugFormat("[SCENE OBJECT GROUP]: Found state for item ID {0} in object {1}", uuid, Name); - UUID itemid = new UUID(uuid); - if (itemid.IsNotZero()) + if (UUID.TryParse(uuid, out UUID itemid) && itemid.IsNotZero()) m_savedScriptState[itemid] = innerXml; } else @@ -1518,16 +1500,16 @@ namespace OpenSim.Region.Framework.Scenes if (IsAttachment) return; m_scene.SceneGraph.FireAttachToBackup(this); -// if (InSceneBackup) - { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID); + //if (InSceneBackup) + //{ + // m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Attaching object {0} {1} to scene presistence sweep", Name, UUID); if (!Backup) m_scene.EventManager.OnBackup += ProcessBackup; Backup = true; - } + //} } /// @@ -1549,10 +1531,7 @@ namespace OpenSim.Region.Framework.Scenes for (int i = 0; i < parts.Length; i++) { part = parts[i]; - if (part.KeyframeMotion is not null) - { - part.KeyframeMotion.UpdateSceneObject(this); - } + part.KeyframeMotion?.UpdateSceneObject(this); if (Object.ReferenceEquals(part, m_rootPart)) continue; @@ -1578,7 +1557,7 @@ namespace OpenSim.Region.Framework.Scenes // If we get a result, we're going to find the closest result to the origin of the ray // and send back the intersection information back to the innerscene. - EntityIntersection result = new EntityIntersection(); + EntityIntersection result = new(); SceneObjectPart[] parts = m_parts.GetArray(); @@ -1710,9 +1689,9 @@ namespace OpenSim.Region.Framework.Scenes Matrix4 m = Matrix4.CreateFromQuaternion(Quaternion.Conjugate(part.GetWorldRotation())); Vector3 a = m.AtAxis; - a.X = Math.Abs(a.X); - a.Y = Math.Abs(a.Y); - a.Z = Math.Abs(a.Z); + a.X = MathF.Abs(a.X); + a.Y = MathF.Abs(a.Y); + a.Z = MathF.Abs(a.Z); float tmpS = Vector3.Dot(a, scale); float tmp = offset.X - tmpS; @@ -1724,9 +1703,9 @@ namespace OpenSim.Region.Framework.Scenes maxX = tmp; a = m.LeftAxis; - a.X = Math.Abs(a.X); - a.Y = Math.Abs(a.Y); - a.Z = Math.Abs(a.Z); + a.X = MathF.Abs(a.X); + a.Y = MathF.Abs(a.Y); + a.Z = MathF.Abs(a.Z); tmpS = Vector3.Dot(a, scale); tmp = offset.Y - tmpS; @@ -1738,9 +1717,9 @@ namespace OpenSim.Region.Framework.Scenes maxY = tmp; a = m.UpAxis; - a.X = Math.Abs(a.X); - a.Y = Math.Abs(a.Y); - a.Z = Math.Abs(a.Z); + a.X = MathF.Abs(a.X); + a.Y = MathF.Abs(a.Y); + a.Z = MathF.Abs(a.Z); tmpS = Vector3.Dot(a, scale); tmp = offset.Z - tmpS; @@ -1762,7 +1741,7 @@ namespace OpenSim.Region.Framework.Scenes public Vector3 GetAxisAlignedBoundingBox(out float offsetHeight) { GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ); - Vector3 boundingBox = new Vector3(maxX - minX, maxY - minY, maxZ - minZ); + Vector3 boundingBox = new(maxX - minX, maxY - minY, maxZ - minZ); offsetHeight = 0; float lower = -minZ; @@ -1785,7 +1764,7 @@ namespace OpenSim.Region.Framework.Scenes private Vector3 m_boundsCenter; private Vector3 m_LastCenterOffset; - private Vector3 last_boundsRot = new Vector3(-10, -10, -10); + private Vector3 last_boundsRot = new(-10, -10, -10); public Vector3 getCenterOffset() { // math is done in GetBoundsRadius(); @@ -1827,8 +1806,7 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart p; SceneObjectPart[] parts = m_parts.GetArray(); - int nparts = parts.Length; - for (int i = 0; i < nparts; i++) + for (int i = 0; i < parts.Length; i++) { p = parts[i]; partR = 0.5f * p.Scale.Length(); @@ -1850,7 +1828,7 @@ namespace OpenSim.Region.Framework.Scenes areaF = 0.5f / areaF; // scale it areaF = Utils.Clamp(areaF, 0.05f, 100f); // clamp it - m_areaFactor = (float)Math.Sqrt(areaF); + m_areaFactor = MathF.Sqrt(areaF); m_boundsCenter = offset; m_boundsRadius = res; return res; @@ -1871,9 +1849,7 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart p; SceneObjectPart[] parts = m_parts.GetArray(); - - int nparts = parts.Length; - for (int i = 0; i < nparts; i++) + for (int i = 0; i < parts.Length; i++) { p = parts[i]; @@ -1891,7 +1867,7 @@ namespace OpenSim.Region.Framework.Scenes partCost = 0; partPhysCost = 0; - for (int i = 0; i < nparts; i++) + for (int i = 0; i < parts.Length; i++) { p = parts[i]; @@ -1917,7 +1893,7 @@ namespace OpenSim.Region.Framework.Scenes { partPhysCost = 1.0f; partCost = 1.0f; - linksetResCost = (float)nparts; + linksetResCost = parts.Length; linksetPhysCost = linksetResCost; } } @@ -1927,13 +1903,11 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart p; SceneObjectPart[] parts = m_parts.GetArray(); - int nparts = parts.Length; - PhysCost = 0; StreamCost = 0; SimulCost = 0; - for (int i = 0; i < nparts; i++) + for (int i = 0; i < parts.Length; i++) { p = parts[i]; @@ -1950,8 +1924,8 @@ namespace OpenSim.Region.Framework.Scenes public void SaveScriptedState(XmlTextWriter writer, bool oldIDs) { - XmlDocument doc = new XmlDocument(); - Dictionary states = new Dictionary(); + XmlDocument doc = new(); + Dictionary states = new(); SceneObjectPart[] parts = m_parts.GetArray(); for (int i = 0; i < parts.Length; i++) @@ -1991,11 +1965,10 @@ namespace OpenSim.Region.Framework.Scenes m_rootPart.AttachedPos = m_rootPart.OffsetPosition; avatar.RemoveAttachment(this); - Vector3 detachedpos = new Vector3(127f,127f,127f); if (avatar is null) return; - detachedpos = avatar.AbsolutePosition; + Vector3 detachedpos = avatar.AbsolutePosition; FromItemID = UUID.Zero; AbsolutePosition = detachedpos; @@ -2006,9 +1979,9 @@ namespace OpenSim.Region.Framework.Scenes // parts[i].AttachedAvatar = UUID.Zero; m_rootPart.SetParentLocalId(0); - AttachmentPoint = (byte)0; + AttachmentPoint = 0; // must check if buildind should be true or false here -// m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false); + //m_rootPart.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), m_rootPart.VolumeDetectActive,false); ApplyPhysics(); HasGroupChanged = true; @@ -2024,11 +1997,8 @@ namespace OpenSim.Region.Framework.Scenes { ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); //Vector3 detachedpos = new Vector3(127f, 127f, 127f); - if (avatar is not null) - { - //detachedpos = avatar.AbsolutePosition; - avatar.RemoveAttachment(this); - } + //detachedpos = avatar.AbsolutePosition; + avatar?.RemoveAttachment(this); AttachedAvatar = UUID.Zero; @@ -2098,7 +2068,7 @@ namespace OpenSim.Region.Framework.Scenes for (int i = 0; i < parts.Length; i++) { SceneObjectPart part = parts[i]; - if (part.UUID != m_rootPart.UUID) + if (part.UUID.NotEqual(m_rootPart.UUID)) part.ParentID = m_rootPart.LocalId; } } @@ -2118,23 +2088,7 @@ namespace OpenSim.Region.Framework.Scenes return 5; } - // justincc: I don't believe this hack is needed any longer, especially since the physics - // parts of set AbsolutePosition were already commented out. By changing HasGroupChanged to false - // this method was preventing proper reload of scene objects. - - // dahlia: I had to uncomment it, without it meshing was failing on some prims and objects - // at region startup - - // teravus: After this was removed from the linking algorithm, Linked prims no longer collided - // properly when non-physical if they havn't been moved. This breaks ALL builds. - // see: http://opensimulator.org/mantis/view.php?id=3108 - - // Here's the deal, this is ABSOLUTELY CRITICAL so the physics scene gets the update about the - // position of linkset prims. IF YOU CHANGE THIS, YOU MUST TEST colliding with just linked and - // unmoved prims! As soon as you move a Prim/group, it will collide properly because Absolute - // Position has been set! - - public void ResetChildPrimPhysicsPositions() + public void ResetChildPrimPhysicsPositions() { // Setting this SOG's absolute position also loops through and sets the positions // of the SOP's in this SOG's linkset. This has the side affect of making sure @@ -2183,11 +2137,11 @@ namespace OpenSim.Region.Framework.Scenes public virtual void OnGrabPart(SceneObjectPart part, Vector3 offsetPos, IClientAPI remoteClient) { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}", -// remoteClient.Name, part.Name, part.LocalId, offsetPos); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Processing OnGrabPart for {0} on {1} {2}, offsetPos {3}", + // remoteClient.Name, part.Name, part.LocalId, offsetPos); -// part.StoreUndoState(); + //part.StoreUndoState(); part.OnGrab(offsetPos, remoteClient); } @@ -2222,7 +2176,7 @@ namespace OpenSim.Region.Framework.Scenes Scene.ForEachScenePresence(delegate(ScenePresence avatar) { - if (!avatar.IsChildAgent && avatar.ParentID == part.LocalId && avatar.ParentUUID == UUID.Zero) + if (!avatar.IsChildAgent && avatar.ParentID == part.LocalId && avatar.ParentUUID.IsZero()) avatar.StandUp(); if (!silent) @@ -2351,8 +2305,6 @@ namespace OpenSim.Region.Framework.Scenes if (part.LocalId != m_rootPart.LocalId) part.ApplyPhysics(m_rootPart.GetEffectiveObjectFlags(), part.VolumeDetectActive, true); } - // Hack to get the physics scene geometries in the right spot -// ResetChildPrimPhysicsPositions(); if (m_rootPart.PhysActor is not null) m_rootPart.PhysActor.Building = false; @@ -2368,9 +2320,9 @@ namespace OpenSim.Region.Framework.Scenes { ForEachPart(delegate(SceneObjectPart part) { - if (part.OwnerID != userId) + if (part.OwnerID.NotEqual(userId)) { - if(part.GroupID != part.OwnerID) + if(part.GroupID.NotEqual(part.OwnerID)) part.LastOwnerID = part.OwnerID; part.OwnerID = userId; } @@ -2424,7 +2376,7 @@ namespace OpenSim.Region.Framework.Scenes if (parcel is not null && parcel.LandData is not null && parcel.LandData.OtherCleanTime != 0) { - if (parcel.LandData.OwnerID != OwnerID && + if (parcel.LandData.OwnerID.NotEqual(OwnerID) && (parcel.LandData.GroupID.NotEqual(GroupID) || parcel.LandData.GroupID.IsZero())) { @@ -2448,7 +2400,7 @@ namespace OpenSim.Region.Framework.Scenes DetachFromBackup(); m_log.Debug( $"[SCENE OBJECT GROUP]: Returning object {RootPart.UUID} due to parcel autoreturn"); - m_scene.AddReturn(OwnerID == GroupID ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn"); + m_scene.AddReturn(OwnerID.Equals(GroupID) ? LastOwnerID : OwnerID, Name, AbsolutePosition, "parcel autoreturn"); m_scene.DeRezObjects(null, new List() { RootPart.LocalId }, UUID.Zero, DeRezAction.Return, UUID.Zero, false); @@ -2557,7 +2509,7 @@ namespace OpenSim.Region.Framework.Scenes m_dupeInProgress = true; SceneObjectGroup dupe = (SceneObjectGroup)MemberwiseClone(); - dupe.m_parts = new MapAndArray(); + dupe.m_parts = new MapAndArray(); dupe.m_targets = new Dictionary(); dupe.m_rotTargets = new Dictionary(); @@ -2579,7 +2531,7 @@ namespace OpenSim.Region.Framework.Scenes if (userExposed) dupe.m_rootPart.TrimPermissions(); - List partList = new List(m_parts.GetArray()); + List partList = new(m_parts.GetArray()); partList.Sort(delegate(SceneObjectPart p1, SceneObjectPart p2) { @@ -2590,11 +2542,11 @@ namespace OpenSim.Region.Framework.Scenes foreach (SceneObjectPart part in partList) { SceneObjectPart newPart; - if (part.UUID != m_rootPart.UUID) + if (part.UUID.NotEqual(m_rootPart.UUID)) { newPart = dupe.CopyPart(part, OwnerID, GroupID, userExposed); newPart.LinkNum = part.LinkNum; -// if (userExposed) + //if (userExposed) newPart.ParentID = dupe.m_rootPart.LocalId; } else @@ -2638,8 +2590,8 @@ namespace OpenSim.Region.Framework.Scenes public void CopyRootPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) { SceneObjectPart newpart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, 0, userExposed); -// SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed); -// newpart.LocalId = m_scene.AllocateLocalId(); + //SceneObjectPart newpart = part.Copy(part.LocalId, OwnerID, GroupID, 0, userExposed); + //newpart.LocalId = m_scene.AllocateLocalId(); SetRootPart(newpart); if (userExposed) @@ -2650,8 +2602,7 @@ namespace OpenSim.Region.Framework.Scenes { if (usePhysics) { - if (RootPart.KeyframeMotion is not null) - RootPart.KeyframeMotion.Stop(); + RootPart.KeyframeMotion?.Stop(); RootPart.KeyframeMotion = null; } UpdateFlags(usePhysics, IsTemporary, IsPhantom, IsVolumeDetect); @@ -2677,15 +2628,11 @@ namespace OpenSim.Region.Framework.Scenes if (IsAttachment) { ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); - if (avatar is not null) - { - avatar.PushForce(impulse); - } + avatar?.PushForce(impulse); } else { PhysicsActor pa = RootPart.PhysActor; - if (pa is not null) { // false to be applied as a impulse @@ -2698,7 +2645,6 @@ namespace OpenSim.Region.Framework.Scenes public void ApplyAngularImpulse(Vector3 impulse) { PhysicsActor pa = RootPart.PhysActor; - if (pa is not null) { if (!IsAttachment) @@ -2723,14 +2669,12 @@ namespace OpenSim.Region.Framework.Scenes if (IsAttachment) { ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); - if (avatar is not null && !avatar.IsSatOnObject) avatar.MoveToTarget(target, false, true, false, tau); } else { PhysicsActor pa = RootPart.PhysActor; - if (pa is not null) { pa.PIDTarget = target; @@ -2748,16 +2692,11 @@ namespace OpenSim.Region.Framework.Scenes if (IsAttachment) { ScenePresence avatar = m_scene.GetScenePresence(AttachedAvatar); - - if (avatar is not null) - { - avatar.ResetMoveToTarget(); - } + avatar?.ResetMoveToTarget(); } else { PhysicsActor pa = RootPart.PhysActor; - if (pa is not null) pa.PIDActive = false; @@ -2777,7 +2716,7 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart rootpart = m_rootPart; if (rootpart is not null) { -/* physics still doesnt suport this + /* physics still doesnt suport this if (rootpart.PhysActor is not null) { rootpart.PhysActor.APIDTarget = new Quaternion(target.X, target.Y, target.Z, target.W); @@ -2785,7 +2724,7 @@ namespace OpenSim.Region.Framework.Scenes rootpart.PhysActor.APIDDamping = damping; rootpart.PhysActor.APIDActive = true; } -*/ + */ // so do it in rootpart rootpart.RotLookAt(target, strength, damping); } @@ -2800,8 +2739,7 @@ namespace OpenSim.Region.Framework.Scenes if(!UsesPhysics || IsAttachment) return; - if (m_rootPart is not null) - m_rootPart.RotLookAt(target, strength, damping); + m_rootPart?.RotLookAt(target, strength, damping); } public void StopLookAt() @@ -2862,13 +2800,13 @@ namespace OpenSim.Region.Framework.Scenes UUID oldowner = rpart.OwnerID; ForEachPart(delegate(SceneObjectPart part) { - if(part.GroupID != part.OwnerID) + if(part.GroupID.NotEqual(part.OwnerID)) part.LastOwnerID = part.OwnerID; part.OwnerID = cAgentID; part.GroupID = cGroupID; }); - if (oldowner != cAgentID) + if (oldowner.NotEqual(cAgentID)) { // Apply Next Owner Permissions if we're not bypassing permissions if (!m_scene.Permissions.BypassPermissions()) @@ -2890,8 +2828,8 @@ namespace OpenSim.Region.Framework.Scenes public SceneObjectPart CopyPart(SceneObjectPart part, UUID cAgentID, UUID cGroupID, bool userExposed) { SceneObjectPart newPart = part.Copy(m_scene.AllocateLocalId(), OwnerID, GroupID, m_parts.Count, userExposed); -// SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed); -// newPart.LocalId = m_scene.AllocateLocalId(); + //SceneObjectPart newPart = part.Copy(part.LocalId, OwnerID, GroupID, m_parts.Count, userExposed); + //newPart.LocalId = m_scene.AllocateLocalId(); AddPart(newPart); @@ -2910,7 +2848,7 @@ namespace OpenSim.Region.Framework.Scenes { lock (m_parts.SyncRoot) { - List partsList = new List(m_parts.GetArray()); + List partsList = new(m_parts.GetArray()); m_parts.Clear(); foreach (SceneObjectPart part in partsList) { @@ -2927,11 +2865,10 @@ namespace OpenSim.Region.Framework.Scenes public void ServiceObjectPropertiesFamilyRequest(IClientAPI remoteClient, UUID AgentID, uint RequestFlags) { remoteClient.SendObjectPropertiesFamilyData(RootPart, RequestFlags); - -// remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask, -// RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask, -// RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category, -// RootPart.CreatorID, RootPart.Name, RootPart.Description); + //remoteClient.SendObjectPropertiesFamilyData(RequestFlags, RootPart.UUID, RootPart.OwnerID, RootPart.GroupID, RootPart.BaseMask, + // RootPart.OwnerMask, RootPart.GroupMask, RootPart.EveryoneMask, RootPart.NextOwnerMask, + // RootPart.OwnershipCost, RootPart.ObjectSaleType, RootPart.SalePrice, RootPart.Category, + // RootPart.CreatorID, RootPart.Name, RootPart.Description); } public void SetPartOwner(SceneObjectPart part, UUID cAgentID, UUID cGroupID) @@ -2985,8 +2922,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void ScheduleGroupForFullUpdate() { - // if (IsAttachment) - // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); + //if (IsAttachment) + // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); if (Scene.GetNumberOfClients() == 0) return; @@ -3003,13 +2940,12 @@ namespace OpenSim.Region.Framework.Scenes public void ScheduleGroupForFullAnimUpdate() { - // if (IsAttachment) - // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); + //if (IsAttachment) + // m_log.DebugFormat("[SOG]: Scheduling full update for {0} {1}", Name, LocalId); if (Scene.GetNumberOfClients() == 0) return; SceneObjectPart[] parts = m_parts.GetArray(); - if (!RootPart.Shape.MeshFlagEntry) { RootPart.ScheduleFullUpdate(); @@ -3425,9 +3361,9 @@ namespace OpenSim.Region.Framework.Scenes /// The object group of the newly delinked prim. public SceneObjectGroup DelinkFromGroup(SceneObjectPart linkPart, bool sendEvents) { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", -// linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", + // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); if (m_rootPart.PhysActor is not null) m_rootPart.PhysActor.Building = true; @@ -3494,7 +3430,7 @@ namespace OpenSim.Region.Framework.Scenes linkPart.setRotationOffset(worldRot); // Create a new SOG to go around this unlinked and unattached SOP - SceneObjectGroup objectGroup = new SceneObjectGroup(linkPart); + SceneObjectGroup objectGroup = new(linkPart); m_scene.AddNewSceneObject(objectGroup, true); linkPart.Rezzed = RootPart.Rezzed; @@ -3516,9 +3452,9 @@ namespace OpenSim.Region.Framework.Scenes /* working on it public void DelinkFromGroup(List linkParts, bool sendEvents) { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", -// linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Delinking part {0}, {1} from group with root part {2}, {3}", + // linkPart.Name, linkPart.UUID, RootPart.Name, RootPart.UUID); if(PrimCount == 1) return; @@ -3670,8 +3606,7 @@ namespace OpenSim.Region.Framework.Scenes // Compute the SOP's rotation relative to the rotation of the group. parentRot = m_rootPart.RotationOffset; - - oldRot = part.RotationOffset; + Quaternion newRot = Quaternion.Conjugate(parentRot) * worldRot; part.setRotationOffset(newRot); @@ -3683,13 +3618,11 @@ namespace OpenSim.Region.Framework.Scenes // Since this SOP's state has changed, push those changes into the physics engine // and the simulator. // done on caller -// part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false); + //part.UpdatePrimFlags(UsesPhysics, IsTemporary, IsPhantom, IsVolumeDetect, false); } double lastTouchTime = 0; - - /// /// If object is physical, apply force to move it around /// If object is not physical, just put it at the resulting location @@ -3761,7 +3694,6 @@ namespace OpenSim.Region.Framework.Scenes if (m_scene.EventManager.TriggerGroupSpinStart(UUID)) { PhysicsActor pa = m_rootPart.PhysActor; - if (pa is not null) { if (pa.IsPhysical) @@ -3891,39 +3823,25 @@ namespace OpenSim.Region.Framework.Scenes public void SetPartText(string text, uint localID) { SceneObjectPart part = GetPart(localID); - if (part is not null) - { - part.SetText(text); - } + part?.SetText(text); } public void SetPartText(string text, UUID partID) { SceneObjectPart part = GetPart(partID); - if (part is not null) - { - part.SetText(text); - } + part?.SetText(text); } public string GetPartName(uint localID) { SceneObjectPart part = GetPart(localID); - if (part is not null) - { - return part.Name; - } - return String.Empty; + return part is not null ? part.Name : string.Empty; } public string GetPartDescription(uint localID) { SceneObjectPart part = GetPart(localID); - if (part is not null) - { - return part.Description; - } - return String.Empty; + return part is not null ? part.Description : string.Empty; } /// @@ -3960,8 +3878,7 @@ namespace OpenSim.Region.Framework.Scenes if (UsePhysics) { int maxprims = m_scene.m_linksetPhysCapacity; - bool checkShape = (maxprims > 0 && - parts.Length > maxprims); + bool checkShape = maxprims > 0 && parts.Length > maxprims; for (int i = 0; i < parts.Length; i++) { @@ -4011,14 +3928,9 @@ namespace OpenSim.Region.Framework.Scenes public void UpdateExtraParam(uint localID, ushort type, bool inUse, byte[] data) { SceneObjectPart part = GetPart(localID); - if (part is not null) - { - part.UpdateExtraParam(type, inUse, data); - } + part?.UpdateExtraParam(type, inUse, data); } - - /// /// Gets the number of parts /// @@ -4046,9 +3958,9 @@ namespace OpenSim.Region.Framework.Scenes uint lockBit = RootPart.OwnerMask & (uint)(PermissionMask.Move); RootPart.OwnerMask = (RootPart.OwnerMask & lockBit) | ((newOwnerMask | foldedPerms) & lockMask); -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: RootPart.OwnerMask now {0} for {1} in {2}", -// (OpenMetaverse.PermissionMask)RootPart.OwnerMask, Name, Scene.Name); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: RootPart.OwnerMask now {0} for {1} in {2}", + // (OpenMetaverse.PermissionMask)RootPart.OwnerMask, Name, Scene.Name); InvalidateEffectivePerms(); RootPart.ScheduleFullUpdate(); } @@ -4117,8 +4029,8 @@ namespace OpenSim.Region.Framework.Scenes /// public void GroupResize(Vector3 scale) { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, scale); if (Scene is null) return; @@ -4139,9 +4051,9 @@ namespace OpenSim.Region.Framework.Scenes scale.Z = Utils.Clamp(scale.Z, minsize, maxsize); // requested scaling factors - float x = (scale.X / RootPart.Scale.X); - float y = (scale.Y / RootPart.Scale.Y); - float z = (scale.Z / RootPart.Scale.Z); + float x = scale.X / RootPart.Scale.X; + float y = scale.Y / RootPart.Scale.Y; + float z = scale.Z / RootPart.Scale.Z; SceneObjectPart[] parts = m_parts.GetArray(); @@ -4151,60 +4063,58 @@ namespace OpenSim.Region.Framework.Scenes SceneObjectPart obPart = parts[i]; if(obPart.UUID != m_rootPart.UUID) { - Vector3 oldSize = new Vector3(obPart.Scale); - - float f = 1.0f; - float a = 1.0f; + Vector3 oldSize = obPart.Scale; + float f; if(oldSize.X * x > maxsize) { f = maxsize / oldSize.X; - a = f / x; - x *= a; - y *= a; - z *= a; + f /= x; + x *= f; + y *= f; + z *= f; } else if(oldSize.X * x < minsize) { f = minsize / oldSize.X; - a = f / x; - x *= a; - y *= a; - z *= a; + f /= x; + x *= f; + y *= f; + z *= f; } if(oldSize.Y * y > maxsize) { f = maxsize / oldSize.Y; - a = f / y; - x *= a; - y *= a; - z *= a; + f /= y; + x *= f; + y *= f; + z *= f; } else if(oldSize.Y * y < minsize) { f = minsize / oldSize.Y; - a = f / y; - x *= a; - y *= a; - z *= a; + f /= y; + x *= f; + y *= f; + z *= f; } if(oldSize.Z * z > maxsize) { f = maxsize / oldSize.Z; - a = f / z; - x *= a; - y *= a; - z *= a; + f /= z; + x *= f; + y *= f; + z *= f; } else if(oldSize.Z * z < minsize) { f = minsize / oldSize.Z; - a = f / z; - x *= a; - y *= a; - z *= a; + f /= z; + x *= f; + y *= f; + z *= f; } } } @@ -4220,14 +4130,14 @@ namespace OpenSim.Region.Framework.Scenes { SceneObjectPart obPart = parts[i]; - if (obPart.UUID != m_rootPart.UUID) + if (obPart.UUID.NotEqual(m_rootPart.UUID)) { - Vector3 currentpos = new Vector3(obPart.OffsetPosition); + Vector3 currentpos = obPart.OffsetPosition; currentpos.X *= x; currentpos.Y *= y; currentpos.Z *= z; - Vector3 newSize = new Vector3(obPart.Scale); + Vector3 newSize = obPart.Scale; newSize.X *= x; newSize.Y *= y; newSize.Z *= z; @@ -4246,8 +4156,8 @@ namespace OpenSim.Region.Framework.Scenes public bool GroupResize(double fscale) { -// m_log.DebugFormat( -// "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, fscale); + //m_log.DebugFormat( + // "[SCENE OBJECT GROUP]: Group resizing {0} {1} from {2} to {3}", Name, LocalId, RootPart.Scale, fscale); if (Scene is null || IsDeleted || inTransit || fscale < 0) return false; @@ -4255,8 +4165,7 @@ namespace OpenSim.Region.Framework.Scenes // ignore lsl restrictions. let them be done a LSL PhysicsActor pa = m_rootPart.PhysActor; - if(RootPart.KeyframeMotion is not null) - RootPart.KeyframeMotion.Suspend(); + RootPart.KeyframeMotion?.Suspend(); float minsize = Scene.m_minNonphys; float maxsize = Scene.m_maxNonphys; @@ -4274,7 +4183,7 @@ namespace OpenSim.Region.Framework.Scenes for(int i = 0; i < parts.Length; i++) { SceneObjectPart obPart = parts[i]; - Vector3 oldSize = new Vector3(obPart.Scale); + Vector3 oldSize = obPart.Scale; tmp = (float)(oldSize.X * fscale); if(tmp > maxsize) return false; @@ -4335,8 +4244,7 @@ namespace OpenSim.Region.Framework.Scenes m_rootPart.TriggerScriptChangedEvent(Changed.SCALE); ScheduleGroupForFullUpdate(); - if(RootPart.KeyframeMotion is not null) - RootPart.KeyframeMotion.Resume(); + RootPart.KeyframeMotion?.Resume(); return true; } @@ -4358,7 +4266,7 @@ namespace OpenSim.Region.Framework.Scenes for(int i = 0; i < parts.Length; i++) { SceneObjectPart obPart = parts[i]; - Vector3 oldSize = new Vector3(obPart.Scale); + Vector3 oldSize = obPart.Scale; if(larger < oldSize.X) larger = oldSize.X; @@ -4395,7 +4303,7 @@ namespace OpenSim.Region.Framework.Scenes for(int i = 0; i < parts.Length; i++) { SceneObjectPart obPart = parts[i]; - Vector3 oldSize = new Vector3(obPart.Scale); + Vector3 oldSize = obPart.Scale; if(smaller > oldSize.X) smaller = oldSize.X; @@ -4472,7 +4380,7 @@ namespace OpenSim.Region.Framework.Scenes if (part is not null) { -// unlock parts position change + // unlock parts position change if (m_rootPart.PhysActor is not null) m_rootPart.PhysActor.Building = true; @@ -4546,14 +4454,14 @@ namespace OpenSim.Region.Framework.Scenes { m_rootPart.UpdateRotation(rot); -/* this is done by rootpart RotationOffset set called by UpdateRotation + /* this is done by rootpart RotationOffset set called by UpdateRotation PhysicsActor actor = m_rootPart.PhysActor; if (actor is not null) { actor.Orientation = m_rootPart.RotationOffset; m_scene.PhysicsScene.AddPhysicsActorTaint(actor); } -*/ + */ HasGroupChanged = true; ScheduleGroupForTerseUpdate(); } @@ -4593,9 +4501,6 @@ namespace OpenSim.Region.Framework.Scenes public void UpdateSingleRotation(Quaternion rot, uint localID) { SceneObjectPart part = GetPart(localID); - - SceneObjectPart[] parts = m_parts.GetArray(); - if (part is not null) { if (m_rootPart.PhysActor is not null) @@ -4658,7 +4563,6 @@ namespace OpenSim.Region.Framework.Scenes m_rootPart.RotationOffset = rot; PhysicsActor pa = m_rootPart.PhysActor; - if (pa is not null) { pa.Orientation = m_rootPart.RotationOffset; @@ -4873,7 +4777,7 @@ namespace OpenSim.Region.Framework.Scenes public int RegisterRotTargetWaypoint(UUID scriptID, Quaternion target, float tolerance) { int handle = m_scene.AllocateIntId(); - scriptRotTarget waypoint = new scriptRotTarget() + scriptRotTarget waypoint = new() { targetRot = target, tolerance = tolerance, @@ -4925,7 +4829,7 @@ namespace OpenSim.Region.Framework.Scenes public int RegisterTargetWaypoint(UUID scriptID, Vector3 target, float tolerance) { int handle = m_scene.AllocateIntId(); - scriptPosTarget waypoint = new scriptPosTarget() + scriptPosTarget waypoint = new() { targetPos = target, tolerance = tolerance * tolerance, @@ -5000,8 +4904,8 @@ namespace OpenSim.Region.Framework.Scenes int targetsCount = m_targets.Count; if (targetsCount > 0 && (m_scriptListens_atTarget || m_scriptListens_notAtTarget)) { - List atTargets = new List(); - HashSet notatTargets = new HashSet(); + List atTargets = new(); + HashSet notatTargets = new(); Vector3 pos = m_rootPart.GroupPosition; lock (m_targets) { @@ -5042,8 +4946,8 @@ namespace OpenSim.Region.Framework.Scenes targetsCount = m_rotTargets.Count; if (targetsCount > 0 && (m_scriptListens_atRotTarget || m_scriptListens_notAtRotTarget)) { - List atRotTargets = new List(targetsCount); - HashSet notatRotTargets = new HashSet(); + List atRotTargets = new(targetsCount); + HashSet notatRotTargets = new(); Quaternion rot = m_rootPart.RotationOffset; lock (m_targets) { @@ -5097,17 +5001,16 @@ namespace OpenSim.Region.Framework.Scenes Vector3 gc = Vector3.Zero; SceneObjectPart[] parts = m_parts.GetArray(); - int nparts = parts.Length; - if (nparts < 2) + if (parts.Length < 2) return gc; // average all parts positions - for (int i = 0; i < nparts; i++) + for (int i = 0; i < parts.Length; i++) { if (parts[i] != RootPart) gc += parts[i].OffsetPosition; } - gc /= nparts; + gc /= parts.Length; return gc; } @@ -5182,7 +5085,7 @@ namespace OpenSim.Region.Framework.Scenes public void SetInertiaData(float TotalMass, Vector3 CenterOfMass, Vector3 Inertia, Vector4 aux ) { - PhysicsInertiaData inertiaData = new PhysicsInertiaData() + PhysicsInertiaData inertiaData = new() { TotalMass = TotalMass, CenterOfMass = CenterOfMass, @@ -5196,8 +5099,7 @@ namespace OpenSim.Region.Framework.Scenes RootPart.PhysicsInertia = inertiaData; PhysicsActor pa = RootPart.PhysActor; - if(pa !=null) - pa.SetInertiaData(inertiaData); + pa?.SetInertiaData(inertiaData); } /// @@ -5256,20 +5158,18 @@ namespace OpenSim.Region.Framework.Scenes // get all the scripts in all parts SceneObjectPart[] parts = m_parts.GetArray(); - List scripts = new List(); + List scripts = new(); for (int i = 0; i < parts.Length; i++) { scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL)); } // extract the UUIDs - List ids = new List(scripts.Count); + HashSet unique = new(); foreach (TaskInventoryItem script in scripts) - { - if (!ids.Contains(script.ItemID)) - { - ids.Add(script.ItemID); - } - } + unique.Add(script.ItemID); + + List ids = unique.ToList(); + // Offer the list of script UUIDs to each engine found and accumulate the time foreach (IScriptModule e in engines) { @@ -5290,7 +5190,7 @@ namespace OpenSim.Region.Framework.Scenes // get all the scripts in all parts SceneObjectPart[] parts = m_parts.GetArray(); - List scripts = new List(); + List scripts = new(); for (int i = 0; i < parts.Length; i++) { scripts.AddRange(parts[i].Inventory.GetInventoryItems(InventoryType.LSL)); @@ -5300,14 +5200,11 @@ namespace OpenSim.Region.Framework.Scenes return false; // extract the UUIDs - List ids = new List(scripts.Count); + HashSet unique = new(); foreach (TaskInventoryItem script in scripts) - { - if (!ids.Contains(script.ItemID)) - { - ids.Add(script.ItemID); - } - } + unique.Add(script.ItemID); + + List ids = unique.ToList(); // Offer the list of script UUIDs to each engine found and accumulate the memory foreach (IScriptModule e in engines) { @@ -5353,7 +5250,7 @@ namespace OpenSim.Region.Framework.Scenes { for(int i = 0; i < m_sittingAvatars.Count; ++i) { - if(m_sittingAvatars[i].UUID == avatarID) + if(m_sittingAvatars[i].UUID.Equals(avatarID)) return true; } } @@ -5397,11 +5294,32 @@ namespace OpenSim.Region.Framework.Scenes public virtual void ExtraFromXmlString(string xmlstr) { - string id = xmlstr.Substring(xmlstr.IndexOf("")); - id = xmlstr.Replace("", ""); - id = id.Replace("", ""); + if (string.IsNullOrEmpty(xmlstr)) + { + FromItemID = UUID.Zero; + return; + } + + int indx = xmlstr.IndexOf(""); + if (indx < 0) + { + FromItemID = UUID.Zero; + return; + } + indx += 17; + if(indx >= xmlstr.Length) + { + FromItemID = UUID.Zero; + return; + } + + int indx2 = xmlstr.IndexOf("", indx); + UUID uuid; + if (indx2 < 0) + _ = UUID.TryParse(xmlstr.AsSpan()[indx..], out uuid); + else + _ = UUID.TryParse(xmlstr.AsSpan()[indx..indx2], out uuid); - UUID.TryParse(id, out UUID uuid); FromItemID = uuid; } @@ -5414,13 +5332,13 @@ namespace OpenSim.Region.Framework.Scenes InvalidateEffectivePerms(); } - private Dictionary m_partsNameToLinkMap = new Dictionary(); + private readonly Dictionary m_partsNameToLinkMap = new(); private string GetLinkNumber_lastname; private int GetLinkNumber_lastnumber; public int GetLinkNumber(string name) { - if(String.IsNullOrEmpty(name) || name == "Object" || name == "Primitive") + if(string.IsNullOrEmpty(name) || name == "Object" || name == "Primitive") return -1; lock(m_partsNameToLinkMap) @@ -5430,14 +5348,14 @@ namespace OpenSim.Region.Framework.Scenes if (m_partsNameToLinkMap.Count == 0) { - GetLinkNumber_lastname = String.Empty; + GetLinkNumber_lastname = string.Empty; GetLinkNumber_lastnumber = -1; SceneObjectPart[] parts = m_parts.GetArray(); for (int i = 0; i < parts.Length; i++) { string s = parts[i].Name; - if(String.IsNullOrEmpty(s) || s == "Object" || s == "Primitive") + if(string.IsNullOrEmpty(s) || s == "Object" || s == "Primitive") continue; if(m_partsNameToLinkMap.ContainsKey(s)) @@ -5484,7 +5402,7 @@ namespace OpenSim.Region.Framework.Scenes { if(all) m_partsNameToLinkMap.Clear(); - GetLinkNumber_lastname = String.Empty; + GetLinkNumber_lastname = string.Empty; GetLinkNumber_lastnumber = -1; } } @@ -5492,8 +5410,8 @@ namespace OpenSim.Region.Framework.Scenes public bool CollisionSoundThrottled(int collisionSoundType) { double time = m_lastCollisionSoundMS; -// m_lastCollisionSoundMS = Util.GetTimeStampMS(); -// time = m_lastCollisionSoundMS - time; + //m_lastCollisionSoundMS = Util.GetTimeStampMS(); + //time = m_lastCollisionSoundMS - time; double now = Util.GetTimeStampMS(); time = now - time; switch (collisionSoundType) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs index 528f6fa5a9..605663c24b 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs @@ -2201,7 +2201,7 @@ namespace OpenSim.Region.Framework.Scenes dupe.LocalId = plocalID; // This may be wrong... it might have to be applied in SceneObjectGroup to the object that's being duplicated. - if(OwnerID != GroupID) + if(OwnerID.NotEqual(GroupID)) dupe.LastOwnerID = OwnerID; else dupe.LastOwnerID = LastOwnerID; // redundant ? @@ -5366,9 +5366,9 @@ namespace OpenSim.Region.Framework.Scenes GroupMask = 0; // DO NOT propagate here } - if (OwnerID != item.Owner) + if (OwnerID.NotEqual(item.Owner)) { - if(OwnerID != GroupID) + if(OwnerID.NotEqual(GroupID)) LastOwnerID = OwnerID; OwnerID = item.Owner; Inventory.ChangeInventoryOwner(item.Owner); diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 947028beab..c0dad7ac42 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -1199,9 +1199,9 @@ namespace OpenSim.Region.Framework.Scenes foreach (SceneObjectPart part in partList) { - if ((part.OwnerID != NewOwner)) + if ((part.OwnerID.NotEqual(NewOwner))) { - if(part.GroupID != part.OwnerID) + if(part.GroupID.NotEqual(part.OwnerID)) part.LastOwnerID = part.OwnerID; part.OwnerID = NewOwner; part.Inventory.ChangeInventoryOwner(NewOwner);