Helpers.cs 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. using System;
  28. using System.IO;
  29. using System.Threading;
  30. using System.Collections;
  31. using System.Collections.Generic;
  32. using System.Runtime.Serialization;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.CoreModules;
  36. using OpenSim.Region.Framework.Scenes;
  37. namespace OpenSim.Region.ScriptEngine.Shared
  38. {
  39. [Serializable]
  40. public class EventAbortException : Exception
  41. {
  42. public EventAbortException()
  43. {
  44. }
  45. protected EventAbortException(
  46. SerializationInfo info,
  47. StreamingContext context)
  48. {
  49. }
  50. }
  51. [Serializable]
  52. public class SelfDeleteException : Exception
  53. {
  54. public SelfDeleteException()
  55. {
  56. }
  57. protected SelfDeleteException(
  58. SerializationInfo info,
  59. StreamingContext context)
  60. {
  61. }
  62. }
  63. [Serializable]
  64. public class ScriptDeleteException : Exception
  65. {
  66. public ScriptDeleteException()
  67. {
  68. }
  69. protected ScriptDeleteException(
  70. SerializationInfo info,
  71. StreamingContext context)
  72. {
  73. }
  74. }
  75. public class DetectParams
  76. {
  77. public DetectParams()
  78. {
  79. Key = UUID.Zero;
  80. OffsetPos = new LSL_Types.Vector3();
  81. LinkNum = 0;
  82. Group = UUID.Zero;
  83. Name = String.Empty;
  84. Owner = UUID.Zero;
  85. Position = new LSL_Types.Vector3();
  86. Rotation = new LSL_Types.Quaternion();
  87. Type = 0;
  88. Velocity = new LSL_Types.Vector3();
  89. initializeSurfaceTouch();
  90. }
  91. public UUID Key;
  92. public LSL_Types.Vector3 OffsetPos;
  93. public int LinkNum;
  94. public UUID Group;
  95. public string Name;
  96. public UUID Owner;
  97. public LSL_Types.Vector3 Position;
  98. public LSL_Types.Quaternion Rotation;
  99. public int Type;
  100. public LSL_Types.Vector3 Velocity;
  101. private LSL_Types.Vector3 touchST;
  102. public LSL_Types.Vector3 TouchST { get { return touchST; } }
  103. private LSL_Types.Vector3 touchNormal;
  104. public LSL_Types.Vector3 TouchNormal { get { return touchNormal; } }
  105. private LSL_Types.Vector3 touchBinormal;
  106. public LSL_Types.Vector3 TouchBinormal { get { return touchBinormal; } }
  107. private LSL_Types.Vector3 touchPos;
  108. public LSL_Types.Vector3 TouchPos { get { return touchPos; } }
  109. private LSL_Types.Vector3 touchUV;
  110. public LSL_Types.Vector3 TouchUV { get { return touchUV; } }
  111. private int touchFace;
  112. public int TouchFace { get { return touchFace; } }
  113. // This can be done in two places including the constructor
  114. // so be carefull what gets added here
  115. private void initializeSurfaceTouch()
  116. {
  117. touchST = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
  118. touchNormal = new LSL_Types.Vector3();
  119. touchBinormal = new LSL_Types.Vector3();
  120. touchPos = new LSL_Types.Vector3();
  121. touchUV = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
  122. touchFace = -1;
  123. }
  124. /*
  125. * Set up the surface touch detected values
  126. */
  127. public SurfaceTouchEventArgs SurfaceTouchArgs
  128. {
  129. set
  130. {
  131. if (value == null)
  132. {
  133. // Initialise to defaults if no value
  134. initializeSurfaceTouch();
  135. }
  136. else
  137. {
  138. // Set the values from the touch data provided by the client
  139. touchST = new LSL_Types.Vector3(value.STCoord.X, value.STCoord.Y, value.STCoord.Z);
  140. touchUV = new LSL_Types.Vector3(value.UVCoord.X, value.UVCoord.Y, value.UVCoord.Z);
  141. touchNormal = new LSL_Types.Vector3(value.Normal.X, value.Normal.Y, value.Normal.Z);
  142. touchBinormal = new LSL_Types.Vector3(value.Binormal.X, value.Binormal.Y, value.Binormal.Z);
  143. touchPos = new LSL_Types.Vector3(value.Position.X, value.Position.Y, value.Position.Z);
  144. touchFace = value.FaceIndex;
  145. }
  146. }
  147. }
  148. public void Populate(Scene scene)
  149. {
  150. SceneObjectPart part = scene.GetSceneObjectPart(Key);
  151. if (part == null) // Avatar, maybe?
  152. {
  153. ScenePresence presence = scene.GetScenePresence(Key);
  154. if (presence == null)
  155. return;
  156. Name = presence.Firstname + " " + presence.Lastname;
  157. Owner = Key;
  158. Position = new LSL_Types.Vector3(
  159. presence.AbsolutePosition.X,
  160. presence.AbsolutePosition.Y,
  161. presence.AbsolutePosition.Z);
  162. Rotation = new LSL_Types.Quaternion(
  163. presence.Rotation.X,
  164. presence.Rotation.Y,
  165. presence.Rotation.Z,
  166. presence.Rotation.W);
  167. Velocity = new LSL_Types.Vector3(
  168. presence.Velocity.X,
  169. presence.Velocity.Y,
  170. presence.Velocity.Z);
  171. Type = 0x01; // Avatar
  172. if (presence.Velocity != Vector3.Zero)
  173. Type |= 0x02; // Active
  174. Group = presence.ControllingClient.ActiveGroupId;
  175. return;
  176. }
  177. part=part.ParentGroup.RootPart; // We detect objects only
  178. LinkNum = 0; // Not relevant
  179. Group = part.GroupID;
  180. Name = part.Name;
  181. Owner = part.OwnerID;
  182. if (part.Velocity == Vector3.Zero)
  183. Type = 0x04; // Passive
  184. else
  185. Type = 0x02; // Passive
  186. foreach (SceneObjectPart p in part.ParentGroup.Children.Values)
  187. {
  188. if (p.Inventory.ContainsScripts())
  189. {
  190. Type |= 0x08; // Scripted
  191. break;
  192. }
  193. }
  194. Position = new LSL_Types.Vector3(part.AbsolutePosition.X,
  195. part.AbsolutePosition.Y,
  196. part.AbsolutePosition.Z);
  197. Quaternion wr = part.ParentGroup.GroupRotation;
  198. Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
  199. Velocity = new LSL_Types.Vector3(part.Velocity.X,
  200. part.Velocity.Y,
  201. part.Velocity.Z);
  202. }
  203. }
  204. /// <summary>
  205. /// Holds all the data required to execute a scripting event.
  206. /// </summary>
  207. public class EventParams
  208. {
  209. public EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
  210. {
  211. EventName = eventName;
  212. Params = eventParams;
  213. DetectParams = detectParams;
  214. }
  215. public string EventName;
  216. public Object[] Params;
  217. public DetectParams[] DetectParams;
  218. }
  219. }