1
0

Helpers.cs 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. using OpenSim.Region.Framework.Interfaces;
  38. namespace OpenSim.Region.ScriptEngine.Shared
  39. {
  40. [Serializable]
  41. public class EventAbortException : Exception
  42. {
  43. public EventAbortException()
  44. {
  45. }
  46. protected EventAbortException(
  47. SerializationInfo info,
  48. StreamingContext context)
  49. {
  50. }
  51. }
  52. [Serializable]
  53. public class SelfDeleteException : Exception
  54. {
  55. public SelfDeleteException()
  56. {
  57. }
  58. protected SelfDeleteException(
  59. SerializationInfo info,
  60. StreamingContext context)
  61. {
  62. }
  63. }
  64. [Serializable]
  65. public class ScriptDeleteException : Exception
  66. {
  67. public ScriptDeleteException()
  68. {
  69. }
  70. protected ScriptDeleteException(
  71. SerializationInfo info,
  72. StreamingContext context)
  73. {
  74. }
  75. }
  76. /// <summary>
  77. /// Used to signal when the script is stopping in co-operation with the script engine
  78. /// (instead of through Thread.Abort()).
  79. /// </summary>
  80. [Serializable]
  81. public class ScriptCoopStopException : Exception
  82. {
  83. public ScriptCoopStopException()
  84. {
  85. }
  86. protected ScriptCoopStopException(
  87. SerializationInfo info,
  88. StreamingContext context)
  89. {
  90. }
  91. }
  92. public class DetectParams
  93. {
  94. public const int AGENT = 1;
  95. public const int ACTIVE = 2;
  96. public const int PASSIVE = 4;
  97. public const int SCRIPTED = 8;
  98. public const int OS_NPC = 0x01000000;
  99. public DetectParams()
  100. {
  101. Key = UUID.Zero;
  102. OffsetPos = new LSL_Types.Vector3();
  103. LinkNum = 0;
  104. Group = UUID.Zero;
  105. Name = String.Empty;
  106. Owner = UUID.Zero;
  107. Position = new LSL_Types.Vector3();
  108. Rotation = new LSL_Types.Quaternion();
  109. Type = 0;
  110. Velocity = new LSL_Types.Vector3();
  111. initializeSurfaceTouch();
  112. }
  113. public UUID Key;
  114. public LSL_Types.Vector3 OffsetPos;
  115. public int LinkNum;
  116. public UUID Group;
  117. public string Name;
  118. public UUID Owner;
  119. public LSL_Types.Vector3 Position;
  120. public LSL_Types.Quaternion Rotation;
  121. public int Type;
  122. public LSL_Types.Vector3 Velocity;
  123. private LSL_Types.Vector3 touchST;
  124. public LSL_Types.Vector3 TouchST { get { return touchST; } }
  125. private LSL_Types.Vector3 touchNormal;
  126. public LSL_Types.Vector3 TouchNormal { get { return touchNormal; } }
  127. private LSL_Types.Vector3 touchBinormal;
  128. public LSL_Types.Vector3 TouchBinormal { get { return touchBinormal; } }
  129. private LSL_Types.Vector3 touchPos;
  130. public LSL_Types.Vector3 TouchPos { get { return touchPos; } }
  131. private LSL_Types.Vector3 touchUV;
  132. public LSL_Types.Vector3 TouchUV { get { return touchUV; } }
  133. private int touchFace;
  134. public int TouchFace { get { return touchFace; } }
  135. // This can be done in two places including the constructor
  136. // so be carefull what gets added here
  137. private void initializeSurfaceTouch()
  138. {
  139. touchST = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
  140. touchNormal = new LSL_Types.Vector3();
  141. touchBinormal = new LSL_Types.Vector3();
  142. touchPos = new LSL_Types.Vector3();
  143. touchUV = new LSL_Types.Vector3(-1.0, -1.0, 0.0);
  144. touchFace = -1;
  145. }
  146. /*
  147. * Set up the surface touch detected values
  148. */
  149. public SurfaceTouchEventArgs SurfaceTouchArgs
  150. {
  151. set
  152. {
  153. if (value == null)
  154. {
  155. // Initialise to defaults if no value
  156. initializeSurfaceTouch();
  157. }
  158. else
  159. {
  160. // Set the values from the touch data provided by the client
  161. touchST = new LSL_Types.Vector3(value.STCoord);
  162. touchUV = new LSL_Types.Vector3(value.UVCoord);
  163. touchNormal = new LSL_Types.Vector3(value.Normal);
  164. touchBinormal = new LSL_Types.Vector3(value.Binormal);
  165. touchPos = new LSL_Types.Vector3(value.Position);
  166. touchFace = value.FaceIndex;
  167. }
  168. }
  169. }
  170. public void Populate(Scene scene)
  171. {
  172. SceneObjectPart part = scene.GetSceneObjectPart(Key);
  173. if (part == null) // Avatar, maybe?
  174. {
  175. ScenePresence presence = scene.GetScenePresence(Key);
  176. if (presence == null)
  177. return;
  178. Name = presence.Firstname + " " + presence.Lastname;
  179. Owner = Key;
  180. Position = new LSL_Types.Vector3(presence.AbsolutePosition);
  181. Rotation = new LSL_Types.Quaternion(
  182. presence.Rotation.X,
  183. presence.Rotation.Y,
  184. presence.Rotation.Z,
  185. presence.Rotation.W);
  186. Velocity = new LSL_Types.Vector3(presence.Velocity);
  187. if (presence.PresenceType != PresenceType.Npc)
  188. {
  189. Type = AGENT;
  190. }
  191. else
  192. {
  193. Type = OS_NPC;
  194. INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
  195. INPC npcData = npcModule.GetNPC(presence.UUID, presence.Scene);
  196. if (npcData.SenseAsAgent)
  197. {
  198. Type |= AGENT;
  199. }
  200. }
  201. if (presence.Velocity != Vector3.Zero)
  202. Type |= ACTIVE;
  203. Group = presence.ControllingClient.ActiveGroupId;
  204. return;
  205. }
  206. part = part.ParentGroup.RootPart; // We detect objects only
  207. LinkNum = 0; // Not relevant
  208. Group = part.GroupID;
  209. Name = part.Name;
  210. Owner = part.OwnerID;
  211. if (part.Velocity == Vector3.Zero)
  212. Type = PASSIVE;
  213. else
  214. Type = ACTIVE;
  215. foreach (SceneObjectPart p in part.ParentGroup.Parts)
  216. {
  217. if (p.Inventory.ContainsScripts())
  218. {
  219. Type |= SCRIPTED; // Scripted
  220. break;
  221. }
  222. }
  223. Position = new LSL_Types.Vector3(part.AbsolutePosition);
  224. Quaternion wr = part.ParentGroup.GroupRotation;
  225. Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
  226. Velocity = new LSL_Types.Vector3(part.Velocity);
  227. }
  228. }
  229. /// <summary>
  230. /// Holds all the data required to execute a scripting event.
  231. /// </summary>
  232. public class EventParams
  233. {
  234. public EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
  235. {
  236. EventName = eventName;
  237. Params = eventParams;
  238. DetectParams = detectParams;
  239. }
  240. public string EventName;
  241. public Object[] Params;
  242. public DetectParams[] DetectParams;
  243. }
  244. }