LandObject.cs 72 KB

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