LandObject.cs 44 KB

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