diff --git a/OpenSim/Addons/Groups/GroupsModule.cs b/OpenSim/Addons/Groups/GroupsModule.cs index 9e42c22f70..cfca4e6003 100755 --- a/OpenSim/Addons/Groups/GroupsModule.cs +++ b/OpenSim/Addons/Groups/GroupsModule.cs @@ -1575,17 +1575,12 @@ namespace OpenSim.Groups private string GetRequestingAgentIDStr(IClientAPI client) { - return GetRequestingAgentID(client).ToString(); + return client is null ? UUID.ZeroString : client.AgentId.ToString(); } private UUID GetRequestingAgentID(IClientAPI client) { - UUID requestingAgentID = UUID.Zero; - if (client != null) - { - requestingAgentID = client.AgentId; - } - return requestingAgentID; + return client is null ? UUID.Zero : client.AgentId; } } diff --git a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs index bc0bf3c30f..735f44e333 100755 --- a/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/Attachments/AttachmentsModule.cs @@ -127,10 +127,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments } m_regionConsole = scene.RequestModuleInterface(); - if (m_regionConsole is not null) - { - m_regionConsole.AddCommand("AttachModule", false, "set auto_grant_attach_perms", "set auto_grant_attach_perms true|false", "Allow objects owned by the region owner or estate managers to obtain attach permissions without asking the user", HandleSetAutoGrantAttachPerms); - } + m_regionConsole?.AddCommand("AttachModule", false, "set auto_grant_attach_perms", "set auto_grant_attach_perms true|false", "Allow objects owned by the region owner or estate managers to obtain attach permissions without asking the user", HandleSetAutoGrantAttachPerms); scene.AddCommand( "Debug", @@ -208,7 +205,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments optionalTargetLastName = cmd[3]; } - StringBuilder sb = new StringBuilder(); + StringBuilder sb = new(); sm.ForEachSelectedScene( scene => { @@ -269,7 +266,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private void HandleSetAutoGrantAttachPerms(string module, string[] parms) { - UUID agentID = new(parms[parms.Length - 1]); + UUID agentID = new(parms[^1]); Array.Resize(ref parms, parms.Length - 1); if (parms.Length != 3) @@ -496,7 +493,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments for (int indx = 0; indx < attachments.Count; ++indx) { InventoryItemBase attItem = attItems[indx]; - if (attItem is null || attItem.Owner != sp.UUID) + if (attItem is null || attItem.Owner.NotEqual(sp.UUID)) continue; AvatarAttachment attach = attachments[indx]; uint attachmentPt = (uint)attach.AttachPoint; @@ -802,7 +799,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments public void DetachSingleAttachmentToGround(IScenePresence sp, uint soLocalId) { - Vector3 pos = new Vector3(2.5f, 0f, 0f); + Vector3 pos = new(2.5f, 0f, 0f); pos *= ((ScenePresence)sp).Rotation; pos += sp.AbsolutePosition; DetachSingleAttachmentToGround(sp, soLocalId, pos, Quaternion.Identity); @@ -1400,9 +1397,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private ISceneEntity Client_OnRezSingleAttachmentFromInv(IClientAPI remoteClient, UUID itemID, uint AttachmentPt) { - if (!Enabled) - return null; - if (DebugLevel > 0) m_log.Debug( $"[ATTACHMENTS MODULE]: Rezzing attachment to point {(AttachmentPoint)AttachmentPt} from item {itemID} for {remoteClient.Name}"); @@ -1419,9 +1413,6 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments private void Client_OnRezMultipleAttachmentsFromInv(IClientAPI remoteClient, List> rezlist) { - if (!Enabled) - return; - if (remoteClient.SceneAgent is ScenePresence sp) RezMultipleAttachmentsFromInventory(sp, rezlist); else @@ -1503,7 +1494,7 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments List attachments = sp.GetAttachments(); foreach (SceneObjectGroup group in attachments) { - if (group.FromItemID.Equals(itemID) && !group.FromItemID.IsZero()) + if (group.FromItemID.Equals(itemID) && group.FromItemID.IsNotZero()) { DetachSingleAttachmentToInv(sp, group); return; diff --git a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs index e0143e02b3..134eeafea7 100755 --- a/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs +++ b/OpenSim/Region/CoreModules/World/Land/LandManagementModule.cs @@ -26,7 +26,6 @@ */ using System; -using System.Collections; using System.Collections.Generic; using System.Net; using System.Reflection; @@ -68,10 +67,6 @@ namespace OpenSim.Region.CoreModules.World.Land { private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - /// - /// Minimum land unit size in region co-ordinates. - /// - private Scene m_scene; //private LandChannel m_landChannel; @@ -93,9 +88,9 @@ namespace OpenSim.Region.CoreModules.World.Land /// Land objects keyed by local id /// - private readonly Dictionary m_landList = new Dictionary(); - private readonly Dictionary m_landGlobalIDs = new Dictionary(); - private readonly Dictionary m_landFakeIDs = new Dictionary(); + private readonly Dictionary m_landList = new(); + private readonly Dictionary m_landGlobalIDs = new(); + private readonly Dictionary m_landFakeIDs = new(); private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1; @@ -106,13 +101,12 @@ namespace OpenSim.Region.CoreModules.World.Land private UUID DefaultGodParcelOwner; // caches ExtendedLandData - static private readonly ExpiringCacheOS m_parcelInfoCache = new ExpiringCacheOS(10000); + static private readonly ExpiringCacheOS m_parcelInfoCache = new(10000); /// /// Record positions that avatar's are currently being forced to move to due to parcel entry restrictions. /// - private HashSet forcedPosition = new HashSet(); - + private readonly HashSet forcedPosition = new(); // Enables limiting parcel layer info transmission when doing simple updates private bool shouldLimitParcelLayerInfoToViewDistance { get; set; } @@ -144,7 +138,7 @@ namespace OpenSim.Region.CoreModules.World.Land shouldLimitParcelLayerInfoToViewDistance = true; parcelLayerViewDistance = 128; IConfig landManagementConfig = source.Configs["LandManagement"]; - if (landManagementConfig != null) + if (landManagementConfig is not null) { shouldLimitParcelLayerInfoToViewDistance = landManagementConfig.GetBoolean("LimitParcelLayerUpdateDistance", shouldLimitParcelLayerInfoToViewDistance); parcelLayerViewDistance = landManagementConfig.GetInt("ParcelLayerViewDistance", parcelLayerViewDistance); @@ -203,12 +197,14 @@ namespace OpenSim.Region.CoreModules.World.Land // TODO: Release event manager listeners here } -// private bool OnVerifyUserConnection(ScenePresence scenePresence, out string reason) -// { -// ILandObject nearestParcel = m_scene.GetNearestAllowedParcel(scenePresence.UUID, scenePresence.AbsolutePosition.X, scenePresence.AbsolutePosition.Y); -// reason = "You are not allowed to enter this sim."; -// return nearestParcel != null; -// } + /* + private bool OnVerifyUserConnection(ScenePresence scenePresence, out string reason) + { + ILandObject nearestParcel = m_scene.GetNearestAllowedParcel(scenePresence.UUID, scenePresence.AbsolutePosition.X, scenePresence.AbsolutePosition.Y); + "You are not allowed to enter this sim."; + return nearestParcel != null; + } + */ void EventManagerOnNewClient(IClientAPI client) { @@ -267,16 +263,16 @@ namespace OpenSim.Region.CoreModules.World.Land if (m_landList.TryGetValue(local_id, out land)) { m_landGlobalIDs.Remove(land.LandData.GlobalID); - if (!land.LandData.FakeID.IsZero()) + if (land.LandData.FakeID.IsNotZero()) m_landFakeIDs.Remove(land.LandData.FakeID); land.LandData = newData; m_landGlobalIDs[newData.GlobalID] = local_id; - if (!newData.FakeID.IsZero()) + if (newData.FakeID.IsNotZero()) m_landFakeIDs[newData.FakeID] = local_id; } } - if (land != null) + if (land is not null) m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land); } @@ -340,13 +336,13 @@ namespace OpenSim.Region.CoreModules.World.Land public List ParcelsNearPoint(Vector3 position) { - List parcelsNear = new List(); + List parcelsNear = new(); for (int x = -8; x <= 8; x += 4) { for (int y = -8; y <= 8; y += 4) { ILandObject check = GetLandObject(position.X + x, position.Y + y); - if (check != null) + if (check is not null) { if (!parcelsNear.Contains(check)) { @@ -415,7 +411,7 @@ namespace OpenSim.Region.CoreModules.World.Land (int) avatar.lastKnownAllowedPosition.Y)) { Vector3? pos = m_scene.GetNearestAllowedPosition(avatar); - if (pos == null) + if (pos is null) { forcedPosition.Remove(avatar.UUID); m_scene.TeleportClientHome(avatar.UUID, avatar.ControllingClient); @@ -464,7 +460,7 @@ namespace OpenSim.Region.CoreModules.World.Land parcelAvatarIsEntering = m_landList[localLandID]; } - if (parcelAvatarIsEntering != null && + if (parcelAvatarIsEntering is not null && avatar.currentParcelUUID.NotEqual(parcelAvatarIsEntering.LandData.GlobalID)) { SendLandUpdate(avatar, parcelAvatarIsEntering); @@ -477,7 +473,7 @@ namespace OpenSim.Region.CoreModules.World.Land public void SendOutNearestBanLine(IClientAPI client) { ScenePresence sp = m_scene.GetScenePresence(client.AgentId); - if (sp == null || sp.IsDeleted) + if (sp is null || sp.IsDeleted) return; List checkLandParcels = ParcelsNearPoint(sp.AbsolutePosition); @@ -499,15 +495,13 @@ namespace OpenSim.Region.CoreModules.World.Land public void sendClientInitialLandInfo(IClientAPI remoteClient, bool overlay) { - ScenePresence avatar; - - if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out avatar)) + if (!m_scene.TryGetScenePresence(remoteClient.AgentId, out ScenePresence avatar)) return; if (!avatar.IsChildAgent) { ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); - if (over == null) + if (over is null) return; avatar.currentParcelUUID = over.LandData.GlobalID; @@ -522,11 +516,11 @@ namespace OpenSim.Region.CoreModules.World.Land if (avatar.IsChildAgent) return; - if (over != null) + if (over is not null) { - over.SendLandUpdateToClient(avatar.ControllingClient); -// sl doesnt seem to send this now, as it used 2 -// SendParcelOverlay(avatar.ControllingClient); + over.SendLandUpdateToClient(avatar.ControllingClient); + // sl doesnt seem to send this now, as it used 2 + //SendParcelOverlay(avatar.ControllingClient); } } @@ -550,12 +544,12 @@ namespace OpenSim.Region.CoreModules.World.Land Vector3 pos = avatar.AbsolutePosition; ILandObject over = GetLandObject(pos.X, pos.Y); - if (over != null) + if (over is not null) { EnforceBans(over, avatar); pos = avatar.AbsolutePosition; ILandObject newover = GetLandObject(pos.X, pos.Y); - if(over != newover || avatar.currentParcelUUID != newover.LandData.GlobalID) + if(over != newover || avatar.currentParcelUUID.NotEqual(newover.LandData.GlobalID)) { m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, newover.LandData.LocalID, m_scene.RegionInfo.RegionID); @@ -571,18 +565,17 @@ namespace OpenSim.Region.CoreModules.World.Land m_landList.TryGetValue(landLocalID, out land); } // trivial checks - if(land == null) + if(land is null) return; LandData ldata = land.LandData; - - if(ldata == null) + if(ldata is null) return; - if(ldata.OwnerID.Equals(targetID)) + if (ldata.PassHours == 0) return; - if(ldata.PassHours == 0) + if (ldata.OwnerID.Equals(targetID)) return; if (m_scene.RegionInfo.EstateSettings.TaxFree) @@ -633,15 +626,17 @@ namespace OpenSim.Region.CoreModules.World.Land return; } } - - LandAccessEntry entry = new LandAccessEntry(); - entry.AgentID = targetID; - entry.Flags = AccessList.Access; - entry.Expires = now + expires; - if(currenttime > 0) + + LandAccessEntry entry = new() + { + AgentID = targetID, + Flags = AccessList.Access, + Expires = now + expires + }; + if (currenttime > 0) entry.Expires += currenttime; IMoneyModule mm = m_scene.RequestModuleInterface(); - if(cost != 0 && mm != null) + if(cost != 0 && mm is not null) { WorkManager.RunInThreadPool( delegate @@ -686,11 +681,7 @@ namespace OpenSim.Region.CoreModules.World.Land { m_landList.TryGetValue(landLocalID, out land); } - - if (land != null) - { - land.SendAccessList(agentID, sessionID, flags, sequenceID, remote_client); - } + land?.SendAccessList(agentID, sessionID, flags, sequenceID, remote_client); } public void ClientOnParcelAccessListUpdateRequest(UUID agentID, @@ -709,7 +700,7 @@ namespace OpenSim.Region.CoreModules.World.Land m_landList.TryGetValue(landLocalID, out land); } - if (land != null) + if (land is not null) { GroupPowers requiredPowers = GroupPowers.None; if ((flags & (uint)AccessList.Access) != 0) @@ -743,7 +734,7 @@ namespace OpenSim.Region.CoreModules.World.Land { // Only now can we add the prim counts to the land object - we rely on the global ID which is generated // as a random UUID inside LandData initialization - if (m_primCountModule != null) + if (m_primCountModule is not null) new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID); lock (m_landList) @@ -842,7 +833,7 @@ namespace OpenSim.Region.CoreModules.World.Land land = m_landList[local_id]; m_landList.Remove(local_id); - if(land != null && land.LandData != null) + if(land is not null && land.LandData is not null) { landGlobalID = land.LandData.GlobalID; m_landGlobalIDs.Remove(landGlobalID); @@ -850,7 +841,7 @@ namespace OpenSim.Region.CoreModules.World.Land } } - if(!landGlobalID.IsZero()) + if(landGlobalID.IsNotZero()) { m_scene.EventManager.TriggerLandObjectRemoved(landGlobalID); land.Clear(); @@ -862,7 +853,7 @@ namespace OpenSim.Region.CoreModules.World.Land /// public void Clear(bool setupDefaultParcel) { - List landworkList = new List(m_landList.Count); + List landworkList = new(m_landList.Count); // move to work pointer since we are deleting it all lock (m_landList) { @@ -906,19 +897,17 @@ namespace OpenSim.Region.CoreModules.World.Land UpdateLandObject(master.LandData.LocalID, master.LandData); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(UUID globalID) { lock (m_landList) { - int lid = -1; - if (m_landGlobalIDs.TryGetValue(globalID, out lid) && lid >= 0) + if (m_landGlobalIDs.TryGetValue(globalID, out int lid)) { - if (m_landList.ContainsKey(lid)) - { - return m_landList[lid]; - } + if (m_landList.TryGetValue(lid, out ILandObject land)) + return land; else - m_landGlobalIDs.Remove(globalID); // auto heal + m_landGlobalIDs.Remove(globalID); } } return null; @@ -928,15 +917,12 @@ namespace OpenSim.Region.CoreModules.World.Land { lock (m_landList) { - int lid = -1; - if (m_landFakeIDs.TryGetValue(fakeID, out lid) && lid >= 0) + if (m_landFakeIDs.TryGetValue(fakeID, out int lid)) { - if (m_landList.ContainsKey(lid)) - { - return m_landList[lid]; - } + if (m_landList.TryGetValue(lid, out ILandObject land)) + return land; else - m_landFakeIDs.Remove(fakeID); // auto heal + m_landFakeIDs.Remove(fakeID); } } if(Util.ParseFakeParcelID(fakeID, out ulong rhandle, out uint x, out uint y) && rhandle == m_regionHandler) @@ -946,16 +932,13 @@ namespace OpenSim.Region.CoreModules.World.Land return null; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(int parcelLocalID) { lock (m_landList) { - if (m_landList.ContainsKey(parcelLocalID)) - { - return m_landList[parcelLocalID]; - } + return m_landList.TryGetValue(parcelLocalID, out ILandObject land) ? land : null; } - return null; } /// @@ -964,11 +947,13 @@ namespace OpenSim.Region.CoreModules.World.Land /// Value between 0 - 256 on the x axis of the point /// Value between 0 - 256 on the y axis of the point /// Land object at the point supplied + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(float x_float, float y_float) { return GetLandObject((int)x_float, (int)y_float, true); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObject(Vector3 position) { return GetLandObject(position.X, position.Y); @@ -979,13 +964,13 @@ namespace OpenSim.Region.CoreModules.World.Land public ILandObject GetLandObjectClippedXY(float x, float y) { //do clip inline - int avx = (int)(Math.Round(x)); + int avx = (int)MathF.Round(x); if (avx < 0) avx = 0; else if (avx >= m_regionSizeX) avx = m_regionSizeX - 1; - int avy = (int)(Math.Round(y)); + int avy = (int)MathF.Round(y); if (avy < 0) avy = 0; else if (avy >= m_regionSizeY) @@ -1025,7 +1010,7 @@ namespace OpenSim.Region.CoreModules.World.Land throw new Exception("Error: Parcel not found at point " + x + ", " + y); } - if(m_landList.Count == 0 || m_landIDList == null) + if(m_landList.Count == 0 || m_landIDList is null) return null; lock (m_landIDList) @@ -1044,7 +1029,7 @@ namespace OpenSim.Region.CoreModules.World.Land [MethodImpl(MethodImplOptions.AggressiveInlining)] public ILandObject GetLandObjectinLandUnits(int x, int y) { - if (m_landList.Count == 0 || m_landIDList == null) + if (m_landList.Count == 0 || m_landIDList is null) return null; lock (m_landIDList) @@ -1124,7 +1109,7 @@ namespace OpenSim.Region.CoreModules.World.Land { Vector3 position = obj.AbsolutePosition; ILandObject landUnderPrim = GetLandObject(position.X, position.Y); - if (landUnderPrim != null) + if (landUnderPrim is not null) { ((LandObject)landUnderPrim).AddPrimOverMe(obj); } @@ -1144,20 +1129,19 @@ namespace OpenSim.Region.CoreModules.World.Land private void FinalizeLandPrimCountUpdate() { //Get Simwide prim count for owner - Dictionary> landOwnersAndParcels = new Dictionary>(); + Dictionary> landOwnersAndParcels = new(); lock (m_landList) { foreach (LandObject p in m_landList.Values) { - if (!landOwnersAndParcels.ContainsKey(p.LandData.OwnerID)) + if (!landOwnersAndParcels.TryGetValue(p.LandData.OwnerID, out List ownerlist)) { - List tempList = new List(); - tempList.Add(p); - landOwnersAndParcels.Add(p.LandData.OwnerID, tempList); + ownerlist = new(){ p }; + landOwnersAndParcels.Add(p.LandData.OwnerID, ownerlist); } else { - landOwnersAndParcels[p.LandData.OwnerID].Add(p); + ownerlist.Add(p); } } } @@ -1190,12 +1174,9 @@ namespace OpenSim.Region.CoreModules.World.Land EntityBase[] entities = m_scene.Entities.GetEntities(); foreach (EntityBase obj in entities) { - if (obj != null) + if (obj is SceneObjectGroup sog && !sog.IsDeleted && !sog.IsAttachment) { - if ((obj is SceneObjectGroup) && !obj.IsDeleted && !((SceneObjectGroup) obj).IsAttachment) - { - m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj); - } + m_scene.EventManager.TriggerParcelPrimCountAdd(sog); } } FinalizeLandPrimCountUpdate(); @@ -1223,14 +1204,11 @@ namespace OpenSim.Region.CoreModules.World.Land //Get the land object at start ILandObject startLandObject = GetLandObject(start_x, start_y); - - if (startLandObject == null) + if (startLandObject is null) return; if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin, true)) - { return; - } //Loop through the points int area = 0; @@ -1241,7 +1219,7 @@ namespace OpenSim.Region.CoreModules.World.Land for (int x = start_x; x < end_x; x++) { ILandObject tempLandObject = GetLandObject(x, y); - if (tempLandObject == null) + if (tempLandObject is null) return; if (tempLandObject != startLandObject) return; @@ -1324,14 +1302,13 @@ namespace OpenSim.Region.CoreModules.World.Land int maxindex = -1; int maxArea = 0; - List selectedLandObjects = new List(); + List selectedLandObjects = new(); for (int x = start_x; x < end_x; x += 4) { for (int y = start_y; y < end_y; y += 4) { ILandObject p = GetLandObject(x, y); - - if (p != null) + if (p is not null) { if (!selectedLandObjects.Contains(p)) { @@ -1361,7 +1338,7 @@ namespace OpenSim.Region.CoreModules.World.Land UUID masterOwner = masterLandObject.LandData.OwnerID; foreach (ILandObject p in selectedLandObjects) { - if (p.LandData.OwnerID != masterOwner) + if (p.LandData.OwnerID.NotEqual(masterOwner)) return; } @@ -1421,11 +1398,11 @@ namespace OpenSim.Region.CoreModules.World.Land continue; ILandObject currentParcel = GetLandObject(curID); - if (currentParcel == null) + if (currentParcel is null) continue; LandData currentParcelLandData = currentParcel.LandData; - if (currentParcelLandData == null) + if (currentParcelLandData is null) continue; // types @@ -1545,7 +1522,7 @@ namespace OpenSim.Region.CoreModules.World.Land public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id, bool snap_selection, IClientAPI remote_client) { - if (m_landList.Count == 0 || m_landIDList == null) + if (m_landList.Count == 0 || m_landIDList is null) return; if (start_x < 0 || start_y < 0 || end_x < 0 || end_y < 0) @@ -1557,8 +1534,7 @@ namespace OpenSim.Region.CoreModules.World.Land end_y - start_y <= Constants.LandUnit) { ILandObject parcel = GetLandObject(start_x, start_y); - if(parcel != null) - parcel.SendLandProperties(sequence_id, snap_selection, LandChannel.LAND_RESULT_SINGLE, remote_client); + parcel?.SendLandProperties(sequence_id, snap_selection, LandChannel.LAND_RESULT_SINGLE, remote_client); return; } @@ -1568,14 +1544,13 @@ namespace OpenSim.Region.CoreModules.World.Land end_y /= Constants.LandUnit; //Get the land objects within the bounds - Dictionary temp = new Dictionary(); + Dictionary temp = new(); for (int x = start_x; x < end_x; ++x) { for (int y = start_y; y < end_y; ++y) { ILandObject currentParcel = GetLandObjectinLandUnits(x, y); - - if (currentParcel != null) + if (currentParcel is not null) { if (!temp.ContainsKey(currentParcel.LandData.LocalID)) { @@ -1595,17 +1570,15 @@ namespace OpenSim.Region.CoreModules.World.Land lo.SendLandProperties(sequence_id, snap_selection, requestResult, remote_client); } -// SendParcelOverlay(remote_client); + //SendParcelOverlay(remote_client); } public void UpdateLandProperties(ILandObject land, LandUpdateArgs args, IClientAPI remote_client) { - bool snap_selection = false; - bool needOverlay = false; - if (land.UpdateLandProperties(args, remote_client, out snap_selection, out needOverlay)) + if (land.UpdateLandProperties(args, remote_client, out bool snap_selection, out bool needOverlay)) { UUID parcelID = land.LandData.GlobalID; - m_scene.ForEachScenePresence(delegate(ScenePresence avatar) + m_scene.ForEachScenePresence(delegate (ScenePresence avatar) { if (avatar.IsDeleted || avatar.IsNPC) return; @@ -1621,12 +1594,12 @@ namespace OpenSim.Region.CoreModules.World.Land } ILandObject aland = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y); - if (aland != null) + if (aland is not null) { - if(land != aland) + if (land != aland) land.SendLandProperties(-10000, false, LandChannel.LAND_RESULT_SINGLE, client); else if (land == aland) - aland.SendLandProperties(0, true, LandChannel.LAND_RESULT_SINGLE, client); + aland.SendLandProperties(0, true, LandChannel.LAND_RESULT_SINGLE, client); } if (avatar.currentParcelUUID.Equals(parcelID)) avatar.currentParcelUUID = parcelID; // force parcel flags review @@ -1639,14 +1612,12 @@ namespace OpenSim.Region.CoreModules.World.Land ILandObject land; lock (m_landList) { - m_landList.TryGetValue(localID, out land); + if(!m_landList.TryGetValue(localID, out land) || land is null) + return; } - if (land != null) - { - UpdateLandProperties(land, args, remote_client); - m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client); - } + UpdateLandProperties(land, args, remote_client); + m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client); } public void ClientOnParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client) @@ -1667,96 +1638,84 @@ namespace OpenSim.Region.CoreModules.World.Land public void ClientOnParcelObjectOwnerRequest(int local_id, IClientAPI remote_client) { - ILandObject land = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(local_id, out land); + if(!m_landList.TryGetValue(local_id, out land) || land is null) + return; } - if (land != null) - { - m_scene.EventManager.TriggerParcelPrimCountUpdate(); - land.SendLandObjectOwners(remote_client); - } - else - { - m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid land object {0} passed for parcel object owner request", local_id); - } + m_scene.EventManager.TriggerParcelPrimCountUpdate(); + land.SendLandObjectOwners(remote_client); } public void ClientOnParcelGodForceOwner(int local_id, UUID ownerID, IClientAPI remote_client) { - ILandObject land = null; + if (!m_scene.Permissions.IsGod(remote_client.AgentId)) + return; + + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(local_id, out land); + if (!m_landList.TryGetValue(local_id, out land) || land is null) + return; } - if (land != null) - { - if (m_scene.Permissions.IsGod(remote_client.AgentId)) - { - land.LandData.OwnerID = ownerID; - land.LandData.GroupID = UUID.Zero; - land.LandData.IsGroupOwned = false; - land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); - UpdateLandObject(land.LandData.LocalID, land.LandData); - m_scene.ForEachClient(SendParcelOverlay); - land.SendLandUpdateToClient(true, remote_client); - } - } + land.LandData.OwnerID = ownerID; + land.LandData.GroupID = UUID.Zero; + land.LandData.IsGroupOwned = false; + land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); + UpdateLandObject(land.LandData.LocalID, land.LandData); + m_scene.ForEachClient(SendParcelOverlay); + land.SendLandUpdateToClient(true, remote_client); } public void ClientOnParcelAbandonRequest(int local_id, IClientAPI remote_client) { - ILandObject land = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(local_id, out land); + if (!m_landList.TryGetValue(local_id, out land) || land is null) + return; } - if (land != null) + if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land)) { - if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land)) - { - land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; - land.LandData.GroupID = UUID.Zero; - land.LandData.IsGroupOwned = false; - land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); + land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; + land.LandData.GroupID = UUID.Zero; + land.LandData.IsGroupOwned = false; + land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); - UpdateLandObject(land.LandData.LocalID, land.LandData); - m_scene.ForEachClient(SendParcelOverlay); - land.SendLandUpdateToAvatars(); - } + UpdateLandObject(land.LandData.LocalID, land.LandData); + m_scene.ForEachClient(SendParcelOverlay); + land.SendLandUpdateToAvatars(); } } public void ClientOnParcelReclaim(int local_id, IClientAPI remote_client) { - ILandObject land = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(local_id, out land); + if (!m_landList.TryGetValue(local_id, out land) || land is null) + return; } - if (land != null) + if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land)) { - if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land)) - { - land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; - land.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); - land.LandData.GroupID = UUID.Zero; - land.LandData.IsGroupOwned = false; - land.LandData.SalePrice = 0; - land.LandData.AuthBuyerID = UUID.Zero; - land.LandData.SeeAVs = true; - land.LandData.AnyAVSounds = true; - land.LandData.GroupAVSounds = true; - land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); - UpdateLandObject(land.LandData.LocalID, land.LandData); - m_scene.ForEachClient(SendParcelOverlay); - land.SendLandUpdateToAvatars(); - } + land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner; + land.LandData.ClaimDate = Util.UnixTimeSinceEpoch(); + land.LandData.GroupID = UUID.Zero; + land.LandData.IsGroupOwned = false; + land.LandData.SalePrice = 0; + land.LandData.AuthBuyerID = UUID.Zero; + land.LandData.SeeAVs = true; + land.LandData.AnyAVSounds = true; + land.LandData.GroupAVSounds = true; + land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory); + UpdateLandObject(land.LandData.LocalID, land.LandData); + m_scene.ForEachClient(SendParcelOverlay); + land.SendLandUpdateToAvatars(); } } #endregion @@ -1772,15 +1731,13 @@ namespace OpenSim.Region.CoreModules.World.Land ILandObject land; lock (m_landList) { - m_landList.TryGetValue(e.parcelLocalID, out land); + if (!m_landList.TryGetValue(e.parcelLocalID, out land) || land is null) + return; } - if (land != null) - { - land.UpdateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea); - m_scene.ForEachClient(SendParcelOverlay); - land.SendLandUpdateToAvatars(); - } + land.UpdateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea); + m_scene.ForEachClient(SendParcelOverlay); + land.SendLandUpdateToAvatars(); } } @@ -1792,49 +1749,45 @@ namespace OpenSim.Region.CoreModules.World.Land { if (e.landValidated == false) { - ILandObject lob = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(e.parcelLocalID, out lob); + if (!m_landList.TryGetValue(e.parcelLocalID, out land) || land is null) + return; } - if (lob != null) - { - UUID AuthorizedID = lob.LandData.AuthBuyerID; - int saleprice = lob.LandData.SalePrice; - UUID pOwnerID = lob.LandData.OwnerID; + UUID AuthorizedID = land.LandData.AuthBuyerID; + int saleprice = land.LandData.SalePrice; + UUID pOwnerID = land.LandData.OwnerID; - bool landforsale = ((lob.LandData.Flags & - (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0); - if ((AuthorizedID.IsZero() || AuthorizedID.Equals(e.agentId)) && e.parcelPrice >= saleprice && landforsale) - { - // TODO I don't think we have to lock it here, no? - //lock (e) - //{ - e.parcelOwnerID = pOwnerID; - e.landValidated = true; - //} - } + bool landforsale = ((land.LandData.Flags & + (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0); + if ((AuthorizedID.IsZero() || AuthorizedID.Equals(e.agentId)) && e.parcelPrice >= saleprice && landforsale) + { + // TODO I don't think we have to lock it here, no? + //lock (e) + //{ + e.parcelOwnerID = pOwnerID; + e.landValidated = true; + //} } } } void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client) { - ILandObject land = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(parcelLocalID, out land); + if(!m_landList.TryGetValue(parcelLocalID, out land) || land is null) + return; } - if (land != null) - { - if (!m_scene.Permissions.CanDeedParcel(remote_client.AgentId, land)) - return; - land.DeedToGroup(groupID); - m_scene.ForEachClient(SendParcelOverlay); - land.SendLandUpdateToAvatars(); - } + if (!m_scene.Permissions.CanDeedParcel(remote_client.AgentId, land)) + return; + land.DeedToGroup(groupID); + m_scene.ForEachClient(SendParcelOverlay); + land.SendLandUpdateToAvatars(); } #region Land Object From Storage Functions @@ -1922,15 +1875,13 @@ namespace OpenSim.Region.CoreModules.World.Land { if (localID != -1) { - ILandObject selectedParcel = null; + ILandObject selectedParcel; lock (m_landList) { - m_landList.TryGetValue(localID, out selectedParcel); + if(!m_landList.TryGetValue(localID, out selectedParcel) || selectedParcel is null) + return; } - if (selectedParcel == null) - return; - selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient); } else @@ -1944,16 +1895,18 @@ namespace OpenSim.Region.CoreModules.World.Land // We get here when the user returns objects from the list of Top Colliders or Top Scripts. // In that case we receive specific object UUID's, but no parcel ID. - Dictionary> returns = new Dictionary>(); - + Dictionary> returns = new(); foreach (UUID groupID in taskIDs) { SceneObjectGroup obj = m_scene.GetSceneObjectGroup(groupID); - if (obj != null) + if (obj is not null) { - if (!returns.ContainsKey(obj.OwnerID)) - returns[obj.OwnerID] = new HashSet(); - returns[obj.OwnerID].Add(obj); + if (!returns.TryGetValue(obj.OwnerID, out HashSet howner)) + { + howner = new HashSet(); + returns[obj.OwnerID] = howner; + } + howner.Add(obj); } else { @@ -1968,7 +1921,7 @@ namespace OpenSim.Region.CoreModules.World.Land foreach (HashSet objs in returns.Values) { - List objs2 = new List(objs); + List objs2 = new(objs); if (m_scene.Permissions.CanReturnObjects(null, remoteClient, objs2)) { m_scene.returnObjects(objs2.ToArray(), remoteClient); @@ -2026,8 +1979,7 @@ namespace OpenSim.Region.CoreModules.World.Land return; } - IClientAPI client; - if (!m_scene.TryGetClient(agentID, out client)) + if (!m_scene.TryGetClient(agentID, out IClientAPI client)) { m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to retrieve IClientAPI for {0}", agentID); response.StatusCode = (int)HttpStatusCode.Gone; @@ -2053,10 +2005,10 @@ namespace OpenSim.Region.CoreModules.World.Land ILandObject land = null; lock (m_landList) { - m_landList.TryGetValue(parcelID, out land); + _ = m_landList.TryGetValue(parcelID, out land); } - if (land == null) + if (land is null) { m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID); response.StatusCode = (int)HttpStatusCode.NotFound; @@ -2065,29 +2017,31 @@ namespace OpenSim.Region.CoreModules.World.Land try { - LandUpdateArgs land_update = new LandUpdateArgs(); - land_update.AuthBuyerID = properties.AuthBuyerID; - land_update.Category = properties.Category; - land_update.Desc = properties.Desc; - land_update.GroupID = properties.GroupID; - land_update.LandingType = (byte) properties.Landing; - land_update.MediaAutoScale = (byte) Convert.ToInt32(properties.MediaAutoScale); - land_update.MediaID = properties.MediaID; - land_update.MediaURL = properties.MediaURL; - land_update.MusicURL = properties.MusicURL; - land_update.Name = properties.Name; - land_update.ParcelFlags = (uint) properties.ParcelFlags; - land_update.PassHours = properties.PassHours; - land_update.PassPrice = (int) properties.PassPrice; - land_update.SalePrice = (int) properties.SalePrice; - land_update.SnapshotID = properties.SnapshotID; - land_update.UserLocation = properties.UserLocation; - land_update.UserLookAt = properties.UserLookAt; - land_update.MediaDescription = properties.MediaDesc; - land_update.MediaType = properties.MediaType; - land_update.MediaWidth = properties.MediaWidth; - land_update.MediaHeight = properties.MediaHeight; - land_update.MediaLoop = properties.MediaLoop; + LandUpdateArgs land_update = new() + { + AuthBuyerID = properties.AuthBuyerID, + Category = properties.Category, + Desc = properties.Desc, + GroupID = properties.GroupID, + LandingType = (byte)properties.Landing, + MediaAutoScale = (byte)Convert.ToInt32(properties.MediaAutoScale), + MediaID = properties.MediaID, + MediaURL = properties.MediaURL, + MusicURL = properties.MusicURL, + Name = properties.Name, + ParcelFlags = (uint)properties.ParcelFlags, + PassHours = properties.PassHours, + PassPrice = (int)properties.PassPrice, + SalePrice = (int)properties.SalePrice, + SnapshotID = properties.SnapshotID, + UserLocation = properties.UserLocation, + UserLookAt = properties.UserLookAt, + MediaDescription = properties.MediaDesc, + MediaType = properties.MediaType, + MediaWidth = properties.MediaWidth, + MediaHeight = properties.MediaHeight, + MediaLoop = properties.MediaLoop + }; if (args.TryGetValue("obscure_moap", out OSD omoap)) land_update.ObscureMOAP = omoap.AsBoolean(); @@ -2137,14 +2091,12 @@ namespace OpenSim.Region.CoreModules.World.Land // private void RemoteParcelRequest(IOSHttpRequest request, IOSHttpResponse response, OSDMap args) { - UUID parcelID = UUID.Zero; - OSD tmp; + UUID parcelID = new(); try { - if (args.TryGetValue("location", out tmp) && tmp is OSDArray) + if (args.TryGetValue("location", out OSD tmp) && tmp is OSDArray list) { UUID scope = m_scene.RegionInfo.ScopeID; - OSDArray list = (OSDArray)tmp; uint x = (uint)(double)list[0]; uint y = (uint)(double)list[1]; ulong myHandle = m_scene.RegionInfo.RegionHandle; @@ -2156,18 +2108,13 @@ namespace OpenSim.Region.CoreModules.World.Land if(regionHandle == myHandle) { ILandObject l = GetLandObjectClippedXY(x, y); - if (l != null) - parcelID = l.LandData.FakeID; - else - parcelID = Util.BuildFakeParcelID(myHandle, x, y); + parcelID = l is null ? Util.BuildFakeParcelID(myHandle, x, y) : l.LandData.FakeID; } else { - uint wx; - uint wy; - Util.RegionHandleToWorldLoc(regionHandle, out wx, out wy); + Util.RegionHandleToWorldLoc(regionHandle, out uint wx, out uint wy); GridRegion info = m_scene.GridService.GetRegionByPosition(scope, (int)wx, (int)wy); - if (info != null) + if (info is not null) { wx -= (uint)info.RegionLocX; wy -= (uint)info.RegionLocY; @@ -2181,10 +2128,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (info.RegionHandle == myHandle) { ILandObject l = GetLandObjectClippedXY(wx, wy); - if (l != null) - parcelID = l.LandData.FakeID; - else - parcelID = Util.BuildFakeParcelID(myHandle, wx, wy); + parcelID = l is null ? Util.BuildFakeParcelID(myHandle, wx, wy) : l.LandData.FakeID; } else { @@ -2199,16 +2143,13 @@ namespace OpenSim.Region.CoreModules.World.Land if (regionID.Equals(m_scene.RegionInfo.RegionID)) { ILandObject l = GetLandObjectClippedXY(x, y); - if (l != null) - parcelID = l.LandData.FakeID; - else - parcelID = Util.BuildFakeParcelID(myHandle, x, y); + parcelID = l is null ? Util.BuildFakeParcelID(myHandle, x, y) : l.LandData.FakeID; } else { // a parcel request for a parcel in another region. Ask the grid about the region GridRegion info = m_scene.GridService.GetRegionByUUID(scope, regionID); - if (info != null) + if (info is not null) parcelID = Util.BuildFakeParcelID(info.RegionHandle, x, y); } } @@ -2240,7 +2181,7 @@ namespace OpenSim.Region.CoreModules.World.Land if(!m_parcelInfoCache.TryGetValue(parcelID, 30000, out ExtendedLandData data)) { data = null; - ExtendedLandData extLandData = new ExtendedLandData(); + ExtendedLandData extLandData = new(); while(true) { @@ -2255,12 +2196,12 @@ namespace OpenSim.Region.CoreModules.World.Land if (extLandData.RegionHandle == m_scene.RegionInfo.RegionHandle) { ILandObject extLandObject = GetLandObjectByfakeID(parcelID); - if (extLandObject == null) + if (extLandObject is null) break; extLandData.LandData = extLandObject.LandData; extLandData.RegionAccess = m_scene.RegionInfo.AccessLevel; - if (extLandData.LandData != null) + if (extLandData.LandData is not null) data = extLandData; break; } @@ -2270,7 +2211,7 @@ namespace OpenSim.Region.CoreModules.World.Land extLandData.LandData = landService.GetLandData(m_scene.RegionInfo.ScopeID, extLandData.RegionHandle, extLandData.X, extLandData.Y, out extLandData.RegionAccess); - if (extLandData.LandData != null) + if (extLandData.LandData is not null) data = extLandData; break; } @@ -2278,14 +2219,14 @@ namespace OpenSim.Region.CoreModules.World.Land m_parcelInfoCache.Add(parcelID, data, 30000); } - if (data != null) // if we found some data, send it + if (data is not null) // if we found some data, send it { GridRegion info; if (data.RegionHandle == m_scene.RegionInfo.RegionHandle) { info = new GridRegion(m_scene.RegionInfo); IDwellModule dwellModule = m_scene.RequestModuleInterface(); - if (dwellModule != null) + if (dwellModule is not null) data.LandData.Dwell = dwellModule.GetDwell(data.LandData); } else @@ -2298,10 +2239,12 @@ namespace OpenSim.Region.CoreModules.World.Land // data.LandData.Name, data.RegionHandle); // HACK for now - RegionInfo r = new RegionInfo(); - r.RegionName = info.RegionName; - r.RegionLocX = (uint)info.RegionLocX; - r.RegionLocY = (uint)info.RegionLocY; + RegionInfo r = new() + { + RegionName = info.RegionName, + RegionLocX = (uint)info.RegionLocX, + RegionLocY = (uint)info.RegionLocY + }; r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess); remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y); } @@ -2311,14 +2254,13 @@ namespace OpenSim.Region.CoreModules.World.Land public void SetParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime) { - ILandObject land = null; + ILandObject land; lock (m_landList) { - m_landList.TryGetValue(localID, out land); + if(!m_landList.TryGetValue(localID, out land) || land is null) + return; } - if (land == null) return; - if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions, false)) return; @@ -2329,9 +2271,7 @@ namespace OpenSim.Region.CoreModules.World.Land public void ClientOnParcelGodMark(IClientAPI client, UUID god, int landID) { - ScenePresence sp = null; - ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out sp); - if (sp == null) + if(!((Scene)client.Scene).TryGetScenePresence(client.AgentId, out ScenePresence sp) || sp is null) return; if (sp.IsChildAgent || sp.IsDeleted || sp.IsInTransit || sp.IsNPC) return; @@ -2351,17 +2291,15 @@ namespace OpenSim.Region.CoreModules.World.Land break; } } - if (land == null) + if (land is null) return; - bool validParcelOwner = false; - if (!DefaultGodParcelOwner.IsZero() && m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, DefaultGodParcelOwner) != null) - validParcelOwner = true; + bool validParcelOwner = DefaultGodParcelOwner.IsNotZero() && m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, DefaultGodParcelOwner) is not null; bool validParcelGroup = false; - if (m_groupManager != null) + if (m_groupManager is not null) { - if (!DefaultGodParcelGroup.IsZero() && m_groupManager.GetGroupRecord(DefaultGodParcelGroup) != null) + if (DefaultGodParcelGroup.IsNotZero() && m_groupManager.GetGroupRecord(DefaultGodParcelGroup) is not null) validParcelGroup = true; } @@ -2431,9 +2369,10 @@ namespace OpenSim.Region.CoreModules.World.Land private void ClientOnSimWideDeletes(IClientAPI client, UUID agentID, int flags, UUID targetID) { - ScenePresence SP; - ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out SP); - List returns = new List(); + if(!((Scene)client.Scene).TryGetScenePresence(client.AgentId, out ScenePresence SP)) + return; + + List returns = new(); if (SP.GodController.UserLevel != 0) { if (flags == 0) //All parcels, scripted or not @@ -2444,8 +2383,7 @@ namespace OpenSim.Region.CoreModules.World.Land { returns.Add(e); } - } - ); + }); } if (flags == 4) //All parcels, scripted object { @@ -2490,27 +2428,28 @@ namespace OpenSim.Region.CoreModules.World.Land ((Scene)client.Scene).returnObjects(objs, client); } - Dictionary Timers = new Dictionary(); + Dictionary Timers = new(); public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) { - ScenePresence targetAvatar = null; - ((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar); - ScenePresence parcelManager = null; - ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager); + Scene clientScene = client.Scene as Scene; + if (!clientScene.TryGetScenePresence(target, out ScenePresence targetAvatar)) + return; + if(!clientScene.TryGetScenePresence(client.AgentId, out ScenePresence parcelManager)) + return; System.Threading.Timer Timer; if (targetAvatar.GodController.UserLevel < 200) { - ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y); - if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze, true)) + ILandObject land = clientScene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y); + if (!clientScene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze, true)) return; if ((flags & 1) == 0) // only lowest bit has meaning for now { targetAvatar.AllowMovement = false; targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has frozen you for 30 seconds. You cannot move or interact with the world."); parcelManager.ControllingClient.SendAlertMessage("Avatar Frozen."); - System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(OnEndParcelFrozen); + System.Threading.TimerCallback timeCB = new(OnEndParcelFrozen); Timer = new System.Threading.Timer(timeCB, targetAvatar, 30000, 0); Timers.Add(targetAvatar.UUID, Timer); } @@ -2519,30 +2458,25 @@ namespace OpenSim.Region.CoreModules.World.Land targetAvatar.AllowMovement = true; targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has unfrozen you."); parcelManager.ControllingClient.SendAlertMessage("Avatar Unfrozen."); - Timers.TryGetValue(targetAvatar.UUID, out Timer); - Timers.Remove(targetAvatar.UUID); - Timer.Dispose(); + if(Timers.Remove(targetAvatar.UUID, out Timer)) + Timer.Dispose(); } } } private void OnEndParcelFrozen(object avatar) { ScenePresence targetAvatar = (ScenePresence)avatar; + if (Timers.Remove(targetAvatar.UUID, out System.Threading.Timer Timer)) + Timer.Dispose(); targetAvatar.AllowMovement = true; - System.Threading.Timer Timer; - Timers.TryGetValue(targetAvatar.UUID, out Timer); - Timers.Remove(targetAvatar.UUID); targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false); } public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target) { - ScenePresence targetAvatar = null; - ScenePresence parcelManager = null; - // Must have presences - if (!m_scene.TryGetScenePresence(target, out targetAvatar) || - !m_scene.TryGetScenePresence(client.AgentId, out parcelManager)) + if (!m_scene.TryGetScenePresence(target, out ScenePresence targetAvatar) || + !m_scene.TryGetScenePresence(client.AgentId, out ScenePresence parcelManager)) return; // Cannot eject estate managers or gods @@ -2563,10 +2497,12 @@ namespace OpenSim.Region.CoreModules.World.Land if ((flags & 1) != 0) // Ban TODO: Remove magic number { - LandAccessEntry entry = new LandAccessEntry(); - entry.AgentID = targetAvatar.UUID; - entry.Flags = AccessList.Ban; - entry.Expires = 0; // Perm + LandAccessEntry entry = new() + { + AgentID = targetAvatar.UUID, + Flags = AccessList.Ban, + Expires = 0 // Perm + }; land.LandData.ParcelAccessList.Add(entry); } @@ -2591,7 +2527,7 @@ namespace OpenSim.Region.CoreModules.World.Land { // Let's find the parcel in question ILandObject land = GetLandObject(position); - if (land == null || m_scene.GridUserService == null) + if (land is null || m_scene.GridUserService is null) { m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed."); return; @@ -2615,16 +2551,14 @@ namespace OpenSim.Region.CoreModules.World.Land // (c) members of the land-associated group in roles that can set home ((gpowers & (ulong)GroupPowers.AllowSetHome) == (ulong)GroupPowers.AllowSetHome) || // (d) parcels with telehubs can be the home of anyone - (telehub != null && land.ContainsPoint((int)telehub.AbsolutePosition.X, (int)telehub.AbsolutePosition.Y)))) + (telehub is not null && land.ContainsPoint((int)telehub.AbsolutePosition.X, (int)telehub.AbsolutePosition.Y)))) { - string userId; - UUID test; - if (!m_scene.UserManagementModule.GetUserUUI(remoteClient.AgentId, out userId)) + if (!m_scene.UserManagementModule.GetUserUUI(remoteClient.AgentId, out string userId)) { /* Do not set a home position in this grid for a HG visitor */ m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed. (User Lookup)"); } - else if (!UUID.TryParse(userId, out test)) + else if (!UUID.TryParse(userId, out UUID _)) { m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed. (HG visitor)"); } @@ -2664,15 +2598,13 @@ namespace OpenSim.Region.CoreModules.World.Land protected void HandleClearCommand(string module, string[] args) { - if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene)) + if (!(MainConsole.Instance.ConsoleScene is null || MainConsole.Instance.ConsoleScene == m_scene)) return; string response = MainConsole.Instance.Prompt( - string.Format( - "Are you sure that you want to clear all land parcels from {0} (y or n)", m_scene.Name), - "n"); + $"Are you sure that you want to clear all land parcels from {m_scene.Name} (y or n)", "n"); - if (response.ToLower() == "y") + if (response.Equals("y", StringComparison.InvariantCultureIgnoreCase)) { Clear(true); MainConsole.Instance.Output("Cleared all parcels from {0}", m_scene.Name); @@ -2685,10 +2617,10 @@ namespace OpenSim.Region.CoreModules.World.Land protected void HandleShowCommand(string module, string[] args) { - if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene)) + if (!(MainConsole.Instance.ConsoleScene is null || MainConsole.Instance.ConsoleScene == m_scene)) return; - StringBuilder report = new StringBuilder(); + StringBuilder report = new(); if (args.Length <= 2) { @@ -2696,9 +2628,7 @@ namespace OpenSim.Region.CoreModules.World.Land } else { - int landLocalId; - - if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[2], out landLocalId)) + if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[2], out int landLocalId)) return; ILandObject lo = null; @@ -2707,7 +2637,7 @@ namespace OpenSim.Region.CoreModules.World.Land { if (!m_landList.TryGetValue(landLocalId, out lo)) { - MainConsole.Instance.Output("No parcel found with local ID {0}", landLocalId); + MainConsole.Instance.Output($"No parcel found with local ID {landLocalId}"); return; } } @@ -2722,7 +2652,7 @@ namespace OpenSim.Region.CoreModules.World.Land { report.AppendFormat("Land information for {0}\n", m_scene.Name); - ConsoleDisplayTable cdt = new ConsoleDisplayTable(); + ConsoleDisplayTable cdt = new(); cdt.AddColumn("Parcel Name", ConsoleDisplayUtil.ParcelNameSize); cdt.AddColumn("ID", 3); cdt.AddColumn("Area", 6); @@ -2740,7 +2670,7 @@ namespace OpenSim.Region.CoreModules.World.Land if (ld.IsGroupOwned) { GroupRecord rec = m_groupManager.GetGroupRecord(ld.GroupID); - ownerName = (rec != null) ? rec.GroupName : "Unknown Group"; + ownerName = (rec is not null) ? rec.GroupName : "Unknown Group"; } else { @@ -2758,7 +2688,7 @@ namespace OpenSim.Region.CoreModules.World.Land { LandData ld = lo.LandData; - ConsoleDisplayList cdl = new ConsoleDisplayList(); + ConsoleDisplayList cdl = new(); cdl.AddRow("Parcel name", ld.Name); cdl.AddRow("Local ID", ld.LocalID); cdl.AddRow("Fake ID", ld.FakeID); diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs index 21da019fe6..62cb3200bd 100755 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/GroupsModule.cs @@ -74,7 +74,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private List m_sceneList = new List(); + private List m_sceneList = new(); private IMessageTransferModule m_msgTransferModule; @@ -1701,12 +1701,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups private UUID GetRequestingAgentID(IClientAPI client) { - UUID requestingAgentID = UUID.Zero; - if (client != null) - { - requestingAgentID = client.AgentId; - } - return requestingAgentID; + return client is null ? UUID.Zero : client.AgentId; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 48a5802f76..5f9c4366a8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -4433,7 +4433,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Key llGetObjectLinkKey(LSL_Key objectid, int linknum) { - if (!UUID.TryParse(objectid, out UUID oID)) + if (!UUID.TryParse(objectid, out UUID oID) || oID.IsZero()) return ScriptBaseClass.NULL_KEY; if (!World.TryGetSceneObjectPart(oID, out SceneObjectPart sop)) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs index 7ff0b301ec..b499bbdf5d 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Stub.cs @@ -662,9 +662,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase return m_LSL_Functions.llGetLinkKey(linknum); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public LSL_Key llGetObjectLinkKey(LSL_Key objectid, int linknum) { - return m_LSL_Functions.llGetObjectLinkKey(objectid, linknum); ; + return m_LSL_Functions.llGetObjectLinkKey(objectid, linknum); } [MethodImpl(MethodImplOptions.AggressiveInlining)]