OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Helpers.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.IO;
30 using System.Threading;
31 using System.Collections;
32 using System.Collections.Generic;
33 using System.Runtime.Serialization;
34 using OpenMetaverse;
35 using OpenSim.Framework;
36 using OpenSim.Region.CoreModules;
37 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Services.Interfaces;
39 using OpenSim.Region.Framework.Interfaces;
40 
41 namespace OpenSim.Region.ScriptEngine.Shared
42 {
43  [Serializable]
44  public class EventAbortException : Exception
45  {
47  {
48  }
49 
51  SerializationInfo info,
52  StreamingContext context)
53  {
54  }
55  }
56 
57  [Serializable]
58  public class SelfDeleteException : Exception
59  {
61  {
62  }
63 
65  SerializationInfo info,
66  StreamingContext context)
67  {
68  }
69  }
70 
71  [Serializable]
72  public class ScriptDeleteException : Exception
73  {
75  {
76  }
77 
79  SerializationInfo info,
80  StreamingContext context)
81  {
82  }
83  }
84 
89  [Serializable]
90  public class ScriptCoopStopException : Exception
91  {
93  {
94  }
95 
97  SerializationInfo info,
98  StreamingContext context)
99  {
100  }
101  }
102 
103  public class DetectParams
104  {
105  public const int AGENT = 1;
106  public const int ACTIVE = 2;
107  public const int PASSIVE = 4;
108  public const int SCRIPTED = 8;
109  public const int OS_NPC = 0x01000000;
110 
111  public DetectParams()
112  {
113  Key = UUID.Zero;
114  OffsetPos = new LSL_Types.Vector3();
115  LinkNum = 0;
116  Group = UUID.Zero;
117  Name = String.Empty;
118  Owner = UUID.Zero;
119  Position = new LSL_Types.Vector3();
121  Type = 0;
122  Velocity = new LSL_Types.Vector3();
123  initializeSurfaceTouch();
124  Country = String.Empty;
125  }
126 
127  public UUID Key;
129  public int LinkNum;
130  public UUID Group;
131  public string Name;
132  public UUID Owner;
135  public int Type;
137 
138  private LSL_Types.Vector3 touchST;
139  public LSL_Types.Vector3 TouchST { get { return touchST; } }
140 
141  private LSL_Types.Vector3 touchNormal;
142  public LSL_Types.Vector3 TouchNormal { get { return touchNormal; } }
143 
144  private LSL_Types.Vector3 touchBinormal;
145  public LSL_Types.Vector3 TouchBinormal { get { return touchBinormal; } }
146 
147  private LSL_Types.Vector3 touchPos;
148  public LSL_Types.Vector3 TouchPos { get { return touchPos; } }
149 
150  private LSL_Types.Vector3 touchUV;
151  public LSL_Types.Vector3 TouchUV { get { return touchUV; } }
152 
153  private int touchFace;
154  public int TouchFace { get { return touchFace; } }
155 
156  public string Country;
157 
158  // This can be done in two places including the constructor
159  // so be carefull what gets added here
160  private void initializeSurfaceTouch()
161  {
162  touchST = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
163  touchNormal = new LSL_Types.Vector3();
164  touchBinormal = new LSL_Types.Vector3();
165  touchPos = new LSL_Types.Vector3();
166  touchUV = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
167  touchFace = -1;
168  }
169 
170  /*
171  * Set up the surface touch detected values
172  */
173  public SurfaceTouchEventArgs SurfaceTouchArgs
174  {
175  set
176  {
177  if (value == null)
178  {
179  // Initialise to defaults if no value
180  initializeSurfaceTouch();
181  }
182  else
183  {
184  // Set the values from the touch data provided by the client
185  touchST = new LSL_Types.Vector3(value.STCoord);
186  touchUV = new LSL_Types.Vector3(value.UVCoord);
187  touchNormal = new LSL_Types.Vector3(value.Normal);
188  touchBinormal = new LSL_Types.Vector3(value.Binormal);
189  touchPos = new LSL_Types.Vector3(value.Position);
190  touchFace = value.FaceIndex;
191  }
192  }
193  }
194 
195  public void Populate(Scene scene)
196  {
197  SceneObjectPart part = scene.GetSceneObjectPart(Key);
198  if (part == null) // Avatar, maybe?
199  {
200  ScenePresence presence = scene.GetScenePresence(Key);
201  if (presence == null)
202  return;
203 
204  Name = presence.Firstname + " " + presence.Lastname;
205  UserAccount account = scene.UserAccountService.GetUserAccount(scene.RegionInfo.ScopeID, Key);
206  if (account != null)
207  Country = account.UserCountry;
208 
209  Owner = Key;
210  Position = new LSL_Types.Vector3(presence.AbsolutePosition);
212  presence.Rotation.X,
213  presence.Rotation.Y,
214  presence.Rotation.Z,
215  presence.Rotation.W);
216  Velocity = new LSL_Types.Vector3(presence.Velocity);
217 
218  Type = 0x01; // Avatar
219  if (presence.PresenceType == PresenceType.Npc)
220  Type = 0x20;
221 
222  // Cope Impl. We don't use OS_NPC.
223  //if (presence.PresenceType != PresenceType.Npc)
224  //{
225  // Type = AGENT;
226  //}
227  //else
228  //{
229  // Type = OS_NPC;
230 
231  // INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
232  // INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene);
233 
234  // if (npcData.SenseAsAgent)
235  // {
236  // Type |= AGENT;
237  // }
238  //}
239 
240  if (presence.Velocity != Vector3.Zero)
241  Type |= ACTIVE;
242 
243  Group = presence.ControllingClient.ActiveGroupId;
244 
245  return;
246  }
247 
248  part = part.ParentGroup.RootPart; // We detect objects only
249 
250  LinkNum = 0; // Not relevant
251 
252  Group = part.GroupID;
253  Name = part.Name;
254  Owner = part.OwnerID;
255  if (part.Velocity == Vector3.Zero)
256  Type = PASSIVE;
257  else
258  Type = ACTIVE;
259 
260  foreach (SceneObjectPart p in part.ParentGroup.Parts)
261  {
262  if (p.Inventory.ContainsScripts())
263  {
264  Type |= SCRIPTED; // Scripted
265  break;
266  }
267  }
268 
269  Position = new LSL_Types.Vector3(part.AbsolutePosition);
270 
271  Quaternion wr = part.ParentGroup.GroupRotation;
272  Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
273 
274  Velocity = new LSL_Types.Vector3(part.Velocity);
275  }
276  }
277 
281  public class EventParams
282  {
283  public EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
284  {
285  EventName = eventName;
286  Params = eventParams;
287  DetectParams = detectParams;
288  }
289 
290  public string EventName;
291  public Object[] Params;
293  }
294 }
IEntityInventory Inventory
This part's inventory
bool ContainsScripts()
Returns true if this inventory contains any scripts
ScriptDeleteException(SerializationInfo info, StreamingContext context)
Definition: Helpers.cs:78
PresenceType
Indicate the type of ScenePresence.
Definition: PresenceType.cs:34
Used to signal when the script is stopping in co-operation with the script engine (instead of through...
Definition: Helpers.cs:90
SelfDeleteException(SerializationInfo info, StreamingContext context)
Definition: Helpers.cs:64
EventAbortException(SerializationInfo info, StreamingContext context)
Definition: Helpers.cs:50
override Vector3 Velocity
Current velocity of the avatar.
Holds all the data required to execute a scripting event.
Definition: Helpers.cs:281
EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
Definition: Helpers.cs:283
ScriptCoopStopException(SerializationInfo info, StreamingContext context)
Definition: Helpers.cs:96