LSLEventProvider.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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.Collections.Generic;
  29. using System.Text;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Region.Framework.Scenes;
  33. using OpenSim.Region.ScriptEngine.Shared;
  34. using OpenSim.ScriptEngine.Shared;
  35. using EventParams = OpenSim.ScriptEngine.Shared.EventParams;
  36. namespace OpenSim.ScriptEngine.Components.DotNetEngine.Events
  37. {
  38. public class LSLEventProvider : IScriptEventProvider
  39. {
  40. public delegate void RezScriptDelegate(uint localID, UUID itemID, string script, int startParam, bool postOnRez,
  41. string engine);
  42. public event RezScriptDelegate RezScript;
  43. public delegate void RemoveScriptDelegate(uint localID, UUID itemID);
  44. public event RemoveScriptDelegate RemoveScript;
  45. public delegate void ScriptChangedDelegate(uint localID, uint change);
  46. public event ScriptChangedDelegate ScriptChanged;
  47. private RegionInfoStructure CurrentRegion;
  48. public void Initialize(RegionInfoStructure currentRegion)
  49. {
  50. CurrentRegion = currentRegion;
  51. HookupEvents();
  52. }
  53. private void HookupEvents()
  54. {
  55. CurrentRegion.Scene.EventManager.OnObjectGrab += OnObjectGrab;
  56. CurrentRegion.Scene.EventManager.OnRezScript += OnRezScript;
  57. CurrentRegion.Scene.EventManager.OnRemoveScript += OnRemoveScript;
  58. CurrentRegion.Scene.EventManager.OnScriptChangedEvent += OnScriptChangedEvent;
  59. }
  60. private void OnScriptChangedEvent(uint localID, uint change)
  61. {
  62. // Script is being changed, fire event
  63. if (ScriptChanged != null)
  64. ScriptChanged(localID, change);
  65. }
  66. private void OnRemoveScript(uint localID, UUID itemID)
  67. {
  68. // Script is being removed, fire event
  69. if (RemoveScript != null)
  70. RemoveScript(localID, itemID);
  71. }
  72. private void OnRezScript(uint localID, UUID itemID, string script, int startParam, bool postOnRez, string engine, int stateSource)
  73. {
  74. // New script being created, fire event
  75. if (RezScript != null)
  76. RezScript(localID, itemID, script, startParam, postOnRez, engine);
  77. }
  78. private void OnObjectGrab(uint localID, uint originalID, Vector3 offsetPos, 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(World);
  85. if (originalID == 0)
  86. {
  87. SceneObjectPart part =
  88. CurrentRegion.Scene.GetSceneObjectPart(localID);
  89. if (part == null)
  90. return;
  91. det[0].LinkNum = part.LinkNum;
  92. }
  93. else
  94. {
  95. SceneObjectPart originalPart =
  96. CurrentRegion.Scene.GetSceneObjectPart(originalID);
  97. det[0].LinkNum = originalPart.LinkNum;
  98. }
  99. if (surfaceArgs != null)
  100. {
  101. det[0].SurfaceTouchArgs = surfaceArgs;
  102. }
  103. Shared.EventParams ep =
  104. new Shared.EventParams(localID, "touch_start", new Object[] {new LSL_Types.LSLInteger(1)}, det);
  105. CurrentRegion.Executors_Execute(ep);
  106. }
  107. }
  108. }