LandObject.cs 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900
  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.Generic;
  29. using System.Reflection;
  30. using log4net;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Framework.Interfaces;
  34. using OpenSim.Region.Framework.Scenes;
  35. using RegionFlags = OpenMetaverse.RegionFlags;
  36. namespace OpenSim.Region.CoreModules.World.Land
  37. {
  38. /// <summary>
  39. /// Keeps track of a specific piece of land's information
  40. /// </summary>
  41. public class LandObject : ILandObject
  42. {
  43. #region Member Variables
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. private static readonly string LogHeader = "[LAND OBJECT]";
  46. private readonly int landUnit = 4;
  47. private int m_lastSeqId = 0;
  48. private int m_expiryCounter = 0;
  49. protected Scene m_scene;
  50. protected List<SceneObjectGroup> primsOverMe = new List<SceneObjectGroup>();
  51. protected Dictionary<uint, UUID> m_listTransactions = new Dictionary<uint, UUID>();
  52. protected ExpiringCache<UUID, bool> m_groupMemberCache = new ExpiringCache<UUID, bool>();
  53. protected TimeSpan m_groupMemberCacheTimeout = TimeSpan.FromSeconds(30); // cache invalidation after 30 seconds
  54. IDwellModule m_dwellModule;
  55. private bool[,] m_landBitmap;
  56. public bool[,] LandBitmap
  57. {
  58. get { return m_landBitmap; }
  59. set { m_landBitmap = value; }
  60. }
  61. #endregion
  62. public int GetPrimsFree()
  63. {
  64. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  65. int free = GetSimulatorMaxPrimCount() - LandData.SimwidePrims;
  66. return free;
  67. }
  68. protected LandData m_landData;
  69. public LandData LandData
  70. {
  71. get { return m_landData; }
  72. set { m_landData = value; }
  73. }
  74. public IPrimCounts PrimCounts { get; set; }
  75. public UUID RegionUUID
  76. {
  77. get { return m_scene.RegionInfo.RegionID; }
  78. }
  79. private Vector2 m_startPoint = Vector2.Zero;
  80. private Vector2 m_endPoint = Vector2.Zero;
  81. private Vector2 m_centerPoint = Vector2.Zero;
  82. private Vector2 m_AABBmin = Vector2.Zero;
  83. private Vector2 m_AABBmax = Vector2.Zero;
  84. public Vector2 StartPoint
  85. {
  86. get
  87. {
  88. return m_startPoint;
  89. }
  90. }
  91. public Vector2 EndPoint
  92. {
  93. get
  94. {
  95. return m_endPoint;
  96. }
  97. }
  98. //estimate a center point of a parcel
  99. public Vector2 CenterPoint
  100. {
  101. get
  102. {
  103. return m_centerPoint;
  104. }
  105. }
  106. public Vector2? GetNearestPoint(Vector3 pos)
  107. {
  108. Vector3 direction = new Vector3(m_centerPoint.X - pos.X, m_centerPoint.Y - pos.Y, 0f );
  109. return GetNearestPointAlongDirection(pos, direction);
  110. }
  111. public Vector2? GetNearestPointAlongDirection(Vector3 pos, Vector3 pdirection)
  112. {
  113. Vector2 testpos;
  114. Vector2 direction;
  115. testpos.X = pos.X / landUnit;
  116. testpos.Y = pos.Y / landUnit;
  117. if(LandBitmap[(int)testpos.X, (int)testpos.Y])
  118. return new Vector2(pos.X, pos.Y); // we are already here
  119. direction.X = pdirection.X;
  120. direction.Y = pdirection.Y;
  121. if(direction.X == 0f && direction.Y == 0f)
  122. return null; // we can't look anywhere
  123. direction.Normalize();
  124. int minx = (int)(m_AABBmin.X / landUnit);
  125. int maxx = (int)(m_AABBmax.X / landUnit);
  126. // check against AABB
  127. if(direction.X > 0f)
  128. {
  129. if(testpos.X >= maxx)
  130. return null; // will never get there
  131. if(testpos.X < minx)
  132. testpos.X = minx;
  133. }
  134. else if(direction.X < 0f)
  135. {
  136. if(testpos.X < minx)
  137. return null; // will never get there
  138. if(testpos.X >= maxx)
  139. testpos.X = maxx - 1;
  140. }
  141. else
  142. {
  143. if(testpos.X < minx)
  144. return null; // will never get there
  145. else if(testpos.X >= maxx)
  146. return null; // will never get there
  147. }
  148. int miny = (int)(m_AABBmin.Y / landUnit);
  149. int maxy = (int)(m_AABBmax.Y / landUnit);
  150. if(direction.Y > 0f)
  151. {
  152. if(testpos.Y >= maxy)
  153. return null; // will never get there
  154. if(testpos.Y < miny)
  155. testpos.Y = miny;
  156. }
  157. else if(direction.Y < 0f)
  158. {
  159. if(testpos.Y < miny)
  160. return null; // will never get there
  161. if(testpos.Y >= maxy)
  162. testpos.Y = maxy - 1;
  163. }
  164. else
  165. {
  166. if(testpos.Y < miny)
  167. return null; // will never get there
  168. else if(testpos.Y >= maxy)
  169. return null; // will never get there
  170. }
  171. while(!LandBitmap[(int)testpos.X, (int)testpos.Y])
  172. {
  173. testpos += direction;
  174. if(testpos.X < minx)
  175. return null;
  176. if (testpos.X >= maxx)
  177. return null;
  178. if(testpos.Y < miny)
  179. return null;
  180. if (testpos.Y >= maxy)
  181. return null;
  182. }
  183. testpos *= landUnit;
  184. float ftmp;
  185. if(Math.Abs(direction.X) > Math.Abs(direction.Y))
  186. {
  187. if(direction.X < 0)
  188. testpos.X += landUnit - 0.5f;
  189. else
  190. testpos.X += 0.5f;
  191. ftmp = testpos.X - pos.X;
  192. ftmp /= direction.X;
  193. ftmp = Math.Abs(ftmp);
  194. ftmp *= direction.Y;
  195. ftmp += pos.Y;
  196. if(ftmp < testpos.Y + .5f)
  197. ftmp = testpos.Y + .5f;
  198. else
  199. {
  200. testpos.Y += landUnit - 0.5f;
  201. if(ftmp > testpos.Y)
  202. ftmp = testpos.Y;
  203. }
  204. testpos.Y = ftmp;
  205. }
  206. else
  207. {
  208. if(direction.Y < 0)
  209. testpos.Y += landUnit - 0.5f;
  210. else
  211. testpos.Y += 0.5f;
  212. ftmp = testpos.Y - pos.Y;
  213. ftmp /= direction.Y;
  214. ftmp = Math.Abs(ftmp);
  215. ftmp *= direction.X;
  216. ftmp += pos.X;
  217. if(ftmp < testpos.X + .5f)
  218. ftmp = testpos.X + .5f;
  219. else
  220. {
  221. testpos.X += landUnit - 0.5f;
  222. if(ftmp > testpos.X)
  223. ftmp = testpos.X;
  224. }
  225. testpos.X = ftmp;
  226. }
  227. return testpos;
  228. }
  229. #region Constructors
  230. public LandObject(LandData landData, Scene scene)
  231. {
  232. LandData = landData.Copy();
  233. m_scene = scene;
  234. m_scene.EventManager.OnFrame += OnFrame;
  235. m_dwellModule = m_scene.RequestModuleInterface<IDwellModule>();
  236. }
  237. public LandObject(UUID owner_id, bool is_group_owned, Scene scene, LandData data = null)
  238. {
  239. m_scene = scene;
  240. if (m_scene == null)
  241. LandBitmap = new bool[Constants.RegionSize / landUnit, Constants.RegionSize / landUnit];
  242. else
  243. {
  244. LandBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
  245. m_dwellModule = m_scene.RequestModuleInterface<IDwellModule>();
  246. }
  247. if(data == null)
  248. LandData = new LandData();
  249. else
  250. LandData = data;
  251. LandData.OwnerID = owner_id;
  252. if (is_group_owned)
  253. LandData.GroupID = owner_id;
  254. LandData.IsGroupOwned = is_group_owned;
  255. if(m_dwellModule == null)
  256. LandData.Dwell = 0;
  257. m_scene.EventManager.OnFrame += OnFrame;
  258. }
  259. public void Clear()
  260. {
  261. if(m_scene != null)
  262. m_scene.EventManager.OnFrame -= OnFrame;
  263. LandData = null;
  264. }
  265. #endregion
  266. #region Member Functions
  267. #region General Functions
  268. /// <summary>
  269. /// Checks to see if this land object contains a point
  270. /// </summary>
  271. /// <param name="x"></param>
  272. /// <param name="y"></param>
  273. /// <returns>Returns true if the piece of land contains the specified point</returns>
  274. public bool ContainsPoint(int x, int y)
  275. {
  276. if (x >= 0 && y >= 0 && x < m_scene.RegionInfo.RegionSizeX && y < m_scene.RegionInfo.RegionSizeY)
  277. {
  278. return LandBitmap[x / landUnit, y / landUnit];
  279. }
  280. else
  281. {
  282. return false;
  283. }
  284. }
  285. public ILandObject Copy()
  286. {
  287. ILandObject newLand = new LandObject(LandData, m_scene);
  288. newLand.LandBitmap = (bool[,]) (LandBitmap.Clone());
  289. return newLand;
  290. }
  291. static overrideParcelMaxPrimCountDelegate overrideParcelMaxPrimCount;
  292. static overrideSimulatorMaxPrimCountDelegate overrideSimulatorMaxPrimCount;
  293. public void SetParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  294. {
  295. overrideParcelMaxPrimCount = overrideDel;
  296. }
  297. public void SetSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  298. {
  299. overrideSimulatorMaxPrimCount = overrideDel;
  300. }
  301. public int GetParcelMaxPrimCount()
  302. {
  303. if (overrideParcelMaxPrimCount != null)
  304. {
  305. return overrideParcelMaxPrimCount(this);
  306. }
  307. else
  308. {
  309. // Normal Calculations
  310. int parcelMax = (int)(
  311. (double)LandData.Area
  312. * (double)m_scene.RegionInfo.ObjectCapacity
  313. * (double)m_scene.RegionInfo.RegionSettings.ObjectBonus
  314. / (double)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY)
  315. + 0.5 );
  316. if(parcelMax > m_scene.RegionInfo.ObjectCapacity)
  317. parcelMax = m_scene.RegionInfo.ObjectCapacity;
  318. //m_log.DebugFormat("Area: {0}, Capacity {1}, Bonus {2}, Parcel {3}", LandData.Area, m_scene.RegionInfo.ObjectCapacity, m_scene.RegionInfo.RegionSettings.ObjectBonus, parcelMax);
  319. return parcelMax;
  320. }
  321. }
  322. // the total prims a parcel owner can have on a region
  323. public int GetSimulatorMaxPrimCount()
  324. {
  325. if (overrideSimulatorMaxPrimCount != null)
  326. {
  327. return overrideSimulatorMaxPrimCount(this);
  328. }
  329. else
  330. {
  331. //Normal Calculations
  332. int simMax = (int)( (double)LandData.SimwideArea
  333. * (double)m_scene.RegionInfo.ObjectCapacity
  334. * (double)m_scene.RegionInfo.RegionSettings.ObjectBonus
  335. / (long)(m_scene.RegionInfo.RegionSizeX * m_scene.RegionInfo.RegionSizeY)
  336. +0.5 );
  337. // sanity check
  338. if(simMax > m_scene.RegionInfo.ObjectCapacity)
  339. simMax = m_scene.RegionInfo.ObjectCapacity;
  340. //m_log.DebugFormat("Simwide Area: {0}, Capacity {1}, SimMax {2}, SimWidePrims {3}",
  341. // LandData.SimwideArea, m_scene.RegionInfo.ObjectCapacity, simMax, LandData.SimwidePrims);
  342. return simMax;
  343. }
  344. }
  345. #endregion
  346. #region Packet Request Handling
  347. public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, IClientAPI remote_client)
  348. {
  349. if(m_scene.RegionInfo.RegionSettings.AllowDamage)
  350. remote_client.SceneAgent.Invulnerable = false;
  351. else
  352. remote_client.SceneAgent.Invulnerable = (m_landData.Flags & (uint)ParcelFlags.AllowDamage) == 0;
  353. if (remote_client.SceneAgent.PresenceType == PresenceType.Npc)
  354. return;
  355. IEstateModule estateModule = m_scene.RequestModuleInterface<IEstateModule>();
  356. // uint regionFlags = 336723974 & ~((uint)(RegionFlags.AllowLandmark | RegionFlags.AllowSetHome));
  357. uint regionFlags = (uint)(RegionFlags.PublicAllowed
  358. | RegionFlags.AllowDirectTeleport
  359. | RegionFlags.AllowParcelChanges
  360. | RegionFlags.AllowVoice );
  361. if (estateModule != null)
  362. regionFlags = estateModule.GetRegionFlags();
  363. int seq_id;
  364. if (snap_selection && (sequence_id == 0))
  365. {
  366. seq_id = m_lastSeqId;
  367. }
  368. else
  369. {
  370. seq_id = sequence_id;
  371. m_lastSeqId = seq_id;
  372. }
  373. remote_client.SendLandProperties(seq_id,
  374. snap_selection, request_result, this,
  375. (float)m_scene.RegionInfo.RegionSettings.ObjectBonus,
  376. GetParcelMaxPrimCount(),
  377. GetSimulatorMaxPrimCount(), regionFlags);
  378. }
  379. public bool UpdateLandProperties(LandUpdateArgs args, IClientAPI remote_client, out bool snap_selection, out bool needOverlay)
  380. {
  381. //Needs later group support
  382. snap_selection = false;
  383. needOverlay = false;
  384. LandData newData = LandData.Copy();
  385. uint allowedDelta = 0;
  386. // These two are always blocked as no client can set them anyway
  387. // ParcelFlags.ForSaleObjects
  388. // ParcelFlags.LindenHome
  389. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, false))
  390. {
  391. allowedDelta |= (uint)(ParcelFlags.AllowLandmark |
  392. ParcelFlags.AllowTerraform |
  393. ParcelFlags.AllowDamage |
  394. ParcelFlags.CreateObjects |
  395. ParcelFlags.RestrictPushObject |
  396. ParcelFlags.AllowOtherScripts |
  397. ParcelFlags.AllowGroupScripts |
  398. ParcelFlags.CreateGroupObjects |
  399. ParcelFlags.AllowAPrimitiveEntry |
  400. ParcelFlags.AllowGroupObjectEntry |
  401. ParcelFlags.AllowFly);
  402. newData.SeeAVs = args.SeeAVs;
  403. newData.AnyAVSounds = args.AnyAVSounds;
  404. newData.GroupAVSounds = args.GroupAVSounds;
  405. }
  406. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandSetSale, true))
  407. {
  408. if (args.AuthBuyerID != newData.AuthBuyerID ||
  409. args.SalePrice != newData.SalePrice)
  410. {
  411. snap_selection = true;
  412. }
  413. newData.AuthBuyerID = args.AuthBuyerID;
  414. newData.SalePrice = args.SalePrice;
  415. if (!LandData.IsGroupOwned)
  416. {
  417. newData.GroupID = args.GroupID;
  418. allowedDelta |= (uint)(ParcelFlags.AllowDeedToGroup |
  419. ParcelFlags.ContributeWithDeed |
  420. ParcelFlags.SellParcelObjects);
  421. }
  422. allowedDelta |= (uint)ParcelFlags.ForSale;
  423. }
  424. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.FindPlaces, false))
  425. {
  426. newData.Category = args.Category;
  427. allowedDelta |= (uint)(ParcelFlags.ShowDirectory |
  428. ParcelFlags.AllowPublish |
  429. ParcelFlags.MaturePublish) | (uint)(1 << 23);
  430. }
  431. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandChangeIdentity, false))
  432. {
  433. newData.Description = args.Desc;
  434. newData.Name = args.Name;
  435. newData.SnapshotID = args.SnapshotID;
  436. }
  437. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.SetLandingPoint, false))
  438. {
  439. newData.LandingType = args.LandingType;
  440. newData.UserLocation = args.UserLocation;
  441. newData.UserLookAt = args.UserLookAt;
  442. }
  443. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.ChangeMedia, false))
  444. {
  445. newData.MediaAutoScale = args.MediaAutoScale;
  446. newData.MediaID = args.MediaID;
  447. newData.MediaURL = args.MediaURL;
  448. newData.MusicURL = args.MusicURL;
  449. newData.MediaType = args.MediaType;
  450. newData.MediaDescription = args.MediaDescription;
  451. newData.MediaWidth = args.MediaWidth;
  452. newData.MediaHeight = args.MediaHeight;
  453. newData.MediaLoop = args.MediaLoop;
  454. newData.ObscureMusic = args.ObscureMusic;
  455. newData.ObscureMedia = args.ObscureMedia;
  456. allowedDelta |= (uint)(ParcelFlags.SoundLocal |
  457. ParcelFlags.UrlWebPage |
  458. ParcelFlags.UrlRawHtml |
  459. ParcelFlags.AllowVoiceChat |
  460. ParcelFlags.UseEstateVoiceChan);
  461. }
  462. // don't allow passes on group owned until we can give money to groups
  463. if (!newData.IsGroupOwned && m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId,this, GroupPowers.LandManagePasses, false))
  464. {
  465. newData.PassHours = args.PassHours;
  466. newData.PassPrice = args.PassPrice;
  467. allowedDelta |= (uint)ParcelFlags.UsePassList;
  468. }
  469. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageAllowed, false))
  470. {
  471. allowedDelta |= (uint)(ParcelFlags.UseAccessGroup |
  472. ParcelFlags.UseAccessList);
  473. }
  474. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandManageBanned, false))
  475. {
  476. allowedDelta |= (uint)(ParcelFlags.UseBanList |
  477. ParcelFlags.DenyAnonymous |
  478. ParcelFlags.DenyAgeUnverified);
  479. }
  480. if (allowedDelta != (uint)ParcelFlags.None)
  481. {
  482. uint preserve = LandData.Flags & ~allowedDelta;
  483. newData.Flags = preserve | (args.ParcelFlags & allowedDelta);
  484. uint curdelta = LandData.Flags ^ newData.Flags;
  485. curdelta &= (uint)(ParcelFlags.SoundLocal);
  486. if(curdelta != 0 || newData.SeeAVs != LandData.SeeAVs)
  487. needOverlay = true;
  488. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  489. return true;
  490. }
  491. return false;
  492. }
  493. public void UpdateLandSold(UUID avatarID, UUID groupID, bool groupOwned, uint AuctionID, int claimprice, int area)
  494. {
  495. LandData newData = LandData.Copy();
  496. newData.OwnerID = avatarID;
  497. newData.GroupID = groupID;
  498. newData.IsGroupOwned = groupOwned;
  499. //newData.auctionID = AuctionID;
  500. newData.ClaimDate = Util.UnixTimeSinceEpoch();
  501. newData.ClaimPrice = claimprice;
  502. newData.SalePrice = 0;
  503. newData.AuthBuyerID = UUID.Zero;
  504. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  505. bool sellObjects = (LandData.Flags & (uint)(ParcelFlags.SellParcelObjects)) != 0
  506. && !LandData.IsGroupOwned && !groupOwned;
  507. UUID previousOwner = LandData.OwnerID;
  508. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  509. // m_scene.EventManager.TriggerParcelPrimCountUpdate();
  510. SendLandUpdateToAvatarsOverMe(true);
  511. if (sellObjects) SellLandObjects(previousOwner);
  512. }
  513. public void DeedToGroup(UUID groupID)
  514. {
  515. LandData newData = LandData.Copy();
  516. newData.OwnerID = groupID;
  517. newData.GroupID = groupID;
  518. newData.IsGroupOwned = true;
  519. // Reset show in directory flag on deed
  520. newData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  521. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  522. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  523. SendLandUpdateToAvatarsOverMe(true);
  524. }
  525. public bool IsEitherBannedOrRestricted(UUID avatar)
  526. {
  527. if (IsBannedFromLand(avatar))
  528. {
  529. return true;
  530. }
  531. else if (IsRestrictedFromLand(avatar))
  532. {
  533. return true;
  534. }
  535. return false;
  536. }
  537. public bool CanBeOnThisLand(UUID avatar, float posHeight)
  538. {
  539. if (posHeight < LandChannel.BAN_LINE_SAFETY_HEIGHT && IsBannedFromLand(avatar))
  540. {
  541. return false;
  542. }
  543. else if (IsRestrictedFromLand(avatar))
  544. {
  545. return false;
  546. }
  547. return true;
  548. }
  549. public bool HasGroupAccess(UUID avatar)
  550. {
  551. if (LandData.GroupID != UUID.Zero && (LandData.Flags & (uint)ParcelFlags.UseAccessGroup) == (uint)ParcelFlags.UseAccessGroup)
  552. {
  553. ScenePresence sp;
  554. if (!m_scene.TryGetScenePresence(avatar, out sp))
  555. {
  556. bool isMember;
  557. if (m_groupMemberCache.TryGetValue(avatar, out isMember))
  558. {
  559. m_groupMemberCache.Update(avatar, isMember, m_groupMemberCacheTimeout);
  560. return isMember;
  561. }
  562. IGroupsModule groupsModule = m_scene.RequestModuleInterface<IGroupsModule>();
  563. if (groupsModule == null)
  564. return false;
  565. GroupMembershipData[] membership = groupsModule.GetMembershipData(avatar);
  566. if (membership == null || membership.Length == 0)
  567. {
  568. m_groupMemberCache.Add(avatar, false, m_groupMemberCacheTimeout);
  569. return false;
  570. }
  571. foreach (GroupMembershipData d in membership)
  572. {
  573. if (d.GroupID == LandData.GroupID)
  574. {
  575. m_groupMemberCache.Add(avatar, true, m_groupMemberCacheTimeout);
  576. return true;
  577. }
  578. }
  579. m_groupMemberCache.Add(avatar, false, m_groupMemberCacheTimeout);
  580. return false;
  581. }
  582. return sp.ControllingClient.IsGroupMember(LandData.GroupID);
  583. }
  584. return false;
  585. }
  586. public bool IsBannedFromLand(UUID avatar)
  587. {
  588. ExpireAccessList();
  589. if (m_scene.Permissions.IsAdministrator(avatar))
  590. return false;
  591. if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
  592. return false;
  593. if (avatar == LandData.OwnerID)
  594. return false;
  595. if ((LandData.Flags & (uint) ParcelFlags.UseBanList) > 0)
  596. {
  597. if (LandData.ParcelAccessList.FindIndex(
  598. delegate(LandAccessEntry e)
  599. {
  600. if (e.AgentID == avatar && e.Flags == AccessList.Ban)
  601. return true;
  602. return false;
  603. }) != -1)
  604. {
  605. return true;
  606. }
  607. }
  608. return false;
  609. }
  610. public bool IsRestrictedFromLand(UUID avatar)
  611. {
  612. if ((LandData.Flags & (uint) ParcelFlags.UseAccessList) == 0)
  613. return false;
  614. if (m_scene.Permissions.IsAdministrator(avatar))
  615. return false;
  616. if (m_scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(avatar))
  617. return false;
  618. if (avatar == LandData.OwnerID)
  619. return false;
  620. if (HasGroupAccess(avatar))
  621. return false;
  622. if(IsInLandAccessList(avatar))
  623. return false;
  624. // check for a NPC
  625. ScenePresence sp;
  626. if (!m_scene.TryGetScenePresence(avatar, out sp))
  627. return true;
  628. if(sp==null || !sp.IsNPC)
  629. return true;
  630. INPC npccli = (INPC)sp.ControllingClient;
  631. if(npccli== null)
  632. return true;
  633. UUID owner = npccli.Owner;
  634. if(owner == UUID.Zero)
  635. return true;
  636. if (owner == LandData.OwnerID)
  637. return false;
  638. return !IsInLandAccessList(owner);
  639. }
  640. public bool IsInLandAccessList(UUID avatar)
  641. {
  642. ExpireAccessList();
  643. if (LandData.ParcelAccessList.FindIndex(
  644. delegate(LandAccessEntry e)
  645. {
  646. if (e.AgentID == avatar && e.Flags == AccessList.Access)
  647. return true;
  648. return false;
  649. }) == -1)
  650. {
  651. return false;
  652. }
  653. return true;
  654. }
  655. public void SendLandUpdateToClient(IClientAPI remote_client)
  656. {
  657. SendLandProperties(0, false, 0, remote_client);
  658. }
  659. public void SendLandUpdateToClient(bool snap_selection, IClientAPI remote_client)
  660. {
  661. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  662. SendLandProperties(0, snap_selection, 0, remote_client);
  663. }
  664. public void SendLandUpdateToAvatarsOverMe()
  665. {
  666. SendLandUpdateToAvatarsOverMe(false);
  667. }
  668. public void SendLandUpdateToAvatarsOverMe(bool snap_selection)
  669. {
  670. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  671. m_scene.ForEachRootScenePresence(delegate(ScenePresence avatar)
  672. {
  673. ILandObject over = null;
  674. try
  675. {
  676. over =
  677. m_scene.LandChannel.GetLandObject(Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.X), 0, ((int)m_scene.RegionInfo.RegionSizeX - 1)),
  678. Util.Clamp<int>((int)Math.Round(avatar.AbsolutePosition.Y), 0, ((int)m_scene.RegionInfo.RegionSizeY - 1)));
  679. }
  680. catch (Exception)
  681. {
  682. m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatar.AbsolutePosition.X) + " y: " +
  683. Math.Round(avatar.AbsolutePosition.Y));
  684. }
  685. if (over != null)
  686. {
  687. if (over.LandData.LocalID == LandData.LocalID)
  688. {
  689. if(m_scene.RegionInfo.RegionSettings.AllowDamage)
  690. avatar.Invulnerable = false;
  691. else
  692. avatar.Invulnerable = (over.LandData.Flags & (uint)ParcelFlags.AllowDamage) == 0;
  693. SendLandUpdateToClient(snap_selection, avatar.ControllingClient);
  694. avatar.currentParcelUUID = LandData.GlobalID;
  695. }
  696. }
  697. });
  698. }
  699. #endregion
  700. #region AccessList Functions
  701. public List<LandAccessEntry> CreateAccessListArrayByFlag(AccessList flag)
  702. {
  703. ExpireAccessList();
  704. List<LandAccessEntry> list = new List<LandAccessEntry>();
  705. foreach (LandAccessEntry entry in LandData.ParcelAccessList)
  706. {
  707. if (entry.Flags == flag)
  708. list.Add(entry);
  709. }
  710. if (list.Count == 0)
  711. {
  712. LandAccessEntry e = new LandAccessEntry();
  713. e.AgentID = UUID.Zero;
  714. e.Flags = 0;
  715. e.Expires = 0;
  716. list.Add(e);
  717. }
  718. return list;
  719. }
  720. public void SendAccessList(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  721. IClientAPI remote_client)
  722. {
  723. if ((flags & (uint) AccessList.Access) != 0)
  724. {
  725. List<LandAccessEntry> accessEntries = CreateAccessListArrayByFlag(AccessList.Access);
  726. remote_client.SendLandAccessListData(accessEntries,(uint) AccessList.Access,LandData.LocalID);
  727. }
  728. if ((flags & (uint) AccessList.Ban) != 0)
  729. {
  730. List<LandAccessEntry> accessEntries = CreateAccessListArrayByFlag(AccessList.Ban);
  731. remote_client.SendLandAccessListData(accessEntries, (uint)AccessList.Ban, LandData.LocalID);
  732. }
  733. }
  734. public void UpdateAccessList(uint flags, UUID transactionID,
  735. int sequenceID, int sections,
  736. List<LandAccessEntry> entries,
  737. IClientAPI remote_client)
  738. {
  739. LandData newData = LandData.Copy();
  740. if ((!m_listTransactions.ContainsKey(flags)) ||
  741. m_listTransactions[flags] != transactionID)
  742. {
  743. m_listTransactions[flags] = transactionID;
  744. List<LandAccessEntry> toRemove =
  745. new List<LandAccessEntry>();
  746. foreach (LandAccessEntry entry in newData.ParcelAccessList)
  747. {
  748. if (entry.Flags == (AccessList)flags)
  749. toRemove.Add(entry);
  750. }
  751. foreach (LandAccessEntry entry in toRemove)
  752. {
  753. newData.ParcelAccessList.Remove(entry);
  754. }
  755. // Checked here because this will always be the first
  756. // and only packet in a transaction
  757. if (entries.Count == 1 && entries[0].AgentID == UUID.Zero)
  758. {
  759. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  760. return;
  761. }
  762. }
  763. foreach (LandAccessEntry entry in entries)
  764. {
  765. LandAccessEntry temp =
  766. new LandAccessEntry();
  767. temp.AgentID = entry.AgentID;
  768. temp.Expires = entry.Expires;
  769. temp.Flags = (AccessList)flags;
  770. newData.ParcelAccessList.Add(temp);
  771. }
  772. // update use lists flags
  773. // rights already checked or we wont be here
  774. uint parcelflags = newData.Flags;
  775. if((flags & (uint)AccessList.Access) != 0)
  776. parcelflags |= (uint)ParcelFlags.UseAccessList;
  777. if((flags & (uint)AccessList.Ban) != 0)
  778. parcelflags |= (uint)ParcelFlags.UseBanList;
  779. newData.Flags = parcelflags;
  780. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, newData);
  781. }
  782. #endregion
  783. #region Update Functions
  784. public void UpdateLandBitmapByteArray()
  785. {
  786. LandData.Bitmap = ConvertLandBitmapToBytes();
  787. }
  788. /// <summary>
  789. /// Update all settings in land such as area, bitmap byte array, etc
  790. /// </summary>
  791. public void ForceUpdateLandInfo()
  792. {
  793. UpdateGeometryValues();
  794. UpdateLandBitmapByteArray();
  795. }
  796. public void SetLandBitmapFromByteArray()
  797. {
  798. LandBitmap = ConvertBytesToLandBitmap();
  799. }
  800. /// <summary>
  801. /// Updates geomtric values after area/shape modification of the land object
  802. /// </summary>
  803. private void UpdateGeometryValues()
  804. {
  805. int min_x = Int32.MaxValue;
  806. int min_y = Int32.MaxValue;
  807. int max_x = Int32.MinValue;
  808. int max_y = Int32.MinValue;
  809. int tempArea = 0;
  810. int x, y;
  811. int lastX = 0;
  812. int lastY = 0;
  813. float avgx = 0f;
  814. float avgy = 0f;
  815. bool needFirst = true;
  816. for (x = 0; x < LandBitmap.GetLength(0); x++)
  817. {
  818. for (y = 0; y < LandBitmap.GetLength(1); y++)
  819. {
  820. if (LandBitmap[x, y])
  821. {
  822. if (min_x > x)
  823. min_x = x;
  824. if (min_y > y)
  825. min_y = y;
  826. if (max_x < x)
  827. max_x = x;
  828. if (max_y < y)
  829. max_y = y;
  830. if(needFirst)
  831. {
  832. avgx = x;
  833. avgy = y;
  834. m_startPoint.X = x * landUnit;
  835. m_startPoint.Y = y * landUnit;
  836. needFirst = false;
  837. }
  838. else
  839. {
  840. // keeping previus odd average
  841. avgx = (avgx * tempArea + x) / (tempArea + 1);
  842. avgy = (avgy * tempArea + y) / (tempArea + 1);
  843. }
  844. tempArea++;
  845. lastX = x;
  846. lastY = y;
  847. }
  848. }
  849. }
  850. int halfunit = landUnit/2;
  851. m_centerPoint.X = avgx * landUnit + halfunit;
  852. m_centerPoint.Y = avgy * landUnit + halfunit;
  853. m_endPoint.X = lastX * landUnit + landUnit;
  854. m_endPoint.Y = lastY * landUnit + landUnit;
  855. // next tests should not be needed
  856. // if they fail, something is wrong
  857. int regionSizeX = (int)Constants.RegionSize;
  858. int regionSizeY = (int)Constants.RegionSize;
  859. if(m_scene != null)
  860. {
  861. regionSizeX = (int)m_scene.RegionInfo.RegionSizeX;
  862. regionSizeY = (int)m_scene.RegionInfo.RegionSizeX;
  863. }
  864. int tx = min_x * landUnit;
  865. if (tx >= regionSizeX)
  866. tx = regionSizeX - 1;
  867. int ty = min_y * landUnit;
  868. if (ty >= regionSizeY)
  869. ty = regionSizeY - 1;
  870. m_AABBmin.X = tx;
  871. m_AABBmin.Y = ty;
  872. if(m_scene == null || m_scene.Heightmap == null)
  873. LandData.AABBMin = new Vector3(tx, ty, 0f);
  874. else
  875. LandData.AABBMin = new Vector3(tx, ty, (float)m_scene.Heightmap[tx, ty]);
  876. max_x++;
  877. tx = max_x * landUnit;
  878. if (tx > regionSizeX)
  879. tx = regionSizeX;
  880. max_y++;
  881. ty = max_y * landUnit;
  882. if (ty > regionSizeY)
  883. ty = regionSizeY;
  884. m_AABBmax.X = tx;
  885. m_AABBmax.Y = ty;
  886. if(m_scene == null || m_scene.Heightmap == null)
  887. LandData.AABBMax = new Vector3(tx, ty, 0f);
  888. else
  889. LandData.AABBMax = new Vector3(tx, ty, (float)m_scene.Heightmap[tx - 1, ty - 1]);
  890. tempArea *= landUnit * landUnit;
  891. LandData.Area = tempArea;
  892. }
  893. #endregion
  894. #region Land Bitmap Functions
  895. /// <summary>
  896. /// Sets the land's bitmap manually
  897. /// </summary>
  898. /// <param name="bitmap">block representing where this land is on a map mapped in a 4x4 meter grid</param>
  899. public void SetLandBitmap(bool[,] bitmap)
  900. {
  901. LandBitmap = bitmap;
  902. ForceUpdateLandInfo();
  903. }
  904. /// <summary>
  905. /// Gets the land's bitmap manually
  906. /// </summary>
  907. /// <returns></returns>
  908. public bool[,] GetLandBitmap()
  909. {
  910. return LandBitmap;
  911. }
  912. public bool[,] BasicFullRegionLandBitmap()
  913. {
  914. return GetSquareLandBitmap(0, 0, (int)m_scene.RegionInfo.RegionSizeX, (int) m_scene.RegionInfo.RegionSizeY, true);
  915. }
  916. public bool[,] GetSquareLandBitmap(int start_x, int start_y, int end_x, int end_y, bool set_value = true)
  917. {
  918. // Empty bitmap for the whole region
  919. bool[,] tempBitmap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
  920. tempBitmap.Initialize();
  921. // Fill the bitmap square area specified by state and end
  922. tempBitmap = ModifyLandBitmapSquare(tempBitmap, start_x, start_y, end_x, end_y, set_value);
  923. // m_log.DebugFormat("{0} GetSquareLandBitmap. tempBitmapSize=<{1},{2}>",
  924. // LogHeader, tempBitmap.GetLength(0), tempBitmap.GetLength(1));
  925. return tempBitmap;
  926. }
  927. /// <summary>
  928. /// Change a land bitmap at within a square and set those points to a specific value
  929. /// </summary>
  930. /// <param name="land_bitmap"></param>
  931. /// <param name="start_x"></param>
  932. /// <param name="start_y"></param>
  933. /// <param name="end_x"></param>
  934. /// <param name="end_y"></param>
  935. /// <param name="set_value"></param>
  936. /// <returns></returns>
  937. public bool[,] ModifyLandBitmapSquare(bool[,] land_bitmap, int start_x, int start_y, int end_x, int end_y,
  938. bool set_value)
  939. {
  940. int x, y;
  941. for (y = 0; y < land_bitmap.GetLength(1); y++)
  942. {
  943. for (x = 0; x < land_bitmap.GetLength(0); x++)
  944. {
  945. if (x >= start_x / landUnit && x < end_x / landUnit
  946. && y >= start_y / landUnit && y < end_y / landUnit)
  947. {
  948. land_bitmap[x, y] = set_value;
  949. }
  950. }
  951. }
  952. // m_log.DebugFormat("{0} ModifyLandBitmapSquare. startXY=<{1},{2}>, endXY=<{3},{4}>, val={5}, landBitmapSize=<{6},{7}>",
  953. // LogHeader, start_x, start_y, end_x, end_y, set_value, land_bitmap.GetLength(0), land_bitmap.GetLength(1));
  954. return land_bitmap;
  955. }
  956. /// <summary>
  957. /// Join the true values of 2 bitmaps together
  958. /// </summary>
  959. /// <param name="bitmap_base"></param>
  960. /// <param name="bitmap_add"></param>
  961. /// <returns></returns>
  962. public bool[,] MergeLandBitmaps(bool[,] bitmap_base, bool[,] bitmap_add)
  963. {
  964. if (bitmap_base.GetLength(0) != bitmap_add.GetLength(0)
  965. || bitmap_base.GetLength(1) != bitmap_add.GetLength(1)
  966. || bitmap_add.Rank != 2
  967. || bitmap_base.Rank != 2)
  968. {
  969. throw new Exception(
  970. String.Format("{0} MergeLandBitmaps. merging maps not same size. baseSizeXY=<{1},{2}>, addSizeXY=<{3},{4}>",
  971. LogHeader, bitmap_base.GetLength(0), bitmap_base.GetLength(1), bitmap_add.GetLength(0), bitmap_add.GetLength(1))
  972. );
  973. }
  974. int x, y;
  975. for (y = 0; y < bitmap_base.GetLength(1); y++)
  976. {
  977. for (x = 0; x < bitmap_add.GetLength(0); x++)
  978. {
  979. if (bitmap_add[x, y])
  980. {
  981. bitmap_base[x, y] = true;
  982. }
  983. }
  984. }
  985. return bitmap_base;
  986. }
  987. /// <summary>
  988. /// Remap a land bitmap. Takes the supplied land bitmap and rotates it, crops it and finally offsets it into
  989. /// a final land bitmap of the target region size.
  990. /// </summary>
  991. /// <param name="bitmap_base">The original parcel bitmap</param>
  992. /// <param name="rotationDegrees"></param>
  993. /// <param name="displacement">&lt;x,y,?&gt;</param>
  994. /// <param name="boundingOrigin">&lt;x,y,?&gt;</param>
  995. /// <param name="boundingSize">&lt;x,y,?&gt;</param>
  996. /// <param name="regionSize">&lt;x,y,?&gt;</param>
  997. /// <param name="isEmptyNow">out: This is set if the resultant bitmap is now empty</param>
  998. /// <param name="AABBMin">out: parcel.AABBMin &lt;x,y,0&gt</param>
  999. /// <param name="AABBMax">out: parcel.AABBMax &lt;x,y,0&gt</param>
  1000. /// <returns>New parcel bitmap</returns>
  1001. public bool[,] RemapLandBitmap(bool[,] bitmap_base, Vector2 displacement, float rotationDegrees, Vector2 boundingOrigin, Vector2 boundingSize, Vector2 regionSize, out bool isEmptyNow, out Vector3 AABBMin, out Vector3 AABBMax)
  1002. {
  1003. // get the size of the incoming bitmap
  1004. int baseX = bitmap_base.GetLength(0);
  1005. int baseY = bitmap_base.GetLength(1);
  1006. // create an intermediate bitmap that is 25% bigger on each side that we can work with to handle rotations
  1007. int offsetX = baseX / 4; // the original origin will now be at these coordinates so now we can have imaginary negative coordinates ;)
  1008. int offsetY = baseY / 4;
  1009. int tmpX = baseX + baseX / 2;
  1010. int tmpY = baseY + baseY / 2;
  1011. int centreX = tmpX / 2;
  1012. int centreY = tmpY / 2;
  1013. bool[,] bitmap_tmp = new bool[tmpX, tmpY];
  1014. double radianRotation = Math.PI * rotationDegrees / 180f;
  1015. double cosR = Math.Cos(radianRotation);
  1016. double sinR = Math.Sin(radianRotation);
  1017. if (rotationDegrees < 0f) rotationDegrees += 360f; //-90=270 -180=180 -270=90
  1018. // So first we apply the rotation to the incoming bitmap, storing the result in bitmap_tmp
  1019. // We special case orthogonal rotations for accuracy because even using double precision math, Math.Cos(90 degrees) is never fully 0
  1020. // and we can never rotate around a centre pixel because the bitmap size is always even
  1021. int x, y, sx, sy;
  1022. for (y = 0; y <= tmpY; y++)
  1023. {
  1024. for (x = 0; x <= tmpX; x++)
  1025. {
  1026. if (rotationDegrees == 0f)
  1027. {
  1028. sx = x - offsetX;
  1029. sy = y - offsetY;
  1030. }
  1031. else if (rotationDegrees == 90f)
  1032. {
  1033. sx = y - offsetX;
  1034. sy = tmpY - 1 - x - offsetY;
  1035. }
  1036. else if (rotationDegrees == 180f)
  1037. {
  1038. sx = tmpX - 1 - x - offsetX;
  1039. sy = tmpY - 1 - y - offsetY;
  1040. }
  1041. else if (rotationDegrees == 270f)
  1042. {
  1043. sx = tmpX - 1 - y - offsetX;
  1044. sy = x - offsetY;
  1045. }
  1046. else
  1047. {
  1048. // arbitary rotation: hmmm should I be using (centreX - 0.5) and (centreY - 0.5) and round cosR and sinR to say only 5 decimal places?
  1049. sx = centreX + (int)Math.Round((((double)x - centreX) * cosR) + (((double)y - centreY) * sinR)) - offsetX;
  1050. sy = centreY + (int)Math.Round((((double)y - centreY) * cosR) - (((double)x - centreX) * sinR)) - offsetY;
  1051. }
  1052. if (sx >= 0 && sx < baseX && sy >= 0 && sy < baseY)
  1053. {
  1054. try
  1055. {
  1056. if (bitmap_base[sx, sy]) bitmap_tmp[x, y] = true;
  1057. }
  1058. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  1059. {
  1060. m_log.DebugFormat("{0} RemapLandBitmap Rotate: Out of Bounds sx={1} sy={2} dx={3} dy={4}", LogHeader, sx, sy, x, y);
  1061. }
  1062. }
  1063. }
  1064. }
  1065. // We could also incorporate the next steps, bounding-rectangle and displacement in the loop above, but it's simpler to visualise if done separately
  1066. // and will also make it much easier when later I want the option for maybe a circular or oval bounding shape too ;).
  1067. // So... our output land bitmap must be the size of the current region but rememeber, parcel landbitmaps are landUnit metres (4x4 metres) per point,
  1068. // and region sizes, boundaries and displacements are in metres so we need to scale down
  1069. int newX = (int)(regionSize.X / landUnit);
  1070. int newY = (int)(regionSize.Y / landUnit);
  1071. bool[,] bitmap_new = new bool[newX, newY];
  1072. // displacement is relative to <0,0> in the destination region and defines where the origin of the data selected by the bounding-rectangle is placed
  1073. int dispX = (int)Math.Floor(displacement.X / landUnit);
  1074. int dispY = (int)Math.Floor(displacement.Y / landUnit);
  1075. // startX/Y and endX/Y are coordinates in bitmap_tmp
  1076. int startX = (int)Math.Floor(boundingOrigin.X / landUnit) + offsetX;
  1077. if (startX > tmpX) startX = tmpX;
  1078. if (startX < 0) startX = 0;
  1079. int startY = (int)Math.Floor(boundingOrigin.Y / landUnit) + offsetY;
  1080. if (startY > tmpY) startY = tmpY;
  1081. if (startY < 0) startY = 0;
  1082. int endX = (int)Math.Floor((boundingOrigin.X + boundingSize.X) / landUnit) + offsetX;
  1083. if (endX > tmpX) endX = tmpX;
  1084. if (endX < 0) endX = 0;
  1085. int endY = (int)Math.Floor((boundingOrigin.Y + boundingSize.Y) / landUnit) + offsetY;
  1086. if (endY > tmpY) endY = tmpY;
  1087. if (endY < 0) endY = 0;
  1088. //m_log.DebugFormat("{0} RemapLandBitmap: inSize=<{1},{2}>, disp=<{3},{4}> rot={5}, offset=<{6},{7}>, boundingStart=<{8},{9}>, boundingEnd=<{10},{11}>, cosR={12}, sinR={13}, outSize=<{14},{15}>", LogHeader,
  1089. // baseX, baseY, dispX, dispY, radianRotation, offsetX, offsetY, startX, startY, endX, endY, cosR, sinR, newX, newY);
  1090. isEmptyNow = true;
  1091. int minX = newX;
  1092. int minY = newY;
  1093. int maxX = 0;
  1094. int maxY = 0;
  1095. int dx, dy;
  1096. for (y = startY; y < endY; y++)
  1097. {
  1098. for (x = startX; x < endX; x++)
  1099. {
  1100. dx = x - startX + dispX;
  1101. dy = y - startY + dispY;
  1102. if (dx >= 0 && dx < newX && dy >= 0 && dy < newY)
  1103. {
  1104. try
  1105. {
  1106. if (bitmap_tmp[x, y])
  1107. {
  1108. bitmap_new[dx, dy] = true;
  1109. isEmptyNow = false;
  1110. if (dx < minX) minX = dx;
  1111. if (dy < minY) minY = dy;
  1112. if (dx > maxX) maxX = dx;
  1113. if (dy > maxY) maxY = dy;
  1114. }
  1115. }
  1116. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  1117. {
  1118. m_log.DebugFormat("{0} RemapLandBitmap - Bound & Displace: Out of Bounds sx={1} sy={2} dx={3} dy={4}", LogHeader, x, y, dx, dy);
  1119. }
  1120. }
  1121. }
  1122. }
  1123. if (isEmptyNow)
  1124. {
  1125. //m_log.DebugFormat("{0} RemapLandBitmap: Land bitmap is marked as Empty", LogHeader);
  1126. minX = 0;
  1127. minY = 0;
  1128. }
  1129. AABBMin = new Vector3(minX * landUnit, minY * landUnit, 0);
  1130. AABBMax = new Vector3(maxX * landUnit, maxY * landUnit, 0);
  1131. return bitmap_new;
  1132. }
  1133. /// <summary>
  1134. /// Clears any parcel data in bitmap_base where there exists parcel data in bitmap_new. In other words the parcel data
  1135. /// in bitmap_new takes over the space of the parcel data in bitmap_base.
  1136. /// </summary>
  1137. /// <param name="bitmap_base"></param>
  1138. /// <param name="bitmap_new"></param>
  1139. /// <param name="isEmptyNow">out: This is set if the resultant bitmap is now empty</param>
  1140. /// <param name="AABBMin">out: parcel.AABBMin &lt;x,y,0&gt</param>
  1141. /// <param name="AABBMax">out: parcel.AABBMax &lt;x,y,0&gt</param>
  1142. /// <returns>New parcel bitmap</returns>
  1143. public bool[,] RemoveFromLandBitmap(bool[,] bitmap_base, bool[,] bitmap_new, out bool isEmptyNow, out Vector3 AABBMin, out Vector3 AABBMax)
  1144. {
  1145. // get the size of the incoming bitmaps
  1146. int baseX = bitmap_base.GetLength(0);
  1147. int baseY = bitmap_base.GetLength(1);
  1148. int newX = bitmap_new.GetLength(0);
  1149. int newY = bitmap_new.GetLength(1);
  1150. if (baseX != newX || baseY != newY)
  1151. {
  1152. throw new Exception(
  1153. String.Format("{0} RemoveFromLandBitmap: Land bitmaps are not the same size! baseX={1} baseY={2} newX={3} newY={4}", LogHeader, baseX, baseY, newX, newY));
  1154. }
  1155. isEmptyNow = true;
  1156. int minX = baseX;
  1157. int minY = baseY;
  1158. int maxX = 0;
  1159. int maxY = 0;
  1160. for (int y = 0; y < baseY; y++)
  1161. {
  1162. for (int x = 0; x < baseX; x++)
  1163. {
  1164. if (bitmap_new[x, y]) bitmap_base[x, y] = false;
  1165. if (bitmap_base[x, y])
  1166. {
  1167. isEmptyNow = false;
  1168. if (x < minX) minX = x;
  1169. if (y < minY) minY = y;
  1170. if (x > maxX) maxX = x;
  1171. if (y > maxY) maxY = y;
  1172. }
  1173. }
  1174. }
  1175. if (isEmptyNow)
  1176. {
  1177. //m_log.DebugFormat("{0} RemoveFromLandBitmap: Land bitmap is marked as Empty", LogHeader);
  1178. minX = 0;
  1179. minY = 0;
  1180. }
  1181. AABBMin = new Vector3(minX * landUnit, minY * landUnit, 0);
  1182. AABBMax = new Vector3(maxX * landUnit, maxY * landUnit, 0);
  1183. return bitmap_base;
  1184. }
  1185. /// <summary>
  1186. /// Converts the land bitmap to a packet friendly byte array
  1187. /// </summary>
  1188. /// <returns></returns>
  1189. public byte[] ConvertLandBitmapToBytes()
  1190. {
  1191. byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
  1192. int tempByte = 0;
  1193. int byteNum = 0;
  1194. int mask = 1;
  1195. for (int y = 0; y < LandBitmap.GetLength(1); y++)
  1196. {
  1197. for (int x = 0; x < LandBitmap.GetLength(0); x++)
  1198. {
  1199. if (LandBitmap[x, y])
  1200. tempByte |= mask;
  1201. mask = mask << 1;
  1202. if (mask == 0x100)
  1203. {
  1204. mask = 1;
  1205. tempConvertArr[byteNum++] = (byte)tempByte;
  1206. tempByte = 0;
  1207. }
  1208. }
  1209. }
  1210. if(tempByte != 0 && byteNum < 512)
  1211. tempConvertArr[byteNum] = (byte)tempByte;
  1212. return tempConvertArr;
  1213. }
  1214. public bool[,] ConvertBytesToLandBitmap(bool overrideRegionSize = false)
  1215. {
  1216. int bitmapLen;
  1217. int xLen;
  1218. bool[,] tempConvertMap;
  1219. if (overrideRegionSize)
  1220. {
  1221. // Importing land parcel data from an OAR where the source region is a different size to the dest region requires us
  1222. // to make a LandBitmap that's not derived from the current region's size. We use the LandData.Bitmap size in bytes
  1223. // to figure out what the OAR's region dimensions are. (Is there a better way to get the src region x and y from the OAR?)
  1224. // This method assumes we always will have square regions
  1225. bitmapLen = LandData.Bitmap.Length;
  1226. xLen = (int)Math.Abs(Math.Sqrt(bitmapLen * 8));
  1227. tempConvertMap = new bool[xLen, xLen];
  1228. tempConvertMap.Initialize();
  1229. }
  1230. else
  1231. {
  1232. tempConvertMap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
  1233. tempConvertMap.Initialize();
  1234. // Math.Min overcomes an old bug that might have made it into the database. Only use the bytes that fit into convertMap.
  1235. bitmapLen = Math.Min(LandData.Bitmap.Length, tempConvertMap.GetLength(0) * tempConvertMap.GetLength(1) / 8);
  1236. xLen = (int)(m_scene.RegionInfo.RegionSizeX / landUnit);
  1237. if (bitmapLen == 512)
  1238. {
  1239. // Legacy bitmap being passed in. Use the legacy region size
  1240. // and only set the lower area of the larger region.
  1241. xLen = (int)(Constants.RegionSize / landUnit);
  1242. }
  1243. }
  1244. // m_log.DebugFormat("{0} ConvertBytesToLandBitmap: bitmapLen={1}, xLen={2}", LogHeader, bitmapLen, xLen);
  1245. byte tempByte;
  1246. int x = 0, y = 0;
  1247. for (int i = 0; i < bitmapLen; i++)
  1248. {
  1249. tempByte = LandData.Bitmap[i];
  1250. for (int bitNum = 0; bitNum < 8; bitNum++)
  1251. {
  1252. bool bit = Convert.ToBoolean(Convert.ToByte(tempByte >> bitNum) & (byte) 1);
  1253. try
  1254. {
  1255. tempConvertMap[x, y] = bit;
  1256. }
  1257. catch (Exception)
  1258. {
  1259. m_log.DebugFormat("{0} ConvertBytestoLandBitmap: i={1}, x={2}, y={3}", LogHeader, i, x, y);
  1260. }
  1261. x++;
  1262. if (x >= xLen)
  1263. {
  1264. x = 0;
  1265. y++;
  1266. }
  1267. }
  1268. }
  1269. return tempConvertMap;
  1270. }
  1271. public bool IsLandBitmapEmpty(bool[,] landBitmap)
  1272. {
  1273. for (int y = 0; y < landBitmap.GetLength(1); y++)
  1274. {
  1275. for (int x = 0; x < landBitmap.GetLength(0); x++)
  1276. {
  1277. if (landBitmap[x, y]) return false;
  1278. }
  1279. }
  1280. return true;
  1281. }
  1282. public void DebugLandBitmap(bool[,] landBitmap)
  1283. {
  1284. m_log.InfoFormat("{0}: Map Key: #=claimed land .=unclaimed land.", LogHeader);
  1285. for (int y = landBitmap.GetLength(1) - 1; y >= 0; y--)
  1286. {
  1287. string row = "";
  1288. for (int x = 0; x < landBitmap.GetLength(0); x++)
  1289. {
  1290. row += landBitmap[x, y] ? "#" : ".";
  1291. }
  1292. m_log.InfoFormat("{0}: {1}", LogHeader, row);
  1293. }
  1294. }
  1295. #endregion
  1296. #region Object Select and Object Owner Listing
  1297. public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  1298. {
  1299. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
  1300. {
  1301. List<uint> resultLocalIDs = new List<uint>();
  1302. try
  1303. {
  1304. lock (primsOverMe)
  1305. {
  1306. foreach (SceneObjectGroup obj in primsOverMe)
  1307. {
  1308. if (obj.LocalId > 0)
  1309. {
  1310. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == LandData.OwnerID)
  1311. {
  1312. resultLocalIDs.Add(obj.LocalId);
  1313. }
  1314. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == LandData.GroupID && LandData.GroupID != UUID.Zero)
  1315. {
  1316. resultLocalIDs.Add(obj.LocalId);
  1317. }
  1318. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  1319. obj.OwnerID != remote_client.AgentId)
  1320. {
  1321. resultLocalIDs.Add(obj.LocalId);
  1322. }
  1323. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  1324. {
  1325. resultLocalIDs.Add(obj.LocalId);
  1326. }
  1327. }
  1328. }
  1329. }
  1330. } catch (InvalidOperationException)
  1331. {
  1332. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  1333. }
  1334. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  1335. }
  1336. }
  1337. /// <summary>
  1338. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  1339. /// aggreagete details such as the number of prims.
  1340. ///
  1341. /// </summary>
  1342. /// <param name="remote_client">
  1343. /// A <see cref="IClientAPI"/>
  1344. /// </param>
  1345. public void SendLandObjectOwners(IClientAPI remote_client)
  1346. {
  1347. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
  1348. {
  1349. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  1350. List<UUID> groups = new List<UUID>();
  1351. lock (primsOverMe)
  1352. {
  1353. // m_log.DebugFormat(
  1354. // "[LAND OBJECT]: Request for SendLandObjectOwners() from {0} with {1} known prims on region",
  1355. // remote_client.Name, primsOverMe.Count);
  1356. try
  1357. {
  1358. foreach (SceneObjectGroup obj in primsOverMe)
  1359. {
  1360. try
  1361. {
  1362. if (!primCount.ContainsKey(obj.OwnerID))
  1363. {
  1364. primCount.Add(obj.OwnerID, 0);
  1365. }
  1366. }
  1367. catch (NullReferenceException)
  1368. {
  1369. m_log.Error("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  1370. }
  1371. try
  1372. {
  1373. primCount[obj.OwnerID] += obj.PrimCount;
  1374. }
  1375. catch (KeyNotFoundException)
  1376. {
  1377. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  1378. }
  1379. if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
  1380. groups.Add(obj.OwnerID);
  1381. }
  1382. }
  1383. catch (InvalidOperationException)
  1384. {
  1385. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  1386. }
  1387. }
  1388. remote_client.SendLandObjectOwners(LandData, groups, primCount);
  1389. }
  1390. }
  1391. public Dictionary<UUID, int> GetLandObjectOwners()
  1392. {
  1393. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  1394. lock (primsOverMe)
  1395. {
  1396. try
  1397. {
  1398. foreach (SceneObjectGroup obj in primsOverMe)
  1399. {
  1400. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  1401. {
  1402. ownersAndCount.Add(obj.OwnerID, 0);
  1403. }
  1404. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  1405. }
  1406. }
  1407. catch (InvalidOperationException)
  1408. {
  1409. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  1410. }
  1411. }
  1412. return ownersAndCount;
  1413. }
  1414. #endregion
  1415. #region Object Sales
  1416. public void SellLandObjects(UUID previousOwner)
  1417. {
  1418. // m_log.DebugFormat(
  1419. // "[LAND OBJECT]: Request to sell objects in {0} from {1}", LandData.Name, previousOwner);
  1420. if (LandData.IsGroupOwned)
  1421. return;
  1422. IBuySellModule m_BuySellModule = m_scene.RequestModuleInterface<IBuySellModule>();
  1423. if (m_BuySellModule == null)
  1424. {
  1425. m_log.Error("[LAND OBJECT]: BuySellModule not found");
  1426. return;
  1427. }
  1428. ScenePresence sp;
  1429. if (!m_scene.TryGetScenePresence(LandData.OwnerID, out sp))
  1430. {
  1431. m_log.Error("[LAND OBJECT]: New owner is not present in scene");
  1432. return;
  1433. }
  1434. lock (primsOverMe)
  1435. {
  1436. foreach (SceneObjectGroup obj in primsOverMe)
  1437. {
  1438. if(m_scene.Permissions.CanSellObject(previousOwner,obj, (byte)SaleType.Original))
  1439. m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0);
  1440. }
  1441. }
  1442. }
  1443. #endregion
  1444. #region Object Returning
  1445. public void ReturnObject(SceneObjectGroup obj)
  1446. {
  1447. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  1448. objs[0] = obj;
  1449. m_scene.returnObjects(objs, null);
  1450. }
  1451. public void ReturnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  1452. {
  1453. // m_log.DebugFormat(
  1454. // "[LAND OBJECT]: Request to return objects in {0} from {1}", LandData.Name, remote_client.Name);
  1455. Dictionary<UUID,List<SceneObjectGroup>> returns = new Dictionary<UUID,List<SceneObjectGroup>>();
  1456. lock (primsOverMe)
  1457. {
  1458. if (type == (uint)ObjectReturnType.Owner)
  1459. {
  1460. foreach (SceneObjectGroup obj in primsOverMe)
  1461. {
  1462. if (obj.OwnerID == LandData.OwnerID)
  1463. {
  1464. if (!returns.ContainsKey(obj.OwnerID))
  1465. returns[obj.OwnerID] =
  1466. new List<SceneObjectGroup>();
  1467. returns[obj.OwnerID].Add(obj);
  1468. }
  1469. }
  1470. }
  1471. else if (type == (uint)ObjectReturnType.Group && LandData.GroupID != UUID.Zero)
  1472. {
  1473. foreach (SceneObjectGroup obj in primsOverMe)
  1474. {
  1475. if (obj.GroupID == LandData.GroupID)
  1476. {
  1477. if (obj.OwnerID == LandData.OwnerID)
  1478. continue;
  1479. if (!returns.ContainsKey(obj.OwnerID))
  1480. returns[obj.OwnerID] =
  1481. new List<SceneObjectGroup>();
  1482. returns[obj.OwnerID].Add(obj);
  1483. }
  1484. }
  1485. }
  1486. else if (type == (uint)ObjectReturnType.Other)
  1487. {
  1488. foreach (SceneObjectGroup obj in primsOverMe)
  1489. {
  1490. if (obj.OwnerID != LandData.OwnerID &&
  1491. (obj.GroupID != LandData.GroupID ||
  1492. LandData.GroupID == UUID.Zero))
  1493. {
  1494. if (!returns.ContainsKey(obj.OwnerID))
  1495. returns[obj.OwnerID] =
  1496. new List<SceneObjectGroup>();
  1497. returns[obj.OwnerID].Add(obj);
  1498. }
  1499. }
  1500. }
  1501. else if (type == (uint)ObjectReturnType.List)
  1502. {
  1503. List<UUID> ownerlist = new List<UUID>(owners);
  1504. foreach (SceneObjectGroup obj in primsOverMe)
  1505. {
  1506. if (ownerlist.Contains(obj.OwnerID))
  1507. {
  1508. if (!returns.ContainsKey(obj.OwnerID))
  1509. returns[obj.OwnerID] =
  1510. new List<SceneObjectGroup>();
  1511. returns[obj.OwnerID].Add(obj);
  1512. }
  1513. }
  1514. }
  1515. }
  1516. foreach (List<SceneObjectGroup> ol in returns.Values)
  1517. {
  1518. if (m_scene.Permissions.CanReturnObjects(this, remote_client, ol))
  1519. m_scene.returnObjects(ol.ToArray(), remote_client);
  1520. }
  1521. }
  1522. #endregion
  1523. #region Object Adding/Removing from Parcel
  1524. public void ResetOverMeRecord()
  1525. {
  1526. lock (primsOverMe)
  1527. primsOverMe.Clear();
  1528. }
  1529. public void AddPrimOverMe(SceneObjectGroup obj)
  1530. {
  1531. // m_log.DebugFormat("[LAND OBJECT]: Adding scene object {0} {1} over {2}", obj.Name, obj.LocalId, LandData.Name);
  1532. lock (primsOverMe)
  1533. primsOverMe.Add(obj);
  1534. }
  1535. public void RemovePrimFromOverMe(SceneObjectGroup obj)
  1536. {
  1537. // m_log.DebugFormat("[LAND OBJECT]: Removing scene object {0} {1} from over {2}", obj.Name, obj.LocalId, LandData.Name);
  1538. lock (primsOverMe)
  1539. primsOverMe.Remove(obj);
  1540. }
  1541. #endregion
  1542. /// <summary>
  1543. /// Set the media url for this land parcel
  1544. /// </summary>
  1545. /// <param name="url"></param>
  1546. public void SetMediaUrl(string url)
  1547. {
  1548. LandData.MediaURL = url;
  1549. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
  1550. SendLandUpdateToAvatarsOverMe();
  1551. }
  1552. /// <summary>
  1553. /// Set the music url for this land parcel
  1554. /// </summary>
  1555. /// <param name="url"></param>
  1556. public void SetMusicUrl(string url)
  1557. {
  1558. LandData.MusicURL = url;
  1559. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
  1560. SendLandUpdateToAvatarsOverMe();
  1561. }
  1562. /// <summary>
  1563. /// Get the music url for this land parcel
  1564. /// </summary>
  1565. /// <returns>The music url.</returns>
  1566. public string GetMusicUrl()
  1567. {
  1568. return LandData.MusicURL;
  1569. }
  1570. #endregion
  1571. private void OnFrame()
  1572. {
  1573. m_expiryCounter++;
  1574. if (m_expiryCounter >= 50)
  1575. {
  1576. ExpireAccessList();
  1577. m_expiryCounter = 0;
  1578. }
  1579. // need to update dwell here bc landdata has no parent info
  1580. if(LandData != null && m_dwellModule != null)
  1581. {
  1582. double now = Util.GetTimeStampMS();
  1583. double elapsed = now - LandData.LastDwellTimeMS;
  1584. if(elapsed > 150000) //2.5 minutes resolution / throttle
  1585. {
  1586. float dwell = LandData.Dwell;
  1587. double cur = dwell * 60000.0;
  1588. double decay = 1.5e-8 * cur * elapsed;
  1589. cur -= decay;
  1590. if(cur < 0)
  1591. cur = 0;
  1592. UUID lgid = LandData.GlobalID;
  1593. m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
  1594. {
  1595. if(sp.IsNPC || sp.IsLoggingIn || sp.IsDeleted || sp.currentParcelUUID != lgid)
  1596. return;
  1597. cur += (now - sp.ParcelDwellTickMS);
  1598. sp.ParcelDwellTickMS = now;
  1599. });
  1600. float newdwell = (float)(cur * 1.666666666667e-5);
  1601. LandData.Dwell = newdwell;
  1602. if(Math.Abs(newdwell - dwell) >= 0.9)
  1603. m_scene.EventManager.TriggerLandObjectAdded(this);
  1604. }
  1605. }
  1606. }
  1607. private void ExpireAccessList()
  1608. {
  1609. List<LandAccessEntry> delete = new List<LandAccessEntry>();
  1610. foreach (LandAccessEntry entry in LandData.ParcelAccessList)
  1611. {
  1612. if (entry.Expires != 0 && entry.Expires < Util.UnixTimeSinceEpoch())
  1613. delete.Add(entry);
  1614. }
  1615. foreach (LandAccessEntry entry in delete)
  1616. {
  1617. LandData.ParcelAccessList.Remove(entry);
  1618. ScenePresence presence;
  1619. if (m_scene.TryGetScenePresence(entry.AgentID, out presence) && (!presence.IsChildAgent))
  1620. {
  1621. ILandObject land = m_scene.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y);
  1622. if (land.LandData.LocalID == LandData.LocalID)
  1623. {
  1624. Vector3 pos = m_scene.GetNearestAllowedPosition(presence, land);
  1625. presence.TeleportOnEject(pos);
  1626. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  1627. }
  1628. }
  1629. m_log.DebugFormat("[LAND]: Removing entry {0} because it has expired", entry.AgentID);
  1630. }
  1631. if (delete.Count > 0)
  1632. m_scene.EventManager.TriggerLandObjectUpdated((uint)LandData.LocalID, this);
  1633. }
  1634. }
  1635. }