LandManagementModule.cs 70 KB

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