LandManagementModule.cs 70 KB

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