aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase
diff options
context:
space:
mode:
authorMelanie Thielker2008-09-25 05:13:44 +0000
committerMelanie Thielker2008-09-25 05:13:44 +0000
commitf3c8963c86dbc969541ede80ae37eb59d26b7809 (patch)
treeff1e5cea74e9d5c2b73c476320a7bddf11d93766 /OpenSim/Region/ScriptEngine/Common/ScriptEngineBase
parentMantis#2123. Thank you kindly, Idb for a patch that solves: (diff)
downloadopensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.zip
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.gz
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.bz2
opensim-SC_OLD-f3c8963c86dbc969541ede80ae37eb59d26b7809.tar.xz
Convergence is almost complete. This brings the diff between the API to < 10k
and makes it use a common set of types in both engine. Fixes the issues with running both engines and HTTP requests / listens / timers etc.. Also fixes a couple of minor Scene issues and a CTB by nullref.
Diffstat (limited to 'OpenSim/Region/ScriptEngine/Common/ScriptEngineBase')
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs234
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Dataserver.cs127
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/HttpRequest.cs98
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Listener.cs76
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs334
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs139
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/XmlRequest.cs130
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs345
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs28
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs19
11 files changed, 210 insertions, 1345 deletions
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
deleted file mode 100644
index 5fa6010..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandManager.cs
+++ /dev/null
@@ -1,234 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System.Collections;
29using System.Threading;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Interfaces;
33using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins;
34using Timer=OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins.Timer;
35
36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
37{
38 /// <summary>
39 /// Handles LSL commands that takes long time and returns an event, for example timers, HTTP requests, etc.
40 /// </summary>
41 public class AsyncCommandManager : iScriptEngineFunctionModule
42 {
43 private static Thread cmdHandlerThread;
44 private static int cmdHandlerThreadCycleSleepms;
45
46 public ScriptEngine m_ScriptEngine;
47
48 private Timer m_Timer;
49 private HttpRequest m_HttpRequest;
50 private Listener m_Listener;
51 private SensorRepeat m_SensorRepeat;
52 private XmlRequest m_XmlRequest;
53 private Dataserver m_Dataserver;
54
55 public Dataserver DataserverPlugin
56 {
57 get { return m_Dataserver; }
58 }
59
60 public Timer TimerPlugin
61 {
62 get { return m_Timer; }
63 }
64
65 public HttpRequest HttpRequestPlugin
66 {
67 get { return m_HttpRequest; }
68 }
69
70 public Listener ListenerPlugin
71 {
72 get { return m_Listener; }
73 }
74
75 public SensorRepeat SensorRepeatPlugin
76 {
77 get { return m_SensorRepeat; }
78 }
79
80 public XmlRequest XmlRequestPlugin
81 {
82 get { return m_XmlRequest; }
83 }
84
85 public AsyncCommandManager(ScriptEngine _ScriptEngine)
86 {
87 m_ScriptEngine = _ScriptEngine;
88 ReadConfig();
89
90 // Create instances of all plugins
91 m_Timer = new Timer(this);
92 m_HttpRequest = new HttpRequest(this);
93 m_Listener = new Listener(this);
94 m_SensorRepeat = new SensorRepeat(this);
95 m_XmlRequest = new XmlRequest(this);
96 m_Dataserver = new Dataserver(this);
97
98 StartThread();
99 }
100
101 private static void StartThread()
102 {
103 if (cmdHandlerThread == null)
104 {
105 // Start the thread that will be doing the work
106 cmdHandlerThread = new Thread(CmdHandlerThreadLoop);
107 cmdHandlerThread.Name = "AsyncLSLCmdHandlerThread";
108 cmdHandlerThread.Priority = ThreadPriority.BelowNormal;
109 cmdHandlerThread.IsBackground = true;
110 cmdHandlerThread.Start();
111 ThreadTracker.Add(cmdHandlerThread);
112 }
113 }
114
115 public void ReadConfig()
116 {
117 cmdHandlerThreadCycleSleepms = m_ScriptEngine.ScriptConfigSource.GetInt("AsyncLLCommandLoopms", 100);
118 }
119
120 ~AsyncCommandManager()
121 {
122 // Shut down thread
123 try
124 {
125 if (cmdHandlerThread != null)
126 {
127 if (cmdHandlerThread.IsAlive == true)
128 {
129 cmdHandlerThread.Abort();
130 //cmdHandlerThread.Join();
131 }
132 }
133 }
134 catch
135 {
136 }
137 }
138
139 private static void CmdHandlerThreadLoop()
140 {
141 while (true)
142 {
143 try
144 {
145 while (true)
146 {
147 Thread.Sleep(cmdHandlerThreadCycleSleepms);
148 //lock (ScriptEngine.ScriptEngines)
149 //{
150 foreach (ScriptEngine se in new ArrayList(ScriptEngine.ScriptEngines))
151 {
152 se.m_ASYNCLSLCommandManager.DoOneCmdHandlerPass();
153 }
154 //}
155 // Sleep before next cycle
156 //Thread.Sleep(cmdHandlerThreadCycleSleepms);
157 }
158 }
159 catch
160 {
161 }
162 }
163 }
164
165 internal void DoOneCmdHandlerPass()
166 {
167 // Check timers
168 m_Timer.CheckTimerEvents();
169 // Check HttpRequests
170 m_HttpRequest.CheckHttpRequests();
171 // Check XMLRPCRequests
172 m_XmlRequest.CheckXMLRPCRequests();
173 // Check Listeners
174 m_Listener.CheckListeners();
175 // Check Sensors
176 m_SensorRepeat.CheckSenseRepeaterEvents();
177 // Check dataserver
178 m_Dataserver.ExpireRequests();
179 }
180
181 /// <summary>
182 /// Remove a specific script (and all its pending commands)
183 /// </summary>
184 /// <param name="localID"></param>
185 /// <param name="itemID"></param>
186 public void RemoveScript(uint localID, UUID itemID)
187 {
188 // Remove a specific script
189
190 // Remove from: Timers
191 m_Timer.UnSetTimerEvents(localID, itemID);
192
193 // Remove from: HttpRequest
194 IHttpRequests iHttpReq =
195 m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
196 iHttpReq.StopHttpRequest(localID, itemID);
197
198 IWorldComm comms = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
199 comms.DeleteListener(itemID);
200
201 IXMLRPC xmlrpc = m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
202 xmlrpc.DeleteChannels(itemID);
203 xmlrpc.CancelSRDRequests(itemID);
204
205 // Remove Sensors
206 m_SensorRepeat.UnSetSenseRepeaterEvents(localID, itemID);
207
208 // Remove queries
209 m_Dataserver.RemoveEvents(localID, itemID);
210
211 }
212
213
214 #region Check llRemoteData channels
215
216
217 #endregion
218
219 #region Check llListeners
220
221
222 #endregion
223
224 /// <summary>
225 /// If set to true then threads and stuff should try to make a graceful exit
226 /// </summary>
227 public bool PleaseShutdown
228 {
229 get { return _PleaseShutdown; }
230 set { _PleaseShutdown = value; }
231 }
232 private bool _PleaseShutdown = false;
233 }
234}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Dataserver.cs
deleted file mode 100644
index 96d7b30..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Dataserver.cs
+++ /dev/null
@@ -1,127 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32using OpenSim.Region.ScriptEngine.Shared;
33
34namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
35
36{
37 public class Dataserver
38 {
39 public AsyncCommandManager m_CmdManager;
40
41 private Dictionary<string, DataserverRequest> DataserverRequests =
42 new Dictionary<string, DataserverRequest>();
43
44 public Dataserver(AsyncCommandManager CmdManager)
45 {
46 m_CmdManager = CmdManager;
47 }
48
49 private class DataserverRequest
50 {
51 public uint localID;
52 public UUID itemID;
53
54 public UUID ID;
55 public string handle;
56
57 public DateTime startTime;
58 }
59
60 public UUID RegisterRequest(uint localID, UUID itemID,
61 string identifier)
62 {
63 lock (DataserverRequests)
64 {
65 if (DataserverRequests.ContainsKey(identifier))
66 return UUID.Zero;
67
68 DataserverRequest ds = new DataserverRequest();
69
70 ds.localID = localID;
71 ds.itemID = itemID;
72
73 ds.ID = UUID.Random();
74 ds.handle = identifier;
75
76 ds.startTime = DateTime.Now;
77
78 DataserverRequests[identifier]=ds;
79
80 return ds.ID;
81 }
82 }
83
84 public void DataserverReply(string identifier, string reply)
85 {
86 DataserverRequest ds;
87
88 lock (DataserverRequests)
89 {
90 if (!DataserverRequests.ContainsKey(identifier))
91 return;
92
93 ds=DataserverRequests[identifier];
94 DataserverRequests.Remove(identifier);
95 }
96
97 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToObjectQueue(
98 ds.localID, "dataserver", EventQueueManager.llDetectNull,
99 new Object[] { new LSL_Types.LSLString(ds.ID.ToString()),
100 new LSL_Types.LSLString(reply)});
101 }
102
103 public void RemoveEvents(uint localID, UUID itemID)
104 {
105 lock (DataserverRequests)
106 {
107 foreach (DataserverRequest ds in new List<DataserverRequest>(DataserverRequests.Values))
108 {
109 if (ds.itemID == itemID)
110 DataserverRequests.Remove(ds.handle);
111 }
112 }
113 }
114
115 public void ExpireRequests()
116 {
117 lock (DataserverRequests)
118 {
119 foreach (DataserverRequest ds in new List<DataserverRequest>(DataserverRequests.Values))
120 {
121 if (ds.startTime > DateTime.Now.AddSeconds(30))
122 DataserverRequests.Remove(ds.handle);
123 }
124 }
125 }
126 }
127}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/HttpRequest.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/HttpRequest.cs
deleted file mode 100644
index 5b4cb83..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/HttpRequest.cs
+++ /dev/null
@@ -1,98 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using OpenSim.Region.Environment.Interfaces;
30using OpenSim.Region.Environment.Modules.Scripting.HttpRequest;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
34{
35 public class HttpRequest
36 {
37 public AsyncCommandManager m_CmdManager;
38
39 public HttpRequest(AsyncCommandManager CmdManager)
40 {
41 m_CmdManager = CmdManager;
42 }
43
44 public void CheckHttpRequests()
45 {
46 if (m_CmdManager.m_ScriptEngine.World == null)
47 return;
48
49 IHttpRequests iHttpReq =
50 m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IHttpRequests>();
51
52 HttpRequestClass httpInfo = null;
53
54 if (iHttpReq != null)
55 httpInfo = iHttpReq.GetNextCompletedRequest();
56
57 while (httpInfo != null)
58 {
59 //m_ScriptEngine.Log.Info("[AsyncLSL]:" + httpInfo.response_body + httpInfo.status);
60
61 // Deliver data to prim's remote_data handler
62 //
63 // TODO: Returning null for metadata, since the lsl function
64 // only returns the byte for HTTP_BODY_TRUNCATED, which is not
65 // implemented here yet anyway. Should be fixed if/when maxsize
66 // is supported
67
68 bool handled = false;
69 iHttpReq.RemoveCompletedRequest(httpInfo.reqID);
70 foreach (ScriptEngine sman in ScriptEngine.ScriptEngines)
71 {
72 if (sman.m_ScriptManager.GetScript(httpInfo.localID, httpInfo.itemID) != null)
73 {
74 object[] resobj = new object[]
75 {
76 new LSL_Types.LSLString(httpInfo.reqID.ToString()), new LSL_Types.LSLInteger(httpInfo.status), null, new LSL_Types.LSLString(httpInfo.response_body)
77 };
78
79 sman.m_EventQueueManager.AddToScriptQueue(
80 httpInfo.localID, httpInfo.itemID, "http_response", EventQueueManager.llDetectNull, resobj
81 );
82
83 handled = true;
84 break;
85 //Thread.Sleep(2500);
86 }
87 }
88
89 if (!handled)
90 {
91 Console.WriteLine("Unhandled http_response: " + httpInfo.reqID);
92 }
93
94 httpInfo = iHttpReq.GetNextCompletedRequest();
95 }
96 }
97 }
98}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Listener.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Listener.cs
deleted file mode 100644
index 0bac22c..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Listener.cs
+++ /dev/null
@@ -1,76 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using OpenSim.Region.Environment.Interfaces;
29using OpenSim.Region.Environment.Modules.Scripting.WorldComm;
30using OpenSim.Region.ScriptEngine.Shared;
31
32namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
33{
34 public class Listener
35 {
36 // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
37
38 public AsyncCommandManager m_CmdManager;
39
40 public Listener(AsyncCommandManager CmdManager)
41 {
42 m_CmdManager = CmdManager;
43 }
44
45 public void CheckListeners()
46 {
47 if (m_CmdManager.m_ScriptEngine.World == null)
48 return;
49 IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
50
51 if (comms != null)
52 {
53 while (comms.HasMessages())
54 {
55 ListenerInfo lInfo = comms.GetNextMessage();
56 if (m_CmdManager.m_ScriptEngine.m_ScriptManager.GetScript(
57 lInfo.GetLocalID(), lInfo.GetItemID()) != null)
58 {
59 //Deliver data to prim's listen handler
60 object[] resobj = new object[]
61 {
62 //lInfo.GetChannel(), lInfo.GetName(), lInfo.GetID().ToString(), lInfo.GetMessage()
63 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())
64 };
65
66 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(
67 lInfo.GetLocalID(), lInfo.GetItemID(), "listen", EventQueueManager.llDetectNull, resobj
68 );
69 }
70 // else
71 // m_log.Info("[ScriptEngineBase.AsyncCommandPlugins: received a listen event for a (no longer) existing script ("+lInfo.GetLocalID().AsString()+")");
72 }
73 }
74 }
75 }
76}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs
deleted file mode 100644
index 7059a1b..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/SensorRepeat.cs
+++ /dev/null
@@ -1,334 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27//#define SPAM
28using System;
29using System.Collections.Generic;
30using OpenMetaverse;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Scenes;
33using OpenSim.Framework.Communications.Cache;
34using OpenSim.Region.ScriptEngine.Shared;
35
36namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
37{
38 public class SensorRepeat
39 {
40 public AsyncCommandManager m_CmdManager;
41
42 public SensorRepeat(AsyncCommandManager CmdManager)
43 {
44 m_CmdManager = CmdManager;
45 }
46
47 public Dictionary<uint, Dictionary<UUID, LSL_Types.list>> SenseEvents =
48 new Dictionary<uint, Dictionary<UUID, LSL_Types.list>>();
49 private Object SenseLock = new Object();
50
51 //
52 // SenseRepeater and Sensors
53 //
54 private class SenseRepeatClass
55 {
56 public uint localID;
57 public UUID itemID;
58 public double interval;
59 public DateTime next;
60
61 public string name;
62 public UUID keyID;
63 public int type;
64 public double range;
65 public double arc;
66 public SceneObjectPart host;
67 }
68
69 private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>();
70 private object SenseRepeatListLock = new object();
71
72 public void SetSenseRepeatEvent(uint m_localID, UUID m_itemID,
73 string name, UUID keyID, int type, double range, double arc, double sec, SceneObjectPart host)
74 {
75 #if SPAM
76 Console.WriteLine("SetSensorEvent");
77 #endif
78 // Always remove first, in case this is a re-set
79 UnSetSenseRepeaterEvents(m_localID, m_itemID);
80 if (sec == 0) // Disabling timer
81 return;
82
83 // Add to timer
84 SenseRepeatClass ts = new SenseRepeatClass();
85 ts.localID = m_localID;
86 ts.itemID = m_itemID;
87 ts.interval = sec;
88 ts.name = name;
89 ts.keyID = keyID;
90 ts.type = type;
91 ts.range = range;
92 ts.arc = arc;
93 ts.host = host;
94
95 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
96 lock (SenseRepeatListLock)
97 {
98 SenseRepeaters.Add(ts);
99 }
100 }
101
102 public void UnSetSenseRepeaterEvents(uint m_localID, UUID m_itemID)
103 {
104 // Remove from timer
105 lock (SenseRepeatListLock)
106 {
107 List<SenseRepeatClass> NewSensors = new List<SenseRepeatClass>();
108 foreach (SenseRepeatClass ts in SenseRepeaters)
109 {
110 if (ts.localID != m_localID && ts.itemID != m_itemID)
111 {
112 NewSensors.Add(ts);
113 }
114 }
115 SenseRepeaters.Clear();
116 SenseRepeaters = NewSensors;
117 }
118 }
119
120 public void CheckSenseRepeaterEvents()
121 {
122 // Nothing to do here?
123 if (SenseRepeaters.Count == 0)
124 return;
125
126 lock (SenseRepeatListLock)
127 {
128 // Go through all timers
129 foreach (SenseRepeatClass ts in SenseRepeaters)
130 {
131 // Time has passed?
132 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
133 {
134 SensorSweep(ts);
135 // set next interval
136 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
137 }
138 }
139 } // lock
140 }
141
142 public void SenseOnce(uint m_localID, UUID m_itemID,
143 string name, UUID keyID, int type,
144 double range, double arc, SceneObjectPart host)
145 {
146 // Add to timer
147 SenseRepeatClass ts = new SenseRepeatClass();
148 ts.localID = m_localID;
149 ts.itemID = m_itemID;
150 ts.interval = 0;
151 ts.name = name;
152 ts.keyID = keyID;
153 ts.type = type;
154 ts.range = range;
155 ts.arc = arc;
156 ts.host = host;
157 SensorSweep(ts);
158 }
159
160 public LSL_Types.list GetSensorList(uint m_localID, UUID m_itemID)
161 {
162 lock (SenseLock)
163 {
164 Dictionary<UUID, LSL_Types.list> Obj = null;
165 if (!SenseEvents.TryGetValue(m_localID, out Obj))
166 {
167 #if SPAM
168 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing localID: " + m_localID);
169 #endif
170 return null;
171 }
172 lock (Obj)
173 {
174 // Get script
175 LSL_Types.list SenseList = null;
176 if (!Obj.TryGetValue(m_itemID, out SenseList))
177 {
178 #if SPAM
179 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing itemID: " + m_itemID);
180 #endif
181 return null;
182 }
183 return SenseList;
184 }
185 }
186 }
187
188 private void SensorSweep(SenseRepeatClass ts)
189 {
190 //m_ScriptEngine.Log.Info("[AsyncLSL]:Enter SensorSweep");
191 SceneObjectPart SensePoint = ts.host;
192
193 if (SensePoint == null)
194 {
195
196 #if SPAM
197 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep (SensePoint == null) for "+ts.itemID.ToString());
198 #endif
199 return;
200 }
201 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep Scan");
202
203 Vector3 sensorPos = SensePoint.AbsolutePosition;
204 Vector3 regionPos = new Vector3(m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocX * Constants.RegionSize, m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
205 Vector3 fromRegionPos = sensorPos + regionPos;
206
207 Quaternion q = SensePoint.RotationOffset;
208 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
209 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
210 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
211
212 // Here we should do some smart culling ...
213 // math seems quicker than strings so try that first
214 LSL_Types.list SensedObjects = new LSL_Types.list();
215 LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
216
217 foreach (EntityBase ent in m_CmdManager.m_ScriptEngine.World.Entities.Values)
218 {
219 Vector3 toRegionPos = ent.AbsolutePosition + regionPos;
220 double dis = Math.Abs((double)Util.GetDistanceTo(toRegionPos, fromRegionPos));
221 if (dis <= ts.range)
222 {
223 // In Range, is it the right Type ?
224 int objtype = 0;
225
226 if (m_CmdManager.m_ScriptEngine.World.GetScenePresence(ent.UUID) != null) objtype |= 0x01; // actor
227 if (ent.Velocity.Equals(ZeroVector))
228 objtype |= 0x04; // passive non-moving
229 else
230 objtype |= 0x02; // active moving
231 if (ent is IScript) objtype |= 0x08; // Scripted. It COULD have one hidden ...
232
233 if (((ts.type & objtype) != 0) || ((ts.type & objtype) == ts.type))
234 {
235 // docs claim AGENT|ACTIVE should find agent objects OR active objects
236 // so the bitwise AND with object type should be non-zero
237
238 // Right type too, what about the other params , key and name ?
239 bool keep = true;
240 if (ts.arc < Math.PI)
241 {
242 // not omni-directional. Can you see it ?
243 // vec forward_dir = llRot2Fwd(llGetRot())
244 // vec obj_dir = toRegionPos-fromRegionPos
245 // dot=dot(forward_dir,obj_dir)
246 // mag_fwd = mag(forward_dir)
247 // mag_obj = mag(obj_dir)
248 // ang = acos(dot /(mag_fwd*mag_obj))
249 double ang_obj = 0;
250 try
251 {
252 Vector3 diff = toRegionPos - fromRegionPos;
253 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
254 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
255 double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
256 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
257 }
258 catch
259 {
260 }
261
262 if (ang_obj > ts.arc) keep = false;
263 }
264
265 if (keep && (ts.keyID != UUID.Zero) && (ts.keyID != ent.UUID))
266 {
267 keep = false;
268 }
269
270 if (keep && (ts.name.Length > 0))
271 {
272 string avatarname=null;
273 string objectname=null;
274 string entname =ent.Name;
275
276 // try avatar username surname
277 CachedUserInfo profile = m_CmdManager.m_ScriptEngine.World.CommsManager.UserProfileCacheService.GetUserDetails(ent.UUID);
278 if (profile != null && profile.UserProfile != null)
279 {
280 avatarname = profile.UserProfile.FirstName + " " + profile.UserProfile.SurName;
281 }
282 // try an scene object
283 SceneObjectPart SOP = m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(ent.UUID);
284 if (SOP != null)
285 {
286 objectname = SOP.Name;
287 }
288
289 if ((ts.name != entname) && (ts.name != avatarname) && (ts.name != objectname))
290 {
291 keep = false;
292 }
293 }
294
295 if (keep == true) SensedObjects.Add(ent.UUID);
296 }
297 }
298 }
299 #if SPAM
300 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep SenseLock");
301 #endif
302 lock (SenseLock)
303 {
304 // Create object if it doesn't exist
305 if (SenseEvents.ContainsKey(ts.localID) == false)
306 {
307 SenseEvents.Add(ts.localID, new Dictionary<UUID, LSL_Types.list>());
308 }
309 // clear if previous traces exist
310 Dictionary<UUID, LSL_Types.list> Obj;
311 SenseEvents.TryGetValue(ts.localID, out Obj);
312 if (Obj.ContainsKey(ts.itemID) == true)
313 Obj.Remove(ts.itemID);
314
315 // note list may be zero length
316 Obj.Add(ts.itemID, SensedObjects);
317
318 if (SensedObjects.Length == 0)
319 {
320 // send a "no_sensor"
321 // Add it to queue
322 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "no_sensor", EventQueueManager.llDetectNull,
323 new object[] { });
324 }
325 else
326 {
327 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "sensor", EventQueueManager.llDetectNull,
328 new object[] { new LSL_Types.LSLInteger(SensedObjects.Length) });
329 }
330 m_CmdManager.m_ScriptEngine.World.EventManager.TriggerTimerEvent(ts.localID, ts.interval);
331 }
332 }
333 }
334}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
deleted file mode 100644
index 7940b36..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/Timer.cs
+++ /dev/null
@@ -1,139 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using OpenMetaverse;
32
33namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
34{
35 public class Timer
36 {
37 public AsyncCommandManager m_CmdManager;
38
39 public Timer(AsyncCommandManager CmdManager)
40 {
41 m_CmdManager = CmdManager;
42 }
43
44 //
45 // TIMER
46 //
47 private class TimerClass
48 {
49 public uint localID;
50 public UUID itemID;
51 //public double interval;
52 public long interval;
53 //public DateTime next;
54 public long next;
55 }
56
57 private List<TimerClass> Timers = new List<TimerClass>();
58 private object TimerListLock = new object();
59
60 public void SetTimerEvent(uint m_localID, UUID m_itemID, double sec)
61 {
62 // Console.WriteLine("SetTimerEvent");
63
64 // Always remove first, in case this is a re-set
65 UnSetTimerEvents(m_localID, m_itemID);
66 if (sec == 0) // Disabling timer
67 return;
68
69 // Add to timer
70 TimerClass ts = new TimerClass();
71 ts.localID = m_localID;
72 ts.itemID = m_itemID;
73 ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait
74 // 2193386136332921 ticks
75 // 219338613 seconds
76
77 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
78 ts.next = DateTime.Now.Ticks + ts.interval;
79 lock (TimerListLock)
80 {
81 Timers.Add(ts);
82 }
83 }
84
85 public void UnSetTimerEvents(uint m_localID, UUID m_itemID)
86 {
87 // Remove from timer
88 lock (TimerListLock)
89 {
90 foreach (TimerClass ts in new ArrayList(Timers))
91 {
92 if (ts.localID == m_localID && ts.itemID == m_itemID)
93 Timers.Remove(ts);
94 }
95 }
96
97 // Old method: Create new list
98 //List<TimerClass> NewTimers = new List<TimerClass>();
99 //foreach (TimerClass ts in Timers)
100 //{
101 // if (ts.localID != m_localID && ts.itemID != m_itemID)
102 // {
103 // NewTimers.Add(ts);
104 // }
105 //}
106 //Timers.Clear();
107 //Timers = NewTimers;
108 //}
109 }
110
111 public void CheckTimerEvents()
112 {
113 // Nothing to do here?
114 if (Timers.Count == 0)
115 return;
116
117 lock (TimerListLock)
118 {
119 // Go through all timers
120 foreach (TimerClass ts in Timers)
121 {
122 // Time has passed?
123 if (ts.next < DateTime.Now.Ticks)
124 {
125 // Console.WriteLine("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
126 // Add it to queue
127 m_CmdManager.m_ScriptEngine.m_EventQueueManager.AddToScriptQueue(ts.localID, ts.itemID, "timer", EventQueueManager.llDetectNull,
128 null);
129 m_CmdManager.m_ScriptEngine.World.EventManager.TriggerTimerEvent(ts.localID, ((double)ts.interval / 10000000));
130 // set next interval
131
132 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
133 ts.next = DateTime.Now.Ticks + ts.interval;
134 }
135 }
136 }
137 }
138 }
139}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/XmlRequest.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/XmlRequest.cs
deleted file mode 100644
index 9a01cc4..0000000
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/AsyncCommandPlugins/XmlRequest.cs
+++ /dev/null
@@ -1,130 +0,0 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using OpenSim.Region.Environment.Interfaces;
30using OpenSim.Region.Environment.Modules.Scripting.XMLRPC;
31using OpenSim.Region.ScriptEngine.Shared;
32
33namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.AsyncCommandPlugins
34{
35 public class XmlRequest
36 {
37 public AsyncCommandManager m_CmdManager;
38
39 public XmlRequest(AsyncCommandManager CmdManager)
40 {
41 m_CmdManager = CmdManager;
42 }
43
44 public void CheckXMLRPCRequests()
45 {
46 if (m_CmdManager.m_ScriptEngine.World == null)
47 return;
48
49 IXMLRPC xmlrpc = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IXMLRPC>();
50 if (null == xmlrpc)
51 return;
52
53 // Process the completed request queue
54 RPCRequestInfo rInfo = xmlrpc.GetNextCompletedRequest();
55
56 while (rInfo != null)
57 {
58 bool handled = false;
59
60 // Request must be taken out of the queue in case there is no handler, otherwise we loop infinitely
61 xmlrpc.RemoveCompletedRequest(rInfo.GetMessageID());
62
63 // And since the xmlrpc request queue is actually shared among all regions on the simulator, we need
64 // to look in each one for the appropriate handler
65 foreach (ScriptEngine sman in ScriptEngine.ScriptEngines) {
66 if (sman.m_ScriptManager.GetScript(rInfo.GetLocalID(),rInfo.GetItemID()) != null) {
67
68 //Deliver data to prim's remote_data handler
69 object[] resobj = new object[]
70 {
71 new LSL_Types.LSLInteger(2), new LSL_Types.LSLString(rInfo.GetChannelKey().ToString()), new LSL_Types.LSLString(rInfo.GetMessageID().ToString()), new LSL_Types.LSLString(String.Empty),
72 new LSL_Types.LSLInteger(rInfo.GetIntValue()),
73 new LSL_Types.LSLString(rInfo.GetStrVal())
74 };
75 sman.m_EventQueueManager.AddToScriptQueue(
76 rInfo.GetLocalID(), rInfo.GetItemID(), "remote_data", EventQueueManager.llDetectNull, resobj
77 );
78
79 handled = true;
80 }
81 }
82
83 if (! handled)
84 {
85 Console.WriteLine("Unhandled xml_request: " + rInfo.GetItemID());
86 }
87
88 rInfo = xmlrpc.GetNextCompletedRequest();
89 }
90
91 // Process the send queue
92 SendRemoteDataRequest srdInfo = xmlrpc.GetNextCompletedSRDRequest();
93
94 while (srdInfo != null)
95 {
96 bool handled = false;
97
98 // Request must be taken out of the queue in case there is no handler, otherwise we loop infinitely
99 xmlrpc.RemoveCompletedSRDRequest(srdInfo.GetReqID());
100
101 // And this is another shared queue... so we check each of the script engines for a handler
102 foreach (ScriptEngine sman in ScriptEngine.ScriptEngines)
103 {
104 if (sman.m_ScriptManager.GetScript(srdInfo.m_localID,srdInfo.m_itemID) != null) {
105
106 //Deliver data to prim's remote_data handler
107 object[] resobj = new object[]
108 {
109 new LSL_Types.LSLInteger(3), new LSL_Types.LSLString(srdInfo.channel.ToString()), new LSL_Types.LSLString(srdInfo.GetReqID().ToString()), new LSL_Types.LSLString(String.Empty),
110 new LSL_Types.LSLInteger(srdInfo.idata),
111 new LSL_Types.LSLString(srdInfo.sdata)
112 };
113 sman.m_EventQueueManager.AddToScriptQueue(
114 srdInfo.m_localID, srdInfo.m_itemID, "remote_data", EventQueueManager.llDetectNull, resobj
115 );
116
117 handled = true;
118 }
119 }
120
121 if (! handled)
122 {
123 Console.WriteLine("Unhandled xml_srdrequest: " + srdInfo.GetReqID());
124 }
125
126 srdInfo = xmlrpc.GetNextCompletedSRDRequest();
127 }
128 }
129 }
130}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs
index d52b642..c8c9cd8 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventManager.cs
@@ -114,83 +114,103 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
114 public void changed(uint localID, uint change) 114 public void changed(uint localID, uint change)
115 { 115 {
116 // Add to queue for all scripts in localID, Object pass change. 116 // Add to queue for all scripts in localID, Object pass change.
117 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "changed", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(change) }); 117 myScriptEngine.PostObjectEvent(localID, new EventParams(
118 "changed",new object[] { new LSL_Types.LSLInteger(change) },
119 new DetectParams[0]));
118 } 120 }
119 121
120 public void state_entry(uint localID) 122 public void state_entry(uint localID)
121 { 123 {
122 // Add to queue for all scripts in ObjectID object 124 // Add to queue for all scripts in ObjectID object
123 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "state_entry", EventQueueManager.llDetectNull, new object[] { }); 125 myScriptEngine.PostObjectEvent(localID, new EventParams(
126 "state_entry",new object[] { },
127 new DetectParams[0]));
124 } 128 }
125 129
126 public void touch_start(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient) 130 public void touch_start(uint localID, uint originalID, Vector3 offsetPos,
131 IClientAPI remoteClient)
127 { 132 {
128 // Add to queue for all scripts in ObjectID object 133 // Add to queue for all scripts in ObjectID object
129 EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); 134 DetectParams[] det = new DetectParams[1];
130 detstruct._key = new LSL_Types.key[1]; 135 det[0] = new DetectParams();
131 detstruct._key2 = new LSL_Types.key[1]; 136 det[0].Key = remoteClient.AgentId;
132 detstruct._string = new string[1]; 137 det[0].Populate(myScriptEngine.World);
133 detstruct._Vector3 = new LSL_Types.Vector3[1]; 138
134 detstruct._Vector32 = new LSL_Types.Vector3[1]; 139 if (originalID == 0)
135 detstruct._Quaternion = new LSL_Types.Quaternion[1]; 140 {
136 detstruct._int = new int[1]; 141 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
137 ScenePresence av = myScriptEngine.World.GetScenePresence(remoteClient.AgentId); 142 if (part == null)
138 if (av != null) 143 return;
144
145 det[0].LinkNum = part.LinkNum;
146 }
147 else
148 {
149 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
150 det[0].LinkNum = originalPart.LinkNum;
151 }
152
153 myScriptEngine.PostObjectEvent(localID, new EventParams(
154 "touch_start", new Object[] { new LSL_Types.LSLInteger(1) },
155 det));
156 }
157
158 public void touch(uint localID, uint originalID, Vector3 offsetPos,
159 IClientAPI remoteClient)
160 {
161 // Add to queue for all scripts in ObjectID object
162 DetectParams[] det = new DetectParams[1];
163 det[0] = new DetectParams();
164 det[0].Key = remoteClient.AgentId;
165 det[0].Populate(myScriptEngine.World);
166 det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X,
167 offsetPos.Y,
168 offsetPos.Z);
169
170 if (originalID == 0)
139 { 171 {
140 detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 172 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
141 detstruct._key2[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 173 if (part == null)
142 detstruct._string[0] = remoteClient.Name; 174 return;
143 detstruct._int[0] = 0; 175
144 detstruct._Quaternion[0] = new LSL_Types.Quaternion(av.Rotation.X,av.Rotation.Y,av.Rotation.Z,av.Rotation.W); 176 det[0].LinkNum = part.LinkNum;
145 detstruct._Vector3[0] = new LSL_Types.Vector3(av.AbsolutePosition.X,av.AbsolutePosition.Y,av.AbsolutePosition.Z);
146 detstruct._Vector32[0] = new LSL_Types.Vector3(av.Velocity.X,av.Velocity.Y,av.Velocity.Z);
147 } 177 }
148 else 178 else
149 { 179 {
150 detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 180 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
151 detstruct._key2[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 181 det[0].LinkNum = originalPart.LinkNum;
152 detstruct._string[0] = remoteClient.Name;
153 detstruct._int[0] = 0;
154 detstruct._Quaternion[0] = new LSL_Types.Quaternion(0, 0, 0, 1);
155 detstruct._Vector3[0] = new LSL_Types.Vector3(0, 0, 0);
156 detstruct._Vector32[0] = new LSL_Types.Vector3(0, 0, 0);
157 } 182 }
158 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_start", detstruct, new object[] { new LSL_Types.LSLInteger(1) }); 183
184 myScriptEngine.PostObjectEvent(localID, new EventParams(
185 "touch", new Object[] { new LSL_Types.LSLInteger(1) },
186 det));
159 } 187 }
160 188
161 public void touch_end(uint localID, uint originalID, IClientAPI remoteClient) 189 public void touch_end(uint localID, uint originalID, IClientAPI remoteClient)
162 { 190 {
163 // Add to queue for all scripts in ObjectID object 191 // Add to queue for all scripts in ObjectID object
164 EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); 192 DetectParams[] det = new DetectParams[1];
165 detstruct._key = new LSL_Types.key[1]; 193 det[0] = new DetectParams();
166 detstruct._key2 = new LSL_Types.key[1]; 194 det[0].Key = remoteClient.AgentId;
167 detstruct._string = new string[1]; 195 det[0].Populate(myScriptEngine.World);
168 detstruct._Vector3 = new LSL_Types.Vector3[1]; 196
169 detstruct._Vector32 = new LSL_Types.Vector3[1]; 197 if (originalID == 0)
170 detstruct._Quaternion = new LSL_Types.Quaternion[1];
171 detstruct._int = new int[1];
172 ScenePresence av = myScriptEngine.World.GetScenePresence(remoteClient.AgentId);
173 if (av != null)
174 { 198 {
175 detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 199 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
176 detstruct._key2[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 200 if (part == null)
177 detstruct._string[0] = remoteClient.Name; 201 return;
178 detstruct._int[0] = 0; 202
179 detstruct._Quaternion[0] = new LSL_Types.Quaternion(av.Rotation.X, av.Rotation.Y, av.Rotation.Z, av.Rotation.W); 203 det[0].LinkNum = part.LinkNum;
180 detstruct._Vector3[0] = new LSL_Types.Vector3(av.AbsolutePosition.X, av.AbsolutePosition.Y, av.AbsolutePosition.Z);
181 detstruct._Vector32[0] = new LSL_Types.Vector3(av.Velocity.X, av.Velocity.Y, av.Velocity.Z);
182 } 204 }
183 else 205 else
184 { 206 {
185 detstruct._key[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 207 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
186 detstruct._key2[0] = new LSL_Types.key(remoteClient.AgentId.ToString()); 208 det[0].LinkNum = originalPart.LinkNum;
187 detstruct._string[0] = remoteClient.Name;
188 detstruct._int[0] = 0;
189 detstruct._Quaternion[0] = new LSL_Types.Quaternion(0, 0, 0, 1);
190 detstruct._Vector3[0] = new LSL_Types.Vector3(0, 0, 0);
191 detstruct._Vector32[0] = new LSL_Types.Vector3(0, 0, 0);
192 } 209 }
193 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "touch_end", detstruct, new object[] { new LSL_Types.LSLInteger(1) }); 210
211 myScriptEngine.PostObjectEvent(localID, new EventParams(
212 "touch_end", new Object[] { new LSL_Types.LSLInteger(1) },
213 det));
194 } 214 }
195 215
196 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine) 216 public void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine)
@@ -228,7 +248,11 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
228 248
229 public void money(uint localID, UUID agentID, int amount) 249 public void money(uint localID, UUID agentID, int amount)
230 { 250 {
231 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "money", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLString(agentID.ToString()), new LSL_Types.LSLInteger(amount) }); 251 myScriptEngine.PostObjectEvent(localID, new EventParams(
252 "money", new object[] {
253 new LSL_Types.LSLString(agentID.ToString()),
254 new LSL_Types.LSLInteger(amount) },
255 new DetectParams[0]));
232 } 256 }
233 257
234 // TODO: Replace placeholders below 258 // TODO: Replace placeholders below
@@ -239,225 +263,196 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
239 263
240 public void state_exit(uint localID) 264 public void state_exit(uint localID)
241 { 265 {
242 // Add to queue for all scripts in ObjectID object 266 myScriptEngine.PostObjectEvent(localID, new EventParams(
243 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "state_exit", EventQueueManager.llDetectNull, new object[] { }); 267 "state_exit", new object[] { },
244 } 268 new DetectParams[0]));
245
246 public void touch(uint localID, uint originalID, UUID itemID)
247 {
248 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "touch", EventQueueManager.llDetectNull);
249 }
250
251 public void touch_end(uint localID, uint originalID, UUID itemID)
252 {
253 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "touch_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(1) });
254 } 269 }
255 270
256 public void collision_start(uint localID, ColliderArgs col) 271 public void collision_start(uint localID, ColliderArgs col)
257 { 272 {
258 EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); 273 // Add to queue for all scripts in ObjectID object
259 detstruct._string = new string[col.Colliders.Count]; 274 List<DetectParams> det = new List<DetectParams>();
260 detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; 275
261 detstruct._int = new int[col.Colliders.Count];
262 detstruct._key = new LSL_Types.key[col.Colliders.Count];
263 detstruct._key2 = new LSL_Types.key[col.Colliders.Count];
264 detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count];
265 detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count];
266 detstruct._bool = new bool[col.Colliders.Count];
267
268 int i = 0;
269 foreach (DetectedObject detobj in col.Colliders) 276 foreach (DetectedObject detobj in col.Colliders)
270 { 277 {
271 detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); 278 DetectParams d = new DetectParams();
272 detstruct._key2[i] = new LSL_Types.key(detobj.ownerUUID.ToString()); 279 d.Key =detobj.keyUUID;
273 detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); 280 d.Populate(myScriptEngine.World);
274 detstruct._string[i] = detobj.nameStr; 281 det.Add(d);
275 detstruct._int[i] = detobj.colliderType;
276 detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z);
277 detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z);
278 detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry...
279 i++;
280 } 282 }
281 283
282 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision_start", detstruct, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); 284 if (det.Count > 0)
285 myScriptEngine.PostObjectEvent(localID, new EventParams(
286 "collision_start",
287 new Object[] { new LSL_Types.LSLInteger(det.Count) },
288 det.ToArray()));
283 } 289 }
284 290
285 public void collision(uint localID, ColliderArgs col) 291 public void collision(uint localID, ColliderArgs col)
286 { 292 {
287 EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); 293 // Add to queue for all scripts in ObjectID object
288 detstruct._string = new string[col.Colliders.Count]; 294 List<DetectParams> det = new List<DetectParams>();
289 detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; 295
290 detstruct._int = new int[col.Colliders.Count];
291 detstruct._key = new LSL_Types.key[col.Colliders.Count];
292 detstruct._key2 = new LSL_Types.key[col.Colliders.Count];
293 detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count];
294 detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count];
295 detstruct._bool = new bool[col.Colliders.Count];
296
297 int i = 0;
298 foreach (DetectedObject detobj in col.Colliders) 296 foreach (DetectedObject detobj in col.Colliders)
299 { 297 {
300 detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); 298 DetectParams d = new DetectParams();
301 detstruct._key2[i] = new LSL_Types.key(detobj.ownerUUID.ToString()); 299 d.Key =detobj.keyUUID;
302 detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); 300 d.Populate(myScriptEngine.World);
303 detstruct._string[i] = detobj.nameStr; 301 det.Add(d);
304 detstruct._int[i] = detobj.colliderType;
305 detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z);
306 detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z);
307 detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry... i++;
308 } 302 }
309 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision", detstruct, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); 303
304 if (det.Count > 0)
305 myScriptEngine.PostObjectEvent(localID, new EventParams(
306 "collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
307 det.ToArray()));
310 } 308 }
311 309
312 public void collision_end(uint localID, ColliderArgs col) 310 public void collision_end(uint localID, ColliderArgs col)
313 { 311 {
314 EventQueueManager.Queue_llDetectParams_Struct detstruct = new EventQueueManager.Queue_llDetectParams_Struct(); 312 // Add to queue for all scripts in ObjectID object
315 detstruct._string = new string[col.Colliders.Count]; 313 List<DetectParams> det = new List<DetectParams>();
316 detstruct._Quaternion = new LSL_Types.Quaternion[col.Colliders.Count]; 314
317 detstruct._int = new int[col.Colliders.Count];
318 detstruct._key = new LSL_Types.key[col.Colliders.Count];
319 detstruct._key2 = new LSL_Types.key[col.Colliders.Count];
320 detstruct._Vector3 = new LSL_Types.Vector3[col.Colliders.Count];
321 detstruct._Vector32 = new LSL_Types.Vector3[col.Colliders.Count];
322 detstruct._bool = new bool[col.Colliders.Count];
323
324 int i = 0;
325 foreach (DetectedObject detobj in col.Colliders) 315 foreach (DetectedObject detobj in col.Colliders)
326 { 316 {
327 detstruct._key[i] = new LSL_Types.key(detobj.keyUUID.ToString()); 317 DetectParams d = new DetectParams();
328 detstruct._key2[i] = new LSL_Types.key(detobj.ownerUUID.ToString()); 318 d.Key =detobj.keyUUID;
329 detstruct._Quaternion[i] = new LSL_Types.Quaternion(detobj.rotQuat.X, detobj.rotQuat.Y, detobj.rotQuat.Z, detobj.rotQuat.W); 319 d.Populate(myScriptEngine.World);
330 detstruct._string[i] = detobj.nameStr; 320 det.Add(d);
331 detstruct._int[i] = detobj.colliderType;
332 detstruct._Vector3[i] = new LSL_Types.Vector3(detobj.posVector.X, detobj.posVector.Y, detobj.posVector.Z);
333 detstruct._Vector32[i] = new LSL_Types.Vector3(detobj.velVector.X, detobj.velVector.Y, detobj.velVector.Z);
334 detstruct._bool[i] = true; // Apparently the script engine uses this to see if this is a valid entry...
335 i++;
336 } 321 }
337 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "collision_end", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(col.Colliders.Count) }); 322
323 if (det.Count > 0)
324 myScriptEngine.PostObjectEvent(localID, new EventParams(
325 "collision_end",
326 new Object[] { new LSL_Types.LSLInteger(det.Count) },
327 det.ToArray()));
338 } 328 }
339 329
340 public void land_collision_start(uint localID, UUID itemID) 330 public void land_collision_start(uint localID, UUID itemID)
341 { 331 {
342 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "land_collision_start", EventQueueManager.llDetectNull); 332 myScriptEngine.PostObjectEvent(localID, new EventParams(
333 "land_collision_start",
334 new object[0],
335 new DetectParams[0]));
343 } 336 }
344 337
345 public void land_collision(uint localID, ColliderArgs col) 338 public void land_collision(uint localID, UUID itemID)
346 { 339 {
347 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "land_collision", EventQueueManager.llDetectNull); 340 myScriptEngine.PostObjectEvent(localID, new EventParams(
341 "land_collision",
342 new object[0],
343 new DetectParams[0]));
348 } 344 }
349 345
350 public void land_collision_end(uint localID, UUID itemID) 346 public void land_collision_end(uint localID, UUID itemID)
351 { 347 {
352 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "land_collision_end", EventQueueManager.llDetectNull); 348 myScriptEngine.PostObjectEvent(localID, new EventParams(
349 "land_collision_end",
350 new object[0],
351 new DetectParams[0]));
353 } 352 }
354 353
355 // Handled by long commands 354 // Handled by long commands
356 public void timer(uint localID, UUID itemID) 355 public void timer(uint localID, UUID itemID)
357 { 356 {
358 //myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, String.Empty);
359 } 357 }
360 358
361 public void listen(uint localID, UUID itemID) 359 public void listen(uint localID, UUID itemID)
362 { 360 {
363 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "listen", EventQueueManager.llDetectNull);
364 }
365
366 public void on_rez(uint localID, UUID itemID)
367 {
368 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "on_rez", EventQueueManager.llDetectNull);
369 }
370
371 public void sensor(uint localID, UUID itemID)
372 {
373 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "sensor", EventQueueManager.llDetectNull);
374 }
375
376 public void no_sensor(uint localID, UUID itemID)
377 {
378 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "no_sensor", EventQueueManager.llDetectNull);
379 } 361 }
380 362
381 public void control(uint localID, UUID itemID, UUID agentID, uint held, uint change) 363 public void control(uint localID, UUID itemID, UUID agentID, uint held, uint change)
382 { 364 {
383 if ((change == 0) && (myScriptEngine.m_EventQueueManager.CheckEeventQueueForEvent(localID,"control"))) return; 365 if ((change == 0) && (myScriptEngine.m_EventQueueManager.CheckEeventQueueForEvent(localID,"control"))) return;
384 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "control", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLString(agentID.ToString()), new LSL_Types.LSLInteger(held), new LSL_Types.LSLInteger(change)}); 366 myScriptEngine.PostObjectEvent(localID, new EventParams(
367 "control",new object[] {
368 new LSL_Types.LSLString(agentID.ToString()),
369 new LSL_Types.LSLInteger(held),
370 new LSL_Types.LSLInteger(change)},
371 new DetectParams[0]));
385 } 372 }
386 373
387 public void email(uint localID, UUID itemID) 374 public void email(uint localID, UUID itemID, string timeSent,
375 string address, string subject, string message, int numLeft)
388 { 376 {
389 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "email", EventQueueManager.llDetectNull); 377 myScriptEngine.PostObjectEvent(localID, new EventParams(
378 "email",new object[] {
379 new LSL_Types.LSLString(timeSent),
380 new LSL_Types.LSLString(address),
381 new LSL_Types.LSLString(subject),
382 new LSL_Types.LSLString(message),
383 new LSL_Types.LSLInteger(numLeft)},
384 new DetectParams[0]));
390 } 385 }
391 386
392 public void at_target(uint localID, uint handle, Vector3 targetpos, Vector3 atpos) 387 public void at_target(uint localID, uint handle, Vector3 targetpos,
388 Vector3 atpos)
393 { 389 {
394 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "at_target", EventQueueManager.llDetectNull, new object[] { new LSL_Types.LSLInteger(handle), new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z), new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) }); 390 myScriptEngine.PostObjectEvent(localID, new EventParams(
391 "at_target", new object[] {
392 new LSL_Types.LSLInteger(handle),
393 new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z),
394 new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) },
395 new DetectParams[0]));
395 } 396 }
396 397
397 public void not_at_target(uint localID) 398 public void not_at_target(uint localID)
398 { 399 {
399 myScriptEngine.m_EventQueueManager.AddToObjectQueue(localID, "not_at_target", EventQueueManager.llDetectNull); 400 myScriptEngine.PostObjectEvent(localID, new EventParams(
401 "not_at_target",new object[0],
402 new DetectParams[0]));
400 } 403 }
401 404
402 public void at_rot_target(uint localID, UUID itemID) 405 public void at_rot_target(uint localID, UUID itemID)
403 { 406 {
404 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "at_rot_target", EventQueueManager.llDetectNull); 407 myScriptEngine.PostObjectEvent(localID, new EventParams(
408 "at_rot_target",new object[0],
409 new DetectParams[0]));
405 } 410 }
406 411
407 public void not_at_rot_target(uint localID, UUID itemID) 412 public void not_at_rot_target(uint localID, UUID itemID)
408 { 413 {
409 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "not_at_rot_target", EventQueueManager.llDetectNull); 414 myScriptEngine.PostObjectEvent(localID, new EventParams(
410 } 415 "not_at_rot_target",new object[0],
411 416 new DetectParams[0]));
412 public void run_time_permissions(uint localID, UUID itemID)
413 {
414 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "run_time_permissions", EventQueueManager.llDetectNull);
415 }
416
417 public void changed(uint localID, UUID itemID)
418 {
419 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "changed", EventQueueManager.llDetectNull);
420 } 417 }
421 418
422 public void attach(uint localID, UUID itemID) 419 public void attach(uint localID, UUID itemID)
423 { 420 {
424 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "attach", EventQueueManager.llDetectNull);
425 } 421 }
426 422
427 public void dataserver(uint localID, UUID itemID) 423 public void dataserver(uint localID, UUID itemID)
428 { 424 {
429 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "dataserver", EventQueueManager.llDetectNull);
430 } 425 }
431 426
432 public void link_message(uint localID, UUID itemID) 427 public void link_message(uint localID, UUID itemID)
433 { 428 {
434 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "link_message", EventQueueManager.llDetectNull);
435 } 429 }
436 430
437 public void moving_start(uint localID, UUID itemID) 431 public void moving_start(uint localID, UUID itemID)
438 { 432 {
439 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "moving_start", EventQueueManager.llDetectNull); 433 myScriptEngine.PostObjectEvent(localID, new EventParams(
434 "moving_start",new object[0],
435 new DetectParams[0]));
440 } 436 }
441 437
442 public void moving_end(uint localID, UUID itemID) 438 public void moving_end(uint localID, UUID itemID)
443 { 439 {
444 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "moving_end", EventQueueManager.llDetectNull); 440 myScriptEngine.PostObjectEvent(localID, new EventParams(
441 "moving_end",new object[0],
442 new DetectParams[0]));
445 } 443 }
446 444
447 public void object_rez(uint localID, UUID itemID) 445 public void object_rez(uint localID, UUID itemID)
448 { 446 {
449 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "object_rez", EventQueueManager.llDetectNull);
450 } 447 }
451 448
452 public void remote_data(uint localID, UUID itemID) 449 public void remote_data(uint localID, UUID itemID)
453 { 450 {
454 myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "remote_data", EventQueueManager.llDetectNull);
455 } 451 }
456 452
457 // Handled by long commands 453 // Handled by long commands
458 public void http_response(uint localID, UUID itemID) 454 public void http_response(uint localID, UUID itemID)
459 { 455 {
460 // myScriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "http_response", EventQueueManager.llDetectNull);
461 } 456 }
462 457
463 /// <summary> 458 /// <summary>
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
index 8c7834a..b13ab21 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/EventQueueManager.cs
@@ -137,32 +137,10 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
137 public uint localID; 137 public uint localID;
138 public UUID itemID; 138 public UUID itemID;
139 public string functionName; 139 public string functionName;
140 public Queue_llDetectParams_Struct llDetectParams; 140 public DetectParams[] llDetectParams;
141 public object[] param; 141 public object[] param;
142 } 142 }
143 143
144 /// <summary>
145 /// Shared empty llDetectNull
146 /// </summary>
147 public readonly static Queue_llDetectParams_Struct llDetectNull = new Queue_llDetectParams_Struct();
148
149 /// <summary>
150 /// Structure to hold data for llDetect* commands
151 /// </summary>
152 [Serializable]
153 public struct Queue_llDetectParams_Struct
154 {
155 // More or less just a placeholder for the actual moving of additional data
156 // should be fixed to something better :)
157 public LSL_Types.key[] _key; // detected key
158 public LSL_Types.key[] _key2; // ownerkey
159 public LSL_Types.Quaternion[] _Quaternion;
160 public LSL_Types.Vector3[] _Vector3; // Pos
161 public LSL_Types.Vector3[] _Vector32; // Vel
162 public bool[] _bool;
163 public int[] _int;
164 public string[] _string;
165 }
166 #endregion 144 #endregion
167 145
168 #region " Initialization / Startup " 146 #region " Initialization / Startup "
@@ -322,7 +300,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
322 /// <param name="localID">Region object ID</param> 300 /// <param name="localID">Region object ID</param>
323 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> 301 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
324 /// <param name="param">Array of parameters to match event mask</param> 302 /// <param name="param">Array of parameters to match event mask</param>
325 public bool AddToObjectQueue(uint localID, string FunctionName, Queue_llDetectParams_Struct qParams, params object[] param) 303 public bool AddToObjectQueue(uint localID, string FunctionName, DetectParams[] qParams, params object[] param)
326 { 304 {
327 // Determine all scripts in Object and add to their queue 305 // Determine all scripts in Object and add to their queue
328 //myScriptEngine.log.Info("[" + ScriptEngineName + "]: EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName); 306 //myScriptEngine.log.Info("[" + ScriptEngineName + "]: EventQueueManager Adding localID: " + localID + ", FunctionName: " + FunctionName);
@@ -353,7 +331,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
353 /// <param name="itemID">Region script ID</param> 331 /// <param name="itemID">Region script ID</param>
354 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param> 332 /// <param name="FunctionName">Name of the function, will be state + "_event_" + FunctionName</param>
355 /// <param name="param">Array of parameters to match event mask</param> 333 /// <param name="param">Array of parameters to match event mask</param>
356 public bool AddToScriptQueue(uint localID, UUID itemID, string FunctionName, Queue_llDetectParams_Struct qParams, params object[] param) 334 public bool AddToScriptQueue(uint localID, UUID itemID, string FunctionName, DetectParams[] qParams, params object[] param)
357 { 335 {
358 List<UUID> keylist = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID); 336 List<UUID> keylist = m_ScriptEngine.m_ScriptManager.GetScriptKeys(localID);
359 337
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
index c972683..b09a30b 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptEngine.cs
@@ -57,7 +57,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
57 public EventQueueManager m_EventQueueManager; // Executes events, handles script threads 57 public EventQueueManager m_EventQueueManager; // Executes events, handles script threads
58 public ScriptManager m_ScriptManager; // Load, unload and execute scripts 58 public ScriptManager m_ScriptManager; // Load, unload and execute scripts
59 public AppDomainManager m_AppDomainManager; // Handles loading/unloading of scripts into AppDomains 59 public AppDomainManager m_AppDomainManager; // Handles loading/unloading of scripts into AppDomains
60 public AsyncCommandManager m_ASYNCLSLCommandManager; // Asyncronous LSL commands (commands that returns with an event)
61 public static MaintenanceThread m_MaintenanceThread; // Thread that does different kinds of maintenance, for example refreshing config and killing scripts that has been running too long 60 public static MaintenanceThread m_MaintenanceThread; // Thread that does different kinds of maintenance, for example refreshing config and killing scripts that has been running too long
62 61
63 public IConfigSource ConfigSource; 62 public IConfigSource ConfigSource;
@@ -121,7 +120,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
121 // We need to start it 120 // We need to start it
122 m_ScriptManager = newScriptManager; 121 m_ScriptManager = newScriptManager;
123 m_AppDomainManager = new AppDomainManager(this); 122 m_AppDomainManager = new AppDomainManager(this);
124 m_ASYNCLSLCommandManager = new AsyncCommandManager(this);
125 if (m_MaintenanceThread == null) 123 if (m_MaintenanceThread == null)
126 m_MaintenanceThread = new MaintenanceThread(); 124 m_MaintenanceThread = new MaintenanceThread();
127 125
@@ -172,7 +170,6 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
172 if (m_EventManager != null) m_EventManager.ReadConfig(); 170 if (m_EventManager != null) m_EventManager.ReadConfig();
173 if (m_ScriptManager != null) m_ScriptManager.ReadConfig(); 171 if (m_ScriptManager != null) m_ScriptManager.ReadConfig();
174 if (m_AppDomainManager != null) m_AppDomainManager.ReadConfig(); 172 if (m_AppDomainManager != null) m_AppDomainManager.ReadConfig();
175 if (m_ASYNCLSLCommandManager != null) m_ASYNCLSLCommandManager.ReadConfig();
176 if (m_MaintenanceThread != null) m_MaintenanceThread.ReadConfig(); 173 if (m_MaintenanceThread != null) m_MaintenanceThread.ReadConfig();
177 } 174 }
178 175
@@ -196,15 +193,33 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
196 193
197 public bool PostObjectEvent(uint localID, EventParams p) 194 public bool PostObjectEvent(uint localID, EventParams p)
198 { 195 {
199 return m_EventQueueManager.AddToObjectQueue(localID, p.EventName, EventQueueManager.llDetectNull, p.Params); 196 return m_EventQueueManager.AddToObjectQueue(localID, p.EventName, p.DetectParams, p.Params);
200 } 197 }
201 198
202 public bool PostScriptEvent(UUID itemID, EventParams p) 199 public bool PostScriptEvent(UUID itemID, EventParams p)
203 { 200 {
204 uint localID = m_ScriptManager.GetLocalID(itemID); 201 uint localID = m_ScriptManager.GetLocalID(itemID);
205 return m_EventQueueManager.AddToScriptQueue(localID, itemID, p.EventName, EventQueueManager.llDetectNull, p.Params); 202 return m_EventQueueManager.AddToScriptQueue(localID, itemID, p.EventName, p.DetectParams, p.Params);
206 } 203 }
207 204
205 public DetectParams GetDetectParams(UUID itemID, int number)
206 {
207 uint localID = m_ScriptManager.GetLocalID(itemID);
208 if (localID == 0)
209 return null;
210
211 IScript Script = m_ScriptManager.GetScript(localID, itemID);
212
213 if (Script == null)
214 return null;
215
216 DetectParams[] det = m_ScriptManager.GetDetectParams(Script);
217
218 if (number < 0 || number >= det.Length)
219 return null;
220
221 return det[number];
222 }
208 #endregion 223 #endregion
209 } 224 }
210} 225}
diff --git a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs
index ff8e16f..095e11f 100644
--- a/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs
+++ b/OpenSim/Region/ScriptEngine/Common/ScriptEngineBase/ScriptManager.cs
@@ -33,6 +33,7 @@ using System.Runtime.Serialization.Formatters.Binary;
33using System.Threading; 33using System.Threading;
34using OpenMetaverse; 34using OpenMetaverse;
35using OpenSim.Region.Environment.Scenes; 35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.ScriptEngine.Shared;
36 37
37namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase 38namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
38{ 39{
@@ -65,6 +66,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
65 private int LoadUnloadMaxQueueSize; 66 private int LoadUnloadMaxQueueSize;
66 private Object scriptLock = new Object(); 67 private Object scriptLock = new Object();
67 private bool m_started = false; 68 private bool m_started = false;
69 private Dictionary<IScript, DetectParams[]> detparms = new Dictionary<IScript, DetectParams[]>();
68 70
69 // Load/Unload structure 71 // Load/Unload structure
70 private struct LUStruct 72 private struct LUStruct
@@ -228,6 +230,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
228 if (item.Action == LUType.Unload) 230 if (item.Action == LUType.Unload)
229 { 231 {
230 _StopScript(item.localID, item.itemID); 232 _StopScript(item.localID, item.itemID);
233 RemoveScript(item.localID, item.itemID);
231 } 234 }
232 else if (item.Action == LUType.Load) 235 else if (item.Action == LUType.Load)
233 { 236 {
@@ -318,7 +321,7 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
318 /// <param name="itemID">Script ID</param> 321 /// <param name="itemID">Script ID</param>
319 /// <param name="FunctionName">Name of function</param> 322 /// <param name="FunctionName">Name of function</param>
320 /// <param name="args">Arguments to pass to function</param> 323 /// <param name="args">Arguments to pass to function</param>
321 internal void ExecuteEvent(uint localID, UUID itemID, string FunctionName, EventQueueManager.Queue_llDetectParams_Struct qParams, object[] args) 324 internal void ExecuteEvent(uint localID, UUID itemID, string FunctionName, DetectParams[] qParams, object[] args)
322 { 325 {
323 //cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined 326 //cfk 2-7-08 dont need this right now and the default Linux build has DEBUG defined
324 ///#if DEBUG 327 ///#if DEBUG
@@ -337,8 +340,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
337 /// Console.WriteLine("ScriptEngine: Executing event: " + FunctionName); 340 /// Console.WriteLine("ScriptEngine: Executing event: " + FunctionName);
338 ///#endif 341 ///#endif
339 // Must be done in correct AppDomain, so leaving it up to the script itself 342 // Must be done in correct AppDomain, so leaving it up to the script itself
340 Script.llDetectParams = qParams; 343 detparms[Script] = qParams;
341 Script.Exec.ExecuteEvent(FunctionName, args); 344 Script.Exec.ExecuteEvent(FunctionName, args);
345 detparms.Remove(Script);
342 } 346 }
343 347
344 public uint GetLocalID(UUID itemID) 348 public uint GetLocalID(UUID itemID)
@@ -430,6 +434,9 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
430 434
431 public void RemoveScript(uint localID, UUID itemID) 435 public void RemoveScript(uint localID, UUID itemID)
432 { 436 {
437 if (localID == 0)
438 localID = GetLocalID(itemID);
439
433 // Don't have that object? 440 // Don't have that object?
434 if (Scripts.ContainsKey(localID) == false) 441 if (Scripts.ContainsKey(localID) == false)
435 return; 442 return;
@@ -486,5 +493,13 @@ namespace OpenSim.Region.ScriptEngine.Common.ScriptEngineBase
486 // set { _PleaseShutdown = value; } 493 // set { _PleaseShutdown = value; }
487 //} 494 //}
488 //private bool _PleaseShutdown = false; 495 //private bool _PleaseShutdown = false;
496
497 public DetectParams[] GetDetectParams(IScript script)
498 {
499 if (detparms.ContainsKey(script))
500 return detparms[script];
501
502 return null;
503 }
489 } 504 }
490} 505}