EstateManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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_world;
  46. private RegionInfo m_regInfo;
  47. public EstateManager(Scene world,RegionInfo reginfo)
  48. {
  49. m_world = world; //Estate settings found at world.m_regInfo.estateSettings
  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. public void handleEstateOwnerMessage(EstateOwnerMessagePacket packet, IClientAPI remote_client)
  62. {
  63. if (remote_client.AgentId == m_regInfo.MasterAvatarAssignedUUID)
  64. {
  65. switch (Helpers.FieldToUTF8String(packet.MethodData.Method))
  66. {
  67. case "getinfo":
  68. Console.WriteLine("GETINFO Requested");
  69. this.sendRegionInfoPacketToAll();
  70. break;
  71. case "setregioninfo":
  72. if (packet.ParamList.Length != 9)
  73. {
  74. MainLog.Instance.Error("EstateOwnerMessage: SetRegionInfo method has a ParamList of invalid length");
  75. }
  76. else
  77. {
  78. m_regInfo.estateSettings.regionFlags = Simulator.RegionFlags.None;
  79. if (convertParamStringToBool(packet.ParamList[0].Parameter))
  80. {
  81. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockTerraform;
  82. }
  83. if (convertParamStringToBool(packet.ParamList[1].Parameter))
  84. {
  85. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.NoFly;
  86. }
  87. if (convertParamStringToBool(packet.ParamList[2].Parameter))
  88. {
  89. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowDamage;
  90. }
  91. if (convertParamStringToBool(packet.ParamList[3].Parameter) == false)
  92. {
  93. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.BlockLandResell;
  94. }
  95. int tempMaxAgents = Convert.ToInt16(Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[4].Parameter)));
  96. m_regInfo.estateSettings.maxAgents = (byte)tempMaxAgents;
  97. float tempObjectBonusFactor = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
  98. m_regInfo.estateSettings.objectBonusFactor = tempObjectBonusFactor;
  99. int tempMatureLevel = Convert.ToInt16(Helpers.FieldToUTF8String(packet.ParamList[6].Parameter));
  100. m_regInfo.estateSettings.simAccess = (Simulator.SimAccess)tempMatureLevel;
  101. if (convertParamStringToBool(packet.ParamList[7].Parameter))
  102. {
  103. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.RestrictPushObject;
  104. }
  105. if (convertParamStringToBool(packet.ParamList[8].Parameter))
  106. {
  107. m_regInfo.estateSettings.regionFlags = m_regInfo.estateSettings.regionFlags | Simulator.RegionFlags.AllowParcelChanges;
  108. }
  109. sendRegionInfoPacketToAll();
  110. }
  111. break;
  112. case "texturebase":
  113. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  114. {
  115. string s = Helpers.FieldToUTF8String(block.Parameter);
  116. string[] splitField = s.Split(' ');
  117. if (splitField.Length == 2)
  118. {
  119. LLUUID tempUUID = new LLUUID(splitField[1]);
  120. switch (Convert.ToInt16(splitField[0]))
  121. {
  122. case 0:
  123. m_regInfo.estateSettings.terrainBase0 = tempUUID;
  124. break;
  125. case 1:
  126. m_regInfo.estateSettings.terrainBase1 = tempUUID;
  127. break;
  128. case 2:
  129. m_regInfo.estateSettings.terrainBase2 = tempUUID;
  130. break;
  131. case 3:
  132. m_regInfo.estateSettings.terrainBase3 = tempUUID;
  133. break;
  134. }
  135. }
  136. }
  137. break;
  138. case "texturedetail":
  139. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  140. {
  141. string s = Helpers.FieldToUTF8String(block.Parameter);
  142. string[] splitField = s.Split(' ');
  143. if (splitField.Length == 2)
  144. {
  145. LLUUID tempUUID = new LLUUID(splitField[1]);
  146. switch (Convert.ToInt16(splitField[0]))
  147. {
  148. case 0:
  149. m_regInfo.estateSettings.terrainDetail0 = tempUUID;
  150. break;
  151. case 1:
  152. m_regInfo.estateSettings.terrainDetail1 = tempUUID;
  153. break;
  154. case 2:
  155. m_regInfo.estateSettings.terrainDetail2 = tempUUID;
  156. break;
  157. case 3:
  158. m_regInfo.estateSettings.terrainDetail3 = tempUUID;
  159. break;
  160. }
  161. }
  162. }
  163. break;
  164. case "textureheights":
  165. foreach (EstateOwnerMessagePacket.ParamListBlock block in packet.ParamList)
  166. {
  167. string s = Helpers.FieldToUTF8String(block.Parameter);
  168. string[] splitField = s.Split(' ');
  169. if (splitField.Length == 3)
  170. {
  171. float tempHeightLow = (float)Convert.ToDecimal(splitField[1]);
  172. float tempHeightHigh = (float)Convert.ToDecimal(splitField[2]);
  173. switch (Convert.ToInt16(splitField[0]))
  174. {
  175. case 0:
  176. m_regInfo.estateSettings.terrainStartHeight0 = tempHeightLow;
  177. m_regInfo.estateSettings.terrainHeightRange0 = tempHeightHigh;
  178. break;
  179. case 1:
  180. m_regInfo.estateSettings.terrainStartHeight1 = tempHeightLow;
  181. m_regInfo.estateSettings.terrainHeightRange1 = tempHeightHigh;
  182. break;
  183. case 2:
  184. m_regInfo.estateSettings.terrainStartHeight2 = tempHeightLow;
  185. m_regInfo.estateSettings.terrainHeightRange2 = tempHeightHigh;
  186. break;
  187. case 3:
  188. m_regInfo.estateSettings.terrainStartHeight3 = tempHeightLow;
  189. m_regInfo.estateSettings.terrainHeightRange3 = tempHeightHigh;
  190. break;
  191. }
  192. }
  193. }
  194. break;
  195. case "texturecommit":
  196. sendRegionHandshakeToAll();
  197. break;
  198. case "setregionterrain":
  199. if (packet.ParamList.Length != 9)
  200. {
  201. MainLog.Instance.Error("EstateOwnerMessage: SetRegionTerrain method has a ParamList of invalid length");
  202. }
  203. else
  204. {
  205. m_regInfo.estateSettings.waterHeight = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[0].Parameter));
  206. m_regInfo.estateSettings.terrainRaiseLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[1].Parameter));
  207. m_regInfo.estateSettings.terrainLowerLimit = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[2].Parameter));
  208. m_regInfo.estateSettings.useFixedSun = this.convertParamStringToBool(packet.ParamList[4].Parameter);
  209. m_regInfo.estateSettings.sunHour = (float)Convert.ToDecimal(Helpers.FieldToUTF8String(packet.ParamList[5].Parameter));
  210. sendRegionInfoPacketToAll();
  211. }
  212. break;
  213. default:
  214. MainLog.Instance.Error("EstateOwnerMessage: Unknown method requested\n" + packet.ToString());
  215. break;
  216. }
  217. }
  218. }
  219. public void sendRegionInfoPacketToAll()
  220. {
  221. List<Avatar> avatars = m_world.RequestAvatarList();
  222. for (int i = 0; i < avatars.Count; i++)
  223. {
  224. this.sendRegionInfoPacket(avatars[i].ControllingClient);
  225. }
  226. }
  227. public void sendRegionHandshakeToAll()
  228. {
  229. List<Avatar> avatars = m_world.RequestAvatarList();
  230. for (int i = 0; i < avatars.Count; i++)
  231. {
  232. this.sendRegionHandshake(avatars[i].ControllingClient);
  233. }
  234. }
  235. public void sendRegionInfoPacket(IClientAPI remote_client)
  236. {
  237. Encoding _enc = Encoding.ASCII;
  238. AgentCircuitData circuitData = remote_client.RequestClientInfo();
  239. RegionInfoPacket regionInfoPacket = new RegionInfoPacket();
  240. regionInfoPacket.AgentData.AgentID = circuitData.AgentID;
  241. regionInfoPacket.AgentData.SessionID = circuitData.SessionID;
  242. regionInfoPacket.RegionInfo.BillableFactor = m_regInfo.estateSettings.billableFactor;
  243. regionInfoPacket.RegionInfo.EstateID = m_regInfo.estateSettings.estateID;
  244. regionInfoPacket.RegionInfo.MaxAgents = m_regInfo.estateSettings.maxAgents;
  245. regionInfoPacket.RegionInfo.ObjectBonusFactor = m_regInfo.estateSettings.objectBonusFactor;
  246. regionInfoPacket.RegionInfo.ParentEstateID = m_regInfo.estateSettings.parentEstateID;
  247. regionInfoPacket.RegionInfo.PricePerMeter = m_regInfo.estateSettings.pricePerMeter;
  248. regionInfoPacket.RegionInfo.RedirectGridX = m_regInfo.estateSettings.redirectGridX;
  249. regionInfoPacket.RegionInfo.RedirectGridY = m_regInfo.estateSettings.redirectGridY;
  250. regionInfoPacket.RegionInfo.RegionFlags = (uint)m_regInfo.estateSettings.regionFlags;
  251. regionInfoPacket.RegionInfo.SimAccess = (byte)m_regInfo.estateSettings.simAccess;
  252. regionInfoPacket.RegionInfo.SimName = _enc.GetBytes( m_regInfo.RegionName);
  253. regionInfoPacket.RegionInfo.SunHour = m_regInfo.estateSettings.sunHour;
  254. regionInfoPacket.RegionInfo.TerrainLowerLimit = m_regInfo.estateSettings.terrainLowerLimit;
  255. regionInfoPacket.RegionInfo.TerrainRaiseLimit = m_regInfo.estateSettings.terrainRaiseLimit;
  256. regionInfoPacket.RegionInfo.UseEstateSun = !m_regInfo.estateSettings.useFixedSun;
  257. regionInfoPacket.RegionInfo.WaterHeight = m_regInfo.estateSettings.waterHeight;
  258. remote_client.OutPacket(regionInfoPacket);
  259. }
  260. public void sendRegionHandshake(IClientAPI remoteClient)
  261. {
  262. remoteClient.SendRegionHandshake(m_regInfo);
  263. }
  264. }
  265. }