LandManagementModule.cs 57 KB

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