LandManagementModule.cs 54 KB

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