LandObject.cs 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  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 log4net;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. using RegionFlags = OpenMetaverse.RegionFlags;
  36. namespace OpenSim.Region.CoreModules.World.Land
  37. {
  38. /// <summary>
  39. /// Keeps track of a specific piece of land's information
  40. /// </summary>
  41. public class LandObject : ILandObject
  42. {
  43. #region Member Variables
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. #pragma warning disable 0429
  46. private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
  47. #pragma warning restore 0429
  48. private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax];
  49. private int m_lastSeqId = 0;
  50. protected LandData m_landData = new LandData();
  51. protected Scene m_scene;
  52. protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
  53. protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
  54. protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>();
  55. protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds
  56. public bool[,] LandBitmap
  57. {
  58. get { return m_landBitmap; }
  59. set { m_landBitmap = value; }
  60. }
  61. #endregion
  62. public int GetPrimsFree()
  63. {
  64. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  65. int free = GetSimulatorMaxPrimCount() - m_landData.SimwidePrims;
  66. return free;
  67. }
  68. public LandData LandData
  69. {
  70. get { return m_landData; }
  71. set { m_landData = value; }
  72. }
  73. public IPrimCounts PrimCounts { get; set; }
  74. public UUID RegionUUID
  75. {
  76. get { return m_scene.RegionInfo.RegionID; }
  77. }
  78. public Vector3 StartPoint
  79. {
  80. get
  81. {
  82. for (int y = 0; y < landArrayMax; y++)
  83. {
  84. for (int x = 0; x < landArrayMax; x++)
  85. {
  86. if (LandBitmap[x, y])
  87. return new Vector3(x * 4, y * 4, 0);
  88. }
  89. }
  90. return new Vector3(-1, -1, -1);
  91. }
  92. }
  93. public Vector3 EndPoint
  94. {
  95. get
  96. {
  97. for (int y = landArrayMax - 1; y >= 0; y--)
  98. {
  99. for (int x = landArrayMax - 1; x >= 0; x--)
  100. {
  101. if (LandBitmap[x, y])
  102. {
  103. return new Vector3(x * 4 + 4, y * 4 + 4, 0);
  104. }
  105. }
  106. }
  107. return new Vector3(-1, -1, -1);
  108. }
  109. }
  110. #region Constructors
  111. public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
  112. {
  113. m_scene = scene;
  114. LandData.OwnerID = owner_id;
  115. if (is_group_owned)
  116. LandData.GroupID = owner_id;
  117. else
  118. LandData.GroupID = UUID.Zero;
  119. LandData.IsGroupOwned = is_group_owned;
  120. }
  121. #endregion
  122. #region Member Functions
  123. #region General Functions
  124. /// <summary>
  125. /// Checks to see if this land object contains a point
  126. /// </summary>
  127. /// <param name="x"></param>
  128. /// <param name="y"></param>
  129. /// <returns>Returns true if the piece of land contains the specified point</returns>
  130. public bool ContainsPoint(int x, int y)
  131. {
  132. if (x >= 0 && y >= 0 && x < Constants.RegionSize && y < Constants.RegionSize)
  133. {
  134. return (LandBitmap[x / 4, y / 4] == true);
  135. }
  136. else
  137. {
  138. return false;
  139. }
  140. }
  141. public ILandObject Copy()
  142. {
  143. ILandObject newLand = new LandObject(LandData.OwnerID, LandData.IsGroupOwned, m_scene);
  144. //Place all new variables here!
  145. newLand.LandBitmap = (bool[,]) (LandBitmap.Clone());
  146. newLand.LandData = LandData.Copy();
  147. return newLand;
  148. }
  149. static overrideParcelMaxPrimCountDelegate overrideParcelMaxPrimCount;
  150. static overrideSimulatorMaxPrimCountDelegate overrideSimulatorMaxPrimCount;
  151. public void SetParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  152. {
  153. overrideParcelMaxPrimCount = overrideDel;
  154. }
  155. public void SetSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  156. {
  157. overrideSimulatorMaxPrimCount = overrideDel;
  158. }
  159. public int GetParcelMaxPrimCount()
  160. {
  161. if (overrideParcelMaxPrimCount != null)
  162. {
  163. return overrideParcelMaxPrimCount(this);
  164. }
  165. else
  166. {
  167. // Normal Calculations
  168. int parcelMax = (int)(((float)LandData.Area / 65536.0f)
  169. * (float)m_scene.RegionInfo.ObjectCapacity
  170. * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
  171. // TODO: The calculation of ObjectBonus should be refactored. It does still not work in the same manner as SL!
  172. return parcelMax;
  173. }
  174. }
  175. public int GetSimulatorMaxPrimCount()
  176. {
  177. if (overrideSimulatorMaxPrimCount != null)
  178. {
  179. return overrideSimulatorMaxPrimCount(this);
  180. }
  181. else
  182. {
  183. //Normal Calculations
  184. int simMax = (int)(((float)LandData.SimwideArea / 65536.0f)
  185. * (float)m_scene.RegionInfo.ObjectCapacity);
  186. return simMax;
  187. }
  188. }
  189. #endregion
  190. #region Packet Request Handling
  191. public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
  192. {
  193. IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
  194. uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
  195. if (estateModule != null)
  196. regionFlags = estateModule.GetRegionFlags();
  197. int seq_id;
  198. if (snap_selection && (sequence_id == 0))
  199. {
  200. seq_id = m_lastSeqId;
  201. }
  202. else
  203. {
  204. seq_id = sequence_id;
  205. m_lastSeqId = seq_id;
  206. }
  207. remote_client.SendLandProperties(seq_id,
  208. snap_selection, request_result, this,
  209. (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
  210. GetParcelMaxPrimCount(),
  211. GetSimulatorMaxPrimCount(), regionFlags);
  212. }
  213. public void UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client)
  214. {
  215. //Needs later group support
  216. bool snap_selection = false;
  217. LandData newData = LandData.Copy();
  218. uint allowedDelta = 0;
  219. // These two are always blocked as no client can set them anyway
  220. // ParcelFlags.ForSaleObjects
  221. // ParcelFlags.LindenHome
  222. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
  223. {
  224. allowedDelta |= (uint)(ParcelFlags.AllowLandmark |
  225. ParcelFlags.AllowTerraform |
  226. ParcelFlags.AllowDamage |
  227. ParcelFlags.CreateObjects |
  228. ParcelFlags.RestrictPushObject |
  229. ParcelFlags.AllowOtherScripts |
  230. ParcelFlags.AllowGroupScripts |
  231. ParcelFlags.CreateGroupObjects |
  232. ParcelFlags.AllowAPrimitiveEntry |
  233. ParcelFlags.AllowGroupObjectEntry |
  234. ParcelFlags.AllowFly);
  235. }
  236. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandSetSale))
  237. {
  238. if (args.AuthBuyerID != newData.AuthBuyerID ||
  239. args.SalePrice != newData.SalePrice)
  240. {
  241. snap_selection = true;
  242. }
  243. newData.AuthBuyerID = args.AuthBuyerID;
  244. newData.SalePrice = args.SalePrice;
  245. if (!LandData.IsGroupOwned)
  246. {
  247. newData.GroupID = args.GroupID;
  248. allowedDelta |= (uint)(ParcelFlags.AllowDeedToGroup |
  249. ParcelFlags.ContributeWithDeed |
  250. ParcelFlags.SellParcelObjects);
  251. }
  252. allowedDelta |= (uint)ParcelFlags.ForSale;
  253. }
  254. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.FindPlaces))
  255. {
  256. newData.Category = args.Category;
  257. allowedDelta |= (uint)(ParcelFlags.ShowDirectory |
  258. ParcelFlags.AllowPublish |
  259. ParcelFlags.MaturePublish);
  260. }
  261. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandChangeIdentity))
  262. {
  263. newData.Description = args.Desc;
  264. newData.Name = args.Name;
  265. newData.SnapshotID = args.SnapshotID;
  266. }
  267. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.SetLandingPoint))
  268. {
  269. newData.LandingType = args.LandingType;
  270. newData.UserLocation = args.UserLocation;
  271. newData.UserLookAt = args.UserLookAt;
  272. }
  273. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.ChangeMedia))
  274. {
  275. newData.MediaAutoScale = args.MediaAutoScale;
  276. newData.MediaID = args.MediaID;
  277. newData.MediaURL = args.MediaURL;
  278. newData.MusicURL = args.MusicURL;
  279. newData.MediaType = args.MediaType;
  280. newData.MediaDescription = args.MediaDescription;
  281. newData.MediaWidth = args.MediaWidth;
  282. newData.MediaHeight = args.MediaHeight;
  283. newData.MediaLoop = args.MediaLoop;
  284. newData.ObscureMusic = args.ObscureMusic;
  285. newData.ObscureMedia = args.ObscureMedia;
  286. allowedDelta |= (uint)(ParcelFlags.SoundLocal |
  287. ParcelFlags.UrlWebPage |
  288. ParcelFlags.UrlRawHtml |
  289. ParcelFlags.AllowVoiceChat |
  290. ParcelFlags.UseEstateVoiceChan);
  291. }
  292. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandManagePasses))
  293. {
  294. newData.PassHours = args.PassHours;
  295. newData.PassPrice = args.PassPrice;
  296. allowedDelta |= (uint)ParcelFlags.UsePassList;
  297. }
  298. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageAllowed))
  299. {
  300. allowedDelta |= (uint)(ParcelFlags.UseAccessGroup |
  301. ParcelFlags.UseAccessList);
  302. }
  303. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageBanned))
  304. {
  305. allowedDelta |= (uint)(ParcelFlags.UseBanList |
  306. ParcelFlags.DenyAnonymous |
  307. ParcelFlags.DenyAgeUnverified);
  308. }
  309. uint preserve = LandData.Flags & ~allowedDelta;
  310. newData.Flags = preserve | (args.ParcelFlags & allowedDelta);
  311. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  312. SendLandUpdateToAvatarsOverMe(snap_selection);
  313. }
  314. public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
  315. {
  316. LandData newData = LandData.Copy();
  317. newData.OwnerID = avatarID;
  318. newData.GroupID = groupID;
  319. newData.IsGroupOwned = groupOwned;
  320. //newData.auctionID = AuctionID;
  321. newData.ClaimDate = Util.UnixTimeSinceEpoch();
  322. newData.ClaimPrice = claimprice;
  323. newData.SalePrice = 0;
  324. newData.AuthBuyerID = UUID.Zero;
  325. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  326. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  327. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  328. SendLandUpdateToAvatarsOverMe(true);
  329. }
  330. public void DeedToGroup(UUID groupID)
  331. {
  332. LandData newData = LandData.Copy();
  333. newData.OwnerID = groupID;
  334. newData.GroupID = groupID;
  335. newData.IsGroupOwned = true;
  336. // Reset show in directory flag on deed
  337. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  338. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  339. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  340. SendLandUpdateToAvatarsOverMe(true);
  341. }
  342. public bool IsEitherBannedOrRestricted(UUID avatar)
  343. {
  344. if (IsBannedFromLand(avatar))
  345. {
  346. return true;
  347. }
  348. else if (IsRestrictedFromLand(avatar))
  349. {
  350. return true;
  351. }
  352. return false;
  353. }
  354. public bool CanBeOnThisLand(UUID avatar, float posHeight)
  355. {
  356. if (posHeight < LandChannel.BAN_LINE_SAFETY_HIEGHT && IsBannedFromLand(avatar))
  357. {
  358. return false;
  359. }
  360. else if (IsRestrictedFromLand(avatar))
  361. {
  362. return false;
  363. }
  364. return true;
  365. }
  366. public bool HasGroupAccess(UUID avatar)
  367. {
  368. if (LandData.GroupID != UUID.Zero && (LandData.Flags & (uint)ParcelFlags.UseAccessGroup) == (uint)ParcelFlags.UseAccessGroup)
  369. {
  370. ScenePresence sp;
  371. if (!m_scene.TryGetScenePresence(avatar, out sp))
  372. {
  373. bool isMember;
  374. if (m_groupMemberCache.TryGetValue(avatar, out isMember))
  375. {
  376. m_groupMemberCache.Update(avatar, isMember, m_groupMemberCacheTimeout);
  377. return isMember;
  378. }
  379. IGroupsModule groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
  380. if (groupsModule == null)
  381. return false;
  382. GroupMembershipData[] membership = groupsModule.GetMembershipData(avatar);
  383. if (membership == null || membership.Length == 0)
  384. {
  385. m_groupMemberCache.Add(avatar, false, m_groupMemberCacheTimeout);
  386. return false;
  387. }
  388. foreach (GroupMembershipData d in membership)
  389. {
  390. if (d.GroupID == LandData.GroupID)
  391. {
  392. m_groupMemberCache.Add(avatar, true, m_groupMemberCacheTimeout);
  393. return true;
  394. }
  395. }
  396. m_groupMemberCache.Add(avatar, false, m_groupMemberCacheTimeout);
  397. return false;
  398. }
  399. return sp.ControllingClient.IsGroupMember(LandData.GroupID);
  400. }
  401. return false;
  402. }
  403. public bool IsBannedFromLand(UUID avatar)
  404. {
  405. ExpireAccessList();
  406. if (m_scene.Permissions.IsAdministrator(avatar))
  407. return false;
  408. if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
  409. return false;
  410. if (avatar == LandData.OwnerID)
  411. return false;
  412. if ((LandData.Flags & (uint) ParcelFlags.UseBanList) > 0)
  413. {
  414. if (LandData.ParcelAccessList.FindIndex(
  415. delegate(LandAccessEntry e)
  416. {
  417. if (e.AgentID == avatar && e.Flags == AccessList.Ban)
  418. return true;
  419. return false;
  420. }) != -1)
  421. {
  422. return true;
  423. }
  424. }
  425. return false;
  426. }
  427. public bool IsRestrictedFromLand(UUID avatar)
  428. {
  429. if ((LandData.Flags & (uint) ParcelFlags.UseAccessList) == 0)
  430. return false;
  431. if (m_scene.Permissions.IsAdministrator(avatar))
  432. return false;
  433. if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
  434. return false;
  435. if (avatar == LandData.OwnerID)
  436. return false;
  437. if (HasGroupAccess(avatar))
  438. return false;
  439. return !IsInLandAccessList(avatar);
  440. }
  441. public bool IsInLandAccessList(UUID avatar)
  442. {
  443. ExpireAccessList();
  444. if (LandData.ParcelAccessList.FindIndex(
  445. delegate(LandAccessEntry e)
  446. {
  447. if (e.AgentID == avatar && e.Flags == AccessList.Access)
  448. return true;
  449. return false;
  450. }) == -1)
  451. {
  452. return false;
  453. }
  454. return true;
  455. }
  456. public void SendLandUpdateToClient(IClientAPI remote_client)
  457. {
  458. SendLandProperties(0, false, 0, remote_client);
  459. }
  460. public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client)
  461. {
  462. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  463. SendLandProperties(0, snap_selection, 0, remote_client);
  464. }
  465. public void SendLandUpdateToAvatarsOverMe()
  466. {
  467. SendLandUpdateToAvatarsOverMe(false);
  468. }
  469. public void SendLandUpdateToAvatarsOverMe(bool snap_selection)
  470. {
  471. m_scene.ForEachRootScenePresence(delegate(ScenePresence avatar)
  472. {
  473. ILandObject over = null;
  474. try
  475. {
  476. over =
  477. m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)),
  478. Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1)));
  479. }
  480. catch (Exception)
  481. {
  482. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatar.AbsolutePosition.X) + " y: " +
  483. Math.Round(avatar.AbsolutePosition.Y));
  484. }
  485. if (over != null)
  486. {
  487. if (over.LandData.LocalID == LandData.LocalID)
  488. {
  489. if (((over.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) &&
  490. m_scene.RegionInfo.RegionSettings.AllowDamage)
  491. avatar.Invulnerable = false;
  492. else
  493. avatar.Invulnerable = true;
  494. SendLandUpdateToClient(snap_selection, avatar.ControllingClient);
  495. }
  496. }
  497. });
  498. }
  499. #endregion
  500. #region AccessList Functions
  501. public List<LandAccessEntry> CreateAccessListArrayByFlag(AccessList flag)
  502. {
  503. ExpireAccessList();
  504. List<LandAccessEntry> list = new List<LandAccessEntry>();
  505. foreach (LandAccessEntry entry in LandData.ParcelAccessList)
  506. {
  507. if (entry.Flags == flag)
  508. list.Add(entry);
  509. }
  510. if (list.Count == 0)
  511. {
  512. LandAccessEntry e = new LandAccessEntry();
  513. e.AgentID = UUID.Zero;
  514. e.Flags = 0;
  515. e.Expires = 0;
  516. list.Add(e);
  517. }
  518. return list;
  519. }
  520. public void SendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  521. IClientAPI remote_client)
  522. {
  523. if (flags == (uint) AccessList.Access || flags == (uint) AccessList.Both)
  524. {
  525. List<LandAccessEntry> accessEntries = CreateAccessListArrayByFlag(AccessList.Access);
  526. remote_client.SendLandAccessListData(accessEntries,(uint) AccessList.Access,LandData.LocalID);
  527. }
  528. if (flags == (uint) AccessList.Ban || flags == (uint) AccessList.Both)
  529. {
  530. List<LandAccessEntry> accessEntries = CreateAccessListArrayByFlag(AccessList.Ban);
  531. remote_client.SendLandAccessListData(accessEntries, (uint)AccessList.Ban, LandData.LocalID);
  532. }
  533. }
  534. public void UpdateAccessList(uint flags, UUID transactionID,
  535. int sequenceID, int sections,
  536. List<LandAccessEntry> entries,
  537. IClientAPI remote_client)
  538. {
  539. LandData newData = LandData.Copy();
  540. if ((!m_listTransactions.ContainsKey(flags)) ||
  541. m_listTransactions[flags] != transactionID)
  542. {
  543. m_listTransactions[flags] = transactionID;
  544. List<LandAccessEntry> toRemove =
  545. new List<LandAccessEntry>();
  546. foreach (LandAccessEntry entry in newData.ParcelAccessList)
  547. {
  548. if (entry.Flags == (AccessList)flags)
  549. toRemove.Add(entry);
  550. }
  551. foreach (LandAccessEntry entry in toRemove)
  552. {
  553. newData.ParcelAccessList.Remove(entry);
  554. }
  555. // Checked here because this will always be the first
  556. // and only packet in a transaction
  557. if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
  558. {
  559. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  560. return;
  561. }
  562. }
  563. foreach (LandAccessEntry entry in entries)
  564. {
  565. LandAccessEntry temp =
  566. new LandAccessEntry();
  567. temp.AgentID = entry.AgentID;
  568. temp.Expires = entry.Expires;
  569. temp.Flags = (AccessList)flags;
  570. newData.ParcelAccessList.Add(temp);
  571. }
  572. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  573. }
  574. #endregion
  575. #region Update Functions
  576. public void UpdateLandBitmapByteArray()
  577. {
  578. LandData.Bitmap = ConvertLandBitmapToBytes();
  579. }
  580. /// <summary>
  581. /// Update all settings in land such as area, bitmap byte array, etc
  582. /// </summary>
  583. public void ForceUpdateLandInfo()
  584. {
  585. UpdateAABBAndAreaValues();
  586. UpdateLandBitmapByteArray();
  587. }
  588. public void SetLandBitmapFromByteArray()
  589. {
  590. LandBitmap = ConvertBytesToLandBitmap();
  591. }
  592. /// <summary>
  593. /// Updates the AABBMin and AABBMax values after area/shape modification of the land object
  594. /// </summary>
  595. private void UpdateAABBAndAreaValues()
  596. {
  597. int min_x = 64;
  598. int min_y = 64;
  599. int max_x = 0;
  600. int max_y = 0;
  601. int tempArea = 0;
  602. int x, y;
  603. for (x = 0; x < 64; x++)
  604. {
  605. for (y = 0; y < 64; y++)
  606. {
  607. if (LandBitmap[x, y] == true)
  608. {
  609. if (min_x > x) min_x = x;
  610. if (min_y > y) min_y = y;
  611. if (max_x < x) max_x = x;
  612. if (max_y < y) max_y = y;
  613. tempArea += 16; //16sqm peice of land
  614. }
  615. }
  616. }
  617. int tx = min_x * 4;
  618. if (tx > ((int)Constants.RegionSize - 1))
  619. tx = ((int)Constants.RegionSize - 1);
  620. int ty = min_y * 4;
  621. if (ty > ((int)Constants.RegionSize - 1))
  622. ty = ((int)Constants.RegionSize - 1);
  623. LandData.AABBMin =
  624. new Vector3(
  625. (float)(min_x * 4), (float)(min_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
  626. tx = max_x * 4;
  627. if (tx > ((int)Constants.RegionSize - 1))
  628. tx = ((int)Constants.RegionSize - 1);
  629. ty = max_y * 4;
  630. if (ty > ((int)Constants.RegionSize - 1))
  631. ty = ((int)Constants.RegionSize - 1);
  632. LandData.AABBMax
  633. = new Vector3(
  634. (float)(max_x * 4), (float)(max_y * 4), m_scene != null ? (float)m_scene.Heightmap[tx, ty] : 0);
  635. LandData.Area = tempArea;
  636. }
  637. #endregion
  638. #region Land Bitmap Functions
  639. /// <summary>
  640. /// Sets the land's bitmap manually
  641. /// </summary>
  642. /// <param name="bitmap">64x64 block representing where this land is on a map</param>
  643. public void SetLandBitmap(bool[,] bitmap)
  644. {
  645. if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
  646. {
  647. //Throw an exception - The bitmap is not 64x64
  648. //throw new Exception("Error: Invalid Parcel Bitmap");
  649. }
  650. else
  651. {
  652. //Valid: Lets set it
  653. LandBitmap = bitmap;
  654. ForceUpdateLandInfo();
  655. }
  656. }
  657. /// <summary>
  658. /// Gets the land's bitmap manually
  659. /// </summary>
  660. /// <returns></returns>
  661. public bool[,] GetLandBitmap()
  662. {
  663. return LandBitmap;
  664. }
  665. public bool[,] BasicFullRegionLandBitmap()
  666. {
  667. return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
  668. }
  669. public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
  670. {
  671. bool[,] tempBitmap = new bool[64,64];
  672. tempBitmap.Initialize();
  673. tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
  674. return tempBitmap;
  675. }
  676. /// <summary>
  677. /// Change a land bitmap at within a square and set those points to a specific value
  678. /// </summary>
  679. /// <param name="land_bitmap"></param>
  680. /// <param name="start_x"></param>
  681. /// <param name="start_y"></param>
  682. /// <param name="end_x"></param>
  683. /// <param name="end_y"></param>
  684. /// <param name="set_value"></param>
  685. /// <returns></returns>
  686. public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  687. bool set_value)
  688. {
  689. if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
  690. {
  691. //Throw an exception - The bitmap is not 64x64
  692. //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
  693. }
  694. int x, y;
  695. for (y = 0; y < 64; y++)
  696. {
  697. for (x = 0; x < 64; x++)
  698. {
  699. if (x >= start_x / 4 && x < end_x / 4
  700. && y >= start_y / 4 && y < end_y / 4)
  701. {
  702. land_bitmap[x, y] = set_value;
  703. }
  704. }
  705. }
  706. return land_bitmap;
  707. }
  708. /// <summary>
  709. /// Join the true values of 2 bitmaps together
  710. /// </summary>
  711. /// <param name="bitmap_base"></param>
  712. /// <param name="bitmap_add"></param>
  713. /// <returns></returns>
  714. public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  715. {
  716. if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
  717. {
  718. //Throw an exception - The bitmap is not 64x64
  719. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
  720. }
  721. if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
  722. {
  723. //Throw an exception - The bitmap is not 64x64
  724. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
  725. }
  726. int x, y;
  727. for (y = 0; y < 64; y++)
  728. {
  729. for (x = 0; x < 64; x++)
  730. {
  731. if (bitmap_add[x, y])
  732. {
  733. bitmap_base[x, y] = true;
  734. }
  735. }
  736. }
  737. return bitmap_base;
  738. }
  739. /// <summary>
  740. /// Converts the land bitmap to a packet friendly byte array
  741. /// </summary>
  742. /// <returns></returns>
  743. private byte[] ConvertLandBitmapToBytes()
  744. {
  745. byte[] tempConvertArr = new byte[512];
  746. byte tempByte = 0;
  747. int x, y, i, byteNum = 0;
  748. i = 0;
  749. for (y = 0; y < 64; y++)
  750. {
  751. for (x = 0; x < 64; x++)
  752. {
  753. tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
  754. if (i % 8 == 0)
  755. {
  756. tempConvertArr[byteNum] = tempByte;
  757. tempByte = (byte) 0;
  758. i = 0;
  759. byteNum++;
  760. }
  761. }
  762. }
  763. return tempConvertArr;
  764. }
  765. private bool[,] ConvertBytesToLandBitmap()
  766. {
  767. bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax];
  768. tempConvertMap.Initialize();
  769. byte tempByte = 0;
  770. int x = 0, y = 0, i = 0, bitNum = 0;
  771. for (i = 0; i < 512; i++)
  772. {
  773. tempByte = LandData.Bitmap[i];
  774. for (bitNum = 0; bitNum < 8; bitNum++)
  775. {
  776. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  777. tempConvertMap[x, y] = bit;
  778. x++;
  779. if (x > 63)
  780. {
  781. x = 0;
  782. y++;
  783. }
  784. }
  785. }
  786. return tempConvertMap;
  787. }
  788. #endregion
  789. #region Object Select and Object Owner Listing
  790. public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  791. {
  792. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
  793. {
  794. List<uint> resultLocalIDs = new List<uint>();
  795. try
  796. {
  797. lock (primsOverMe)
  798. {
  799. foreach (SceneObjectGroup obj in primsOverMe)
  800. {
  801. if (obj.LocalId > 0)
  802. {
  803. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == LandData.OwnerID)
  804. {
  805. resultLocalIDs.Add(obj.LocalId);
  806. }
  807. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == LandData.GroupID && LandData.GroupID != UUID.Zero)
  808. {
  809. resultLocalIDs.Add(obj.LocalId);
  810. }
  811. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  812. obj.OwnerID != remote_client.AgentId)
  813. {
  814. resultLocalIDs.Add(obj.LocalId);
  815. }
  816. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  817. {
  818. resultLocalIDs.Add(obj.LocalId);
  819. }
  820. }
  821. }
  822. }
  823. } catch (InvalidOperationException)
  824. {
  825. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  826. }
  827. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  828. }
  829. }
  830. /// <summary>
  831. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  832. /// aggreagete details such as the number of prims.
  833. ///
  834. /// </summary>
  835. /// <param name="remote_client">
  836. /// A <see cref="IClientAPI"/>
  837. /// </param>
  838. public void SendLandObjectOwners(IClientAPI remote_client)
  839. {
  840. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions))
  841. {
  842. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  843. List<UUID> groups = new List<UUID>();
  844. lock (primsOverMe)
  845. {
  846. // m_log.DebugFormat(
  847. // "[LAND OBJECT]: Request for SendLandObjectOwners() from {0} with {1} known prims on region",
  848. // remote_client.Name, primsOverMe.Count);
  849. try
  850. {
  851. foreach (SceneObjectGroup obj in primsOverMe)
  852. {
  853. try
  854. {
  855. if (!primCount.ContainsKey(obj.OwnerID))
  856. {
  857. primCount.Add(obj.OwnerID, 0);
  858. }
  859. }
  860. catch (NullReferenceException)
  861. {
  862. m_log.Error("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  863. }
  864. try
  865. {
  866. primCount[obj.OwnerID] += obj.PrimCount;
  867. }
  868. catch (KeyNotFoundException)
  869. {
  870. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  871. }
  872. if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
  873. groups.Add(obj.OwnerID);
  874. }
  875. }
  876. catch (InvalidOperationException)
  877. {
  878. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  879. }
  880. }
  881. remote_client.SendLandObjectOwners(LandData, groups, primCount);
  882. }
  883. }
  884. public Dictionary<UUID, int> GetLandObjectOwners()
  885. {
  886. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  887. lock (primsOverMe)
  888. {
  889. try
  890. {
  891. foreach (SceneObjectGroup obj in primsOverMe)
  892. {
  893. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  894. {
  895. ownersAndCount.Add(obj.OwnerID, 0);
  896. }
  897. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  898. }
  899. }
  900. catch (InvalidOperationException)
  901. {
  902. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  903. }
  904. }
  905. return ownersAndCount;
  906. }
  907. #endregion
  908. #region Object Returning
  909. public void ReturnObject(SceneObjectGroup obj)
  910. {
  911. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  912. objs[0] = obj;
  913. m_scene.returnObjects(objs, obj.OwnerID);
  914. }
  915. public void ReturnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  916. {
  917. // m_log.DebugFormat(
  918. // "[LAND OBJECT]: Request to return objects in {0} from {1}", LandData.Name, remote_client.Name);
  919. Dictionary<UUID,List<SceneObjectGroup>> returns = new Dictionary<UUID,List<SceneObjectGroup>>();
  920. lock (primsOverMe)
  921. {
  922. if (type == (uint)ObjectReturnType.Owner)
  923. {
  924. foreach (SceneObjectGroup obj in primsOverMe)
  925. {
  926. if (obj.OwnerID == m_landData.OwnerID)
  927. {
  928. if (!returns.ContainsKey(obj.OwnerID))
  929. returns[obj.OwnerID] =
  930. new List<SceneObjectGroup>();
  931. returns[obj.OwnerID].Add(obj);
  932. }
  933. }
  934. }
  935. else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero)
  936. {
  937. foreach (SceneObjectGroup obj in primsOverMe)
  938. {
  939. if (obj.GroupID == m_landData.GroupID)
  940. {
  941. if (!returns.ContainsKey(obj.OwnerID))
  942. returns[obj.OwnerID] =
  943. new List<SceneObjectGroup>();
  944. returns[obj.OwnerID].Add(obj);
  945. }
  946. }
  947. }
  948. else if (type == (uint)ObjectReturnType.Other)
  949. {
  950. foreach (SceneObjectGroup obj in primsOverMe)
  951. {
  952. if (obj.OwnerID != m_landData.OwnerID &&
  953. (obj.GroupID != m_landData.GroupID ||
  954. m_landData.GroupID == UUID.Zero))
  955. {
  956. if (!returns.ContainsKey(obj.OwnerID))
  957. returns[obj.OwnerID] =
  958. new List<SceneObjectGroup>();
  959. returns[obj.OwnerID].Add(obj);
  960. }
  961. }
  962. }
  963. else if (type == (uint)ObjectReturnType.List)
  964. {
  965. List<UUID> ownerlist = new List<UUID>(owners);
  966. foreach (SceneObjectGroup obj in primsOverMe)
  967. {
  968. if (ownerlist.Contains(obj.OwnerID))
  969. {
  970. if (!returns.ContainsKey(obj.OwnerID))
  971. returns[obj.OwnerID] =
  972. new List<SceneObjectGroup>();
  973. returns[obj.OwnerID].Add(obj);
  974. }
  975. }
  976. }
  977. }
  978. foreach (List<SceneObjectGroup> ol in returns.Values)
  979. {
  980. if (m_scene.Permissions.CanReturnObjects(this, remote_client.AgentId, ol))
  981. m_scene.returnObjects(ol.ToArray(), remote_client.AgentId);
  982. }
  983. }
  984. #endregion
  985. #region Object Adding/Removing from Parcel
  986. public void ResetOverMeRecord()
  987. {
  988. lock (primsOverMe)
  989. primsOverMe.Clear();
  990. }
  991. public void AddPrimOverMe(SceneObjectGroup obj)
  992. {
  993. // m_log.DebugFormat("[LAND OBJECT]: Adding scene object {0} {1} over {2}", obj.Name, obj.LocalId, LandData.Name);
  994. lock (primsOverMe)
  995. primsOverMe.Add(obj);
  996. }
  997. public void RemovePrimFromOverMe(SceneObjectGroup obj)
  998. {
  999. // m_log.DebugFormat("[LAND OBJECT]: Removing scene object {0} {1} from over {2}", obj.Name, obj.LocalId, LandData.Name);
  1000. lock (primsOverMe)
  1001. primsOverMe.Remove(obj);
  1002. }
  1003. #endregion
  1004. /// <summary>
  1005. /// Set the media url for this land parcel
  1006. /// </summary>
  1007. /// <param name="url"></param>
  1008. public void SetMediaUrl(string url)
  1009. {
  1010. LandData.MediaURL = url;
  1011. SendLandUpdateToAvatarsOverMe();
  1012. }
  1013. /// <summary>
  1014. /// Set the music url for this land parcel
  1015. /// </summary>
  1016. /// <param name="url"></param>
  1017. public void SetMusicUrl(string url)
  1018. {
  1019. LandData.MusicURL = url;
  1020. SendLandUpdateToAvatarsOverMe();
  1021. }
  1022. /// <summary>
  1023. /// Get the music url for this land parcel
  1024. /// </summary>
  1025. /// <returns>The music url.</returns>
  1026. public string GetMusicUrl()
  1027. {
  1028. return LandData.MusicURL;
  1029. }
  1030. #endregion
  1031. private void ExpireAccessList()
  1032. {
  1033. List<LandAccessEntry> delete = new List<LandAccessEntry>();
  1034. foreach (LandAccessEntry entry in LandData.ParcelAccessList)
  1035. {
  1036. if (entry.Expires != 0 && entry.Expires < Util.UnixTimeSinceEpoch())
  1037. delete.Add(entry);
  1038. }
  1039. foreach (LandAccessEntry entry in delete)
  1040. LandData.ParcelAccessList.Remove(entry);
  1041. if (delete.Count > 0)
  1042. m_scene.EventManager.TriggerLandObjectUpdated((uint)LandData.LocalID, this);
  1043. }
  1044. }
  1045. }