From 1cbef0b9084bce0816c7ef471b3b58d1dbf9de7c Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Mon, 18 Feb 2008 11:14:53 +0000
Subject: Patch from Michael Osias IBM (jimbo2120) In his own words: If a prim
 becomes a listener or remote channel and the script is deleted, it cannot
 become a listener or channel again with a new script. This patch fixes that.

---
 .../Region/Environment/Interfaces/IWorldComm.cs    |  1 +
 OpenSim/Region/Environment/Interfaces/IXMLRPC.cs   |  1 +
 .../Region/Environment/Modules/WorldCommModule.cs  | 22 ++++++++++++++++++++++
 OpenSim/Region/Environment/Modules/XMLRPCModule.cs | 19 +++++++++++++++++++
 .../ScriptEngineBase/AsyncLSLCommandManager.cs     |  7 +++++++
 5 files changed, 50 insertions(+)

diff --git a/OpenSim/Region/Environment/Interfaces/IWorldComm.cs b/OpenSim/Region/Environment/Interfaces/IWorldComm.cs
index d8811c6..7567bb2 100644
--- a/OpenSim/Region/Environment/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Environment/Interfaces/IWorldComm.cs
@@ -40,5 +40,6 @@ namespace OpenSim.Region.Environment.Interfaces
         ListenerInfo GetNextMessage();
         void ListenControl(int handle, int active);
         void ListenRemove(int handle);
+        void DeleteListener(LLUUID itemID);
     }
 }
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Interfaces/IXMLRPC.cs b/OpenSim/Region/Environment/Interfaces/IXMLRPC.cs
index 02b74cb..82b692d 100644
--- a/OpenSim/Region/Environment/Interfaces/IXMLRPC.cs
+++ b/OpenSim/Region/Environment/Interfaces/IXMLRPC.cs
@@ -39,5 +39,6 @@ namespace OpenSim.Region.Environment.Interfaces
         RPCRequestInfo GetNextRequest();
         void RemoteDataReply(string channel, string message_id, string sdata, int idata);
         bool IsEnabled();
+        void DeleteChannel(LLUUID itemID);
     }
 }
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Modules/WorldCommModule.cs b/OpenSim/Region/Environment/Modules/WorldCommModule.cs
index 6b9ae46..a426eda 100644
--- a/OpenSim/Region/Environment/Modules/WorldCommModule.cs
+++ b/OpenSim/Region/Environment/Modules/WorldCommModule.cs
@@ -70,6 +70,7 @@ namespace OpenSim.Region.Environment.Modules
     {
         private Scene m_scene;
         private object CommListLock = new object();
+        private object ListLock = new object();
         private string m_name = "WorldCommModule";
         private ListenerManager m_listenerManager;
         private Queue<ListenerInfo> m_pending;
@@ -136,6 +137,15 @@ namespace OpenSim.Region.Environment.Modules
             m_listenerManager.Remove(handle);
         }
 
+        public void DeleteListener(LLUUID itemID)
+        {
+            lock (ListLock)
+            {
+                m_listenerManager.DeleteListener(itemID);
+            }
+
+        }
+
         // This method scans nearby objects and determines if they are listeners,
         // and if so if this message fits the filter.  If it does, then
         // enqueue the message for delivery to the objects listen event handler.
@@ -303,6 +313,18 @@ namespace OpenSim.Region.Environment.Modules
             m_listeners.Remove(handle);
         }
 
+        public void DeleteListener(LLUUID itemID)
+        {
+            foreach (ListenerInfo li in m_listeners.Values)
+            {
+                if (li.GetItemID().Equals(itemID))
+                {
+                    Remove(li.GetHandle());
+                    return;
+                }
+            }
+        }
+
         private int GetNewHandle()
         {
             for (int i = 0; i < int.MaxValue - 1; i++)
diff --git a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs
index 762e76d..edd1df8 100644
--- a/OpenSim/Region/Environment/Modules/XMLRPCModule.cs
+++ b/OpenSim/Region/Environment/Modules/XMLRPCModule.cs
@@ -188,6 +188,24 @@ namespace OpenSim.Region.Environment.Modules
             return channel;
         }
 
+        public void DeleteChannel(LLUUID itemID)
+        {
+
+            foreach (RPCChannelInfo li in m_openChannels.Values)
+            {
+
+                if (li.GetItemID().Equals(itemID))
+                {
+
+                    m_openChannels.Remove(li.GetChannelID());
+                    return;
+
+                }
+
+            }
+
+        }
+
         /**********************************************
          * Remote Data Reply
          * 
@@ -408,5 +426,6 @@ namespace OpenSim.Region.Environment.Modules
         {
             return m_localID;
         }
+
     }
 }
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs
index c8b1256..1afe71c 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncLSLCommandManager.cs
@@ -120,6 +120,13 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
             IHttpRequests iHttpReq =
                 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
             iHttpReq.StopHttpRequest(localID, itemID);
+
+            IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+            comms.DeleteListener(itemID);
+
+            IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
+            xmlrpc.DeleteChannel(itemID);
+
         }
 
         #region TIMER
-- 
cgit v1.1