aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
diff options
context:
space:
mode:
authorUbitUmarov2015-09-01 11:43:07 +0100
committerUbitUmarov2015-09-01 11:43:07 +0100
commitfb78b182520fc9bb0f971afd0322029c70278ea6 (patch)
treeb4e30d383938fdeef8c92d1d1c2f44bb61d329bd /OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
parentlixo (diff)
parentMantis #7713: fixed bug introduced by 1st MOSES patch. (diff)
downloadopensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.zip
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.gz
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.bz2
opensim-SC-fb78b182520fc9bb0f971afd0322029c70278ea6.tar.xz
Merge remote-tracking branch 'os/master'
Diffstat (limited to 'OpenSim/Region/ScriptEngine/XEngine/EventManager.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/XEngine/EventManager.cs442
1 files changed, 442 insertions, 0 deletions
diff --git a/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
new file mode 100644
index 0000000..0ff2da3
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/XEngine/EventManager.cs
@@ -0,0 +1,442 @@
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
40namespace OpenSim.Region.ScriptEngine.XEngine
41{
42 /// <summary>
43 /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
44 /// </summary>
45 public class EventManager
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 private XEngine myScriptEngine;
50
51 public EventManager(XEngine _ScriptEngine)
52 {
53 myScriptEngine = _ScriptEngine;
54
55// m_log.Info("[XEngine] Hooking up to server events");
56 myScriptEngine.World.EventManager.OnAttach += attach;
57 myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
58 myScriptEngine.World.EventManager.OnObjectGrabbing += touch;
59 myScriptEngine.World.EventManager.OnObjectDeGrab += touch_end;
60 myScriptEngine.World.EventManager.OnScriptChangedEvent += changed;
61 myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target;
62 myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
63 myScriptEngine.World.EventManager.OnScriptAtRotTargetEvent += at_rot_target;
64 myScriptEngine.World.EventManager.OnScriptNotAtRotTargetEvent += not_at_rot_target;
65 myScriptEngine.World.EventManager.OnScriptMovingStartEvent += moving_start;
66 myScriptEngine.World.EventManager.OnScriptMovingEndEvent += moving_end;
67 myScriptEngine.World.EventManager.OnScriptControlEvent += control;
68 myScriptEngine.World.EventManager.OnScriptColliderStart += collision_start;
69 myScriptEngine.World.EventManager.OnScriptColliding += collision;
70 myScriptEngine.World.EventManager.OnScriptCollidingEnd += collision_end;
71 myScriptEngine.World.EventManager.OnScriptLandColliderStart += land_collision_start;
72 myScriptEngine.World.EventManager.OnScriptLandColliding += land_collision;
73 myScriptEngine.World.EventManager.OnScriptLandColliderEnd += land_collision_end;
74 IMoneyModule money = myScriptEngine.World.RequestModuleInterface<IMoneyModule>();
75 if (money != null)
76 {
77 money.OnObjectPaid+=HandleObjectPaid;
78 }
79 }
80
81 /// <summary>
82 /// When an object gets paid by an avatar and generates the paid event,
83 /// this will pipe it to the script engine
84 /// </summary>
85 /// <param name="objectID">Object ID that got paid</param>
86 /// <param name="agentID">Agent Id that did the paying</param>
87 /// <param name="amount">Amount paid</param>
88 private void HandleObjectPaid(UUID objectID, UUID agentID,
89 int amount)
90 {
91 // Since this is an event from a shared module, all scenes will
92 // get it. But only one has the object in question. The others
93 // just ignore it.
94 //
95 SceneObjectPart part =
96 myScriptEngine.World.GetSceneObjectPart(objectID);
97
98 if (part == null)
99 return;
100
101 if ((part.ScriptEvents & scriptEvents.money) == 0)
102 part = part.ParentGroup.RootPart;
103
104 m_log.Debug("Paid: " + objectID + " from " + agentID + ", amount " + amount);
105
106// part = part.ParentGroup.RootPart;
107 money(part.LocalId, agentID, amount);
108 }
109
110 /// <summary>
111 /// Handles piping the proper stuff to The script engine for touching
112 /// Including DetectedParams
113 /// </summary>
114 /// <param name="localID"></param>
115 /// <param name="originalID"></param>
116 /// <param name="offsetPos"></param>
117 /// <param name="remoteClient"></param>
118 /// <param name="surfaceArgs"></param>
119 public void touch_start(uint localID, uint originalID, Vector3 offsetPos,
120 IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
121 {
122 // Add to queue for all scripts in ObjectID object
123 DetectParams[] det = new DetectParams[1];
124 det[0] = new DetectParams();
125 det[0].Key = remoteClient.AgentId;
126 det[0].Populate(myScriptEngine.World);
127
128 if (originalID == 0)
129 {
130 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
131 if (part == null)
132 return;
133
134 det[0].LinkNum = part.LinkNum;
135 }
136 else
137 {
138 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
139 det[0].LinkNum = originalPart.LinkNum;
140 }
141
142 if (surfaceArgs != null)
143 {
144 det[0].SurfaceTouchArgs = surfaceArgs;
145 }
146
147 myScriptEngine.PostObjectEvent(localID, new EventParams(
148 "touch_start", new Object[] { new LSL_Types.LSLInteger(1) },
149 det));
150 }
151
152 public void touch(uint localID, uint originalID, Vector3 offsetPos,
153 IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
154 {
155 // Add to queue for all scripts in ObjectID object
156 DetectParams[] det = new DetectParams[1];
157 det[0] = new DetectParams();
158 det[0].Key = remoteClient.AgentId;
159 det[0].Populate(myScriptEngine.World);
160 det[0].OffsetPos = offsetPos;
161
162 if (originalID == 0)
163 {
164 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
165 if (part == null)
166 return;
167
168 det[0].LinkNum = part.LinkNum;
169 }
170 else
171 {
172 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
173 det[0].LinkNum = originalPart.LinkNum;
174 }
175 if (surfaceArgs != null)
176 {
177 det[0].SurfaceTouchArgs = surfaceArgs;
178 }
179
180 myScriptEngine.PostObjectEvent(localID, new EventParams(
181 "touch", new Object[] { new LSL_Types.LSLInteger(1) },
182 det));
183 }
184
185 public void touch_end(uint localID, uint originalID, IClientAPI remoteClient,
186 SurfaceTouchEventArgs surfaceArgs)
187 {
188 // Add to queue for all scripts in ObjectID object
189 DetectParams[] det = new DetectParams[1];
190 det[0] = new DetectParams();
191 det[0].Key = remoteClient.AgentId;
192 det[0].Populate(myScriptEngine.World);
193
194 if (originalID == 0)
195 {
196 SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
197 if (part == null)
198 return;
199
200 det[0].LinkNum = part.LinkNum;
201 }
202 else
203 {
204 SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
205 det[0].LinkNum = originalPart.LinkNum;
206 }
207
208 if (surfaceArgs != null)
209 {
210 det[0].SurfaceTouchArgs = surfaceArgs;
211 }
212
213 myScriptEngine.PostObjectEvent(localID, new EventParams(
214 "touch_end", new Object[] { new LSL_Types.LSLInteger(1) },
215 det));
216 }
217
218 public void changed(uint localID, uint change)
219 {
220 // Add to queue for all scripts in localID, Object pass change.
221 myScriptEngine.PostObjectEvent(localID, new EventParams(
222 "changed",new object[] { new LSL_Types.LSLInteger(change) },
223 new DetectParams[0]));
224 }
225
226 // state_entry: not processed here
227 // state_exit: not processed here
228
229 public void money(uint localID, UUID agentID, int amount)
230 {
231 myScriptEngine.PostObjectEvent(localID, new EventParams(
232 "money", new object[] {
233 new LSL_Types.LSLString(agentID.ToString()),
234 new LSL_Types.LSLInteger(amount) },
235 new DetectParams[0]));
236 }
237
238 public void collision_start(uint localID, ColliderArgs col)
239 {
240 // Add to queue for all scripts in ObjectID object
241 List<DetectParams> det = new List<DetectParams>();
242
243 foreach (DetectedObject detobj in col.Colliders)
244 {
245 DetectParams d = new DetectParams();
246 d.Key =detobj.keyUUID;
247 d.Populate(myScriptEngine.World);
248 det.Add(d);
249 }
250
251 if (det.Count > 0)
252 myScriptEngine.PostObjectEvent(localID, new EventParams(
253 "collision_start",
254 new Object[] { new LSL_Types.LSLInteger(det.Count) },
255 det.ToArray()));
256 }
257
258 public void collision(uint localID, ColliderArgs col)
259 {
260 // Add to queue for all scripts in ObjectID object
261 List<DetectParams> det = new List<DetectParams>();
262
263 foreach (DetectedObject detobj in col.Colliders)
264 {
265 DetectParams d = new DetectParams();
266 d.Key =detobj.keyUUID;
267 d.Populate(myScriptEngine.World);
268 det.Add(d);
269 }
270
271 if (det.Count > 0)
272 myScriptEngine.PostObjectEvent(localID, new EventParams(
273 "collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
274 det.ToArray()));
275 }
276
277 public void collision_end(uint localID, ColliderArgs col)
278 {
279 // Add to queue for all scripts in ObjectID object
280 List<DetectParams> det = new List<DetectParams>();
281
282 foreach (DetectedObject detobj in col.Colliders)
283 {
284 DetectParams d = new DetectParams();
285 d.Key =detobj.keyUUID;
286 d.Populate(myScriptEngine.World);
287 det.Add(d);
288 }
289
290 if (det.Count > 0)
291 myScriptEngine.PostObjectEvent(localID, new EventParams(
292 "collision_end",
293 new Object[] { new LSL_Types.LSLInteger(det.Count) },
294 det.ToArray()));
295 }
296
297 public void land_collision_start(uint localID, ColliderArgs col)
298 {
299 List<DetectParams> det = new List<DetectParams>();
300
301 foreach (DetectedObject detobj in col.Colliders)
302 {
303 DetectParams d = new DetectParams();
304 d.Position = detobj.posVector;
305 d.Populate(myScriptEngine.World);
306 det.Add(d);
307 myScriptEngine.PostObjectEvent(localID, new EventParams(
308 "land_collision_start",
309 new Object[] { new LSL_Types.Vector3(d.Position) },
310 det.ToArray()));
311 }
312
313 }
314
315 public void land_collision(uint localID, ColliderArgs col)
316 {
317 List<DetectParams> det = new List<DetectParams>();
318
319 foreach (DetectedObject detobj in col.Colliders)
320 {
321 DetectParams d = new DetectParams();
322 d.Position = detobj.posVector;
323 d.Populate(myScriptEngine.World);
324 det.Add(d);
325 myScriptEngine.PostObjectEvent(localID, new EventParams(
326 "land_collision",
327 new Object[] { new LSL_Types.Vector3(d.Position) },
328 det.ToArray()));
329 }
330 }
331
332 public void land_collision_end(uint localID, ColliderArgs col)
333 {
334 List<DetectParams> det = new List<DetectParams>();
335
336 foreach (DetectedObject detobj in col.Colliders)
337 {
338 DetectParams d = new DetectParams();
339 d.Position = detobj.posVector;
340 d.Populate(myScriptEngine.World);
341 det.Add(d);
342 myScriptEngine.PostObjectEvent(localID, new EventParams(
343 "land_collision_end",
344 new Object[] { new LSL_Types.Vector3(d.Position) },
345 det.ToArray()));
346 }
347 }
348
349 // timer: not handled here
350 // listen: not handled here
351
352 public void control(UUID itemID, UUID agentID, uint held, uint change)
353 {
354 myScriptEngine.PostScriptEvent(itemID, new EventParams(
355 "control",new object[] {
356 new LSL_Types.LSLString(agentID.ToString()),
357 new LSL_Types.LSLInteger(held),
358 new LSL_Types.LSLInteger(change)},
359 new DetectParams[0]));
360 }
361
362 public void email(uint localID, UUID itemID, string timeSent,
363 string address, string subject, string message, int numLeft)
364 {
365 myScriptEngine.PostObjectEvent(localID, new EventParams(
366 "email",new object[] {
367 new LSL_Types.LSLString(timeSent),
368 new LSL_Types.LSLString(address),
369 new LSL_Types.LSLString(subject),
370 new LSL_Types.LSLString(message),
371 new LSL_Types.LSLInteger(numLeft)},
372 new DetectParams[0]));
373 }
374
375 public void at_target(uint localID, uint handle, Vector3 targetpos,
376 Vector3 atpos)
377 {
378 myScriptEngine.PostObjectEvent(localID, new EventParams(
379 "at_target", new object[] {
380 new LSL_Types.LSLInteger(handle),
381 new LSL_Types.Vector3(targetpos),
382 new LSL_Types.Vector3(atpos) },
383 new DetectParams[0]));
384 }
385
386 public void not_at_target(uint localID)
387 {
388 myScriptEngine.PostObjectEvent(localID, new EventParams(
389 "not_at_target",new object[0],
390 new DetectParams[0]));
391 }
392
393 public void at_rot_target(uint localID, uint handle, Quaternion targetrot,
394 Quaternion atrot)
395 {
396 myScriptEngine.PostObjectEvent(localID, new EventParams(
397 "at_rot_target", new object[] {
398 new LSL_Types.LSLInteger(handle),
399 new LSL_Types.Quaternion(targetrot),
400 new LSL_Types.Quaternion(atrot) },
401 new DetectParams[0]));
402 }
403
404 public void not_at_rot_target(uint localID)
405 {
406 myScriptEngine.PostObjectEvent(localID, new EventParams(
407 "not_at_rot_target",new object[0],
408 new DetectParams[0]));
409 }
410
411 // run_time_permissions: not handled here
412
413 public void attach(uint localID, UUID itemID, UUID avatar)
414 {
415 myScriptEngine.PostObjectEvent(localID, new EventParams(
416 "attach",new object[] {
417 new LSL_Types.LSLString(avatar.ToString()) },
418 new DetectParams[0]));
419 }
420
421 // dataserver: not handled here
422 // link_message: not handled here
423
424 public void moving_start(uint localID)
425 {
426 myScriptEngine.PostObjectEvent(localID, new EventParams(
427 "moving_start",new object[0],
428 new DetectParams[0]));
429 }
430
431 public void moving_end(uint localID)
432 {
433 myScriptEngine.PostObjectEvent(localID, new EventParams(
434 "moving_end",new object[0],
435 new DetectParams[0]));
436 }
437
438 // object_rez: not handled here
439 // remote_data: not handled here
440 // http_response: not handled here
441 }
442}