RegionCombinerIndividualEventForwarder.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 OpenMetaverse;
  29. using OpenSim.Framework;
  30. using OpenSim.Region.CoreModules.Avatar.Attachments;
  31. using OpenSim.Region.CoreModules.Avatar.Gods;
  32. using OpenSim.Region.Framework.Interfaces;
  33. using OpenSim.Region.Framework.Scenes;
  34. namespace OpenSim.Region.RegionCombinerModule
  35. {
  36. public class RegionCombinerIndividualEventForwarder
  37. {
  38. private Scene m_rootScene;
  39. private Scene m_virtScene;
  40. public RegionCombinerIndividualEventForwarder(Scene rootScene, Scene virtScene)
  41. {
  42. m_rootScene = rootScene;
  43. m_virtScene = virtScene;
  44. }
  45. public void ClientConnect(IClientAPI client)
  46. {
  47. m_virtScene.UnSubscribeToClientPrimEvents(client);
  48. m_virtScene.UnSubscribeToClientPrimRezEvents(client);
  49. m_virtScene.UnSubscribeToClientInventoryEvents(client);
  50. ((AttachmentsModule)m_virtScene.AttachmentsModule).UnsubscribeFromClientEvents(client);
  51. //m_virtScene.UnSubscribeToClientTeleportEvents(client);
  52. m_virtScene.UnSubscribeToClientScriptEvents(client);
  53. IGodsModule virtGodsModule = m_virtScene.RequestModuleInterface<IGodsModule>();
  54. if (virtGodsModule != null)
  55. ((GodsModule)virtGodsModule).UnsubscribeFromClientEvents(client);
  56. m_virtScene.UnSubscribeToClientNetworkEvents(client);
  57. m_rootScene.SubscribeToClientPrimEvents(client);
  58. client.OnAddPrim += LocalAddNewPrim;
  59. client.OnRezObject += LocalRezObject;
  60. m_rootScene.SubscribeToClientInventoryEvents(client);
  61. ((AttachmentsModule)m_rootScene.AttachmentsModule).SubscribeToClientEvents(client);
  62. //m_rootScene.SubscribeToClientTeleportEvents(client);
  63. m_rootScene.SubscribeToClientScriptEvents(client);
  64. IGodsModule rootGodsModule = m_virtScene.RequestModuleInterface<IGodsModule>();
  65. if (rootGodsModule != null)
  66. ((GodsModule)rootGodsModule).UnsubscribeFromClientEvents(client);
  67. m_rootScene.SubscribeToClientNetworkEvents(client);
  68. }
  69. public void ClientClosed(UUID clientid, Scene scene)
  70. {
  71. }
  72. /// <summary>
  73. /// Fixes position based on the region the Rez event came in on
  74. /// </summary>
  75. /// <param name="remoteclient"></param>
  76. /// <param name="itemid"></param>
  77. /// <param name="rayend"></param>
  78. /// <param name="raystart"></param>
  79. /// <param name="raytargetid"></param>
  80. /// <param name="bypassraycast"></param>
  81. /// <param name="rayendisintersection"></param>
  82. /// <param name="rezselected"></param>
  83. /// <param name="removeitem"></param>
  84. /// <param name="fromtaskid"></param>
  85. private void LocalRezObject(IClientAPI remoteclient, UUID itemid, Vector3 rayend, Vector3 raystart,
  86. UUID raytargetid, byte bypassraycast, bool rayendisintersection, bool rezselected, bool removeitem,
  87. UUID fromtaskid)
  88. {
  89. int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX;
  90. int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY;
  91. rayend.X += differenceX * (int)Constants.RegionSize;
  92. rayend.Y += differenceY * (int)Constants.RegionSize;
  93. raystart.X += differenceX * (int)Constants.RegionSize;
  94. raystart.Y += differenceY * (int)Constants.RegionSize;
  95. m_rootScene.RezObject(remoteclient, itemid, rayend, raystart, raytargetid, bypassraycast,
  96. rayendisintersection, rezselected, removeitem, fromtaskid);
  97. }
  98. /// <summary>
  99. /// Fixes position based on the region the AddPrimShape event came in on
  100. /// </summary>
  101. /// <param name="ownerid"></param>
  102. /// <param name="groupid"></param>
  103. /// <param name="rayend"></param>
  104. /// <param name="rot"></param>
  105. /// <param name="shape"></param>
  106. /// <param name="bypassraycast"></param>
  107. /// <param name="raystart"></param>
  108. /// <param name="raytargetid"></param>
  109. /// <param name="rayendisintersection"></param>
  110. private void LocalAddNewPrim(UUID ownerid, UUID groupid, Vector3 rayend, Quaternion rot,
  111. PrimitiveBaseShape shape, byte bypassraycast, Vector3 raystart, UUID raytargetid,
  112. byte rayendisintersection)
  113. {
  114. int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX;
  115. int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY;
  116. rayend.X += differenceX * (int)Constants.RegionSize;
  117. rayend.Y += differenceY * (int)Constants.RegionSize;
  118. raystart.X += differenceX * (int)Constants.RegionSize;
  119. raystart.Y += differenceY * (int)Constants.RegionSize;
  120. m_rootScene.AddNewPrim(ownerid, groupid, rayend, rot, shape, bypassraycast, raystart, raytargetid,
  121. rayendisintersection);
  122. }
  123. }
  124. }