EstateManager.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (c) Contributors, http://www.openmetaverse.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 OpenSim 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. */
  28. using System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using libsecondlife;
  32. using libsecondlife.Packets;
  33. using OpenSim.Framework.Console;
  34. using OpenSim.Framework.Interfaces;
  35. using OpenSim.Framework.Types;
  36. using OpenSim.Region.Environment.Scenes;
  37. using Avatar = OpenSim.Region.Environment.Scenes.ScenePresence;
  38. namespace OpenSim.Region.Environment
  39. {
  40. /// <summary>
  41. /// Processes requests regarding estates. Refer to EstateSettings.cs in OpenSim.Framework. Types for all of the core settings
  42. /// </summary>
  43. public class EstateManager
  44. {
  45. private Scene m_scene;
  46. private RegionInfo m_regInfo;
  47. public EstateManager(Scene scene,RegionInfo reginfo)
  48. {
  49. m_scene = scene;
  50. m_regInfo = reginfo;
  51. }
  52. private bool convertParamStringToBool(byte[] field)
  53. {
  54. string s = Helpers.FieldToUTF8String(field);
  55. if (s == "1" || s.ToLower() == "y" || s.ToLower() == "yes" || s.ToLower() == "t" || s.ToLower() == "true")
  56. {
  57. return true;
  58. }
  59. return false;
  60. }
  61. /// <summary>
  62. /// Sets terrain texture heights for each of the four corners of the region - textures are distributed as a linear range between the two heights.
  63. /// </summary>
  64. /// <param name="corner">Which corner</param>
  65. /// <param name="lowValue">Minimum height that texture range should cover</param>
  66. /// <param name="highValue">Maximum height that texture range should cover</param>
  67. public void setEstateTextureRange(Int16 corner, float lowValue, float highValue)
  68. {
  69. switch (corner)
  70. {
  71. case 0:
  72. m_regInfo.estateSettings.terrainStartHeight0 = lowValue;
  73. m_regInfo.estateSettings.terrainHeightRange0 = highValue;
  74. break;
  75. case 1:
  76. m_regInfo.estateSettings.terrainStartHeight1 = lowValue;
  77. m_regInfo.estateSettings.terrainHeightRange1 = highValue;
  78. break;
  79. case 2:
  80. m_regInfo.estateSettings.terrainStartHeight2 = lowValue;
  81. m_regInfo.estateSettings.terrainHeightRange2 = highValue;
  82. break;
  83. case 3:
  84. m_regInfo.estateSettings.terrainStartHeight3 = lowValue;
  85. m_regInfo.estateSettings.terrainHeightRange3 = highValue;
  86. break;
  87. }
  88. }
  89. /// <summary>
  90. /// Sets the 'detail' terrain texture on each of the bands.
  91. /// </summary>
  92. /// <param name="band">Which texture band</param>
  93. /// <param name="textureUUID">The UUID of the texture</param>
  94. public void setTerrainTexture(Int16 band, LLUUID textureUUID)
  95. {
  96. switch (band)
  97. {
  98. case 0:
  99. m_regInfo.estateSettings.terrainDetail0 = textureUUID;
  100. break;
  101. case 1:
  102. m_regInfo.estateSettings.terrainDetail1 = textureUUID;
  103. break;
  104. case 2:
  105. m_regInfo.estateSettings.terrainDetail2 = textureUUID;
  106. break;
  107. case 3:
  108. m_regInfo.estateSettings.terrainDetail3 = textureUUID;
  109. break;
  110. }
  111. }
  112. /// <summary>
  113. /// Sets common region settings
  114. /// </summary>
  115. /// <param name="WaterHeight">Water height of the waterplane (may not nessecarily be one value)</param>
  116. /// <param name="TerrainRaiseLimit">Maximum amount terrain can be raised from previous baking</param>
  117. /// <param name="TerrainLowerLimit">Minimum amount terrain can be lowered from previous baking</param>
  118. /// <param name="UseFixedSun">Use a fixed time of day on the sun?</param>
  119. /// <param name="SunHour">The offset hour of the day</param>
  120. public void setRegionSettings(float WaterHeight, float TerrainRaiseLimit, float TerrainLowerLimit, bool UseFixedSun, float SunHour)
  121. {
  122. // Water Height
  123. m_regInfo.estateSettings.waterHeight = WaterHeight;
  124. m_scene.Terrain.watermap.Fill(WaterHeight);
  125. // Terraforming limits
  126. m_regInfo.estateSettings.terrainRaiseLimit = TerrainRaiseLimit;
  127. m_regInfo.estateSettings.terrainLowerLimit = TerrainLowerLimit;
  128. m_scene.Terrain.maxRaise = TerrainRaiseLimit;
  129. m_scene.Terrain.minLower = TerrainLowerLimit;
  130. // Time of day / fixed sun
  131. m_regInfo.estateSettings.useFixedSun = UseFixedSun;
  132. m_regInfo.estateSettings.sunHour = SunHour;
  133. }
  134. #region Packet Handlers
  135. public void handleEstateOwnerMessage(EstateOwnerMessagePacket packet, IClientAPI remote_client)
  136. {
  137. switch (Helpers.FieldToUTF8String(packet.MethodData.Method))
  138. {
  139. case "getinfo":
  140. this.sendRegionInfoPacketToAll();
  141. break;
  142. case "setregioninfo":
  143. if (m_scene.PermissionsMngr.CanEditEstateTerrain(remote_client.AgentId))
  144. estateSetRegionInfoHandler(packet);
  145. break;
  146. case "texturebase":
  147. if (m_scene.PermissionsMngr.CanEditEstateTerrain(remote_client.AgentId))
  148. estateTextureBaseHandler(packet);
  149. break;
  150. case "texturedetail":
  151. if (m_scene.PermissionsMngr.CanEditEstateTerrain(remote_client.AgentId))
  152. estateTextureDetailHandler(packet);
  153. break;
  154. case "textureheights":
  155. if (m_scene.PermissionsMngr.CanEditEstateTerrain(remote_client.AgentId))
  156. estateTextureHeightsHandler(packet);
  157. break;
  158. case "texturecommit":
  159. sendRegionHandshakeToAll();
  160. break;
  161. case "setregionterrain":
  162. if (m_scene.PermissionsMngr.CanEditEstateTerrain(remote_client.AgentId))
  163. estateSetRegionTerrainHandler(packet);
  164. break;
  165. default:
  166. MainLog.Instance.Error("EstateOwnerMessage: Unknown method requested\n" + packet.ToString());
  167. break;
  168. }
  169. }
  170. private void estateSetRegionInfoHandler(EstateOwnerMessagePacket packet)
  171. {
  172. if (packet.ParamList.Length != 9)
  173. {
  174. MainLog.Instance.Error("EstateOwnerMessage: SetRegionInfo method has a ParamList of invalid length");
  175. }
  176. else
  177. {
  178. m_regInfo.estateSettings.regionFlags = Simulator.RegionFlags.None;
  179. if (convertParamStringToBool(packet.ParamList[0].Parameter))
  180. {
  181. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockTerraform;
  182. }
  183. if (convertParamStringToBool(packet.ParamList[1].Parameter))
  184. {
  185. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.NoFly;
  186. }
  187. if (convertParamStringToBool(packet.ParamList[2].Parameter))
  188. {
  189. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowDamage;
  190. }
  191. if (convertParamStringToBool(packet.ParamList[3].Parameter) == false)
  192. {
  193. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockLandResell;
  194. }
  195. int tempMaxAgents = Convert.ToInt16(Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[4].Parameter)));
  196. m_regInfo.estateSettings.maxAgents = (byte)tempMaxAgents;
  197. float tempObjectBonusFactor = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
  198. m_regInfo.estateSettings.objectBonusFactor = tempObjectBonusFactor;
  199. int tempMatureLevel = Convert.ToInt16(Helpers.FieldToUTF8String(packet.ParamList[6].Parameter));
  200. m_regInfo.estateSettings.simAccess = (Simulator.SimAccess)tempMatureLevel;
  201. if (convertParamStringToBool(packet.ParamList[7].Parameter))
  202. {
  203. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.RestrictPushObject;
  204. }
  205. if (convertParamStringToBool(packet.ParamList[8].Parameter))
  206. {
  207. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowParcelChanges;
  208. }
  209. sendRegionInfoPacketToAll();
  210. }
  211. }
  212. private void estateSetRegionTerrainHandler(EstateOwnerMessagePacket packet)
  213. {
  214. if (packet.ParamList.Length != 9)
  215. {
  216. MainLog.Instance.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  217. }
  218. else
  219. {
  220. float WaterHeight = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[0].Parameter));
  221. float TerrainRaiseLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[1].Parameter));
  222. float TerrainLowerLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[2].Parameter));
  223. bool UseFixedSun = this.convertParamStringToBool(packet.ParamList[4].Parameter);
  224. float SunHour = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
  225. setRegionSettings(WaterHeight, TerrainRaiseLimit, TerrainLowerLimit, UseFixedSun, SunHour);
  226. sendRegionInfoPacketToAll();
  227. }
  228. }
  229. private void estateTextureHeightsHandler(EstateOwnerMessagePacket packet)
  230. {
  231. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  232. {
  233. string s = Helpers.FieldToUTF8String(block.Parameter);
  234. string[] splitField = s.Split(' ');
  235. if (splitField.Length == 3)
  236. {
  237. Int16 corner = Convert.ToInt16(splitField[0]);
  238. float lowValue = (float)Convert.ToDecimal(splitField[1]);
  239. float highValue = (float)Convert.ToDecimal(splitField[2]);
  240. setEstateTextureRange(corner, lowValue, highValue);
  241. }
  242. }
  243. }
  244. private void estateTextureDetailHandler(EstateOwnerMessagePacket packet)
  245. {
  246. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  247. {
  248. string s = Helpers.FieldToUTF8String(block.Parameter);
  249. string[] splitField = s.Split(' ');
  250. if (splitField.Length == 2)
  251. {
  252. Int16 corner = Convert.ToInt16(splitField[0]);
  253. LLUUID textureUUID = new LLUUID(splitField[1]);
  254. setTerrainTexture(corner, textureUUID);
  255. }
  256. }
  257. }
  258. private void estateTextureBaseHandler(EstateOwnerMessagePacket packet)
  259. {
  260. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  261. {
  262. string s = Helpers.FieldToUTF8String(block.Parameter);
  263. string[] splitField = s.Split(' ');
  264. if (splitField.Length == 2)
  265. {
  266. LLUUID tempUUID = new LLUUID(splitField[1]);
  267. switch (Convert.ToInt16(splitField[0]))
  268. {
  269. case 0:
  270. m_regInfo.estateSettings.terrainBase0 = tempUUID;
  271. break;
  272. case 1:
  273. m_regInfo.estateSettings.terrainBase1 = tempUUID;
  274. break;
  275. case 2:
  276. m_regInfo.estateSettings.terrainBase2 = tempUUID;
  277. break;
  278. case 3:
  279. m_regInfo.estateSettings.terrainBase3 = tempUUID;
  280. break;
  281. }
  282. }
  283. }
  284. }
  285. #endregion
  286. #region Outgoing Packets
  287. public void sendRegionInfoPacketToAll()
  288. {
  289. List<Avatar> avatars = m_scene.RequestAvatarList();
  290. for (int i = 0; i < avatars.Count; i++)
  291. {
  292. this.sendRegionInfoPacket(avatars[i].ControllingClient);
  293. }
  294. }
  295. public void sendRegionHandshakeToAll()
  296. {
  297. List<Avatar> avatars = m_scene.RequestAvatarList();
  298. for (int i = 0; i < avatars.Count; i++)
  299. {
  300. this.sendRegionHandshake(avatars[i].ControllingClient);
  301. }
  302. }
  303. public void sendRegionInfoPacket(IClientAPI remote_client)
  304. {
  305. Encoding _enc = Encoding.ASCII;
  306. AgentCircuitData circuitData = remote_client.RequestClientInfo();
  307. RegionInfoPacket regionInfoPacket = new RegionInfoPacket();
  308. regionInfoPacket.AgentData.AgentID = circuitData.AgentID;
  309. regionInfoPacket.AgentData.SessionID = circuitData.SessionID;
  310. regionInfoPacket.RegionInfo.BillableFactor = m_regInfo.estateSettings.billableFactor;
  311. regionInfoPacket.RegionInfo.EstateID = m_regInfo.estateSettings.estateID;
  312. regionInfoPacket.RegionInfo.MaxAgents = m_regInfo.estateSettings.maxAgents;
  313. regionInfoPacket.RegionInfo.ObjectBonusFactor = m_regInfo.estateSettings.objectBonusFactor;
  314. regionInfoPacket.RegionInfo.ParentEstateID = m_regInfo.estateSettings.parentEstateID;
  315. regionInfoPacket.RegionInfo.PricePerMeter = m_regInfo.estateSettings.pricePerMeter;
  316. regionInfoPacket.RegionInfo.RedirectGridX = m_regInfo.estateSettings.redirectGridX;
  317. regionInfoPacket.RegionInfo.RedirectGridY = m_regInfo.estateSettings.redirectGridY;
  318. regionInfoPacket.RegionInfo.RegionFlags = (uint)m_regInfo.estateSettings.regionFlags;
  319. regionInfoPacket.RegionInfo.SimAccess = (byte)m_regInfo.estateSettings.simAccess;
  320. regionInfoPacket.RegionInfo.SimName = _enc.GetBytes( m_regInfo.RegionName);
  321. regionInfoPacket.RegionInfo.SunHour = m_regInfo.estateSettings.sunHour;
  322. regionInfoPacket.RegionInfo.TerrainLowerLimit = m_regInfo.estateSettings.terrainLowerLimit;
  323. regionInfoPacket.RegionInfo.TerrainRaiseLimit = m_regInfo.estateSettings.terrainRaiseLimit;
  324. regionInfoPacket.RegionInfo.UseEstateSun = !m_regInfo.estateSettings.useFixedSun;
  325. regionInfoPacket.RegionInfo.WaterHeight = m_regInfo.estateSettings.waterHeight;
  326. remote_client.OutPacket(regionInfoPacket);
  327. }
  328. public void sendRegionHandshake(IClientAPI remoteClient)
  329. {
  330. remoteClient.SendRegionHandshake(m_regInfo);
  331. }
  332. #endregion
  333. }
  334. }