LandManagementModule.cs 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  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 log4net;
  32. using Nini.Config;
  33. using OpenMetaverse;
  34. using OpenSim.Framework;
  35. using OpenSim.Framework.Communications.Capabilities;
  36. using OpenSim.Framework.Servers;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. using OpenSim.Region.Physics.Manager;
  40. using Caps=OpenSim.Framework.Communications.Capabilities.Caps;
  41. namespace OpenSim.Region.CoreModules.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 = 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. }