aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins
diff options
context:
space:
mode:
authorlbsa712008-06-24 21:09:49 +0000
committerlbsa712008-06-24 21:09:49 +0000
commit6b7930104bdb845d3b9c085dc04f52b6446f23b1 (patch)
tree05ee45781a455817fa400bb99f30f4d19d4eb1f8 /OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins
parentbased on positive feedback on performance of making keys fixed length (diff)
downloadopensim-SC_OLD-6b7930104bdb845d3b9c085dc04f52b6446f23b1.zip
opensim-SC_OLD-6b7930104bdb845d3b9c085dc04f52b6446f23b1.tar.gz
opensim-SC_OLD-6b7930104bdb845d3b9c085dc04f52b6446f23b1.tar.bz2
opensim-SC_OLD-6b7930104bdb845d3b9c085dc04f52b6446f23b1.tar.xz
* Applied patch from Melanie, mantis issue #1581 - "Refactor LSL language, api and compiler out of XEngine"
"First stage in a major Script Engine refactor, that will result in the LSL implementaions ebing reconverged. Not there yet, but one major part is done." Thank you, Melanie!
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Dataserver.cs127
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Eventstream.cs75
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/HttpRequest.cs89
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Listener.cs91
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/SensorRepeat.cs393
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs161
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/XmlRequest.cs115
7 files changed, 0 insertions, 1051 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Dataserver.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Dataserver.cs
deleted file mode 100644
index 47ab420..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/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 libsecondlife;
32using OpenSim.Region.ScriptEngine.XEngine.Script;
33
34namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
35{
36 public class Dataserver
37 {
38 public AsyncCommandManager m_CmdManager;
39
40 private Dictionary<string, DataserverRequest> DataserverRequests =
41 new Dictionary<string, DataserverRequest>();
42
43 public Dataserver(AsyncCommandManager CmdManager)
44 {
45 m_CmdManager = CmdManager;
46 }
47
48 private class DataserverRequest
49 {
50 public uint localID;
51 public LLUUID itemID;
52
53 public LLUUID ID;
54 public string handle;
55
56 public DateTime startTime;
57 }
58
59 public LLUUID RegisterRequest(uint localID, LLUUID itemID,
60 string identifier)
61 {
62 lock (DataserverRequests)
63 {
64 if (DataserverRequests.ContainsKey(identifier))
65 return LLUUID.Zero;
66
67 DataserverRequest ds = new DataserverRequest();
68
69 ds.localID = localID;
70 ds.itemID = itemID;
71
72 ds.ID = LLUUID.Random();
73 ds.handle = identifier;
74
75 ds.startTime = DateTime.Now;
76
77 DataserverRequests[identifier]=ds;
78
79 return ds.ID;
80 }
81 }
82
83 public void DataserverReply(string identifier, string reply)
84 {
85 DataserverRequest ds;
86
87 lock (DataserverRequests)
88 {
89 if (!DataserverRequests.ContainsKey(identifier))
90 return;
91
92 ds=DataserverRequests[identifier];
93 DataserverRequests.Remove(identifier);
94 }
95
96 m_CmdManager.m_ScriptEngine.PostObjectEvent(ds.localID,
97 new XEventParams("dataserver", new Object[]
98 { new LSL_Types.LSLString(ds.ID.ToString()),
99 new LSL_Types.LSLString(reply)},
100 new XDetectParams[0]));
101 }
102
103 public void RemoveEvents(uint localID, LLUUID 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/XEngine/AsyncCommandPlugins/Eventstream.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Eventstream.cs
deleted file mode 100644
index dab7a0a..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Eventstream.cs
+++ /dev/null
@@ -1,75 +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 libsecondlife;
32using OpenSim.Region.Environment.Scenes;
33
34namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
35{
36 public class Eventstream
37 {
38 public AsyncCommandManager m_CmdManager;
39
40 private class Event
41 {
42 public uint LocalID;
43 public string EventName;
44 public Dictionary<LLUUID, XDetectParams> DetectParams;
45 }
46
47 private Dictionary<uint, Dictionary<string, Event> > m_Events =
48 new Dictionary<uint, Dictionary<string, Event> >();
49
50 public Eventstream(AsyncCommandManager CmdManager)
51 {
52 m_CmdManager = CmdManager;
53 }
54
55 public void AddObjectEvent(uint localID, string eventName, XDetectParams det)
56 {
57 SceneObjectPart part = m_CmdManager.m_ScriptEngine.World.
58 GetSceneObjectPart(localID);
59
60 if (part == null) // Can't register events for non-prims
61 return;
62
63 if (!part.ContainsScripts())
64 return;
65 }
66
67 public void RemoveObjectEvent(uint localID, string eventName, LLUUID id)
68 {
69 }
70
71 public void RemoveObjects(uint localID)
72 {
73 }
74 }
75}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/HttpRequest.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/HttpRequest.cs
deleted file mode 100644
index 089e016..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/HttpRequest.cs
+++ /dev/null
@@ -1,89 +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.XEngine.Script;
32
33namespace OpenSim.Region.ScriptEngine.XEngine.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 iHttpReq.RemoveCompletedRequest(httpInfo.reqID);
69
70 object[] resobj = new object[]
71 {
72 new LSL_Types.LSLString(httpInfo.reqID.ToString()),
73 new LSL_Types.LSLInteger(httpInfo.status),
74 new LSL_Types.list(),
75 new LSL_Types.LSLString(httpInfo.response_body)
76 };
77
78 foreach (XEngine xe in XEngine.ScriptEngines)
79 {
80 if (xe.PostObjectEvent(httpInfo.localID,
81 new XEventParams("http_response",
82 resobj, new XDetectParams[0])))
83 break;
84 }
85 httpInfo = iHttpReq.GetNextCompletedRequest();
86 }
87 }
88 }
89}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Listener.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Listener.cs
deleted file mode 100644
index 1144c00..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Listener.cs
+++ /dev/null
@@ -1,91 +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 libsecondlife;
30using OpenSim.Region.Environment.Interfaces;
31using OpenSim.Region.Environment.Modules.Scripting.WorldComm;
32using OpenSim.Region.ScriptEngine.XEngine.Script;
33
34namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
35{
36 public class Listener
37 {
38 // private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
39
40 public AsyncCommandManager m_CmdManager;
41
42 public Listener(AsyncCommandManager CmdManager)
43 {
44 m_CmdManager = CmdManager;
45 }
46
47 public void CheckListeners()
48 {
49 if (m_CmdManager.m_ScriptEngine.World == null)
50 return;
51 IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
52
53 if (comms != null)
54 {
55 while (comms.HasMessages())
56 {
57 ListenerInfo lInfo = comms.GetNextMessage();
58
59 //Deliver data to prim's listen handler
60 object[] resobj = new object[]
61 {
62 new LSL_Types.LSLInteger(lInfo.GetChannel()),
63 new LSL_Types.LSLString(lInfo.GetName()),
64 new LSL_Types.LSLString(lInfo.GetID().ToString()),
65 new LSL_Types.LSLString(lInfo.GetMessage())
66 };
67
68 m_CmdManager.m_ScriptEngine.PostScriptEvent(
69 lInfo.GetItemID(), new XEventParams(
70 "listen", resobj,
71 new XDetectParams[0]));
72 }
73 }
74 }
75
76 public Object[] GetSerializationData(LLUUID itemID)
77 {
78 IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
79
80 return comms.GetSerializationData(itemID);
81 }
82
83 public void CreateFromData(uint localID, LLUUID itemID, LLUUID hostID,
84 Object[] data)
85 {
86 IWorldComm comms = m_CmdManager.m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
87
88 comms.CreateFromData(localID, itemID, hostID, data);
89 }
90 }
91}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/SensorRepeat.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/SensorRepeat.cs
deleted file mode 100644
index 8a25098..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/SensorRepeat.cs
+++ /dev/null
@@ -1,393 +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.Generic;
30using libsecondlife;
31using OpenSim.Framework;
32using OpenSim.Region.Environment.Scenes;
33using OpenSim.Region.ScriptEngine.XEngine.Script;
34
35namespace OpenSim.Region.ScriptEngine.XEngine.AsyncCommandPlugins
36{
37 public class SensorRepeat
38 {
39 public AsyncCommandManager m_CmdManager;
40
41 public SensorRepeat(AsyncCommandManager CmdManager)
42 {
43 m_CmdManager = CmdManager;
44 }
45
46 public Dictionary<uint, Dictionary<LLUUID, LSL_Types.list>> SenseEvents =
47 new Dictionary<uint, Dictionary<LLUUID, LSL_Types.list>>();
48 private Object SenseLock = new Object();
49
50 //
51 // SenseRepeater and Sensors
52 //
53 private class SenseRepeatClass
54 {
55 public uint localID;
56 public LLUUID itemID;
57 public double interval;
58 public DateTime next;
59
60 public string name;
61 public LLUUID keyID;
62 public int type;
63 public double range;
64 public double arc;
65 public SceneObjectPart host;
66 }
67
68 private List<SenseRepeatClass> SenseRepeaters = new List<SenseRepeatClass>();
69 private object SenseRepeatListLock = new object();
70
71 public void SetSenseRepeatEvent(uint m_localID, LLUUID m_itemID,
72 string name, LLUUID keyID, int type, double range,
73 double arc, double sec, SceneObjectPart host)
74 {
75 Console.WriteLine("SetSensorEvent");
76
77 // Always remove first, in case this is a re-set
78 UnSetSenseRepeaterEvents(m_localID, m_itemID);
79 if (sec == 0) // Disabling timer
80 return;
81
82 // Add to timer
83 SenseRepeatClass ts = new SenseRepeatClass();
84 ts.localID = m_localID;
85 ts.itemID = m_itemID;
86 ts.interval = sec;
87 ts.name = name;
88 ts.keyID = keyID;
89 ts.type = type;
90 ts.range = range;
91 ts.arc = arc;
92 ts.host = host;
93
94 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
95 lock (SenseRepeatListLock)
96 {
97 SenseRepeaters.Add(ts);
98 }
99 }
100
101 public void UnSetSenseRepeaterEvents(uint m_localID, LLUUID m_itemID)
102 {
103 // Remove from timer
104 lock (SenseRepeatListLock)
105 {
106 List<SenseRepeatClass> NewSensors = new List<SenseRepeatClass>();
107 foreach (SenseRepeatClass ts in SenseRepeaters)
108 {
109 if (ts.localID != m_localID && ts.itemID != m_itemID)
110 {
111 NewSensors.Add(ts);
112 }
113 }
114 SenseRepeaters.Clear();
115 SenseRepeaters = NewSensors;
116 }
117 }
118
119 public void CheckSenseRepeaterEvents()
120 {
121 // Nothing to do here?
122 if (SenseRepeaters.Count == 0)
123 return;
124
125 lock (SenseRepeatListLock)
126 {
127 // Go through all timers
128 foreach (SenseRepeatClass ts in SenseRepeaters)
129 {
130 // Time has passed?
131 if (ts.next.ToUniversalTime() < DateTime.Now.ToUniversalTime())
132 {
133 SensorSweep(ts);
134 // set next interval
135 ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
136 }
137 }
138 } // lock
139 }
140
141 public void SenseOnce(uint m_localID, LLUUID m_itemID,
142 string name, LLUUID keyID, int type,
143 double range, double arc, SceneObjectPart host)
144 {
145 // Add to timer
146 SenseRepeatClass ts = new SenseRepeatClass();
147 ts.localID = m_localID;
148 ts.itemID = m_itemID;
149 ts.interval = 0;
150 ts.name = name;
151 ts.keyID = keyID;
152 ts.type = type;
153 ts.range = range;
154 ts.arc = arc;
155 ts.host = host;
156 SensorSweep(ts);
157 }
158
159 public LSL_Types.list GetSensorList(uint m_localID, LLUUID m_itemID)
160 {
161 lock (SenseLock)
162 {
163 Dictionary<LLUUID, LSL_Types.list> Obj = null;
164 if (!SenseEvents.TryGetValue(m_localID, out Obj))
165 {
166 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing localID: " + m_localID);
167 return null;
168 }
169 lock (Obj)
170 {
171 // Get script
172 LSL_Types.list SenseList = null;
173 if (!Obj.TryGetValue(m_itemID, out SenseList))
174 {
175 m_CmdManager.m_ScriptEngine.Log.Info("[AsyncLSL]: GetSensorList missing itemID: " + m_itemID);
176 return null;
177 }
178 return SenseList;
179 }
180 }
181 }
182
183 private void SensorSweep(SenseRepeatClass ts)
184 {
185 //m_ScriptEngine.Log.Info("[AsyncLSL]:Enter SensorSweep");
186 SceneObjectPart SensePoint = ts.host;
187
188 if (SensePoint == null)
189 {
190 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep (SensePoint == null) for "+ts.itemID.ToString());
191 return;
192 }
193 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep Scan");
194
195 LLVector3 sensorPos = SensePoint.AbsolutePosition;
196 LLVector3 regionPos = new LLVector3(m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocX * Constants.RegionSize, m_CmdManager.m_ScriptEngine.World.RegionInfo.RegionLocY * Constants.RegionSize, 0);
197 LLVector3 fromRegionPos = sensorPos + regionPos;
198
199 LLQuaternion q = SensePoint.RotationOffset;
200 LSL_Types.Quaternion r = new LSL_Types.Quaternion(q.X, q.Y, q.Z, q.W);
201 LSL_Types.Vector3 forward_dir = (new LSL_Types.Vector3(1, 0, 0) * r);
202 double mag_fwd = LSL_Types.Vector3.Mag(forward_dir);
203
204 // Here we should do some smart culling ...
205 // math seems quicker than strings so try that first
206 LSL_Types.list SensedObjects = new LSL_Types.list();
207 LSL_Types.Vector3 ZeroVector = new LSL_Types.Vector3(0, 0, 0);
208
209 foreach (EntityBase ent in m_CmdManager.m_ScriptEngine.World.Entities.Values)
210 {
211 LLVector3 toRegionPos = ent.AbsolutePosition + regionPos;
212 double dis = Math.Abs((double)Util.GetDistanceTo(toRegionPos, fromRegionPos));
213 if (dis <= ts.range)
214 {
215 // In Range, is it the right Type ?
216 int objtype = 0;
217
218 if (m_CmdManager.m_ScriptEngine.World.GetScenePresence(ent.UUID) != null) objtype |= 0x01; // actor
219 if (ent.Velocity.Equals(ZeroVector))
220 objtype |= 0x04; // passive non-moving
221 else
222 objtype |= 0x02; // active moving
223 if (ent is IScript) objtype |= 0x08; // Scripted. It COULD have one hidden ...
224
225 if (((ts.type & objtype) != 0) || ((ts.type & objtype) == ts.type))
226 {
227 // docs claim AGENT|ACTIVE should find agent objects OR active objects
228 // so the bitwise AND with object type should be non-zero
229
230 // Right type too, what about the other params , key and name ?
231 bool keep = true;
232 if (ts.arc < Math.PI)
233 {
234 // not omni-directional. Can you see it ?
235 // vec forward_dir = llRot2Fwd(llGetRot())
236 // vec obj_dir = toRegionPos-fromRegionPos
237 // dot=dot(forward_dir,obj_dir)
238 // mag_fwd = mag(forward_dir)
239 // mag_obj = mag(obj_dir)
240 // ang = acos(dot /(mag_fwd*mag_obj))
241 double ang_obj = 0;
242 try
243 {
244 LLVector3 diff = toRegionPos - fromRegionPos;
245 LSL_Types.Vector3 obj_dir = new LSL_Types.Vector3(diff.X, diff.Y, diff.Z);
246 double dot = LSL_Types.Vector3.Dot(forward_dir, obj_dir);
247 double mag_obj = LSL_Types.Vector3.Mag(obj_dir);
248 ang_obj = Math.Acos(dot / (mag_fwd * mag_obj));
249 }
250 catch
251 {
252 }
253
254 if (ang_obj > ts.arc) keep = false;
255 }
256
257 if (keep && (ts.keyID != LLUUID.Zero) && (ts.keyID != ent.UUID))
258 {
259 keep = false;
260 }
261
262 if (keep && (ts.name.Length > 0))
263 {
264 string avatarname=null;
265 string objectname=null;
266 string entname =ent.Name;
267
268 // try avatar username surname
269 UserProfileData profile = m_CmdManager.m_ScriptEngine.World.CommsManager.UserService.GetUserProfile(ent.UUID);
270 if (profile != null)
271 {
272 avatarname = profile.FirstName + " " + profile.SurName;
273 }
274 // try an scene object
275 SceneObjectPart SOP = m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(ent.UUID);
276 if (SOP != null)
277 {
278 objectname = SOP.Name;
279 }
280
281 if ((ts.name != entname) && (ts.name != avatarname) && (ts.name != objectname))
282 {
283 keep = false;
284 }
285 }
286
287 if (keep == true) SensedObjects.Add(ent.UUID);
288 }
289 }
290 }
291 //m_ScriptEngine.Log.Info("[AsyncLSL]: Enter SensorSweep SenseLock");
292
293 lock (SenseLock)
294 {
295 // Create object if it doesn't exist
296 if (SenseEvents.ContainsKey(ts.localID) == false)
297 {
298 SenseEvents.Add(ts.localID, new Dictionary<LLUUID, LSL_Types.list>());
299 }
300 // clear if previous traces exist
301 Dictionary<LLUUID, LSL_Types.list> Obj;
302 SenseEvents.TryGetValue(ts.localID, out Obj);
303 if (Obj.ContainsKey(ts.itemID) == true)
304 Obj.Remove(ts.itemID);
305
306 // note list may be zero length
307 Obj.Add(ts.itemID, SensedObjects);
308
309 if (SensedObjects.Length == 0)
310 {
311 // send a "no_sensor"
312 // Add it to queue
313 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
314 new XEventParams("no_sensor", new Object[0],
315 new XDetectParams[0]));
316 }
317 else
318 {
319 XDetectParams[] detect =
320 new XDetectParams[SensedObjects.Length];
321
322 int idx;
323 for (idx = 0; idx < SensedObjects.Length; idx++)
324 {
325 detect[idx] = new XDetectParams();
326 detect[idx].Key=(LLUUID)(SensedObjects.Data[idx]);
327 detect[idx].Populate(m_CmdManager.m_ScriptEngine.World);
328 }
329
330 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
331 new XEventParams("sensor",
332 new Object[] {
333 new LSL_Types.LSLInteger(SensedObjects.Length) },
334 detect));
335 }
336 }
337 }
338
339 public Object[] GetSerializationData(LLUUID itemID)
340 {
341 List<Object> data = new List<Object>();
342
343 foreach (SenseRepeatClass ts in SenseRepeaters)
344 {
345 if (ts.itemID == itemID)
346 {
347 data.Add(ts.interval);
348 data.Add(ts.name);
349 data.Add(ts.keyID);
350 data.Add(ts.type);
351 data.Add(ts.range);
352 data.Add(ts.arc);
353 }
354 }
355 return data.ToArray();
356 }
357
358 public void CreateFromData(uint localID, LLUUID itemID, LLUUID objectID,
359 Object[] data)
360 {
361 SceneObjectPart part =
362 m_CmdManager.m_ScriptEngine.World.GetSceneObjectPart(
363 objectID);
364
365 if (part == null)
366 return;
367
368 int idx = 0;
369
370 while (idx < data.Length)
371 {
372 SenseRepeatClass ts = new SenseRepeatClass();
373
374 ts.localID = localID;
375 ts.itemID = itemID;
376
377 ts.interval = (double)data[idx];
378 ts.name = (string)data[idx+1];
379 ts.keyID = (LLUUID)data[idx+2];
380 ts.type = (int)data[idx+3];
381 ts.range = (double)data[idx+4];
382 ts.arc = (double)data[idx+5];
383 ts.host = part;
384
385 ts.next =
386 DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
387
388 SenseRepeaters.Add(ts);
389 idx += 6;
390 }
391 }
392 }
393}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs
deleted file mode 100644
index 3dd875a..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/Timer.cs
+++ /dev/null
@@ -1,161 +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 libsecondlife;
32
33namespace OpenSim.Region.ScriptEngine.XEngine.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 LLUUID 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, LLUUID m_itemID, double sec)
61 {
62 // Always remove first, in case this is a re-set
63 UnSetTimerEvents(m_localID, m_itemID);
64 if (sec == 0) // Disabling timer
65 return;
66
67 // Add to timer
68 TimerClass ts = new TimerClass();
69 ts.localID = m_localID;
70 ts.itemID = m_itemID;
71 ts.interval = Convert.ToInt64(sec * 10000000); // How many 100 nanoseconds (ticks) should we wait
72 // 2193386136332921 ticks
73 // 219338613 seconds
74
75 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
76 ts.next = DateTime.Now.Ticks + ts.interval;
77 lock (TimerListLock)
78 {
79 Timers.Add(ts);
80 }
81 }
82
83 public void UnSetTimerEvents(uint m_localID, LLUUID m_itemID)
84 {
85 // Remove from timer
86 lock (TimerListLock)
87 {
88 foreach (TimerClass ts in new ArrayList(Timers))
89 {
90 if (ts.localID == m_localID && ts.itemID == m_itemID)
91 Timers.Remove(ts);
92 }
93 }
94 }
95
96 public void CheckTimerEvents()
97 {
98 // Nothing to do here?
99 if (Timers.Count == 0)
100 return;
101
102 lock (TimerListLock)
103 {
104 // Go through all timers
105 foreach (TimerClass ts in Timers)
106 {
107 // Time has passed?
108 if (ts.next < DateTime.Now.Ticks)
109 {
110 // Console.WriteLine("Time has passed: Now: " + DateTime.Now.Ticks + ", Passed: " + ts.next);
111 // Add it to queue
112 m_CmdManager.m_ScriptEngine.PostScriptEvent(ts.itemID,
113 new XEventParams("timer", new Object[0],
114 new XDetectParams[0]));
115 // set next interval
116
117 //ts.next = DateTime.Now.ToUniversalTime().AddSeconds(ts.interval);
118 ts.next = DateTime.Now.Ticks + ts.interval;
119 }
120 }
121 }
122 }
123
124 public Object[] GetSerializationData(LLUUID itemID)
125 {
126 List<Object> data = new List<Object>();
127
128 lock (TimerListLock)
129 {
130 foreach (TimerClass ts in Timers)
131 {
132 if (ts.itemID == itemID)
133 {
134 data.Add(ts.interval);
135 data.Add(ts.next-DateTime.Now.Ticks);
136 }
137 }
138 }
139 return data.ToArray();
140 }
141
142 public void CreateFromData(uint localID, LLUUID itemID, LLUUID objectID,
143 Object[] data)
144 {
145 int idx = 0;
146
147 while (idx < data.Length)
148 {
149 TimerClass ts = new TimerClass();
150
151 ts.localID = localID;
152 ts.itemID = itemID;
153 ts.interval = (long)data[idx];
154 ts.next = DateTime.Now.Ticks + (long)data[idx+1];
155 idx += 2;
156
157 Timers.Add(ts);
158 }
159 }
160 }
161}
diff --git a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/XmlRequest.cs b/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/XmlRequest.cs
deleted file mode 100644
index 288349e..0000000
--- a/OpenSim/Region/ScriptEngine/XEngine/AsyncCommandPlugins/XmlRequest.cs
+++ /dev/null
@@ -1,115 +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.XEngine.Script;
32
33namespace OpenSim.Region.ScriptEngine.XEngine.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
51 if (xmlrpc != null)
52 {
53 RPCRequestInfo rInfo = xmlrpc.GetNextCompletedRequest();
54
55 while (rInfo != null)
56 {
57 xmlrpc.RemoveCompletedRequest(rInfo.GetMessageID());
58
59 //Deliver data to prim's remote_data handler
60 object[] resobj = new object[]
61 {
62 new LSL_Types.LSLInteger(2),
63 new LSL_Types.LSLString(
64 rInfo.GetChannelKey().ToString()),
65 new LSL_Types.LSLString(
66 rInfo.GetMessageID().ToString()),
67 new LSL_Types.LSLString(String.Empty),
68 new LSL_Types.LSLInteger(rInfo.GetIntValue()),
69 new LSL_Types.LSLString(rInfo.GetStrVal())
70 };
71
72 foreach (XEngine xe in XEngine.ScriptEngines)
73 {
74 if (xe.PostScriptEvent(
75 rInfo.GetItemID(), new XEventParams(
76 "remote_data", resobj,
77 new XDetectParams[0])))
78 break;
79 }
80
81 rInfo = xmlrpc.GetNextCompletedRequest();
82 }
83
84 SendRemoteDataRequest srdInfo = xmlrpc.GetNextCompletedSRDRequest();
85
86 while (srdInfo != null)
87 {
88 xmlrpc.RemoveCompletedSRDRequest(srdInfo.GetReqID());
89
90 //Deliver data to prim's remote_data handler
91 object[] resobj = new object[]
92 {
93 new LSL_Types.LSLInteger(3),
94 new LSL_Types.LSLString(srdInfo.channel.ToString()),
95 new LSL_Types.LSLString(srdInfo.GetReqID().ToString()),
96 new LSL_Types.LSLString(String.Empty),
97 new LSL_Types.LSLInteger(srdInfo.idata),
98 new LSL_Types.LSLString(srdInfo.sdata)
99 };
100
101 foreach (XEngine xe in XEngine.ScriptEngines)
102 {
103 if (xe.PostScriptEvent(
104 srdInfo.m_itemID, new XEventParams(
105 "remote_data", resobj,
106 new XDetectParams[0])))
107 break;
108 }
109
110 srdInfo = xmlrpc.GetNextCompletedSRDRequest();
111 }
112 }
113 }
114 }
115}