Helpers.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 OpenSim 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 libsecondlife;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Environment;
  36. using OpenSim.Region.Environment.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. public class DetectParams
  64. {
  65. public DetectParams()
  66. {
  67. Key = LLUUID.Zero;
  68. OffsetPos = new LSL_Types.Vector3();
  69. LinkNum = 0;
  70. Group = LLUUID.Zero;
  71. Name = String.Empty;
  72. Owner = LLUUID.Zero;
  73. Position = new LSL_Types.Vector3();
  74. Rotation = new LSL_Types.Quaternion();
  75. Type = 0;
  76. Velocity = new LSL_Types.Vector3();
  77. }
  78. public LLUUID Key;
  79. public LSL_Types.Vector3 OffsetPos;
  80. public int LinkNum;
  81. public LLUUID Group;
  82. public string Name;
  83. public LLUUID Owner;
  84. public LSL_Types.Vector3 Position;
  85. public LSL_Types.Quaternion Rotation;
  86. public int Type;
  87. public LSL_Types.Vector3 Velocity;
  88. public void Populate(Scene scene)
  89. {
  90. SceneObjectPart part = scene.GetSceneObjectPart(Key);
  91. if (part == null) // Avatar, maybe?
  92. {
  93. ScenePresence presence = scene.GetScenePresence(Key);
  94. if (presence == null)
  95. return;
  96. Name = presence.Firstname + " " + presence.Lastname;
  97. Owner = Key;
  98. Position = new LSL_Types.Vector3(
  99. presence.AbsolutePosition.X,
  100. presence.AbsolutePosition.X,
  101. presence.AbsolutePosition.Z);
  102. Rotation = new LSL_Types.Quaternion(
  103. presence.Rotation.x,
  104. presence.Rotation.y,
  105. presence.Rotation.z,
  106. presence.Rotation.w);
  107. Velocity = new LSL_Types.Vector3(
  108. presence.Velocity.X,
  109. presence.Velocity.X,
  110. presence.Velocity.Z);
  111. Type = 0x01; // Avatar
  112. if (presence.Velocity != LLVector3.Zero)
  113. Type |= 0x02; // Active
  114. Group = presence.ControllingClient.ActiveGroupId;
  115. return;
  116. }
  117. part=part.ParentGroup.RootPart; // We detect objects only
  118. LinkNum = 0; // Not relevant
  119. Group = part.GroupID;
  120. Name = part.Name;
  121. Owner = part.OwnerID;
  122. if (part.Velocity == LLVector3.Zero)
  123. Type = 0x04; // Passive
  124. else
  125. Type = 0x02; // Passive
  126. foreach (SceneObjectPart p in part.ParentGroup.Children.Values)
  127. {
  128. if (p.ContainsScripts())
  129. {
  130. Type |= 0x08; // Scripted
  131. break;
  132. }
  133. }
  134. Position = new LSL_Types.Vector3(part.AbsolutePosition.X,
  135. part.AbsolutePosition.Y,
  136. part.AbsolutePosition.Z);
  137. LLQuaternion wr = part.GetWorldRotation();
  138. Rotation = new LSL_Types.Quaternion(wr.X, wr.Y, wr.Z, wr.W);
  139. Velocity = new LSL_Types.Vector3(part.Velocity.X,
  140. part.Velocity.Y,
  141. part.Velocity.Z);
  142. }
  143. }
  144. public class EventParams
  145. {
  146. public EventParams(string eventName, Object[] eventParams, DetectParams[] detectParams)
  147. {
  148. EventName=eventName;
  149. Params=eventParams;
  150. DetectParams=detectParams;
  151. }
  152. public string EventName;
  153. public Object[] Params;
  154. public DetectParams[] DetectParams;
  155. }
  156. }