LandManagementModule.cs 88 KB

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