LandManagementModule.cs 110 KB

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