LandObject.cs 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  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 previus 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. || bitmap_add.Rank != 2
  970. || bitmap_base.Rank != 2)
  971. {
  972. throw new Exception(
  973. String.Format("{0} MergeLandBitmaps. merging maps not same size. baseSizeXY=<{1},{2}>, addSizeXY=<{3},{4}>",
  974. LogHeader, bitmap_base.GetLength(0), bitmap_base.GetLength(1), bitmap_add.GetLength(0), bitmap_add.GetLength(1))
  975. );
  976. }
  977. int x, y;
  978. for (y = 0; y < bitmap_base.GetLength(1); y++)
  979. {
  980. for (x = 0; x < bitmap_add.GetLength(0); x++)
  981. {
  982. if (bitmap_add[x, y])
  983. {
  984. bitmap_base[x, y] = true;
  985. }
  986. }
  987. }
  988. return bitmap_base;
  989. }
  990. /// <summary>
  991. /// Remap a land bitmap. Takes the supplied land bitmap and rotates it, crops it and finally offsets it into
  992. /// a final land bitmap of the target region size.
  993. /// </summary>
  994. /// <param name="bitmap_base">The original parcel bitmap</param>
  995. /// <param name="rotationDegrees"></param>
  996. /// <param name="displacement">&lt;x,y,?&gt;</param>
  997. /// <param name="boundingOrigin">&lt;x,y,?&gt;</param>
  998. /// <param name="boundingSize">&lt;x,y,?&gt;</param>
  999. /// <param name="regionSize">&lt;x,y,?&gt;</param>
  1000. /// <param name="isEmptyNow">out: This is set if the resultant bitmap is now empty</param>
  1001. /// <param name="AABBMin">out: parcel.AABBMin &lt;x,y,0&gt</param>
  1002. /// <param name="AABBMax">out: parcel.AABBMax &lt;x,y,0&gt</param>
  1003. /// <returns>New parcel bitmap</returns>
  1004. 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)
  1005. {
  1006. // get the size of the incoming bitmap
  1007. int baseX = bitmap_base.GetLength(0);
  1008. int baseY = bitmap_base.GetLength(1);
  1009. // create an intermediate bitmap that is 25% bigger on each side that we can work with to handle rotations
  1010. int offsetX = baseX / 4; // the original origin will now be at these coordinates so now we can have imaginary negative coordinates ;)
  1011. int offsetY = baseY / 4;
  1012. int tmpX = baseX + baseX / 2;
  1013. int tmpY = baseY + baseY / 2;
  1014. int centreX = tmpX / 2;
  1015. int centreY = tmpY / 2;
  1016. bool[,] bitmap_tmp = new bool[tmpX, tmpY];
  1017. double radianRotation = Math.PI * rotationDegrees / 180f;
  1018. double cosR = Math.Cos(radianRotation);
  1019. double sinR = Math.Sin(radianRotation);
  1020. if (rotationDegrees < 0f) rotationDegrees += 360f; //-90=270 -180=180 -270=90
  1021. // So first we apply the rotation to the incoming bitmap, storing the result in bitmap_tmp
  1022. // We special case orthogonal rotations for accuracy because even using double precision math, Math.Cos(90 degrees) is never fully 0
  1023. // and we can never rotate around a centre pixel because the bitmap size is always even
  1024. int x, y, sx, sy;
  1025. for (y = 0; y <= tmpY; y++)
  1026. {
  1027. for (x = 0; x <= tmpX; x++)
  1028. {
  1029. if (rotationDegrees == 0f)
  1030. {
  1031. sx = x - offsetX;
  1032. sy = y - offsetY;
  1033. }
  1034. else if (rotationDegrees == 90f)
  1035. {
  1036. sx = y - offsetX;
  1037. sy = tmpY - 1 - x - offsetY;
  1038. }
  1039. else if (rotationDegrees == 180f)
  1040. {
  1041. sx = tmpX - 1 - x - offsetX;
  1042. sy = tmpY - 1 - y - offsetY;
  1043. }
  1044. else if (rotationDegrees == 270f)
  1045. {
  1046. sx = tmpX - 1 - y - offsetX;
  1047. sy = x - offsetY;
  1048. }
  1049. else
  1050. {
  1051. // 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?
  1052. sx = centreX + (int)Math.Round((((double)x - centreX) * cosR) + (((double)y - centreY) * sinR)) - offsetX;
  1053. sy = centreY + (int)Math.Round((((double)y - centreY) * cosR) - (((double)x - centreX) * sinR)) - offsetY;
  1054. }
  1055. if (sx >= 0 && sx < baseX && sy >= 0 && sy < baseY)
  1056. {
  1057. try
  1058. {
  1059. if (bitmap_base[sx, sy]) bitmap_tmp[x, y] = true;
  1060. }
  1061. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  1062. {
  1063. m_log.DebugFormat("{0} RemapLandBitmap Rotate: Out of Bounds sx={1} sy={2} dx={3} dy={4}", LogHeader, sx, sy, x, y);
  1064. }
  1065. }
  1066. }
  1067. }
  1068. // We could also incorporate the next steps, bounding-rectangle and displacement in the loop above, but it's simpler to visualise if done separately
  1069. // and will also make it much easier when later I want the option for maybe a circular or oval bounding shape too ;).
  1070. // So... our output land bitmap must be the size of the current region but rememeber, parcel landbitmaps are landUnit metres (4x4 metres) per point,
  1071. // and region sizes, boundaries and displacements are in metres so we need to scale down
  1072. int newX = (int)(regionSize.X / landUnit);
  1073. int newY = (int)(regionSize.Y / landUnit);
  1074. bool[,] bitmap_new = new bool[newX, newY];
  1075. // 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
  1076. int dispX = (int)Math.Floor(displacement.X / landUnit);
  1077. int dispY = (int)Math.Floor(displacement.Y / landUnit);
  1078. // startX/Y and endX/Y are coordinates in bitmap_tmp
  1079. int startX = (int)Math.Floor(boundingOrigin.X / landUnit) + offsetX;
  1080. if (startX > tmpX) startX = tmpX;
  1081. if (startX < 0) startX = 0;
  1082. int startY = (int)Math.Floor(boundingOrigin.Y / landUnit) + offsetY;
  1083. if (startY > tmpY) startY = tmpY;
  1084. if (startY < 0) startY = 0;
  1085. int endX = (int)Math.Floor((boundingOrigin.X + boundingSize.X) / landUnit) + offsetX;
  1086. if (endX > tmpX) endX = tmpX;
  1087. if (endX < 0) endX = 0;
  1088. int endY = (int)Math.Floor((boundingOrigin.Y + boundingSize.Y) / landUnit) + offsetY;
  1089. if (endY > tmpY) endY = tmpY;
  1090. if (endY < 0) endY = 0;
  1091. //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,
  1092. // baseX, baseY, dispX, dispY, radianRotation, offsetX, offsetY, startX, startY, endX, endY, cosR, sinR, newX, newY);
  1093. isEmptyNow = true;
  1094. int minX = newX;
  1095. int minY = newY;
  1096. int maxX = 0;
  1097. int maxY = 0;
  1098. int dx, dy;
  1099. for (y = startY; y < endY; y++)
  1100. {
  1101. for (x = startX; x < endX; x++)
  1102. {
  1103. dx = x - startX + dispX;
  1104. dy = y - startY + dispY;
  1105. if (dx >= 0 && dx < newX && dy >= 0 && dy < newY)
  1106. {
  1107. try
  1108. {
  1109. if (bitmap_tmp[x, y])
  1110. {
  1111. bitmap_new[dx, dy] = true;
  1112. isEmptyNow = false;
  1113. if (dx < minX) minX = dx;
  1114. if (dy < minY) minY = dy;
  1115. if (dx > maxX) maxX = dx;
  1116. if (dy > maxY) maxY = dy;
  1117. }
  1118. }
  1119. catch (Exception) //just in case we've still not taken care of every way the arrays might go out of bounds! ;)
  1120. {
  1121. m_log.DebugFormat("{0} RemapLandBitmap - Bound & Displace: Out of Bounds sx={1} sy={2} dx={3} dy={4}", LogHeader, x, y, dx, dy);
  1122. }
  1123. }
  1124. }
  1125. }
  1126. if (isEmptyNow)
  1127. {
  1128. //m_log.DebugFormat("{0} RemapLandBitmap: Land bitmap is marked as Empty", LogHeader);
  1129. minX = 0;
  1130. minY = 0;
  1131. }
  1132. AABBMin = new Vector3(minX * landUnit, minY * landUnit, 0);
  1133. AABBMax = new Vector3(maxX * landUnit, maxY * landUnit, 0);
  1134. return bitmap_new;
  1135. }
  1136. /// <summary>
  1137. /// Clears any parcel data in bitmap_base where there exists parcel data in bitmap_new. In other words the parcel data
  1138. /// in bitmap_new takes over the space of the parcel data in bitmap_base.
  1139. /// </summary>
  1140. /// <param name="bitmap_base"></param>
  1141. /// <param name="bitmap_new"></param>
  1142. /// <param name="isEmptyNow">out: This is set if the resultant bitmap is now empty</param>
  1143. /// <param name="AABBMin">out: parcel.AABBMin &lt;x,y,0&gt</param>
  1144. /// <param name="AABBMax">out: parcel.AABBMax &lt;x,y,0&gt</param>
  1145. /// <returns>New parcel bitmap</returns>
  1146. public bool[,] RemoveFromLandBitmap(bool[,] bitmap_base, bool[,] bitmap_new, out bool isEmptyNow, out Vector3 AABBMin, out Vector3 AABBMax)
  1147. {
  1148. // get the size of the incoming bitmaps
  1149. int baseX = bitmap_base.GetLength(0);
  1150. int baseY = bitmap_base.GetLength(1);
  1151. int newX = bitmap_new.GetLength(0);
  1152. int newY = bitmap_new.GetLength(1);
  1153. if (baseX != newX || baseY != newY)
  1154. {
  1155. throw new Exception(
  1156. String.Format("{0} RemoveFromLandBitmap: Land bitmaps are not the same size! baseX={1} baseY={2} newX={3} newY={4}", LogHeader, baseX, baseY, newX, newY));
  1157. }
  1158. isEmptyNow = true;
  1159. int minX = baseX;
  1160. int minY = baseY;
  1161. int maxX = 0;
  1162. int maxY = 0;
  1163. for (int y = 0; y < baseY; y++)
  1164. {
  1165. for (int x = 0; x < baseX; x++)
  1166. {
  1167. if (bitmap_new[x, y]) bitmap_base[x, y] = false;
  1168. if (bitmap_base[x, y])
  1169. {
  1170. isEmptyNow = false;
  1171. if (x < minX) minX = x;
  1172. if (y < minY) minY = y;
  1173. if (x > maxX) maxX = x;
  1174. if (y > maxY) maxY = y;
  1175. }
  1176. }
  1177. }
  1178. if (isEmptyNow)
  1179. {
  1180. //m_log.DebugFormat("{0} RemoveFromLandBitmap: Land bitmap is marked as Empty", LogHeader);
  1181. minX = 0;
  1182. minY = 0;
  1183. }
  1184. AABBMin = new Vector3(minX * landUnit, minY * landUnit, 0);
  1185. AABBMax = new Vector3(maxX * landUnit, maxY * landUnit, 0);
  1186. return bitmap_base;
  1187. }
  1188. /// <summary>
  1189. /// Converts the land bitmap to a packet friendly byte array
  1190. /// </summary>
  1191. /// <returns></returns>
  1192. public byte[] ConvertLandBitmapToBytes()
  1193. {
  1194. byte[] tempConvertArr = new byte[LandBitmap.GetLength(0) * LandBitmap.GetLength(1) / 8];
  1195. int tempByte = 0;
  1196. int byteNum = 0;
  1197. int mask = 1;
  1198. for (int y = 0; y < LandBitmap.GetLength(1); y++)
  1199. {
  1200. for (int x = 0; x < LandBitmap.GetLength(0); x++)
  1201. {
  1202. if (LandBitmap[x, y])
  1203. tempByte |= mask;
  1204. mask = mask << 1;
  1205. if (mask == 0x100)
  1206. {
  1207. mask = 1;
  1208. tempConvertArr[byteNum++] = (byte)tempByte;
  1209. tempByte = 0;
  1210. }
  1211. }
  1212. }
  1213. if(tempByte != 0 && byteNum < 512)
  1214. tempConvertArr[byteNum] = (byte)tempByte;
  1215. return tempConvertArr;
  1216. }
  1217. public bool[,] ConvertBytesToLandBitmap(bool overrideRegionSize = false)
  1218. {
  1219. int bitmapLen;
  1220. int xLen;
  1221. bool[,] tempConvertMap;
  1222. if (overrideRegionSize)
  1223. {
  1224. // Importing land parcel data from an OAR where the source region is a different size to the dest region requires us
  1225. // to make a LandBitmap that's not derived from the current region's size. We use the LandData.Bitmap size in bytes
  1226. // 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?)
  1227. // This method assumes we always will have square regions
  1228. bitmapLen = LandData.Bitmap.Length;
  1229. xLen = (int)Math.Abs(Math.Sqrt(bitmapLen * 8));
  1230. tempConvertMap = new bool[xLen, xLen];
  1231. tempConvertMap.Initialize();
  1232. }
  1233. else
  1234. {
  1235. tempConvertMap = new bool[m_scene.RegionInfo.RegionSizeX / landUnit, m_scene.RegionInfo.RegionSizeY / landUnit];
  1236. tempConvertMap.Initialize();
  1237. // Math.Min overcomes an old bug that might have made it into the database. Only use the bytes that fit into convertMap.
  1238. bitmapLen = Math.Min(LandData.Bitmap.Length, tempConvertMap.GetLength(0) * tempConvertMap.GetLength(1) / 8);
  1239. xLen = (int)(m_scene.RegionInfo.RegionSizeX / landUnit);
  1240. if (bitmapLen == 512)
  1241. {
  1242. // Legacy bitmap being passed in. Use the legacy region size
  1243. // and only set the lower area of the larger region.
  1244. xLen = (int)(Constants.RegionSize / landUnit);
  1245. }
  1246. }
  1247. // m_log.DebugFormat("{0} ConvertBytesToLandBitmap: bitmapLen={1}, xLen={2}", LogHeader, bitmapLen, xLen);
  1248. byte tempByte;
  1249. int x = 0, y = 0;
  1250. for (int i = 0; i < bitmapLen; i++)
  1251. {
  1252. tempByte = LandData.Bitmap[i];
  1253. for (int bitmask = 0x01; bitmask < 0x100; bitmask = bitmask << 1)
  1254. {
  1255. bool bit = (tempByte & bitmask) == bitmask;
  1256. try
  1257. {
  1258. tempConvertMap[x, y] = bit;
  1259. }
  1260. catch (Exception)
  1261. {
  1262. m_log.DebugFormat("{0} ConvertBytestoLandBitmap: i={1}, x={2}, y={3}", LogHeader, i, x, y);
  1263. }
  1264. x++;
  1265. if (x >= xLen)
  1266. {
  1267. x = 0;
  1268. y++;
  1269. }
  1270. }
  1271. }
  1272. return tempConvertMap;
  1273. }
  1274. public bool IsLandBitmapEmpty(bool[,] landBitmap)
  1275. {
  1276. for (int y = 0; y < landBitmap.GetLength(1); y++)
  1277. {
  1278. for (int x = 0; x < landBitmap.GetLength(0); x++)
  1279. {
  1280. if (landBitmap[x, y]) return false;
  1281. }
  1282. }
  1283. return true;
  1284. }
  1285. public void DebugLandBitmap(bool[,] landBitmap)
  1286. {
  1287. m_log.InfoFormat("{0}: Map Key: #=claimed land .=unclaimed land.", LogHeader);
  1288. for (int y = landBitmap.GetLength(1) - 1; y >= 0; y--)
  1289. {
  1290. string row = "";
  1291. for (int x = 0; x < landBitmap.GetLength(0); x++)
  1292. {
  1293. row += landBitmap[x, y] ? "#" : ".";
  1294. }
  1295. m_log.InfoFormat("{0}: {1}", LogHeader, row);
  1296. }
  1297. }
  1298. #endregion
  1299. #region Object Select and Object Owner Listing
  1300. public void SendForceObjectSelect(int local_id, int request_type, List<UUID> returnIDs, IClientAPI remote_client)
  1301. {
  1302. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
  1303. {
  1304. List<uint> resultLocalIDs = new List<uint>();
  1305. try
  1306. {
  1307. lock (primsOverMe)
  1308. {
  1309. foreach (SceneObjectGroup obj in primsOverMe)
  1310. {
  1311. if (obj.LocalId > 0)
  1312. {
  1313. if (request_type == LandChannel.LAND_SELECT_OBJECTS_OWNER && obj.OwnerID == LandData.OwnerID)
  1314. {
  1315. resultLocalIDs.Add(obj.LocalId);
  1316. }
  1317. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_GROUP && obj.GroupID == LandData.GroupID && LandData.GroupID != UUID.Zero)
  1318. {
  1319. resultLocalIDs.Add(obj.LocalId);
  1320. }
  1321. else if (request_type == LandChannel.LAND_SELECT_OBJECTS_OTHER &&
  1322. obj.OwnerID != remote_client.AgentId)
  1323. {
  1324. resultLocalIDs.Add(obj.LocalId);
  1325. }
  1326. else if (request_type == (int)ObjectReturnType.List && returnIDs.Contains(obj.OwnerID))
  1327. {
  1328. resultLocalIDs.Add(obj.LocalId);
  1329. }
  1330. }
  1331. }
  1332. }
  1333. } catch (InvalidOperationException)
  1334. {
  1335. m_log.Error("[LAND]: Unable to force select the parcel objects. Arr.");
  1336. }
  1337. remote_client.SendForceClientSelectObjects(resultLocalIDs);
  1338. }
  1339. }
  1340. /// <summary>
  1341. /// Notify the parcel owner each avatar that owns prims situated on their land. This notification includes
  1342. /// aggreagete details such as the number of prims.
  1343. ///
  1344. /// </summary>
  1345. /// <param name="remote_client">
  1346. /// A <see cref="IClientAPI"/>
  1347. /// </param>
  1348. public void SendLandObjectOwners(IClientAPI remote_client)
  1349. {
  1350. if (m_scene.Permissions.CanEditParcelProperties(remote_client.AgentId, this, GroupPowers.LandOptions, true))
  1351. {
  1352. Dictionary<UUID, int> primCount = new Dictionary<UUID, int>();
  1353. List<UUID> groups = new List<UUID>();
  1354. lock (primsOverMe)
  1355. {
  1356. // m_log.DebugFormat(
  1357. // "[LAND OBJECT]: Request for SendLandObjectOwners() from {0} with {1} known prims on region",
  1358. // remote_client.Name, primsOverMe.Count);
  1359. try
  1360. {
  1361. foreach (SceneObjectGroup obj in primsOverMe)
  1362. {
  1363. try
  1364. {
  1365. if (!primCount.ContainsKey(obj.OwnerID))
  1366. {
  1367. primCount.Add(obj.OwnerID, 0);
  1368. }
  1369. }
  1370. catch (NullReferenceException)
  1371. {
  1372. m_log.Error("[LAND]: " + "Got Null Reference when searching land owners from the parcel panel");
  1373. }
  1374. try
  1375. {
  1376. primCount[obj.OwnerID] += obj.PrimCount;
  1377. }
  1378. catch (KeyNotFoundException)
  1379. {
  1380. m_log.Error("[LAND]: Unable to match a prim with it's owner.");
  1381. }
  1382. if (obj.OwnerID == obj.GroupID && (!groups.Contains(obj.OwnerID)))
  1383. groups.Add(obj.OwnerID);
  1384. }
  1385. }
  1386. catch (InvalidOperationException)
  1387. {
  1388. m_log.Error("[LAND]: Unable to Enumerate Land object arr.");
  1389. }
  1390. }
  1391. remote_client.SendLandObjectOwners(LandData, groups, primCount);
  1392. }
  1393. }
  1394. public Dictionary<UUID, int> GetLandObjectOwners()
  1395. {
  1396. Dictionary<UUID, int> ownersAndCount = new Dictionary<UUID, int>();
  1397. lock (primsOverMe)
  1398. {
  1399. try
  1400. {
  1401. foreach (SceneObjectGroup obj in primsOverMe)
  1402. {
  1403. if (!ownersAndCount.ContainsKey(obj.OwnerID))
  1404. {
  1405. ownersAndCount.Add(obj.OwnerID, 0);
  1406. }
  1407. ownersAndCount[obj.OwnerID] += obj.PrimCount;
  1408. }
  1409. }
  1410. catch (InvalidOperationException)
  1411. {
  1412. m_log.Error("[LAND]: Unable to enumerate land owners. arr.");
  1413. }
  1414. }
  1415. return ownersAndCount;
  1416. }
  1417. #endregion
  1418. #region Object Sales
  1419. public void SellLandObjects(UUID previousOwner)
  1420. {
  1421. // m_log.DebugFormat(
  1422. // "[LAND OBJECT]: Request to sell objects in {0} from {1}", LandData.Name, previousOwner);
  1423. if (LandData.IsGroupOwned)
  1424. return;
  1425. IBuySellModule m_BuySellModule = m_scene.RequestModuleInterface<IBuySellModule>();
  1426. if (m_BuySellModule == null)
  1427. {
  1428. m_log.Error("[LAND OBJECT]: BuySellModule not found");
  1429. return;
  1430. }
  1431. ScenePresence sp;
  1432. if (!m_scene.TryGetScenePresence(LandData.OwnerID, out sp))
  1433. {
  1434. m_log.Error("[LAND OBJECT]: New owner is not present in scene");
  1435. return;
  1436. }
  1437. lock (primsOverMe)
  1438. {
  1439. foreach (SceneObjectGroup obj in primsOverMe)
  1440. {
  1441. if(m_scene.Permissions.CanSellObject(previousOwner,obj, (byte)SaleType.Original))
  1442. m_BuySellModule.BuyObject(sp.ControllingClient, UUID.Zero, obj.LocalId, 1, 0);
  1443. }
  1444. }
  1445. }
  1446. #endregion
  1447. #region Object Returning
  1448. public void ReturnObject(SceneObjectGroup obj)
  1449. {
  1450. SceneObjectGroup[] objs = new SceneObjectGroup[1];
  1451. objs[0] = obj;
  1452. m_scene.returnObjects(objs, null);
  1453. }
  1454. public void ReturnLandObjects(uint type, UUID[] owners, UUID[] tasks, IClientAPI remote_client)
  1455. {
  1456. // m_log.DebugFormat(
  1457. // "[LAND OBJECT]: Request to return objects in {0} from {1}", LandData.Name, remote_client.Name);
  1458. Dictionary<UUID,List<SceneObjectGroup>> returns = new Dictionary<UUID,List<SceneObjectGroup>>();
  1459. lock (primsOverMe)
  1460. {
  1461. if (type == (uint)ObjectReturnType.Owner)
  1462. {
  1463. foreach (SceneObjectGroup obj in primsOverMe)
  1464. {
  1465. if (obj.OwnerID == LandData.OwnerID)
  1466. {
  1467. if (!returns.ContainsKey(obj.OwnerID))
  1468. returns[obj.OwnerID] =
  1469. new List<SceneObjectGroup>();
  1470. returns[obj.OwnerID].Add(obj);
  1471. }
  1472. }
  1473. }
  1474. else if (type == (uint)ObjectReturnType.Group && LandData.GroupID != UUID.Zero)
  1475. {
  1476. foreach (SceneObjectGroup obj in primsOverMe)
  1477. {
  1478. if (obj.GroupID == LandData.GroupID)
  1479. {
  1480. if (obj.OwnerID == LandData.OwnerID)
  1481. continue;
  1482. if (!returns.ContainsKey(obj.OwnerID))
  1483. returns[obj.OwnerID] =
  1484. new List<SceneObjectGroup>();
  1485. returns[obj.OwnerID].Add(obj);
  1486. }
  1487. }
  1488. }
  1489. else if (type == (uint)ObjectReturnType.Other)
  1490. {
  1491. foreach (SceneObjectGroup obj in primsOverMe)
  1492. {
  1493. if (obj.OwnerID != LandData.OwnerID &&
  1494. (obj.GroupID != LandData.GroupID ||
  1495. LandData.GroupID == UUID.Zero))
  1496. {
  1497. if (!returns.ContainsKey(obj.OwnerID))
  1498. returns[obj.OwnerID] =
  1499. new List<SceneObjectGroup>();
  1500. returns[obj.OwnerID].Add(obj);
  1501. }
  1502. }
  1503. }
  1504. else if (type == (uint)ObjectReturnType.List)
  1505. {
  1506. List<UUID> ownerlist = new List<UUID>(owners);
  1507. foreach (SceneObjectGroup obj in primsOverMe)
  1508. {
  1509. if (ownerlist.Contains(obj.OwnerID))
  1510. {
  1511. if (!returns.ContainsKey(obj.OwnerID))
  1512. returns[obj.OwnerID] =
  1513. new List<SceneObjectGroup>();
  1514. returns[obj.OwnerID].Add(obj);
  1515. }
  1516. }
  1517. }
  1518. }
  1519. foreach (List<SceneObjectGroup> ol in returns.Values)
  1520. {
  1521. if (m_scene.Permissions.CanReturnObjects(this, remote_client, ol))
  1522. m_scene.returnObjects(ol.ToArray(), remote_client);
  1523. }
  1524. }
  1525. #endregion
  1526. #region Object Adding/Removing from Parcel
  1527. public void ResetOverMeRecord()
  1528. {
  1529. lock (primsOverMe)
  1530. primsOverMe.Clear();
  1531. }
  1532. public void AddPrimOverMe(SceneObjectGroup obj)
  1533. {
  1534. // m_log.DebugFormat("[LAND OBJECT]: Adding scene object {0} {1} over {2}", obj.Name, obj.LocalId, LandData.Name);
  1535. lock (primsOverMe)
  1536. primsOverMe.Add(obj);
  1537. }
  1538. public void RemovePrimFromOverMe(SceneObjectGroup obj)
  1539. {
  1540. // m_log.DebugFormat("[LAND OBJECT]: Removing scene object {0} {1} from over {2}", obj.Name, obj.LocalId, LandData.Name);
  1541. lock (primsOverMe)
  1542. primsOverMe.Remove(obj);
  1543. }
  1544. #endregion
  1545. /// <summary>
  1546. /// Set the media url for this land parcel
  1547. /// </summary>
  1548. /// <param name="url"></param>
  1549. public void SetMediaUrl(string url)
  1550. {
  1551. LandData.MediaURL = url;
  1552. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
  1553. SendLandUpdateToAvatarsOverMe();
  1554. }
  1555. /// <summary>
  1556. /// Set the music url for this land parcel
  1557. /// </summary>
  1558. /// <param name="url"></param>
  1559. public void SetMusicUrl(string url)
  1560. {
  1561. LandData.MusicURL = url;
  1562. m_scene.LandChannel.UpdateLandObject(LandData.LocalID, LandData);
  1563. SendLandUpdateToAvatarsOverMe();
  1564. }
  1565. /// <summary>
  1566. /// Get the music url for this land parcel
  1567. /// </summary>
  1568. /// <returns>The music url.</returns>
  1569. public string GetMusicUrl()
  1570. {
  1571. return LandData.MusicURL;
  1572. }
  1573. #endregion
  1574. private void OnFrame()
  1575. {
  1576. m_expiryCounter++;
  1577. if (m_expiryCounter >= 50)
  1578. {
  1579. ExpireAccessList();
  1580. m_expiryCounter = 0;
  1581. }
  1582. // need to update dwell here bc landdata has no parent info
  1583. if(LandData != null && m_dwellModule != null)
  1584. {
  1585. double now = Util.GetTimeStampMS();
  1586. double elapsed = now - LandData.LastDwellTimeMS;
  1587. if(elapsed > 150000) //2.5 minutes resolution / throttle
  1588. {
  1589. float dwell = LandData.Dwell;
  1590. double cur = dwell * 60000.0;
  1591. double decay = 1.5e-8 * cur * elapsed;
  1592. cur -= decay;
  1593. if(cur < 0)
  1594. cur = 0;
  1595. UUID lgid = LandData.GlobalID;
  1596. m_scene.ForEachRootScenePresence(delegate(ScenePresence sp)
  1597. {
  1598. if(sp.IsNPC || sp.IsLoggingIn || sp.IsDeleted || sp.currentParcelUUID != lgid)
  1599. return;
  1600. cur += (now - sp.ParcelDwellTickMS);
  1601. sp.ParcelDwellTickMS = now;
  1602. });
  1603. float newdwell = (float)(cur * 1.666666666667e-5);
  1604. LandData.Dwell = newdwell;
  1605. if(Math.Abs(newdwell - dwell) >= 0.9)
  1606. m_scene.EventManager.TriggerLandObjectAdded(this);
  1607. }
  1608. }
  1609. }
  1610. private void ExpireAccessList()
  1611. {
  1612. List<LandAccessEntry> delete = new List<LandAccessEntry>();
  1613. foreach (LandAccessEntry entry in LandData.ParcelAccessList)
  1614. {
  1615. if (entry.Expires != 0 && entry.Expires < Util.UnixTimeSinceEpoch())
  1616. delete.Add(entry);
  1617. }
  1618. foreach (LandAccessEntry entry in delete)
  1619. {
  1620. LandData.ParcelAccessList.Remove(entry);
  1621. ScenePresence presence;
  1622. if (m_scene.TryGetScenePresence(entry.AgentID, out presence) && (!presence.IsChildAgent))
  1623. {
  1624. ILandObject land = m_scene.LandChannel.GetLandObject(presence.AbsolutePosition.X, presence.AbsolutePosition.Y);
  1625. if (land.LandData.LocalID == LandData.LocalID)
  1626. {
  1627. Vector3 pos = m_scene.GetNearestAllowedPosition(presence, land);
  1628. presence.TeleportOnEject(pos);
  1629. presence.ControllingClient.SendAlertMessage("You have been ejected from this land");
  1630. }
  1631. }
  1632. m_log.DebugFormat("[LAND]: Removing entry {0} because it has expired", entry.AgentID);
  1633. }
  1634. if (delete.Count > 0)
  1635. m_scene.EventManager.TriggerLandObjectUpdated((uint)LandData.LocalID, this);
  1636. }
  1637. }
  1638. }