LandObject.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  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 OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Reflection;
  30. using OpenMetaverse;
  31. using log4net;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Environment.Interfaces;
  34. using OpenSim.Region.Environment.Scenes;
  35. namespace OpenSim.Region.Environment.Modules.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. private bool[,] m_landBitmap = new bool[64,64];
  45. protected LandData m_landData = new LandData();
  46. protected Scene m_scene;
  47. protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
  48. public bool[,] landBitmap
  49. {
  50. get { return m_landBitmap; }
  51. set { m_landBitmap = value; }
  52. }
  53. #endregion
  54. #region ILandObject Members
  55. public LandData landData
  56. {
  57. get { return m_landData; }
  58. set { m_landData = value; }
  59. }
  60. public UUID regionUUID
  61. {
  62. get { return m_scene.RegionInfo.RegionID; }
  63. }
  64. #region Constructors
  65. public LandObject(UUID owner_id, bool is_group_owned, Scene scene)
  66. {
  67. m_scene = scene;
  68. landData.OwnerID = owner_id;
  69. landData.IsGroupOwned = is_group_owned;
  70. }
  71. #endregion
  72. #region Member Functions
  73. #region General Functions
  74. /// <summary>
  75. /// Checks to see if this land object contains a point
  76. /// </summary>
  77. /// <param name="x"></param>
  78. /// <param name="y"></param>
  79. /// <returns>Returns true if the piece of land contains the specified point</returns>
  80. public bool containsPoint(int x, int y)
  81. {
  82. if (x >= 0 && y >= 0 && x <= Constants.RegionSize && x <= Constants.RegionSize)
  83. {
  84. return (landBitmap[x / 4, y / 4] == true);
  85. }
  86. else
  87. {
  88. return false;
  89. }
  90. }
  91. public ILandObject Copy()
  92. {
  93. ILandObject newLand = new LandObject(landData.OwnerID, landData.IsGroupOwned, m_scene);
  94. //Place all new variables here!
  95. newLand.landBitmap = (bool[,]) (landBitmap.Clone());
  96. newLand.landData = landData.Copy();
  97. return newLand;
  98. }
  99. static overrideParcelMaxPrimCountDelegate overrideParcelMaxPrimCount;
  100. static overrideSimulatorMaxPrimCountDelegate overrideSimulatorMaxPrimCount;
  101. public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  102. {
  103. overrideParcelMaxPrimCount = overrideDel;
  104. }
  105. public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  106. {
  107. overrideSimulatorMaxPrimCount = overrideDel;
  108. }
  109. public int getParcelMaxPrimCount(ILandObject thisObject)
  110. {
  111. if (overrideParcelMaxPrimCount != null)
  112. {
  113. return overrideParcelMaxPrimCount(thisObject);
  114. }
  115. else
  116. {
  117. //Normal Calculations
  118. return Convert.ToInt32(
  119. Math.Round((Convert.ToDecimal(landData.Area) / Convert.ToDecimal(65536)) * m_scene.objectCapacity *
  120. Convert.ToDecimal(m_scene.RegionInfo.RegionSettings.ObjectBonus))); ;
  121. }
  122. }
  123. public int getSimulatorMaxPrimCount(ILandObject thisObject)
  124. {
  125. if (overrideSimulatorMaxPrimCount != null)
  126. {
  127. return overrideSimulatorMaxPrimCount(thisObject);
  128. }
  129. else
  130. {
  131. //Normal Calculations
  132. return m_scene.objectCapacity;
  133. }
  134. }
  135. #endregion
  136. #region Packet Request Handling
  137. public void sendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
  138. {
  139. IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
  140. uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
  141. if (estateModule != null)
  142. regionFlags = estateModule.GetRegionFlags();
  143. // In a perfect world, this would have worked.
  144. //
  145. // if ((landData.Flags & (uint)Parcel.ParcelFlags.AllowLandmark) != 0)
  146. // regionFlags |= (uint)RegionFlags.AllowLandmark;
  147. // if (landData.OwnerID == remote_client.AgentId)
  148. // regionFlags |= (uint)RegionFlags.AllowSetHome;
  149. remote_client.SendLandProperties(sequence_id,
  150. snap_selection, request_result, landData,
  151. (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
  152. getParcelMaxPrimCount(this),
  153. getSimulatorMaxPrimCount(this), regionFlags);
  154. }
  155. public void updateLandProperties(LandUpdateArgs args, IClientAPI remote_client)
  156. {
  157. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId,this))
  158. {
  159. //Needs later group support
  160. LandData newData = landData.Copy();
  161. if (args.AuthBuyerID != newData.AuthBuyerID || args.SalePrice != newData.SalePrice)
  162. {
  163. if (m_scene.Permissions.CanSellParcel(remote_client.AgentId, this))
  164. {
  165. newData.AuthBuyerID = args.AuthBuyerID;
  166. newData.SalePrice = args.SalePrice;
  167. }
  168. }
  169. newData.Category = args.Category;
  170. newData.Description = args.Desc;
  171. newData.GroupID = args.GroupID;
  172. newData.LandingType = args.LandingType;
  173. newData.MediaAutoScale = args.MediaAutoScale;
  174. newData.MediaID = args.MediaID;
  175. newData.MediaURL = args.MediaURL;
  176. newData.MusicURL = args.MusicURL;
  177. newData.Name = args.Name;
  178. newData.Flags = args.ParcelFlags;
  179. newData.PassHours = args.PassHours;
  180. newData.PassPrice = args.PassPrice;
  181. newData.SnapshotID = args.SnapshotID;
  182. newData.UserLocation = args.UserLocation;
  183. newData.UserLookAt = args.UserLookAt;
  184. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  185. sendLandUpdateToAvatarsOverMe();
  186. }
  187. }
  188. public void updateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
  189. {
  190. LandData newData = landData.Copy();
  191. newData.OwnerID = avatarID;
  192. newData.GroupID = groupID;
  193. newData.IsGroupOwned = groupOwned;
  194. //newData.auctionID = AuctionID;
  195. newData.ClaimDate = Util.UnixTimeSinceEpoch();
  196. newData.ClaimPrice = claimprice;
  197. newData.SalePrice = 0;
  198. newData.AuthBuyerID = UUID.Zero;
  199. newData.Flags &= ~(uint) (Parcel.ParcelFlags.ForSale | Parcel.ParcelFlags.ForSaleObjects | Parcel.ParcelFlags.SellParcelObjects);
  200. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  201. sendLandUpdateToAvatarsOverMe();
  202. }
  203. public bool isEitherBannedOrRestricted(UUID avatar)
  204. {
  205. if (isBannedFromLand(avatar))
  206. {
  207. return true;
  208. }
  209. else if (isRestrictedFromLand(avatar))
  210. {
  211. return true;
  212. }
  213. return false;
  214. }
  215. public bool isBannedFromLand(UUID avatar)
  216. {
  217. if ((landData.Flags & (uint) Parcel.ParcelFlags.UseBanList) > 0)
  218. {
  219. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  220. entry.AgentID = avatar;
  221. entry.Flags = AccessList.Ban;
  222. entry.Time = new DateTime();
  223. if (landData.ParcelAccessList.Contains(entry))
  224. {
  225. //They are banned, so lets send them a notice about this parcel
  226. return true;
  227. }
  228. }
  229. return false;
  230. }
  231. public bool isRestrictedFromLand(UUID avatar)
  232. {
  233. if ((landData.Flags & (uint) Parcel.ParcelFlags.UseAccessList) > 0)
  234. {
  235. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  236. entry.AgentID = avatar;
  237. entry.Flags = AccessList.Access;
  238. entry.Time = new DateTime();
  239. if (!landData.ParcelAccessList.Contains(entry))
  240. {
  241. //They are not allowed in this parcel, but not banned, so lets send them a notice about this parcel
  242. return true;
  243. }
  244. }
  245. return false;
  246. }
  247. public void sendLandUpdateToClient(IClientAPI remote_client)
  248. {
  249. sendLandProperties(0, false, 0, remote_client);
  250. }
  251. public void sendLandUpdateToAvatarsOverMe()
  252. {
  253. List<ScenePresence> avatars = m_scene.GetAvatars();
  254. ILandObject over = null;
  255. for (int i = 0; i < avatars.Count; i++)
  256. {
  257. try
  258. {
  259. over =
  260. m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatars[i].AbsolutePosition.X), 0, 255),
  261. Util.Clamp<int>((int)Math.Round(avatars[i].AbsolutePosition.Y), 0, 255));
  262. }
  263. catch (Exception)
  264. {
  265. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatars[i].AbsolutePosition.X) + " y: " +
  266. Math.Round(avatars[i].AbsolutePosition.Y));
  267. }
  268. if (over != null)
  269. {
  270. if (over.landData.LocalID == landData.LocalID)
  271. {
  272. if (((over.landData.Flags & (uint)Parcel.ParcelFlags.AllowDamage) != 0) && m_scene.RegionInfo.RegionSettings.AllowDamage)
  273. avatars[i].Invulnerable = false;
  274. else
  275. avatars[i].Invulnerable = true;
  276. sendLandUpdateToClient(avatars[i].ControllingClient);
  277. }
  278. }
  279. }
  280. }
  281. #endregion
  282. #region AccessList Functions
  283. public List<UUID> createAccessListArrayByFlag(AccessList flag)
  284. {
  285. List<UUID> list = new List<UUID>();
  286. foreach (ParcelManager.ParcelAccessEntry entry in landData.ParcelAccessList)
  287. {
  288. if (entry.Flags == flag)
  289. {
  290. list.Add(entry.AgentID);
  291. }
  292. }
  293. if (list.Count == 0)
  294. {
  295. list.Add(UUID.Zero);
  296. }
  297. return list;
  298. }
  299. public void sendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  300. IClientAPI remote_client)
  301. {
  302. if (flags == (uint) AccessList.Access || flags == (uint) AccessList.Both)
  303. {
  304. List<UUID> avatars = createAccessListArrayByFlag(AccessList.Access);
  305. remote_client.SendLandAccessListData(avatars,(uint) AccessList.Access,landData.LocalID);
  306. }
  307. if (flags == (uint) AccessList.Ban || flags == (uint) AccessList.Both)
  308. {
  309. List<UUID> avatars = createAccessListArrayByFlag(AccessList.Ban);
  310. remote_client.SendLandAccessListData(avatars, (uint)AccessList.Ban, landData.LocalID);
  311. }
  312. }
  313. public void updateAccessList(uint flags, List<ParcelManager.ParcelAccessEntry> entries, IClientAPI remote_client)
  314. {
  315. LandData newData = landData.Copy();
  316. if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
  317. {
  318. entries.Clear();
  319. }
  320. List<ParcelManager.ParcelAccessEntry> toRemove = new List<ParcelManager.ParcelAccessEntry>();
  321. foreach (ParcelManager.ParcelAccessEntry entry in newData.ParcelAccessList)
  322. {
  323. if (entry.Flags == (AccessList)flags)
  324. {
  325. toRemove.Add(entry);
  326. }
  327. }
  328. foreach (ParcelManager.ParcelAccessEntry entry in toRemove)
  329. {
  330. newData.ParcelAccessList.Remove(entry);
  331. }
  332. foreach (ParcelManager.ParcelAccessEntry entry in entries)
  333. {
  334. ParcelManager.ParcelAccessEntry temp = new ParcelManager.ParcelAccessEntry();
  335. temp.AgentID = entry.AgentID;
  336. temp.Time = new DateTime(); //Pointless? Yes.
  337. temp.Flags = (AccessList)flags;
  338. if (!newData.ParcelAccessList.Contains(temp))
  339. {
  340. newData.ParcelAccessList.Add(temp);
  341. }
  342. }
  343. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  344. }
  345. #endregion
  346. #region Update Functions
  347. public void updateLandBitmapByteArray()
  348. {
  349. landData.Bitmap = convertLandBitmapToBytes();
  350. }
  351. /// <summary>
  352. /// Update all settings in land such as area, bitmap byte array, etc
  353. /// </summary>
  354. public void forceUpdateLandInfo()
  355. {
  356. updateAABBAndAreaValues();
  357. updateLandBitmapByteArray();
  358. }
  359. public void setLandBitmapFromByteArray()
  360. {
  361. landBitmap = convertBytesToLandBitmap();
  362. }
  363. /// <summary>
  364. /// Updates the AABBMin and AABBMax values after area/shape modification of the land object
  365. /// </summary>
  366. private void updateAABBAndAreaValues()
  367. {
  368. int min_x = 64;
  369. int min_y = 64;
  370. int max_x = 0;
  371. int max_y = 0;
  372. int tempArea = 0;
  373. int x, y;
  374. for (x = 0; x < 64; x++)
  375. {
  376. for (y = 0; y < 64; y++)
  377. {
  378. if (landBitmap[x, y] == true)
  379. {
  380. if (min_x > x) min_x = x;
  381. if (min_y > y) min_y = y;
  382. if (max_x < x) max_x = x;
  383. if (max_y < y) max_y = y;
  384. tempArea += 16; //16sqm peice of land
  385. }
  386. }
  387. }
  388. int tx = min_x * 4;
  389. if (tx > 255)
  390. tx = 255;
  391. int ty = min_y * 4;
  392. if (ty > 255)
  393. ty = 255;
  394. landData.AABBMin =
  395. new Vector3((float) (min_x * 4), (float) (min_y * 4),
  396. (float) m_scene.Heightmap[tx, ty]);
  397. tx = max_x * 4;
  398. if (tx > 255)
  399. tx = 255;
  400. ty = max_y * 4;
  401. if (ty > 255)
  402. ty = 255;
  403. landData.AABBMax =
  404. new Vector3((float) (max_x * 4), (float) (max_y * 4),
  405. (float) m_scene.Heightmap[tx, ty]);
  406. landData.Area = tempArea;
  407. }
  408. #endregion
  409. #region Land Bitmap Functions
  410. /// <summary>
  411. /// Sets the land's bitmap manually
  412. /// </summary>
  413. /// <param name="bitmap">64x64 block representing where this land is on a map</param>
  414. public void setLandBitmap(bool[,] bitmap)
  415. {
  416. if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
  417. {
  418. //Throw an exception - The bitmap is not 64x64
  419. //throw new Exception("Error: Invalid Parcel Bitmap");
  420. }
  421. else
  422. {
  423. //Valid: Lets set it
  424. landBitmap = bitmap;
  425. forceUpdateLandInfo();
  426. }
  427. }
  428. /// <summary>
  429. /// Gets the land's bitmap manually
  430. /// </summary>
  431. /// <returns></returns>
  432. public bool[,] getLandBitmap()
  433. {
  434. return landBitmap;
  435. }
  436. /// <summary>
  437. /// Full sim land object creation
  438. /// </summary>
  439. /// <returns></returns>
  440. public bool[,] basicFullRegionLandBitmap()
  441. {
  442. return getSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
  443. }
  444. /// <summary>
  445. /// Used to modify the bitmap between the x and y points. Points use 64 scale
  446. /// </summary>
  447. /// <param name="start_x"></param>
  448. /// <param name="start_y"></param>
  449. /// <param name="end_x"></param>
  450. /// <param name="end_y"></param>
  451. /// <returns></returns>
  452. public bool[,] getSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
  453. {
  454. bool[,] tempBitmap = new bool[64,64];
  455. tempBitmap.Initialize();
  456. tempBitmap = modifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
  457. return tempBitmap;
  458. }
  459. /// <summary>
  460. /// Change a land bitmap at within a square and set those points to a specific value
  461. /// </summary>
  462. /// <param name="land_bitmap"></param>
  463. /// <param name="start_x"></param>
  464. /// <param name="start_y"></param>
  465. /// <param name="end_x"></param>
  466. /// <param name="end_y"></param>
  467. /// <param name="set_value"></param>
  468. /// <returns></returns>
  469. public bool[,] modifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  470. bool set_value)
  471. {
  472. if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
  473. {
  474. //Throw an exception - The bitmap is not 64x64
  475. //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
  476. }
  477. int x, y;
  478. for (y = 0; y < 64; y++)
  479. {
  480. for (x = 0; x < 64; x++)
  481. {
  482. if (x >= start_x / 4 && x < end_x / 4
  483. && y >= start_y / 4 && y < end_y / 4)
  484. {
  485. land_bitmap[x, y] = set_value;
  486. }
  487. }
  488. }
  489. return land_bitmap;
  490. }
  491. /// <summary>
  492. /// Join the true values of 2 bitmaps together
  493. /// </summary>
  494. /// <param name="bitmap_base"></param>
  495. /// <param name="bitmap_add"></param>
  496. /// <returns></returns>
  497. public bool[,] mergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  498. {
  499. if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
  500. {
  501. //Throw an exception - The bitmap is not 64x64
  502. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
  503. }
  504. if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
  505. {
  506. //Throw an exception - The bitmap is not 64x64
  507. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
  508. }
  509. int x, y;
  510. for (y = 0; y < 64; y++)
  511. {
  512. for (x = 0; x < 64; x++)
  513. {
  514. if (bitmap_add[x, y])
  515. {
  516. bitmap_base[x, y] = true;
  517. }
  518. }
  519. }
  520. return bitmap_base;
  521. }
  522. /// <summary>
  523. /// Converts the land bitmap to a packet friendly byte array
  524. /// </summary>
  525. /// <returns></returns>
  526. private byte[] convertLandBitmapToBytes()
  527. {
  528. byte[] tempConvertArr = new byte[512];
  529. byte tempByte = 0;
  530. int x, y, i, byteNum = 0;
  531. i = 0;
  532. for (y = 0; y < 64; y++)
  533. {
  534. for (x = 0; x < 64; x++)
  535. {
  536. tempByte = Convert.ToByte(tempByte | Convert.ToByte(landBitmap[x, y]) << (i++ % 8));
  537. if (i % 8 == 0)
  538. {
  539. tempConvertArr[byteNum] = tempByte;
  540. tempByte = (byte) 0;
  541. i = 0;
  542. byteNum++;
  543. }
  544. }
  545. }
  546. return tempConvertArr;
  547. }
  548. private bool[,] convertBytesToLandBitmap()
  549. {
  550. bool[,] tempConvertMap = new bool[64,64];
  551. tempConvertMap.Initialize();
  552. byte tempByte = 0;
  553. int x = 0, y = 0, i = 0, bitNum = 0;
  554. for (i = 0; i < 512; i++)
  555. {
  556. tempByte = landData.Bitmap[i];
  557. for (bitNum = 0; bitNum < 8; bitNum++)
  558. {
  559. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  560. tempConvertMap[x, y] = bit;
  561. x++;
  562. if (x > 63)
  563. {
  564. x = 0;
  565. y++;
  566. }
  567. }
  568. }
  569. return tempConvertMap;
  570. }
  571. #endregion
  572. #region Object Select and Object Owner Listing
  573. public void sendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  574. {
  575. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  576. {
  577. List<uint> resultLocalIDs = new List<uint>();
  578. try
  579. {
  580. lock (primsOverMe)
  581. {
  582. foreach (SceneObjectGroup obj in primsOverMe)
  583. {
  584. if (obj.LocalId > 0)
  585. {
  586. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == landData.OwnerID)
  587. {
  588. resultLocalIDs.Add(obj.LocalId);
  589. }
  590. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == landData.GroupID && landData.GroupID != UUID.Zero)
  591. {
  592. resultLocalIDs.Add(obj.LocalId);
  593. }
  594. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  595. obj.OwnerID != remote_client.AgentId)
  596. {
  597. resultLocalIDs.Add(obj.LocalId);
  598. }
  599. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  600. {
  601. resultLocalIDs.Add(obj.LocalId);
  602. }
  603. }
  604. }
  605. }
  606. } catch (InvalidOperationException)
  607. {
  608. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  609. }
  610. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  611. }
  612. }
  613. /// <summary>
  614. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  615. /// aggreagete details such as the number of prims.
  616. ///
  617. /// </summary>
  618. /// <param name="remote_client">
  619. /// A <see cref="IClientAPI"/>
  620. /// </param>
  621. public void sendLandObjectOwners(IClientAPI remote_client)
  622. {
  623. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  624. {
  625. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  626. lock (primsOverMe)
  627. {
  628. try
  629. {
  630. foreach (SceneObjectGroup obj in primsOverMe)
  631. {
  632. try
  633. {
  634. if (!primCount.ContainsKey(obj.OwnerID))
  635. {
  636. primCount.Add(obj.OwnerID, 0);
  637. }
  638. }
  639. catch (NullReferenceException)
  640. {
  641. m_log.Info("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  642. }
  643. try
  644. {
  645. primCount[obj.OwnerID] += obj.PrimCount;
  646. }
  647. catch (KeyNotFoundException)
  648. {
  649. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  650. }
  651. }
  652. }
  653. catch (InvalidOperationException)
  654. {
  655. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  656. }
  657. }
  658. remote_client.SendLandObjectOwners(primCount);
  659. }
  660. }
  661. public Dictionary<UUID, int> getLandObjectOwners()
  662. {
  663. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  664. lock (primsOverMe)
  665. {
  666. try
  667. {
  668. foreach (SceneObjectGroup obj in primsOverMe)
  669. {
  670. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  671. {
  672. ownersAndCount.Add(obj.OwnerID, 0);
  673. }
  674. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  675. }
  676. }
  677. catch (InvalidOperationException)
  678. {
  679. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  680. }
  681. }
  682. return ownersAndCount;
  683. }
  684. #endregion
  685. #region Object Returning
  686. public void returnObject(SceneObjectGroup obj)
  687. {
  688. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  689. objs[0] = obj;
  690. m_scene.returnObjects(objs, obj.OwnerID);
  691. }
  692. public void returnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  693. {
  694. Dictionary<UUID,List<SceneObjectGroup>> returns =
  695. new Dictionary<UUID,List<SceneObjectGroup>>();
  696. lock (primsOverMe)
  697. {
  698. if (type == (uint)ObjectReturnType.Owner)
  699. {
  700. foreach (SceneObjectGroup obj in primsOverMe)
  701. {
  702. if (obj.OwnerID == m_landData.OwnerID)
  703. {
  704. if (!returns.ContainsKey(obj.OwnerID))
  705. returns[obj.OwnerID] =
  706. new List<SceneObjectGroup>();
  707. returns[obj.OwnerID].Add(obj);
  708. }
  709. }
  710. }
  711. else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero)
  712. {
  713. foreach (SceneObjectGroup obj in primsOverMe)
  714. {
  715. if (obj.GroupID == m_landData.GroupID)
  716. {
  717. if (!returns.ContainsKey(obj.OwnerID))
  718. returns[obj.OwnerID] =
  719. new List<SceneObjectGroup>();
  720. returns[obj.OwnerID].Add(obj);
  721. }
  722. }
  723. }
  724. else if (type == (uint)ObjectReturnType.Other)
  725. {
  726. foreach (SceneObjectGroup obj in primsOverMe)
  727. {
  728. if (obj.OwnerID != m_landData.OwnerID &&
  729. (obj.GroupID != m_landData.GroupID ||
  730. m_landData.GroupID == UUID.Zero))
  731. {
  732. if (!returns.ContainsKey(obj.OwnerID))
  733. returns[obj.OwnerID] =
  734. new List<SceneObjectGroup>();
  735. returns[obj.OwnerID].Add(obj);
  736. }
  737. }
  738. }
  739. else if (type == (uint)ObjectReturnType.List)
  740. {
  741. List<UUID> ownerlist = new List<UUID>(owners);
  742. foreach (SceneObjectGroup obj in primsOverMe)
  743. {
  744. if (ownerlist.Contains(obj.OwnerID))
  745. {
  746. if (!returns.ContainsKey(obj.OwnerID))
  747. returns[obj.OwnerID] =
  748. new List<SceneObjectGroup>();
  749. returns[obj.OwnerID].Add(obj);
  750. }
  751. }
  752. }
  753. }
  754. foreach (List<SceneObjectGroup> ol in returns.Values)
  755. m_scene.returnObjects(ol.ToArray(), remote_client.AgentId);
  756. }
  757. #endregion
  758. #region Object Adding/Removing from Parcel
  759. public void resetLandPrimCounts()
  760. {
  761. landData.GroupPrims = 0;
  762. landData.OwnerPrims = 0;
  763. landData.OtherPrims = 0;
  764. landData.SelectedPrims = 0;
  765. lock (primsOverMe)
  766. primsOverMe.Clear();
  767. }
  768. public void addPrimToCount(SceneObjectGroup obj)
  769. {
  770. UUID prim_owner = obj.OwnerID;
  771. int prim_count = obj.PrimCount;
  772. if (obj.IsSelected)
  773. {
  774. landData.SelectedPrims += prim_count;
  775. }
  776. else
  777. {
  778. if (prim_owner == landData.OwnerID)
  779. {
  780. landData.OwnerPrims += prim_count;
  781. }
  782. else if ((obj.GroupID == landData.GroupID ||
  783. prim_owner == landData.GroupID) &&
  784. landData.GroupID != UUID.Zero)
  785. {
  786. landData.GroupPrims += prim_count;
  787. }
  788. else
  789. {
  790. landData.OtherPrims += prim_count;
  791. }
  792. }
  793. lock (primsOverMe)
  794. primsOverMe.Add(obj);
  795. }
  796. public void removePrimFromCount(SceneObjectGroup obj)
  797. {
  798. lock (primsOverMe)
  799. {
  800. if (primsOverMe.Contains(obj))
  801. {
  802. UUID prim_owner = obj.OwnerID;
  803. int prim_count = obj.PrimCount;
  804. if (prim_owner == landData.OwnerID)
  805. {
  806. landData.OwnerPrims -= prim_count;
  807. }
  808. else if (obj.GroupID == landData.GroupID ||
  809. prim_owner == landData.GroupID)
  810. {
  811. landData.GroupPrims -= prim_count;
  812. }
  813. else
  814. {
  815. landData.OtherPrims -= prim_count;
  816. }
  817. primsOverMe.Remove(obj);
  818. }
  819. }
  820. }
  821. #endregion
  822. #endregion
  823. #endregion
  824. }
  825. }