EventManager.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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 libsecondlife;
  29. using OpenSim.Framework;
  30. using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
  31. using OpenSim.Region.Environment.Scenes;
  32. using OpenSim.Region.Environment.Interfaces;
  33. using OpenSim.Region.ScriptEngine.XEngine.Script;
  34. using Axiom.Math;
  35. namespace OpenSim.Region.ScriptEngine.XEngine
  36. {
  37. /// <summary>
  38. /// Prepares events so they can be directly executed upon a script by EventQueueManager, then queues it.
  39. /// </summary>
  40. public class EventManager
  41. {
  42. private XEngine myScriptEngine;
  43. public EventManager(XEngine _ScriptEngine)
  44. {
  45. myScriptEngine = _ScriptEngine;
  46. myScriptEngine.Log.Info("[XEngine] Hooking up to server events");
  47. myScriptEngine.World.EventManager.OnObjectGrab += touch_start;
  48. myScriptEngine.World.EventManager.OnObjectDeGrab += touch_end;
  49. myScriptEngine.World.EventManager.OnScriptChangedEvent += changed;
  50. myScriptEngine.World.EventManager.OnScriptAtTargetEvent += at_target;
  51. myScriptEngine.World.EventManager.OnScriptNotAtTargetEvent += not_at_target;
  52. myScriptEngine.World.EventManager.OnScriptControlEvent += control;
  53. IMoneyModule money=myScriptEngine.World.RequestModuleInterface<IMoneyModule>();
  54. if (money != null)
  55. {
  56. money.OnObjectPaid+=HandleObjectPaid;
  57. }
  58. }
  59. private void HandleObjectPaid(LLUUID objectID, LLUUID agentID,
  60. int amount)
  61. {
  62. SceneObjectPart part =
  63. myScriptEngine.World.GetSceneObjectPart(objectID);
  64. if (part != null)
  65. {
  66. money(part.LocalId, agentID, amount);
  67. }
  68. }
  69. public void touch_start(uint localID, LLVector3 offsetPos,
  70. IClientAPI remoteClient)
  71. {
  72. // Add to queue for all scripts in ObjectID object
  73. XDetectParams[] det = new XDetectParams[1];
  74. det[0].Key = remoteClient.AgentId;
  75. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  76. "touch_start", new Object[] { new LSL_Types.LSLInteger(1) },
  77. det));
  78. }
  79. public void touch(uint localID, LLVector3 offsetPos,
  80. IClientAPI remoteClient)
  81. {
  82. // Add to queue for all scripts in ObjectID object
  83. XDetectParams[] det = new XDetectParams[1];
  84. det[0].Key = remoteClient.AgentId;
  85. det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X,
  86. offsetPos.Y,
  87. offsetPos.Z);
  88. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  89. "touch", new Object[] { new LSL_Types.LSLInteger(1) },
  90. det));
  91. }
  92. public void touch_end(uint localID, IClientAPI remoteClient)
  93. {
  94. // Add to queue for all scripts in ObjectID object
  95. XDetectParams[] det = new XDetectParams[1];
  96. det[0].Key = remoteClient.AgentId;
  97. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  98. "touch_end", new Object[] { new LSL_Types.LSLInteger(1) },
  99. det));
  100. }
  101. public void changed(uint localID, uint change)
  102. {
  103. // Add to queue for all scripts in localID, Object pass change.
  104. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  105. "changed",new object[] { new LSL_Types.LSLInteger(change) },
  106. new XDetectParams[0]));
  107. }
  108. // state_entry: not processed here
  109. // state_exit: not processed here
  110. public void money(uint localID, LLUUID agentID, int amount)
  111. {
  112. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  113. "money", new object[] {
  114. new LSL_Types.LSLString(agentID.ToString()),
  115. new LSL_Types.LSLInteger(amount) },
  116. new XDetectParams[0]));
  117. }
  118. public void collision_start(uint localID, LLUUID itemID,
  119. IClientAPI remoteClient)
  120. {
  121. // Add to queue for all scripts in ObjectID object
  122. XDetectParams[] det = new XDetectParams[1];
  123. det[0].Key = remoteClient.AgentId;
  124. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  125. "collision_start",
  126. new Object[] { new LSL_Types.LSLInteger(1) },
  127. det));
  128. }
  129. public void collision(uint localID, LLUUID itemID,
  130. IClientAPI remoteClient)
  131. {
  132. // Add to queue for all scripts in ObjectID object
  133. XDetectParams[] det = new XDetectParams[1];
  134. det[0].Key = remoteClient.AgentId;
  135. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  136. "collision", new Object[] { new LSL_Types.LSLInteger(1) },
  137. det));
  138. }
  139. public void collision_end(uint localID, LLUUID itemID,
  140. IClientAPI remoteClient)
  141. {
  142. // Add to queue for all scripts in ObjectID object
  143. XDetectParams[] det = new XDetectParams[1];
  144. det[0].Key = remoteClient.AgentId;
  145. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  146. "collision_end",
  147. new Object[] { new LSL_Types.LSLInteger(1) },
  148. det));
  149. }
  150. public void land_collision_start(uint localID, LLUUID itemID)
  151. {
  152. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  153. "land_collision_start",
  154. new object[0],
  155. new XDetectParams[0]));
  156. }
  157. public void land_collision(uint localID, LLUUID itemID)
  158. {
  159. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  160. "land_collision",
  161. new object[0],
  162. new XDetectParams[0]));
  163. }
  164. public void land_collision_end(uint localID, LLUUID itemID)
  165. {
  166. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  167. "land_collision_end",
  168. new object[0],
  169. new XDetectParams[0]));
  170. }
  171. // timer: not handled here
  172. // listen: not handled here
  173. public void on_rez(uint localID, LLUUID itemID, int startParam)
  174. {
  175. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  176. "on_rez",new object[] {
  177. new LSL_Types.LSLInteger(startParam)},
  178. new XDetectParams[0]));
  179. }
  180. public void control(uint localID, LLUUID itemID, LLUUID agentID, uint held, uint change)
  181. {
  182. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  183. "control",new object[] {
  184. new LSL_Types.LSLString(agentID.ToString()),
  185. new LSL_Types.LSLInteger(held),
  186. new LSL_Types.LSLInteger(change)},
  187. new XDetectParams[0]));
  188. }
  189. public void email(uint localID, LLUUID itemID, string timeSent,
  190. string address, string subject, string message, int numLeft)
  191. {
  192. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  193. "email",new object[] {
  194. new LSL_Types.LSLString(timeSent),
  195. new LSL_Types.LSLString(address),
  196. new LSL_Types.LSLString(subject),
  197. new LSL_Types.LSLString(message),
  198. new LSL_Types.LSLInteger(numLeft)},
  199. new XDetectParams[0]));
  200. }
  201. public void at_target(uint localID, uint handle, LLVector3 targetpos,
  202. LLVector3 atpos)
  203. {
  204. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  205. "at_target", new object[] {
  206. new LSL_Types.LSLInteger(handle),
  207. new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z),
  208. new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) },
  209. new XDetectParams[0]));
  210. }
  211. public void not_at_target(uint localID)
  212. {
  213. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  214. "not_at_target",new object[0],
  215. new XDetectParams[0]));
  216. }
  217. public void at_rot_target(uint localID, LLUUID itemID)
  218. {
  219. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  220. "at_rot_target",new object[0],
  221. new XDetectParams[0]));
  222. }
  223. public void not_at_rot_target(uint localID, LLUUID itemID)
  224. {
  225. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  226. "not_at_rot_target",new object[0],
  227. new XDetectParams[0]));
  228. }
  229. // run_time_permissions: not handled here
  230. public void attach(uint localID, LLUUID itemID, LLUUID avatar)
  231. {
  232. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  233. "attach",new object[] {
  234. new LSL_Types.LSLString(avatar.ToString()) },
  235. new XDetectParams[0]));
  236. }
  237. // dataserver: not handled here
  238. // link_message: not handled here
  239. public void moving_start(uint localID, LLUUID itemID)
  240. {
  241. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  242. "moving_start",new object[0],
  243. new XDetectParams[0]));
  244. }
  245. public void moving_end(uint localID, LLUUID itemID)
  246. {
  247. myScriptEngine.PostObjectEvent(localID, new XEventParams(
  248. "moving_end",new object[0],
  249. new XDetectParams[0]));
  250. }
  251. // object_rez: not handled here
  252. // remote_data: not handled here
  253. // http_response: not handled here
  254. }
  255. }