LandManagementModule.cs 100 KB

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