LandManagementModule.cs 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080
  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 libsecondlife;
  30. using Nini.Config;
  31. using OpenSim.Region.Environment.Interfaces;
  32. using OpenSim.Region.Environment.Scenes;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Physics.Manager;
  35. using Axiom.Math;
  36. namespace OpenSim.Region.Environment.Modules.World.Land
  37. {
  38. public class LandManagementModule : IRegionModule
  39. {
  40. private LandChannel landChannel;
  41. private Scene m_scene;
  42. private readonly int[,] landIDList = new int[64, 64];
  43. private readonly Dictionary<int, ILandObject> landList = new Dictionary<int, ILandObject>();
  44. private bool landPrimCountTainted;
  45. private int lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  46. private bool m_allowedForcefulBans = true;
  47. #region IRegionModule Members
  48. public void Initialise(Scene scene, IConfigSource source)
  49. {
  50. m_scene = scene;
  51. landIDList.Initialize();
  52. landChannel = new LandChannel(scene, this);
  53. m_scene.EventManager.OnParcelPrimCountAdd += AddPrimToLandPrimCounts;
  54. m_scene.EventManager.OnParcelPrimCountUpdate += UpdateLandPrimCounts;
  55. m_scene.EventManager.OnAvatarEnteringNewParcel += new EventManager.AvatarEnteringNewParcel(handleAvatarChangingParcel);
  56. m_scene.EventManager.OnClientMovement += new EventManager.ClientMovement(handleAnyClientMovement);
  57. m_scene.EventManager.OnValidateLandBuy += handleLandValidationRequest;
  58. m_scene.EventManager.OnLandBuy += handleLandBuyRequest;
  59. m_scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient);
  60. m_scene.EventManager.OnSignificantClientMovement += handleSignificantClientMovement;
  61. m_scene.EventManager.OnObjectBeingRemovedFromScene += RemovePrimFromLandPrimCounts;
  62. m_scene.EventManager.OnNoticeNoLandDataFromStorage += this.NoLandDataFromStorage;
  63. m_scene.EventManager.OnIncomingLandDataFromStorage += this.IncomingLandObjectsFromStorage;
  64. m_scene.EventManager.OnSetAllowForcefulBan += this.SetAllowedForcefulBans;
  65. m_scene.EventManager.OnRequestParcelPrimCountUpdate += this.PerformParcelPrimCountUpdate;
  66. m_scene.EventManager.OnParcelPrimCountTainted += this.SetPrimsTainted;
  67. lock (m_scene)
  68. {
  69. m_scene.LandChannel = (ILandChannel) landChannel;
  70. }
  71. }
  72. void EventManager_OnNewClient(IClientAPI client)
  73. {
  74. //Register some client events
  75. client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(handleParcelPropertiesRequest);
  76. client.OnParcelDivideRequest += new ParcelDivideRequest(handleParcelDivideRequest);
  77. client.OnParcelJoinRequest += new ParcelJoinRequest(handleParcelJoinRequest);
  78. client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(handleParcelPropertiesUpdateRequest);
  79. client.OnParcelSelectObjects += new ParcelSelectObjects(handleParcelSelectObjectsRequest);
  80. client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(handleParcelObjectOwnersRequest);
  81. client.OnParcelAccessListRequest += new ParcelAccessListRequest(handleParcelAccessRequest);
  82. client.OnParcelAccessListUpdateRequest += new ParcelAccessListUpdateRequest(handleParcelAccessUpdateRequest);
  83. client.OnParcelAbandonRequest += new ParcelAbandonRequest(handleParcelAbandonRequest);
  84. client.OnParcelReclaim += new ParcelReclaim(handleParcelReclaim);
  85. if (m_scene.Entities.ContainsKey(client.AgentId))
  86. {
  87. SendLandUpdate((ScenePresence)m_scene.Entities[client.AgentId], true);
  88. SendParcelOverlay(client);
  89. }
  90. }
  91. public void PostInitialise()
  92. {
  93. }
  94. public void Close()
  95. {
  96. }
  97. public string Name
  98. {
  99. get { return "LandManagementModule"; }
  100. }
  101. public bool IsSharedModule
  102. {
  103. get { return false; }
  104. }
  105. #endregion
  106. #region Parcel Add/Remove/Get/Create
  107. public void SetAllowedForcefulBans(bool forceful)
  108. {
  109. AllowedForcefulBans = forceful;
  110. }
  111. public void UpdateLandObject(int local_id, LandData newData)
  112. {
  113. if (landList.ContainsKey(local_id))
  114. {
  115. landList[local_id].landData = newData.Copy();
  116. m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, landList[local_id]);
  117. }
  118. }
  119. public bool AllowedForcefulBans
  120. {
  121. get { return m_allowedForcefulBans; }
  122. set { m_allowedForcefulBans = value; }
  123. }
  124. /// <summary>
  125. /// Resets the sim to the default land object (full sim piece of land owned by the default user)
  126. /// </summary>
  127. public void ResetSimLandObjects()
  128. {
  129. //Remove all the land objects in the sim and add a blank, full sim land object set to public
  130. landList.Clear();
  131. lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  132. landIDList.Initialize();
  133. ILandObject fullSimParcel = new LandObject(LLUUID.Zero, false, m_scene);
  134. fullSimParcel.setLandBitmap(fullSimParcel.getSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
  135. fullSimParcel.landData.ownerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  136. fullSimParcel.landData.claimDate = Util.UnixTimeSinceEpoch();
  137. AddLandObject(fullSimParcel);
  138. }
  139. public List<ILandObject> ParcelsNearPoint(LLVector3 position)
  140. {
  141. List<ILandObject> parcelsNear = new List<ILandObject>();
  142. int x;
  143. for (x = -4; x <= 4; x += 4)
  144. {
  145. int y;
  146. for (y = -4; y <= 4; y += 4)
  147. {
  148. ILandObject check = GetLandObject(position.X + x, position.Y + y);
  149. if (check != null)
  150. {
  151. if (!parcelsNear.Contains(check))
  152. {
  153. parcelsNear.Add(check);
  154. }
  155. }
  156. }
  157. }
  158. return parcelsNear;
  159. }
  160. public void SendYouAreBannedNotice(ScenePresence avatar)
  161. {
  162. if (AllowedForcefulBans)
  163. {
  164. avatar.ControllingClient.SendAlertMessage(
  165. "You are not allowed on this parcel because you are banned. Please go away. <3 OpenSim Developers");
  166. avatar.PhysicsActor.Position =
  167. new PhysicsVector(avatar.lastKnownAllowedPosition.x, avatar.lastKnownAllowedPosition.y,
  168. avatar.lastKnownAllowedPosition.z);
  169. avatar.PhysicsActor.Velocity = new PhysicsVector(0, 0, 0);
  170. }
  171. else
  172. {
  173. avatar.ControllingClient.SendAlertMessage(
  174. "You are not allowed on this parcel because you are banned; however, the grid administrator has disabled ban lines globally. Please obey the land owner's requests or you can be banned from the entire sim! <3 OpenSim Developers");
  175. }
  176. }
  177. public void handleAvatarChangingParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
  178. {
  179. if (m_scene.RegionInfo.RegionID == regionID)
  180. {
  181. if (landList[localLandID] != null)
  182. {
  183. ILandObject parcelAvatarIsEntering = landList[localLandID];
  184. if (avatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT)
  185. {
  186. if (parcelAvatarIsEntering.isBannedFromLand(avatar.UUID))
  187. {
  188. SendYouAreBannedNotice(avatar);
  189. }
  190. else if (parcelAvatarIsEntering.isRestrictedFromLand(avatar.UUID))
  191. {
  192. avatar.ControllingClient.SendAlertMessage(
  193. "You are not allowed on this parcel because the land owner has restricted access. For now, you can enter, but please respect the land owner's decisions (or he can ban you!). <3 OpenSim Developers");
  194. }
  195. else
  196. {
  197. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  198. }
  199. }
  200. else
  201. {
  202. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  203. }
  204. }
  205. }
  206. }
  207. public void SendOutNearestBanLine(IClientAPI avatar)
  208. {
  209. List<ScenePresence> avatars = m_scene.GetAvatars();
  210. foreach (ScenePresence presence in avatars)
  211. {
  212. if (presence.UUID == avatar.AgentId)
  213. {
  214. List<ILandObject> checkLandParcels = ParcelsNearPoint(presence.AbsolutePosition);
  215. foreach (ILandObject checkBan in checkLandParcels)
  216. {
  217. if (checkBan.isBannedFromLand(avatar.AgentId))
  218. {
  219. checkBan.sendLandProperties(-30000, false, (int)ParcelManager.ParcelResult.Single, avatar);
  220. return; //Only send one
  221. }
  222. if (checkBan.isRestrictedFromLand(avatar.AgentId))
  223. {
  224. checkBan.sendLandProperties(-40000, false, (int)ParcelManager.ParcelResult.Single, avatar);
  225. return; //Only send one
  226. }
  227. }
  228. return;
  229. }
  230. }
  231. }
  232. public void SendLandUpdate(ScenePresence avatar, bool force)
  233. {
  234. ILandObject over = GetLandObject((int)Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
  235. (int)Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
  236. if (over != null)
  237. {
  238. if (force)
  239. {
  240. if (!avatar.IsChildAgent)
  241. {
  242. over.sendLandUpdateToClient(avatar.ControllingClient);
  243. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.localID,
  244. m_scene.RegionInfo.RegionID);
  245. }
  246. }
  247. if (avatar.currentParcelUUID != over.landData.globalID)
  248. {
  249. if (!avatar.IsChildAgent)
  250. {
  251. over.sendLandUpdateToClient(avatar.ControllingClient);
  252. avatar.currentParcelUUID = over.landData.globalID;
  253. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.localID,
  254. m_scene.RegionInfo.RegionID);
  255. }
  256. }
  257. }
  258. }
  259. public void SendLandUpdate(ScenePresence avatar)
  260. {
  261. SendLandUpdate(avatar, false);
  262. }
  263. public void handleSignificantClientMovement(IClientAPI remote_client)
  264. {
  265. ScenePresence clientAvatar = m_scene.GetScenePresence(remote_client.AgentId);
  266. if (clientAvatar != null)
  267. {
  268. SendLandUpdate(clientAvatar);
  269. SendOutNearestBanLine(remote_client);
  270. ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
  271. if (parcel != null)
  272. {
  273. if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  274. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
  275. {
  276. handleAvatarChangingParcel(clientAvatar, parcel.landData.localID, m_scene.RegionInfo.RegionID);
  277. //They are going below the safety line!
  278. if (!parcel.isBannedFromLand(clientAvatar.UUID))
  279. {
  280. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
  281. }
  282. }
  283. else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  284. parcel.isBannedFromLand(clientAvatar.UUID))
  285. {
  286. SendYouAreBannedNotice(clientAvatar);
  287. }
  288. }
  289. }
  290. }
  291. public void handleAnyClientMovement(ScenePresence avatar)
  292. //Like handleSignificantClientMovement, but called with an AgentUpdate regardless of distance.
  293. {
  294. ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  295. if (over != null)
  296. {
  297. if (!over.isBannedFromLand(avatar.UUID) || avatar.AbsolutePosition.Z >= LandChannel.BAN_LINE_SAFETY_HIEGHT)
  298. {
  299. avatar.lastKnownAllowedPosition =
  300. new Vector3(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
  301. }
  302. }
  303. }
  304. public void handleParcelAccessRequest(LLUUID agentID, LLUUID sessionID, uint flags, int sequenceID,
  305. int landLocalID, IClientAPI remote_client)
  306. {
  307. if (landList.ContainsKey(landLocalID))
  308. {
  309. landList[landLocalID].sendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
  310. }
  311. }
  312. public void handleParcelAccessUpdateRequest(LLUUID agentID, LLUUID sessionID, uint flags, int landLocalID,
  313. List<ParcelManager.ParcelAccessEntry> entries,
  314. IClientAPI remote_client)
  315. {
  316. if (landList.ContainsKey(landLocalID))
  317. {
  318. if (agentID == landList[landLocalID].landData.ownerID)
  319. {
  320. landList[landLocalID].updateAccessList(flags, entries, remote_client);
  321. }
  322. }
  323. else
  324. {
  325. Console.WriteLine("INVALID LOCAL LAND ID");
  326. }
  327. }
  328. /// <summary>
  329. /// Creates a basic Parcel object without an owner (a zeroed key)
  330. /// </summary>
  331. /// <returns></returns>
  332. public ILandObject CreateBaseLand()
  333. {
  334. return new LandObject(LLUUID.Zero, false, m_scene);
  335. }
  336. /// <summary>
  337. /// Adds a land object to the stored list and adds them to the landIDList to what they own
  338. /// </summary>
  339. /// <param name="new_land">The land object being added</param>
  340. public ILandObject AddLandObject(ILandObject new_land)
  341. {
  342. lastLandLocalID++;
  343. new_land.landData.localID = lastLandLocalID;
  344. landList.Add(lastLandLocalID, new_land.Copy());
  345. bool[,] landBitmap = new_land.getLandBitmap();
  346. int x;
  347. for (x = 0; x < 64; x++)
  348. {
  349. int y;
  350. for (y = 0; y < 64; y++)
  351. {
  352. if (landBitmap[x, y])
  353. {
  354. landIDList[x, y] = lastLandLocalID;
  355. }
  356. }
  357. }
  358. landList[lastLandLocalID].forceUpdateLandInfo();
  359. m_scene.EventManager.TriggerLandObjectAdded(new_land);
  360. return new_land;
  361. }
  362. /// <summary>
  363. /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
  364. /// </summary>
  365. /// <param name="local_id">Land.localID of the peice of land to remove.</param>
  366. public void removeLandObject(int local_id)
  367. {
  368. int x;
  369. for (x = 0; x < 64; x++)
  370. {
  371. int y;
  372. for (y = 0; y < 64; y++)
  373. {
  374. if (landIDList[x, y] == local_id)
  375. {
  376. return;
  377. //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
  378. }
  379. }
  380. }
  381. m_scene.EventManager.TriggerLandObjectRemoved(landList[local_id].landData.globalID);
  382. landList.Remove(local_id);
  383. }
  384. private void performFinalLandJoin(ILandObject master, ILandObject slave)
  385. {
  386. int x;
  387. bool[,] landBitmapSlave = slave.getLandBitmap();
  388. for (x = 0; x < 64; x++)
  389. {
  390. int y;
  391. for (y = 0; y < 64; y++)
  392. {
  393. if (landBitmapSlave[x, y])
  394. {
  395. landIDList[x, y] = master.landData.localID;
  396. }
  397. }
  398. }
  399. removeLandObject(slave.landData.localID);
  400. UpdateLandObject(master.landData.localID, master.landData);
  401. }
  402. public ILandObject GetLandObject(int parcelLocalID)
  403. {
  404. lock (landList)
  405. {
  406. if (landList.ContainsKey(parcelLocalID))
  407. {
  408. return landList[parcelLocalID];
  409. }
  410. }
  411. return null;
  412. }
  413. /// <summary>
  414. /// Get the land object at the specified point
  415. /// </summary>
  416. /// <param name="x_float">Value between 0 - 256 on the x axis of the point</param>
  417. /// <param name="y_float">Value between 0 - 256 on the y axis of the point</param>
  418. /// <returns>Land object at the point supplied</returns>
  419. public ILandObject GetLandObject(float x_float, float y_float)
  420. {
  421. int x;
  422. int y;
  423. try
  424. {
  425. x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / Convert.ToDouble(4.0)));
  426. y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / Convert.ToDouble(4.0)));
  427. }
  428. catch (OverflowException)
  429. {
  430. return null;
  431. }
  432. if (x >= 64 || y >= 64 || x < 0 || y < 0)
  433. {
  434. return null;
  435. }
  436. return landList[landIDList[x, y]];
  437. }
  438. public ILandObject GetLandObject(int x, int y)
  439. {
  440. if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0)
  441. {
  442. // These exceptions here will cause a lot of complaints from the users specifically because
  443. // they happen every time at border crossings
  444. throw new Exception("Error: Parcel not found at point " + x + ", " + y);
  445. }
  446. return landList[landIDList[x / 4, y / 4]];
  447. }
  448. #endregion
  449. #region Parcel Modification
  450. public void ResetAllLandPrimCounts()
  451. {
  452. foreach (LandObject p in landList.Values)
  453. {
  454. p.resetLandPrimCounts();
  455. }
  456. }
  457. public void SetPrimsTainted()
  458. {
  459. landPrimCountTainted = true;
  460. }
  461. public bool IsLandPrimCountTainted()
  462. {
  463. return landPrimCountTainted;
  464. }
  465. public void AddPrimToLandPrimCounts(SceneObjectGroup obj)
  466. {
  467. LLVector3 position = obj.AbsolutePosition;
  468. ILandObject landUnderPrim = GetLandObject(position.X, position.Y);
  469. if (landUnderPrim != null)
  470. {
  471. landUnderPrim.addPrimToCount(obj);
  472. }
  473. }
  474. public void RemovePrimFromLandPrimCounts(SceneObjectGroup obj)
  475. {
  476. foreach (LandObject p in landList.Values)
  477. {
  478. p.removePrimFromCount(obj);
  479. }
  480. }
  481. public void FinalizeLandPrimCountUpdate()
  482. {
  483. //Get Simwide prim count for owner
  484. Dictionary<LLUUID, List<LandObject>> landOwnersAndParcels = new Dictionary<LLUUID, List<LandObject>>();
  485. foreach (LandObject p in landList.Values)
  486. {
  487. if (!landOwnersAndParcels.ContainsKey(p.landData.ownerID))
  488. {
  489. List<LandObject> tempList = new List<LandObject>();
  490. tempList.Add(p);
  491. landOwnersAndParcels.Add(p.landData.ownerID, tempList);
  492. }
  493. else
  494. {
  495. landOwnersAndParcels[p.landData.ownerID].Add(p);
  496. }
  497. }
  498. foreach (LLUUID owner in landOwnersAndParcels.Keys)
  499. {
  500. int simArea = 0;
  501. int simPrims = 0;
  502. foreach (LandObject p in landOwnersAndParcels[owner])
  503. {
  504. simArea += p.landData.area;
  505. simPrims += p.landData.ownerPrims + p.landData.otherPrims + p.landData.groupPrims +
  506. p.landData.selectedPrims;
  507. }
  508. foreach (LandObject p in landOwnersAndParcels[owner])
  509. {
  510. p.landData.simwideArea = simArea;
  511. p.landData.simwidePrims = simPrims;
  512. }
  513. }
  514. }
  515. public void UpdateLandPrimCounts()
  516. {
  517. ResetAllLandPrimCounts();
  518. lock (m_scene.Entities)
  519. {
  520. foreach (EntityBase obj in m_scene.Entities.Values)
  521. {
  522. if (obj != null)
  523. {
  524. if (obj is SceneObjectGroup)
  525. {
  526. m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup)obj);
  527. }
  528. }
  529. }
  530. }
  531. FinalizeLandPrimCountUpdate();
  532. landPrimCountTainted = false;
  533. }
  534. public void PerformParcelPrimCountUpdate()
  535. {
  536. ResetAllLandPrimCounts();
  537. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  538. FinalizeLandPrimCountUpdate();
  539. landPrimCountTainted = false;
  540. }
  541. /// <summary>
  542. /// Subdivides a piece of land
  543. /// </summary>
  544. /// <param name="start_x">West Point</param>
  545. /// <param name="start_y">South Point</param>
  546. /// <param name="end_x">East Point</param>
  547. /// <param name="end_y">North Point</param>
  548. /// <param name="attempting_user_id">LLUUID of user who is trying to subdivide</param>
  549. /// <returns>Returns true if successful</returns>
  550. private void subdivide(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
  551. {
  552. //First, lets loop through the points and make sure they are all in the same peice of land
  553. //Get the land object at start
  554. ILandObject startLandObject = GetLandObject(start_x, start_y);
  555. if (startLandObject == null) return;
  556. //Loop through the points
  557. try
  558. {
  559. int totalX = end_x - start_x;
  560. int totalY = end_y - start_y;
  561. int y;
  562. for (y = 0; y < totalY; y++)
  563. {
  564. int x;
  565. for (x = 0; x < totalX; x++)
  566. {
  567. ILandObject tempLandObject = GetLandObject(start_x + x, start_y + y);
  568. if (tempLandObject == null) return;
  569. if (tempLandObject != startLandObject) return;
  570. }
  571. }
  572. }
  573. catch (Exception)
  574. {
  575. return;
  576. }
  577. //If we are still here, then they are subdividing within one piece of land
  578. //Check owner
  579. if (!m_scene.ExternalChecks.ExternalChecksCanEditParcel(attempting_user_id, startLandObject))
  580. {
  581. return;
  582. }
  583. //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
  584. ILandObject newLand = startLandObject.Copy();
  585. newLand.landData.landName = "Subdivision of " + newLand.landData.landName;
  586. newLand.landData.globalID = LLUUID.Random();
  587. newLand.setLandBitmap(newLand.getSquareLandBitmap(start_x, start_y, end_x, end_y));
  588. //Now, lets set the subdivision area of the original to false
  589. int startLandObjectIndex = startLandObject.landData.localID;
  590. landList[startLandObjectIndex].setLandBitmap(
  591. newLand.modifyLandBitmapSquare(startLandObject.getLandBitmap(), start_x, start_y, end_x, end_y, false));
  592. landList[startLandObjectIndex].forceUpdateLandInfo();
  593. SetPrimsTainted();
  594. //Now add the new land object
  595. ILandObject result = AddLandObject(newLand);
  596. UpdateLandObject(startLandObject.landData.localID, startLandObject.landData);
  597. result.sendLandUpdateToAvatarsOverMe();
  598. return;
  599. }
  600. /// <summary>
  601. /// Join 2 land objects together
  602. /// </summary>
  603. /// <param name="start_x">x value in first piece of land</param>
  604. /// <param name="start_y">y value in first piece of land</param>
  605. /// <param name="end_x">x value in second peice of land</param>
  606. /// <param name="end_y">y value in second peice of land</param>
  607. /// <param name="attempting_user_id">LLUUID of the avatar trying to join the land objects</param>
  608. /// <returns>Returns true if successful</returns>
  609. private void join(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
  610. {
  611. end_x -= 4;
  612. end_y -= 4;
  613. List<ILandObject> selectedLandObjects = new List<ILandObject>();
  614. int stepYSelected;
  615. for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
  616. {
  617. int stepXSelected;
  618. for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
  619. {
  620. ILandObject p = GetLandObject(stepXSelected, stepYSelected);
  621. if (p != null)
  622. {
  623. if (!selectedLandObjects.Contains(p))
  624. {
  625. selectedLandObjects.Add(p);
  626. }
  627. }
  628. }
  629. }
  630. ILandObject masterLandObject = selectedLandObjects[0];
  631. selectedLandObjects.RemoveAt(0);
  632. if (selectedLandObjects.Count < 1)
  633. {
  634. return;
  635. }
  636. if (!m_scene.ExternalChecks.ExternalChecksCanEditParcel(attempting_user_id, masterLandObject))
  637. {
  638. return;
  639. }
  640. foreach (ILandObject p in selectedLandObjects)
  641. {
  642. if (p.landData.ownerID != masterLandObject.landData.ownerID)
  643. {
  644. return;
  645. }
  646. }
  647. foreach (ILandObject slaveLandObject in selectedLandObjects)
  648. {
  649. landList[masterLandObject.landData.localID].setLandBitmap(
  650. slaveLandObject.mergeLandBitmaps(masterLandObject.getLandBitmap(), slaveLandObject.getLandBitmap()));
  651. performFinalLandJoin(masterLandObject, slaveLandObject);
  652. }
  653. SetPrimsTainted();
  654. masterLandObject.sendLandUpdateToAvatarsOverMe();
  655. return;
  656. }
  657. #endregion
  658. #region Parcel Updating
  659. /// <summary>
  660. /// Where we send the ParcelOverlay packet to the client
  661. /// </summary>
  662. /// <param name="remote_client">The object representing the client</param>
  663. public void SendParcelOverlay(IClientAPI remote_client)
  664. {
  665. const int LAND_BLOCKS_PER_PACKET = 1024;
  666. byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  667. int byteArrayCount = 0;
  668. int sequenceID = 0;
  669. int y;
  670. for (y = 0; y < 64; y++)
  671. {
  672. int x;
  673. for (x = 0; x < 64; x++)
  674. {
  675. byte tempByte = 0; //This represents the byte for the current 4x4
  676. ILandObject currentParcelBlock = GetLandObject(x * 4, y * 4);
  677. if (currentParcelBlock != null)
  678. {
  679. if (currentParcelBlock.landData.ownerID == remote_client.AgentId)
  680. {
  681. //Owner Flag
  682. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
  683. }
  684. else if (currentParcelBlock.landData.salePrice > 0 &&
  685. (currentParcelBlock.landData.authBuyerID == LLUUID.Zero ||
  686. currentParcelBlock.landData.authBuyerID == remote_client.AgentId))
  687. {
  688. //Sale Flag
  689. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
  690. }
  691. else if (currentParcelBlock.landData.ownerID == LLUUID.Zero)
  692. {
  693. //Public Flag
  694. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
  695. }
  696. else
  697. {
  698. //Other Flag
  699. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
  700. }
  701. //Now for border control
  702. ILandObject westParcel = null;
  703. ILandObject southParcel = null;
  704. if (x > 0)
  705. {
  706. westParcel = GetLandObject((x - 1) * 4, y * 4);
  707. }
  708. if (y > 0)
  709. {
  710. southParcel = GetLandObject(x * 4, (y - 1) * 4);
  711. }
  712. if (x == 0)
  713. {
  714. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  715. }
  716. else if (westParcel != null && westParcel != currentParcelBlock)
  717. {
  718. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  719. }
  720. if (y == 0)
  721. {
  722. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  723. }
  724. else if (southParcel != null && southParcel != currentParcelBlock)
  725. {
  726. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  727. }
  728. byteArray[byteArrayCount] = tempByte;
  729. byteArrayCount++;
  730. if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
  731. {
  732. remote_client.SendLandParcelOverlay(byteArray, sequenceID);
  733. byteArrayCount = 0;
  734. sequenceID++;
  735. byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  736. }
  737. }
  738. }
  739. }
  740. }
  741. public void handleParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
  742. bool snap_selection, IClientAPI remote_client)
  743. {
  744. //Get the land objects within the bounds
  745. List<ILandObject> temp = new List<ILandObject>();
  746. int x;
  747. int i;
  748. int inc_x = end_x - start_x;
  749. int inc_y = end_y - start_y;
  750. for (x = 0; x < inc_x; x++)
  751. {
  752. int y;
  753. for (y = 0; y < inc_y; y++)
  754. {
  755. ILandObject currentParcel = GetLandObject(start_x + x, start_y + y);
  756. if (currentParcel != null)
  757. {
  758. if (!temp.Contains(currentParcel))
  759. {
  760. currentParcel.forceUpdateLandInfo();
  761. temp.Add(currentParcel);
  762. }
  763. }
  764. }
  765. }
  766. int requestResult = LandChannel.LAND_RESULT_SINGLE;
  767. if (temp.Count > 1)
  768. {
  769. requestResult = LandChannel.LAND_RESULT_MULTIPLE;
  770. }
  771. for (i = 0; i < temp.Count; i++)
  772. {
  773. temp[i].sendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
  774. }
  775. SendParcelOverlay(remote_client);
  776. }
  777. public void handleParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
  778. {
  779. if (landList.ContainsKey(localID))
  780. {
  781. landList[localID].updateLandProperties(args, remote_client);
  782. }
  783. }
  784. public void handleParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
  785. {
  786. subdivide(west, south, east, north, remote_client.AgentId);
  787. }
  788. public void handleParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
  789. {
  790. join(west, south, east, north, remote_client.AgentId);
  791. }
  792. public void handleParcelSelectObjectsRequest(int local_id, int request_type, IClientAPI remote_client)
  793. {
  794. landList[local_id].sendForceObjectSelect(local_id, request_type, remote_client);
  795. }
  796. public void handleParcelObjectOwnersRequest(int local_id, IClientAPI remote_client)
  797. {
  798. lock (landList)
  799. {
  800. if (landList.ContainsKey(local_id))
  801. {
  802. landList[local_id].sendLandObjectOwners(remote_client);
  803. }
  804. else
  805. {
  806. System.Console.WriteLine("[PARCEL]: Invalid land object passed for parcel object owner request");
  807. }
  808. }
  809. }
  810. public void handleParcelAbandonRequest(int local_id, IClientAPI remote_client)
  811. {
  812. if (landList.ContainsKey(local_id))
  813. {
  814. if (m_scene.ExternalChecks.ExternalChecksCanAbandonParcel(remote_client.AgentId, landList[local_id]))
  815. {
  816. landList[local_id].landData.ownerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  817. m_scene.Broadcast(SendParcelOverlay);
  818. landList[local_id].sendLandUpdateToClient(remote_client);
  819. }
  820. }
  821. }
  822. public void handleParcelReclaim(int local_id, IClientAPI remote_client)
  823. {
  824. if (landList.ContainsKey(local_id))
  825. {
  826. if (m_scene.ExternalChecks.ExternalChecksCanReclaimParcel(remote_client.AgentId, landList[local_id]))
  827. {
  828. landList[local_id].landData.ownerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  829. landList[local_id].landData.claimDate = Util.UnixTimeSinceEpoch();
  830. m_scene.Broadcast(SendParcelOverlay);
  831. landList[local_id].sendLandUpdateToClient(remote_client);
  832. }
  833. }
  834. }
  835. #endregion
  836. // If the economy has been validated by the economy module,
  837. // and land has been validated as well, this method transfers
  838. // the land ownership
  839. public void handleLandBuyRequest(Object o, EventManager.LandBuyArgs e)
  840. {
  841. if (e.economyValidated && e.landValidated)
  842. {
  843. lock (landList)
  844. {
  845. if (landList.ContainsKey(e.parcelLocalID))
  846. {
  847. landList[e.parcelLocalID].updateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea);
  848. return;
  849. }
  850. }
  851. }
  852. }
  853. // After receiving a land buy packet, first the data needs to
  854. // be validated. This method validates the right to buy the
  855. // parcel
  856. public void handleLandValidationRequest(Object o, EventManager.LandBuyArgs e)
  857. {
  858. if (e.landValidated == false)
  859. {
  860. ILandObject lob = null;
  861. lock (landList)
  862. {
  863. if (landList.ContainsKey(e.parcelLocalID))
  864. {
  865. lob = landList[e.parcelLocalID];
  866. }
  867. }
  868. if (lob != null)
  869. {
  870. LLUUID AuthorizedID = lob.landData.authBuyerID;
  871. int saleprice = lob.landData.salePrice;
  872. LLUUID pOwnerID = lob.landData.ownerID;
  873. bool landforsale = ((lob.landData.landFlags &
  874. (uint)(Parcel.ParcelFlags.ForSale | Parcel.ParcelFlags.ForSaleObjects | Parcel.ParcelFlags.SellParcelObjects)) != 0);
  875. if ((AuthorizedID == LLUUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
  876. {
  877. lock (e)
  878. {
  879. e.parcelOwnerID = pOwnerID;
  880. e.landValidated = true;
  881. }
  882. }
  883. }
  884. }
  885. }
  886. #region Land Object From Storage Functions
  887. public void IncomingLandObjectsFromStorage(List<LandData> data)
  888. {
  889. for (int i = 0; i < data.Count; i++)
  890. {
  891. //try
  892. //{
  893. IncomingLandObjectFromStorage(data[i]);
  894. //}
  895. //catch (Exception ex)
  896. //{
  897. //m_log.Error("[LandManager]: IncomingLandObjectsFromStorage: Exception: " + ex.ToString());
  898. //throw ex;
  899. //}
  900. }
  901. //foreach (LandData parcel in data)
  902. //{
  903. // IncomingLandObjectFromStorage(parcel);
  904. //}
  905. }
  906. public void IncomingLandObjectFromStorage(LandData data)
  907. {
  908. ILandObject new_land = new LandObject(data.ownerID, data.isGroupOwned, m_scene);
  909. new_land.landData = data.Copy();
  910. new_land.setLandBitmapFromByteArray();
  911. AddLandObject(new_land);
  912. }
  913. public void ReturnObjectsInParcel(int localID, uint returnType, LLUUID[] agentIDs, LLUUID[] taskIDs, IClientAPI remoteClient)
  914. {
  915. ILandObject selectedParcel = null;
  916. lock (landList)
  917. {
  918. if (landList.ContainsKey(localID))
  919. selectedParcel = landList[localID];
  920. }
  921. if (selectedParcel == null)
  922. return;
  923. if (returnType == 16) // parcel return
  924. {
  925. selectedParcel.returnLandObjects(returnType, agentIDs, remoteClient);
  926. }
  927. }
  928. public void NoLandDataFromStorage()
  929. {
  930. ResetSimLandObjects();
  931. }
  932. #endregion
  933. public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  934. {
  935. foreach (LandObject obj in landList.Values)
  936. {
  937. obj.setParcelObjectMaxOverride(overrideDel);
  938. }
  939. }
  940. public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  941. {
  942. }
  943. }
  944. }