try simplify lsl listen code a bit

UbitUmarov [2022-06-18 21:40:01]
try simplify lsl listen code a bit
Filename
OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
OpenSim/Region/Framework/Interfaces/IWorldComm.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs
OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 0b3d18d..58ae2c3 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -210,11 +210,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
         /// </param>
         /// <param name="msg">msg to filter on</param>
         /// <returns>number of the scripts handle</returns>
-        public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
-                string name, UUID id, string msg)
+        public int Listen(UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
         {
-            return m_listenerManager.AddListener(localID, itemID, hostID,
-                channel, name, id, msg);
+            return m_listenerManager.AddListener(itemID, hostID, channel, name, id, msg);
         }

         /// <summary>
@@ -223,7 +221,6 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
         /// the script during 'peek' time. Parameter hostID is needed to
         /// determine the position of the script.
         /// </summary>
-        /// <param name="localID">localID of the script engine</param>
         /// <param name="itemID">UUID of the script engine</param>
         /// <param name="hostID">UUID of the SceneObjectPart</param>
         /// <param name="channel">channel to listen on</param>
@@ -236,11 +233,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
         /// Bitfield indicating which strings should be processed as regex.
         /// </param>
         /// <returns>number of the scripts handle</returns>
-        public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
+        public int Listen(UUID itemID, UUID hostID, int channel,
                 string name, UUID id, string msg, int regexBitfield)
         {
-            return m_listenerManager.AddListener(localID, itemID, hostID,
-                    channel, name, id, msg, regexBitfield);
+            return m_listenerManager.AddListener(itemID, hostID, channel, name, id, msg, regexBitfield);
         }

         /// <summary>
@@ -340,12 +336,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
             // in a limited set of listeners, each belonging a host. If the host is in range, add them
             // to the pending queue.

-            UUID hostID;
             foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
             {
-                hostID = li.GetHostID();
                 // Dont process if this message is from yourself!
-                if (id == hostID)
+                if (id.Equals(li.HostID))
                     continue;

                 if(maxDistanceSQ < 0)
@@ -354,7 +348,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                     continue;
                 }

-                SceneObjectPart sPart = m_scene.GetSceneObjectPart(hostID);
+                SceneObjectPart sPart = m_scene.GetSceneObjectPart(li.HostID);
                 if (sPart == null)
                     continue;

@@ -424,8 +418,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm

                 foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
                 {
-                    UUID liHostID = li.GetHostID();
-                    if (liHostID.Equals(id))
+                    UUID liHostID = li.HostID;
+                    if (li.HostID.Equals(id))
                         continue;
                     if (m_scene.GetSceneObjectPart(liHostID) == null)
                         continue;
@@ -443,7 +437,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm

             foreach (ListenerInfo li in m_listenerManager.GetListeners(UUID.Zero, channel, name, id, msg))
             {
-                UUID liHostID = li.GetHostID();
+                UUID liHostID = li.HostID;
                 // Dont process if this message is from yourself!
                 if (liHostID.Equals(id))
                     continue;
@@ -507,10 +501,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
             return m_listenerManager.GetSerializationData(itemID);
         }

-        public void CreateFromData(uint localID, UUID itemID, UUID hostID,
+        public void CreateFromData(UUID itemID, UUID hostID,
                 Object[] data)
         {
-            m_listenerManager.AddFromData(localID, itemID, hostID, data);
+            m_listenerManager.AddFromData(itemID, hostID, data);
         }
     }

@@ -541,15 +535,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
             m_curlisteners = 0;
         }

-        public int AddListener(uint localID, UUID itemID, UUID hostID,
-                int channel, string name, UUID id, string msg)
+        public int AddListener(UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
         {
-            return AddListener(localID, itemID, hostID, channel, name, id,
-                    msg, 0);
+            return AddListener(itemID, hostID, channel, name, id, msg, 0);
         }

-        public int AddListener(uint localID, UUID itemID, UUID hostID,
-                int channel, string name, UUID id, string msg,
+        public int AddListener(UUID itemID, UUID hostID, int channel, string name, UUID id, string msg,
                 int regexBitfield)
         {
             // do we already have a match on this particular filter event?
@@ -559,7 +550,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
             {
                 // special case, called with same filter settings, return same
                 // handle (2008-05-02, tested on 1.21.1 server, still holds)
-                return coll[0].GetHandle();
+                return coll[0].Handle;
             }

             lock (mainLock)
@@ -570,7 +561,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm

                     if (newHandle > 0)
                     {
-                        ListenerInfo li = new ListenerInfo(newHandle, localID,
+                        ListenerInfo li = new ListenerInfo(newHandle,
                                 itemID, hostID, channel, name, id, msg,
                                 regexBitfield);

@@ -597,7 +588,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 {
                     foreach (ListenerInfo li in lis.Value)
                     {
-                        if (handle == li.GetHandle() && itemID == li.GetItemID())
+                        if (handle == li.Handle && itemID.Equals(li.ItemID))
                         {
                             lis.Value.Remove(li);
                             m_curlisteners--;
@@ -622,7 +613,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 {
                     foreach (ListenerInfo li in lis.Value)
                     {
-                        if (itemID == li.GetItemID())
+                        if (itemID.Equals(li.ItemID))
                             removedListeners.Add(li);
                     }

@@ -651,7 +642,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 {
                     foreach (ListenerInfo li in lis.Value)
                     {
-                        if (handle == li.GetHandle() && itemID == li.GetItemID())
+                        if (handle == li.Handle && itemID.Equals(li.ItemID))
                         {
                             li.Activate();
                             return;
@@ -669,7 +660,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 {
                     foreach (ListenerInfo li in lis.Value)
                     {
-                        if (handle == li.GetHandle() && itemID == li.GetItemID())
+                        if (handle == li.Handle && itemID.Equals(li.ItemID))
                         {
                             li.Deactivate();
                             return;
@@ -694,8 +685,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
             {
                 foreach (ListenerInfo li in lis.Value)
                 {
-                    if (itemID == li.GetItemID())
-                        handles.Add(li.GetHandle());
+                    if (itemID == li.ItemID)
+                        handles.Add(li.Handle);
                 }
             }

@@ -748,48 +739,103 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm

             lock (mainLock)
             {
-                List<ListenerInfo> listeners;
-                if (!m_listenersByChannel.TryGetValue(channel, out listeners))
+                if (!m_listenersByChannel.TryGetValue(channel, out List<ListenerInfo> listeners))
                 {
                     return collection;
                 }

-                bool itemIDNotZero = !itemID.IsZero();
+                bool itemIDNotZero = itemID.IsNotZero();
+                bool nameNotEmpty = !string.IsNullOrEmpty(name);
+                bool msgNotEmpty = !string.IsNullOrEmpty(msg);
                 foreach (ListenerInfo li in listeners)
                 {
-                    if (!li.IsActive())
+                    if (!li.IsActive)
                         continue;

-                    if (itemIDNotZero && itemID != li.GetItemID())
+                    if (itemIDNotZero && itemID.NotEqual(li.ItemID))
                         continue;

-                    if (!li.GetID().IsZero() && id.NotEqual(li.GetID()))
+                    if (li.ID.IsNotZero() && id.NotEqual(li.ID))
                         continue;

-                    if (li.GetName().Length > 0)
+                    if (nameNotEmpty && li.Name.Length > 0)
                     {
-                        if((li.RegexBitfield & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME)
+                        if ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME)
                         {
-                            if (!Regex.IsMatch(name, li.GetName()))
+                            if (!Regex.IsMatch(name, li.Name))
                                 continue;
                         }
                         else
                         {
-                            if (!li.GetName().Equals(name))
+                            if (!li.Name.Equals(name))
                                 continue;
                         }
                     }

-                    if (li.GetMessage().Length > 0)
+                    if (msgNotEmpty && li.Message.Length > 0)
                     {
-                        if((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE)
+                        if ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE)
                         {
-                            if(!Regex.IsMatch(msg, li.GetMessage()))
+                            if (!Regex.IsMatch(msg, li.Message))
                                 continue;
                         }
                         else
                         {
-                            if(!li.GetMessage().Equals(msg))
+                            if (!li.Message.Equals(msg))
+                                continue;
+                        }
+                    }
+                    collection.Add(li);
+                }
+            }
+            return collection;
+        }
+
+        public List<ListenerInfo> GetListeners(int channel, string name, UUID id, string msg)
+        {
+            List<ListenerInfo> collection = new List<ListenerInfo>();
+
+            lock (mainLock)
+            {
+                if (!m_listenersByChannel.TryGetValue(channel, out List<ListenerInfo> listeners))
+                {
+                    return collection;
+                }
+
+                bool nameNotEmpty = !string.IsNullOrEmpty(name);
+                bool msgNotEmpty = !string.IsNullOrEmpty(msg);
+                foreach (ListenerInfo li in listeners)
+                {
+                    if (!li.IsActive)
+                        continue;
+
+                    if (li.ID.IsNotZero() && id.NotEqual(li.ID))
+                        continue;
+
+                    if (nameNotEmpty && li.Name.Length > 0)
+                    {
+                        if ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME)
+                        {
+                            if (!Regex.IsMatch(name, li.Name))
+                                continue;
+                        }
+                        else
+                        {
+                            if (!li.Name.Equals(name))
+                                continue;
+                        }
+                    }
+
+                    if (msgNotEmpty && li.Message.Length > 0)
+                    {
+                        if ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE)
+                        {
+                            if (!Regex.IsMatch(msg, li.Message))
+                                continue;
+                        }
+                        else
+                        {
+                            if (!li.Message.Equals(msg))
                                 continue;
                         }
                     }
@@ -809,16 +855,15 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 {
                     foreach (ListenerInfo l in list)
                     {
-                        if (l.GetItemID() == itemID)
+                        if (itemID.Equals(l.ItemID))
                             data.AddRange(l.GetSerializationData());
                     }
                 }
             }
-            return (Object[])data.ToArray();
+            return data.ToArray();
         }

-        public void AddFromData(uint localID, UUID itemID, UUID hostID,
-                Object[] data)
+        public void AddFromData(UUID itemID, UUID hostID, Object[] data)
         {
             int idx = 0;
             Object[] item = new Object[6];
@@ -830,8 +875,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
                 item = new Object[dataItemLength];
                 Array.Copy(data, idx, item, 0, dataItemLength);

-                ListenerInfo info =
-                        ListenerInfo.FromData(localID, itemID, hostID, item);
+                ListenerInfo info = ListenerInfo.FromData(itemID, hostID, item);

                 lock (mainLock)
                 {
@@ -852,91 +896,99 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
         /// <summary>
         /// Listener is active or not
         /// </summary>
-        private bool m_active;
+        public bool IsActive { get; private set; }

         /// <summary>
         /// Assigned handle of this listener
         /// </summary>
-        private int m_handle;
-
-        /// <summary>
-        /// Local ID from script engine
-        /// </summary>
-        private uint m_localID;
+        public int Handle { get; private set; }

         /// <summary>
         /// ID of the host script engine
         /// </summary>
-        private UUID m_itemID;
+        public UUID ItemID { get; private set; }

         /// <summary>
         /// ID of the host/scene part
         /// </summary>
-        private UUID m_hostID;
+        public UUID HostID { get; private set; }

         /// <summary>
         /// Channel
         /// </summary>
-        private int m_channel;
+        public int Channel { get; private set; }

         /// <summary>
         /// ID to filter messages from
         /// </summary>
-        private UUID m_id;
+        public UUID ID { get; private set; }

         /// <summary>
         /// Object name to filter messages from
         /// </summary>
-        private string m_name;
+        public string Name { get; private set; }

         /// <summary>
         /// The message
         /// </summary>
-        private string m_message;
+        public string Message { get; private set; }
+        public int RegexBitfield { get; private set; }
+
+        public ListenerInfo()
+        {
+        }

-        public ListenerInfo(int handle, uint localID, UUID ItemID,
+        public ListenerInfo(int handle, UUID _ItemID,
                 UUID hostID, int channel, string name, UUID id,
                 string message)
         {
-            Initialise(handle, localID, ItemID, hostID, channel, name, id,
-                    message, 0);
+            IsActive = true;
+            Handle = handle;
+            ItemID = _ItemID;
+            HostID = hostID;
+            Channel = channel;
+            Name = name;
+            ID = id;
+            Message = message;
+            RegexBitfield = 0;
         }

-        public ListenerInfo(int handle, uint localID, UUID ItemID,
+        public ListenerInfo(int handle, UUID _ItemID,
                 UUID hostID, int channel, string name, UUID id,
                 string message, int regexBitfield)
         {
-            Initialise(handle, localID, ItemID, hostID, channel, name, id,
-                    message, regexBitfield);
-        }
-
-        public ListenerInfo(ListenerInfo li, string name, UUID id,
-                string message)
-        {
-            Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID,
-                    li.m_channel, name, id, message, 0);
+            Handle = handle;
+            ItemID = _ItemID;
+            HostID = hostID;
+            Channel = channel;
+            Name = name;
+            ID = id;
+            Message = message;
+            RegexBitfield = regexBitfield;
         }

-        public ListenerInfo(ListenerInfo li, string name, UUID id,
-                string message, int regexBitfield)
+        public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
         {
-            Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID,
-                    li.m_channel, name, id, message, regexBitfield);
+            IsActive = true;
+            Handle = li.Handle;
+            ItemID = li.ItemID;
+            HostID = li.HostID;
+            Channel = li.Channel;
+            Name = name;
+            ID = id;
+            Message = message;
         }

-        private void Initialise(int handle, uint localID, UUID ItemID,
-                UUID hostID, int channel, string name, UUID id,
-                string message, int regexBitfield)
+        public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
         {
-            m_active = true;
-            m_handle = handle;
-            m_localID = localID;
-            m_itemID = ItemID;
-            m_hostID = hostID;
-            m_channel = channel;
-            m_name = name;
-            m_id = id;
-            m_message = message;
+            IsActive = true;
+            Handle = li.Handle;
+            ItemID = li.ItemID;
+            HostID = li.HostID;
+            Channel = li.Channel;
+            Name = name;
+            ID = id;
+            Message = message;
             RegexBitfield = regexBitfield;
         }

@@ -944,87 +996,41 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
         {
             Object[] data = new Object[7];

-            data[0] = m_active;
-            data[1] = m_handle;
-            data[2] = m_channel;
-            data[3] = m_name;
-            data[4] = m_id;
-            data[5] = m_message;
+            data[0] = IsActive;
+            data[1] = Handle;
+            data[2] = Channel;
+            data[3] = Name;
+            data[4] = ID;
+            data[5] = Message;
             data[6] = RegexBitfield;

             return data;
         }

-        public static ListenerInfo FromData(uint localID, UUID ItemID,
-                UUID hostID, Object[] data)
+        public static ListenerInfo FromData(UUID _ItemID, UUID hostID, Object[] data)
         {
-            ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
-                    ItemID, hostID, (int)data[2], (string)data[3],
-                    (UUID)data[4], (string)data[5]);
-            linfo.m_active = (bool)data[0];
-            if (data.Length >= 7)
+            return new ListenerInfo()
             {
-                linfo.RegexBitfield = (int)data[6];
-            }
-
-            return linfo;
-        }
-
-        public UUID GetItemID()
-        {
-            return m_itemID;
-        }
-
-        public UUID GetHostID()
-        {
-            return m_hostID;
-        }
-
-        public int GetChannel()
-        {
-            return m_channel;
-        }
-
-        public uint GetLocalID()
-        {
-            return m_localID;
-        }
-
-        public int GetHandle()
-        {
-            return m_handle;
-        }
-
-        public string GetMessage()
-        {
-            return m_message;
-        }
-
-        public string GetName()
-        {
-            return m_name;
-        }
-
-        public bool IsActive()
-        {
-            return m_active;
-        }
-
-        public void Deactivate()
-        {
-            m_active = false;
+                IsActive = (bool)data[0],
+                Handle = (int)data[1],
+                ItemID = _ItemID,
+                HostID = hostID,
+                Channel = (int)data[2],
+                Name = (string)data[3],
+                ID = (UUID)data[4],
+                Message = (string)data[5],
+                RegexBitfield = (data.Length > 6) ? (int)data[6] : 0
+            };
         }

         public void Activate()
         {
-            m_active = true;
+            IsActive = true;
         }

-        public UUID GetID()
+        public void Deactivate()
         {
-            return m_id;
+            IsActive = false;
         }
-
-        public int RegexBitfield { get; private set; }
     }
 }
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 00344ec..e677b66 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -33,18 +33,14 @@ namespace OpenSim.Region.Framework.Interfaces
 {
     public interface IWorldCommListenerInfo
     {
-        Object[] GetSerializationData();
-        UUID GetItemID();
-        UUID GetHostID();
-        int GetChannel();
-        uint GetLocalID();
-        int GetHandle();
-        string GetMessage();
-        string GetName();
-        bool IsActive();
-        void Deactivate();
-        void Activate();
-        UUID GetID();
+        bool IsActive { get; }
+        int Handle { get; }
+        UUID ItemID { get; }
+        UUID HostID { get; }
+        int Channel { get; }
+        string Message { get; }
+        string Name { get; }
+        UUID ID { get; }

         /// <summary>
         /// Bitfield indicating which strings should be processed as regex.
@@ -52,6 +48,10 @@ namespace OpenSim.Region.Framework.Interfaces
         /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
         /// </summary>
         int RegexBitfield { get; }
+        Object[] GetSerializationData();
+
+        void Deactivate();
+        void Activate();
     }

     public interface IWorldComm
@@ -67,7 +67,6 @@ namespace OpenSim.Region.Framework.Interfaces
         /// the script during 'peek' time. Parameter hostID is needed to
         /// determine the position of the script.
         /// </summary>
-        /// <param name="LocalID">localID of the script engine</param>
         /// <param name="itemID">UUID of the script engine</param>
         /// <param name="hostID">UUID of the SceneObjectPart</param>
         /// <param name="channel">channel to listen on</param>
@@ -75,7 +74,7 @@ namespace OpenSim.Region.Framework.Interfaces
         /// <param name="id">key to filter on (user given, could be totally faked)</param>
         /// <param name="msg">msg to filter on</param>
         /// <returns>number of the scripts handle</returns>
-        int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
+        int Listen(UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);

          /// <summary>
         /// Create a listen event callback with the specified filters.
@@ -83,7 +82,6 @@ namespace OpenSim.Region.Framework.Interfaces
         /// the script during 'peek' time. Parameter hostID is needed to
         /// determine the position of the script.
         /// </summary>
-        /// <param name="LocalID">localID of the script engine</param>
         /// <param name="itemID">UUID of the script engine</param>
         /// <param name="hostID">UUID of the SceneObjectPart</param>
         /// <param name="channel">channel to listen on</param>
@@ -92,7 +90,7 @@ namespace OpenSim.Region.Framework.Interfaces
         /// <param name="msg">msg to filter on</param>
         /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
         /// <returns>number of the scripts handle</returns>
-        int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
+        int Listen(UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);

         /// <summary>
         /// This method scans over the objects which registered an interest in listen callbacks.
@@ -146,7 +144,6 @@ namespace OpenSim.Region.Framework.Interfaces
         void ListenRemove(UUID itemID, int handle);
         void DeleteListener(UUID itemID);
         Object[] GetSerializationData(UUID itemID);
-        void CreateFromData(uint localID, UUID itemID, UUID hostID,
-                            Object[] data);
+        void CreateFromData(UUID itemID, UUID hostID, Object[] data);
     }
 }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
index 719bb7e..2cc502c 100755
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs
@@ -454,16 +454,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                     switch (type)
                     {
                         case "listener":
-                            m_Listener[engine].CreateFromData(localID, itemID,
-                                                        hostID, item);
+                            m_Listener[engine].CreateFromData(itemID, hostID, item);
                             break;
                         case "timer":
-                            m_ScriptTimer[engine].CreateFromData(localID, itemID,
-                                                        hostID, item);
+                            m_ScriptTimer[engine].CreateFromData(localID, itemID, hostID, item);
                             break;
                         case "sensor":
-                            m_SensorRepeat[engine].CreateFromData(localID,
-                                                        itemID, hostID, item);
+                            m_SensorRepeat[engine].CreateFromData(localID, itemID, hostID, item);
                             break;
                         }
                     }
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 49d8aec..c49848d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -1340,7 +1340,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                 return -1;

             UUID.TryParse(ID, out UUID keyID);
-            return wComm.Listen(m_host.LocalId, m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
+            return wComm.Listen(m_item.ItemID, m_host.UUID, channelID, name, keyID, msg);
         }

         public void llListenControl(int number, int active)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index b22279e..fc75570 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3998,7 +3998,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
             if(UUID.TryParse(prim, out UUID pID) && pID.IsNotZero())
             {
                 SceneObjectPart obj = World.GetSceneObjectPart(pID);
-                SetProjectionParams(obj, llprojection, texture, fov, focus, amb);
+                if(obj != null)
+                {
+                    if(obj.OwnerID.Equals(m_host.OwnerID))
+                        SetProjectionParams(obj, llprojection, texture, fov, focus, amb);
+                }
             }
             else
                 SetProjectionParams(m_host, llprojection, texture, fov, focus, amb);
@@ -4598,9 +4602,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
         public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
         {
             CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+            IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+            if(wComm == null)
+                return -1;

             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)
             {
@@ -4608,7 +4614,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                 {
                     Regex.IsMatch("", name);
                 }
-                catch (Exception)
+                catch
                 {
                     OSSLShoutError("Name regex is invalid.");
                     return -1;
@@ -4622,24 +4628,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
                 {
                     Regex.IsMatch("", msg);
                 }
-                catch (Exception)
+                catch
                 {
                     OSSLShoutError("Message regex is invalid.");
                     return -1;
                 }
             }

-            IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
-            return (wComm == null) ? -1 : wComm.Listen(
-                m_host.LocalId,
-                m_item.ItemID,
-                m_host.UUID,
-                channelID,
-                name,
-                keyID,
-                msg,
-                regexBitfield
-            );
+            return wComm.Listen(m_item.ItemID, m_host.UUID,
+                        channelID, name, keyID, msg, regexBitfield);
         }

         public LSL_Integer osRegexIsMatch(string input, string pattern)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
index 008b25c..6315a83 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Dataserver.cs
@@ -189,10 +189,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
             catch { }

             ds.action = null;
+
             lock (DataserverRequests)
             {
-                if (DataserverRequests.TryGetValue(id, out ds))
-                    DataserverRequests.Remove(id);
+                DataserverRequests.Remove(id);
             }
         }

@@ -200,20 +200,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
         public void DataserverReply(string identifier, string reply)
         {
             DataserverRequest ds;
-
             lock (DataserverRequests)
             {
-                if (!DataserverRequests.ContainsKey(identifier))
+                if (!DataserverRequests.TryGetValue(identifier, out ds))
                     return;
-
-                ds = DataserverRequests[identifier];
                 DataserverRequests.Remove(identifier);
             }

             m_CmdManager.m_ScriptEngine.PostObjectEvent(ds.localID,
                     new EventParams("dataserver", new Object[]
-                            { new LSL_Types.LSLString(ds.ID.ToString()),
-                            new LSL_Types.LSLString(reply)},
+                    {
+                        new LSL_Types.LSLString(ds.ID.ToString()),
+                        new LSL_Types.LSLString(reply)
+                    },
                     new DetectParams[0]));
         }

diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs
index efa86fc..5115205 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/Plugins/Listener.cs
@@ -62,25 +62,21 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins

             if (m_commsPlugin != null)
             {
-                while (m_commsPlugin.HasMessages())
+                ListenerInfo lInfo;
+                while ((lInfo = (ListenerInfo)m_commsPlugin.GetNextMessage()) != null)
                 {
-                    ListenerInfo lInfo = (ListenerInfo)m_commsPlugin.GetNextMessage();
-
                     //Deliver data to prim's listen handler
                     object[] resobj = new object[]
                     {
-                        new LSL_Types.LSLInteger(lInfo.GetChannel()),
-                        new LSL_Types.LSLString(lInfo.GetName()),
-                        new LSL_Types.LSLString(lInfo.GetID().ToString()),
-                        new LSL_Types.LSLString(lInfo.GetMessage())
+                        new LSL_Types.LSLInteger(lInfo.Channel),
+                        new LSL_Types.LSLString(lInfo.Name),
+                        new LSL_Types.LSLString(lInfo.ID.ToString()),
+                        new LSL_Types.LSLString(lInfo.Message)
                     };

                     foreach (IScriptEngine e in m_CmdManager.ScriptEngines)
                     {
-                        e.PostScriptEvent(
-                                lInfo.GetItemID(), new EventParams(
-                                "listen", resobj,
-                                new DetectParams[0]));
+                        e.PostScriptEvent(lInfo.ItemID, new EventParams("listen", resobj, new DetectParams[0]));
                     }
                 }
             }
@@ -94,11 +90,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Plugins
                 return new Object[]{};
         }

-        public void CreateFromData(uint localID, UUID itemID, UUID hostID,
-                Object[] data)
+        public void CreateFromData( UUID itemID, UUID hostID, Object[] data)
         {
             if (m_commsPlugin != null)
-                m_commsPlugin.CreateFromData(localID, itemID, hostID, data);
+                m_commsPlugin.CreateFromData(itemID, hostID, data);
         }
     }
 }
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
index b8938ff..58b1f87 100755
--- a/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
+++ b/OpenSim/Region/ScriptEngine/XEngine/XEngine.cs
@@ -253,10 +253,15 @@ namespace OpenSim.Region.ScriptEngine.XEngine

         public void Initialise(IConfigSource configSource)
         {
-            if (configSource.Configs["XEngine"] == null)
+            m_ScriptConfig = configSource.Configs["XEngine"];
+            if (m_ScriptConfig == null)
                 return;

-            m_ScriptConfig = configSource.Configs["XEngine"];
+            if (!m_ScriptConfig.GetBoolean("Enabled", true))
+                return;
+
+            m_Enabled = true;
+
             m_ConfigSource = configSource;

             string rawScriptStopStrategy = m_ScriptConfig.GetString("ScriptStopStrategy", "co-op");
@@ -282,19 +287,13 @@ namespace OpenSim.Region.ScriptEngine.XEngine

         public void AddRegion(Scene scene)
         {
-            if (m_ScriptConfig == null)
+            if (!m_Enabled)
                 return;
-
+
             m_ScriptFailCount = 0;
             m_ScriptErrorMessage = String.Empty;

-            m_Enabled = m_ScriptConfig.GetBoolean("Enabled", true);
-
-            if (!m_Enabled)
-                return;
-
-            AppDomain.CurrentDomain.AssemblyResolve +=
-                OnAssemblyResolve;
+            AppDomain.CurrentDomain.AssemblyResolve +=  OnAssemblyResolve;

             m_Scene = scene;
             m_log.InfoFormat("[XEngine]: Initializing scripts in region {0}", m_Scene.RegionInfo.RegionName);
ViewGit