From a2fe315d943223c28c5ee5c76bca438fd20d384c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Sun, 9 Aug 2020 01:37:54 +0100 Subject: [PATCH] cosmetics --- .../Caps/EventQueue/EventQueueGetModule.cs | 25 +- .../World/Permissions/PermissionsModule.cs | 12 +- .../OptionalModules/World/NPC/NPCAvatar.cs | 66 +-- .../Shared/Api/Implementation/LSL_Api.cs | 558 +++++++++--------- .../Shared/Api/Implementation/OSSL_Api.cs | 220 +++---- .../Implementation/Plugins/SensorRepeat.cs | 86 +-- .../ScriptEngine/YEngine/XMRInstBackend.cs | 2 +- 7 files changed, 444 insertions(+), 525 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index bf9bf6d50e..d5ea325525 100755 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -139,9 +139,8 @@ namespace OpenSim.Region.ClientStack.Linden protected void HandleDebugEq(string module, string[] args) { - int debugLevel; - if (!(args.Length == 3 && int.TryParse(args[2], out debugLevel))) + if (!(args.Length == 3 && int.TryParse(args[2], out int debugLevel))) { MainConsole.Instance.Output("Usage: debug eq [0|1|2]"); } @@ -175,10 +174,9 @@ namespace OpenSim.Region.ClientStack.Linden { lock (queues) { - Queue queue; - if (queues.TryGetValue(agentId, out queue)) + if (queues.TryGetValue(agentId, out Queue queue)) return queue; - + if (DebugLevel > 0) m_log.DebugFormat( "[EVENTQUEUE]: Adding new queue for agent {0} in region {1}", @@ -481,8 +479,7 @@ namespace OpenSim.Region.ClientStack.Linden thisID = -thisID; } - elements = new List(queue.Count + 2); - elements.Add(EventHeader); + elements = new List(queue.Count + 2) {EventHeader}; while (queue.Count > 0) { @@ -524,9 +521,11 @@ namespace OpenSim.Region.ClientStack.Linden elements.Add(element); totalSize += element.Length; - Hashtable responsedata = new Hashtable(); - responsedata["int_response_code"] = 200; - responsedata["content_type"] = "application/xml"; + Hashtable responsedata = new Hashtable + { + ["int_response_code"] = 200, + ["content_type"] = "application/xml" + }; //temporary byte[] finalData = new byte[totalSize]; @@ -559,8 +558,10 @@ namespace OpenSim.Region.ClientStack.Linden public Hashtable NoAgent(UUID requestID, UUID agentID) { - Hashtable responsedata = new Hashtable(); - responsedata["int_response_code"] = (int)HttpStatusCode.NotFound; + Hashtable responsedata = new Hashtable + { + ["int_response_code"] = (int)HttpStatusCode.NotFound + }; return responsedata; } } diff --git a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs index 9b76491a66..73b9be8a36 100644 --- a/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs +++ b/OpenSim/Region/CoreModules/World/Permissions/PermissionsModule.cs @@ -458,9 +458,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions if (args.Length > 2) { - bool val; - - if (!bool.TryParse(args[2], out val)) + if (!bool.TryParse(args[2], out bool val)) return; m_bypassPermissions = val; @@ -487,9 +485,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions if (args.Length > 2) { - bool val; - - if (!bool.TryParse(args[2], out val)) + if (!bool.TryParse(args[2], out bool val)) return; m_bypassPermissionsValue = val; @@ -508,9 +504,7 @@ namespace OpenSim.Region.CoreModules.World.Permissions if (args.Length > 2) { - bool val; - - if (!bool.TryParse(args[2], out val)) + if (!bool.TryParse(args[2], out bool val)) return; m_debugPermissions = val; diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 96b6a64886..d9b41d298c 100755 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs @@ -180,22 +180,21 @@ namespace OpenSim.Region.OptionalModules.World.NPC if (!objectTouchable) return false; // Set up the surface args as if the touch is from a client that does not support this - SurfaceTouchEventArgs surfaceArgs = new SurfaceTouchEventArgs(); - surfaceArgs.FaceIndex = -1; // TOUCH_INVALID_FACE - surfaceArgs.Binormal = Vector3.Zero; // TOUCH_INVALID_VECTOR - surfaceArgs.Normal = Vector3.Zero; // TOUCH_INVALID_VECTOR - surfaceArgs.STCoord = new Vector3(-1.0f, -1.0f, 0.0f); // TOUCH_INVALID_TEXCOORD - surfaceArgs.UVCoord = surfaceArgs.STCoord; // TOUCH_INVALID_TEXCOORD - List touchArgs = new List(); - touchArgs.Add(surfaceArgs); + SurfaceTouchEventArgs surfaceArgs = new SurfaceTouchEventArgs() + { + FaceIndex = -1, // TOUCH_INVALID_FACE + Binormal = Vector3.Zero, // TOUCH_INVALID_VECTOR + Normal = Vector3.Zero, // TOUCH_INVALID_VECTOR + STCoord = new Vector3(-1.0f, -1.0f, 0.0f), // TOUCH_INVALID_TEXCOORD + UVCoord = new Vector3(-1.0f, -1.0f, 0.0f) // TOUCH_INVALID_TEXCOORD + }; + List touchArgs = new List() { surfaceArgs }; Vector3 offset = part.OffsetPosition * -1.0f; if (OnGrabObject == null) return false; OnGrabObject(part.LocalId, offset, this, touchArgs); - if (OnGrabUpdate != null) - OnGrabUpdate(part.UUID, offset, part.ParentGroup.RootPart.GroupPosition, this, touchArgs); - if (OnDeGrabObject != null) - OnDeGrabObject(part.LocalId, this, touchArgs); + OnGrabUpdate?.Invoke(part.UUID, offset, part.ParentGroup.RootPart.GroupPosition, this, touchArgs); + OnDeGrabObject?.Invoke(part.LocalId, this, touchArgs); return true; } @@ -263,25 +262,29 @@ namespace OpenSim.Region.OptionalModules.World.NPC private void SendOnChatFromClient(int channel, string message, ChatTypeEnum chatType) { + if(OnChatFromClient == null) + return; + if (channel == 0) { message = message.Trim(); if (string.IsNullOrEmpty(message)) - { return; - } } - OSChatMessage chatFromClient = new OSChatMessage(); - chatFromClient.Channel = channel; - chatFromClient.From = Name; - chatFromClient.Message = message; - chatFromClient.Position = StartPos; - chatFromClient.Scene = m_scene; - chatFromClient.Sender = this; - chatFromClient.SenderUUID = AgentId; - chatFromClient.Type = chatType; - OnChatFromClient(this, chatFromClient); + OSChatMessage chatFromClient = new OSChatMessage() + { + Channel = channel, + From = Name, + Message = message, + Position = StartPos, + Scene = m_scene, + Sender = this, + SenderUUID = AgentId, + Type = chatType + }; + + OnChatFromClient?.Invoke(this, chatFromClient); } #endregion @@ -718,18 +721,12 @@ namespace OpenSim.Region.OptionalModules.World.NPC string message, byte type, Vector3 fromPos, string fromName, UUID fromAgentID, UUID ownerID, byte source, byte audible) { - ChatToNPC ctn = OnChatToNPC; - - if (ctn != null) - ctn(message, type, fromPos, fromName, fromAgentID, ownerID, source, audible); + OnChatToNPC?.Invoke(message, type, fromPos, fromName, fromAgentID, ownerID, source, audible); } public void SendInstantMessage(GridInstantMessage im) { - Action oimtn = OnInstantMessageToNPC; - - if (oimtn != null) - oimtn(im); + OnInstantMessageToNPC?.Invoke(im); } public void SendGenericMessage(string method, UUID invoice, List message) @@ -938,10 +935,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC public virtual void SendRegionHandshake() { - if (OnRegionHandShakeReply != null) - { - OnRegionHandShakeReply(this); - } + OnRegionHandShakeReply?.Invoke(this); } public void SendAssetUploadCompleteMessage(sbyte AssetType, bool Success, UUID AssetFullID) diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 309ae10395..b6ecd1fb37 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -110,7 +110,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected TaskInventoryItem m_item; protected bool throwErrorOnNotImplemented = false; - protected AsyncCommandManager AsyncCommands = null; protected float m_ScriptDelayFactor = 1.0f; protected float m_ScriptDistanceFactor = 1.0f; protected float m_MinTimerInterval = 0.5f; @@ -125,8 +124,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected int m_scriptConsoleChannel = 0; protected bool m_scriptConsoleChannelEnabled = false; protected bool m_debuggerSafe = false; - protected IUrlModule m_UrlModule = null; + protected AsyncCommandManager m_AsyncCommands = null; + protected IUrlModule m_UrlModule = null; protected IMaterialsModule m_materialsModule = null; protected IEnvironmentModule m_envModule = null; protected IEmailModule m_emailModule = null; @@ -318,7 +318,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_emailModule = m_ScriptEngine.World.RequestModuleInterface(); m_envModule = m_ScriptEngine.World.RequestModuleInterface< IEnvironmentModule>(); - AsyncCommands = new AsyncCommandManager(m_ScriptEngine); + m_AsyncCommands = new AsyncCommandManager(m_ScriptEngine); } /// @@ -1244,8 +1244,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (channel == ScriptBaseClass.DEBUG_CHANNEL) return; - UUID TargetID; - UUID.TryParse(target, out TargetID); + UUID.TryParse(target, out UUID TargetID); IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface(); if (wComm != null) @@ -1255,8 +1254,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llListen(int channelID, string name, string ID, string msg) { m_host.AddScriptLPS(1); - UUID keyID; - UUID.TryParse(ID, out keyID); + UUID.TryParse(ID, out UUID keyID); IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface(); if (wComm != null) return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg); @@ -1286,7 +1284,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID keyID = UUID.Zero; UUID.TryParse(id, out keyID); - AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host); + m_AsyncCommands.SensorRepeatPlugin.SenseOnce(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, m_host); } public void llSensorRepeat(string name, string id, int type, double range, double arc, double rate) @@ -1295,13 +1293,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID keyID = UUID.Zero; UUID.TryParse(id, out keyID); - AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host); + m_AsyncCommands.SensorRepeatPlugin.SetSenseRepeatEvent(m_host.LocalId, m_item.ItemID, name, keyID, type, range, arc, rate, m_host); } public void llSensorRemove() { m_host.AddScriptLPS(1); - AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID); + m_AsyncCommands.SensorRepeatPlugin.UnSetSenseRepeaterEvents(m_host.LocalId, m_item.ItemID); } public string resolveName(UUID objecUUID) @@ -1321,8 +1319,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return objectname; } - EntityBase SensedObject; - World.Entities.TryGetValue(objecUUID, out SensedObject); + World.Entities.TryGetValue(objecUUID, out EntityBase SensedObject); if (SensedObject == null) { @@ -1887,8 +1884,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_UrlModule == null) return; - UUID id; - if(!UUID.TryParse(reqid, out id)) + if(!UUID.TryParse(reqid, out UUID id)) return; // Make sure the content type is text/plain to start with @@ -3497,10 +3493,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return; } - string reason; - money.ObjectGiveMoney( - - m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount,UUID.Zero, out reason); + money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, + toID, amount,UUID.Zero, out string reason); }, null, "LSL_Api.llGiveMoney"); return 0; @@ -3678,7 +3672,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api sec = m_MinTimerInterval; m_host.AddScriptLPS(1); // Setting timer repeat - AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec); + m_AsyncCommands.TimerPlugin.SetTimerEvent(m_host.LocalId, m_item.ItemID, sec); } public virtual void llSleep(double sec) @@ -3729,15 +3723,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); m_host.CollisionFilter.Clear(); - UUID objectID; - if (!UUID.TryParse(id, out objectID)) - objectID = UUID.Zero; + if (!UUID.TryParse(id, out UUID objectID)) + return; if (objectID == UUID.Zero && name == "") return; - m_host.CollisionFilter.Add(accept,objectID.ToString() + name); + m_host.CollisionFilter.Add(accept, objectID.ToString() + name); } public void llTakeControls(int controls, int accept, int pass_on) @@ -3855,8 +3848,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (grp == null || grp.IsDeleted || grp.IsAttachment) return; - ScenePresence target; - if (!World.TryGetScenePresence(m_item.PermsGranter, out target)) + if (!World.TryGetScenePresence(m_item.PermsGranter, out ScenePresence target)) return; if (target.UUID != grp.OwnerID) @@ -3926,8 +3918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llInstantMessage(string user, string message) { m_host.AddScriptLPS(1); - UUID result; - if (!UUID.TryParse(user, out result) || result == UUID.Zero) + if (!UUID.TryParse(user, out UUID result) || result == UUID.Zero) { Error("llInstantMessage","An invalid key was passed to llInstantMessage"); ScriptSleep(2000); @@ -3947,12 +3938,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api //m_pendingFriendRequests.Add(friendTransactionID, fromAgentID); - GridInstantMessage msg = new GridInstantMessage(); - msg.fromAgentID = new Guid(m_host.OwnerID.ToString()); // fromAgentID.Guid; - msg.toAgentID = new Guid(user); // toAgentID.Guid; - msg.imSessionID = new Guid(m_host.UUID.ToString()); // This is the item we're mucking with here - msg.timestamp = (uint)Util.UnixTimeSinceEpoch(); - msg.fromAgentName = m_host.Name;//client.FirstName + " " + client.LastName;// fromAgentName; + GridInstantMessage msg = new GridInstantMessage + { + fromAgentID = new Guid(m_host.OwnerID.ToString()), // fromAgentID.Guid; + toAgentID = new Guid(user), // toAgentID.Guid; + imSessionID = new Guid(m_host.UUID.ToString()), // This is the item we're mucking with here + timestamp = (uint)Util.UnixTimeSinceEpoch(), + fromAgentName = m_host.Name//client.FirstName + " " + client.LastName;// fromAgentName; + }; if (message != null && message.Length > 1024) msg.message = message.Substring(0, 1024); @@ -4319,9 +4312,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llRequestPermissions(string agent, int perm) { - UUID agentID; - - if (!UUID.TryParse(agent, out agentID)) + if (!UUID.TryParse(agent, out UUID agentID)) return; if (agentID == UUID.Zero || perm == 0) // Releasing permissions @@ -4519,9 +4510,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - UUID targetID; - - if (!UUID.TryParse(target, out targetID)) + if (!UUID.TryParse(target, out UUID targetID)) return; if ((m_item.PermsMask & ScriptBaseClass.PERMISSION_CHANGE_LINKS) == 0 @@ -4536,12 +4525,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void CreateLink(string target, int parent) { - UUID targetID; - - if (!UUID.TryParse(target, out targetID)) + if (!UUID.TryParse(target, out UUID targetID)) return; - SceneObjectPart targetPart = World.GetSceneObjectPart((UUID)targetID); + SceneObjectPart targetPart = World.GetSceneObjectPart(targetID); if (targetPart == null) return; @@ -4900,8 +4887,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } // destination is an avatar - string message; - InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out message); + InventoryItemBase agentItem = World.MoveTaskInventoryItem(destId, UUID.Zero, m_host, objId, out string message); if (agentItem == null) { @@ -4920,9 +4906,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api agentItem.ID, true, m_host.AbsolutePosition, bucket, true); - ScenePresence sp; - - if (World.TryGetScenePresence(destId, out sp)) + if (World.TryGetScenePresence(destId, out ScenePresence sp)) { sp.ControllingClient.SendInstantMessage(msg); } @@ -4982,14 +4966,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - UUID uuid; - if (UUID.TryParse(id, out uuid)) + if (UUID.TryParse(id, out UUID uuid)) { PresenceInfo pinfo = null; UserAccount account; - UserInfoCacheEntry ce; - if (!m_userInfoCache.TryGetValue(uuid, out ce)) + if (!m_userInfoCache.TryGetValue(uuid, out UserInfoCacheEntry ce)) { account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); if (account == null) @@ -5010,10 +4992,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - ce = new UserInfoCacheEntry(); - ce.time = Util.EnvironmentTickCount(); - ce.account = account; - ce.pinfo = pinfo; + ce = new UserInfoCacheEntry + { + time = Util.EnvironmentTickCount(), + account = account, + pinfo = pinfo + }; m_userInfoCache[uuid] = ce; } else @@ -5079,12 +5063,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api UUID rq = UUID.Random(); - UUID tid = AsyncCommands. + UUID tid = m_AsyncCommands. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); - AsyncCommands. - DataserverPlugin.DataserverReply(rq.ToString(), reply); + m_AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), reply); ScriptSleep(m_sleepMsOnRequestAgentData); return tid.ToString(); @@ -5104,7 +5087,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (item.Type == 3 && item.Name == name) { - UUID tid = AsyncCommands. + UUID tid = m_AsyncCommands. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, item.AssetID.ToString()); @@ -5120,7 +5103,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api region = lm.Position + new Vector3(rx, ry, 0) - region; string reply = region.ToString(); - AsyncCommands. + m_AsyncCommands. DataserverPlugin.DataserverReply(i.ToString(), reply); }); @@ -5347,8 +5330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { // This should only return a value if the avatar is in the same region m_host.AddScriptLPS(1); - UUID avatar; - if(!UUID.TryParse(id, out avatar)) + if(!UUID.TryParse(id, out UUID avatar)) return ""; ScenePresence presence = World.GetScenePresence(avatar); if (presence == null) @@ -5364,9 +5346,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // return "Sitting"; string movementAnimation = presence.Animator.CurrentMovementAnimation; - string lslMovementAnimation; - - if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out lslMovementAnimation)) + if (MovementAnimationsForLSL.TryGetValue(movementAnimation, out string lslMovementAnimation)) return lslMovementAnimation; } } @@ -5589,7 +5569,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - return m_item.Name != null ? m_item.Name : String.Empty; + return m_item.Name ?? String.Empty; } public LSL_Integer llGetLinkNumberOfSides(int link) @@ -5931,9 +5911,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // valid keys seem to get parsed as integers then converted to floats if (item is LSL_Key) { - UUID uuidt; string s = item.ToString(); - if(UUID.TryParse(s, out uuidt)) + if(UUID.TryParse(s, out UUID uuidt)) return Convert.ToDouble(new LSL_Integer(s).value); // we can't do this because a string is also a LSL_Key for now :( // else @@ -5953,8 +5932,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m != Match.Empty) { str = m.Value; - double d = 0.0; - if (!Double.TryParse(str, out d)) + if (!Double.TryParse(str, out double d)) return 0.0; return d; } @@ -6093,8 +6071,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return 2; if (src.Data[index] is LSL_String || src.Data[index] is String) { - UUID tuuid; - if (UUID.TryParse(src.Data[index].ToString(), out tuuid)) + if (UUID.TryParse(src.Data[index].ToString(), out UUID tuuid)) { return 4; } @@ -6543,13 +6520,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String llGetObjectName() { m_host.AddScriptLPS(1); - return m_host.Name !=null ? m_host.Name : String.Empty; + return m_host.Name ?? string.Empty; } public void llSetObjectName(string name) { m_host.AddScriptLPS(1); - m_host.Name = name != null ? name : String.Empty; + m_host.Name = name ?? String.Empty; } public LSL_String llGetDate() @@ -6935,8 +6912,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api private void SetTextureAnim(SceneObjectPart part, int mode, int face, int sizex, int sizey, double start, double length, double rate) { - Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation(); - pTexAnim.Flags = (Primitive.TextureAnimMode)mode; + Primitive.TextureAnimation pTexAnim = new Primitive.TextureAnimation + { + Flags = (Primitive.TextureAnimMode)mode + }; //ALL_SIDES if (face == ScriptBaseClass.ALL_SIDES) @@ -7042,8 +7021,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Vector llGetAgentSize(LSL_Key id) { m_host.AddScriptLPS(1); - UUID avID; - if(!UUID.TryParse(id, out avID)) + + if(!UUID.TryParse(id, out UUID avID)) return ScriptBaseClass.ZERO_VECTOR; ScenePresence avatar = World.GetScenePresence(avID); @@ -7204,10 +7183,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api v1.Normalize(); //Find the cross product of the vectors (the slope normal). - Vector3 vsn = new Vector3(); - vsn.X = (v0.Y * v1.Z) - (v0.Z * v1.Y); - vsn.Y = (v0.Z * v1.X) - (v0.X * v1.Z); - vsn.Z = (v0.X * v1.Y) - (v0.Y * v1.X); + Vector3 vsn = new Vector3 + { + X = (v0.Y * v1.Z) - (v0.Z * v1.Y), + Y = (v0.Z * v1.X) - (v0.X * v1.Z), + Z = (v0.X * v1.Y) - (v0.Y * v1.X) + }; vsn.Normalize(); //I believe the crossproduct of two normalized vectors is a normalized vector so //this normalization may be overkill @@ -7232,8 +7213,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - UUID avID; - if(!UUID.TryParse(id, out avID)) + if(!UUID.TryParse(id, out UUID avID)) return new LSL_List("NOT_FOUND"); ScenePresence av = World.GetScenePresence(avID); @@ -7345,24 +7325,24 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected Primitive.ParticleSystem getNewParticleSystemWithSLDefaultValues() { - Primitive.ParticleSystem ps = new Primitive.ParticleSystem(); - - // TODO find out about the other defaults and add them here - ps.PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f); - ps.PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f); - ps.PartStartScaleX = 1.0f; - ps.PartStartScaleY = 1.0f; - ps.PartEndScaleX = 1.0f; - ps.PartEndScaleY = 1.0f; - ps.BurstSpeedMin = 1.0f; - ps.BurstSpeedMax = 1.0f; - ps.BurstRate = 0.1f; - ps.PartMaxAge = 10.0f; - ps.BurstPartCount = 1; - ps.BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA; - ps.BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA; - ps.PartStartGlow = 0.0f; - ps.PartEndGlow = 0.0f; + Primitive.ParticleSystem ps = new Primitive.ParticleSystem + { + PartStartColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f), + PartEndColor = new Color4(1.0f, 1.0f, 1.0f, 1.0f), + PartStartScaleX = 1.0f, + PartStartScaleY = 1.0f, + PartEndScaleX = 1.0f, + PartEndScaleY = 1.0f, + BurstSpeedMin = 1.0f, + BurstSpeedMax = 1.0f, + BurstRate = 0.1f, + PartMaxAge = 10.0f, + BurstPartCount = 1, + BlendFuncSource = ScriptBaseClass.PSYS_PART_BF_SOURCE_ALPHA, + BlendFuncDest = ScriptBaseClass.PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA, + PartStartGlow = 0.0f, + PartEndGlow = 0.0f + }; return ps; } @@ -7825,14 +7805,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - UUID destID; - if (!UUID.TryParse(destination, out destID)) + if (!UUID.TryParse(destination, out UUID destID)) return; - SceneObjectPart destsop = null; ScenePresence sp = null; bool isNotOwner = true; - if (!World.TryGetSceneObjectPart(destID, out destsop)) + if (!World.TryGetSceneObjectPart(destID, out SceneObjectPart destsop)) { if (!World.TryGetScenePresence(destID, out sp)) { @@ -8046,16 +8024,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llAddToLandPassList(LSL_Key avatar, LSL_Float hours) { m_host.AddScriptLPS(1); - UUID key; - ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); + ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false)) { int expires = 0; if (hours != 0) expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours); - if (UUID.TryParse(avatar, out key)) + if (UUID.TryParse(avatar, out UUID key)) { int idx = land.LandData.ParcelAccessList.FindIndex( delegate(LandAccessEntry e) @@ -8071,11 +8048,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (idx != -1) land.LandData.ParcelAccessList.RemoveAt(idx); - LandAccessEntry entry = new LandAccessEntry(); - - entry.AgentID = key; - entry.Flags = AccessList.Access; - entry.Expires = expires; + LandAccessEntry entry = new LandAccessEntry + { + AgentID = key, + Flags = AccessList.Access, + Expires = expires + }; land.LandData.ParcelAccessList.Add(entry); @@ -8786,9 +8764,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return; ObjectShapePacket.ObjectDataBlock shapeBlock = new ObjectShapePacket.ObjectDataBlock(); - UUID sculptId; - if (!UUID.TryParse(map, out sculptId)) + if (!UUID.TryParse(map, out UUID sculptId)) sculptId = ScriptUtils.GetAssetIdFromItemName(m_host, map, (int)AssetType.Texture); if (sculptId == UUID.Zero) @@ -8961,9 +8938,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (remain < elemLength) break; - KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe(); - frame.Position = null; - frame.Rotation = null; + KeyframeMotion.Keyframe frame = new KeyframeMotion.Keyframe + { + Position = null, + Rotation = null + }; if (hasTranslation) { @@ -9041,12 +9020,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api float material_density, float material_friction, float material_restitution, float material_gravity_modifier) { - ExtraPhysicsData physdata = new ExtraPhysicsData(); - physdata.PhysShapeType = (PhysShapeType)part.PhysicsShapeType; - physdata.Density = part.Density; - physdata.Friction = part.Friction; - physdata.Bounce = part.Restitution; - physdata.GravitationModifier = part.GravityModifier; + ExtraPhysicsData physdata = new ExtraPhysicsData + { + PhysShapeType = (PhysShapeType)part.PhysicsShapeType, + Density = part.Density, + Friction = part.Friction, + Bounce = part.Restitution, + GravitationModifier = part.GravityModifier + }; if ((material_bits & (int)ScriptBaseClass.DENSITY) != 0) physdata.Density = material_density; @@ -10152,11 +10133,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LSL_List(); } - ExtraPhysicsData physdata = new ExtraPhysicsData(); - physdata.Density = part.Density; - physdata.Bounce = part.Restitution; - physdata.GravitationModifier = part.GravityModifier; - physdata.PhysShapeType = (PhysShapeType)shape_type; + ExtraPhysicsData physdata = new ExtraPhysicsData + { + Density = part.Density, + Bounce = part.Restitution, + GravitationModifier = part.GravityModifier, + PhysShapeType = (PhysShapeType)shape_type + }; part.UpdateExtraPhysics(physdata); @@ -11129,8 +11112,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { m_host.AddScriptLPS(1); - UUID avID; - if(!UUID.TryParse(id, out avID)) + if(!UUID.TryParse(id, out UUID avID)) return new LSL_List(); ScenePresence av = World.GetScenePresence(avID); @@ -11210,13 +11192,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_String llGetObjectDesc() { - return m_host.Description!=null?m_host.Description:String.Empty; + return m_host.Description ?? String.Empty; } public void llSetObjectDesc(string desc) { m_host.AddScriptLPS(1); - m_host.Description = desc!=null?desc:String.Empty; + m_host.Description = desc ?? String.Empty; } public LSL_Key llGetCreator() @@ -11340,13 +11322,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return result; } - float minX; - float maxX; - float minY; - float maxY; - float minZ; - float maxZ; - sog.GetBoundingBox(out minX, out maxX, out minY, out maxY, out minZ, out maxZ); + sog.GetBoundingBox(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ); result.Add(new LSL_Vector(minX, minY, minZ)); result.Add(new LSL_Vector(maxX, maxY, maxZ)); @@ -11403,7 +11379,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_List remaining = GetPrimParams(m_host, rules, ref result); - while ((object)remaining != null && remaining.Length > 1) + while (!(remaining is null) && remaining.Length > 1) { int linknumber = remaining.GetLSLIntegerItem(0); rules = remaining.GetSublist(1, -1); @@ -13055,8 +13031,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (isHypergridRegion) { - uint rx = 0, ry = 0; - Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out rx, out ry); + Utils.LongToUInts(Convert.ToUInt64(info.RegionSecret), out uint rx, out uint ry); reply = new LSL_Vector( rx, @@ -13103,10 +13078,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } UUID rq = UUID.Random(); - UUID tid = AsyncCommands. + UUID tid = m_AsyncCommands. DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); - AsyncCommands. + m_AsyncCommands. DataserverPlugin.DataserverReply(rq.ToString(), reply); ScriptSleep(m_sleepMsOnRequestSimulatorData); @@ -13309,8 +13284,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (commandList.Data[i + 1] is LSL_String) { - UUID agentID; - if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out agentID)) + if (UUID.TryParse((LSL_String)commandList.Data[i + 1], out UUID agentID)) { presence = World.GetScenePresence(agentID); if(presence == null || presence.IsNPC) @@ -13587,10 +13561,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llModPow(int a, int b, int c) { m_host.AddScriptLPS(1); - Int64 tmp = 0; - Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out tmp); + Math.DivRem(Convert.ToInt64(Math.Pow(a, b)), c, out long tmp); ScriptSleep(m_sleepMsOnModPow); - return Convert.ToInt32(tmp); + return (int)tmp; } public LSL_Integer llGetInventoryType(string name) @@ -13724,8 +13697,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { if (m_host.ParentGroup.IsAttachment == true) { - detectedParams = new DetectParams(); - detectedParams.Key = m_host.OwnerID; + detectedParams = new DetectParams + { + Key = m_host.OwnerID + }; } else { @@ -13745,7 +13720,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llAddToLandBanList(LSL_Key avatar, LSL_Float hours) { m_host.AddScriptLPS(1); - UUID key; + ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false)) { @@ -13753,7 +13728,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (hours != 0) expires = Util.UnixTimeSinceEpoch() + (int)(3600.0 * hours); - if (UUID.TryParse(avatar, out key)) + if (UUID.TryParse(avatar, out UUID key)) { int idx = land.LandData.ParcelAccessList.FindIndex( delegate(LandAccessEntry e) @@ -13769,11 +13744,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (idx != -1) land.LandData.ParcelAccessList.RemoveAt(idx); - LandAccessEntry entry = new LandAccessEntry(); - - entry.AgentID = key; - entry.Flags = AccessList.Ban; - entry.Expires = expires; + LandAccessEntry entry = new LandAccessEntry + { + AgentID = key, + Flags = AccessList.Ban, + Expires = expires + }; land.LandData.ParcelAccessList.Add(entry); @@ -13786,11 +13762,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llRemoveFromLandPassList(string avatar) { m_host.AddScriptLPS(1); - UUID key; + ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManagePasses, false)) { - if (UUID.TryParse(avatar, out key)) + if (UUID.TryParse(avatar, out UUID key)) { int idx = land.LandData.ParcelAccessList.FindIndex( delegate(LandAccessEntry e) @@ -13813,11 +13789,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void llRemoveFromLandBanList(string avatar) { m_host.AddScriptLPS(1); - UUID key; + ILandObject land = World.LandChannel.GetLandObject(m_host.AbsolutePosition); if (World.Permissions.CanEditParcelProperties(m_host.OwnerID, land, GroupPowers.LandManageBanned, false)) { - if (UUID.TryParse(avatar, out key)) + if (UUID.TryParse(avatar, out UUID key)) { int idx = land.LandData.ParcelAccessList.FindIndex( delegate(LandAccessEntry e) @@ -14120,12 +14096,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api List param = new List(); bool ok; - Int32 flag; int nCustomHeaders = 0; for (int i = 0; i < parameters.Data.Length; i += 2) { - ok = Int32.TryParse(parameters.Data[i].ToString(), out flag); + ok = Int32.TryParse(parameters.Data[i].ToString(), out int flag); if (!ok || flag < 0 || flag > (int)HttpRequestConstants.HTTP_PRAGMA_NO_CACHE) { @@ -14287,8 +14262,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } } - HttpInitialRequestStatus status; - UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, out status); + UUID reqID = httpScriptMod.StartHttpRequest(m_host.LocalId, m_item.ItemID, url, param, httpHeaders, body, + out HttpInitialRequestStatus status); if (status == HttpInitialRequestStatus.DISALLOWED_BY_FILTER) Error("llHttpRequest", string.Format("Request to {0} disallowed by filter", url)); @@ -14409,8 +14384,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public LSL_Integer llGetObjectPrimCount(LSL_Key object_id) { m_host.AddScriptLPS(1); - UUID id; - if(!UUID.TryParse(object_id, out id)) + + if(!UUID.TryParse(object_id, out UUID id)) return 0; SceneObjectPart part = World.GetSceneObjectPart(id); @@ -15074,11 +15049,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api string reqIdentifier = UUID.Random().ToString(); // was: UUID tid = tid = AsyncCommands. - UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); + UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); if (NotecardCache.IsCached(assetID)) { - AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString()); + m_AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(assetID).ToString()); ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines); return tid.ToString(); @@ -15093,7 +15068,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } NotecardCache.Cache(id, a.Data); - AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString()); + m_AsyncCommands.DataserverPlugin.DataserverReply(reqIdentifier, NotecardCache.GetLines(id).ToString()); }); ScriptSleep(m_sleepMsOnGetNumberOfNotecardLines); @@ -15125,11 +15100,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api string reqIdentifier = UUID.Random().ToString(); // was: UUID tid = tid = AsyncCommands. - UUID tid = AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); + UUID tid = m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, reqIdentifier); if (NotecardCache.IsCached(assetID)) { - AsyncCommands.DataserverPlugin.DataserverReply( + m_AsyncCommands.DataserverPlugin.DataserverReply( reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); ScriptSleep(m_sleepMsOnGetNotecardLine); @@ -15147,7 +15122,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api //string data = Encoding.UTF8.GetString(a.Data); //m_log.Debug(data); NotecardCache.Cache(id, a.Data); - AsyncCommands.DataserverPlugin.DataserverReply( + m_AsyncCommands.DataserverPlugin.DataserverReply( reqIdentifier, NotecardCache.GetLine(assetID, line, m_notecardLineReadCharsMax)); }); @@ -15157,8 +15132,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void SetPrimitiveParamsEx(LSL_Key prim, LSL_List rules, string originFunc) { - UUID id; - if (!UUID.TryParse(prim, out id)) + if (!UUID.TryParse(prim, out UUID id)) return; SceneObjectPart obj = World.GetSceneObjectPart(id); if (obj == null || obj.OwnerID != m_host.OwnerID) @@ -15199,8 +15173,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { LSL_List result = new LSL_List(); - UUID id; - if (!UUID.TryParse(prim, out id)) + if (!UUID.TryParse(prim, out UUID id)) return result; SceneObjectPart obj = World.GetSceneObjectPart(id); @@ -15279,9 +15252,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { UUID rq = UUID.Random(); - AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); + m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); - AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); + m_AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), Name2Username(llKey2Name(id))); return rq.ToString(); } @@ -15295,9 +15268,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { UUID rq = UUID.Random(); - AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); + m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, rq.ToString()); - AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); + m_AsyncCommands.DataserverPlugin.DataserverReply(rq.ToString(), llKey2Name(id)); return rq.ToString(); } @@ -15357,11 +15330,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!InBoundingBox(sp, p)) return; - ContactResult result = new ContactResult (); - result.ConsumerID = sp.LocalId; - result.Depth = Vector3.Distance(rayStart, p); - result.Normal = Vector3.Zero; - result.Pos = p; + ContactResult result = new ContactResult + { + ConsumerID = sp.LocalId, + Depth = Vector3.Distance(rayStart, p), + Normal = Vector3.Zero, + Pos = p + }; contacts.Add(result); }); @@ -15404,16 +15379,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } // Find the radius ouside of which we don't even need to hit test - float minX; - float maxX; - float minY; - float maxY; - float minZ; - float maxZ; - float radius = 0.0f; - - group.GetAxisAlignedBoundingBoxRaw(out minX, out maxX, out minY, out maxY, out minZ, out maxZ); + group.GetAxisAlignedBoundingBoxRaw(out float minX, out float maxX, out float minY, out float maxY, out float minZ, out float maxZ); if (Math.Abs(minX) > radius) radius = Math.Abs(minX); @@ -15456,11 +15423,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api intersection.ipoint.Z >= b1.Z && intersection.ipoint.Z <= b2.Z)) return; - ContactResult result = new ContactResult (); - result.ConsumerID = group.LocalId; -// result.Depth = intersection.distance; - result.Normal = intersection.normal; - result.Pos = intersection.ipoint; + ContactResult result = new ContactResult + { + ConsumerID = group.LocalId, + //Depth = intersection.distance; + Normal = intersection.normal, + Pos = intersection.ipoint + }; result.Depth = Vector3.Mag(rayStart - result.Pos); contacts.Add(result); @@ -15575,11 +15544,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api continue; // Add contact point - ContactResult result = new ContactResult (); - result.ConsumerID = 0; - result.Depth = Vector3.Distance(rayStart, ip); - result.Normal = n; - result.Pos = ip; + ContactResult result = new ContactResult + { + ConsumerID = 0, + Depth = Vector3.Distance(rayStart, ip), + Normal = n, + Pos = ip + }; contacts.Add(result); } @@ -16001,17 +15972,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax)) { // Prepare data needed to check for ray hits - RayTrans rayTrans = new RayTrans(); - rayTrans.PartId = part.UUID; - rayTrans.GroupId = part.ParentGroup.UUID; - rayTrans.Link = group.PrimCount > 1 ? part.LinkNum : 0; - rayTrans.ScalePart = scalePart; - rayTrans.PositionPart = posPart; - rayTrans.RotationPart = rotPart; - rayTrans.ShapeNeedsEnds = true; - rayTrans.Position1Ray = pos1Ray; - rayTrans.Position1RayProj = pos1RayProj; - rayTrans.VectorRayProj = pos2RayProj - pos1RayProj; + RayTrans rayTrans = new RayTrans + { + PartId = part.UUID, + GroupId = part.ParentGroup.UUID, + Link = group.PrimCount > 1 ? part.LinkNum : 0, + ScalePart = scalePart, + PositionPart = posPart, + RotationPart = rotPart, + ShapeNeedsEnds = true, + Position1Ray = pos1Ray, + Position1RayProj = pos1RayProj, + VectorRayProj = pos2RayProj - pos1RayProj + }; // Get detail level depending on type int lod = 0; @@ -16109,9 +16082,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api delegate (ScenePresence sp) { // Get bounding box - Vector3 lower; - Vector3 upper; - BoundingBoxOfScenePresence(sp, out lower, out upper); + BoundingBoxOfScenePresence(sp, out Vector3 lower, out Vector3 upper); // Parse avatar Vector3 scalePart = upper - lower; Vector3 posPart = sp.AbsolutePosition; @@ -16127,17 +16098,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (RayIntersectsShapeBox(pos1RayProj, pos2RayProj, shapeBoxMax)) { // Prepare data needed to check for ray hits - RayTrans rayTrans = new RayTrans(); - rayTrans.PartId = sp.UUID; - rayTrans.GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID; - rayTrans.Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0; - rayTrans.ScalePart = scalePart; - rayTrans.PositionPart = posPart; - rayTrans.RotationPart = rotPart; - rayTrans.ShapeNeedsEnds = false; - rayTrans.Position1Ray = pos1Ray; - rayTrans.Position1RayProj = pos1RayProj; - rayTrans.VectorRayProj = pos2RayProj - pos1RayProj; + RayTrans rayTrans = new RayTrans + { + PartId = sp.UUID, + GroupId = sp.ParentPart != null ? sp.ParentPart.ParentGroup.UUID : sp.UUID, + Link = sp.ParentPart != null ? UUID2LinkNumber(sp.ParentPart, sp.UUID) : 0, + ScalePart = scalePart, + PositionPart = posPart, + RotationPart = rotPart, + ShapeNeedsEnds = false, + Position1Ray = pos1Ray, + Position1RayProj = pos1RayProj, + VectorRayProj = pos2RayProj - pos1RayProj + }; // Try to get cached mesh if configured PrimitiveBaseShape prim = PrimitiveBaseShape.CreateSphere(); @@ -16185,25 +16158,25 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Parse terrain // Mesh terrain and check bounding box - Vector3 lower; - Vector3 upper; - List triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out lower, out upper); + List triangles = TrisFromHeightmapUnderRay(pos1Ray, pos2Ray, out Vector3 lower, out Vector3 upper); lower.Z -= tol; upper.Z += tol; if ((pos1Ray.Z >= lower.Z || pos2Ray.Z >= lower.Z) && (pos1Ray.Z <= upper.Z || pos2Ray.Z <= upper.Z)) { // Prepare data needed to check for ray hits - RayTrans rayTrans = new RayTrans(); - rayTrans.PartId = UUID.Zero; - rayTrans.GroupId = UUID.Zero; - rayTrans.Link = 0; - rayTrans.ScalePart = new Vector3 (1.0f, 1.0f, 1.0f); - rayTrans.PositionPart = Vector3.Zero; - rayTrans.RotationPart = Quaternion.Identity; - rayTrans.ShapeNeedsEnds = true; - rayTrans.Position1Ray = pos1Ray; - rayTrans.Position1RayProj = pos1Ray; - rayTrans.VectorRayProj = vecRay; + RayTrans rayTrans = new RayTrans + { + PartId = UUID.Zero, + GroupId = UUID.Zero, + Link = 0, + ScalePart = new Vector3(1.0f, 1.0f, 1.0f), + PositionPart = Vector3.Zero, + RotationPart = Quaternion.Identity, + ShapeNeedsEnds = true, + Position1Ray = pos1Ray, + Position1RayProj = pos1Ray, + VectorRayProj = vecRay + }; // Check mesh AddRayInTris(triangles, rayTrans, ref rayHits); @@ -16282,11 +16255,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api stopWatch.Stop(); lock (m_castRayCalls) { - CastRayCall castRayCall = new CastRayCall(); - castRayCall.RegionId = regionId; - castRayCall.UserId = userId; - castRayCall.CalledMs = calledMs; - castRayCall.UsedMs = (int)stopWatch.ElapsedMilliseconds; + CastRayCall castRayCall = new CastRayCall + { + RegionId = regionId, + UserId = userId, + CalledMs = calledMs, + UsedMs = (int)stopWatch.ElapsedMilliseconds + }; m_castRayCalls.Add(castRayCall); } @@ -16406,10 +16381,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { for (int i = 0; i < face.Indices.Count; i += 3) { - Tri triangle = new Tri(); - triangle.p1 = face.Vertices[face.Indices[i]].Position; - triangle.p2 = face.Vertices[face.Indices[i + 1]].Position; - triangle.p3 = face.Vertices[face.Indices[i + 2]].Position; + Tri triangle = new Tri + { + p1 = face.Vertices[face.Indices[i]].Position, + p2 = face.Vertices[face.Indices[i + 1]].Position, + p3 = face.Vertices[face.Indices[i + 2]].Position + }; AddRayInTri(triangle, rayTrans, ref rayHits); } } @@ -16433,9 +16410,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api private void AddRayInTri(Tri triProj, RayTrans rayTrans, ref List rayHits) { // Check for hit in triangle - Vector3 posHitProj; - Vector3 normalProj; - if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out posHitProj, out normalProj)) + if (HitRayInTri(triProj, rayTrans.Position1RayProj, rayTrans.VectorRayProj, out Vector3 posHitProj, out Vector3 normalProj)) { // Hack to circumvent ghost face bug in PrimMesher by removing hits in (ghost) face plane through shape center if (Math.Abs(Vector3.Dot(posHitProj, normalProj)) < m_floatToleranceInCastRay && !rayTrans.ShapeNeedsEnds) @@ -16456,13 +16431,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } // Build result data set - RayHit rayHit = new RayHit(); - rayHit.PartId = rayTrans.PartId; - rayHit.GroupId = rayTrans.GroupId; - rayHit.Link = rayTrans.Link; - rayHit.Position = posHit; - rayHit.Normal = normal; - rayHit.Distance = distance; + RayHit rayHit = new RayHit + { + PartId = rayTrans.PartId, + GroupId = rayTrans.GroupId, + Link = rayTrans.Link, + Position = posHit, + Normal = normal, + Distance = distance + }; rayHits.Add(rayHit); } } @@ -16660,17 +16637,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api zUpper = Math.Max(zUpper, pos4.Z); // Add triangle 1 - Tri triangle1 = new Tri(); - triangle1.p1 = pos1; - triangle1.p2 = pos2; - triangle1.p3 = pos3; + Tri triangle1 = new Tri + { + p1 = pos1, + p2 = pos2, + p3 = pos3 + }; triangles.Add(triangle1); // Add triangle 2 - Tri triangle2 = new Tri(); - triangle2.p1 = pos3; - triangle2.p2 = pos4; - triangle2.p3 = pos1; + Tri triangle2 = new Tri + { + p1 = pos3, + p2 = pos4, + p3 = pos1 + }; triangles.Add(triangle2); } @@ -16751,9 +16732,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_ADD: if (!isAccount) return 0; if (estate.IsBanned(id, World.GetUserFlags(id))) return 1; - EstateBan ban = new EstateBan(); - ban.EstateID = estate.EstateID; - ban.BannedUserID = id; + EstateBan ban = new EstateBan + { + EstateID = estate.EstateID, + BannedUserID = id + }; estate.AddBan(ban); break; case ScriptBaseClass.ESTATE_ACCESS_BANNED_AGENT_REMOVE: @@ -16941,9 +16924,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return; } - string reason; - bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, toID, amount, txn, out reason); - + bool result = money.ObjectGiveMoney( m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, + toID, amount, txn, out string reason); if (result) { replycode = 1; @@ -18136,14 +18118,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } LitJson.JsonData newval = null; - float num; if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null") newval = null; else if(val == ScriptBaseClass.JSON_TRUE || val == "true") newval = new LitJson.JsonData(true); else if(val == ScriptBaseClass.JSON_FALSE || val == "false") newval = new LitJson.JsonData(false); - else if(float.TryParse(val, out num)) + else if(float.TryParse(val, out float num)) { // assuming we are at en.us already if(num - (int)num == 0.0f && !val.Contains(".")) @@ -18197,7 +18178,6 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api object spec = level >= specifiers.Data.Length ? null : specifiers.Data[level]; // 20131224 not used object specNext = i+1 >= specifiers.Data.Length ? null : specifiers.Data[i+1]; - float num; if (spec == null) { if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null") @@ -18210,7 +18190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return new LitJson.JsonData(false); if(val == null || val == ScriptBaseClass.JSON_NULL || val == "null") return null; - if(float.TryParse(val, out num)) + if(float.TryParse(val, out float num)) { // assuming we are at en.us already if(num - (int)num == 0.0f && !val.Contains(".")) @@ -18477,9 +18457,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (m_Notecards.ContainsKey(assetID)) return; - Notecard nc = new Notecard(); - nc.lastRef = DateTime.Now; - nc.text = SLUtil.ParseNotecardToArray(text); + Notecard nc = new Notecard + { + lastRef = DateTime.Now, + text = SLUtil.ParseNotecardToArray(text) + }; m_Notecards[assetID] = nc; } } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs index 8d489ae1a2..02ddd133cf 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs @@ -139,7 +139,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // shared things private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); - private static object m_OSSLLock = new object(); + private static readonly object m_OSSLLock = new object(); private static bool m_doneSharedInit = false; internal static bool m_OSFunctionsEnabled = false; internal static TimeZoneInfo PSTTimeZone = null; @@ -342,8 +342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // or a string explaining why this function can't be used. private string CheckThreatLevelTest(ThreatLevel level, string function) { - FunctionPerms perms; - if (!m_FunctionPerms.TryGetValue(function, out perms)) + if (!m_FunctionPerms.TryGetValue(function, out FunctionPerms perms)) { perms = new FunctionPerms(); @@ -744,12 +743,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (dm == null) return; - UUID avatarID; - if (!UUID.TryParse(agentID, out avatarID)) + if (!UUID.TryParse(agentID, out UUID avatarID)) return; - ScenePresence sp = null; - if (!World.TryGetScenePresence(avatarID, out sp)) + if (!World.TryGetScenePresence(avatarID, out ScenePresence sp)) return; if (sp == null || sp.IsChildAgent || sp.IsDeleted || sp.IsInTransit || sp.IsNPC) @@ -767,8 +764,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (World.Entities.ContainsKey(target)) { - EntityBase entity; - if (World.Entities.TryGetValue(target, out entity)) + if (World.Entities.TryGetValue(target, out EntityBase entity)) { if (entity is SceneObjectGroup) ((SceneObjectGroup)entity).UpdateGroupRotationR(rotation); @@ -1001,8 +997,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api // Teleport functions public void osLocalTeleportAgent(LSL_Key agent, LSL_Types.Vector3 position, LSL_Types.Vector3 velocity, LSL_Types.Vector3 lookat, LSL_Integer flags) { - UUID agentId; - if (!UUID.TryParse(agent, out agentId)) + if (!UUID.TryParse(agent, out UUID agentId)) return; ScenePresence presence = World.GetScenePresence(agentId); @@ -1031,21 +1026,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if(String.IsNullOrEmpty(regionName)) regionName = World.RegionInfo.RegionName; - UUID agentId; - if (UUID.TryParse(agent, out agentId)) + if (UUID.TryParse(agent, out UUID agentId)) { ScenePresence presence = World.GetScenePresence(agentId); if (presence == null || presence.IsDeleted || presence.IsInTransit) return; Vector3 pos = presence.AbsolutePosition; - if(!checkAllowAgentTPbyLandOwner(agentId, pos)) + if (!checkAllowAgentTPbyLandOwner(agentId, pos)) { ScriptSleep(500); return; } - if(regionName == World.RegionInfo.RegionName) + if (regionName == World.RegionInfo.RegionName) { // should be faster than going to threadpool World.RequestTeleportLocation(presence.ControllingClient, regionName, position, @@ -1054,14 +1048,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api } else { - // We will launch the teleport on a new thread so that when the script threads are terminated - // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. - Util.FireAndForget( - o => World.RequestTeleportLocation( - presence.ControllingClient, regionName, position, - lookat, (uint)TPFlags.ViaLocation), - null, "OSSL_Api.TeleportAgentByRegionCoords"); - ScriptSleep(5000); + // We will launch the teleport on a new thread so that when the script threads are terminated + // before teleport in ScriptInstance.GetXMLState(), we don't end up aborting the one doing the teleporting. + Util.FireAndForget( + o => World.RequestTeleportLocation( + presence.ControllingClient, regionName, position, + lookat, (uint)TPFlags.ViaLocation), + null, "OSSL_Api.TeleportAgentByRegionCoords"); + ScriptSleep(5000); } } } @@ -1080,15 +1074,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { ulong regionHandle = Util.RegionGridLocToHandle((uint)regionGridX, (uint)regionGridY); - UUID agentId; - if (UUID.TryParse(agent, out agentId)) + if (UUID.TryParse(agent, out UUID agentId)) { ScenePresence presence = World.GetScenePresence(agentId); if (presence == null || presence.IsDeleted || presence.IsInTransit) return; Vector3 pos = presence.AbsolutePosition; - if(!checkAllowAgentTPbyLandOwner(agentId, pos)) + if (!checkAllowAgentTPbyLandOwner(agentId, pos)) { ScriptSleep(500); return; @@ -1106,15 +1099,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void osTeleportAgent(string agent, LSL_Types.Vector3 position, LSL_Types.Vector3 lookat) { - UUID agentId; - if (UUID.TryParse(agent, out agentId)) + if (UUID.TryParse(agent, out UUID agentId)) { ScenePresence presence = World.GetScenePresence(agentId); if (presence == null || presence.IsDeleted || presence.IsInTransit) return; Vector3 pos = presence.AbsolutePosition; - if(!checkAllowAgentTPbyLandOwner(agentId, pos)) + if (!checkAllowAgentTPbyLandOwner(agentId, pos)) { ScriptSleep(500); return; @@ -1179,9 +1171,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api public void ForceSit(string avatar, UUID targetID) { - UUID agentID; - - if (!UUID.TryParse(avatar, out agentID)) + if (!UUID.TryParse(avatar, out UUID agentID)) return; ScenePresence presence = World.GetScenePresence(agentID); @@ -1235,8 +1225,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarPlayAnimation"); - UUID avatarID; - if(!UUID.TryParse(avatar, out avatarID)) + if (!UUID.TryParse(avatar, out UUID avatarID)) return; ScenePresence target = World.GetScenePresence(avatarID); @@ -1268,16 +1257,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.VeryHigh, "osAvatarStopAnimation"); - UUID avatarID; - if(!UUID.TryParse(avatar, out avatarID)) + if (!UUID.TryParse(avatar, out UUID avatarID)) return; ScenePresence target = World.GetScenePresence(avatarID); if (target == null) return; - UUID animID; - if (!UUID.TryParse(animation, out animID)) + if (!UUID.TryParse(animation, out UUID animID)) { TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation); if (item != null && item.Type == (int)AssetType.Animation) @@ -1490,9 +1477,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api IDynamicTextureManager textureManager = World.RequestModuleInterface(); if (textureManager != null) { - double xSize, ySize; textureManager.GetDrawStringSize(contentType, text, fontName, fontSize, - out xSize, out ySize); + out double xSize, out double ySize); vec.x = xSize; vec.y = ySize; } @@ -2134,8 +2120,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Low, "osMessageObject"); - UUID objUUID; - if (!UUID.TryParse(objectUUID, out objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead. + if (!UUID.TryParse(objectUUID, out UUID objUUID)) // prior to patching, a thrown exception regarding invalid GUID format would be shouted instead. { OSSLShoutError("osMessageObject() cannot send messages to objects with invalid UUIDs"); return; @@ -2174,8 +2159,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(ThreatLevel.Low, "osDie"); - UUID objUUID; - if (!UUID.TryParse(objectUUID, out objUUID)) + if (!UUID.TryParse(objectUUID, out UUID objUUID)) { OSSLShoutError("osDie() cannot delete objects with invalid UUIDs"); return; @@ -2249,8 +2233,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api protected TaskInventoryItem SaveNotecard(string name, string description, string data, bool forceSameName) { // Create new asset - AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()); - asset.Description = description; + AssetBase asset = new AssetBase(UUID.Random(), name, (sbyte)AssetType.Notecard, m_host.OwnerID.ToString()) + { + Description = description + }; byte[] a; byte[] b; byte[] c; @@ -2496,10 +2482,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return userID.ToString(); // HG ? - string realFirstName; - string realLastName; - string serverURI; - if (Util.ParseForeignAvatarName(firstname, lastname, out realFirstName, out realLastName, out serverURI)) + if (Util.ParseForeignAvatarName(firstname, lastname, out string realFirstName, out string realLastName, out string serverURI)) { try { @@ -2542,9 +2525,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (uInfo != null) { - UUID userUUID; String gridURL; String firstName; String lastName; String tmp; - if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out userUUID, out gridURL, out firstName, out lastName, out tmp)) + if (Util.ParseUniversalUserIdentifier(uInfo.UserID, out UUID userUUID, + out string gridURL, out string firstName, + out string lastName, out string tmp)) { string grid = new Uri(gridURL).Authority; return firstName + "." + lastName + " @" + grid; @@ -2934,8 +2918,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - UUID npcId; - if (UUID.TryParse(npc.m_string, out npcId)) + if (UUID.TryParse(npc.m_string, out UUID npcId)) if (module.IsNPC(npcId, World)) return ScriptBaseClass.TRUE; } @@ -3038,8 +3021,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if((createFlags & NPCOptionsFlags.AllowCloneOtherAvatars) != 0) { - UUID id; - if (UUID.TryParse(notecard, out id)) + if (UUID.TryParse(notecard, out UUID id)) { ScenePresence clonePresence = World.GetScenePresence(id); if (clonePresence != null) @@ -3086,8 +3068,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api World, appearance); - ScenePresence sp; - if (World.TryGetScenePresence(x, out sp)) + if (World.TryGetScenePresence(x, out ScenePresence sp)) { sp.SendAvatarDataToAllAgents(); } @@ -3139,8 +3120,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (npcModule != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return; if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) @@ -3169,8 +3149,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) { - UUID npcId; - if (UUID.TryParse(npc.m_string, out npcId)) + if (UUID.TryParse(npc.m_string, out UUID npcId)) { UUID owner = npcModule.GetOwner(npcId); if (owner != UUID.Zero) @@ -3190,8 +3169,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return new LSL_Vector(0, 0, 0); if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) @@ -3213,8 +3191,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return; if (!module.CheckPermissions(npcId, m_host.OwnerID)) @@ -3231,8 +3208,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule module = World.RequestModuleInterface(); if (module != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return; if (!module.CheckPermissions(npcId, m_host.OwnerID)) @@ -3255,8 +3231,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return new LSL_Rotation(Quaternion.Identity); if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) @@ -3278,8 +3253,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api INPCModule npcModule = World.RequestModuleInterface(); if (npcModule != null) { - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return; if (!npcModule.CheckPermissions(npcId, m_host.OwnerID)) @@ -3383,12 +3357,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (module == null) return; - UUID npcId; - if (!UUID.TryParse(npc.m_string, out npcId)) + if (!UUID.TryParse(npc.m_string, out UUID npcId)) return; - UUID TargetID; - if (!UUID.TryParse(target.m_string, out TargetID)) + if (!UUID.TryParse(target.m_string, out UUID TargetID)) return; if (!module.CheckPermissions(npcId, m_host.OwnerID)) @@ -3482,8 +3454,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (module == null) return; - UUID npcID; - if(!UUID.TryParse(npc.m_string, out npcID)) + if (!UUID.TryParse(npc.m_string, out UUID npcID)) return; ScenePresence target = World.GetScenePresence(npcID); @@ -3522,8 +3493,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (module == null) return; - UUID npcID; - if (!UUID.TryParse(npc.m_string, out npcID)) + if (!UUID.TryParse(npc.m_string, out UUID npcID)) return; ScenePresence target = World.GetScenePresence(npcID); @@ -3533,8 +3503,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (!module.CheckPermissions(npcID, m_host.OwnerID)) return; - UUID animID; - if (!UUID.TryParse(animation, out animID)) + if (!UUID.TryParse(animation, out UUID animID)) { TaskInventoryItem item = m_host.Inventory.GetInventoryItem(animation); if (item != null && item.Type == (int)AssetType.Animation) @@ -3573,13 +3542,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api int linkNum = link_num.value; if (module != null || (linkNum < 0 && linkNum != ScriptBaseClass.LINK_THIS)) { - UUID npcId; - if (!UUID.TryParse(npcLSL_Key, out npcId) || !module.CheckPermissions(npcId, m_host.OwnerID)) + if (!UUID.TryParse(npcLSL_Key, out UUID npcId) || !module.CheckPermissions(npcId, m_host.OwnerID)) return; SceneObjectPart part = null; - UUID objectId; - if (UUID.TryParse(LSL_String.ToString(object_key), out objectId)) + if (UUID.TryParse(LSL_String.ToString(object_key), out UUID objectId)) part = World.GetSceneObjectPart(objectId); if (part == null) @@ -3681,8 +3648,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.None, "osGetGender"); - UUID avatarId; - if (!UUID.TryParse(rawAvatarId, out avatarId)) + if (!UUID.TryParse(rawAvatarId, out UUID avatarId)) return new LSL_String("unknown"); ScenePresence sp = World.GetScenePresence(avatarId); @@ -3826,8 +3792,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Moderate, "osSetSpeed"); - UUID avid; - if(!UUID.TryParse(ID, out avid)) + if (!UUID.TryParse(ID, out UUID avid)) return; ScenePresence avatar = World.GetScenePresence(avid); @@ -3869,8 +3834,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Severe, "osKickAvatar"); - UUID id; - if (!UUID.TryParse(agentKey, out id) || id == UUID.Zero) + if (!UUID.TryParse(agentKey, out UUID id) || id == UUID.Zero) return; ScenePresence sp = World.GetScenePresence(id); @@ -3891,8 +3855,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Float health = new LSL_Float(-1); - UUID id; - if (!UUID.TryParse(agentKey, out id) || id == UUID.Zero) + if (!UUID.TryParse(agentKey, out UUID id) || id == UUID.Zero) return health; ScenePresence presence = World.GetScenePresence(id); @@ -3905,8 +3868,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.High, "osCauseDamage"); - UUID avatarId; - if (!UUID.TryParse(avatar, out avatarId)) + if (!UUID.TryParse(avatar, out UUID avatarId)) return; ScenePresence presence = World.GetScenePresence(avatarId); @@ -3934,8 +3896,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.High, "osCauseHealing"); - UUID avatarId; - if (!UUID.TryParse(avatar, out avatarId)) + if (!UUID.TryParse(avatar, out UUID avatarId)) return; ScenePresence presence = World.GetScenePresence(avatarId); @@ -3973,8 +3934,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.High, "osSetHealRate"); - UUID avatarId; - if (!UUID.TryParse(avatar, out avatarId)) + if (!UUID.TryParse(avatar, out UUID avatarId)) return; ScenePresence presence = World.GetScenePresence(avatarId); @@ -3990,8 +3950,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api LSL_Float rate = new LSL_Float(0); - UUID avatarId; - if (!UUID.TryParse(avatar, out avatarId)) + if (!UUID.TryParse(avatar, out UUID avatarId)) return rate; ScenePresence presence = World.GetScenePresence(avatarId); @@ -4282,9 +4241,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.VeryHigh, "osForceAttachToOtherAvatarFromInventory"); - UUID avatarId; - - if (!UUID.TryParse(rawAvatarId, out avatarId)) + if (!UUID.TryParse(rawAvatarId, out UUID avatarId)) return; ForceAttachToAvatarFromInventory(avatarId, itemName, attachmentPoint); @@ -4322,8 +4279,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (sp == null) return; - string message; - InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out message); + InventoryItemBase newItem = World.MoveTaskInventoryItem(sp.UUID, UUID.Zero, m_host, item.ItemID, out string message); if (newItem == null) { @@ -4349,11 +4305,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Moderate, "osGetNumberOfAttachments"); - UUID targetUUID; - ScenePresence target; LSL_List resp = new LSL_List(); - if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out targetUUID) && World.TryGetScenePresence(targetUUID, out target)) + if (attachmentPoints.Length >= 1 && UUID.TryParse(avatar.ToString(), out UUID targetUUID) && World.TryGetScenePresence(targetUUID, out ScenePresence target)) { foreach (object point in attachmentPoints.Data) { @@ -4383,18 +4337,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Moderate, "osMessageAttachments"); - UUID targetUUID; - if(!UUID.TryParse(avatar.ToString(), out targetUUID)) + if (!UUID.TryParse(avatar.ToString(), out UUID targetUUID)) return; - if(targetUUID == UUID.Zero) + if (targetUUID == UUID.Zero) return; - ScenePresence target; - if(!World.TryGetScenePresence(targetUUID, out target)) - return; + if (!World.TryGetScenePresence(targetUUID, out ScenePresence target)) + return; - if(target.IsDeleted || target.IsInTransit) + if (target.IsDeleted || target.IsInTransit) return; List aps = new List(); @@ -4402,8 +4354,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { foreach (object point in attachmentPoints.Data) { - int ipoint; - if (int.TryParse(point.ToString(), out ipoint)) + if (int.TryParse(point.ToString(), out int ipoint)) { aps.Add(ipoint); } @@ -4492,8 +4443,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(); - UUID test; - return UUID.TryParse(thing, out test) ? 1 : 0; + return UUID.TryParse(thing, out UUID test) ? 1 : 0; } /// @@ -4629,8 +4579,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Low, "osListenRegex"); - UUID keyID; - UUID.TryParse(ID, out keyID); + UUID.TryParse(ID, out UUID keyID); // if we want the name to be used as a regular expression, ensure it is valid first. if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME) @@ -4781,16 +4730,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api CheckThreatLevel(); LSL_List result = new LSL_List(); - float TotalMass; - Vector3 CenterOfMass; - Vector3 Inertia; - Vector4 aux; SceneObjectGroup sog = m_host.ParentGroup; - if(sog== null || sog.IsDeleted) + if (sog== null || sog.IsDeleted) return result; - sog.GetInertiaData(out TotalMass, out CenterOfMass, out Inertia, out aux ); + sog.GetInertiaData(out float TotalMass, out Vector3 CenterOfMass, out Vector3 Inertia, out Vector4 aux ); if(TotalMass > 0) { float t = 1.0f/TotalMass; @@ -5041,8 +4986,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api { CheckThreatLevel(ThreatLevel.Severe, "osTeleportObject"); - UUID objUUID; - if (!UUID.TryParse(objectUUID, out objUUID)) + if (!UUID.TryParse(objectUUID, out UUID objUUID)) { OSSLShoutError("osTeleportObject() invalid object Key"); return -1; @@ -5343,8 +5287,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api if (World.UserAccountService == null) return String.Empty; - UUID key; - if (!UUID.TryParse(id, out key)) + if (!UUID.TryParse(id, out UUID key)) return String.Empty; if (key == UUID.Zero) return String.Empty; @@ -5638,8 +5581,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); TaskInventoryItem item = null; - UUID itemID; - if (UUID.TryParse(itemNameorid, out itemID)) + if (UUID.TryParse(itemNameorid, out UUID itemID)) item = m_host.Inventory.GetInventoryItem(itemID); else item = m_host.Inventory.GetInventoryItem(itemNameorid); @@ -5677,8 +5619,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); TaskInventoryItem item = null; - UUID itemID; - if (UUID.TryParse(itemId, out itemID)) + if (UUID.TryParse(itemId, out UUID itemID)) item = m_host.Inventory.GetInventoryItem(itemID); if (item == null) @@ -5692,8 +5633,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api m_host.AddScriptLPS(1); TaskInventoryItem item = null; - UUID itemID; - if (UUID.TryParse(itemNameorid, out itemID)) + if (UUID.TryParse(itemNameorid, out UUID itemID)) item = m_host.Inventory.GetInventoryItem(itemID); else item = m_host.Inventory.GetInventoryItem(itemNameorid); @@ -6100,4 +6040,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return 1; } } -} +} \ No newline at end of file diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs index 2b37adce20..f8b73220a8 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/SensorRepeat.cs @@ -88,7 +88,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins private INPCModule m_npcModule; - private Object SenseLock = new Object(); + private readonly object SenseLock = new object(); private const int AGENT = 1; private const int AGENT_BY_USERNAME = 0x10; @@ -133,7 +133,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins /// Always lock SenseRepeatListLock when updating this list. /// private List SenseRepeaters = new List(); - private object SenseRepeatListLock = new object(); + private readonly object SenseRepeatListLock = new object(); public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID, string name, UUID keyID, int type, double range, @@ -146,13 +146,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins return; // Add to timer - SensorInfo ts = new SensorInfo(); - ts.localID = m_localID; - ts.itemID = m_itemID; - ts.interval = sec; - ts.name = name; - ts.keyID = keyID; - ts.type = type; + SensorInfo ts = new SensorInfo + { + localID = m_localID, + itemID = m_itemID, + interval = sec, + name = name, + keyID = keyID, + type = type + }; if (range > maximumRange) ts.range = maximumRange; else @@ -169,8 +171,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { lock (SenseRepeatListLock) { - List newSenseRepeaters = new List(SenseRepeaters); - newSenseRepeaters.Add(senseRepeater); + List newSenseRepeaters = new List(SenseRepeaters) + { + senseRepeater + }; SenseRepeaters = newSenseRepeaters; } } @@ -219,13 +223,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins double range, double arc, SceneObjectPart host) { // Add to timer - SensorInfo ts = new SensorInfo(); - ts.localID = m_localID; - ts.itemID = m_itemID; - ts.interval = 0; - ts.name = name; - ts.keyID = keyID; - ts.type = type; + SensorInfo ts = new SensorInfo + { + localID = m_localID, + itemID = m_itemID, + interval = 0, + name = name, + keyID = keyID, + type = type + }; if (range > maximumRange) ts.range = maximumRange; else @@ -277,8 +283,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins { try { - DetectParams detect = new DetectParams(); - detect.Key = sensedEntities[idx].itemID; + DetectParams detect = new DetectParams + { + Key = sensedEntities[idx].itemID + }; detect.Populate(m_CmdManager.m_ScriptEngine.World); detected.Add(detect); } @@ -320,12 +328,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { - EntityBase e = null; - m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out e); + m_CmdManager.m_ScriptEngine.World.Entities.TryGetValue(ts.keyID, out EntityBase e); if (e == null) return sensedEntities; - Entities = new List(); - Entities.Add(e); + Entities = new List + { + e + }; } else { @@ -617,17 +626,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins // rather than getting a list to scan through if (ts.keyID != UUID.Zero) { - ScenePresence sp; // Try direct lookup by UUID - if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out sp)) + if (!m_CmdManager.m_ScriptEngine.World.TryGetScenePresence(ts.keyID, out ScenePresence sp)) return sensedEntities; senseEntity(sp); } else if (!string.IsNullOrEmpty(ts.name)) { - ScenePresence sp; // Try lookup by name will return if/when found - if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out sp)) + if (((ts.type & AGENT) != 0) && m_CmdManager.m_ScriptEngine.World.TryGetAvatarByName(ts.name, out ScenePresence sp)) senseEntity(sp); if ((ts.type & AGENT_BY_USERNAME) != 0) { @@ -689,18 +696,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins while (idx < data.Length) { - SensorInfo ts = new SensorInfo(); + SensorInfo ts = new SensorInfo + { + localID = localID, + itemID = itemID, - ts.localID = localID; - ts.itemID = itemID; - - ts.interval = (double)data[idx]; - ts.name = (string)data[idx+1]; - ts.keyID = (UUID)data[idx+2]; - ts.type = (int)data[idx+3]; - ts.range = (double)data[idx+4]; - ts.arc = (double)data[idx+5]; - ts.host = part; + interval = (double)data[idx], + name = (string)data[idx + 1], + keyID = (UUID)data[idx + 2], + type = (int)data[idx + 3], + range = (double)data[idx + 4], + arc = (double)data[idx + 5], + host = part + }; ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval); diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs b/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs index 8c033c58f7..bee890ba5c 100644 --- a/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs +++ b/OpenSim/Region/ScriptEngine/YEngine/XMRInstBackend.cs @@ -55,7 +55,7 @@ namespace OpenSim.Region.ScriptEngine.Yengine public void InitXMRLSLApi(XMRInstance i) { - acm = AsyncCommands; + acm = m_AsyncCommands; inst = i; }