LandObject.cs 35 KB

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