LandManagementModule.cs 109 KB

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