EventManager.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Environment.Modules.Avatar.Currency.SampleMoney;
  33. using OpenSim.Region.Interfaces;
  34. using OpenSim.Region.Environment.Scenes;
  35. using OpenSim.Region.Environment.Interfaces;
  36. using OpenSim.Region.ScriptEngine.Shared;
  37. using OpenSim.Region.ScriptEngine.Interfaces;
  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(UUID objectID, UUID agentID,
  66. int amount)
  67. {
  68. SceneObjectPart part =
  69. myScriptEngine.World.GetSceneObjectPart(objectID);
  70. if (part.ParentGroup != null)
  71. part = part.ParentGroup.RootPart;
  72. if (part != null)
  73. {
  74. money(part.LocalId, agentID, amount);
  75. }
  76. }
  77. public void touch_start(uint localID, uint originalID, Vector3 offsetPos,
  78. IClientAPI remoteClient, SurfaceTouchEventArgs surfaceArgs)
  79. {
  80. // Add to queue for all scripts in ObjectID object
  81. DetectParams[] det = new DetectParams[1];
  82. det[0] = new DetectParams();
  83. det[0].Key = remoteClient.AgentId;
  84. det[0].Populate(myScriptEngine.World);
  85. if (originalID == 0)
  86. {
  87. SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
  88. if (part == null)
  89. return;
  90. det[0].LinkNum = part.LinkNum;
  91. }
  92. else
  93. {
  94. SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
  95. det[0].LinkNum = originalPart.LinkNum;
  96. }
  97. if (surfaceArgs != null)
  98. {
  99. det[0].SurfaceTouchArgs = surfaceArgs;
  100. }
  101. myScriptEngine.PostObjectEvent(localID, new EventParams(
  102. "touch_start", new Object[] { new LSL_Types.LSLInteger(1) },
  103. det));
  104. }
  105. public void touch(uint localID, uint originalID, Vector3 offsetPos,
  106. IClientAPI remoteClient)
  107. {
  108. // Add to queue for all scripts in ObjectID object
  109. DetectParams[] det = new DetectParams[1];
  110. det[0] = new DetectParams();
  111. det[0].Key = remoteClient.AgentId;
  112. det[0].Populate(myScriptEngine.World);
  113. det[0].OffsetPos = new LSL_Types.Vector3(offsetPos.X,
  114. offsetPos.Y,
  115. offsetPos.Z);
  116. if (originalID == 0)
  117. {
  118. SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
  119. if (part == null)
  120. return;
  121. det[0].LinkNum = part.LinkNum;
  122. }
  123. else
  124. {
  125. SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
  126. det[0].LinkNum = originalPart.LinkNum;
  127. }
  128. myScriptEngine.PostObjectEvent(localID, new EventParams(
  129. "touch", new Object[] { new LSL_Types.LSLInteger(1) },
  130. det));
  131. }
  132. public void touch_end(uint localID, uint originalID, IClientAPI remoteClient)
  133. {
  134. // Add to queue for all scripts in ObjectID object
  135. DetectParams[] det = new DetectParams[1];
  136. det[0] = new DetectParams();
  137. det[0].Key = remoteClient.AgentId;
  138. det[0].Populate(myScriptEngine.World);
  139. if (originalID == 0)
  140. {
  141. SceneObjectPart part = myScriptEngine.World.GetSceneObjectPart(localID);
  142. if (part == null)
  143. return;
  144. det[0].LinkNum = part.LinkNum;
  145. }
  146. else
  147. {
  148. SceneObjectPart originalPart = myScriptEngine.World.GetSceneObjectPart(originalID);
  149. det[0].LinkNum = originalPart.LinkNum;
  150. }
  151. myScriptEngine.PostObjectEvent(localID, new EventParams(
  152. "touch_end", new Object[] { new LSL_Types.LSLInteger(1) },
  153. det));
  154. }
  155. public void changed(uint localID, uint change)
  156. {
  157. // Add to queue for all scripts in localID, Object pass change.
  158. myScriptEngine.PostObjectEvent(localID, new EventParams(
  159. "changed",new object[] { new LSL_Types.LSLInteger(change) },
  160. new DetectParams[0]));
  161. }
  162. // state_entry: not processed here
  163. // state_exit: not processed here
  164. public void money(uint localID, UUID agentID, int amount)
  165. {
  166. myScriptEngine.PostObjectEvent(localID, new EventParams(
  167. "money", new object[] {
  168. new LSL_Types.LSLString(agentID.ToString()),
  169. new LSL_Types.LSLInteger(amount) },
  170. new DetectParams[0]));
  171. }
  172. public void collision_start(uint localID, ColliderArgs col)
  173. {
  174. // Add to queue for all scripts in ObjectID object
  175. List<DetectParams> det = new List<DetectParams>();
  176. foreach (DetectedObject detobj in col.Colliders)
  177. {
  178. DetectParams d = new DetectParams();
  179. d.Key =detobj.keyUUID;
  180. d.Populate(myScriptEngine.World);
  181. det.Add(d);
  182. }
  183. if (det.Count > 0)
  184. myScriptEngine.PostObjectEvent(localID, new EventParams(
  185. "collision_start",
  186. new Object[] { new LSL_Types.LSLInteger(det.Count) },
  187. det.ToArray()));
  188. }
  189. public void collision(uint localID, ColliderArgs col)
  190. {
  191. // Add to queue for all scripts in ObjectID object
  192. List<DetectParams> det = new List<DetectParams>();
  193. foreach (DetectedObject detobj in col.Colliders)
  194. {
  195. DetectParams d = new DetectParams();
  196. d.Key =detobj.keyUUID;
  197. d.Populate(myScriptEngine.World);
  198. det.Add(d);
  199. }
  200. if (det.Count > 0)
  201. myScriptEngine.PostObjectEvent(localID, new EventParams(
  202. "collision", new Object[] { new LSL_Types.LSLInteger(det.Count) },
  203. det.ToArray()));
  204. }
  205. public void collision_end(uint localID, ColliderArgs col)
  206. {
  207. // Add to queue for all scripts in ObjectID object
  208. List<DetectParams> det = new List<DetectParams>();
  209. foreach (DetectedObject detobj in col.Colliders)
  210. {
  211. DetectParams d = new DetectParams();
  212. d.Key =detobj.keyUUID;
  213. d.Populate(myScriptEngine.World);
  214. det.Add(d);
  215. }
  216. if (det.Count > 0)
  217. myScriptEngine.PostObjectEvent(localID, new EventParams(
  218. "collision_end",
  219. new Object[] { new LSL_Types.LSLInteger(det.Count) },
  220. det.ToArray()));
  221. }
  222. public void land_collision_start(uint localID, UUID itemID)
  223. {
  224. myScriptEngine.PostObjectEvent(localID, new EventParams(
  225. "land_collision_start",
  226. new object[0],
  227. new DetectParams[0]));
  228. }
  229. public void land_collision(uint localID, UUID itemID)
  230. {
  231. myScriptEngine.PostObjectEvent(localID, new EventParams(
  232. "land_collision",
  233. new object[0],
  234. new DetectParams[0]));
  235. }
  236. public void land_collision_end(uint localID, UUID itemID)
  237. {
  238. myScriptEngine.PostObjectEvent(localID, new EventParams(
  239. "land_collision_end",
  240. new object[0],
  241. new DetectParams[0]));
  242. }
  243. // timer: not handled here
  244. // listen: not handled here
  245. public void control(uint localID, UUID itemID, UUID agentID, uint held, uint change)
  246. {
  247. myScriptEngine.PostObjectEvent(localID, new EventParams(
  248. "control",new object[] {
  249. new LSL_Types.LSLString(agentID.ToString()),
  250. new LSL_Types.LSLInteger(held),
  251. new LSL_Types.LSLInteger(change)},
  252. new DetectParams[0]));
  253. }
  254. public void email(uint localID, UUID itemID, string timeSent,
  255. string address, string subject, string message, int numLeft)
  256. {
  257. myScriptEngine.PostObjectEvent(localID, new EventParams(
  258. "email",new object[] {
  259. new LSL_Types.LSLString(timeSent),
  260. new LSL_Types.LSLString(address),
  261. new LSL_Types.LSLString(subject),
  262. new LSL_Types.LSLString(message),
  263. new LSL_Types.LSLInteger(numLeft)},
  264. new DetectParams[0]));
  265. }
  266. public void at_target(uint localID, uint handle, Vector3 targetpos,
  267. Vector3 atpos)
  268. {
  269. myScriptEngine.PostObjectEvent(localID, new EventParams(
  270. "at_target", new object[] {
  271. new LSL_Types.LSLInteger(handle),
  272. new LSL_Types.Vector3(targetpos.X,targetpos.Y,targetpos.Z),
  273. new LSL_Types.Vector3(atpos.X,atpos.Y,atpos.Z) },
  274. new DetectParams[0]));
  275. }
  276. public void not_at_target(uint localID)
  277. {
  278. myScriptEngine.PostObjectEvent(localID, new EventParams(
  279. "not_at_target",new object[0],
  280. new DetectParams[0]));
  281. }
  282. public void at_rot_target(uint localID, UUID itemID)
  283. {
  284. myScriptEngine.PostObjectEvent(localID, new EventParams(
  285. "at_rot_target",new object[0],
  286. new DetectParams[0]));
  287. }
  288. public void not_at_rot_target(uint localID, UUID itemID)
  289. {
  290. myScriptEngine.PostObjectEvent(localID, new EventParams(
  291. "not_at_rot_target",new object[0],
  292. new DetectParams[0]));
  293. }
  294. // run_time_permissions: not handled here
  295. public void attach(uint localID, UUID itemID, UUID avatar)
  296. {
  297. myScriptEngine.PostObjectEvent(localID, new EventParams(
  298. "attach",new object[] {
  299. new LSL_Types.LSLString(avatar.ToString()) },
  300. new DetectParams[0]));
  301. }
  302. // dataserver: not handled here
  303. // link_message: not handled here
  304. public void moving_start(uint localID, UUID itemID)
  305. {
  306. myScriptEngine.PostObjectEvent(localID, new EventParams(
  307. "moving_start",new object[0],
  308. new DetectParams[0]));
  309. }
  310. public void moving_end(uint localID, UUID itemID)
  311. {
  312. myScriptEngine.PostObjectEvent(localID, new EventParams(
  313. "moving_end",new object[0],
  314. new DetectParams[0]));
  315. }
  316. // object_rez: not handled here
  317. // remote_data: not handled here
  318. // http_response: not handled here
  319. }
  320. }