LandManagementModule.cs 110 KB

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