1
0

LandServicesConnector.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 log4net;
  28. using System;
  29. using System.Collections;
  30. using System.Collections.Generic;
  31. using System.IO;
  32. using System.Reflection;
  33. using Nini.Config;
  34. using OpenSim.Framework;
  35. using OpenSim.Services.Interfaces;
  36. using OpenMetaverse;
  37. using Nwc.XmlRpc;
  38. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  39. using System.Net.Http;
  40. namespace OpenSim.Services.Connectors
  41. {
  42. public class LandServicesConnector : ILandService
  43. {
  44. private static readonly ILog m_log =
  45. LogManager.GetLogger(
  46. MethodBase.GetCurrentMethod().DeclaringType);
  47. protected IGridService m_GridService = null;
  48. public LandServicesConnector()
  49. {
  50. }
  51. public LandServicesConnector(IGridService gridServices)
  52. {
  53. Initialise(gridServices);
  54. }
  55. public virtual void Initialise(IGridService gridServices)
  56. {
  57. m_GridService = gridServices;
  58. }
  59. public virtual LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess)
  60. {
  61. LandData landData = null;
  62. IList paramList = new ArrayList();
  63. regionAccess = 42; // Default to adult. Better safe...
  64. try
  65. {
  66. uint xpos = 0, ypos = 0;
  67. Util.RegionHandleToWorldLoc(regionHandle, out xpos, out ypos);
  68. GridRegion info = m_GridService.GetRegionByPosition(scopeID, (int)xpos, (int)ypos);
  69. if (info != null) // just to be sure
  70. {
  71. string targetHandlestr = info.RegionHandle.ToString();
  72. if( ypos == 0 ) //HG proxy?
  73. {
  74. // this is real region handle on hg proxies hack
  75. targetHandlestr = info.RegionSecret;
  76. }
  77. Hashtable hash = new Hashtable();
  78. hash["region_handle"] = targetHandlestr;
  79. hash["x"] = x.ToString();
  80. hash["y"] = y.ToString();
  81. paramList.Add(hash);
  82. XmlRpcRequest request = new XmlRpcRequest("land_data", paramList);
  83. using HttpClient hclient = WebUtil.GetNewGlobalHttpClient(10000);
  84. XmlRpcResponse response = request.Send(info.ServerURI, hclient);
  85. if (response.IsFault)
  86. {
  87. m_log.ErrorFormat("[LAND CONNECTOR]: remote call returned an error: {0}", response.FaultString);
  88. }
  89. else
  90. {
  91. hash = (Hashtable)response.Value;
  92. try
  93. {
  94. landData = new LandData();
  95. landData.AABBMax = Vector3.Parse((string)hash["AABBMax"]);
  96. landData.AABBMin = Vector3.Parse((string)hash["AABBMin"]);
  97. landData.Area = Convert.ToInt32(hash["Area"]);
  98. landData.AuctionID = Convert.ToUInt32(hash["AuctionID"]);
  99. landData.Description = (string)hash["Description"];
  100. landData.Flags = Convert.ToUInt32(hash["Flags"]);
  101. landData.GlobalID = new UUID((string)hash["GlobalID"]);
  102. landData.Name = (string)hash["Name"];
  103. landData.OwnerID = new UUID((string)hash["OwnerID"]);
  104. landData.SalePrice = Convert.ToInt32(hash["SalePrice"]);
  105. landData.SnapshotID = new UUID((string)hash["SnapshotID"]);
  106. landData.UserLocation = Vector3.Parse((string)hash["UserLocation"]);
  107. if (hash["RegionAccess"] != null)
  108. regionAccess = (byte)Convert.ToInt32((string)hash["RegionAccess"]);
  109. if(hash["Dwell"] != null)
  110. landData.Dwell = Convert.ToSingle((string)hash["Dwell"]);
  111. //m_log.DebugFormat("[LAND CONNECTOR]: Got land data for parcel {0}", landData.Name);
  112. }
  113. catch (Exception e)
  114. {
  115. m_log.ErrorFormat(
  116. "[LAND CONNECTOR]: Got exception while parsing land-data: {0} {1}",
  117. e.Message, e.StackTrace);
  118. }
  119. }
  120. }
  121. else
  122. m_log.WarnFormat("[LAND CONNECTOR]: Couldn't find region with handle {0}", regionHandle);
  123. }
  124. catch (Exception e)
  125. {
  126. m_log.ErrorFormat("[LAND CONNECTOR]: Couldn't contact region {0}: {1}", regionHandle, e.Message);
  127. }
  128. return landData;
  129. }
  130. }
  131. }