aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs369
1 files changed, 369 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs b/OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs
new file mode 100644
index 0000000..f6c2d73
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/XMREngine/XMREvents.cs
@@ -0,0 +1,369 @@
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 OpenSimulator 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 System.Reflection;
32using OpenMetaverse;
33using OpenSim.Framework;
34using OpenSim.Region.Framework.Scenes;
35using OpenSim.Region.Framework.Interfaces;
36using OpenSim.Region.ScriptEngine.Shared;
37using OpenSim.Region.ScriptEngine.Interfaces;
38using log4net;
39
40using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
41using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
42using LSL_Key = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
43using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
44using LSL_Rotation = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Quaternion;
45using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
46using LSL_Vector = OpenSim.Region.ScriptEngine.Shared.LSL_Types.Vector3;
47
48namespace OpenSim.Region.ScriptEngine.XMREngine
49{
50 /// <summary>
51 /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
52 /// </summary>
53 public partial class XMREngine
54 {
55 public static readonly object[] zeroObjectArray = new object[0];
56 public static readonly object[] oneObjectArrayOne = new object[1] { 1 };
57
58 private void InitEvents()
59 {
60 m_log.Info("[XMREngine] Hooking up to server events");
61 this.World.EventManager.OnAttach += attach;
62 this.World.EventManager.OnObjectGrab += touch_start;
63 this.World.EventManager.OnObjectGrabbing += touch;
64 this.World.EventManager.OnObjectDeGrab += touch_end;
65 this.World.EventManager.OnScriptChangedEvent += changed;
66 this.World.EventManager.OnScriptAtTargetEvent += at_target;
67 this.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
68 this.World.EventManager.OnScriptAtRotTargetEvent += at_rot_target;
69 this.World.EventManager.OnScriptNotAtRotTargetEvent += not_at_rot_target;
70 this.World.EventManager.OnScriptMovingStartEvent += moving_start;
71 this.World.EventManager.OnScriptMovingEndEvent += moving_end;
72 this.World.EventManager.OnScriptControlEvent += control;
73 this.World.EventManager.OnScriptColliderStart += collision_start;
74 this.World.EventManager.OnScriptColliding += collision;
75 this.World.EventManager.OnScriptCollidingEnd += collision_end;
76 this.World.EventManager.OnScriptLandColliderStart += land_collision_start;
77 this.World.EventManager.OnScriptLandColliding += land_collision;
78 this.World.EventManager.OnScriptLandColliderEnd += land_collision_end;
79 IMoneyModule money=this.World.RequestModuleInterface<IMoneyModule>();
80 if (money != null)
81 {
82 money.OnObjectPaid+=HandleObjectPaid;
83 }
84 }
85
86 /// <summary>
87 /// When an object gets paid by an avatar and generates the paid event,
88 /// this will pipe it to the script engine
89 /// </summary>
90 /// <param name="objectID">Object ID that got paid</param>
91 /// <param name="agentID">Agent Id that did the paying</param>
92 /// <param name="amount">Amount paid</param>
93 private void HandleObjectPaid(UUID objectID, UUID agentID,
94 int amount)
95 {
96 // Add to queue for all scripts in ObjectID object
97 DetectParams[] det = new DetectParams[1];
98 det[0] = new DetectParams();
99 det[0].Key = agentID;
100 det[0].Populate(this.World);
101
102 // Since this is an event from a shared module, all scenes will
103 // get it. But only one has the object in question. The others
104 // just ignore it.
105 //
106 SceneObjectPart part =
107 this.World.GetSceneObjectPart(objectID);
108
109 if (part == null)
110 return;
111
112 if ((part.ScriptEvents & scriptEvents.money) == 0)
113 part = part.ParentGroup.RootPart;
114
115 Verbose ("Paid: " + objectID + " from " + agentID + ", amount " + amount);
116
117 if (part != null)
118 {
119 money(part.LocalId, agentID, amount, det);
120 }
121 }
122
123 /// <summary>
124 /// Handles piping the proper stuff to The script engine for touching
125 /// Including DetectedParams
126 /// </summary>
127 /// <param name="localID"></param>
128 /// <param name="originalID"></param>
129 /// <param name="offsetPos"></param>
130 /// <param name="remoteClient"></param>
131 /// <param name="surfaceArgs"></param>
132 public void touch_start(uint localID, uint originalID, Vector3 offsetPos,
133 IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
134 {
135 touches(localID, originalID, offsetPos, remoteClient, surfaceArgs, "touch_start");
136 }
137
138 public void touch(uint localID, uint originalID, Vector3 offsetPos,
139 IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
140 {
141 touches(localID, originalID, offsetPos, remoteClient, surfaceArgs, "touch");
142 }
143
144 private static Vector3 zeroVec3 = new Vector3(0,0,0);
145 public void touch_end(uint localID, uint originalID, IClientAPI remoteClient,
146 SurfaceTouchEventArgs surfaceArgs)
147 {
148 touches(localID, originalID, zeroVec3, remoteClient, surfaceArgs, "touch_end");
149 }
150
151 private void touches(uint localID, uint originalID, Vector3 offsetPos,
152 IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs, string eventname)
153 {
154 SceneObjectPart part;
155 if (originalID == 0) {
156 part = this.World.GetSceneObjectPart(localID);
157 if (part == null) return;
158 } else {
159 part = this.World.GetSceneObjectPart(originalID);
160 }
161
162 DetectParams det = new DetectParams();
163 det.Key = remoteClient.AgentId;
164 det.Populate(this.World);
165 det.OffsetPos = new LSL_Vector(offsetPos.X,
166 offsetPos.Y,
167 offsetPos.Z);
168 det.LinkNum = part.LinkNum;
169
170 if (surfaceArgs != null) {
171 det.SurfaceTouchArgs = surfaceArgs;
172 }
173
174 // Add to queue for all scripts in ObjectID object
175 this.PostObjectEvent(localID, new EventParams(
176 eventname, oneObjectArrayOne,
177 new DetectParams[] { det }));
178 }
179
180 public void changed(uint localID, uint change)
181 {
182 int ch = (int)change;
183 // Add to queue for all scripts in localID, Object pass change.
184 this.PostObjectEvent(localID, new EventParams(
185 "changed",new object[] { ch },
186 zeroDetectParams));
187 }
188
189 // state_entry: not processed here
190 // state_exit: not processed here
191
192 public void money(uint localID, UUID agentID, int amount, DetectParams[] det)
193 {
194 this.PostObjectEvent(localID, new EventParams(
195 "money", new object[] {
196 agentID.ToString(),
197 amount },
198 det));
199 }
200
201 public void collision_start(uint localID, ColliderArgs col)
202 {
203 collisions(localID, col, "collision_start");
204 }
205
206 public void collision(uint localID, ColliderArgs col)
207 {
208 collisions(localID, col, "collision");
209 }
210
211 public void collision_end(uint localID, ColliderArgs col)
212 {
213 collisions(localID, col, "collision_end");
214 }
215
216 private void collisions(uint localID, ColliderArgs col, string eventname)
217 {
218 int dc = col.Colliders.Count;
219 if (dc > 0) {
220 DetectParams[] det = new DetectParams[dc];
221 int i = 0;
222 foreach (DetectedObject detobj in col.Colliders) {
223 DetectParams d = new DetectParams();
224 det[i++] = d;
225
226 d.Key = detobj.keyUUID;
227 d.Populate (this.World);
228
229 /* not done by XEngine...
230 d.Position = detobj.posVector;
231 d.Rotation = detobj.rotQuat;
232 d.Velocity = detobj.velVector;
233 ... */
234 }
235
236 this.PostObjectEvent(localID, new EventParams(
237 eventname,
238 new Object[] { dc },
239 det));
240 }
241 }
242
243 public void land_collision_start(uint localID, ColliderArgs col)
244 {
245 land_collisions(localID, col, "land_collision_start");
246 }
247
248 public void land_collision(uint localID, ColliderArgs col)
249 {
250 land_collisions(localID, col, "land_collision");
251 }
252
253 public void land_collision_end(uint localID, ColliderArgs col)
254 {
255 land_collisions(localID, col, "land_collision_end");
256 }
257
258 private void land_collisions(uint localID, ColliderArgs col, string eventname)
259 {
260 foreach (DetectedObject detobj in col.Colliders) {
261 LSL_Vector vec = new LSL_Vector(detobj.posVector.X,
262 detobj.posVector.Y,
263 detobj.posVector.Z);
264 EventParams eps = new EventParams(eventname,
265 new Object[] { vec },
266 zeroDetectParams);
267 this.PostObjectEvent(localID, eps);
268 }
269 }
270
271 // timer: not handled here
272 // listen: not handled here
273
274 public void control(UUID itemID, UUID agentID, uint held, uint change)
275 {
276 this.PostScriptEvent(itemID, new EventParams(
277 "control",new object[] {
278 agentID.ToString(),
279 (int)held,
280 (int)change},
281 zeroDetectParams));
282 }
283
284 public void email(uint localID, UUID itemID, string timeSent,
285 string address, string subject, string message, int numLeft)
286 {
287 this.PostObjectEvent(localID, new EventParams(
288 "email",new object[] {
289 timeSent,
290 address,
291 subject,
292 message,
293 numLeft},
294 zeroDetectParams));
295 }
296
297 public void at_target(uint localID, uint handle, Vector3 targetpos,
298 Vector3 atpos)
299 {
300 this.PostObjectEvent(localID, new EventParams(
301 "at_target", new object[] {
302 (int)handle,
303 new LSL_Vector(targetpos.X,targetpos.Y,targetpos.Z),
304 new LSL_Vector(atpos.X,atpos.Y,atpos.Z) },
305 zeroDetectParams));
306 }
307
308 public void not_at_target(uint localID)
309 {
310 this.PostObjectEvent(localID, new EventParams(
311 "not_at_target",zeroObjectArray,
312 zeroDetectParams));
313 }
314
315 public void at_rot_target(uint localID, uint handle, OpenMetaverse.Quaternion targetrot, OpenMetaverse.Quaternion atrot)
316 {
317 this.PostObjectEvent(
318 localID,
319 new EventParams(
320 "at_rot_target",
321 new object[] {
322 new LSL_Integer(handle),
323 new LSL_Rotation(targetrot.X, targetrot.Y, targetrot.Z, targetrot.W),
324 new LSL_Rotation(atrot.X, atrot.Y, atrot.Z, atrot.W)
325 },
326 zeroDetectParams
327 )
328 );
329 }
330
331 public void not_at_rot_target(uint localID)
332 {
333 this.PostObjectEvent(localID, new EventParams(
334 "not_at_rot_target",zeroObjectArray,
335 zeroDetectParams));
336 }
337
338 // run_time_permissions: not handled here
339
340 public void attach(uint localID, UUID itemID, UUID avatar)
341 {
342 this.PostObjectEvent(localID, new EventParams(
343 "attach",new object[] {
344 avatar.ToString() },
345 zeroDetectParams));
346 }
347
348 // dataserver: not handled here
349 // link_message: not handled here
350
351 public void moving_start(uint localID)
352 {
353 this.PostObjectEvent(localID, new EventParams(
354 "moving_start",zeroObjectArray,
355 zeroDetectParams));
356 }
357
358 public void moving_end(uint localID)
359 {
360 this.PostObjectEvent(localID, new EventParams(
361 "moving_end",zeroObjectArray,
362 zeroDetectParams));
363 }
364
365 // object_rez: not handled here
366 // remote_data: not handled here
367 // http_response: not handled here
368 }
369}