1
0

EstateConnector.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 EstateModule m_EstateModule;
  44. private string token;
  45. uint port = 0;
  46. public EstateConnector(EstateModule module, string _token, uint _port)
  47. {
  48. m_EstateModule = module;
  49. token = _token;
  50. port = _port;
  51. }
  52. public void SendTeleportHomeOneUser(uint EstateID, UUID PreyID)
  53. {
  54. Dictionary<string, object> sendData = new Dictionary<string, object>();
  55. sendData["METHOD"] = "teleport_home_one_user";
  56. sendData["TOKEN"] = token;
  57. sendData["EstateID"] = EstateID.ToString();
  58. sendData["PreyID"] = PreyID.ToString();
  59. SendToEstate(EstateID, sendData);
  60. }
  61. public void SendTeleportHomeAllUsers(uint EstateID)
  62. {
  63. Dictionary<string, object> sendData = new Dictionary<string, object>();
  64. sendData["METHOD"] = "teleport_home_all_users";
  65. sendData["TOKEN"] = token;
  66. sendData["EstateID"] = EstateID.ToString();
  67. SendToEstate(EstateID, sendData);
  68. }
  69. public bool SendUpdateCovenant(uint EstateID, UUID CovenantID)
  70. {
  71. Dictionary<string, object> sendData = new Dictionary<string, object>();
  72. sendData["METHOD"] = "update_covenant";
  73. sendData["TOKEN"] = token;
  74. sendData["CovenantID"] = CovenantID.ToString();
  75. sendData["EstateID"] = EstateID.ToString();
  76. // Handle local regions locally
  77. //
  78. foreach (Scene s in m_EstateModule.Scenes)
  79. {
  80. if (s.RegionInfo.EstateSettings.EstateID == EstateID)
  81. s.RegionInfo.RegionSettings.Covenant = CovenantID;
  82. // s.ReloadEstateData();
  83. }
  84. SendToEstate(EstateID, sendData);
  85. return true;
  86. }
  87. public bool SendUpdateEstate(uint EstateID)
  88. {
  89. Dictionary<string, object> sendData = new Dictionary<string, object>();
  90. sendData["METHOD"] = "update_estate";
  91. sendData["TOKEN"] = token;
  92. sendData["EstateID"] = EstateID.ToString();
  93. // Handle local regions locally
  94. //
  95. foreach (Scene s in m_EstateModule.Scenes)
  96. {
  97. if (s.RegionInfo.EstateSettings.EstateID == EstateID)
  98. s.ReloadEstateData();
  99. }
  100. SendToEstate(EstateID, sendData);
  101. return true;
  102. }
  103. public void SendEstateMessage(uint EstateID, UUID FromID, string FromName, string Message)
  104. {
  105. Dictionary<string, object> sendData = new Dictionary<string, object>();
  106. sendData["METHOD"] = "estate_message";
  107. sendData["TOKEN"] = token;
  108. sendData["EstateID"] = EstateID.ToString();
  109. sendData["FromID"] = FromID.ToString();
  110. sendData["FromName"] = FromName;
  111. sendData["Message"] = Message;
  112. SendToEstate(EstateID, sendData);
  113. }
  114. private void SendToEstate(uint EstateID, Dictionary<string, object> sendData)
  115. {
  116. List<UUID> regions = m_EstateModule.Scenes[0].GetEstateRegions((int)EstateID);
  117. // Don't send to the same instance twice
  118. List<string> done = new List<string>();
  119. // Handle local regions locally
  120. lock (m_EstateModule.Scenes)
  121. {
  122. foreach (Scene s in m_EstateModule.Scenes)
  123. {
  124. RegionInfo sreg = s.RegionInfo;
  125. if (regions.Contains(sreg.RegionID))
  126. {
  127. string url = sreg.ExternalHostName + ":" + sreg.HttpPort;
  128. regions.Remove(sreg.RegionID);
  129. if(!done.Contains(url)) // we may have older regs with same url lost in dbs
  130. done.Add(url);
  131. }
  132. }
  133. }
  134. if(regions.Count == 0)
  135. return;
  136. Scene baseScene = m_EstateModule.Scenes[0];
  137. UUID ScopeID = baseScene.RegionInfo.ScopeID;
  138. IGridService gridService = baseScene.GridService;
  139. if(gridService == null)
  140. return;
  141. // Send to remote regions
  142. foreach (UUID regionID in regions)
  143. {
  144. GridRegion region = gridService.GetRegionByUUID(ScopeID, regionID);
  145. if (region != null)
  146. {
  147. string url = region.ExternalHostName + ":" + region.HttpPort;
  148. if(done.Contains(url))
  149. continue;
  150. Call(region, sendData);
  151. done.Add(url);
  152. }
  153. }
  154. }
  155. private bool Call(GridRegion region, Dictionary<string, object> sendData)
  156. {
  157. string reqString = ServerUtils.BuildQueryString(sendData);
  158. // m_log.DebugFormat("[XESTATE CONNECTOR]: queryString = {0}", reqString);
  159. try
  160. {
  161. string url = "";
  162. if(port != 0)
  163. url = "http://" + region.ExternalHostName + ":" + port + "/";
  164. else
  165. url = region.ServerURI;
  166. string reply = SynchronousRestFormsRequester.MakeRequest("POST",
  167. url + "estate",
  168. reqString);
  169. if (reply != string.Empty)
  170. {
  171. Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
  172. if (replyData.ContainsKey("RESULT"))
  173. {
  174. if (replyData["RESULT"].ToString().ToLower() == "true")
  175. return true;
  176. else
  177. return false;
  178. }
  179. else
  180. m_log.DebugFormat("[XESTATE CONNECTOR]: reply data does not contain result field");
  181. }
  182. else
  183. m_log.DebugFormat("[XESTATE CONNECTOR]: received empty reply");
  184. }
  185. catch (Exception e)
  186. {
  187. m_log.DebugFormat("[XESTATE CONNECTOR]: Exception when contacting remote sim: {0}", e.Message);
  188. }
  189. return false;
  190. }
  191. }
  192. }