LandManagementModule.cs 104 KB

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