LandObject.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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 libsecondlife;
  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 LLUUID regionUUID
  61. {
  62. get { return m_scene.RegionInfo.RegionID; }
  63. }
  64. #region Constructors
  65. public LandObject(LLUUID 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)(Simulator.RegionFlags.AllowLandmark | Simulator.RegionFlags.AllowSetHome));
  141. if(estateModule != null)
  142. regionFlags = estateModule.GetRegionFlags();
  143. if((landData.landFlags & (uint)Parcel.ParcelFlags.AllowLandmark) != 0)
  144. regionFlags |= (uint)Simulator.RegionFlags.AllowLandmark;
  145. if(landData.ownerID == remote_client.AgentId)
  146. regionFlags |= (uint)Simulator.RegionFlags.AllowSetHome;
  147. remote_client.SendLandProperties(remote_client, sequence_id,
  148. snap_selection, request_result, landData,
  149. (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
  150. getParcelMaxPrimCount(this),
  151. getSimulatorMaxPrimCount(this), regionFlags);
  152. }
  153. public void updateLandProperties(LandUpdateArgs args, IClientAPI remote_client)
  154. {
  155. if (m_scene.ExternalChecks.ExternalChecksCanEditParcel(remote_client.AgentId,this))
  156. {
  157. //Needs later group support
  158. LandData newData = landData.Copy();
  159. if (args.AuthBuyerID != newData.authBuyerID || args.SalePrice != newData.salePrice)
  160. {
  161. if (m_scene.ExternalChecks.ExternalChecksCanSellParcel(remote_client.AgentId, this))
  162. {
  163. newData.authBuyerID = args.AuthBuyerID;
  164. newData.salePrice = args.SalePrice;
  165. }
  166. }
  167. newData.category = args.Category;
  168. newData.landDesc = args.Desc;
  169. newData.groupID = args.GroupID;
  170. newData.landingType = args.LandingType;
  171. newData.mediaAutoScale = args.MediaAutoScale;
  172. newData.mediaID = args.MediaID;
  173. newData.mediaURL = args.MediaURL;
  174. newData.musicURL = args.MusicURL;
  175. newData.landName = args.Name;
  176. newData.landFlags = args.ParcelFlags;
  177. newData.passHours = args.PassHours;
  178. newData.passPrice = args.PassPrice;
  179. newData.snapshotID = args.SnapshotID;
  180. newData.userLocation = args.UserLocation;
  181. newData.userLookAt = args.UserLookAt;
  182. m_scene.LandChannel.UpdateLandObject(landData.localID, newData);
  183. sendLandUpdateToAvatarsOverMe();
  184. }
  185. }
  186. public void updateLandSold(LLUUID avatarID, LLUUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
  187. {
  188. LandData newData = landData.Copy();
  189. newData.ownerID = avatarID;
  190. newData.groupID = groupID;
  191. newData.isGroupOwned = groupOwned;
  192. //newData.auctionID = AuctionID;
  193. newData.claimDate = Util.UnixTimeSinceEpoch();
  194. newData.claimPrice = claimprice;
  195. newData.salePrice = 0;
  196. newData.authBuyerID = LLUUID.Zero;
  197. newData.landFlags &= ~(uint) (Parcel.ParcelFlags.ForSale | Parcel.ParcelFlags.ForSaleObjects | Parcel.ParcelFlags.SellParcelObjects);
  198. m_scene.LandChannel.UpdateLandObject(landData.localID, newData);
  199. sendLandUpdateToAvatarsOverMe();
  200. }
  201. public bool isEitherBannedOrRestricted(LLUUID avatar)
  202. {
  203. if (isBannedFromLand(avatar))
  204. {
  205. return true;
  206. }
  207. else if (isRestrictedFromLand(avatar))
  208. {
  209. return true;
  210. }
  211. return false;
  212. }
  213. public bool isBannedFromLand(LLUUID avatar)
  214. {
  215. if ((landData.landFlags & (uint) Parcel.ParcelFlags.UseBanList) > 0)
  216. {
  217. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  218. entry.AgentID = avatar;
  219. entry.Flags = ParcelManager.AccessList.Ban;
  220. entry.Time = new DateTime();
  221. if (landData.parcelAccessList.Contains(entry))
  222. {
  223. //They are banned, so lets send them a notice about this parcel
  224. return true;
  225. }
  226. }
  227. return false;
  228. }
  229. public bool isRestrictedFromLand(LLUUID avatar)
  230. {
  231. if ((landData.landFlags & (uint) Parcel.ParcelFlags.UseAccessList) > 0)
  232. {
  233. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  234. entry.AgentID = avatar;
  235. entry.Flags = ParcelManager.AccessList.Access;
  236. entry.Time = new DateTime();
  237. if (!landData.parcelAccessList.Contains(entry))
  238. {
  239. //They are not allowed in this parcel, but not banned, so lets send them a notice about this parcel
  240. return true;
  241. }
  242. }
  243. return false;
  244. }
  245. public void sendLandUpdateToClient(IClientAPI remote_client)
  246. {
  247. sendLandProperties(0, false, 0, remote_client);
  248. }
  249. public void sendLandUpdateToAvatarsOverMe()
  250. {
  251. List<ScenePresence> avatars = m_scene.GetAvatars();
  252. ILandObject over = null;
  253. for (int i = 0; i < avatars.Count; i++)
  254. {
  255. try
  256. {
  257. over =
  258. m_scene.LandChannel.GetLandObject((int) Math.Max(255, Math.Min(0, Math.Round(avatars[i].AbsolutePosition.X))),
  259. (int) Math.Max(255, Math.Min(0, Math.Round(avatars[i].AbsolutePosition.Y))));
  260. }
  261. catch (Exception)
  262. {
  263. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatars[i].AbsolutePosition.X) + " y: " +
  264. Math.Round(avatars[i].AbsolutePosition.Y));
  265. }
  266. if (over != null)
  267. {
  268. if (over.landData.localID == landData.localID)
  269. {
  270. if (((over.landData.landFlags & (uint)Parcel.ParcelFlags.AllowDamage) != 0) && m_scene.RegionInfo.RegionSettings.AllowDamage)
  271. avatars[i].Invulnerable = false;
  272. else
  273. avatars[i].Invulnerable = true;
  274. sendLandUpdateToClient(avatars[i].ControllingClient);
  275. }
  276. }
  277. }
  278. }
  279. #endregion
  280. #region AccessList Functions
  281. public List<LLUUID> createAccessListArrayByFlag(ParcelManager.AccessList flag)
  282. {
  283. List<LLUUID> list = new List<LLUUID>();
  284. foreach (ParcelManager.ParcelAccessEntry entry in landData.parcelAccessList)
  285. {
  286. if (entry.Flags == flag)
  287. {
  288. list.Add(entry.AgentID);
  289. }
  290. }
  291. if (list.Count == 0)
  292. {
  293. list.Add(LLUUID.Zero);
  294. }
  295. return list;
  296. }
  297. public void sendAccessList(LLUUID agentID, LLUUID sessionID, uint flags, int sequenceID,
  298. IClientAPI remote_client)
  299. {
  300. if (flags == (uint) ParcelManager.AccessList.Access || flags == (uint) ParcelManager.AccessList.Both)
  301. {
  302. List<LLUUID> avatars = createAccessListArrayByFlag(ParcelManager.AccessList.Access);
  303. remote_client.SendLandAccessListData(avatars,(uint) ParcelManager.AccessList.Access,landData.localID);
  304. }
  305. if (flags == (uint) ParcelManager.AccessList.Ban || flags == (uint) ParcelManager.AccessList.Both)
  306. {
  307. List<LLUUID> avatars = createAccessListArrayByFlag(ParcelManager.AccessList.Ban);
  308. remote_client.SendLandAccessListData(avatars, (uint)ParcelManager.AccessList.Ban, landData.localID);
  309. }
  310. }
  311. public void updateAccessList(uint flags, List<ParcelManager.ParcelAccessEntry> entries, IClientAPI remote_client)
  312. {
  313. LandData newData = landData.Copy();
  314. if (entries.Count == 1 && entries[0].AgentID == LLUUID.Zero)
  315. {
  316. entries.Clear();
  317. }
  318. List<ParcelManager.ParcelAccessEntry> toRemove = new List<ParcelManager.ParcelAccessEntry>();
  319. foreach (ParcelManager.ParcelAccessEntry entry in newData.parcelAccessList)
  320. {
  321. if (entry.Flags == (ParcelManager.AccessList) flags)
  322. {
  323. toRemove.Add(entry);
  324. }
  325. }
  326. foreach (ParcelManager.ParcelAccessEntry entry in toRemove)
  327. {
  328. newData.parcelAccessList.Remove(entry);
  329. }
  330. foreach (ParcelManager.ParcelAccessEntry entry in entries)
  331. {
  332. ParcelManager.ParcelAccessEntry temp = new ParcelManager.ParcelAccessEntry();
  333. temp.AgentID = entry.AgentID;
  334. temp.Time = new DateTime(); //Pointless? Yes.
  335. temp.Flags = (ParcelManager.AccessList) flags;
  336. if (!newData.parcelAccessList.Contains(temp))
  337. {
  338. newData.parcelAccessList.Add(temp);
  339. }
  340. }
  341. m_scene.LandChannel.UpdateLandObject(landData.localID, newData);
  342. }
  343. #endregion
  344. #region Update Functions
  345. public void updateLandBitmapByteArray()
  346. {
  347. landData.landBitmapByteArray = convertLandBitmapToBytes();
  348. }
  349. /// <summary>
  350. /// Update all settings in land such as area, bitmap byte array, etc
  351. /// </summary>
  352. public void forceUpdateLandInfo()
  353. {
  354. updateAABBAndAreaValues();
  355. updateLandBitmapByteArray();
  356. }
  357. public void setLandBitmapFromByteArray()
  358. {
  359. landBitmap = convertBytesToLandBitmap();
  360. }
  361. /// <summary>
  362. /// Updates the AABBMin and AABBMax values after area/shape modification of the land object
  363. /// </summary>
  364. private void updateAABBAndAreaValues()
  365. {
  366. int min_x = 64;
  367. int min_y = 64;
  368. int max_x = 0;
  369. int max_y = 0;
  370. int tempArea = 0;
  371. int x, y;
  372. for (x = 0; x < 64; x++)
  373. {
  374. for (y = 0; y < 64; y++)
  375. {
  376. if (landBitmap[x, y] == true)
  377. {
  378. if (min_x > x) min_x = x;
  379. if (min_y > y) min_y = y;
  380. if (max_x < x) max_x = x;
  381. if (max_y < y) max_y = y;
  382. tempArea += 16; //16sqm peice of land
  383. }
  384. }
  385. }
  386. int tx = min_x * 4;
  387. if (tx > 255)
  388. tx = 255;
  389. int ty = min_y * 4;
  390. if (ty > 255)
  391. ty = 255;
  392. landData.AABBMin =
  393. new LLVector3((float) (min_x * 4), (float) (min_y * 4),
  394. (float) m_scene.Heightmap[tx, ty]);
  395. tx = max_x * 4;
  396. if (tx > 255)
  397. tx = 255;
  398. ty = max_y * 4;
  399. if (ty > 255)
  400. ty = 255;
  401. landData.AABBMax =
  402. new LLVector3((float) (max_x * 4), (float) (max_y * 4),
  403. (float) m_scene.Heightmap[tx, ty]);
  404. landData.area = tempArea;
  405. }
  406. #endregion
  407. #region Land Bitmap Functions
  408. /// <summary>
  409. /// Sets the land's bitmap manually
  410. /// </summary>
  411. /// <param name="bitmap">64x64 block representing where this land is on a map</param>
  412. public void setLandBitmap(bool[,] bitmap)
  413. {
  414. if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
  415. {
  416. //Throw an exception - The bitmap is not 64x64
  417. //throw new Exception("Error: Invalid Parcel Bitmap");
  418. }
  419. else
  420. {
  421. //Valid: Lets set it
  422. landBitmap = bitmap;
  423. forceUpdateLandInfo();
  424. }
  425. }
  426. /// <summary>
  427. /// Gets the land's bitmap manually
  428. /// </summary>
  429. /// <returns></returns>
  430. public bool[,] getLandBitmap()
  431. {
  432. return landBitmap;
  433. }
  434. /// <summary>
  435. /// Full sim land object creation
  436. /// </summary>
  437. /// <returns></returns>
  438. public bool[,] basicFullRegionLandBitmap()
  439. {
  440. return getSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
  441. }
  442. /// <summary>
  443. /// Used to modify the bitmap between the x and y points. Points use 64 scale
  444. /// </summary>
  445. /// <param name="start_x"></param>
  446. /// <param name="start_y"></param>
  447. /// <param name="end_x"></param>
  448. /// <param name="end_y"></param>
  449. /// <returns></returns>
  450. public bool[,] getSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
  451. {
  452. bool[,] tempBitmap = new bool[64,64];
  453. tempBitmap.Initialize();
  454. tempBitmap = modifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
  455. return tempBitmap;
  456. }
  457. /// <summary>
  458. /// Change a land bitmap at within a square and set those points to a specific value
  459. /// </summary>
  460. /// <param name="land_bitmap"></param>
  461. /// <param name="start_x"></param>
  462. /// <param name="start_y"></param>
  463. /// <param name="end_x"></param>
  464. /// <param name="end_y"></param>
  465. /// <param name="set_value"></param>
  466. /// <returns></returns>
  467. public bool[,] modifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  468. bool set_value)
  469. {
  470. if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
  471. {
  472. //Throw an exception - The bitmap is not 64x64
  473. //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
  474. }
  475. int x, y;
  476. for (y = 0; y < 64; y++)
  477. {
  478. for (x = 0; x < 64; x++)
  479. {
  480. if (x >= start_x / 4 && x < end_x / 4
  481. && y >= start_y / 4 && y < end_y / 4)
  482. {
  483. land_bitmap[x, y] = set_value;
  484. }
  485. }
  486. }
  487. return land_bitmap;
  488. }
  489. /// <summary>
  490. /// Join the true values of 2 bitmaps together
  491. /// </summary>
  492. /// <param name="bitmap_base"></param>
  493. /// <param name="bitmap_add"></param>
  494. /// <returns></returns>
  495. public bool[,] mergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  496. {
  497. if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
  498. {
  499. //Throw an exception - The bitmap is not 64x64
  500. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
  501. }
  502. if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
  503. {
  504. //Throw an exception - The bitmap is not 64x64
  505. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
  506. }
  507. int x, y;
  508. for (y = 0; y < 64; y++)
  509. {
  510. for (x = 0; x < 64; x++)
  511. {
  512. if (bitmap_add[x, y])
  513. {
  514. bitmap_base[x, y] = true;
  515. }
  516. }
  517. }
  518. return bitmap_base;
  519. }
  520. /// <summary>
  521. /// Converts the land bitmap to a packet friendly byte array
  522. /// </summary>
  523. /// <returns></returns>
  524. private byte[] convertLandBitmapToBytes()
  525. {
  526. byte[] tempConvertArr = new byte[512];
  527. byte tempByte = 0;
  528. int x, y, i, byteNum = 0;
  529. i = 0;
  530. for (y = 0; y < 64; y++)
  531. {
  532. for (x = 0; x < 64; x++)
  533. {
  534. tempByte = Convert.ToByte(tempByte | Convert.ToByte(landBitmap[x, y]) << (i++ % 8));
  535. if (i % 8 == 0)
  536. {
  537. tempConvertArr[byteNum] = tempByte;
  538. tempByte = (byte) 0;
  539. i = 0;
  540. byteNum++;
  541. }
  542. }
  543. }
  544. return tempConvertArr;
  545. }
  546. private bool[,] convertBytesToLandBitmap()
  547. {
  548. bool[,] tempConvertMap = new bool[64,64];
  549. tempConvertMap.Initialize();
  550. byte tempByte = 0;
  551. int x = 0, y = 0, i = 0, bitNum = 0;
  552. for (i = 0; i < 512; i++)
  553. {
  554. tempByte = landData.landBitmapByteArray[i];
  555. for (bitNum = 0; bitNum < 8; bitNum++)
  556. {
  557. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  558. tempConvertMap[x, y] = bit;
  559. x++;
  560. if (x > 63)
  561. {
  562. x = 0;
  563. y++;
  564. }
  565. }
  566. }
  567. return tempConvertMap;
  568. }
  569. #endregion
  570. #region Object Select and Object Owner Listing
  571. public void sendForceObjectSelect(int local_id, int request_type, IClientAPI remote_client)
  572. {
  573. if (m_scene.ExternalChecks.ExternalChecksCanEditParcel(remote_client.AgentId, this))
  574. {
  575. List<uint> resultLocalIDs = new List<uint>();
  576. try
  577. {
  578. lock (primsOverMe)
  579. {
  580. foreach (SceneObjectGroup obj in primsOverMe)
  581. {
  582. if (obj.LocalId > 0)
  583. {
  584. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == landData.ownerID)
  585. {
  586. resultLocalIDs.Add(obj.LocalId);
  587. }
  588. // else if (request_type == LandManager.LAND_SELECT_OBJECTS_GROUP && ...) // TODO: group support
  589. // {
  590. // }
  591. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  592. obj.OwnerID != remote_client.AgentId)
  593. {
  594. resultLocalIDs.Add(obj.LocalId);
  595. }
  596. }
  597. }
  598. }
  599. } catch (InvalidOperationException)
  600. {
  601. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  602. }
  603. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  604. }
  605. }
  606. /// <summary>
  607. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  608. /// aggreagete details such as the number of prims.
  609. ///
  610. /// </summary>
  611. /// <param name="remote_client">
  612. /// A <see cref="IClientAPI"/>
  613. /// </param>
  614. public void sendLandObjectOwners(IClientAPI remote_client)
  615. {
  616. if (m_scene.ExternalChecks.ExternalChecksCanEditParcel(remote_client.AgentId, this))
  617. {
  618. Dictionary<LLUUID, int> primCount = new Dictionary<LLUUID, int>();
  619. lock (primsOverMe)
  620. {
  621. try
  622. {
  623. foreach (SceneObjectGroup obj in primsOverMe)
  624. {
  625. try
  626. {
  627. if (!primCount.ContainsKey(obj.OwnerID))
  628. {
  629. primCount.Add(obj.OwnerID, 0);
  630. }
  631. }
  632. catch (NullReferenceException)
  633. {
  634. m_log.Info("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  635. }
  636. try
  637. {
  638. primCount[obj.OwnerID] += obj.PrimCount;
  639. }
  640. catch (KeyNotFoundException)
  641. {
  642. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  643. }
  644. }
  645. }
  646. catch (InvalidOperationException)
  647. {
  648. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  649. }
  650. }
  651. remote_client.SendLandObjectOwners(primCount);
  652. }
  653. }
  654. public Dictionary<LLUUID, int> getLandObjectOwners()
  655. {
  656. Dictionary<LLUUID, int> ownersAndCount = new Dictionary<LLUUID, int>();
  657. lock (primsOverMe)
  658. {
  659. try
  660. {
  661. foreach (SceneObjectGroup obj in primsOverMe)
  662. {
  663. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  664. {
  665. ownersAndCount.Add(obj.OwnerID, 0);
  666. }
  667. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  668. }
  669. }
  670. catch (InvalidOperationException)
  671. {
  672. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  673. }
  674. }
  675. return ownersAndCount;
  676. }
  677. #endregion
  678. #region Object Returning
  679. public void returnObject(SceneObjectGroup obj)
  680. {
  681. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  682. objs[0] = obj;
  683. m_scene.returnObjects(objs, obj.OwnerID);
  684. }
  685. public void returnLandObjects(uint type, LLUUID[] owners, IClientAPI remote_client)
  686. {
  687. List<SceneObjectGroup> objlist = new List<SceneObjectGroup>();
  688. for (int i = 0; i < owners.Length; i++)
  689. {
  690. lock (primsOverMe)
  691. {
  692. try
  693. {
  694. foreach (SceneObjectGroup obj in primsOverMe)
  695. {
  696. if (obj.OwnerID == owners[i])
  697. objlist.Add(obj);
  698. }
  699. }
  700. catch (InvalidOperationException)
  701. {
  702. m_log.Info("[PARCEL]: Unable to figure out all the objects owned by " + owners[i].ToString() + " arr.");
  703. }
  704. }
  705. }
  706. m_scene.returnObjects(objlist.ToArray(), remote_client.AgentId);
  707. }
  708. #endregion
  709. #region Object Adding/Removing from Parcel
  710. public void resetLandPrimCounts()
  711. {
  712. landData.groupPrims = 0;
  713. landData.ownerPrims = 0;
  714. landData.otherPrims = 0;
  715. landData.selectedPrims = 0;
  716. lock (primsOverMe)
  717. primsOverMe.Clear();
  718. }
  719. public void addPrimToCount(SceneObjectGroup obj)
  720. {
  721. LLUUID prim_owner = obj.OwnerID;
  722. int prim_count = obj.PrimCount;
  723. if (obj.IsSelected)
  724. {
  725. landData.selectedPrims += prim_count;
  726. }
  727. else
  728. {
  729. if (prim_owner == landData.ownerID)
  730. {
  731. landData.ownerPrims += prim_count;
  732. }
  733. else
  734. {
  735. landData.otherPrims += prim_count;
  736. }
  737. }
  738. lock (primsOverMe)
  739. primsOverMe.Add(obj);
  740. }
  741. public void removePrimFromCount(SceneObjectGroup obj)
  742. {
  743. lock (primsOverMe)
  744. {
  745. if (primsOverMe.Contains(obj))
  746. {
  747. LLUUID prim_owner = obj.OwnerID;
  748. int prim_count = obj.PrimCount;
  749. if (prim_owner == landData.ownerID)
  750. {
  751. landData.ownerPrims -= prim_count;
  752. }
  753. else if (prim_owner == landData.groupID)
  754. {
  755. landData.groupPrims -= prim_count;
  756. }
  757. else
  758. {
  759. landData.otherPrims -= prim_count;
  760. }
  761. primsOverMe.Remove(obj);
  762. }
  763. }
  764. }
  765. #endregion
  766. #endregion
  767. #endregion
  768. }
  769. }