aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs377
1 files changed, 377 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs b/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs
new file mode 100644
index 0000000..b4e92b9
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/YEngine/XMREvents.cs
@@ -0,0 +1,377 @@
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.Yengine
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 Yengine
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("[YEngine] 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 {
157 part = this.World.GetSceneObjectPart(localID);
158 if(part == null)
159 return;
160 }
161 else
162 {
163 part = this.World.GetSceneObjectPart(originalID);
164 }
165
166 DetectParams det = new DetectParams();
167 det.Key = remoteClient.AgentId;
168 det.Populate(this.World);
169 det.OffsetPos = new LSL_Vector(offsetPos.X,
170 offsetPos.Y,
171 offsetPos.Z);
172 det.LinkNum = part.LinkNum;
173
174 if(surfaceArgs != null)
175 {
176 det.SurfaceTouchArgs = surfaceArgs;
177 }
178
179 // Add to queue for all scripts in ObjectID object
180 this.PostObjectEvent(localID, new EventParams(
181 eventname, oneObjectArrayOne,
182 new DetectParams[] { det }));
183 }
184
185 public void changed(uint localID, uint change)
186 {
187 int ch = (int)change;
188 // Add to queue for all scripts in localID, Object pass change.
189 this.PostObjectEvent(localID, new EventParams(
190 "changed", new object[] { ch },
191 zeroDetectParams));
192 }
193
194 // state_entry: not processed here
195 // state_exit: not processed here
196
197 public void money(uint localID, UUID agentID, int amount, DetectParams[] det)
198 {
199 this.PostObjectEvent(localID, new EventParams(
200 "money", new object[] {
201 agentID.ToString(),
202 amount },
203 det));
204 }
205
206 public void collision_start(uint localID, ColliderArgs col)
207 {
208 collisions(localID, col, "collision_start");
209 }
210
211 public void collision(uint localID, ColliderArgs col)
212 {
213 collisions(localID, col, "collision");
214 }
215
216 public void collision_end(uint localID, ColliderArgs col)
217 {
218 collisions(localID, col, "collision_end");
219 }
220
221 private void collisions(uint localID, ColliderArgs col, string eventname)
222 {
223 int dc = col.Colliders.Count;
224 if(dc > 0)
225 {
226 DetectParams[] det = new DetectParams[dc];
227 int i = 0;
228 foreach(DetectedObject detobj in col.Colliders)
229 {
230 DetectParams d = new DetectParams();
231 det[i++] = d;
232
233 d.Key = detobj.keyUUID;
234 d.Populate(this.World);
235
236 /* not done by XEngine...
237 d.Position = detobj.posVector;
238 d.Rotation = detobj.rotQuat;
239 d.Velocity = detobj.velVector;
240 ... */
241 }
242
243 this.PostObjectEvent(localID, new EventParams(
244 eventname,
245 new Object[] { dc },
246 det));
247 }
248 }
249
250 public void land_collision_start(uint localID, ColliderArgs col)
251 {
252 land_collisions(localID, col, "land_collision_start");
253 }
254
255 public void land_collision(uint localID, ColliderArgs col)
256 {
257 land_collisions(localID, col, "land_collision");
258 }
259
260 public void land_collision_end(uint localID, ColliderArgs col)
261 {
262 land_collisions(localID, col, "land_collision_end");
263 }
264
265 private void land_collisions(uint localID, ColliderArgs col, string eventname)
266 {
267 foreach(DetectedObject detobj in col.Colliders)
268 {
269 LSL_Vector vec = new LSL_Vector(detobj.posVector.X,
270 detobj.posVector.Y,
271 detobj.posVector.Z);
272 EventParams eps = new EventParams(eventname,
273 new Object[] { vec },
274 zeroDetectParams);
275 this.PostObjectEvent(localID, eps);
276 }
277 }
278
279 // timer: not handled here
280 // listen: not handled here
281
282 public void control(UUID itemID, UUID agentID, uint held, uint change)
283 {
284 this.PostScriptEvent(itemID, new EventParams(
285 "control", new object[] {
286 agentID.ToString(),
287 (int)held,
288 (int)change},
289 zeroDetectParams));
290 }
291
292 public void email(uint localID, UUID itemID, string timeSent,
293 string address, string subject, string message, int numLeft)
294 {
295 this.PostObjectEvent(localID, new EventParams(
296 "email", new object[] {
297 timeSent,
298 address,
299 subject,
300 message,
301 numLeft},
302 zeroDetectParams));
303 }
304
305 public void at_target(uint localID, uint handle, Vector3 targetpos,
306 Vector3 atpos)
307 {
308 this.PostObjectEvent(localID, new EventParams(
309 "at_target", new object[] {
310 (int)handle,
311 new LSL_Vector(targetpos.X,targetpos.Y,targetpos.Z),
312 new LSL_Vector(atpos.X,atpos.Y,atpos.Z) },
313 zeroDetectParams));
314 }
315
316 public void not_at_target(uint localID)
317 {
318 this.PostObjectEvent(localID, new EventParams(
319 "not_at_target", zeroObjectArray,
320 zeroDetectParams));
321 }
322
323 public void at_rot_target(uint localID, uint handle, OpenMetaverse.Quaternion targetrot, OpenMetaverse.Quaternion atrot)
324 {
325 this.PostObjectEvent(
326 localID,
327 new EventParams(
328 "at_rot_target",
329 new object[] {
330 new LSL_Integer(handle),
331 new LSL_Rotation(targetrot.X, targetrot.Y, targetrot.Z, targetrot.W),
332 new LSL_Rotation(atrot.X, atrot.Y, atrot.Z, atrot.W)
333 },
334 zeroDetectParams
335 )
336 );
337 }
338
339 public void not_at_rot_target(uint localID)
340 {
341 this.PostObjectEvent(localID, new EventParams(
342 "not_at_rot_target", zeroObjectArray,
343 zeroDetectParams));
344 }
345
346 // run_time_permissions: not handled here
347
348 public void attach(uint localID, UUID itemID, UUID avatar)
349 {
350 this.PostObjectEvent(localID, new EventParams(
351 "attach", new object[] {
352 avatar.ToString() },
353 zeroDetectParams));
354 }
355
356 // dataserver: not handled here
357 // link_message: not handled here
358
359 public void moving_start(uint localID)
360 {
361 this.PostObjectEvent(localID, new EventParams(
362 "moving_start", zeroObjectArray,
363 zeroDetectParams));
364 }
365
366 public void moving_end(uint localID)
367 {
368 this.PostObjectEvent(localID, new EventParams(
369 "moving_end", zeroObjectArray,
370 zeroDetectParams));
371 }
372
373 // object_rez: not handled here
374 // remote_data: not handled here
375 // http_response: not handled here
376 }
377}