LandManagementModule.cs 73 KB

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