LandObject.cs 72 KB

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