LandManagementModule.cs 91 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173
  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.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. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LandManagementModule")]
  61. public class LandManagementModule : INonSharedRegionModule
  62. {
  63. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  64. private static readonly string LogHeader = "[LAND MANAGEMENT MODULE]";
  65. /// <summary>
  66. /// Minimum land unit size in region co-ordinates.
  67. /// </summary>
  68. public const int LandUnit = 4;
  69. private static readonly string remoteParcelRequestPath = "0009/";
  70. private LandChannel landChannel;
  71. private Scene m_scene;
  72. protected IUserManagement m_userManager;
  73. protected IPrimCountModule m_primCountModule;
  74. protected IDialogModule m_Dialog;
  75. /// <value>
  76. /// Local land ids at specified region co-ordinates (region size / 4)
  77. /// </value>
  78. private int[,] m_landIDList;
  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 = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
  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. lock (m_scene)
  123. {
  124. m_scene.LandChannel = (ILandChannel)landChannel;
  125. }
  126. RegisterCommands();
  127. }
  128. public void RegionLoaded(Scene scene)
  129. {
  130. m_userManager = m_scene.RequestModuleInterface<IUserManagement>();
  131. m_primCountModule = m_scene.RequestModuleInterface<IPrimCountModule>();
  132. m_Dialog = m_scene.RequestModuleInterface<IDialogModule>();
  133. }
  134. public void RemoveRegion(Scene scene)
  135. {
  136. // TODO: Release event manager listeners here
  137. }
  138. // private bool OnVerifyUserConnection(ScenePresence scenePresence, out string reason)
  139. // {
  140. // ILandObject nearestParcel = m_scene.GetNearestAllowedParcel(scenePresence.UUID, scenePresence.AbsolutePosition.X, scenePresence.AbsolutePosition.Y);
  141. // reason = "You are not allowed to enter this sim.";
  142. // return nearestParcel != null;
  143. // }
  144. void EventManagerOnNewClient(IClientAPI client)
  145. {
  146. //Register some client events
  147. client.OnParcelPropertiesRequest += ClientOnParcelPropertiesRequest;
  148. client.OnParcelDivideRequest += ClientOnParcelDivideRequest;
  149. client.OnParcelJoinRequest += ClientOnParcelJoinRequest;
  150. client.OnParcelPropertiesUpdateRequest += ClientOnParcelPropertiesUpdateRequest;
  151. client.OnParcelSelectObjects += ClientOnParcelSelectObjects;
  152. client.OnParcelObjectOwnerRequest += ClientOnParcelObjectOwnerRequest;
  153. client.OnParcelAccessListRequest += ClientOnParcelAccessListRequest;
  154. client.OnParcelAccessListUpdateRequest += ClientOnParcelAccessListUpdateRequest;
  155. client.OnParcelAbandonRequest += ClientOnParcelAbandonRequest;
  156. client.OnParcelGodForceOwner += ClientOnParcelGodForceOwner;
  157. client.OnParcelReclaim += ClientOnParcelReclaim;
  158. client.OnParcelInfoRequest += ClientOnParcelInfoRequest;
  159. client.OnParcelDeedToGroup += ClientOnParcelDeedToGroup;
  160. client.OnPreAgentUpdate += ClientOnPreAgentUpdate;
  161. client.OnParcelEjectUser += ClientOnParcelEjectUser;
  162. client.OnParcelFreezeUser += ClientOnParcelFreezeUser;
  163. client.OnSetStartLocationRequest += ClientOnSetHome;
  164. EntityBase presenceEntity;
  165. if (m_scene.Entities.TryGetValue(client.AgentId, out presenceEntity) && presenceEntity is ScenePresence)
  166. {
  167. SendLandUpdate((ScenePresence)presenceEntity, true);
  168. SendParcelOverlay(client);
  169. }
  170. }
  171. public void EventMakeChildAgent(ScenePresence avatar)
  172. {
  173. avatar.currentParcelUUID = UUID.Zero;
  174. }
  175. void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
  176. {
  177. //If we are forcing a position for them to go
  178. if (forcedPosition.ContainsKey(remoteClient.AgentId))
  179. {
  180. ScenePresence clientAvatar = m_scene.GetScenePresence(remoteClient.AgentId);
  181. //Putting the user into flying, both keeps the avatar in fligth when it bumps into something and stopped from going another direction AND
  182. //When the avatar walks into a ban line on the ground, it prevents getting stuck
  183. agentData.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
  184. //Make sure we stop if they get about to the right place to prevent yoyo and prevents getting stuck on banlines
  185. if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) < .2)
  186. {
  187. // m_log.DebugFormat(
  188. // "[LAND MANAGEMENT MODULE]: Stopping force position of {0} because {1} is close enough to {2}",
  189. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
  190. forcedPosition.Remove(remoteClient.AgentId);
  191. }
  192. //if we are far away, teleport
  193. else if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) > 3)
  194. {
  195. Vector3 forcePosition = forcedPosition[remoteClient.AgentId];
  196. // m_log.DebugFormat(
  197. // "[LAND MANAGEMENT MODULE]: Teleporting out {0} because {1} is too far from avatar position {2}",
  198. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcePosition);
  199. m_scene.RequestTeleportLocation(remoteClient, m_scene.RegionInfo.RegionHandle,
  200. forcePosition, clientAvatar.Lookat, (uint)Constants.TeleportFlags.ForceRedirect);
  201. forcedPosition.Remove(remoteClient.AgentId);
  202. }
  203. else
  204. {
  205. // m_log.DebugFormat(
  206. // "[LAND MANAGEMENT MODULE]: Forcing {0} from {1} to {2}",
  207. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
  208. //Forces them toward the forced position we want if they aren't there yet
  209. agentData.UseClientAgentPosition = true;
  210. agentData.ClientAgentPosition = forcedPosition[remoteClient.AgentId];
  211. }
  212. }
  213. }
  214. public void Close()
  215. {
  216. }
  217. public string Name
  218. {
  219. get { return "LandManagementModule"; }
  220. }
  221. #endregion
  222. #region Parcel Add/Remove/Get/Create
  223. public void EventManagerOnSetAllowedForcefulBan(bool forceful)
  224. {
  225. AllowedForcefulBans = forceful;
  226. }
  227. public void UpdateLandObject(int local_id, LandData data)
  228. {
  229. LandData newData = data.Copy();
  230. newData.LocalID = local_id;
  231. ILandObject land;
  232. lock (m_landList)
  233. {
  234. if (m_landList.TryGetValue(local_id, out land))
  235. land.LandData = newData;
  236. }
  237. if (land != null)
  238. m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land);
  239. }
  240. public bool AllowedForcefulBans
  241. {
  242. get { return m_allowedForcefulBans; }
  243. set { m_allowedForcefulBans = value; }
  244. }
  245. /// <summary>
  246. /// Resets the sim to the default land object (full sim piece of land owned by the default user)
  247. /// </summary>
  248. public void ResetSimLandObjects()
  249. {
  250. //Remove all the land objects in the sim and add a blank, full sim land object set to public
  251. lock (m_landList)
  252. {
  253. m_landList.Clear();
  254. m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  255. m_landIDList = new int[m_scene.RegionInfo.RegionSizeX / LandUnit, m_scene.RegionInfo.RegionSizeY / LandUnit];
  256. }
  257. }
  258. /// <summary>
  259. /// Create a default parcel that spans the entire region and is owned by the estate owner.
  260. /// </summary>
  261. /// <returns>The parcel created.</returns>
  262. protected ILandObject CreateDefaultParcel()
  263. {
  264. m_log.DebugFormat(
  265. "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
  266. ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
  267. fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0,
  268. (int)m_scene.RegionInfo.RegionSizeX, (int)m_scene.RegionInfo.RegionSizeY));
  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)m_scene.RegionInfo.RegionSizeX - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
  384. (int)Math.Min(((int)m_scene.RegionInfo.RegionSizeY - 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(ScenePresence clientAvatar)
  413. {
  414. SendLandUpdate(clientAvatar);
  415. SendOutNearestBanLine(clientAvatar.ControllingClient);
  416. ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
  417. if (parcel != null)
  418. {
  419. if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  420. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
  421. {
  422. EventManagerOnAvatarEnteringNewParcel(clientAvatar, parcel.LandData.LocalID,
  423. m_scene.RegionInfo.RegionID);
  424. //They are going under the safety line!
  425. if (!parcel.IsBannedFromLand(clientAvatar.UUID))
  426. {
  427. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
  428. }
  429. }
  430. else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  431. parcel.IsBannedFromLand(clientAvatar.UUID))
  432. {
  433. //once we've sent the message once, keep going toward the target until we are done
  434. if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
  435. {
  436. SendYouAreBannedNotice(clientAvatar);
  437. ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
  438. }
  439. }
  440. else if (parcel.IsRestrictedFromLand(clientAvatar.UUID))
  441. {
  442. //once we've sent the message once, keep going toward the target until we are done
  443. if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
  444. {
  445. SendYouAreRestrictedNotice(clientAvatar);
  446. ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
  447. }
  448. }
  449. else
  450. {
  451. //when we are finally in a safe place, lets release the forced position lock
  452. forcedPosition.Remove(clientAvatar.ControllingClient.AgentId);
  453. }
  454. }
  455. }
  456. /// <summary>
  457. /// Like handleEventManagerOnSignificantClientMovement, but called with an AgentUpdate regardless of distance.
  458. /// </summary>
  459. /// <param name="avatar"></param>
  460. public void EventManagerOnClientMovement(ScenePresence avatar)
  461. //
  462. {
  463. ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  464. if (over != null)
  465. {
  466. if (!over.IsRestrictedFromLand(avatar.UUID) && (!over.IsBannedFromLand(avatar.UUID) || avatar.AbsolutePosition.Z >= LandChannel.BAN_LINE_SAFETY_HIEGHT))
  467. {
  468. avatar.lastKnownAllowedPosition =
  469. new Vector3(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
  470. }
  471. }
  472. }
  473. public void ClientOnParcelAccessListRequest(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  474. int landLocalID, IClientAPI remote_client)
  475. {
  476. ILandObject land;
  477. lock (m_landList)
  478. {
  479. m_landList.TryGetValue(landLocalID, out land);
  480. }
  481. if (land != null)
  482. {
  483. land.SendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
  484. }
  485. }
  486. public void ClientOnParcelAccessListUpdateRequest(UUID agentID,
  487. uint flags, int landLocalID, UUID transactionID, int sequenceID,
  488. int sections, List<LandAccessEntry> entries,
  489. IClientAPI remote_client)
  490. {
  491. // Flags is the list to update, it can mean either the ban or
  492. // the access list (WTH is a pass list? Mentioned in ParcelFlags)
  493. //
  494. // There may be multiple packets, because these can get LONG.
  495. // Use transactionID to determine a new chain of packets since
  496. // packets may have come in out of sequence and that would be
  497. // a big mess if using the sequenceID
  498. ILandObject land;
  499. lock (m_landList)
  500. {
  501. m_landList.TryGetValue(landLocalID, out land);
  502. }
  503. if (land != null)
  504. {
  505. GroupPowers requiredPowers = GroupPowers.LandManageAllowed;
  506. if (flags == (uint)AccessList.Ban)
  507. requiredPowers = GroupPowers.LandManageBanned;
  508. if (m_scene.Permissions.CanEditParcelProperties(agentID,
  509. land, requiredPowers))
  510. {
  511. land.UpdateAccessList(flags, transactionID, sequenceID,
  512. sections, entries, remote_client);
  513. }
  514. }
  515. else
  516. {
  517. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid local land ID {0}", landLocalID);
  518. }
  519. }
  520. /// <summary>
  521. /// Adds a land object to the stored list and adds them to the landIDList to what they own
  522. /// </summary>
  523. /// <param name="new_land">
  524. /// The land object being added.
  525. /// Will return null if this overlaps with an existing parcel that has not had its bitmap adjusted.
  526. /// </param>
  527. public ILandObject AddLandObject(ILandObject land)
  528. {
  529. ILandObject new_land = land.Copy();
  530. // Only now can we add the prim counts to the land object - we rely on the global ID which is generated
  531. // as a random UUID inside LandData initialization
  532. if (m_primCountModule != null)
  533. new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID);
  534. lock (m_landList)
  535. {
  536. int newLandLocalID = m_lastLandLocalID + 1;
  537. new_land.LandData.LocalID = newLandLocalID;
  538. bool[,] landBitmap = new_land.GetLandBitmap();
  539. // m_log.DebugFormat("{0} AddLandObject. new_land.bitmapSize=({1},{2}). newLocalID={3}",
  540. // LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), newLandLocalID);
  541. if (landBitmap.GetLength(0) != m_landIDList.GetLength(0) || landBitmap.GetLength(1) != m_landIDList.GetLength(1))
  542. {
  543. // Going to variable sized regions can cause mismatches
  544. m_log.ErrorFormat("{0} AddLandObject. Added land bitmap different size than region ID map. bitmapSize=({1},{2}), landIDSize=({3},{4})",
  545. LogHeader, landBitmap.GetLength(0), landBitmap.GetLength(1), m_landIDList.GetLength(0), m_landIDList.GetLength(1) );
  546. }
  547. else
  548. {
  549. // If other land objects still believe that they occupy any parts of the same space,
  550. // then do not allow the add to proceed.
  551. for (int x = 0; x < landBitmap.GetLength(0); x++)
  552. {
  553. for (int y = 0; y < landBitmap.GetLength(1); y++)
  554. {
  555. if (landBitmap[x, y])
  556. {
  557. int lastRecordedLandId = m_landIDList[x, y];
  558. if (lastRecordedLandId > 0)
  559. {
  560. ILandObject lastRecordedLo = m_landList[lastRecordedLandId];
  561. if (lastRecordedLo.LandBitmap[x, y])
  562. {
  563. m_log.ErrorFormat(
  564. "{0}: Cannot add parcel \"{1}\", local ID {2} at tile {3},{4} because this is still occupied by parcel \"{5}\", local ID {6} in {7}",
  565. LogHeader, new_land.LandData.Name, new_land.LandData.LocalID, x, y,
  566. lastRecordedLo.LandData.Name, lastRecordedLo.LandData.LocalID, m_scene.Name);
  567. return null;
  568. }
  569. }
  570. }
  571. }
  572. }
  573. for (int x = 0; x < landBitmap.GetLength(0); x++)
  574. {
  575. for (int y = 0; y < landBitmap.GetLength(1); y++)
  576. {
  577. if (landBitmap[x, y])
  578. {
  579. // m_log.DebugFormat(
  580. // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
  581. // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
  582. m_landIDList[x, y] = newLandLocalID;
  583. }
  584. }
  585. }
  586. }
  587. m_landList.Add(newLandLocalID, new_land);
  588. m_lastLandLocalID++;
  589. }
  590. new_land.ForceUpdateLandInfo();
  591. m_scene.EventManager.TriggerLandObjectAdded(new_land);
  592. return new_land;
  593. }
  594. /// <summary>
  595. /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
  596. /// </summary>
  597. /// <param name="local_id">Land.localID of the peice of land to remove.</param>
  598. public void removeLandObject(int local_id)
  599. {
  600. ILandObject land;
  601. lock (m_landList)
  602. {
  603. for (int x = 0; x < m_landIDList.GetLength(0); x++)
  604. {
  605. for (int y = 0; y < m_landIDList.GetLength(1); y++)
  606. {
  607. if (m_landIDList[x, y] == local_id)
  608. {
  609. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Not removing land object {0}; still being used at {1}, {2}",
  610. local_id, x, y);
  611. return;
  612. //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
  613. }
  614. }
  615. }
  616. land = m_landList[local_id];
  617. m_landList.Remove(local_id);
  618. }
  619. m_scene.EventManager.TriggerLandObjectRemoved(land.LandData.GlobalID);
  620. }
  621. /// <summary>
  622. /// Clear the scene of all parcels
  623. /// </summary>
  624. public void Clear(bool setupDefaultParcel)
  625. {
  626. List<ILandObject> parcels;
  627. lock (m_landList)
  628. {
  629. parcels = new List<ILandObject>(m_landList.Values);
  630. }
  631. foreach (ILandObject lo in parcels)
  632. {
  633. //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID);
  634. m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID);
  635. }
  636. lock (m_landList)
  637. {
  638. m_landList.Clear();
  639. ResetSimLandObjects();
  640. }
  641. if (setupDefaultParcel)
  642. CreateDefaultParcel();
  643. }
  644. private void performFinalLandJoin(ILandObject master, ILandObject slave)
  645. {
  646. bool[,] landBitmapSlave = slave.GetLandBitmap();
  647. lock (m_landList)
  648. {
  649. for (int x = 0; x < landBitmapSlave.GetLength(0); x++)
  650. {
  651. for (int y = 0; y < landBitmapSlave.GetLength(1); y++)
  652. {
  653. if (landBitmapSlave[x, y])
  654. {
  655. m_landIDList[x, y] = master.LandData.LocalID;
  656. }
  657. }
  658. }
  659. }
  660. removeLandObject(slave.LandData.LocalID);
  661. UpdateLandObject(master.LandData.LocalID, master.LandData);
  662. }
  663. public ILandObject GetLandObject(int parcelLocalID)
  664. {
  665. lock (m_landList)
  666. {
  667. if (m_landList.ContainsKey(parcelLocalID))
  668. {
  669. return m_landList[parcelLocalID];
  670. }
  671. }
  672. return null;
  673. }
  674. /// <summary>
  675. /// Get the land object at the specified point
  676. /// </summary>
  677. /// <param name="x_float">Value between 0 - 256 on the x axis of the point</param>
  678. /// <param name="y_float">Value between 0 - 256 on the y axis of the point</param>
  679. /// <returns>Land object at the point supplied</returns>
  680. public ILandObject GetLandObject(float x_float, float y_float)
  681. {
  682. return GetLandObject((int)x_float, (int)y_float, true /* returnNullIfLandObjectNotFound */);
  683. /*
  684. int x;
  685. int y;
  686. if (x_float >= m_scene.RegionInfo.RegionSizeX || x_float < 0 || y_float >= m_scene.RegionInfo.RegionSizeX || y_float < 0)
  687. return null;
  688. try
  689. {
  690. x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / (float)landUnit));
  691. y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / (float)landUnit));
  692. }
  693. catch (OverflowException)
  694. {
  695. return null;
  696. }
  697. if (x >= (m_scene.RegionInfo.RegionSizeX / landUnit)
  698. || y >= (m_scene.RegionInfo.RegionSizeY / landUnit)
  699. || x < 0
  700. || y < 0)
  701. {
  702. return null;
  703. }
  704. lock (m_landList)
  705. {
  706. // Corner case. If an autoreturn happens during sim startup
  707. // we will come here with the list uninitialized
  708. //
  709. // int landId = m_landIDList[x, y];
  710. // if (landId == 0)
  711. // m_log.DebugFormat(
  712. // "[LAND MANAGEMENT MODULE]: No land object found at ({0}, {1}) on {2}",
  713. // x, y, m_scene.RegionInfo.RegionName);
  714. try
  715. {
  716. if (m_landList.ContainsKey(m_landIDList[x, y]))
  717. return m_landList[m_landIDList[x, y]];
  718. }
  719. catch (Exception e)
  720. {
  721. m_log.DebugFormat("{0} GetLandObject exception. x={1}, y={2}, m_landIDList.len=({3},{4})",
  722. LogHeader, x, y, m_landIDList.GetLength(0), m_landIDList.GetLength(1));
  723. }
  724. return null;
  725. }
  726. */
  727. }
  728. // Public entry.
  729. // Throws exception if land object is not found
  730. public ILandObject GetLandObject(int x, int y)
  731. {
  732. return GetLandObject(x, y, false /* returnNullIfLandObjectNotFound */);
  733. }
  734. /// <summary>
  735. /// Given a region position, return the parcel land object for that location
  736. /// </summary>
  737. /// <returns>
  738. /// The land object.
  739. /// </returns>
  740. /// <param name='x'></param>
  741. /// <param name='y'></param>
  742. /// <param name='returnNullIfLandObjectNotFound'>
  743. /// Return null if the land object requested is not within the region's bounds.
  744. /// </param>
  745. private ILandObject GetLandObject(int x, int y, bool returnNullIfLandObjectOutsideBounds)
  746. {
  747. ILandObject ret = null;
  748. if (x >= m_scene.RegionInfo.RegionSizeX || y >= m_scene.RegionInfo.RegionSizeY || x < 0 || y < 0)
  749. {
  750. // These exceptions here will cause a lot of complaints from the users specifically because
  751. // they happen every time at border crossings
  752. if (returnNullIfLandObjectOutsideBounds)
  753. return null;
  754. else
  755. throw new Exception(
  756. String.Format("{0} GetLandObject for non-existant position. Region={1}, pos=<{2},{3}",
  757. LogHeader, m_scene.RegionInfo.RegionName, x, y)
  758. );
  759. }
  760. return m_landList[m_landIDList[x / 4, y / 4]];
  761. }
  762. // Create a 'parcel is here' bitmap for the parcel identified by the passed landID
  763. private bool[,] CreateBitmapForID(int landID)
  764. {
  765. bool[,] ret = new bool[m_landIDList.GetLength(0), m_landIDList.GetLength(1)];
  766. for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
  767. for (int yy = 0; yy < m_landIDList.GetLength(0); yy++)
  768. if (m_landIDList[xx, yy] == landID)
  769. ret[xx, yy] = true;
  770. return ret;
  771. }
  772. #endregion
  773. #region Parcel Modification
  774. public void ResetOverMeRecords()
  775. {
  776. lock (m_landList)
  777. {
  778. foreach (LandObject p in m_landList.Values)
  779. {
  780. p.ResetOverMeRecord();
  781. }
  782. }
  783. }
  784. public void EventManagerOnParcelPrimCountAdd(SceneObjectGroup obj)
  785. {
  786. Vector3 position = obj.AbsolutePosition;
  787. ILandObject landUnderPrim = GetLandObject(position.X, position.Y);
  788. if (landUnderPrim != null)
  789. {
  790. ((LandObject)landUnderPrim).AddPrimOverMe(obj);
  791. }
  792. }
  793. public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
  794. {
  795. lock (m_landList)
  796. {
  797. foreach (LandObject p in m_landList.Values)
  798. {
  799. p.RemovePrimFromOverMe(obj);
  800. }
  801. }
  802. }
  803. public void FinalizeLandPrimCountUpdate()
  804. {
  805. //Get Simwide prim count for owner
  806. Dictionary<UUID, List<LandObject>> landOwnersAndParcels = new Dictionary<UUID, List<LandObject>>();
  807. lock (m_landList)
  808. {
  809. foreach (LandObject p in m_landList.Values)
  810. {
  811. if (!landOwnersAndParcels.ContainsKey(p.LandData.OwnerID))
  812. {
  813. List<LandObject> tempList = new List<LandObject>();
  814. tempList.Add(p);
  815. landOwnersAndParcels.Add(p.LandData.OwnerID, tempList);
  816. }
  817. else
  818. {
  819. landOwnersAndParcels[p.LandData.OwnerID].Add(p);
  820. }
  821. }
  822. }
  823. foreach (UUID owner in landOwnersAndParcels.Keys)
  824. {
  825. int simArea = 0;
  826. int simPrims = 0;
  827. foreach (LandObject p in landOwnersAndParcels[owner])
  828. {
  829. simArea += p.LandData.Area;
  830. simPrims += p.PrimCounts.Total;
  831. }
  832. foreach (LandObject p in landOwnersAndParcels[owner])
  833. {
  834. p.LandData.SimwideArea = simArea;
  835. p.LandData.SimwidePrims = simPrims;
  836. }
  837. }
  838. }
  839. public void EventManagerOnParcelPrimCountUpdate()
  840. {
  841. // m_log.DebugFormat(
  842. // "[LAND MANAGEMENT MODULE]: Triggered EventManagerOnParcelPrimCountUpdate() for {0}",
  843. // m_scene.RegionInfo.RegionName);
  844. ResetOverMeRecords();
  845. EntityBase[] entities = m_scene.Entities.GetEntities();
  846. foreach (EntityBase obj in entities)
  847. {
  848. if (obj != null)
  849. {
  850. if ((obj is SceneObjectGroup) && !obj.IsDeleted && !((SceneObjectGroup) obj).IsAttachment)
  851. {
  852. m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj);
  853. }
  854. }
  855. }
  856. FinalizeLandPrimCountUpdate();
  857. }
  858. public void EventManagerOnRequestParcelPrimCountUpdate()
  859. {
  860. ResetOverMeRecords();
  861. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  862. FinalizeLandPrimCountUpdate();
  863. }
  864. /// <summary>
  865. /// Subdivides a piece of land
  866. /// </summary>
  867. /// <param name="start_x">West Point</param>
  868. /// <param name="start_y">South Point</param>
  869. /// <param name="end_x">East Point</param>
  870. /// <param name="end_y">North Point</param>
  871. /// <param name="attempting_user_id">UUID of user who is trying to subdivide</param>
  872. /// <returns>Returns true if successful</returns>
  873. private void subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  874. {
  875. //First, lets loop through the points and make sure they are all in the same peice of land
  876. //Get the land object at start
  877. ILandObject startLandObject = GetLandObject(start_x, start_y);
  878. if (startLandObject == null) return;
  879. //Loop through the points
  880. try
  881. {
  882. int totalX = end_x - start_x;
  883. int totalY = end_y - start_y;
  884. for (int y = 0; y < totalY; y++)
  885. {
  886. for (int x = 0; x < totalX; x++)
  887. {
  888. ILandObject tempLandObject = GetLandObject(start_x + x, start_y + y);
  889. if (tempLandObject == null) return;
  890. if (tempLandObject != startLandObject) return;
  891. }
  892. }
  893. }
  894. catch (Exception)
  895. {
  896. return;
  897. }
  898. //If we are still here, then they are subdividing within one piece of land
  899. //Check owner
  900. if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin))
  901. {
  902. return;
  903. }
  904. //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
  905. ILandObject newLand = startLandObject.Copy();
  906. newLand.LandData.Name = newLand.LandData.Name;
  907. newLand.LandData.GlobalID = UUID.Random();
  908. newLand.LandData.Dwell = 0;
  909. newLand.SetLandBitmap(newLand.GetSquareLandBitmap(start_x, start_y, end_x, end_y));
  910. //Now, lets set the subdivision area of the original to false
  911. int startLandObjectIndex = startLandObject.LandData.LocalID;
  912. lock (m_landList)
  913. {
  914. m_landList[startLandObjectIndex].SetLandBitmap(
  915. newLand.ModifyLandBitmapSquare(startLandObject.GetLandBitmap(), start_x, start_y, end_x, end_y, false));
  916. m_landList[startLandObjectIndex].ForceUpdateLandInfo();
  917. }
  918. //Now add the new land object
  919. ILandObject result = AddLandObject(newLand);
  920. if (result != null)
  921. {
  922. UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData);
  923. result.SendLandUpdateToAvatarsOverMe();
  924. }
  925. }
  926. /// <summary>
  927. /// Join 2 land objects together
  928. /// </summary>
  929. /// <param name="start_x">x value in first piece of land</param>
  930. /// <param name="start_y">y value in first piece of land</param>
  931. /// <param name="end_x">x value in second peice of land</param>
  932. /// <param name="end_y">y value in second peice of land</param>
  933. /// <param name="attempting_user_id">UUID of the avatar trying to join the land objects</param>
  934. /// <returns>Returns true if successful</returns>
  935. private void join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  936. {
  937. end_x -= 4;
  938. end_y -= 4;
  939. List<ILandObject> selectedLandObjects = new List<ILandObject>();
  940. int stepYSelected;
  941. for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
  942. {
  943. int stepXSelected;
  944. for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
  945. {
  946. ILandObject p = GetLandObject(stepXSelected, stepYSelected);
  947. if (p != null)
  948. {
  949. if (!selectedLandObjects.Contains(p))
  950. {
  951. selectedLandObjects.Add(p);
  952. }
  953. }
  954. }
  955. }
  956. ILandObject masterLandObject = selectedLandObjects[0];
  957. selectedLandObjects.RemoveAt(0);
  958. if (selectedLandObjects.Count < 1)
  959. {
  960. return;
  961. }
  962. if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, masterLandObject, GroupPowers.LandDivideJoin))
  963. {
  964. return;
  965. }
  966. foreach (ILandObject p in selectedLandObjects)
  967. {
  968. if (p.LandData.OwnerID != masterLandObject.LandData.OwnerID)
  969. {
  970. return;
  971. }
  972. }
  973. lock (m_landList)
  974. {
  975. foreach (ILandObject slaveLandObject in selectedLandObjects)
  976. {
  977. m_landList[masterLandObject.LandData.LocalID].SetLandBitmap(
  978. slaveLandObject.MergeLandBitmaps(masterLandObject.GetLandBitmap(), slaveLandObject.GetLandBitmap()));
  979. performFinalLandJoin(masterLandObject, slaveLandObject);
  980. }
  981. }
  982. masterLandObject.SendLandUpdateToAvatarsOverMe();
  983. }
  984. public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  985. {
  986. join(start_x, start_y, end_x, end_y, attempting_user_id);
  987. }
  988. public void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  989. {
  990. subdivide(start_x, start_y, end_x, end_y, attempting_user_id);
  991. }
  992. #endregion
  993. #region Parcel Updating
  994. /// <summary>
  995. /// Where we send the ParcelOverlay packet to the client
  996. /// </summary>
  997. /// <param name="remote_client">The object representing the client</param>
  998. public void SendParcelOverlay(IClientAPI remote_client)
  999. {
  1000. const int LAND_BLOCKS_PER_PACKET = 1024;
  1001. byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  1002. int byteArrayCount = 0;
  1003. int sequenceID = 0;
  1004. // Layer data is in landUnit (4m) chunks
  1005. for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
  1006. {
  1007. for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++)
  1008. {
  1009. byteArray[byteArrayCount] = BuildLayerByte(GetLandObject(x * LandUnit, y * LandUnit), x, y, remote_client);
  1010. byteArrayCount++;
  1011. if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
  1012. {
  1013. remote_client.SendLandParcelOverlay(byteArray, sequenceID);
  1014. byteArrayCount = 0;
  1015. sequenceID++;
  1016. byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  1017. }
  1018. }
  1019. }
  1020. if (byteArrayCount != 0)
  1021. {
  1022. remote_client.SendLandParcelOverlay(byteArray, sequenceID);
  1023. }
  1024. }
  1025. private byte BuildLayerByte(ILandObject currentParcelBlock, int x, int y, IClientAPI remote_client)
  1026. {
  1027. byte tempByte = 0; //This represents the byte for the current 4x4
  1028. if (currentParcelBlock != null)
  1029. {
  1030. if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId)
  1031. {
  1032. //Owner Flag
  1033. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
  1034. }
  1035. else if (currentParcelBlock.LandData.SalePrice > 0 &&
  1036. (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
  1037. currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
  1038. {
  1039. //Sale Flag
  1040. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
  1041. }
  1042. else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
  1043. {
  1044. //Public Flag
  1045. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
  1046. }
  1047. else
  1048. {
  1049. //Other Flag
  1050. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
  1051. }
  1052. //Now for border control
  1053. ILandObject westParcel = null;
  1054. ILandObject southParcel = null;
  1055. if (x > 0)
  1056. {
  1057. westParcel = GetLandObject((x - 1) * LandUnit, y * LandUnit);
  1058. }
  1059. if (y > 0)
  1060. {
  1061. southParcel = GetLandObject(x * LandUnit, (y - 1) * LandUnit);
  1062. }
  1063. if (x == 0)
  1064. {
  1065. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  1066. }
  1067. else if (westParcel != null && westParcel != currentParcelBlock)
  1068. {
  1069. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  1070. }
  1071. if (y == 0)
  1072. {
  1073. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  1074. }
  1075. else if (southParcel != null && southParcel != currentParcelBlock)
  1076. {
  1077. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  1078. }
  1079. }
  1080. return tempByte;
  1081. }
  1082. public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
  1083. bool snap_selection, IClientAPI remote_client)
  1084. {
  1085. //Get the land objects within the bounds
  1086. List<ILandObject> temp = new List<ILandObject>();
  1087. int inc_x = end_x - start_x;
  1088. int inc_y = end_y - start_y;
  1089. for (int x = 0; x < inc_x; x++)
  1090. {
  1091. for (int y = 0; y < inc_y; y++)
  1092. {
  1093. ILandObject currentParcel = GetLandObject(start_x + x, start_y + y);
  1094. if (currentParcel != null)
  1095. {
  1096. if (!temp.Contains(currentParcel))
  1097. {
  1098. currentParcel.ForceUpdateLandInfo();
  1099. temp.Add(currentParcel);
  1100. }
  1101. }
  1102. }
  1103. }
  1104. int requestResult = LandChannel.LAND_RESULT_SINGLE;
  1105. if (temp.Count > 1)
  1106. {
  1107. requestResult = LandChannel.LAND_RESULT_MULTIPLE;
  1108. }
  1109. for (int i = 0; i < temp.Count; i++)
  1110. {
  1111. temp[i].SendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
  1112. }
  1113. SendParcelOverlay(remote_client);
  1114. }
  1115. public void ClientOnParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
  1116. {
  1117. ILandObject land;
  1118. lock (m_landList)
  1119. {
  1120. m_landList.TryGetValue(localID, out land);
  1121. }
  1122. if (land != null)
  1123. {
  1124. land.UpdateLandProperties(args, remote_client);
  1125. m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client);
  1126. }
  1127. }
  1128. public void ClientOnParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
  1129. {
  1130. subdivide(west, south, east, north, remote_client.AgentId);
  1131. }
  1132. public void ClientOnParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
  1133. {
  1134. join(west, south, east, north, remote_client.AgentId);
  1135. }
  1136. public void ClientOnParcelSelectObjects(int local_id, int request_type,
  1137. List<UUID> returnIDs, IClientAPI remote_client)
  1138. {
  1139. m_landList[local_id].SendForceObjectSelect(local_id, request_type, returnIDs, remote_client);
  1140. }
  1141. public void ClientOnParcelObjectOwnerRequest(int local_id, IClientAPI remote_client)
  1142. {
  1143. ILandObject land;
  1144. lock (m_landList)
  1145. {
  1146. m_landList.TryGetValue(local_id, out land);
  1147. }
  1148. if (land != null)
  1149. {
  1150. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  1151. m_landList[local_id].SendLandObjectOwners(remote_client);
  1152. }
  1153. else
  1154. {
  1155. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid land object {0} passed for parcel object owner request", local_id);
  1156. }
  1157. }
  1158. public void ClientOnParcelGodForceOwner(int local_id, UUID ownerID, IClientAPI remote_client)
  1159. {
  1160. ILandObject land;
  1161. lock (m_landList)
  1162. {
  1163. m_landList.TryGetValue(local_id, out land);
  1164. }
  1165. if (land != null)
  1166. {
  1167. if (m_scene.Permissions.IsGod(remote_client.AgentId))
  1168. {
  1169. land.LandData.OwnerID = ownerID;
  1170. land.LandData.GroupID = UUID.Zero;
  1171. land.LandData.IsGroupOwned = false;
  1172. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1173. m_scene.ForEachClient(SendParcelOverlay);
  1174. land.SendLandUpdateToClient(true, remote_client);
  1175. UpdateLandObject(land.LandData.LocalID, land.LandData);
  1176. }
  1177. }
  1178. }
  1179. public void ClientOnParcelAbandonRequest(int local_id, IClientAPI remote_client)
  1180. {
  1181. ILandObject land;
  1182. lock (m_landList)
  1183. {
  1184. m_landList.TryGetValue(local_id, out land);
  1185. }
  1186. if (land != null)
  1187. {
  1188. if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land))
  1189. {
  1190. land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  1191. land.LandData.GroupID = UUID.Zero;
  1192. land.LandData.IsGroupOwned = false;
  1193. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1194. m_scene.ForEachClient(SendParcelOverlay);
  1195. land.SendLandUpdateToClient(true, remote_client);
  1196. UpdateLandObject(land.LandData.LocalID, land.LandData);
  1197. }
  1198. }
  1199. }
  1200. public void ClientOnParcelReclaim(int local_id, IClientAPI remote_client)
  1201. {
  1202. ILandObject land;
  1203. lock (m_landList)
  1204. {
  1205. m_landList.TryGetValue(local_id, out land);
  1206. }
  1207. if (land != null)
  1208. {
  1209. if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land))
  1210. {
  1211. land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  1212. land.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
  1213. land.LandData.GroupID = UUID.Zero;
  1214. land.LandData.IsGroupOwned = false;
  1215. land.LandData.SalePrice = 0;
  1216. land.LandData.AuthBuyerID = UUID.Zero;
  1217. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1218. m_scene.ForEachClient(SendParcelOverlay);
  1219. land.SendLandUpdateToClient(true, remote_client);
  1220. UpdateLandObject(land.LandData.LocalID, land.LandData);
  1221. }
  1222. }
  1223. }
  1224. #endregion
  1225. // If the economy has been validated by the economy module,
  1226. // and land has been validated as well, this method transfers
  1227. // the land ownership
  1228. public void EventManagerOnLandBuy(Object o, EventManager.LandBuyArgs e)
  1229. {
  1230. if (e.economyValidated && e.landValidated)
  1231. {
  1232. ILandObject land;
  1233. lock (m_landList)
  1234. {
  1235. m_landList.TryGetValue(e.parcelLocalID, out land);
  1236. }
  1237. if (land != null)
  1238. {
  1239. land.UpdateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea);
  1240. }
  1241. }
  1242. }
  1243. // After receiving a land buy packet, first the data needs to
  1244. // be validated. This method validates the right to buy the
  1245. // parcel
  1246. public void EventManagerOnValidateLandBuy(Object o, EventManager.LandBuyArgs e)
  1247. {
  1248. if (e.landValidated == false)
  1249. {
  1250. ILandObject lob = null;
  1251. lock (m_landList)
  1252. {
  1253. m_landList.TryGetValue(e.parcelLocalID, out lob);
  1254. }
  1255. if (lob != null)
  1256. {
  1257. UUID AuthorizedID = lob.LandData.AuthBuyerID;
  1258. int saleprice = lob.LandData.SalePrice;
  1259. UUID pOwnerID = lob.LandData.OwnerID;
  1260. bool landforsale = ((lob.LandData.Flags &
  1261. (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0);
  1262. if ((AuthorizedID == UUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
  1263. {
  1264. // TODO I don't think we have to lock it here, no?
  1265. //lock (e)
  1266. //{
  1267. e.parcelOwnerID = pOwnerID;
  1268. e.landValidated = true;
  1269. //}
  1270. }
  1271. }
  1272. }
  1273. }
  1274. void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client)
  1275. {
  1276. ILandObject land;
  1277. lock (m_landList)
  1278. {
  1279. m_landList.TryGetValue(parcelLocalID, out land);
  1280. }
  1281. if (!m_scene.Permissions.CanDeedParcel(remote_client.AgentId, land))
  1282. return;
  1283. if (land != null)
  1284. {
  1285. land.DeedToGroup(groupID);
  1286. }
  1287. }
  1288. #region Land Object From Storage Functions
  1289. private void EventManagerOnIncomingLandDataFromStorage(List<LandData> data)
  1290. {
  1291. // m_log.DebugFormat(
  1292. // "[LAND MANAGMENT MODULE]: Processing {0} incoming parcels on {1}", data.Count, m_scene.Name);
  1293. // Prevent race conditions from any auto-creation of new parcels for varregions whilst we are still loading
  1294. // the existing parcels.
  1295. lock (m_landList)
  1296. {
  1297. for (int i = 0; i < data.Count; i++)
  1298. IncomingLandObjectFromStorage(data[i]);
  1299. // Layer data is in landUnit (4m) chunks
  1300. for (int y = 0; y < m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); y++)
  1301. {
  1302. for (int x = 0; x < m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize * (Constants.TerrainPatchSize / LandUnit); x++)
  1303. {
  1304. if (m_landIDList[x, y] == 0)
  1305. {
  1306. if (m_landList.Count == 1)
  1307. {
  1308. m_log.DebugFormat(
  1309. "[{0}]: Auto-extending land parcel as landID at {1},{2} is 0 and only one land parcel is present in {3}",
  1310. LogHeader, x, y, m_scene.Name);
  1311. int onlyParcelID = 0;
  1312. ILandObject onlyLandObject = null;
  1313. foreach (KeyValuePair<int, ILandObject> kvp in m_landList)
  1314. {
  1315. onlyParcelID = kvp.Key;
  1316. onlyLandObject = kvp.Value;
  1317. break;
  1318. }
  1319. // There is only one parcel. Grow it to fill all the unallocated spaces.
  1320. for (int xx = 0; xx < m_landIDList.GetLength(0); xx++)
  1321. for (int yy = 0; yy < m_landIDList.GetLength(1); yy++)
  1322. if (m_landIDList[xx, yy] == 0)
  1323. m_landIDList[xx, yy] = onlyParcelID;
  1324. onlyLandObject.LandBitmap = CreateBitmapForID(onlyParcelID);
  1325. }
  1326. else if (m_landList.Count > 1)
  1327. {
  1328. m_log.DebugFormat(
  1329. "{0}: Auto-creating land parcel as landID at {1},{2} is 0 and more than one land parcel is present in {3}",
  1330. LogHeader, x, y, m_scene.Name);
  1331. // There are several other parcels so we must create a new one for the unassigned space
  1332. ILandObject newLand = new LandObject(UUID.Zero, false, m_scene);
  1333. // Claim all the unclaimed "0" ids
  1334. newLand.SetLandBitmap(CreateBitmapForID(0));
  1335. newLand.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  1336. newLand.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
  1337. newLand = AddLandObject(newLand);
  1338. }
  1339. else
  1340. {
  1341. // We should never reach this point as the separate code path when no land data exists should have fired instead.
  1342. m_log.WarnFormat(
  1343. "{0}: Ignoring request to auto-create parcel in {1} as there are no other parcels present",
  1344. LogHeader, m_scene.Name);
  1345. }
  1346. }
  1347. }
  1348. }
  1349. }
  1350. }
  1351. private void IncomingLandObjectFromStorage(LandData data)
  1352. {
  1353. ILandObject new_land = new LandObject(data.OwnerID, data.IsGroupOwned, m_scene);
  1354. new_land.LandData = data.Copy();
  1355. new_land.SetLandBitmapFromByteArray();
  1356. AddLandObject(new_land);
  1357. }
  1358. public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient)
  1359. {
  1360. if (localID != -1)
  1361. {
  1362. ILandObject selectedParcel = null;
  1363. lock (m_landList)
  1364. {
  1365. m_landList.TryGetValue(localID, out selectedParcel);
  1366. }
  1367. if (selectedParcel == null)
  1368. return;
  1369. selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient);
  1370. }
  1371. else
  1372. {
  1373. if (returnType != 1)
  1374. {
  1375. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown return type {0}", returnType);
  1376. return;
  1377. }
  1378. // We get here when the user returns objects from the list of Top Colliders or Top Scripts.
  1379. // In that case we receive specific object UUID's, but no parcel ID.
  1380. Dictionary<UUID, HashSet<SceneObjectGroup>> returns = new Dictionary<UUID, HashSet<SceneObjectGroup>>();
  1381. foreach (UUID groupID in taskIDs)
  1382. {
  1383. SceneObjectGroup obj = m_scene.GetSceneObjectGroup(groupID);
  1384. if (obj != null)
  1385. {
  1386. if (!returns.ContainsKey(obj.OwnerID))
  1387. returns[obj.OwnerID] = new HashSet<SceneObjectGroup>();
  1388. returns[obj.OwnerID].Add(obj);
  1389. }
  1390. else
  1391. {
  1392. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown object {0}", groupID);
  1393. }
  1394. }
  1395. int num = 0;
  1396. foreach (HashSet<SceneObjectGroup> objs in returns.Values)
  1397. num += objs.Count;
  1398. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Returning {0} specific object(s)", num);
  1399. foreach (HashSet<SceneObjectGroup> objs in returns.Values)
  1400. {
  1401. List<SceneObjectGroup> objs2 = new List<SceneObjectGroup>(objs);
  1402. if (m_scene.Permissions.CanReturnObjects(null, remoteClient.AgentId, objs2))
  1403. {
  1404. m_scene.returnObjects(objs2.ToArray(), remoteClient.AgentId);
  1405. }
  1406. else
  1407. {
  1408. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: not permitted to return {0} object(s) belonging to user {1}",
  1409. objs2.Count, objs2[0].OwnerID);
  1410. }
  1411. }
  1412. }
  1413. }
  1414. public void EventManagerOnNoLandDataFromStorage()
  1415. {
  1416. ResetSimLandObjects();
  1417. CreateDefaultParcel();
  1418. }
  1419. #endregion
  1420. public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  1421. {
  1422. lock (m_landList)
  1423. {
  1424. foreach (LandObject obj in m_landList.Values)
  1425. {
  1426. obj.SetParcelObjectMaxOverride(overrideDel);
  1427. }
  1428. }
  1429. }
  1430. public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  1431. {
  1432. }
  1433. #region CAPS handler
  1434. private void EventManagerOnRegisterCaps(UUID agentID, Caps caps)
  1435. {
  1436. string capsBase = "/CAPS/" + caps.CapsObjectPath;
  1437. caps.RegisterHandler(
  1438. "RemoteParcelRequest",
  1439. new RestStreamHandler(
  1440. "POST",
  1441. capsBase + remoteParcelRequestPath,
  1442. (request, path, param, httpRequest, httpResponse)
  1443. => RemoteParcelRequest(request, path, param, agentID, caps),
  1444. "RemoteParcelRequest",
  1445. agentID.ToString()));
  1446. UUID parcelCapID = UUID.Random();
  1447. caps.RegisterHandler(
  1448. "ParcelPropertiesUpdate",
  1449. new RestStreamHandler(
  1450. "POST",
  1451. "/CAPS/" + parcelCapID,
  1452. (request, path, param, httpRequest, httpResponse)
  1453. => ProcessPropertiesUpdate(request, path, param, agentID, caps),
  1454. "ParcelPropertiesUpdate",
  1455. agentID.ToString()));
  1456. }
  1457. private string ProcessPropertiesUpdate(string request, string path, string param, UUID agentID, Caps caps)
  1458. {
  1459. IClientAPI client;
  1460. if (!m_scene.TryGetClient(agentID, out client))
  1461. {
  1462. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to retrieve IClientAPI for {0}", agentID);
  1463. return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
  1464. }
  1465. ParcelPropertiesUpdateMessage properties = new ParcelPropertiesUpdateMessage();
  1466. OpenMetaverse.StructuredData.OSDMap args = (OpenMetaverse.StructuredData.OSDMap) OSDParser.DeserializeLLSDXml(request);
  1467. properties.Deserialize(args);
  1468. LandUpdateArgs land_update = new LandUpdateArgs();
  1469. int parcelID = properties.LocalID;
  1470. land_update.AuthBuyerID = properties.AuthBuyerID;
  1471. land_update.Category = properties.Category;
  1472. land_update.Desc = properties.Desc;
  1473. land_update.GroupID = properties.GroupID;
  1474. land_update.LandingType = (byte) properties.Landing;
  1475. land_update.MediaAutoScale = (byte) Convert.ToInt32(properties.MediaAutoScale);
  1476. land_update.MediaID = properties.MediaID;
  1477. land_update.MediaURL = properties.MediaURL;
  1478. land_update.MusicURL = properties.MusicURL;
  1479. land_update.Name = properties.Name;
  1480. land_update.ParcelFlags = (uint) properties.ParcelFlags;
  1481. land_update.PassHours = (int) properties.PassHours;
  1482. land_update.PassPrice = (int) properties.PassPrice;
  1483. land_update.SalePrice = (int) properties.SalePrice;
  1484. land_update.SnapshotID = properties.SnapshotID;
  1485. land_update.UserLocation = properties.UserLocation;
  1486. land_update.UserLookAt = properties.UserLookAt;
  1487. land_update.MediaDescription = properties.MediaDesc;
  1488. land_update.MediaType = properties.MediaType;
  1489. land_update.MediaWidth = properties.MediaWidth;
  1490. land_update.MediaHeight = properties.MediaHeight;
  1491. land_update.MediaLoop = properties.MediaLoop;
  1492. land_update.ObscureMusic = properties.ObscureMusic;
  1493. land_update.ObscureMedia = properties.ObscureMedia;
  1494. ILandObject land;
  1495. lock (m_landList)
  1496. {
  1497. m_landList.TryGetValue(parcelID, out land);
  1498. }
  1499. if (land != null)
  1500. {
  1501. land.UpdateLandProperties(land_update, client);
  1502. m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(land_update, parcelID, client);
  1503. }
  1504. else
  1505. {
  1506. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID);
  1507. }
  1508. return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
  1509. }
  1510. // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the
  1511. // "real" parcelID, because we wouldn't be able to map that to the region the parcel belongs to.
  1512. // So, we create a "fake" parcelID by using the regionHandle (64 bit), and the local (integer) x
  1513. // and y coordinate (each 8 bit), encoded in a UUID (128 bit).
  1514. //
  1515. // Request format:
  1516. // <llsd>
  1517. // <map>
  1518. // <key>location</key>
  1519. // <array>
  1520. // <real>1.23</real>
  1521. // <real>45..6</real>
  1522. // <real>78.9</real>
  1523. // </array>
  1524. // <key>region_id</key>
  1525. // <uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid>
  1526. // </map>
  1527. // </llsd>
  1528. private string RemoteParcelRequest(string request, string path, string param, UUID agentID, Caps caps)
  1529. {
  1530. UUID parcelID = UUID.Zero;
  1531. try
  1532. {
  1533. Hashtable hash = new Hashtable();
  1534. hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  1535. if (hash.ContainsKey("region_id") && hash.ContainsKey("location"))
  1536. {
  1537. UUID regionID = (UUID)hash["region_id"];
  1538. ArrayList list = (ArrayList)hash["location"];
  1539. uint x = (uint)(double)list[0];
  1540. uint y = (uint)(double)list[1];
  1541. if (hash.ContainsKey("region_handle"))
  1542. {
  1543. // if you do a "About Landmark" on a landmark a second time, the viewer sends the
  1544. // region_handle it got earlier via RegionHandleRequest
  1545. ulong regionHandle = Util.BytesToUInt64Big((byte[])hash["region_handle"]);
  1546. parcelID = Util.BuildFakeParcelID(regionHandle, x, y);
  1547. }
  1548. else if (regionID == m_scene.RegionInfo.RegionID)
  1549. {
  1550. // a parcel request for a local parcel => no need to query the grid
  1551. parcelID = Util.BuildFakeParcelID(m_scene.RegionInfo.RegionHandle, x, y);
  1552. }
  1553. else
  1554. {
  1555. // a parcel request for a parcel in another region. Ask the grid about the region
  1556. GridRegion info = m_scene.GridService.GetRegionByUUID(UUID.Zero, regionID);
  1557. if (info != null)
  1558. parcelID = Util.BuildFakeParcelID(info.RegionHandle, x, y);
  1559. }
  1560. }
  1561. }
  1562. catch (LLSD.LLSDParseException e)
  1563. {
  1564. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Fetch error: {0}", e.Message);
  1565. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: ... in request {0}", request);
  1566. }
  1567. catch (InvalidCastException)
  1568. {
  1569. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Wrong type in request {0}", request);
  1570. }
  1571. LLSDRemoteParcelResponse response = new LLSDRemoteParcelResponse();
  1572. response.parcel_id = parcelID;
  1573. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelID {0}", parcelID);
  1574. return LLSDHelpers.SerialiseLLSDReply(response);
  1575. }
  1576. #endregion
  1577. private void ClientOnParcelInfoRequest(IClientAPI remoteClient, UUID parcelID)
  1578. {
  1579. if (parcelID == UUID.Zero)
  1580. return;
  1581. ExtendedLandData data = (ExtendedLandData)parcelInfoCache.Get(parcelID.ToString(),
  1582. delegate(string id)
  1583. {
  1584. UUID parcel = UUID.Zero;
  1585. UUID.TryParse(id, out parcel);
  1586. // assume we've got the parcelID we just computed in RemoteParcelRequest
  1587. ExtendedLandData extLandData = new ExtendedLandData();
  1588. Util.ParseFakeParcelID(parcel, out extLandData.RegionHandle,
  1589. out extLandData.X, out extLandData.Y);
  1590. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
  1591. extLandData.RegionHandle, extLandData.X, extLandData.Y);
  1592. // for this region or for somewhere else?
  1593. if (extLandData.RegionHandle == m_scene.RegionInfo.RegionHandle)
  1594. {
  1595. extLandData.LandData = this.GetLandObject(extLandData.X, extLandData.Y).LandData;
  1596. extLandData.RegionAccess = m_scene.RegionInfo.AccessLevel;
  1597. }
  1598. else
  1599. {
  1600. ILandService landService = m_scene.RequestModuleInterface<ILandService>();
  1601. extLandData.LandData = landService.GetLandData(m_scene.RegionInfo.ScopeID,
  1602. extLandData.RegionHandle,
  1603. extLandData.X,
  1604. extLandData.Y,
  1605. out extLandData.RegionAccess);
  1606. if (extLandData.LandData == null)
  1607. {
  1608. // we didn't find the region/land => don't cache
  1609. return null;
  1610. }
  1611. }
  1612. return extLandData;
  1613. });
  1614. if (data != null) // if we found some data, send it
  1615. {
  1616. GridRegion info;
  1617. if (data.RegionHandle == m_scene.RegionInfo.RegionHandle)
  1618. {
  1619. info = new GridRegion(m_scene.RegionInfo);
  1620. }
  1621. else
  1622. {
  1623. // most likely still cached from building the extLandData entry
  1624. uint x = 0, y = 0;
  1625. Util.RegionHandleToWorldLoc(data.RegionHandle, out x, out y);
  1626. info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
  1627. }
  1628. // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
  1629. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: got parcelinfo for parcel {0} in region {1}; sending...",
  1630. data.LandData.Name, data.RegionHandle);
  1631. // HACK for now
  1632. RegionInfo r = new RegionInfo();
  1633. r.RegionName = info.RegionName;
  1634. r.RegionLocX = (uint)info.RegionLocX;
  1635. r.RegionLocY = (uint)info.RegionLocY;
  1636. r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess);
  1637. remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y);
  1638. }
  1639. else
  1640. m_log.Debug("[LAND MANAGEMENT MODULE]: got no parcelinfo; not sending");
  1641. }
  1642. public void setParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime)
  1643. {
  1644. ILandObject land;
  1645. lock (m_landList)
  1646. {
  1647. m_landList.TryGetValue(localID, out land);
  1648. }
  1649. if (land == null) return;
  1650. if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions))
  1651. return;
  1652. land.LandData.OtherCleanTime = otherCleanTime;
  1653. UpdateLandObject(localID, land.LandData);
  1654. }
  1655. Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>();
  1656. public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
  1657. {
  1658. ScenePresence targetAvatar = null;
  1659. ((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar);
  1660. ScenePresence parcelManager = null;
  1661. ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager);
  1662. System.Threading.Timer Timer;
  1663. if (targetAvatar.UserLevel == 0)
  1664. {
  1665. ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
  1666. if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze))
  1667. return;
  1668. if (flags == 0)
  1669. {
  1670. targetAvatar.AllowMovement = false;
  1671. targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has frozen you for 30 seconds. You cannot move or interact with the world.");
  1672. parcelManager.ControllingClient.SendAlertMessage("Avatar Frozen.");
  1673. System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(OnEndParcelFrozen);
  1674. Timer = new System.Threading.Timer(timeCB, targetAvatar, 30000, 0);
  1675. Timers.Add(targetAvatar.UUID, Timer);
  1676. }
  1677. else
  1678. {
  1679. targetAvatar.AllowMovement = true;
  1680. targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has unfrozen you.");
  1681. parcelManager.ControllingClient.SendAlertMessage("Avatar Unfrozen.");
  1682. Timers.TryGetValue(targetAvatar.UUID, out Timer);
  1683. Timers.Remove(targetAvatar.UUID);
  1684. Timer.Dispose();
  1685. }
  1686. }
  1687. }
  1688. private void OnEndParcelFrozen(object avatar)
  1689. {
  1690. ScenePresence targetAvatar = (ScenePresence)avatar;
  1691. targetAvatar.AllowMovement = true;
  1692. System.Threading.Timer Timer;
  1693. Timers.TryGetValue(targetAvatar.UUID, out Timer);
  1694. Timers.Remove(targetAvatar.UUID);
  1695. targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false);
  1696. }
  1697. public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
  1698. {
  1699. ScenePresence targetAvatar = null;
  1700. ScenePresence parcelManager = null;
  1701. // Must have presences
  1702. if (!m_scene.TryGetScenePresence(target, out targetAvatar) ||
  1703. !m_scene.TryGetScenePresence(client.AgentId, out parcelManager))
  1704. return;
  1705. // Cannot eject estate managers or gods
  1706. if (m_scene.Permissions.IsAdministrator(target))
  1707. return;
  1708. // Check if you even have permission to do this
  1709. ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
  1710. if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) &&
  1711. !m_scene.Permissions.IsAdministrator(client.AgentId))
  1712. return;
  1713. Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
  1714. targetAvatar.TeleportWithMomentum(pos, null);
  1715. targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
  1716. parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
  1717. if ((flags & 1) != 0) // Ban TODO: Remove magic number
  1718. {
  1719. LandAccessEntry entry = new LandAccessEntry();
  1720. entry.AgentID = targetAvatar.UUID;
  1721. entry.Flags = AccessList.Ban;
  1722. entry.Expires = 0; // Perm
  1723. land.LandData.ParcelAccessList.Add(entry);
  1724. }
  1725. }
  1726. /// <summary>
  1727. /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
  1728. /// </summary>
  1729. /// <param name="remoteClient"></param>
  1730. /// <param name="regionHandle"></param>
  1731. /// <param name="position"></param>
  1732. /// <param name="lookAt"></param>
  1733. /// <param name="flags"></param>
  1734. public virtual void ClientOnSetHome(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
  1735. {
  1736. // Let's find the parcel in question
  1737. ILandObject land = landChannel.GetLandObject(position);
  1738. if (land == null || m_scene.GridUserService == null)
  1739. {
  1740. m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
  1741. return;
  1742. }
  1743. // Gather some data
  1744. ulong gpowers = remoteClient.GetGroupPowers(land.LandData.GroupID);
  1745. SceneObjectGroup telehub = null;
  1746. if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero)
  1747. // Does the telehub exist in the scene?
  1748. telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject);
  1749. // Can the user set home here?
  1750. if (// (a) gods and land managers can set home
  1751. m_scene.Permissions.IsAdministrator(remoteClient.AgentId) ||
  1752. m_scene.Permissions.IsGod(remoteClient.AgentId) ||
  1753. // (b) land owners can set home
  1754. remoteClient.AgentId == land.LandData.OwnerID ||
  1755. // (c) members of the land-associated group in roles that can set home
  1756. ((gpowers & (ulong)GroupPowers.AllowSetHome) == (ulong)GroupPowers.AllowSetHome) ||
  1757. // (d) parcels with telehubs can be the home of anyone
  1758. (telehub != null && land.ContainsPoint((int)telehub.AbsolutePosition.X, (int)telehub.AbsolutePosition.Y)))
  1759. {
  1760. if (m_scene.GridUserService.SetHome(remoteClient.AgentId.ToString(), land.RegionUUID, position, lookAt))
  1761. // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
  1762. m_Dialog.SendAlertToUser(remoteClient, "Home position set.");
  1763. else
  1764. m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
  1765. }
  1766. else
  1767. m_Dialog.SendAlertToUser(remoteClient, "You are not allowed to set your home location in this parcel.");
  1768. }
  1769. protected void RegisterCommands()
  1770. {
  1771. ICommands commands = MainConsole.Instance.Commands;
  1772. commands.AddCommand(
  1773. "Land", false, "land clear",
  1774. "land clear",
  1775. "Clear all the parcels from the region.",
  1776. "Command will ask for confirmation before proceeding.",
  1777. HandleClearCommand);
  1778. commands.AddCommand(
  1779. "Land", false, "land show",
  1780. "land show [<local-land-id>]",
  1781. "Show information about the parcels on the region.",
  1782. "If no local land ID is given, then summary information about all the parcels is shown.\n"
  1783. + "If a local land ID is given then full information about that parcel is shown.",
  1784. HandleShowCommand);
  1785. }
  1786. protected void HandleClearCommand(string module, string[] args)
  1787. {
  1788. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  1789. return;
  1790. string response = MainConsole.Instance.CmdPrompt(
  1791. string.Format(
  1792. "Are you sure that you want to clear all land parcels from {0} (y or n)", m_scene.Name),
  1793. "n");
  1794. if (response.ToLower() == "y")
  1795. {
  1796. Clear(true);
  1797. MainConsole.Instance.OutputFormat("Cleared all parcels from {0}", m_scene.Name);
  1798. }
  1799. else
  1800. {
  1801. MainConsole.Instance.OutputFormat("Aborting clear of all parcels from {0}", m_scene.Name);
  1802. }
  1803. }
  1804. protected void HandleShowCommand(string module, string[] args)
  1805. {
  1806. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  1807. return;
  1808. StringBuilder report = new StringBuilder();
  1809. if (args.Length <= 2)
  1810. {
  1811. AppendParcelsSummaryReport(report);
  1812. }
  1813. else
  1814. {
  1815. int landLocalId;
  1816. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[2], out landLocalId))
  1817. return;
  1818. ILandObject lo;
  1819. lock (m_landList)
  1820. {
  1821. if (!m_landList.TryGetValue(landLocalId, out lo))
  1822. {
  1823. MainConsole.Instance.OutputFormat("No parcel found with local ID {0}", landLocalId);
  1824. return;
  1825. }
  1826. }
  1827. AppendParcelReport(report, lo);
  1828. }
  1829. MainConsole.Instance.Output(report.ToString());
  1830. }
  1831. private void AppendParcelsSummaryReport(StringBuilder report)
  1832. {
  1833. report.AppendFormat("Land information for {0}\n", m_scene.Name);
  1834. ConsoleDisplayTable cdt = new ConsoleDisplayTable();
  1835. cdt.AddColumn("Parcel Name", ConsoleDisplayUtil.ParcelNameSize);
  1836. cdt.AddColumn("ID", 3);
  1837. cdt.AddColumn("Area", 6);
  1838. cdt.AddColumn("Starts", ConsoleDisplayUtil.VectorSize);
  1839. cdt.AddColumn("Ends", ConsoleDisplayUtil.VectorSize);
  1840. cdt.AddColumn("Owner", ConsoleDisplayUtil.UserNameSize);
  1841. lock (m_landList)
  1842. {
  1843. foreach (ILandObject lo in m_landList.Values)
  1844. {
  1845. LandData ld = lo.LandData;
  1846. cdt.AddRow(
  1847. ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, m_userManager.GetUserName(ld.OwnerID));
  1848. }
  1849. }
  1850. report.Append(cdt.ToString());
  1851. }
  1852. private void AppendParcelReport(StringBuilder report, ILandObject lo)
  1853. {
  1854. LandData ld = lo.LandData;
  1855. ConsoleDisplayList cdl = new ConsoleDisplayList();
  1856. cdl.AddRow("Parcel name", ld.Name);
  1857. cdl.AddRow("Local ID", ld.LocalID);
  1858. cdl.AddRow("Description", ld.Description);
  1859. cdl.AddRow("Snapshot ID", ld.SnapshotID);
  1860. cdl.AddRow("Area", ld.Area);
  1861. cdl.AddRow("Starts", lo.StartPoint);
  1862. cdl.AddRow("Ends", lo.EndPoint);
  1863. cdl.AddRow("AABB Min", ld.AABBMin);
  1864. cdl.AddRow("AABB Max", ld.AABBMax);
  1865. cdl.AddRow("Owner", m_userManager.GetUserName(ld.OwnerID));
  1866. cdl.AddRow("Is group owned?", ld.IsGroupOwned);
  1867. cdl.AddRow("GroupID", ld.GroupID);
  1868. cdl.AddRow("Status", ld.Status);
  1869. cdl.AddRow("Flags", (ParcelFlags)ld.Flags);
  1870. cdl.AddRow("Landing Type", (LandingType)ld.LandingType);
  1871. cdl.AddRow("User Location", ld.UserLocation);
  1872. cdl.AddRow("User look at", ld.UserLookAt);
  1873. cdl.AddRow("Other clean time", ld.OtherCleanTime);
  1874. cdl.AddRow("Max Prims", lo.GetParcelMaxPrimCount());
  1875. IPrimCounts pc = lo.PrimCounts;
  1876. cdl.AddRow("Owner Prims", pc.Owner);
  1877. cdl.AddRow("Group Prims", pc.Group);
  1878. cdl.AddRow("Other Prims", pc.Others);
  1879. cdl.AddRow("Selected Prims", pc.Selected);
  1880. cdl.AddRow("Total Prims", pc.Total);
  1881. cdl.AddRow("Music URL", ld.MusicURL);
  1882. cdl.AddRow("Obscure Music", ld.ObscureMusic);
  1883. cdl.AddRow("Media ID", ld.MediaID);
  1884. cdl.AddRow("Media Autoscale", Convert.ToBoolean(ld.MediaAutoScale));
  1885. cdl.AddRow("Media URL", ld.MediaURL);
  1886. cdl.AddRow("Media Type", ld.MediaType);
  1887. cdl.AddRow("Media Description", ld.MediaDescription);
  1888. cdl.AddRow("Media Width", ld.MediaWidth);
  1889. cdl.AddRow("Media Height", ld.MediaHeight);
  1890. cdl.AddRow("Media Loop", ld.MediaLoop);
  1891. cdl.AddRow("Obscure Media", ld.ObscureMedia);
  1892. cdl.AddRow("Parcel Category", ld.Category);
  1893. cdl.AddRow("Claim Date", ld.ClaimDate);
  1894. cdl.AddRow("Claim Price", ld.ClaimPrice);
  1895. cdl.AddRow("Pass Hours", ld.PassHours);
  1896. cdl.AddRow("Pass Price", ld.PassPrice);
  1897. cdl.AddRow("Auction ID", ld.AuctionID);
  1898. cdl.AddRow("Authorized Buyer ID", ld.AuthBuyerID);
  1899. cdl.AddRow("Sale Price", ld.SalePrice);
  1900. cdl.AddToStringBuilder(report);
  1901. }
  1902. }
  1903. }