1
0

RegionCombinerIndividualEventForwarder.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. if(m_virtScene.AttachmentsModule != null)
  51. ((AttachmentsModule)m_virtScene.AttachmentsModule).UnsubscribeFromClientEvents(client);
  52. //m_virtScene.UnSubscribeToClientTeleportEvents(client);
  53. m_virtScene.UnSubscribeToClientScriptEvents(client);
  54. IGodsModule virtGodsModule = m_virtScene.RequestModuleInterface<IGodsModule>();
  55. if (virtGodsModule != null)
  56. ((GodsModule)virtGodsModule).UnsubscribeFromClientEvents(client);
  57. m_virtScene.UnSubscribeToClientNetworkEvents(client);
  58. m_rootScene.SubscribeToClientPrimEvents(client);
  59. client.OnAddPrim += LocalAddNewPrim;
  60. client.OnRezObject += LocalRezObject;
  61. m_rootScene.SubscribeToClientInventoryEvents(client);
  62. if (m_rootScene.AttachmentsModule != null)
  63. ((AttachmentsModule)m_rootScene.AttachmentsModule).SubscribeToClientEvents(client);
  64. //m_rootScene.SubscribeToClientTeleportEvents(client);
  65. m_rootScene.SubscribeToClientScriptEvents(client);
  66. IGodsModule rootGodsModule = m_virtScene.RequestModuleInterface<IGodsModule>();
  67. if (rootGodsModule != null)
  68. ((GodsModule)rootGodsModule).UnsubscribeFromClientEvents(client);
  69. m_rootScene.SubscribeToClientNetworkEvents(client);
  70. }
  71. public void ClientClosed(UUID clientid, Scene scene)
  72. {
  73. }
  74. /// <summary>
  75. /// Fixes position based on the region the Rez event came in on
  76. /// </summary>
  77. /// <param name="remoteclient"></param>
  78. /// <param name="itemid"></param>
  79. /// <param name="rayend"></param>
  80. /// <param name="raystart"></param>
  81. /// <param name="raytargetid"></param>
  82. /// <param name="bypassraycast"></param>
  83. /// <param name="rayendisintersection"></param>
  84. /// <param name="rezselected"></param>
  85. /// <param name="removeitem"></param>
  86. /// <param name="fromtaskid"></param>
  87. private void LocalRezObject(IClientAPI remoteclient, UUID itemid, Vector3 rayend, Vector3 raystart,
  88. UUID raytargetid, byte bypassraycast, bool rayendisintersection, bool rezselected, bool removeitem,
  89. UUID fromtaskid)
  90. {
  91. int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX;
  92. int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY;
  93. rayend.X += differenceX * (int)Constants.RegionSize;
  94. rayend.Y += differenceY * (int)Constants.RegionSize;
  95. raystart.X += differenceX * (int)Constants.RegionSize;
  96. raystart.Y += differenceY * (int)Constants.RegionSize;
  97. m_rootScene.RezObject(remoteclient, itemid, rayend, raystart, raytargetid, bypassraycast,
  98. rayendisintersection, rezselected, removeitem, fromtaskid);
  99. }
  100. /// <summary>
  101. /// Fixes position based on the region the AddPrimShape event came in on
  102. /// </summary>
  103. /// <param name="ownerid"></param>
  104. /// <param name="groupid"></param>
  105. /// <param name="rayend"></param>
  106. /// <param name="rot"></param>
  107. /// <param name="shape"></param>
  108. /// <param name="bypassraycast"></param>
  109. /// <param name="raystart"></param>
  110. /// <param name="raytargetid"></param>
  111. /// <param name="rayendisintersection"></param>
  112. private void LocalAddNewPrim(UUID ownerid, UUID groupid, Vector3 rayend, Quaternion rot,
  113. PrimitiveBaseShape shape, byte bypassraycast, Vector3 raystart, UUID raytargetid,
  114. byte rayendisintersection)
  115. {
  116. int differenceX = (int)m_virtScene.RegionInfo.RegionLocX - (int)m_rootScene.RegionInfo.RegionLocX;
  117. int differenceY = (int)m_virtScene.RegionInfo.RegionLocY - (int)m_rootScene.RegionInfo.RegionLocY;
  118. rayend.X += differenceX * (int)Constants.RegionSize;
  119. rayend.Y += differenceY * (int)Constants.RegionSize;
  120. raystart.X += differenceX * (int)Constants.RegionSize;
  121. raystart.Y += differenceY * (int)Constants.RegionSize;
  122. m_rootScene.AddNewPrim(ownerid, groupid, rayend, rot, shape, bypassraycast, raystart, raytargetid,
  123. rayendisintersection);
  124. }
  125. }
  126. }