LandManagementModule.cs 61 KB

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