LandObject.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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. 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)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) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects);
  200. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  201. sendLandUpdateToAvatarsOverMe();
  202. }
  203. public void deedToGroup(UUID groupID)
  204. {
  205. LandData newData = landData.Copy();
  206. newData.OwnerID = groupID;
  207. newData.GroupID = groupID;
  208. newData.IsGroupOwned = true;
  209. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  210. sendLandUpdateToAvatarsOverMe();
  211. }
  212. public bool isEitherBannedOrRestricted(UUID avatar)
  213. {
  214. if (isBannedFromLand(avatar))
  215. {
  216. return true;
  217. }
  218. else if (isRestrictedFromLand(avatar))
  219. {
  220. return true;
  221. }
  222. return false;
  223. }
  224. public bool isBannedFromLand(UUID avatar)
  225. {
  226. if ((landData.Flags & (uint) ParcelFlags.UseBanList) > 0)
  227. {
  228. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  229. entry.AgentID = avatar;
  230. entry.Flags = AccessList.Ban;
  231. entry.Time = new DateTime();
  232. if (landData.ParcelAccessList.Contains(entry))
  233. {
  234. //They are banned, so lets send them a notice about this parcel
  235. return true;
  236. }
  237. }
  238. return false;
  239. }
  240. public bool isRestrictedFromLand(UUID avatar)
  241. {
  242. if ((landData.Flags & (uint) ParcelFlags.UseAccessList) > 0)
  243. {
  244. ParcelManager.ParcelAccessEntry entry = new ParcelManager.ParcelAccessEntry();
  245. entry.AgentID = avatar;
  246. entry.Flags = AccessList.Access;
  247. entry.Time = new DateTime();
  248. if (!landData.ParcelAccessList.Contains(entry))
  249. {
  250. //They are not allowed in this parcel, but not banned, so lets send them a notice about this parcel
  251. return true;
  252. }
  253. }
  254. return false;
  255. }
  256. public void sendLandUpdateToClient(IClientAPI remote_client)
  257. {
  258. sendLandProperties(0, false, 0, remote_client);
  259. }
  260. public void sendLandUpdateToAvatarsOverMe()
  261. {
  262. List<ScenePresence> avatars = m_scene.GetAvatars();
  263. ILandObject over = null;
  264. for (int i = 0; i < avatars.Count; i++)
  265. {
  266. try
  267. {
  268. over =
  269. m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatars[i].AbsolutePosition.X), 0, 255),
  270. Util.Clamp<int>((int)Math.Round(avatars[i].AbsolutePosition.Y), 0, 255));
  271. }
  272. catch (Exception)
  273. {
  274. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatars[i].AbsolutePosition.X) + " y: " +
  275. Math.Round(avatars[i].AbsolutePosition.Y));
  276. }
  277. if (over != null)
  278. {
  279. if (over.landData.LocalID == landData.LocalID)
  280. {
  281. if (((over.landData.Flags & (uint)ParcelFlags.AllowDamage) != 0) && m_scene.RegionInfo.RegionSettings.AllowDamage)
  282. avatars[i].Invulnerable = false;
  283. else
  284. avatars[i].Invulnerable = true;
  285. sendLandUpdateToClient(avatars[i].ControllingClient);
  286. }
  287. }
  288. }
  289. }
  290. #endregion
  291. #region AccessList Functions
  292. public List<UUID> createAccessListArrayByFlag(AccessList flag)
  293. {
  294. List<UUID> list = new List<UUID>();
  295. foreach (ParcelManager.ParcelAccessEntry entry in landData.ParcelAccessList)
  296. {
  297. if (entry.Flags == flag)
  298. {
  299. list.Add(entry.AgentID);
  300. }
  301. }
  302. if (list.Count == 0)
  303. {
  304. list.Add(UUID.Zero);
  305. }
  306. return list;
  307. }
  308. public void sendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  309. IClientAPI remote_client)
  310. {
  311. if (flags == (uint) AccessList.Access || flags == (uint) AccessList.Both)
  312. {
  313. List<UUID> avatars = createAccessListArrayByFlag(AccessList.Access);
  314. remote_client.SendLandAccessListData(avatars,(uint) AccessList.Access,landData.LocalID);
  315. }
  316. if (flags == (uint) AccessList.Ban || flags == (uint) AccessList.Both)
  317. {
  318. List<UUID> avatars = createAccessListArrayByFlag(AccessList.Ban);
  319. remote_client.SendLandAccessListData(avatars, (uint)AccessList.Ban, landData.LocalID);
  320. }
  321. }
  322. public void updateAccessList(uint flags, List<ParcelManager.ParcelAccessEntry> entries, IClientAPI remote_client)
  323. {
  324. LandData newData = landData.Copy();
  325. if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
  326. {
  327. entries.Clear();
  328. }
  329. List<ParcelManager.ParcelAccessEntry> toRemove = new List<ParcelManager.ParcelAccessEntry>();
  330. foreach (ParcelManager.ParcelAccessEntry entry in newData.ParcelAccessList)
  331. {
  332. if (entry.Flags == (AccessList)flags)
  333. {
  334. toRemove.Add(entry);
  335. }
  336. }
  337. foreach (ParcelManager.ParcelAccessEntry entry in toRemove)
  338. {
  339. newData.ParcelAccessList.Remove(entry);
  340. }
  341. foreach (ParcelManager.ParcelAccessEntry entry in entries)
  342. {
  343. ParcelManager.ParcelAccessEntry temp = new ParcelManager.ParcelAccessEntry();
  344. temp.AgentID = entry.AgentID;
  345. temp.Time = new DateTime(); //Pointless? Yes.
  346. temp.Flags = (AccessList)flags;
  347. if (!newData.ParcelAccessList.Contains(temp))
  348. {
  349. newData.ParcelAccessList.Add(temp);
  350. }
  351. }
  352. m_scene.LandChannel.UpdateLandObject(landData.LocalID, newData);
  353. }
  354. #endregion
  355. #region Update Functions
  356. public void updateLandBitmapByteArray()
  357. {
  358. landData.Bitmap = convertLandBitmapToBytes();
  359. }
  360. /// <summary>
  361. /// Update all settings in land such as area, bitmap byte array, etc
  362. /// </summary>
  363. public void forceUpdateLandInfo()
  364. {
  365. updateAABBAndAreaValues();
  366. updateLandBitmapByteArray();
  367. }
  368. public void setLandBitmapFromByteArray()
  369. {
  370. landBitmap = convertBytesToLandBitmap();
  371. }
  372. /// <summary>
  373. /// Updates the AABBMin and AABBMax values after area/shape modification of the land object
  374. /// </summary>
  375. private void updateAABBAndAreaValues()
  376. {
  377. int min_x = 64;
  378. int min_y = 64;
  379. int max_x = 0;
  380. int max_y = 0;
  381. int tempArea = 0;
  382. int x, y;
  383. for (x = 0; x < 64; x++)
  384. {
  385. for (y = 0; y < 64; y++)
  386. {
  387. if (landBitmap[x, y] == true)
  388. {
  389. if (min_x > x) min_x = x;
  390. if (min_y > y) min_y = y;
  391. if (max_x < x) max_x = x;
  392. if (max_y < y) max_y = y;
  393. tempArea += 16; //16sqm peice of land
  394. }
  395. }
  396. }
  397. int tx = min_x * 4;
  398. if (tx > 255)
  399. tx = 255;
  400. int ty = min_y * 4;
  401. if (ty > 255)
  402. ty = 255;
  403. landData.AABBMin =
  404. new Vector3((float) (min_x * 4), (float) (min_y * 4),
  405. (float) m_scene.Heightmap[tx, ty]);
  406. tx = max_x * 4;
  407. if (tx > 255)
  408. tx = 255;
  409. ty = max_y * 4;
  410. if (ty > 255)
  411. ty = 255;
  412. landData.AABBMax =
  413. new Vector3((float) (max_x * 4), (float) (max_y * 4),
  414. (float) m_scene.Heightmap[tx, ty]);
  415. landData.Area = tempArea;
  416. }
  417. #endregion
  418. #region Land Bitmap Functions
  419. /// <summary>
  420. /// Sets the land's bitmap manually
  421. /// </summary>
  422. /// <param name="bitmap">64x64 block representing where this land is on a map</param>
  423. public void setLandBitmap(bool[,] bitmap)
  424. {
  425. if (bitmap.GetLength(0) != 64 || bitmap.GetLength(1) != 64 || bitmap.Rank != 2)
  426. {
  427. //Throw an exception - The bitmap is not 64x64
  428. //throw new Exception("Error: Invalid Parcel Bitmap");
  429. }
  430. else
  431. {
  432. //Valid: Lets set it
  433. landBitmap = bitmap;
  434. forceUpdateLandInfo();
  435. }
  436. }
  437. /// <summary>
  438. /// Gets the land's bitmap manually
  439. /// </summary>
  440. /// <returns></returns>
  441. public bool[,] getLandBitmap()
  442. {
  443. return landBitmap;
  444. }
  445. /// <summary>
  446. /// Full sim land object creation
  447. /// </summary>
  448. /// <returns></returns>
  449. public bool[,] basicFullRegionLandBitmap()
  450. {
  451. return getSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize);
  452. }
  453. /// <summary>
  454. /// Used to modify the bitmap between the x and y points. Points use 64 scale
  455. /// </summary>
  456. /// <param name="start_x"></param>
  457. /// <param name="start_y"></param>
  458. /// <param name="end_x"></param>
  459. /// <param name="end_y"></param>
  460. /// <returns></returns>
  461. public bool[,] getSquareLandBitmap(int start_x, int start_y, int end_x, int end_y)
  462. {
  463. bool[,] tempBitmap = new bool[64,64];
  464. tempBitmap.Initialize();
  465. tempBitmap = modifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, true);
  466. return tempBitmap;
  467. }
  468. /// <summary>
  469. /// Change a land bitmap at within a square and set those points to a specific value
  470. /// </summary>
  471. /// <param name="land_bitmap"></param>
  472. /// <param name="start_x"></param>
  473. /// <param name="start_y"></param>
  474. /// <param name="end_x"></param>
  475. /// <param name="end_y"></param>
  476. /// <param name="set_value"></param>
  477. /// <returns></returns>
  478. public bool[,] modifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  479. bool set_value)
  480. {
  481. if (land_bitmap.GetLength(0) != 64 || land_bitmap.GetLength(1) != 64 || land_bitmap.Rank != 2)
  482. {
  483. //Throw an exception - The bitmap is not 64x64
  484. //throw new Exception("Error: Invalid Parcel Bitmap in modifyLandBitmapSquare()");
  485. }
  486. int x, y;
  487. for (y = 0; y < 64; y++)
  488. {
  489. for (x = 0; x < 64; x++)
  490. {
  491. if (x >= start_x / 4 && x < end_x / 4
  492. && y >= start_y / 4 && y < end_y / 4)
  493. {
  494. land_bitmap[x, y] = set_value;
  495. }
  496. }
  497. }
  498. return land_bitmap;
  499. }
  500. /// <summary>
  501. /// Join the true values of 2 bitmaps together
  502. /// </summary>
  503. /// <param name="bitmap_base"></param>
  504. /// <param name="bitmap_add"></param>
  505. /// <returns></returns>
  506. public bool[,] mergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  507. {
  508. if (bitmap_base.GetLength(0) != 64 || bitmap_base.GetLength(1) != 64 || bitmap_base.Rank != 2)
  509. {
  510. //Throw an exception - The bitmap is not 64x64
  511. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_base in mergeLandBitmaps");
  512. }
  513. if (bitmap_add.GetLength(0) != 64 || bitmap_add.GetLength(1) != 64 || bitmap_add.Rank != 2)
  514. {
  515. //Throw an exception - The bitmap is not 64x64
  516. throw new Exception("Error: Invalid Parcel Bitmap - Bitmap_add in mergeLandBitmaps");
  517. }
  518. int x, y;
  519. for (y = 0; y < 64; y++)
  520. {
  521. for (x = 0; x < 64; x++)
  522. {
  523. if (bitmap_add[x, y])
  524. {
  525. bitmap_base[x, y] = true;
  526. }
  527. }
  528. }
  529. return bitmap_base;
  530. }
  531. /// <summary>
  532. /// Converts the land bitmap to a packet friendly byte array
  533. /// </summary>
  534. /// <returns></returns>
  535. private byte[] convertLandBitmapToBytes()
  536. {
  537. byte[] tempConvertArr = new byte[512];
  538. byte tempByte = 0;
  539. int x, y, i, byteNum = 0;
  540. i = 0;
  541. for (y = 0; y < 64; y++)
  542. {
  543. for (x = 0; x < 64; x++)
  544. {
  545. tempByte = Convert.ToByte(tempByte | Convert.ToByte(landBitmap[x, y]) << (i++ % 8));
  546. if (i % 8 == 0)
  547. {
  548. tempConvertArr[byteNum] = tempByte;
  549. tempByte = (byte) 0;
  550. i = 0;
  551. byteNum++;
  552. }
  553. }
  554. }
  555. return tempConvertArr;
  556. }
  557. private bool[,] convertBytesToLandBitmap()
  558. {
  559. bool[,] tempConvertMap = new bool[64,64];
  560. tempConvertMap.Initialize();
  561. byte tempByte = 0;
  562. int x = 0, y = 0, i = 0, bitNum = 0;
  563. for (i = 0; i < 512; i++)
  564. {
  565. tempByte = landData.Bitmap[i];
  566. for (bitNum = 0; bitNum < 8; bitNum++)
  567. {
  568. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  569. tempConvertMap[x, y] = bit;
  570. x++;
  571. if (x > 63)
  572. {
  573. x = 0;
  574. y++;
  575. }
  576. }
  577. }
  578. return tempConvertMap;
  579. }
  580. #endregion
  581. #region Object Select and Object Owner Listing
  582. public void sendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  583. {
  584. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  585. {
  586. List<uint> resultLocalIDs = new List<uint>();
  587. try
  588. {
  589. lock (primsOverMe)
  590. {
  591. foreach (SceneObjectGroup obj in primsOverMe)
  592. {
  593. if (obj.LocalId > 0)
  594. {
  595. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == landData.OwnerID)
  596. {
  597. resultLocalIDs.Add(obj.LocalId);
  598. }
  599. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == landData.GroupID && landData.GroupID != UUID.Zero)
  600. {
  601. resultLocalIDs.Add(obj.LocalId);
  602. }
  603. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  604. obj.OwnerID != remote_client.AgentId)
  605. {
  606. resultLocalIDs.Add(obj.LocalId);
  607. }
  608. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  609. {
  610. resultLocalIDs.Add(obj.LocalId);
  611. }
  612. }
  613. }
  614. }
  615. } catch (InvalidOperationException)
  616. {
  617. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  618. }
  619. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  620. }
  621. }
  622. /// <summary>
  623. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  624. /// aggreagete details such as the number of prims.
  625. ///
  626. /// </summary>
  627. /// <param name="remote_client">
  628. /// A <see cref="IClientAPI"/>
  629. /// </param>
  630. public void sendLandObjectOwners(IClientAPI remote_client)
  631. {
  632. if (m_scene.Permissions.CanEditParcel(remote_client.AgentId, this))
  633. {
  634. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  635. List<UUID> groups = new List<UUID>();
  636. lock (primsOverMe)
  637. {
  638. try
  639. {
  640. foreach (SceneObjectGroup obj in primsOverMe)
  641. {
  642. try
  643. {
  644. if (!primCount.ContainsKey(obj.OwnerID))
  645. {
  646. primCount.Add(obj.OwnerID, 0);
  647. }
  648. }
  649. catch (NullReferenceException)
  650. {
  651. m_log.Info("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  652. }
  653. try
  654. {
  655. primCount[obj.OwnerID] += obj.PrimCount;
  656. }
  657. catch (KeyNotFoundException)
  658. {
  659. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  660. }
  661. if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
  662. groups.Add(obj.OwnerID);
  663. }
  664. }
  665. catch (InvalidOperationException)
  666. {
  667. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  668. }
  669. }
  670. remote_client.SendLandObjectOwners(landData, groups, primCount);
  671. }
  672. }
  673. public Dictionary<UUID, int> getLandObjectOwners()
  674. {
  675. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  676. lock (primsOverMe)
  677. {
  678. try
  679. {
  680. foreach (SceneObjectGroup obj in primsOverMe)
  681. {
  682. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  683. {
  684. ownersAndCount.Add(obj.OwnerID, 0);
  685. }
  686. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  687. }
  688. }
  689. catch (InvalidOperationException)
  690. {
  691. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  692. }
  693. }
  694. return ownersAndCount;
  695. }
  696. #endregion
  697. #region Object Returning
  698. public void returnObject(SceneObjectGroup obj)
  699. {
  700. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  701. objs[0] = obj;
  702. m_scene.returnObjects(objs, obj.OwnerID);
  703. }
  704. public void returnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  705. {
  706. Dictionary<UUID,List<SceneObjectGroup>> returns =
  707. new Dictionary<UUID,List<SceneObjectGroup>>();
  708. lock (primsOverMe)
  709. {
  710. if (type == (uint)ObjectReturnType.Owner)
  711. {
  712. foreach (SceneObjectGroup obj in primsOverMe)
  713. {
  714. if (obj.OwnerID == m_landData.OwnerID)
  715. {
  716. if (!returns.ContainsKey(obj.OwnerID))
  717. returns[obj.OwnerID] =
  718. new List<SceneObjectGroup>();
  719. returns[obj.OwnerID].Add(obj);
  720. }
  721. }
  722. }
  723. else if (type == (uint)ObjectReturnType.Group && m_landData.GroupID != UUID.Zero)
  724. {
  725. foreach (SceneObjectGroup obj in primsOverMe)
  726. {
  727. if (obj.GroupID == m_landData.GroupID)
  728. {
  729. if (!returns.ContainsKey(obj.OwnerID))
  730. returns[obj.OwnerID] =
  731. new List<SceneObjectGroup>();
  732. returns[obj.OwnerID].Add(obj);
  733. }
  734. }
  735. }
  736. else if (type == (uint)ObjectReturnType.Other)
  737. {
  738. foreach (SceneObjectGroup obj in primsOverMe)
  739. {
  740. if (obj.OwnerID != m_landData.OwnerID &&
  741. (obj.GroupID != m_landData.GroupID ||
  742. m_landData.GroupID == UUID.Zero))
  743. {
  744. if (!returns.ContainsKey(obj.OwnerID))
  745. returns[obj.OwnerID] =
  746. new List<SceneObjectGroup>();
  747. returns[obj.OwnerID].Add(obj);
  748. }
  749. }
  750. }
  751. else if (type == (uint)ObjectReturnType.List)
  752. {
  753. List<UUID> ownerlist = new List<UUID>(owners);
  754. foreach (SceneObjectGroup obj in primsOverMe)
  755. {
  756. if (ownerlist.Contains(obj.OwnerID))
  757. {
  758. if (!returns.ContainsKey(obj.OwnerID))
  759. returns[obj.OwnerID] =
  760. new List<SceneObjectGroup>();
  761. returns[obj.OwnerID].Add(obj);
  762. }
  763. }
  764. }
  765. }
  766. foreach (List<SceneObjectGroup> ol in returns.Values)
  767. {
  768. if (m_scene.Permissions.CanUseObjectReturn(this, type, remote_client, ol))
  769. m_scene.returnObjects(ol.ToArray(), remote_client.AgentId);
  770. }
  771. }
  772. #endregion
  773. #region Object Adding/Removing from Parcel
  774. public void resetLandPrimCounts()
  775. {
  776. landData.GroupPrims = 0;
  777. landData.OwnerPrims = 0;
  778. landData.OtherPrims = 0;
  779. landData.SelectedPrims = 0;
  780. lock (primsOverMe)
  781. primsOverMe.Clear();
  782. }
  783. public void addPrimToCount(SceneObjectGroup obj)
  784. {
  785. UUID prim_owner = obj.OwnerID;
  786. int prim_count = obj.PrimCount;
  787. if (obj.IsSelected)
  788. {
  789. landData.SelectedPrims += prim_count;
  790. }
  791. else
  792. {
  793. if (prim_owner == landData.OwnerID)
  794. {
  795. landData.OwnerPrims += prim_count;
  796. }
  797. else if ((obj.GroupID == landData.GroupID ||
  798. prim_owner == landData.GroupID) &&
  799. landData.GroupID != UUID.Zero)
  800. {
  801. landData.GroupPrims += prim_count;
  802. }
  803. else
  804. {
  805. landData.OtherPrims += prim_count;
  806. }
  807. }
  808. lock (primsOverMe)
  809. primsOverMe.Add(obj);
  810. }
  811. public void removePrimFromCount(SceneObjectGroup obj)
  812. {
  813. lock (primsOverMe)
  814. {
  815. if (primsOverMe.Contains(obj))
  816. {
  817. UUID prim_owner = obj.OwnerID;
  818. int prim_count = obj.PrimCount;
  819. if (prim_owner == landData.OwnerID)
  820. {
  821. landData.OwnerPrims -= prim_count;
  822. }
  823. else if (obj.GroupID == landData.GroupID ||
  824. prim_owner == landData.GroupID)
  825. {
  826. landData.GroupPrims -= prim_count;
  827. }
  828. else
  829. {
  830. landData.OtherPrims -= prim_count;
  831. }
  832. primsOverMe.Remove(obj);
  833. }
  834. }
  835. }
  836. #endregion
  837. #endregion
  838. #endregion
  839. /// <summary>
  840. /// Set the media url for this land parcel
  841. /// </summary>
  842. /// <param name="url"></param>
  843. public void SetMediaUrl(string url)
  844. {
  845. landData.MediaURL = url;
  846. sendLandUpdateToAvatarsOverMe();
  847. }
  848. /// <summary>
  849. /// Set the music url for this land parcel
  850. /// </summary>
  851. /// <param name="url"></param>
  852. public void SetMusicUrl(string url)
  853. {
  854. landData.MusicURL = url;
  855. sendLandUpdateToAvatarsOverMe();
  856. }
  857. }
  858. }