LandManagementModule.cs 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenSim.Region.Environment.Interfaces;
  35. using OpenSim.Region.Environment.Scenes;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Servers;
  38. using OpenSim.Framework.Communications.Capabilities;
  39. using OpenSim.Region.Physics.Manager;
  40. using Caps = OpenSim.Framework.Communications.Capabilities.Caps;
  41. namespace OpenSim.Region.Environment.Modules.World.Land
  42. {
  43. // used for caching
  44. internal class ExtendedLandData {
  45. public LandData landData;
  46. public ulong regionHandle;
  47. public uint x, y;
  48. }
  49. public class LandManagementModule : IRegionModule
  50. {
  51. private static readonly ILog m_log =
  52. LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  53. private static readonly string remoteParcelRequestPath = "0009/";
  54. private LandChannel landChannel;
  55. private Scene m_scene;
  56. private readonly int[,] m_landIDList = new int[64, 64];
  57. private readonly Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>();
  58. private bool m_landPrimCountTainted;
  59. private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  60. private bool m_allowedForcefulBans = true;
  61. // caches ExtendedLandData
  62. private Cache parcelInfoCache;
  63. #region IRegionModule Members
  64. public void Initialise(Scene scene, IConfigSource source)
  65. {
  66. m_scene = scene;
  67. m_landIDList.Initialize();
  68. landChannel = new LandChannel(scene, this);
  69. parcelInfoCache = new Cache();
  70. parcelInfoCache.Size = 30; // the number of different parcel requests in this region to cache
  71. parcelInfoCache.DefaultTTL = new TimeSpan(0, 5, 0);
  72. m_scene.EventManager.OnParcelPrimCountAdd += AddPrimToLandPrimCounts;
  73. m_scene.EventManager.OnParcelPrimCountUpdate += UpdateLandPrimCounts;
  74. m_scene.EventManager.OnAvatarEnteringNewParcel += new EventManager.AvatarEnteringNewParcel(handleAvatarChangingParcel);
  75. m_scene.EventManager.OnClientMovement += new EventManager.ClientMovement(handleAnyClientMovement);
  76. m_scene.EventManager.OnValidateLandBuy += handleLandValidationRequest;
  77. m_scene.EventManager.OnLandBuy += handleLandBuyRequest;
  78. m_scene.EventManager.OnNewClient += new EventManager.OnNewClientDelegate(EventManager_OnNewClient);
  79. m_scene.EventManager.OnSignificantClientMovement += handleSignificantClientMovement;
  80. m_scene.EventManager.OnObjectBeingRemovedFromScene += RemovePrimFromLandPrimCounts;
  81. m_scene.EventManager.OnNoticeNoLandDataFromStorage += this.NoLandDataFromStorage;
  82. m_scene.EventManager.OnIncomingLandDataFromStorage += this.IncomingLandObjectsFromStorage;
  83. m_scene.EventManager.OnSetAllowForcefulBan += this.SetAllowedForcefulBans;
  84. m_scene.EventManager.OnRequestParcelPrimCountUpdate += this.PerformParcelPrimCountUpdate;
  85. m_scene.EventManager.OnParcelPrimCountTainted += this.SetPrimsTainted;
  86. m_scene.EventManager.OnRegisterCaps += this.OnRegisterCaps;
  87. lock (m_scene)
  88. {
  89. m_scene.LandChannel = (ILandChannel) landChannel;
  90. }
  91. }
  92. void EventManager_OnNewClient(IClientAPI client)
  93. {
  94. //Register some client events
  95. client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(handleParcelPropertiesRequest);
  96. client.OnParcelDivideRequest += new ParcelDivideRequest(handleParcelDivideRequest);
  97. client.OnParcelJoinRequest += new ParcelJoinRequest(handleParcelJoinRequest);
  98. client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(handleParcelPropertiesUpdateRequest);
  99. client.OnParcelSelectObjects += new ParcelSelectObjects(handleParcelSelectObjectsRequest);
  100. client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(handleParcelObjectOwnersRequest);
  101. client.OnParcelAccessListRequest += new ParcelAccessListRequest(handleParcelAccessRequest);
  102. client.OnParcelAccessListUpdateRequest += new ParcelAccessListUpdateRequest(handleParcelAccessUpdateRequest);
  103. client.OnParcelAbandonRequest += new ParcelAbandonRequest(handleParcelAbandonRequest);
  104. client.OnParcelGodForceOwner += new ParcelGodForceOwner(handleParcelGodForceOwner);
  105. client.OnParcelReclaim += new ParcelReclaim(handleParcelReclaim);
  106. client.OnParcelInfoRequest += new ParcelInfoRequest(handleParcelInfo);
  107. client.OnParcelDwellRequest += new ParcelDwellRequest(handleParcelDwell);
  108. if (m_scene.Entities.ContainsKey(client.AgentId))
  109. {
  110. SendLandUpdate((ScenePresence)m_scene.Entities[client.AgentId], true);
  111. SendParcelOverlay(client);
  112. }
  113. }
  114. public void PostInitialise()
  115. {
  116. }
  117. public void Close()
  118. {
  119. }
  120. public string Name
  121. {
  122. get { return "LandManagementModule"; }
  123. }
  124. public bool IsSharedModule
  125. {
  126. get { return false; }
  127. }
  128. #endregion
  129. #region Parcel Add/Remove/Get/Create
  130. public void SetAllowedForcefulBans(bool forceful)
  131. {
  132. AllowedForcefulBans = forceful;
  133. }
  134. public void UpdateLandObject(int local_id, LandData data)
  135. {
  136. LandData newData = data.Copy();
  137. newData.LocalID = local_id;
  138. lock (m_landList)
  139. {
  140. if (m_landList.ContainsKey(local_id))
  141. {
  142. m_landList[local_id].landData = newData;
  143. m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, m_landList[local_id]);
  144. }
  145. }
  146. }
  147. public bool AllowedForcefulBans
  148. {
  149. get { return m_allowedForcefulBans; }
  150. set { m_allowedForcefulBans = value; }
  151. }
  152. /// <summary>
  153. /// Resets the sim to the default land object (full sim piece of land owned by the default user)
  154. /// </summary>
  155. public void ResetSimLandObjects()
  156. {
  157. //Remove all the land objects in the sim and add a blank, full sim land object set to public
  158. lock (m_landList)
  159. {
  160. m_landList.Clear();
  161. m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  162. m_landIDList.Initialize();
  163. }
  164. ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
  165. fullSimParcel.setLandBitmap(fullSimParcel.getSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
  166. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  167. fullSimParcel.landData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  168. else
  169. fullSimParcel.landData.OwnerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  170. fullSimParcel.landData.ClaimDate = Util.UnixTimeSinceEpoch();
  171. AddLandObject(fullSimParcel);
  172. }
  173. public List<ILandObject> AllParcels()
  174. {
  175. lock (m_landList)
  176. {
  177. return new List<ILandObject>(m_landList.Values);
  178. }
  179. }
  180. public List<ILandObject> ParcelsNearPoint(Vector3 position)
  181. {
  182. List<ILandObject> parcelsNear = new List<ILandObject>();
  183. for (int x = -4; x <= 4; x += 4)
  184. {
  185. for (int y = -4; y <= 4; y += 4)
  186. {
  187. ILandObject check = GetLandObject(position.X + x, position.Y + y);
  188. if (check != null)
  189. {
  190. if (!parcelsNear.Contains(check))
  191. {
  192. parcelsNear.Add(check);
  193. }
  194. }
  195. }
  196. }
  197. return parcelsNear;
  198. }
  199. public void SendYouAreBannedNotice(ScenePresence avatar)
  200. {
  201. if (AllowedForcefulBans)
  202. {
  203. avatar.ControllingClient.SendAlertMessage(
  204. "You are not allowed on this parcel because you are banned. Please go away.");
  205. avatar.PhysicsActor.Position =
  206. new PhysicsVector(avatar.lastKnownAllowedPosition.X, avatar.lastKnownAllowedPosition.Y,
  207. avatar.lastKnownAllowedPosition.Z);
  208. avatar.PhysicsActor.Velocity = new PhysicsVector(0, 0, 0);
  209. }
  210. else
  211. {
  212. avatar.ControllingClient.SendAlertMessage(
  213. "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!");
  214. }
  215. }
  216. public void handleAvatarChangingParcel(ScenePresence avatar, int localLandID, UUID regionID)
  217. {
  218. if (m_scene.RegionInfo.RegionID == regionID)
  219. {
  220. ILandObject parcelAvatarIsEntering;
  221. lock (m_landList)
  222. {
  223. parcelAvatarIsEntering = m_landList[localLandID];
  224. }
  225. if (parcelAvatarIsEntering != null)
  226. {
  227. if (avatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT)
  228. {
  229. if (parcelAvatarIsEntering.isBannedFromLand(avatar.UUID))
  230. {
  231. SendYouAreBannedNotice(avatar);
  232. }
  233. else if (parcelAvatarIsEntering.isRestrictedFromLand(avatar.UUID))
  234. {
  235. avatar.ControllingClient.SendAlertMessage(
  236. "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!).");
  237. }
  238. else
  239. {
  240. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  241. }
  242. }
  243. else
  244. {
  245. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  246. }
  247. }
  248. }
  249. }
  250. public void SendOutNearestBanLine(IClientAPI avatar)
  251. {
  252. List<ScenePresence> avatars = m_scene.GetAvatars();
  253. foreach (ScenePresence presence in avatars)
  254. {
  255. if (presence.UUID == avatar.AgentId)
  256. {
  257. List<ILandObject> checkLandParcels = ParcelsNearPoint(presence.AbsolutePosition);
  258. foreach (ILandObject checkBan in checkLandParcels)
  259. {
  260. if (checkBan.isBannedFromLand(avatar.AgentId))
  261. {
  262. checkBan.sendLandProperties((int)ParcelStatus.CollisionBanned, false, (int)ParcelResult.Single, avatar);
  263. return; //Only send one
  264. }
  265. if (checkBan.isRestrictedFromLand(avatar.AgentId))
  266. {
  267. checkBan.sendLandProperties((int)ParcelStatus.CollisionNotOnAccessList, false, (int)ParcelResult.Single, avatar);
  268. return; //Only send one
  269. }
  270. }
  271. return;
  272. }
  273. }
  274. }
  275. public void SendLandUpdate(ScenePresence avatar, bool force)
  276. {
  277. ILandObject over = GetLandObject((int)Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
  278. (int)Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
  279. if (over != null)
  280. {
  281. if (force)
  282. {
  283. if (!avatar.IsChildAgent)
  284. {
  285. over.sendLandUpdateToClient(avatar.ControllingClient);
  286. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.LocalID,
  287. m_scene.RegionInfo.RegionID);
  288. }
  289. }
  290. if (avatar.currentParcelUUID != over.landData.GlobalID)
  291. {
  292. if (!avatar.IsChildAgent)
  293. {
  294. over.sendLandUpdateToClient(avatar.ControllingClient);
  295. avatar.currentParcelUUID = over.landData.GlobalID;
  296. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.LocalID,
  297. m_scene.RegionInfo.RegionID);
  298. }
  299. }
  300. }
  301. }
  302. public void SendLandUpdate(ScenePresence avatar)
  303. {
  304. SendLandUpdate(avatar, false);
  305. }
  306. public void handleSignificantClientMovement(IClientAPI remote_client)
  307. {
  308. ScenePresence clientAvatar = m_scene.GetScenePresence(remote_client.AgentId);
  309. if (clientAvatar != null)
  310. {
  311. SendLandUpdate(clientAvatar);
  312. SendOutNearestBanLine(remote_client);
  313. ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
  314. if (parcel != null)
  315. {
  316. if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  317. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
  318. {
  319. handleAvatarChangingParcel(clientAvatar, parcel.landData.LocalID, m_scene.RegionInfo.RegionID);
  320. //They are going below the safety line!
  321. if (!parcel.isBannedFromLand(clientAvatar.UUID))
  322. {
  323. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
  324. }
  325. }
  326. else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  327. parcel.isBannedFromLand(clientAvatar.UUID))
  328. {
  329. SendYouAreBannedNotice(clientAvatar);
  330. }
  331. }
  332. }
  333. }
  334. public void handleAnyClientMovement(ScenePresence avatar)
  335. //Like handleSignificantClientMovement, but called with an AgentUpdate regardless of distance.
  336. {
  337. ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  338. if (over != null)
  339. {
  340. if (!over.isBannedFromLand(avatar.UUID) || avatar.AbsolutePosition.Z >= LandChannel.BAN_LINE_SAFETY_HIEGHT)
  341. {
  342. avatar.lastKnownAllowedPosition =
  343. new Vector3(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
  344. }
  345. }
  346. }
  347. public void handleParcelAccessRequest(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  348. int landLocalID, IClientAPI remote_client)
  349. {
  350. ILandObject land;
  351. lock (m_landList)
  352. {
  353. m_landList.TryGetValue(landLocalID, out land);
  354. }
  355. if (land != null)
  356. {
  357. m_landList[landLocalID].sendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
  358. }
  359. }
  360. public void handleParcelAccessUpdateRequest(UUID agentID, UUID sessionID, uint flags, int landLocalID,
  361. List<ParcelManager.ParcelAccessEntry> entries,
  362. IClientAPI remote_client)
  363. {
  364. ILandObject land;
  365. lock (m_landList)
  366. {
  367. m_landList.TryGetValue(landLocalID, out land);
  368. }
  369. if (land != null)
  370. {
  371. if (agentID == land.landData.OwnerID)
  372. {
  373. land.updateAccessList(flags, entries, remote_client);
  374. }
  375. }
  376. else
  377. {
  378. m_log.WarnFormat("[LAND]: Invalid local land ID {0}", landLocalID);
  379. }
  380. }
  381. /// <summary>
  382. /// Creates a basic Parcel object without an owner (a zeroed key)
  383. /// </summary>
  384. /// <returns></returns>
  385. public ILandObject CreateBaseLand()
  386. {
  387. return new LandObject(UUID.Zero, false, m_scene);
  388. }
  389. /// <summary>
  390. /// Adds a land object to the stored list and adds them to the landIDList to what they own
  391. /// </summary>
  392. /// <param name="new_land">The land object being added</param>
  393. public ILandObject AddLandObject(ILandObject land)
  394. {
  395. ILandObject new_land = land.Copy();
  396. lock (m_landList)
  397. {
  398. int newLandLocalID = ++m_lastLandLocalID;
  399. new_land.landData.LocalID = newLandLocalID;
  400. bool[,] landBitmap = new_land.getLandBitmap();
  401. for (int x = 0; x < 64; x++)
  402. {
  403. for (int y = 0; y < 64; y++)
  404. {
  405. if (landBitmap[x, y])
  406. {
  407. m_landIDList[x, y] = newLandLocalID;
  408. }
  409. }
  410. }
  411. m_landList.Add(newLandLocalID, new_land);
  412. }
  413. new_land.forceUpdateLandInfo();
  414. m_scene.EventManager.TriggerLandObjectAdded(new_land);
  415. return new_land;
  416. }
  417. /// <summary>
  418. /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
  419. /// </summary>
  420. /// <param name="local_id">Land.localID of the peice of land to remove.</param>
  421. public void removeLandObject(int local_id)
  422. {
  423. lock (m_landList)
  424. {
  425. for (int x = 0; x < 64; x++)
  426. {
  427. for (int y = 0; y < 64; y++)
  428. {
  429. if (m_landIDList[x, y] == local_id)
  430. {
  431. m_log.WarnFormat("[LAND]: Not removing land object {0}; still being used at {1}, {2}",
  432. local_id, x, y);
  433. return;
  434. //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
  435. }
  436. }
  437. }
  438. m_scene.EventManager.TriggerLandObjectRemoved(m_landList[local_id].landData.GlobalID);
  439. m_landList.Remove(local_id);
  440. }
  441. }
  442. private void performFinalLandJoin(ILandObject master, ILandObject slave)
  443. {
  444. bool[,] landBitmapSlave = slave.getLandBitmap();
  445. lock (m_landList)
  446. {
  447. for (int x = 0; x < 64; x++)
  448. {
  449. for (int y = 0; y < 64; y++)
  450. {
  451. if (landBitmapSlave[x, y])
  452. {
  453. m_landIDList[x, y] = master.landData.LocalID;
  454. }
  455. }
  456. }
  457. }
  458. removeLandObject(slave.landData.LocalID);
  459. UpdateLandObject(master.landData.LocalID, master.landData);
  460. }
  461. public ILandObject GetLandObject(int parcelLocalID)
  462. {
  463. lock (m_landList)
  464. {
  465. if (m_landList.ContainsKey(parcelLocalID))
  466. {
  467. return m_landList[parcelLocalID];
  468. }
  469. }
  470. return null;
  471. }
  472. /// <summary>
  473. /// Get the land object at the specified point
  474. /// </summary>
  475. /// <param name="x_float">Value between 0 - 256 on the x axis of the point</param>
  476. /// <param name="y_float">Value between 0 - 256 on the y axis of the point</param>
  477. /// <returns>Land object at the point supplied</returns>
  478. public ILandObject GetLandObject(float x_float, float y_float)
  479. {
  480. int x;
  481. int y;
  482. try
  483. {
  484. x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / 4.0));
  485. y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / 4.0));
  486. }
  487. catch (OverflowException)
  488. {
  489. return null;
  490. }
  491. if (x >= 64 || y >= 64 || x < 0 || y < 0)
  492. {
  493. return null;
  494. }
  495. lock (m_landList)
  496. {
  497. // Corner case. If an autoreturn happens during sim startup
  498. // we will come here with the list uninitialized
  499. //
  500. if (m_landList.ContainsKey(m_landIDList[x, y]))
  501. return m_landList[m_landIDList[x, y]];
  502. return null;
  503. }
  504. }
  505. public ILandObject GetLandObject(int x, int y)
  506. {
  507. if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0)
  508. {
  509. // These exceptions here will cause a lot of complaints from the users specifically because
  510. // they happen every time at border crossings
  511. throw new Exception("Error: Parcel not found at point " + x + ", " + y);
  512. }
  513. lock (m_landIDList)
  514. {
  515. return m_landList[m_landIDList[x / 4, y / 4]];
  516. }
  517. }
  518. #endregion
  519. #region Parcel Modification
  520. public void ResetAllLandPrimCounts()
  521. {
  522. lock (m_landList)
  523. {
  524. foreach (LandObject p in m_landList.Values)
  525. {
  526. p.resetLandPrimCounts();
  527. }
  528. }
  529. }
  530. public void SetPrimsTainted()
  531. {
  532. m_landPrimCountTainted = true;
  533. }
  534. public bool IsLandPrimCountTainted()
  535. {
  536. return m_landPrimCountTainted;
  537. }
  538. public void AddPrimToLandPrimCounts(SceneObjectGroup obj)
  539. {
  540. Vector3 position = obj.AbsolutePosition;
  541. ILandObject landUnderPrim = GetLandObject(position.X, position.Y);
  542. if (landUnderPrim != null)
  543. {
  544. landUnderPrim.addPrimToCount(obj);
  545. }
  546. }
  547. public void RemovePrimFromLandPrimCounts(SceneObjectGroup obj)
  548. {
  549. lock (m_landList)
  550. {
  551. foreach (LandObject p in m_landList.Values)
  552. {
  553. p.removePrimFromCount(obj);
  554. }
  555. }
  556. }
  557. public void FinalizeLandPrimCountUpdate()
  558. {
  559. //Get Simwide prim count for owner
  560. Dictionary<UUID, List<LandObject>> landOwnersAndParcels = new Dictionary<UUID, List<LandObject>>();
  561. lock (m_landList)
  562. {
  563. foreach (LandObject p in m_landList.Values)
  564. {
  565. if (!landOwnersAndParcels.ContainsKey(p.landData.OwnerID))
  566. {
  567. List<LandObject> tempList = new List<LandObject>();
  568. tempList.Add(p);
  569. landOwnersAndParcels.Add(p.landData.OwnerID, tempList);
  570. }
  571. else
  572. {
  573. landOwnersAndParcels[p.landData.OwnerID].Add(p);
  574. }
  575. }
  576. }
  577. foreach (UUID owner in landOwnersAndParcels.Keys)
  578. {
  579. int simArea = 0;
  580. int simPrims = 0;
  581. foreach (LandObject p in landOwnersAndParcels[owner])
  582. {
  583. simArea += p.landData.Area;
  584. simPrims += p.landData.OwnerPrims + p.landData.OtherPrims + p.landData.GroupPrims +
  585. p.landData.SelectedPrims;
  586. }
  587. foreach (LandObject p in landOwnersAndParcels[owner])
  588. {
  589. p.landData.SimwideArea = simArea;
  590. p.landData.SimwidePrims = simPrims;
  591. }
  592. }
  593. }
  594. public void UpdateLandPrimCounts()
  595. {
  596. ResetAllLandPrimCounts();
  597. foreach (EntityBase obj in m_scene.Entities)
  598. {
  599. if (obj != null)
  600. {
  601. if ((obj is SceneObjectGroup) && !obj.IsDeleted && !((SceneObjectGroup) obj).IsAttachment)
  602. {
  603. m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj);
  604. }
  605. }
  606. }
  607. FinalizeLandPrimCountUpdate();
  608. m_landPrimCountTainted = false;
  609. }
  610. public void PerformParcelPrimCountUpdate()
  611. {
  612. ResetAllLandPrimCounts();
  613. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  614. FinalizeLandPrimCountUpdate();
  615. m_landPrimCountTainted = false;
  616. }
  617. /// <summary>
  618. /// Subdivides a piece of land
  619. /// </summary>
  620. /// <param name="start_x">West Point</param>
  621. /// <param name="start_y">South Point</param>
  622. /// <param name="end_x">East Point</param>
  623. /// <param name="end_y">North Point</param>
  624. /// <param name="attempting_user_id">UUID of user who is trying to subdivide</param>
  625. /// <returns>Returns true if successful</returns>
  626. private void subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  627. {
  628. //First, lets loop through the points and make sure they are all in the same peice of land
  629. //Get the land object at start
  630. ILandObject startLandObject = GetLandObject(start_x, start_y);
  631. if (startLandObject == null) return;
  632. //Loop through the points
  633. try
  634. {
  635. int totalX = end_x - start_x;
  636. int totalY = end_y - start_y;
  637. for (int y = 0; y < totalY; y++)
  638. {
  639. for (int x = 0; x < totalX; x++)
  640. {
  641. ILandObject tempLandObject = GetLandObject(start_x + x, start_y + y);
  642. if (tempLandObject == null) return;
  643. if (tempLandObject != startLandObject) return;
  644. }
  645. }
  646. }
  647. catch (Exception)
  648. {
  649. return;
  650. }
  651. //If we are still here, then they are subdividing within one piece of land
  652. //Check owner
  653. if (!m_scene.Permissions.CanEditParcel(attempting_user_id, startLandObject))
  654. {
  655. return;
  656. }
  657. //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
  658. ILandObject newLand = startLandObject.Copy();
  659. newLand.landData.Name = "Subdivision of " + newLand.landData.Name;
  660. newLand.landData.GlobalID = UUID.Random();
  661. newLand.setLandBitmap(newLand.getSquareLandBitmap(start_x, start_y, end_x, end_y));
  662. //Now, lets set the subdivision area of the original to false
  663. int startLandObjectIndex = startLandObject.landData.LocalID;
  664. lock (m_landList)
  665. {
  666. m_landList[startLandObjectIndex].setLandBitmap(
  667. newLand.modifyLandBitmapSquare(startLandObject.getLandBitmap(), start_x, start_y, end_x, end_y, false));
  668. m_landList[startLandObjectIndex].forceUpdateLandInfo();
  669. }
  670. SetPrimsTainted();
  671. //Now add the new land object
  672. ILandObject result = AddLandObject(newLand);
  673. UpdateLandObject(startLandObject.landData.LocalID, startLandObject.landData);
  674. result.sendLandUpdateToAvatarsOverMe();
  675. }
  676. /// <summary>
  677. /// Join 2 land objects together
  678. /// </summary>
  679. /// <param name="start_x">x value in first piece of land</param>
  680. /// <param name="start_y">y value in first piece of land</param>
  681. /// <param name="end_x">x value in second peice of land</param>
  682. /// <param name="end_y">y value in second peice of land</param>
  683. /// <param name="attempting_user_id">UUID of the avatar trying to join the land objects</param>
  684. /// <returns>Returns true if successful</returns>
  685. private void join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  686. {
  687. end_x -= 4;
  688. end_y -= 4;
  689. List<ILandObject> selectedLandObjects = new List<ILandObject>();
  690. int stepYSelected;
  691. for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
  692. {
  693. int stepXSelected;
  694. for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
  695. {
  696. ILandObject p = GetLandObject(stepXSelected, stepYSelected);
  697. if (p != null)
  698. {
  699. if (!selectedLandObjects.Contains(p))
  700. {
  701. selectedLandObjects.Add(p);
  702. }
  703. }
  704. }
  705. }
  706. ILandObject masterLandObject = selectedLandObjects[0];
  707. selectedLandObjects.RemoveAt(0);
  708. if (selectedLandObjects.Count < 1)
  709. {
  710. return;
  711. }
  712. if (!m_scene.Permissions.CanEditParcel(attempting_user_id, masterLandObject))
  713. {
  714. return;
  715. }
  716. foreach (ILandObject p in selectedLandObjects)
  717. {
  718. if (p.landData.OwnerID != masterLandObject.landData.OwnerID)
  719. {
  720. return;
  721. }
  722. }
  723. lock (m_landList)
  724. {
  725. foreach (ILandObject slaveLandObject in selectedLandObjects)
  726. {
  727. m_landList[masterLandObject.landData.LocalID].setLandBitmap(
  728. slaveLandObject.mergeLandBitmaps(masterLandObject.getLandBitmap(), slaveLandObject.getLandBitmap()));
  729. performFinalLandJoin(masterLandObject, slaveLandObject);
  730. }
  731. }
  732. SetPrimsTainted();
  733. masterLandObject.sendLandUpdateToAvatarsOverMe();
  734. }
  735. #endregion
  736. #region Parcel Updating
  737. /// <summary>
  738. /// Where we send the ParcelOverlay packet to the client
  739. /// </summary>
  740. /// <param name="remote_client">The object representing the client</param>
  741. public void SendParcelOverlay(IClientAPI remote_client)
  742. {
  743. const int LAND_BLOCKS_PER_PACKET = 1024;
  744. byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  745. int byteArrayCount = 0;
  746. int sequenceID = 0;
  747. for (int y = 0; y < 64; y++)
  748. {
  749. for (int x = 0; x < 64; x++)
  750. {
  751. byte tempByte = 0; //This represents the byte for the current 4x4
  752. ILandObject currentParcelBlock = GetLandObject(x * 4, y * 4);
  753. if (currentParcelBlock != null)
  754. {
  755. if (currentParcelBlock.landData.OwnerID == remote_client.AgentId)
  756. {
  757. //Owner Flag
  758. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
  759. }
  760. else if (currentParcelBlock.landData.SalePrice > 0 &&
  761. (currentParcelBlock.landData.AuthBuyerID == UUID.Zero ||
  762. currentParcelBlock.landData.AuthBuyerID == remote_client.AgentId))
  763. {
  764. //Sale Flag
  765. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
  766. }
  767. else if (currentParcelBlock.landData.OwnerID == UUID.Zero)
  768. {
  769. //Public Flag
  770. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
  771. }
  772. else
  773. {
  774. //Other Flag
  775. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
  776. }
  777. //Now for border control
  778. ILandObject westParcel = null;
  779. ILandObject southParcel = null;
  780. if (x > 0)
  781. {
  782. westParcel = GetLandObject((x - 1) * 4, y * 4);
  783. }
  784. if (y > 0)
  785. {
  786. southParcel = GetLandObject(x * 4, (y - 1) * 4);
  787. }
  788. if (x == 0)
  789. {
  790. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  791. }
  792. else if (westParcel != null && westParcel != currentParcelBlock)
  793. {
  794. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  795. }
  796. if (y == 0)
  797. {
  798. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  799. }
  800. else if (southParcel != null && southParcel != currentParcelBlock)
  801. {
  802. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  803. }
  804. byteArray[byteArrayCount] = tempByte;
  805. byteArrayCount++;
  806. if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
  807. {
  808. remote_client.SendLandParcelOverlay(byteArray, sequenceID);
  809. byteArrayCount = 0;
  810. sequenceID++;
  811. byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  812. }
  813. }
  814. }
  815. }
  816. }
  817. public void handleParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
  818. bool snap_selection, IClientAPI remote_client)
  819. {
  820. //Get the land objects within the bounds
  821. List<ILandObject> temp = new List<ILandObject>();
  822. int inc_x = end_x - start_x;
  823. int inc_y = end_y - start_y;
  824. for (int x = 0; x < inc_x; x++)
  825. {
  826. for (int y = 0; y < inc_y; y++)
  827. {
  828. ILandObject currentParcel = GetLandObject(start_x + x, start_y + y);
  829. if (currentParcel != null)
  830. {
  831. if (!temp.Contains(currentParcel))
  832. {
  833. currentParcel.forceUpdateLandInfo();
  834. temp.Add(currentParcel);
  835. }
  836. }
  837. }
  838. }
  839. int requestResult = LandChannel.LAND_RESULT_SINGLE;
  840. if (temp.Count > 1)
  841. {
  842. requestResult = LandChannel.LAND_RESULT_MULTIPLE;
  843. }
  844. for (int i = 0; i < temp.Count; i++)
  845. {
  846. temp[i].sendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
  847. }
  848. SendParcelOverlay(remote_client);
  849. }
  850. public void handleParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
  851. {
  852. ILandObject land;
  853. lock (m_landList)
  854. {
  855. m_landList.TryGetValue(localID, out land);
  856. }
  857. if (land != null) land.updateLandProperties(args, remote_client);
  858. }
  859. public void handleParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
  860. {
  861. subdivide(west, south, east, north, remote_client.AgentId);
  862. }
  863. public void handleParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
  864. {
  865. join(west, south, east, north, remote_client.AgentId);
  866. }
  867. public void handleParcelSelectObjectsRequest(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  868. {
  869. m_landList[local_id].sendForceObjectSelect(local_id, request_type, returnIDs, remote_client);
  870. }
  871. public void handleParcelObjectOwnersRequest(int local_id, IClientAPI remote_client)
  872. {
  873. ILandObject land;
  874. lock (m_landList)
  875. {
  876. m_landList.TryGetValue(local_id, out land);
  877. }
  878. if (land != null)
  879. {
  880. m_landList[local_id].sendLandObjectOwners(remote_client);
  881. }
  882. else
  883. {
  884. m_log.WarnFormat("[PARCEL]: Invalid land object {0} passed for parcel object owner request", local_id);
  885. }
  886. }
  887. public void handleParcelGodForceOwner(int local_id, UUID ownerID, IClientAPI remote_client)
  888. {
  889. ILandObject land;
  890. lock (m_landList)
  891. {
  892. m_landList.TryGetValue(local_id, out land);
  893. }
  894. if (land != null)
  895. {
  896. if (m_scene.Permissions.IsGod(remote_client.AgentId))
  897. {
  898. land.landData.OwnerID = ownerID;
  899. m_scene.Broadcast(SendParcelOverlay);
  900. land.sendLandUpdateToClient(remote_client);
  901. }
  902. }
  903. }
  904. public void handleParcelAbandonRequest(int local_id, IClientAPI remote_client)
  905. {
  906. ILandObject land;
  907. lock (m_landList)
  908. {
  909. m_landList.TryGetValue(local_id, out land);
  910. }
  911. if (land != null)
  912. {
  913. if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land))
  914. {
  915. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  916. land.landData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  917. else
  918. land.landData.OwnerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  919. m_scene.Broadcast(SendParcelOverlay);
  920. land.sendLandUpdateToClient(remote_client);
  921. }
  922. }
  923. }
  924. public void handleParcelReclaim(int local_id, IClientAPI remote_client)
  925. {
  926. ILandObject land;
  927. lock (m_landList)
  928. {
  929. m_landList.TryGetValue(local_id, out land);
  930. }
  931. if (land != null)
  932. {
  933. if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land))
  934. {
  935. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  936. land.landData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  937. else
  938. land.landData.OwnerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  939. land.landData.ClaimDate = Util.UnixTimeSinceEpoch();
  940. m_scene.Broadcast(SendParcelOverlay);
  941. land.sendLandUpdateToClient(remote_client);
  942. }
  943. }
  944. }
  945. #endregion
  946. // If the economy has been validated by the economy module,
  947. // and land has been validated as well, this method transfers
  948. // the land ownership
  949. public void handleLandBuyRequest(Object o, EventManager.LandBuyArgs e)
  950. {
  951. if (e.economyValidated && e.landValidated)
  952. {
  953. ILandObject land;
  954. lock (m_landList)
  955. {
  956. m_landList.TryGetValue(e.parcelLocalID, out land);
  957. }
  958. if (land != null)
  959. {
  960. land.updateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea);
  961. }
  962. }
  963. }
  964. // After receiving a land buy packet, first the data needs to
  965. // be validated. This method validates the right to buy the
  966. // parcel
  967. public void handleLandValidationRequest(Object o, EventManager.LandBuyArgs e)
  968. {
  969. if (e.landValidated == false)
  970. {
  971. ILandObject lob = null;
  972. lock (m_landList)
  973. {
  974. m_landList.TryGetValue(e.parcelLocalID, out lob);
  975. }
  976. if (lob != null)
  977. {
  978. UUID AuthorizedID = lob.landData.AuthBuyerID;
  979. int saleprice = lob.landData.SalePrice;
  980. UUID pOwnerID = lob.landData.OwnerID;
  981. bool landforsale = ((lob.landData.Flags &
  982. (uint)(Parcel.ParcelFlags.ForSale | Parcel.ParcelFlags.ForSaleObjects | Parcel.ParcelFlags.SellParcelObjects)) != 0);
  983. if ((AuthorizedID == UUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
  984. {
  985. // TODO I don't think we have to lock it here, no?
  986. //lock (e)
  987. //{
  988. e.parcelOwnerID = pOwnerID;
  989. e.landValidated = true;
  990. //}
  991. }
  992. }
  993. }
  994. }
  995. #region Land Object From Storage Functions
  996. public void IncomingLandObjectsFromStorage(List<LandData> data)
  997. {
  998. for (int i = 0; i < data.Count; i++)
  999. {
  1000. IncomingLandObjectFromStorage(data[i]);
  1001. }
  1002. }
  1003. public void IncomingLandObjectFromStorage(LandData data)
  1004. {
  1005. ILandObject new_land = new LandObject(data.OwnerID, data.IsGroupOwned, m_scene);
  1006. new_land.landData = data.Copy();
  1007. new_land.setLandBitmapFromByteArray();
  1008. AddLandObject(new_land);
  1009. }
  1010. public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient)
  1011. {
  1012. ILandObject selectedParcel = null;
  1013. lock (m_landList)
  1014. {
  1015. m_landList.TryGetValue(localID, out selectedParcel);
  1016. }
  1017. if (selectedParcel == null) return;
  1018. selectedParcel.returnLandObjects(returnType, agentIDs, taskIDs, remoteClient);
  1019. }
  1020. public void NoLandDataFromStorage()
  1021. {
  1022. ResetSimLandObjects();
  1023. }
  1024. #endregion
  1025. public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  1026. {
  1027. lock (m_landList)
  1028. {
  1029. foreach (LandObject obj in m_landList.Values)
  1030. {
  1031. obj.setParcelObjectMaxOverride(overrideDel);
  1032. }
  1033. }
  1034. }
  1035. public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  1036. {
  1037. }
  1038. #region CAPS handler
  1039. private void OnRegisterCaps(UUID agentID, Caps caps)
  1040. {
  1041. string capsBase = "/CAPS/" + caps.CapsObjectPath;
  1042. caps.RegisterHandler("RemoteParcelRequest",
  1043. new RestStreamHandler("POST", capsBase + remoteParcelRequestPath,
  1044. delegate(string request, string path, string param,
  1045. OSHttpRequest httpRequest, OSHttpResponse httpResponse)
  1046. {
  1047. return RemoteParcelRequest(request, path, param, agentID, caps);
  1048. }));
  1049. }
  1050. // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the
  1051. // "real" parcelID, because we wouldn't be able to map that to the region the parcel belongs to.
  1052. // So, we create a "fake" parcelID by using the regionHandle (64 bit), and the local (integer) x
  1053. // and y coordinate (each 8 bit), encoded in a UUID (128 bit).
  1054. //
  1055. // Request format:
  1056. // <llsd>
  1057. // <map>
  1058. // <key>location</key>
  1059. // <array>
  1060. // <real>1.23</real>
  1061. // <real>45..6</real>
  1062. // <real>78.9</real>
  1063. // </array>
  1064. // <key>region_id</key>
  1065. // <uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid>
  1066. // </map>
  1067. // </llsd>
  1068. private string RemoteParcelRequest(string request, string path, string param, UUID agentID, Caps caps)
  1069. {
  1070. UUID parcelID = UUID.Zero;
  1071. try
  1072. {
  1073. Hashtable hash = new Hashtable();
  1074. hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  1075. if (hash.ContainsKey("region_id") && hash.ContainsKey("location"))
  1076. {
  1077. UUID regionID = (UUID)hash["region_id"];
  1078. ArrayList list = (ArrayList)hash["location"];
  1079. uint x = (uint)(double)list[0];
  1080. uint y = (uint)(double)list[1];
  1081. if (hash.ContainsKey("region_handle"))
  1082. {
  1083. // if you do a "About Landmark" on a landmark a second time, the viewer sends the
  1084. // region_handle it got earlier via RegionHandleRequest
  1085. ulong regionHandle = Util.BytesToUInt64Big((byte[])hash["region_handle"]);
  1086. parcelID = Util.BuildFakeParcelID(regionHandle, x, y);
  1087. }
  1088. else if (regionID == m_scene.RegionInfo.RegionID)
  1089. {
  1090. // a parcel request for a local parcel => no need to query the grid
  1091. parcelID = Util.BuildFakeParcelID(m_scene.RegionInfo.RegionHandle, x, y);
  1092. }
  1093. else
  1094. {
  1095. // a parcel request for a parcel in another region. Ask the grid about the region
  1096. RegionInfo info = m_scene.CommsManager.GridService.RequestNeighbourInfo(regionID);
  1097. if (info != null)
  1098. parcelID = Util.BuildFakeParcelID(info.RegionHandle, x, y);
  1099. }
  1100. }
  1101. }
  1102. catch (LLSD.LLSDParseException e)
  1103. {
  1104. m_log.ErrorFormat("[LAND] Fetch error: {0}", e.Message);
  1105. m_log.ErrorFormat("[LAND] ... in request {0}", request);
  1106. }
  1107. catch(InvalidCastException)
  1108. {
  1109. m_log.ErrorFormat("[LAND] Wrong type in request {0}", request);
  1110. }
  1111. LLSDRemoteParcelResponse response = new LLSDRemoteParcelResponse();
  1112. response.parcel_id = parcelID;
  1113. m_log.DebugFormat("[LAND] got parcelID {0}", parcelID);
  1114. return LLSDHelpers.SerialiseLLSDReply(response);
  1115. }
  1116. #endregion
  1117. private void handleParcelDwell(int localID, IClientAPI remoteClient)
  1118. {
  1119. ILandObject selectedParcel = null;
  1120. lock (m_landList)
  1121. {
  1122. if (!m_landList.TryGetValue(localID, out selectedParcel))
  1123. return;
  1124. }
  1125. remoteClient.SendParcelDwellReply(localID, selectedParcel.landData.GlobalID, selectedParcel.landData.Dwell);
  1126. }
  1127. private void handleParcelInfo(IClientAPI remoteClient, UUID parcelID)
  1128. {
  1129. if (parcelID == UUID.Zero)
  1130. return;
  1131. ExtendedLandData data = (ExtendedLandData)parcelInfoCache.Get(parcelID, delegate(UUID parcel) {
  1132. // assume we've got the parcelID we just computed in RemoteParcelRequest
  1133. ExtendedLandData extLandData = new ExtendedLandData();
  1134. Util.ParseFakeParcelID(parcel, out extLandData.regionHandle, out extLandData.x, out extLandData.y);
  1135. m_log.DebugFormat("[LAND] got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
  1136. extLandData.regionHandle, extLandData.x, extLandData.y);
  1137. // for this region or for somewhere else?
  1138. if (extLandData.regionHandle == m_scene.RegionInfo.RegionHandle)
  1139. {
  1140. extLandData.landData = this.GetLandObject(extLandData.x, extLandData.y).landData;
  1141. }
  1142. else
  1143. {
  1144. extLandData.landData = m_scene.CommsManager.GridService.RequestLandData(extLandData.regionHandle,
  1145. extLandData.x,
  1146. extLandData.y);
  1147. if (extLandData.landData == null)
  1148. {
  1149. // we didn't find the region/land => don't cache
  1150. return null;
  1151. }
  1152. }
  1153. return extLandData;
  1154. });
  1155. if (data != null) // if we found some data, send it
  1156. {
  1157. RegionInfo info;
  1158. if (data.regionHandle == m_scene.RegionInfo.RegionHandle)
  1159. {
  1160. info = m_scene.RegionInfo;
  1161. }
  1162. else
  1163. {
  1164. // most likely still cached from building the extLandData entry
  1165. info = m_scene.CommsManager.GridService.RequestNeighbourInfo(data.regionHandle);
  1166. }
  1167. // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
  1168. m_log.DebugFormat("[LAND] got parcelinfo for parcel {0} in region {1}; sending...",
  1169. data.landData.Name, data.regionHandle);
  1170. remoteClient.SendParcelInfo(info, data.landData, parcelID, data.x, data.y);
  1171. }
  1172. else
  1173. m_log.Debug("[LAND] got no parcelinfo; not sending");
  1174. }
  1175. public void setParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime)
  1176. {
  1177. ILandObject land;
  1178. lock (m_landList)
  1179. {
  1180. m_landList.TryGetValue(localID, out land);
  1181. }
  1182. if (land == null) return;
  1183. if (!m_scene.Permissions.CanEditParcel(remoteClient.AgentId, land))
  1184. return;
  1185. land.landData.OtherCleanTime = otherCleanTime;
  1186. UpdateLandObject(localID, land.landData);
  1187. }
  1188. }
  1189. }