EventManager.cs 13 KB

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