XEstateConnector.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.Reflection;
  30. using OpenSim.Services.Interfaces;
  31. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  32. using OpenSim.Server.Base;
  33. using OpenSim.Framework.Servers.HttpServer;
  34. using OpenSim.Framework;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenMetaverse;
  37. using log4net;
  38. namespace OpenSim.Region.CoreModules.World.Estate
  39. {
  40. public class EstateConnector
  41. {
  42. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  43. protected XEstateModule m_EstateModule;
  44. public EstateConnector(XEstateModule module)
  45. {
  46. m_EstateModule = module;
  47. }
  48. public void SendTeleportHomeOneUser(uint EstateID, UUID PreyID)
  49. {
  50. Dictionary<string, object> sendData = new Dictionary<string, object>();
  51. sendData["METHOD"] = "teleport_home_one_user";
  52. sendData["EstateID"] = EstateID.ToString();
  53. sendData["PreyID"] = PreyID.ToString();
  54. SendToEstate(EstateID, sendData);
  55. }
  56. public void SendTeleportHomeAllUsers(uint EstateID)
  57. {
  58. Dictionary<string, object> sendData = new Dictionary<string, object>();
  59. sendData["METHOD"] = "teleport_home_all_users";
  60. sendData["EstateID"] = EstateID.ToString();
  61. SendToEstate(EstateID, sendData);
  62. }
  63. public bool SendUpdateCovenant(uint EstateID, UUID CovenantID)
  64. {
  65. Dictionary<string, object> sendData = new Dictionary<string, object>();
  66. sendData["METHOD"] = "update_covenant";
  67. sendData["CovenantID"] = CovenantID.ToString();
  68. sendData["EstateID"] = EstateID.ToString();
  69. // Handle local regions locally
  70. //
  71. foreach (Scene s in m_EstateModule.Scenes)
  72. {
  73. if (s.RegionInfo.EstateSettings.EstateID == EstateID)
  74. s.RegionInfo.RegionSettings.Covenant = CovenantID;
  75. // s.ReloadEstateData();
  76. }
  77. SendToEstate(EstateID, sendData);
  78. return true;
  79. }
  80. public bool SendUpdateEstate(uint EstateID)
  81. {
  82. Dictionary<string, object> sendData = new Dictionary<string, object>();
  83. sendData["METHOD"] = "update_estate";
  84. sendData["EstateID"] = EstateID.ToString();
  85. // Handle local regions locally
  86. //
  87. foreach (Scene s in m_EstateModule.Scenes)
  88. {
  89. if (s.RegionInfo.EstateSettings.EstateID == EstateID)
  90. s.ReloadEstateData();
  91. }
  92. SendToEstate(EstateID, sendData);
  93. return true;
  94. }
  95. public void SendEstateMessage(uint EstateID, UUID FromID, string FromName, string Message)
  96. {
  97. Dictionary<string, object> sendData = new Dictionary<string, object>();
  98. sendData["METHOD"] = "estate_message";
  99. sendData["EstateID"] = EstateID.ToString();
  100. sendData["FromID"] = FromID.ToString();
  101. sendData["FromName"] = FromName;
  102. sendData["Message"] = Message;
  103. SendToEstate(EstateID, sendData);
  104. }
  105. private void SendToEstate(uint EstateID, Dictionary<string, object> sendData)
  106. {
  107. List<UUID> regions = m_EstateModule.Scenes[0].GetEstateRegions((int)EstateID);
  108. UUID ScopeID = UUID.Zero;
  109. // Handle local regions locally
  110. //
  111. lock (m_EstateModule.Scenes)
  112. {
  113. foreach (Scene s in m_EstateModule.Scenes)
  114. {
  115. if (regions.Contains(s.RegionInfo.RegionID))
  116. {
  117. // All regions in one estate are in the same scope.
  118. // Use that scope.
  119. //
  120. ScopeID = s.RegionInfo.ScopeID;
  121. regions.Remove(s.RegionInfo.RegionID);
  122. }
  123. }
  124. }
  125. // Our own region should always be in the above list.
  126. // In a standalone this would not be true. But then,
  127. // Scope ID is not relevat there. Use first scope.
  128. //
  129. if (ScopeID == UUID.Zero)
  130. ScopeID = m_EstateModule.Scenes[0].RegionInfo.ScopeID;
  131. // Don't send to the same instance twice
  132. //
  133. List<string> done = new List<string>();
  134. // Send to remote regions
  135. //
  136. foreach (UUID regionID in regions)
  137. {
  138. GridRegion region = m_EstateModule.Scenes[0].GridService.GetRegionByUUID(ScopeID, regionID);
  139. if (region != null)
  140. {
  141. string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
  142. if (done.Contains(url))
  143. continue;
  144. Call(region, sendData);
  145. done.Add(url);
  146. }
  147. }
  148. }
  149. private bool Call(GridRegion region, Dictionary<string, object> sendData)
  150. {
  151. string reqString = ServerUtils.BuildQueryString(sendData);
  152. // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString);
  153. try
  154. {
  155. string url = "http://" + region.ExternalHostName + ":" + region.HttpPort;
  156. string reply = SynchronousRestFormsRequester.MakeRequest("POST",
  157. url + "/estate",
  158. reqString);
  159. if (reply != string.Empty)
  160. {
  161. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  162. if (replyData.ContainsKey("RESULT"))
  163. {
  164. if (replyData["RESULT"].ToString().ToLower() == "true")
  165. return true;
  166. else
  167. return false;
  168. }
  169. else
  170. m_log.DebugFormat("[XESTATE CONNECTOR]: reply data does not contain result field");
  171. }
  172. else
  173. m_log.DebugFormat("[XESTATE CONNECTOR]: received empty reply");
  174. }
  175. catch (Exception e)
  176. {
  177. m_log.DebugFormat("[XESTATE CONNECTOR]: Exception when contacting remote sim: {0}", e.Message);
  178. }
  179. return false;
  180. }
  181. }
  182. }