OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
EventManager.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Reflection;
32 using OpenMetaverse;
33 using OpenSim.Framework;
34 using OpenSim.Region.Framework.Scenes;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.ScriptEngine.Shared;
37 using OpenSim.Region.ScriptEngine.Interfaces;
38 using log4net;
39 
40 namespace OpenSim.Region.ScriptEngine.XEngine
41 {
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 
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 
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  d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
249  det.Add(d);
250  }
251 
252  if (det.Count > 0)
253  myScriptEngine.PostObjectEvent(localID, new EventParams(
254  "collision_start",
255  new Object[] { new LSL_Types.LSLInteger(det.Count) },
256  det.ToArray()));
257  }
258 
259  public void collision(uint localID, ColliderArgs col)
260  {
261  // Add to queue for all scripts in ObjectID object
262  List<DetectParams> det = new List<DetectParams>();
263 
264  foreach (DetectedObject detobj in col.Colliders)
265  {
266  DetectParams d = new DetectParams();
267  d.Key =detobj.keyUUID;
268  d.Populate(myScriptEngine.World);
269  d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
270  det.Add(d);
271  }
272 
273  if (det.Count > 0)
274  myScriptEngine.PostObjectEvent(localID, new EventParams(
275  "collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
276  det.ToArray()));
277  }
278 
279  public void collision_end(uint localID, ColliderArgs col)
280  {
281  // Add to queue for all scripts in ObjectID object
282  List<DetectParams> det = new List<DetectParams>();
283 
284  foreach (DetectedObject detobj in col.Colliders)
285  {
286  DetectParams d = new DetectParams();
287  d.Key =detobj.keyUUID;
288  d.Populate(myScriptEngine.World);
289  d.LinkNum = detobj.linkNumber; // do it here since currently linknum is collided part
290  det.Add(d);
291  }
292 
293  if (det.Count > 0)
294  myScriptEngine.PostObjectEvent(localID, new EventParams(
295  "collision_end",
296  new Object[] { new LSL_Types.LSLInteger(det.Count) },
297  det.ToArray()));
298  }
299 
300  public void land_collision_start(uint localID, ColliderArgs col)
301  {
302  List<DetectParams> det = new List<DetectParams>();
303 
304  foreach (DetectedObject detobj in col.Colliders)
305  {
306  DetectParams d = new DetectParams();
307  d.Position = detobj.posVector;
308  d.Populate(myScriptEngine.World);
309  det.Add(d);
310  myScriptEngine.PostObjectEvent(localID, new EventParams(
311  "land_collision_start",
312  new Object[] { new LSL_Types.Vector3(d.Position) },
313  det.ToArray()));
314  }
315 
316  }
317 
318  public void land_collision(uint localID, ColliderArgs col)
319  {
320  List<DetectParams> det = new List<DetectParams>();
321 
322  foreach (DetectedObject detobj in col.Colliders)
323  {
324  DetectParams d = new DetectParams();
325  d.Position = detobj.posVector;
326  d.Populate(myScriptEngine.World);
327  det.Add(d);
328  myScriptEngine.PostObjectEvent(localID, new EventParams(
329  "land_collision",
330  new Object[] { new LSL_Types.Vector3(d.Position) },
331  det.ToArray()));
332  }
333  }
334 
335  public void land_collision_end(uint localID, ColliderArgs col)
336  {
337  List<DetectParams> det = new List<DetectParams>();
338 
339  foreach (DetectedObject detobj in col.Colliders)
340  {
341  DetectParams d = new DetectParams();
342  d.Position = detobj.posVector;
343  d.Populate(myScriptEngine.World);
344  det.Add(d);
345  myScriptEngine.PostObjectEvent(localID, new EventParams(
346  "land_collision_end",
347  new Object[] { new LSL_Types.Vector3(d.Position) },
348  det.ToArray()));
349  }
350  }
351 
352  // timer: not handled here
353  // listen: not handled here
354 
355  public void control(UUID itemID, UUID agentID, uint held, uint change)
356  {
357  myScriptEngine.PostScriptEvent(itemID, new EventParams(
358  "control",new object[] {
359  new LSL_Types.LSLString(agentID.ToString()),
360  new LSL_Types.LSLInteger(held),
361  new LSL_Types.LSLInteger(change)},
362  new DetectParams[0]));
363  }
364 
365  public void email(uint localID, UUID itemID, string timeSent,
366  string address, string subject, string message, int numLeft)
367  {
368  myScriptEngine.PostObjectEvent(localID, new EventParams(
369  "email",new object[] {
370  new LSL_Types.LSLString(timeSent),
371  new LSL_Types.LSLString(address),
372  new LSL_Types.LSLString(subject),
373  new LSL_Types.LSLString(message),
374  new LSL_Types.LSLInteger(numLeft)},
375  new DetectParams[0]));
376  }
377 
378  public void at_target(uint localID, uint handle, Vector3 targetpos,
379  Vector3 atpos)
380  {
381  myScriptEngine.PostObjectEvent(localID, new EventParams(
382  "at_target", new object[] {
383  new LSL_Types.LSLInteger(handle),
384  new LSL_Types.Vector3(targetpos),
385  new LSL_Types.Vector3(atpos) },
386  new DetectParams[0]));
387  }
388 
389  public void not_at_target(uint localID)
390  {
391  myScriptEngine.PostObjectEvent(localID, new EventParams(
392  "not_at_target",new object[0],
393  new DetectParams[0]));
394  }
395 
396  public void at_rot_target(uint localID, uint handle, Quaternion targetrot,
397  Quaternion atrot)
398  {
399  myScriptEngine.PostObjectEvent(localID, new EventParams(
400  "at_rot_target", new object[] {
401  new LSL_Types.LSLInteger(handle),
402  new LSL_Types.Quaternion(targetrot),
403  new LSL_Types.Quaternion(atrot) },
404  new DetectParams[0]));
405  }
406 
407  public void not_at_rot_target(uint localID)
408  {
409  myScriptEngine.PostObjectEvent(localID, new EventParams(
410  "not_at_rot_target",new object[0],
411  new DetectParams[0]));
412  }
413 
414  // run_time_permissions: not handled here
415 
416  public void attach(uint localID, UUID itemID, UUID avatar)
417  {
418  myScriptEngine.PostObjectEvent(localID, new EventParams(
419  "attach",new object[] {
420  new LSL_Types.LSLString(avatar.ToString()) },
421  new DetectParams[0]));
422  }
423 
424  // dataserver: not handled here
425  // link_message: not handled here
426 
427  public void moving_start(uint localID)
428  {
429  myScriptEngine.PostObjectEvent(localID, new EventParams(
430  "moving_start",new object[0],
431  new DetectParams[0]));
432  }
433 
434  public void moving_end(uint localID)
435  {
436  myScriptEngine.PostObjectEvent(localID, new EventParams(
437  "moving_end",new object[0],
438  new DetectParams[0]));
439  }
440 
441  // object_rez: not handled here
442  // remote_data: not handled here
443  // http_response: not handled here
444  }
445 }
void touch(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
void touch_end(uint localID, uint originalID, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
void at_target(uint localID, uint handle, Vector3 targetpos, Vector3 atpos)
void control(UUID itemID, UUID agentID, uint held, uint change)
void collision(uint localID, ColliderArgs col)
void money(uint localID, UUID agentID, int amount)
void at_rot_target(uint localID, uint handle, Quaternion targetrot, Quaternion atrot)
void land_collision(uint localID, ColliderArgs col)
void attach(uint localID, UUID itemID, UUID avatar)
void changed(uint localID, uint change)
Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
Definition: EventManager.cs:45
void land_collision_start(uint localID, ColliderArgs col)
void email(uint localID, UUID itemID, string timeSent, string address, string subject, string message, int numLeft)
void collision_end(uint localID, ColliderArgs col)
void touch_start(uint localID, uint originalID, Vector3 offsetPos, IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
Handles piping the proper stuff to The script engine for touching Including DetectedParams ...
void land_collision_end(uint localID, ColliderArgs col)
Holds all the data required to execute a scripting event.
Definition: Helpers.cs:281
void collision_start(uint localID, ColliderArgs col)