LandObject.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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. namespace OpenSim.Region.CoreModules.World.Land
  36. {
  37. /// <summary>
  38. /// Keeps track of a specific piece of land's information
  39. /// </summary>
  40. public class LandObject : ILandObject
  41. {
  42. #region Member Variables
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. #pragma warning disable 0429
  45. private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
  46. #pragma warning restore 0429
  47. private bool[,] m_landBitmap = new bool[landArrayMax,landArrayMax];
  48. private int m_lastSeqId = 0;
  49. protected LandData m_landData = new LandData();
  50. protected Scene m_scene;
  51. protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
  52. public bool[,] LandBitmap
  53. {
  54. get { return m_landBitmap; }
  55. set { m_landBitmap = value; }
  56. }
  57. #endregion
  58. #region ILandObject Members
  59. public LandData LandData
  60. {
  61. get { return m_landData; }
  62. set { m_landData = value; }
  63. }
  64. public UUID RegionUUID
  65. {
  66. get { return m_scene.RegionInfo.RegionID; }
  67. }
  68. #region Constructors
  69. public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
  70. {
  71. m_scene = scene;
  72. LandData.OwnerID = owner_id;
  73. if (is_group_owned)
  74. LandData.GroupID = owner_id;
  75. else
  76. LandData.GroupID = UUID.Zero;
  77. LandData.IsGroupOwned = is_group_owned;
  78. }
  79. #endregion
  80. #region Member Functions
  81. #region General Functions
  82. /// <summary>
  83. /// Checks to see if this land object contains a point
  84. /// </summary>
  85. /// <param name="x"></param>
  86. /// <param name="y"></param>
  87. /// <returns>Returns true if the piece of land contains the specified point</returns>
  88. public bool ContainsPoint(int x, int y)
  89. {
  90. if (x >= 0 && y >= 0 && x <= Constants.RegionSize && y <= Constants.RegionSize)
  91. {
  92. return (LandBitmap[x / 4, y / 4] == true);
  93. }
  94. else
  95. {
  96. return false;
  97. }
  98. }
  99. public ILandObject Copy()
  100. {
  101. ILandObject newLand = new LandObject(LandData.OwnerID, LandData.IsGroupOwned, m_scene);
  102. //Place all new variables here!
  103. newLand.LandBitmap = (bool[,]) (LandBitmap.Clone());
  104. newLand.LandData = LandData.Copy();
  105. return newLand;
  106. }
  107. static overrideParcelMaxPrimCountDelegate overrideParcelMaxPrimCount;
  108. static overrideSimulatorMaxPrimCountDelegate overrideSimulatorMaxPrimCount;
  109. public void SetParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  110. {
  111. overrideParcelMaxPrimCount = overrideDel;
  112. }
  113. public void SetSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  114. {
  115. overrideSimulatorMaxPrimCount = overrideDel;
  116. }
  117. public int GetParcelMaxPrimCount(ILandObject thisObject)
  118. {
  119. if (overrideParcelMaxPrimCount != null)
  120. {
  121. return overrideParcelMaxPrimCount(thisObject);
  122. }
  123. else
  124. {
  125. // Normal Calculations
  126. return (int)Math.Round(((float)LandData.Area / 65536.0f) * (float)m_scene.RegionInfo.ObjectCapacity * (float)m_scene.RegionInfo.RegionSettings.ObjectBonus);
  127. }
  128. }
  129. public int GetSimulatorMaxPrimCount(ILandObject thisObject)
  130. {
  131. if (overrideSimulatorMaxPrimCount != null)
  132. {
  133. return overrideSimulatorMaxPrimCount(thisObject);
  134. }
  135. else
  136. {
  137. //Normal Calculations
  138. return m_scene.RegionInfo.ObjectCapacity;
  139. }
  140. }
  141. #endregion
  142. #region Packet Request Handling
  143. public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
  144. {
  145. IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
  146. uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
  147. if (estateModule != null)
  148. regionFlags = estateModule.GetRegionFlags();
  149. // In a perfect world, this would have worked.
  150. //
  151. // if ((landData.Flags & (uint)ParcelFlags.AllowLandmark) != 0)
  152. // regionFlags |= (uint)RegionFlags.AllowLandmark;
  153. // if (landData.OwnerID == remote_client.AgentId)
  154. // regionFlags |= (uint)RegionFlags.AllowSetHome;
  155. int seq_id;
  156. if (snap_selection && (sequence_id == 0))
  157. {
  158. seq_id = m_lastSeqId;
  159. }
  160. else
  161. {
  162. seq_id = sequence_id;
  163. m_lastSeqId = seq_id;
  164. }
  165. remote_client.SendLandProperties(seq_id,
  166. snap_selection, request_result, LandData,
  167. (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
  168. GetParcelMaxPrimCount(this),
  169. GetSimulatorMaxPrimCount(this), regionFlags);
  170. }
  171. public void UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client)
  172. {
  173. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId,this))
  174. {
  175. //Needs later group support
  176. bool snap_selection = false;
  177. LandData newData = LandData.Copy();
  178. if (args.AuthBuyerID != newData.AuthBuyerID || args.SalePrice != newData.SalePrice)
  179. {
  180. if (m_scene.Permissions.CanSellParcel(remote_client.AgentId, this))
  181. {
  182. newData.AuthBuyerID = args.AuthBuyerID;
  183. newData.SalePrice = args.SalePrice;
  184. snap_selection = true;
  185. }
  186. }
  187. newData.Category = args.Category;
  188. newData.Description = args.Desc;
  189. newData.GroupID = args.GroupID;
  190. newData.LandingType = args.LandingType;
  191. newData.MediaAutoScale = args.MediaAutoScale;
  192. newData.MediaID = args.MediaID;
  193. newData.MediaURL = args.MediaURL;
  194. newData.MusicURL = args.MusicURL;
  195. newData.Name = args.Name;
  196. newData.Flags = args.ParcelFlags;
  197. newData.PassHours = args.PassHours;
  198. newData.PassPrice = args.PassPrice;
  199. newData.SnapshotID = args.SnapshotID;
  200. newData.UserLocation = args.UserLocation;
  201. newData.UserLookAt = args.UserLookAt;
  202. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  203. SendLandUpdateToAvatarsOverMe(snap_selection);
  204. }
  205. }
  206. public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
  207. {
  208. LandData newData = LandData.Copy();
  209. newData.OwnerID = avatarID;
  210. newData.GroupID = groupID;
  211. newData.IsGroupOwned = groupOwned;
  212. //newData.auctionID = AuctionID;
  213. newData.ClaimDate = Util.UnixTimeSinceEpoch();
  214. newData.ClaimPrice = claimprice;
  215. newData.SalePrice = 0;
  216. newData.AuthBuyerID = UUID.Zero;
  217. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  218. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  219. SendLandUpdateToAvatarsOverMe(true);
  220. }
  221. public void DeedToGroup(UUID groupID)
  222. {
  223. LandData newData = LandData.Copy();
  224. newData.OwnerID = groupID;
  225. newData.GroupID = groupID;
  226. newData.IsGroupOwned = true;
  227. // Reset show in directory flag on deed
  228. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  229. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  230. SendLandUpdateToAvatarsOverMe(true);
  231. }
  232. public bool IsEitherBannedOrRestricted(UUID avatar)
  233. {
  234. if (IsBannedFromLand(avatar))
  235. {
  236. return true;
  237. }
  238. else if (IsRestrictedFromLand(avatar))
  239. {
  240. return true;
  241. }
  242. return false;
  243. }
  244. public bool IsBannedFromLand(UUID avatar)
  245. {
  246. if ((LandData.Flags & (uint) ParcelFlags.UseBanList) > 0)
  247. {
  248. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  249. entry.AgentID = avatar;
  250. entry.Flags = AccessList.Ban;
  251. entry.Time = new DateTime();
  252. //See if they are on the list, but make sure the owner isn't banned
  253. if (LandData.ParcelAccessList.Contains(entry) && LandData.OwnerID != avatar)
  254. {
  255. //They are banned, so lets send them a notice about this parcel
  256. return true;
  257. }
  258. }
  259. return false;
  260. }
  261. public bool IsRestrictedFromLand(UUID avatar)
  262. {
  263. if ((LandData.Flags & (uint) ParcelFlags.UseAccessList) > 0)
  264. {
  265. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  266. entry.AgentID = avatar;
  267. entry.Flags = AccessList.Access;
  268. entry.Time = new DateTime();
  269. //If they are not on the access list and are not the owner
  270. if (!LandData.ParcelAccessList.Contains(entry) && LandData.OwnerID != avatar)
  271. {
  272. //They are not allowed in this parcel, but not banned, so lets send them a notice about this parcel
  273. return true;
  274. }
  275. }
  276. return false;
  277. }
  278. public void SendLandUpdateToClient(IClientAPI remote_client)
  279. {
  280. SendLandProperties(0, false, 0, remote_client);
  281. }
  282. public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client)
  283. {
  284. SendLandProperties(0, snap_selection, 0, remote_client);
  285. }
  286. public void SendLandUpdateToAvatarsOverMe()
  287. {
  288. SendLandUpdateToAvatarsOverMe(false);
  289. }
  290. public void SendLandUpdateToAvatarsOverMe(bool snap_selection)
  291. {
  292. m_scene.ForEachScenePresence(delegate(ScenePresence avatar)
  293. {
  294. if (avatar.IsChildAgent)
  295. return;
  296. ILandObject over = null;
  297. try
  298. {
  299. over =
  300. m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)Constants.RegionSize - 1)),
  301. Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)Constants.RegionSize - 1)));
  302. }
  303. catch (Exception)
  304. {
  305. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatar.AbsolutePosition.X) + " y: " +
  306. Math.Round(avatar.AbsolutePosition.Y));
  307. }
  308. if (over != null)
  309. {
  310. if (over.LandData.LocalID == LandData.LocalID)
  311. {
  312. if (((over.LandData.Flags & (uint)ParcelFlags.AllowDamage) != 0) &&
  313. m_scene.RegionInfo.RegionSettings.AllowDamage)
  314. avatar.Invulnerable = false;
  315. else
  316. avatar.Invulnerable = true;
  317. SendLandUpdateToClient(snap_selection, avatar.ControllingClient);
  318. }
  319. }
  320. });
  321. }
  322. #endregion
  323. #region AccessList Functions
  324. public List<UUID> CreateAccessListArrayByFlag(AccessList flag)
  325. {
  326. List<UUID> list = new List<UUID>();
  327. foreach (ParcelManager.ParcelAccessEntry entry in LandData.ParcelAccessList)
  328. {
  329. if (entry.Flags == flag)
  330. {
  331. list.Add(entry.AgentID);
  332. }
  333. }
  334. if (list.Count == 0)
  335. {
  336. list.Add(UUID.Zero);
  337. }
  338. return list;
  339. }
  340. public void SendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  341. IClientAPI remote_client)
  342. {
  343. if (flags == (uint) AccessList.Access || flags == (uint) AccessList.Both)
  344. {
  345. List<UUID> avatars = CreateAccessListArrayByFlag(AccessList.Access);
  346. remote_client.SendLandAccessListData(avatars,(uint) AccessList.Access,LandData.LocalID);
  347. }
  348. if (flags == (uint) AccessList.Ban || flags == (uint) AccessList.Both)
  349. {
  350. List<UUID> avatars = CreateAccessListArrayByFlag(AccessList.Ban);
  351. remote_client.SendLandAccessListData(avatars, (uint)AccessList.Ban, LandData.LocalID);
  352. }
  353. }
  354. public void UpdateAccessList(uint flags, List<ParcelManager.ParcelAccessEntry> entries, IClientAPI remote_client)
  355. {
  356. LandData newData = LandData.Copy();
  357. if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
  358. {
  359. entries.Clear();
  360. }
  361. List<ParcelManager.ParcelAccessEntry> toRemove = new List<ParcelManager.ParcelAccessEntry>();
  362. foreach (ParcelManager.ParcelAccessEntry entry in newData.ParcelAccessList)
  363. {
  364. if (entry.Flags == (AccessList)flags)
  365. {
  366. toRemove.Add(entry);
  367. }
  368. }
  369. foreach (ParcelManager.ParcelAccessEntry entry in toRemove)
  370. {
  371. newData.ParcelAccessList.Remove(entry);
  372. }
  373. foreach (ParcelManager.ParcelAccessEntry entry in entries)
  374. {
  375. ParcelManager.ParcelAccessEntry temp = new ParcelManager.ParcelAccessEntry();
  376. temp.AgentID = entry.AgentID;
  377. temp.Time = new DateTime(); //Pointless? Yes.
  378. temp.Flags = (AccessList)flags;
  379. if (!newData.ParcelAccessList.Contains(temp))
  380. {
  381. newData.ParcelAccessList.Add(temp);
  382. }
  383. }
  384. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  385. }
  386. #endregion
  387. #region Update Functions
  388. public void UpdateLandBitmapByteArray()
  389. {
  390. LandData.Bitmap = ConvertLandBitmapToBytes();
  391. }
  392. /// <summary>
  393. /// Update all settings in land such as area, bitmap byte array, etc
  394. /// </summary>
  395. public void ForceUpdateLandInfo()
  396. {
  397. UpdateAABBAndAreaValues();
  398. UpdateLandBitmapByteArray();
  399. }
  400. public void SetLandBitmapFromByteArray()
  401. {
  402. LandBitmap = ConvertBytesToLandBitmap();
  403. }
  404. /// <summary>
  405. /// Updates the AABBMin and AABBMax values after area/shape modification of the land object
  406. /// </summary>
  407. private void UpdateAABBAndAreaValues()
  408. {
  409. int min_x = 64;
  410. int min_y = 64;
  411. int max_x = 0;
  412. int max_y = 0;
  413. int tempArea = 0;
  414. int x, y;
  415. for (x = 0; x < 64; x++)
  416. {
  417. for (y = 0; y < 64; y++)
  418. {
  419. if (LandBitmap[x, y] == true)
  420. {
  421. if (min_x > x) min_x = x;
  422. if (min_y > y) min_y = y;
  423. if (max_x < x) max_x = x;
  424. if (max_y < y) max_y = y;
  425. tempArea += 16; //16sqm peice of land
  426. }
  427. }
  428. }
  429. int tx = min_x * 4;
  430. if (tx > ((int)Constants.RegionSize - 1))
  431. tx = ((int)Constants.RegionSize - 1);
  432. int ty = min_y * 4;
  433. if (ty > ((int)Constants.RegionSize - 1))
  434. ty = ((int)Constants.RegionSize - 1);
  435. LandData.AABBMin =
  436. new Vector3((float) (min_x * 4), (float) (min_y * 4),
  437. (float) m_scene.Heightmap[tx, ty]);
  438. tx = max_x * 4;
  439. if (tx > ((int)Constants.RegionSize - 1))
  440. tx = ((int)Constants.RegionSize - 1);
  441. ty = max_y * 4;
  442. if (ty > ((int)Constants.RegionSize - 1))
  443. ty = ((int)Constants.RegionSize - 1);
  444. LandData.AABBMax =
  445. new Vector3((float) (max_x * 4), (float) (max_y * 4),
  446. (float) m_scene.Heightmap[tx, ty]);
  447. LandData.Area = tempArea;
  448. }
  449. #endregion
  450. #region Land Bitmap Functions
  451. /// <summary>
  452. /// Sets the land's bitmap manually
  453. /// </summary>
  454. /// <param name="bitmap">64x64 block representing where this land is on a map</param>
  455. public void SetLandBitmap(bool[,] bitmap)
  456. {
  457. if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
  458. {
  459. //Throw an exception - The bitmap is not 64x64
  460. //throw new Exception("Error: Invalid Parcel Bitmap");
  461. }
  462. else
  463. {
  464. //Valid: Lets set it
  465. LandBitmap = bitmap;
  466. ForceUpdateLandInfo();
  467. }
  468. }
  469. /// <summary>
  470. /// Gets the land's bitmap manually
  471. /// </summary>
  472. /// <returns></returns>
  473. public bool[,] GetLandBitmap()
  474. {
  475. return LandBitmap;
  476. }
  477. /// <summary>
  478. /// Full sim land object creation
  479. /// </summary>
  480. /// <returns></returns>
  481. public bool[,] BasicFullRegionLandBitmap()
  482. {
  483. return GetSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
  484. }
  485. /// <summary>
  486. /// Used to modify the bitmap between the x and y points. Points use 64 scale
  487. /// </summary>
  488. /// <param name="start_x"></param>
  489. /// <param name="start_y"></param>
  490. /// <param name="end_x"></param>
  491. /// <param name="end_y"></param>
  492. /// <returns></returns>
  493. public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
  494. {
  495. bool[,] tempBitmap = new bool[64,64];
  496. tempBitmap.Initialize();
  497. tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
  498. return tempBitmap;
  499. }
  500. /// <summary>
  501. /// Change a land bitmap at within a square and set those points to a specific value
  502. /// </summary>
  503. /// <param name="land_bitmap"></param>
  504. /// <param name="start_x"></param>
  505. /// <param name="start_y"></param>
  506. /// <param name="end_x"></param>
  507. /// <param name="end_y"></param>
  508. /// <param name="set_value"></param>
  509. /// <returns></returns>
  510. public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  511. bool set_value)
  512. {
  513. if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
  514. {
  515. //Throw an exception - The bitmap is not 64x64
  516. //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
  517. }
  518. int x, y;
  519. for (y = 0; y < 64; y++)
  520. {
  521. for (x = 0; x < 64; x++)
  522. {
  523. if (x >= start_x / 4 && x < end_x / 4
  524. && y >= start_y / 4 && y < end_y / 4)
  525. {
  526. land_bitmap[x, y] = set_value;
  527. }
  528. }
  529. }
  530. return land_bitmap;
  531. }
  532. /// <summary>
  533. /// Join the true values of 2 bitmaps together
  534. /// </summary>
  535. /// <param name="bitmap_base"></param>
  536. /// <param name="bitmap_add"></param>
  537. /// <returns></returns>
  538. public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  539. {
  540. if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
  541. {
  542. //Throw an exception - The bitmap is not 64x64
  543. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
  544. }
  545. if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
  546. {
  547. //Throw an exception - The bitmap is not 64x64
  548. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
  549. }
  550. int x, y;
  551. for (y = 0; y < 64; y++)
  552. {
  553. for (x = 0; x < 64; x++)
  554. {
  555. if (bitmap_add[x, y])
  556. {
  557. bitmap_base[x, y] = true;
  558. }
  559. }
  560. }
  561. return bitmap_base;
  562. }
  563. /// <summary>
  564. /// Converts the land bitmap to a packet friendly byte array
  565. /// </summary>
  566. /// <returns></returns>
  567. private byte[] ConvertLandBitmapToBytes()
  568. {
  569. byte[] tempConvertArr = new byte[512];
  570. byte tempByte = 0;
  571. int x, y, i, byteNum = 0;
  572. i = 0;
  573. for (y = 0; y < 64; y++)
  574. {
  575. for (x = 0; x < 64; x++)
  576. {
  577. tempByte = Convert.ToByte(tempByte | Convert.ToByte(LandBitmap[x, y]) << (i++ % 8));
  578. if (i % 8 == 0)
  579. {
  580. tempConvertArr[byteNum] = tempByte;
  581. tempByte = (byte) 0;
  582. i = 0;
  583. byteNum++;
  584. }
  585. }
  586. }
  587. return tempConvertArr;
  588. }
  589. private bool[,] ConvertBytesToLandBitmap()
  590. {
  591. bool[,] tempConvertMap = new bool[landArrayMax, landArrayMax];
  592. tempConvertMap.Initialize();
  593. byte tempByte = 0;
  594. int x = 0, y = 0, i = 0, bitNum = 0;
  595. for (i = 0; i < 512; i++)
  596. {
  597. tempByte = LandData.Bitmap[i];
  598. for (bitNum = 0; bitNum < 8; bitNum++)
  599. {
  600. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  601. tempConvertMap[x, y] = bit;
  602. x++;
  603. if (x > 63)
  604. {
  605. x = 0;
  606. y++;
  607. }
  608. }
  609. }
  610. return tempConvertMap;
  611. }
  612. #endregion
  613. #region Object Select and Object Owner Listing
  614. public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  615. {
  616. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  617. {
  618. List<uint> resultLocalIDs = new List<uint>();
  619. try
  620. {
  621. lock (primsOverMe)
  622. {
  623. foreach (SceneObjectGroup obj in primsOverMe)
  624. {
  625. if (obj.LocalId > 0)
  626. {
  627. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == LandData.OwnerID)
  628. {
  629. resultLocalIDs.Add(obj.LocalId);
  630. }
  631. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == LandData.GroupID && LandData.GroupID != UUID.Zero)
  632. {
  633. resultLocalIDs.Add(obj.LocalId);
  634. }
  635. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  636. obj.OwnerID != remote_client.AgentId)
  637. {
  638. resultLocalIDs.Add(obj.LocalId);
  639. }
  640. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  641. {
  642. resultLocalIDs.Add(obj.LocalId);
  643. }
  644. }
  645. }
  646. }
  647. } catch (InvalidOperationException)
  648. {
  649. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  650. }
  651. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  652. }
  653. }
  654. /// <summary>
  655. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  656. /// aggreagete details such as the number of prims.
  657. ///
  658. /// </summary>
  659. /// <param name="remote_client">
  660. /// A <see cref="IClientAPI"/>
  661. /// </param>
  662. public void SendLandObjectOwners(IClientAPI remote_client)
  663. {
  664. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  665. {
  666. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  667. List<UUID> groups = new List<UUID>();
  668. lock (primsOverMe)
  669. {
  670. try
  671. {
  672. foreach (SceneObjectGroup obj in primsOverMe)
  673. {
  674. try
  675. {
  676. if (!primCount.ContainsKey(obj.OwnerID))
  677. {
  678. primCount.Add(obj.OwnerID, 0);
  679. }
  680. }
  681. catch (NullReferenceException)
  682. {
  683. m_log.Info("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  684. }
  685. try
  686. {
  687. primCount[obj.OwnerID] += obj.PrimCount;
  688. }
  689. catch (KeyNotFoundException)
  690. {
  691. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  692. }
  693. if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
  694. groups.Add(obj.OwnerID);
  695. }
  696. }
  697. catch (InvalidOperationException)
  698. {
  699. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  700. }
  701. }
  702. remote_client.SendLandObjectOwners(LandData, groups, primCount);
  703. }
  704. }
  705. public Dictionary<UUID, int> GetLandObjectOwners()
  706. {
  707. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  708. lock (primsOverMe)
  709. {
  710. try
  711. {
  712. foreach (SceneObjectGroup obj in primsOverMe)
  713. {
  714. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  715. {
  716. ownersAndCount.Add(obj.OwnerID, 0);
  717. }
  718. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  719. }
  720. }
  721. catch (InvalidOperationException)
  722. {
  723. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  724. }
  725. }
  726. return ownersAndCount;
  727. }
  728. #endregion
  729. #region Object Returning
  730. public void ReturnObject(SceneObjectGroup obj)
  731. {
  732. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  733. objs[0] = obj;
  734. m_scene.returnObjects(objs, obj.OwnerID);
  735. }
  736. public void ReturnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  737. {
  738. Dictionary<UUID,List<SceneObjectGroup>> returns =
  739. new Dictionary<UUID,List<SceneObjectGroup>>();
  740. lock (primsOverMe)
  741. {
  742. if (type == (uint)ObjectReturnType.Owner)
  743. {
  744. foreach (SceneObjectGroup obj in primsOverMe)
  745. {
  746. if (obj.OwnerID == m_landData.OwnerID)
  747. {
  748. if (!returns.ContainsKey(obj.OwnerID))
  749. returns[obj.OwnerID] =
  750. new List<SceneObjectGroup>();
  751. returns[obj.OwnerID].Add(obj);
  752. }
  753. }
  754. }
  755. else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero)
  756. {
  757. foreach (SceneObjectGroup obj in primsOverMe)
  758. {
  759. if (obj.GroupID == m_landData.GroupID)
  760. {
  761. if (!returns.ContainsKey(obj.OwnerID))
  762. returns[obj.OwnerID] =
  763. new List<SceneObjectGroup>();
  764. returns[obj.OwnerID].Add(obj);
  765. }
  766. }
  767. }
  768. else if (type == (uint)ObjectReturnType.Other)
  769. {
  770. foreach (SceneObjectGroup obj in primsOverMe)
  771. {
  772. if (obj.OwnerID != m_landData.OwnerID &&
  773. (obj.GroupID != m_landData.GroupID ||
  774. m_landData.GroupID == UUID.Zero))
  775. {
  776. if (!returns.ContainsKey(obj.OwnerID))
  777. returns[obj.OwnerID] =
  778. new List<SceneObjectGroup>();
  779. returns[obj.OwnerID].Add(obj);
  780. }
  781. }
  782. }
  783. else if (type == (uint)ObjectReturnType.List)
  784. {
  785. List<UUID> ownerlist = new List<UUID>(owners);
  786. foreach (SceneObjectGroup obj in primsOverMe)
  787. {
  788. if (ownerlist.Contains(obj.OwnerID))
  789. {
  790. if (!returns.ContainsKey(obj.OwnerID))
  791. returns[obj.OwnerID] =
  792. new List<SceneObjectGroup>();
  793. returns[obj.OwnerID].Add(obj);
  794. }
  795. }
  796. }
  797. }
  798. foreach (List<SceneObjectGroup> ol in returns.Values)
  799. {
  800. if (m_scene.Permissions.CanReturnObjects(this, remote_client.AgentId, ol))
  801. m_scene.returnObjects(ol.ToArray(), remote_client.AgentId);
  802. }
  803. }
  804. #endregion
  805. #region Object Adding/Removing from Parcel
  806. public void ResetLandPrimCounts()
  807. {
  808. LandData.GroupPrims = 0;
  809. LandData.OwnerPrims = 0;
  810. LandData.OtherPrims = 0;
  811. LandData.SelectedPrims = 0;
  812. lock (primsOverMe)
  813. primsOverMe.Clear();
  814. }
  815. public void AddPrimToCount(SceneObjectGroup obj)
  816. {
  817. UUID prim_owner = obj.OwnerID;
  818. int prim_count = obj.PrimCount;
  819. if (obj.IsSelected)
  820. {
  821. LandData.SelectedPrims += prim_count;
  822. }
  823. else
  824. {
  825. if (prim_owner == LandData.OwnerID)
  826. {
  827. LandData.OwnerPrims += prim_count;
  828. }
  829. else if ((obj.GroupID == LandData.GroupID ||
  830. prim_owner == LandData.GroupID) &&
  831. LandData.GroupID != UUID.Zero)
  832. {
  833. LandData.GroupPrims += prim_count;
  834. }
  835. else
  836. {
  837. LandData.OtherPrims += prim_count;
  838. }
  839. }
  840. lock (primsOverMe)
  841. primsOverMe.Add(obj);
  842. }
  843. public void RemovePrimFromCount(SceneObjectGroup obj)
  844. {
  845. lock (primsOverMe)
  846. {
  847. if (primsOverMe.Contains(obj))
  848. {
  849. UUID prim_owner = obj.OwnerID;
  850. int prim_count = obj.PrimCount;
  851. if (prim_owner == LandData.OwnerID)
  852. {
  853. LandData.OwnerPrims -= prim_count;
  854. }
  855. else if (obj.GroupID == LandData.GroupID ||
  856. prim_owner == LandData.GroupID)
  857. {
  858. LandData.GroupPrims -= prim_count;
  859. }
  860. else
  861. {
  862. LandData.OtherPrims -= prim_count;
  863. }
  864. primsOverMe.Remove(obj);
  865. }
  866. }
  867. }
  868. #endregion
  869. #endregion
  870. #endregion
  871. /// <summary>
  872. /// Set the media url for this land parcel
  873. /// </summary>
  874. /// <param name="url"></param>
  875. public void SetMediaUrl(string url)
  876. {
  877. LandData.MediaURL = url;
  878. SendLandUpdateToAvatarsOverMe();
  879. }
  880. /// <summary>
  881. /// Set the music url for this land parcel
  882. /// </summary>
  883. /// <param name="url"></param>
  884. public void SetMusicUrl(string url)
  885. {
  886. LandData.MusicURL = url;
  887. SendLandUpdateToAvatarsOverMe();
  888. }
  889. }
  890. }