LandManagementModule.cs 83 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  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.Servers.HttpServer;
  44. using OpenSim.Region.Framework.Interfaces;
  45. using OpenSim.Region.Framework.Scenes;
  46. using OpenSim.Region.Physics.Manager;
  47. using OpenSim.Services.Interfaces;
  48. using Caps = OpenSim.Framework.Capabilities.Caps;
  49. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  50. namespace OpenSim.Region.CoreModules.World.Land
  51. {
  52. // used for caching
  53. internal class ExtendedLandData
  54. {
  55. public LandData LandData;
  56. public ulong RegionHandle;
  57. public uint X, Y;
  58. public byte RegionAccess;
  59. }
  60. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LandManagementModule")]
  61. public class LandManagementModule : INonSharedRegionModule
  62. {
  63. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  64. private static readonly string remoteParcelRequestPath = "0009/";
  65. private LandChannel landChannel;
  66. private Scene m_scene;
  67. protected IUserManagement m_userManager;
  68. protected IPrimCountModule m_primCountModule;
  69. protected IDialogModule m_Dialog;
  70. // Minimum for parcels to work is 64m even if we don't actually use them.
  71. #pragma warning disable 0429
  72. private const int landArrayMax = ((int)((int)Constants.RegionSize / 4) >= 64) ? (int)((int)Constants.RegionSize / 4) : 64;
  73. #pragma warning restore 0429
  74. /// <value>
  75. /// Local land ids at specified region co-ordinates (region size / 4)
  76. /// </value>
  77. private readonly int[,] m_landIDList = new int[landArrayMax, landArrayMax];
  78. /// <value>
  79. /// Land objects keyed by local id
  80. /// </value>
  81. private readonly Dictionary<int, ILandObject> m_landList = new Dictionary<int, ILandObject>();
  82. private int m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  83. private bool m_allowedForcefulBans = true;
  84. // caches ExtendedLandData
  85. private Cache parcelInfoCache;
  86. /// <summary>
  87. /// Record positions that avatar's are currently being forced to move to due to parcel entry restrictions.
  88. /// </summary>
  89. private Dictionary<UUID, Vector3> forcedPosition = new Dictionary<UUID, Vector3>();
  90. #region INonSharedRegionModule Members
  91. public Type ReplaceableInterface
  92. {
  93. get { return null; }
  94. }
  95. public void Initialise(IConfigSource source)
  96. {
  97. }
  98. public void AddRegion(Scene scene)
  99. {
  100. m_scene = scene;
  101. m_landIDList.Initialize();
  102. landChannel = new LandChannel(scene, this);
  103. parcelInfoCache = new Cache();
  104. parcelInfoCache.Size = 30; // the number of different parcel requests in this region to cache
  105. parcelInfoCache.DefaultTTL = new TimeSpan(0, 5, 0);
  106. m_scene.EventManager.OnParcelPrimCountAdd += EventManagerOnParcelPrimCountAdd;
  107. m_scene.EventManager.OnParcelPrimCountUpdate += EventManagerOnParcelPrimCountUpdate;
  108. m_scene.EventManager.OnObjectBeingRemovedFromScene += EventManagerOnObjectBeingRemovedFromScene;
  109. m_scene.EventManager.OnRequestParcelPrimCountUpdate += EventManagerOnRequestParcelPrimCountUpdate;
  110. m_scene.EventManager.OnAvatarEnteringNewParcel += EventManagerOnAvatarEnteringNewParcel;
  111. m_scene.EventManager.OnClientMovement += EventManagerOnClientMovement;
  112. m_scene.EventManager.OnValidateLandBuy += EventManagerOnValidateLandBuy;
  113. m_scene.EventManager.OnLandBuy += EventManagerOnLandBuy;
  114. m_scene.EventManager.OnNewClient += EventManagerOnNewClient;
  115. m_scene.EventManager.OnMakeChildAgent += EventMakeChildAgent;
  116. m_scene.EventManager.OnSignificantClientMovement += EventManagerOnSignificantClientMovement;
  117. m_scene.EventManager.OnNoticeNoLandDataFromStorage += EventManagerOnNoLandDataFromStorage;
  118. m_scene.EventManager.OnIncomingLandDataFromStorage += EventManagerOnIncomingLandDataFromStorage;
  119. m_scene.EventManager.OnSetAllowForcefulBan += EventManagerOnSetAllowedForcefulBan;
  120. m_scene.EventManager.OnRegisterCaps += EventManagerOnRegisterCaps;
  121. lock (m_scene)
  122. {
  123. m_scene.LandChannel = (ILandChannel)landChannel;
  124. }
  125. RegisterCommands();
  126. }
  127. public void RegionLoaded(Scene scene)
  128. {
  129. m_userManager = m_scene.RequestModuleInterface<IUserManagement>();
  130. m_primCountModule = m_scene.RequestModuleInterface<IPrimCountModule>();
  131. m_Dialog = m_scene.RequestModuleInterface<IDialogModule>();
  132. }
  133. public void RemoveRegion(Scene scene)
  134. {
  135. // TODO: Release event manager listeners here
  136. }
  137. // private bool OnVerifyUserConnection(ScenePresence scenePresence, out string reason)
  138. // {
  139. // ILandObject nearestParcel = m_scene.GetNearestAllowedParcel(scenePresence.UUID, scenePresence.AbsolutePosition.X, scenePresence.AbsolutePosition.Y);
  140. // reason = "You are not allowed to enter this sim.";
  141. // return nearestParcel != null;
  142. // }
  143. void EventManagerOnNewClient(IClientAPI client)
  144. {
  145. //Register some client events
  146. client.OnParcelPropertiesRequest += ClientOnParcelPropertiesRequest;
  147. client.OnParcelDivideRequest += ClientOnParcelDivideRequest;
  148. client.OnParcelJoinRequest += ClientOnParcelJoinRequest;
  149. client.OnParcelPropertiesUpdateRequest += ClientOnParcelPropertiesUpdateRequest;
  150. client.OnParcelSelectObjects += ClientOnParcelSelectObjects;
  151. client.OnParcelObjectOwnerRequest += ClientOnParcelObjectOwnerRequest;
  152. client.OnParcelAccessListRequest += ClientOnParcelAccessListRequest;
  153. client.OnParcelAccessListUpdateRequest += ClientOnParcelAccessListUpdateRequest;
  154. client.OnParcelAbandonRequest += ClientOnParcelAbandonRequest;
  155. client.OnParcelGodForceOwner += ClientOnParcelGodForceOwner;
  156. client.OnParcelReclaim += ClientOnParcelReclaim;
  157. client.OnParcelInfoRequest += ClientOnParcelInfoRequest;
  158. client.OnParcelDeedToGroup += ClientOnParcelDeedToGroup;
  159. client.OnPreAgentUpdate += ClientOnPreAgentUpdate;
  160. client.OnParcelEjectUser += ClientOnParcelEjectUser;
  161. client.OnParcelFreezeUser += ClientOnParcelFreezeUser;
  162. client.OnSetStartLocationRequest += ClientOnSetHome;
  163. EntityBase presenceEntity;
  164. if (m_scene.Entities.TryGetValue(client.AgentId, out presenceEntity) && presenceEntity is ScenePresence)
  165. {
  166. SendLandUpdate((ScenePresence)presenceEntity, true);
  167. SendParcelOverlay(client);
  168. }
  169. }
  170. public void EventMakeChildAgent(ScenePresence avatar)
  171. {
  172. avatar.currentParcelUUID = UUID.Zero;
  173. }
  174. void ClientOnPreAgentUpdate(IClientAPI remoteClient, AgentUpdateArgs agentData)
  175. {
  176. //If we are forcing a position for them to go
  177. if (forcedPosition.ContainsKey(remoteClient.AgentId))
  178. {
  179. ScenePresence clientAvatar = m_scene.GetScenePresence(remoteClient.AgentId);
  180. //Putting the user into flying, both keeps the avatar in fligth when it bumps into something and stopped from going another direction AND
  181. //When the avatar walks into a ban line on the ground, it prevents getting stuck
  182. agentData.ControlFlags = (uint)AgentManager.ControlFlags.AGENT_CONTROL_FLY;
  183. //Make sure we stop if they get about to the right place to prevent yoyo and prevents getting stuck on banlines
  184. if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) < .2)
  185. {
  186. // m_log.DebugFormat(
  187. // "[LAND MANAGEMENT MODULE]: Stopping force position of {0} because {1} is close enough to {2}",
  188. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
  189. forcedPosition.Remove(remoteClient.AgentId);
  190. }
  191. //if we are far away, teleport
  192. else if (Vector3.Distance(clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]) > 3)
  193. {
  194. Vector3 forcePosition = forcedPosition[remoteClient.AgentId];
  195. // m_log.DebugFormat(
  196. // "[LAND MANAGEMENT MODULE]: Teleporting out {0} because {1} is too far from avatar position {2}",
  197. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcePosition);
  198. m_scene.RequestTeleportLocation(remoteClient, m_scene.RegionInfo.RegionHandle,
  199. forcePosition, clientAvatar.Lookat, (uint)Constants.TeleportFlags.ForceRedirect);
  200. forcedPosition.Remove(remoteClient.AgentId);
  201. }
  202. else
  203. {
  204. // m_log.DebugFormat(
  205. // "[LAND MANAGEMENT MODULE]: Forcing {0} from {1} to {2}",
  206. // clientAvatar.Name, clientAvatar.AbsolutePosition, forcedPosition[remoteClient.AgentId]);
  207. //Forces them toward the forced position we want if they aren't there yet
  208. agentData.UseClientAgentPosition = true;
  209. agentData.ClientAgentPosition = forcedPosition[remoteClient.AgentId];
  210. }
  211. }
  212. }
  213. public void Close()
  214. {
  215. }
  216. public string Name
  217. {
  218. get { return "LandManagementModule"; }
  219. }
  220. #endregion
  221. #region Parcel Add/Remove/Get/Create
  222. public void EventManagerOnSetAllowedForcefulBan(bool forceful)
  223. {
  224. AllowedForcefulBans = forceful;
  225. }
  226. public void UpdateLandObject(int local_id, LandData data)
  227. {
  228. LandData newData = data.Copy();
  229. newData.LocalID = local_id;
  230. ILandObject land;
  231. lock (m_landList)
  232. {
  233. if (m_landList.TryGetValue(local_id, out land))
  234. land.LandData = newData;
  235. }
  236. if (land != null)
  237. m_scene.EventManager.TriggerLandObjectUpdated((uint)local_id, land);
  238. }
  239. public bool AllowedForcefulBans
  240. {
  241. get { return m_allowedForcefulBans; }
  242. set { m_allowedForcefulBans = value; }
  243. }
  244. /// <summary>
  245. /// Resets the sim to the default land object (full sim piece of land owned by the default user)
  246. /// </summary>
  247. public void ResetSimLandObjects()
  248. {
  249. //Remove all the land objects in the sim and add a blank, full sim land object set to public
  250. lock (m_landList)
  251. {
  252. m_landList.Clear();
  253. m_lastLandLocalID = LandChannel.START_LAND_LOCAL_ID - 1;
  254. m_landIDList.Initialize();
  255. }
  256. }
  257. /// <summary>
  258. /// Create a default parcel that spans the entire region and is owned by the estate owner.
  259. /// </summary>
  260. /// <returns>The parcel created.</returns>
  261. protected ILandObject CreateDefaultParcel()
  262. {
  263. m_log.DebugFormat(
  264. "[LAND MANAGEMENT MODULE]: Creating default parcel for region {0}", m_scene.RegionInfo.RegionName);
  265. ILandObject fullSimParcel = new LandObject(UUID.Zero, false, m_scene);
  266. fullSimParcel.SetLandBitmap(fullSimParcel.GetSquareLandBitmap(0, 0, (int)Constants.RegionSize, (int)Constants.RegionSize));
  267. fullSimParcel.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  268. fullSimParcel.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
  269. return AddLandObject(fullSimParcel);
  270. }
  271. public List<ILandObject> AllParcels()
  272. {
  273. lock (m_landList)
  274. {
  275. return new List<ILandObject>(m_landList.Values);
  276. }
  277. }
  278. public List<ILandObject> ParcelsNearPoint(Vector3 position)
  279. {
  280. List<ILandObject> parcelsNear = new List<ILandObject>();
  281. for (int x = -4; x <= 4; x += 4)
  282. {
  283. for (int y = -4; y <= 4; y += 4)
  284. {
  285. ILandObject check = GetLandObject(position.X + x, position.Y + y);
  286. if (check != null)
  287. {
  288. if (!parcelsNear.Contains(check))
  289. {
  290. parcelsNear.Add(check);
  291. }
  292. }
  293. }
  294. }
  295. return parcelsNear;
  296. }
  297. public void SendYouAreBannedNotice(ScenePresence avatar)
  298. {
  299. if (AllowedForcefulBans)
  300. {
  301. avatar.ControllingClient.SendAlertMessage(
  302. "You are not allowed on this parcel because you are banned. Please go away.");
  303. }
  304. else
  305. {
  306. avatar.ControllingClient.SendAlertMessage(
  307. "You are not allowed on this parcel because you are banned; however, the grid administrator has disabled ban lines globally. Please obey the land owner's requests or you can be banned from the entire sim!");
  308. }
  309. }
  310. private void ForceAvatarToPosition(ScenePresence avatar, Vector3? position)
  311. {
  312. if (m_scene.Permissions.IsGod(avatar.UUID)) return;
  313. if (position.HasValue)
  314. {
  315. forcedPosition[avatar.ControllingClient.AgentId] = (Vector3)position;
  316. }
  317. }
  318. public void SendYouAreRestrictedNotice(ScenePresence avatar)
  319. {
  320. avatar.ControllingClient.SendAlertMessage(
  321. "You are not allowed on this parcel because the land owner has restricted access.");
  322. }
  323. public void EventManagerOnAvatarEnteringNewParcel(ScenePresence avatar, int localLandID, UUID regionID)
  324. {
  325. if (m_scene.RegionInfo.RegionID == regionID)
  326. {
  327. ILandObject parcelAvatarIsEntering;
  328. lock (m_landList)
  329. {
  330. parcelAvatarIsEntering = m_landList[localLandID];
  331. }
  332. if (parcelAvatarIsEntering != null)
  333. {
  334. if (avatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT)
  335. {
  336. if (parcelAvatarIsEntering.IsBannedFromLand(avatar.UUID))
  337. {
  338. SendYouAreBannedNotice(avatar);
  339. ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
  340. }
  341. else if (parcelAvatarIsEntering.IsRestrictedFromLand(avatar.UUID))
  342. {
  343. SendYouAreRestrictedNotice(avatar);
  344. ForceAvatarToPosition(avatar, m_scene.GetNearestAllowedPosition(avatar));
  345. }
  346. else
  347. {
  348. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  349. }
  350. }
  351. else
  352. {
  353. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  354. }
  355. }
  356. }
  357. }
  358. public void SendOutNearestBanLine(IClientAPI client)
  359. {
  360. ScenePresence sp = m_scene.GetScenePresence(client.AgentId);
  361. if (sp == null || sp.IsChildAgent)
  362. return;
  363. List<ILandObject> checkLandParcels = ParcelsNearPoint(sp.AbsolutePosition);
  364. foreach (ILandObject checkBan in checkLandParcels)
  365. {
  366. if (checkBan.IsBannedFromLand(client.AgentId))
  367. {
  368. checkBan.SendLandProperties((int)ParcelPropertiesStatus.CollisionBanned, false, (int)ParcelResult.Single, client);
  369. return; //Only send one
  370. }
  371. if (checkBan.IsRestrictedFromLand(client.AgentId))
  372. {
  373. checkBan.SendLandProperties((int)ParcelPropertiesStatus.CollisionNotOnAccessList, false, (int)ParcelResult.Single, client);
  374. return; //Only send one
  375. }
  376. }
  377. return;
  378. }
  379. public void SendLandUpdate(ScenePresence avatar, bool force)
  380. {
  381. ILandObject over = GetLandObject((int)Math.Min(((int)Constants.RegionSize - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
  382. (int)Math.Min(((int)Constants.RegionSize - 1), Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
  383. if (over != null)
  384. {
  385. if (force)
  386. {
  387. if (!avatar.IsChildAgent)
  388. {
  389. over.SendLandUpdateToClient(avatar.ControllingClient);
  390. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
  391. m_scene.RegionInfo.RegionID);
  392. }
  393. }
  394. if (avatar.currentParcelUUID != over.LandData.GlobalID)
  395. {
  396. if (!avatar.IsChildAgent)
  397. {
  398. over.SendLandUpdateToClient(avatar.ControllingClient);
  399. avatar.currentParcelUUID = over.LandData.GlobalID;
  400. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.LandData.LocalID,
  401. m_scene.RegionInfo.RegionID);
  402. }
  403. }
  404. }
  405. }
  406. public void SendLandUpdate(ScenePresence avatar)
  407. {
  408. SendLandUpdate(avatar, false);
  409. }
  410. public void EventManagerOnSignificantClientMovement(ScenePresence clientAvatar)
  411. {
  412. SendLandUpdate(clientAvatar);
  413. SendOutNearestBanLine(clientAvatar.ControllingClient);
  414. ILandObject parcel = GetLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
  415. if (parcel != null)
  416. {
  417. if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  418. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
  419. {
  420. EventManagerOnAvatarEnteringNewParcel(clientAvatar, parcel.LandData.LocalID,
  421. m_scene.RegionInfo.RegionID);
  422. //They are going under the safety line!
  423. if (!parcel.IsBannedFromLand(clientAvatar.UUID))
  424. {
  425. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
  426. }
  427. }
  428. else if (clientAvatar.AbsolutePosition.Z < LandChannel.BAN_LINE_SAFETY_HIEGHT &&
  429. parcel.IsBannedFromLand(clientAvatar.UUID))
  430. {
  431. //once we've sent the message once, keep going toward the target until we are done
  432. if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
  433. {
  434. SendYouAreBannedNotice(clientAvatar);
  435. ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
  436. }
  437. }
  438. else if (parcel.IsRestrictedFromLand(clientAvatar.UUID))
  439. {
  440. //once we've sent the message once, keep going toward the target until we are done
  441. if (forcedPosition.ContainsKey(clientAvatar.ControllingClient.AgentId))
  442. {
  443. SendYouAreRestrictedNotice(clientAvatar);
  444. ForceAvatarToPosition(clientAvatar, m_scene.GetNearestAllowedPosition(clientAvatar));
  445. }
  446. }
  447. else
  448. {
  449. //when we are finally in a safe place, lets release the forced position lock
  450. forcedPosition.Remove(clientAvatar.ControllingClient.AgentId);
  451. }
  452. }
  453. }
  454. /// <summary>
  455. /// Like handleEventManagerOnSignificantClientMovement, but called with an AgentUpdate regardless of distance.
  456. /// </summary>
  457. /// <param name="avatar"></param>
  458. public void EventManagerOnClientMovement(ScenePresence avatar)
  459. //
  460. {
  461. ILandObject over = GetLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  462. if (over != null)
  463. {
  464. if (!over.IsRestrictedFromLand(avatar.UUID) && (!over.IsBannedFromLand(avatar.UUID) || avatar.AbsolutePosition.Z >= LandChannel.BAN_LINE_SAFETY_HIEGHT))
  465. {
  466. avatar.lastKnownAllowedPosition =
  467. new Vector3(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
  468. }
  469. }
  470. }
  471. public void ClientOnParcelAccessListRequest(UUID agentID, UUID sessionID, uint flags, int sequenceID,
  472. int landLocalID, IClientAPI remote_client)
  473. {
  474. ILandObject land;
  475. lock (m_landList)
  476. {
  477. m_landList.TryGetValue(landLocalID, out land);
  478. }
  479. if (land != null)
  480. {
  481. land.SendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
  482. }
  483. }
  484. public void ClientOnParcelAccessListUpdateRequest(UUID agentID,
  485. uint flags, int landLocalID, UUID transactionID, int sequenceID,
  486. int sections, List<LandAccessEntry> entries,
  487. IClientAPI remote_client)
  488. {
  489. // Flags is the list to update, it can mean either the ban or
  490. // the access list (WTH is a pass list? Mentioned in ParcelFlags)
  491. //
  492. // There may be multiple packets, because these can get LONG.
  493. // Use transactionID to determine a new chain of packets since
  494. // packets may have come in out of sequence and that would be
  495. // a big mess if using the sequenceID
  496. ILandObject land;
  497. lock (m_landList)
  498. {
  499. m_landList.TryGetValue(landLocalID, out land);
  500. }
  501. if (land != null)
  502. {
  503. GroupPowers requiredPowers = GroupPowers.LandManageAllowed;
  504. if (flags == (uint)AccessList.Ban)
  505. requiredPowers = GroupPowers.LandManageBanned;
  506. if (m_scene.Permissions.CanEditParcelProperties(agentID,
  507. land, requiredPowers))
  508. {
  509. land.UpdateAccessList(flags, transactionID, sequenceID,
  510. sections, entries, remote_client);
  511. }
  512. }
  513. else
  514. {
  515. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid local land ID {0}", landLocalID);
  516. }
  517. }
  518. /// <summary>
  519. /// Adds a land object to the stored list and adds them to the landIDList to what they own
  520. /// </summary>
  521. /// <param name="new_land">The land object being added</param>
  522. public ILandObject AddLandObject(ILandObject land)
  523. {
  524. ILandObject new_land = land.Copy();
  525. // Only now can we add the prim counts to the land object - we rely on the global ID which is generated
  526. // as a random UUID inside LandData initialization
  527. if (m_primCountModule != null)
  528. new_land.PrimCounts = m_primCountModule.GetPrimCounts(new_land.LandData.GlobalID);
  529. lock (m_landList)
  530. {
  531. int newLandLocalID = ++m_lastLandLocalID;
  532. new_land.LandData.LocalID = newLandLocalID;
  533. bool[,] landBitmap = new_land.GetLandBitmap();
  534. for (int x = 0; x < landArrayMax; x++)
  535. {
  536. for (int y = 0; y < landArrayMax; y++)
  537. {
  538. if (landBitmap[x, y])
  539. {
  540. // m_log.DebugFormat(
  541. // "[LAND MANAGEMENT MODULE]: Registering parcel {0} for land co-ord ({1}, {2}) on {3}",
  542. // new_land.LandData.Name, x, y, m_scene.RegionInfo.RegionName);
  543. m_landIDList[x, y] = newLandLocalID;
  544. }
  545. }
  546. }
  547. m_landList.Add(newLandLocalID, new_land);
  548. }
  549. new_land.ForceUpdateLandInfo();
  550. m_scene.EventManager.TriggerLandObjectAdded(new_land);
  551. return new_land;
  552. }
  553. /// <summary>
  554. /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
  555. /// </summary>
  556. /// <param name="local_id">Land.localID of the peice of land to remove.</param>
  557. public void removeLandObject(int local_id)
  558. {
  559. ILandObject land;
  560. lock (m_landList)
  561. {
  562. for (int x = 0; x < 64; x++)
  563. {
  564. for (int y = 0; y < 64; y++)
  565. {
  566. if (m_landIDList[x, y] == local_id)
  567. {
  568. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Not removing land object {0}; still being used at {1}, {2}",
  569. local_id, x, y);
  570. return;
  571. //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
  572. }
  573. }
  574. }
  575. land = m_landList[local_id];
  576. m_landList.Remove(local_id);
  577. }
  578. m_scene.EventManager.TriggerLandObjectRemoved(land.LandData.GlobalID);
  579. }
  580. /// <summary>
  581. /// Clear the scene of all parcels
  582. /// </summary>
  583. public void Clear(bool setupDefaultParcel)
  584. {
  585. List<ILandObject> parcels;
  586. lock (m_landList)
  587. {
  588. parcels = new List<ILandObject>(m_landList.Values);
  589. }
  590. foreach (ILandObject lo in parcels)
  591. {
  592. //m_scene.SimulationDataService.RemoveLandObject(lo.LandData.GlobalID);
  593. m_scene.EventManager.TriggerLandObjectRemoved(lo.LandData.GlobalID);
  594. }
  595. lock (m_landList)
  596. {
  597. m_landList.Clear();
  598. ResetSimLandObjects();
  599. }
  600. if (setupDefaultParcel)
  601. CreateDefaultParcel();
  602. }
  603. private void performFinalLandJoin(ILandObject master, ILandObject slave)
  604. {
  605. bool[,] landBitmapSlave = slave.GetLandBitmap();
  606. lock (m_landList)
  607. {
  608. for (int x = 0; x < 64; x++)
  609. {
  610. for (int y = 0; y < 64; y++)
  611. {
  612. if (landBitmapSlave[x, y])
  613. {
  614. m_landIDList[x, y] = master.LandData.LocalID;
  615. }
  616. }
  617. }
  618. }
  619. removeLandObject(slave.LandData.LocalID);
  620. UpdateLandObject(master.LandData.LocalID, master.LandData);
  621. }
  622. public ILandObject GetLandObject(int parcelLocalID)
  623. {
  624. lock (m_landList)
  625. {
  626. if (m_landList.ContainsKey(parcelLocalID))
  627. {
  628. return m_landList[parcelLocalID];
  629. }
  630. }
  631. return null;
  632. }
  633. /// <summary>
  634. /// Get the land object at the specified point
  635. /// </summary>
  636. /// <param name="x_float">Value between 0 - 256 on the x axis of the point</param>
  637. /// <param name="y_float">Value between 0 - 256 on the y axis of the point</param>
  638. /// <returns>Land object at the point supplied</returns>
  639. public ILandObject GetLandObject(float x_float, float y_float)
  640. {
  641. int x;
  642. int y;
  643. if (x_float >= Constants.RegionSize || x_float < 0 || y_float >= Constants.RegionSize || y_float < 0)
  644. return null;
  645. try
  646. {
  647. x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / 4.0));
  648. y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / 4.0));
  649. }
  650. catch (OverflowException)
  651. {
  652. return null;
  653. }
  654. if (x >= 64 || y >= 64 || x < 0 || y < 0)
  655. {
  656. return null;
  657. }
  658. lock (m_landList)
  659. {
  660. // Corner case. If an autoreturn happens during sim startup
  661. // we will come here with the list uninitialized
  662. //
  663. // int landId = m_landIDList[x, y];
  664. // if (landId == 0)
  665. // m_log.DebugFormat(
  666. // "[LAND MANAGEMENT MODULE]: No land object found at ({0}, {1}) on {2}",
  667. // x, y, m_scene.RegionInfo.RegionName);
  668. if (m_landList.ContainsKey(m_landIDList[x, y]))
  669. return m_landList[m_landIDList[x, y]];
  670. return null;
  671. }
  672. }
  673. public ILandObject GetLandObject(int x, int y)
  674. {
  675. if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0)
  676. {
  677. // These exceptions here will cause a lot of complaints from the users specifically because
  678. // they happen every time at border crossings
  679. throw new Exception("Error: Parcel not found at point " + x + ", " + y);
  680. }
  681. lock (m_landIDList)
  682. {
  683. try
  684. {
  685. return m_landList[m_landIDList[x / 4, y / 4]];
  686. }
  687. catch (IndexOutOfRangeException)
  688. {
  689. // m_log.WarnFormat(
  690. // "[LAND MANAGEMENT MODULE]: Tried to retrieve land object from out of bounds co-ordinate ({0},{1}) in {2}",
  691. // x, y, m_scene.RegionInfo.RegionName);
  692. return null;
  693. }
  694. }
  695. }
  696. #endregion
  697. #region Parcel Modification
  698. public void ResetOverMeRecords()
  699. {
  700. lock (m_landList)
  701. {
  702. foreach (LandObject p in m_landList.Values)
  703. {
  704. p.ResetOverMeRecord();
  705. }
  706. }
  707. }
  708. public void EventManagerOnParcelPrimCountAdd(SceneObjectGroup obj)
  709. {
  710. Vector3 position = obj.AbsolutePosition;
  711. ILandObject landUnderPrim = GetLandObject(position.X, position.Y);
  712. if (landUnderPrim != null)
  713. {
  714. ((LandObject)landUnderPrim).AddPrimOverMe(obj);
  715. }
  716. }
  717. public void EventManagerOnObjectBeingRemovedFromScene(SceneObjectGroup obj)
  718. {
  719. lock (m_landList)
  720. {
  721. foreach (LandObject p in m_landList.Values)
  722. {
  723. p.RemovePrimFromOverMe(obj);
  724. }
  725. }
  726. }
  727. public void FinalizeLandPrimCountUpdate()
  728. {
  729. //Get Simwide prim count for owner
  730. Dictionary<UUID, List<LandObject>> landOwnersAndParcels = new Dictionary<UUID, List<LandObject>>();
  731. lock (m_landList)
  732. {
  733. foreach (LandObject p in m_landList.Values)
  734. {
  735. if (!landOwnersAndParcels.ContainsKey(p.LandData.OwnerID))
  736. {
  737. List<LandObject> tempList = new List<LandObject>();
  738. tempList.Add(p);
  739. landOwnersAndParcels.Add(p.LandData.OwnerID, tempList);
  740. }
  741. else
  742. {
  743. landOwnersAndParcels[p.LandData.OwnerID].Add(p);
  744. }
  745. }
  746. }
  747. foreach (UUID owner in landOwnersAndParcels.Keys)
  748. {
  749. int simArea = 0;
  750. int simPrims = 0;
  751. foreach (LandObject p in landOwnersAndParcels[owner])
  752. {
  753. simArea += p.LandData.Area;
  754. simPrims += p.PrimCounts.Total;
  755. }
  756. foreach (LandObject p in landOwnersAndParcels[owner])
  757. {
  758. p.LandData.SimwideArea = simArea;
  759. p.LandData.SimwidePrims = simPrims;
  760. }
  761. }
  762. }
  763. public void EventManagerOnParcelPrimCountUpdate()
  764. {
  765. // m_log.DebugFormat(
  766. // "[LAND MANAGEMENT MODULE]: Triggered EventManagerOnParcelPrimCountUpdate() for {0}",
  767. // m_scene.RegionInfo.RegionName);
  768. ResetOverMeRecords();
  769. EntityBase[] entities = m_scene.Entities.GetEntities();
  770. foreach (EntityBase obj in entities)
  771. {
  772. if (obj != null)
  773. {
  774. if ((obj is SceneObjectGroup) && !obj.IsDeleted && !((SceneObjectGroup) obj).IsAttachment)
  775. {
  776. m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj);
  777. }
  778. }
  779. }
  780. FinalizeLandPrimCountUpdate();
  781. }
  782. public void EventManagerOnRequestParcelPrimCountUpdate()
  783. {
  784. ResetOverMeRecords();
  785. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  786. FinalizeLandPrimCountUpdate();
  787. }
  788. /// <summary>
  789. /// Subdivides a piece of land
  790. /// </summary>
  791. /// <param name="start_x">West Point</param>
  792. /// <param name="start_y">South Point</param>
  793. /// <param name="end_x">East Point</param>
  794. /// <param name="end_y">North Point</param>
  795. /// <param name="attempting_user_id">UUID of user who is trying to subdivide</param>
  796. /// <returns>Returns true if successful</returns>
  797. private void subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  798. {
  799. //First, lets loop through the points and make sure they are all in the same peice of land
  800. //Get the land object at start
  801. ILandObject startLandObject = GetLandObject(start_x, start_y);
  802. if (startLandObject == null) return;
  803. //Loop through the points
  804. try
  805. {
  806. int totalX = end_x - start_x;
  807. int totalY = end_y - start_y;
  808. for (int y = 0; y < totalY; y++)
  809. {
  810. for (int x = 0; x < totalX; x++)
  811. {
  812. ILandObject tempLandObject = GetLandObject(start_x + x, start_y + y);
  813. if (tempLandObject == null) return;
  814. if (tempLandObject != startLandObject) return;
  815. }
  816. }
  817. }
  818. catch (Exception)
  819. {
  820. return;
  821. }
  822. //If we are still here, then they are subdividing within one piece of land
  823. //Check owner
  824. if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, startLandObject, GroupPowers.LandDivideJoin))
  825. {
  826. return;
  827. }
  828. //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
  829. ILandObject newLand = startLandObject.Copy();
  830. newLand.LandData.Name = newLand.LandData.Name;
  831. newLand.LandData.GlobalID = UUID.Random();
  832. newLand.LandData.Dwell = 0;
  833. newLand.SetLandBitmap(newLand.GetSquareLandBitmap(start_x, start_y, end_x, end_y));
  834. //Now, lets set the subdivision area of the original to false
  835. int startLandObjectIndex = startLandObject.LandData.LocalID;
  836. lock (m_landList)
  837. {
  838. m_landList[startLandObjectIndex].SetLandBitmap(
  839. newLand.ModifyLandBitmapSquare(startLandObject.GetLandBitmap(), start_x, start_y, end_x, end_y, false));
  840. m_landList[startLandObjectIndex].ForceUpdateLandInfo();
  841. }
  842. //Now add the new land object
  843. ILandObject result = AddLandObject(newLand);
  844. UpdateLandObject(startLandObject.LandData.LocalID, startLandObject.LandData);
  845. result.SendLandUpdateToAvatarsOverMe();
  846. }
  847. /// <summary>
  848. /// Join 2 land objects together
  849. /// </summary>
  850. /// <param name="start_x">x value in first piece of land</param>
  851. /// <param name="start_y">y value in first piece of land</param>
  852. /// <param name="end_x">x value in second peice of land</param>
  853. /// <param name="end_y">y value in second peice of land</param>
  854. /// <param name="attempting_user_id">UUID of the avatar trying to join the land objects</param>
  855. /// <returns>Returns true if successful</returns>
  856. private void join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  857. {
  858. end_x -= 4;
  859. end_y -= 4;
  860. List<ILandObject> selectedLandObjects = new List<ILandObject>();
  861. int stepYSelected;
  862. for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
  863. {
  864. int stepXSelected;
  865. for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
  866. {
  867. ILandObject p = GetLandObject(stepXSelected, stepYSelected);
  868. if (p != null)
  869. {
  870. if (!selectedLandObjects.Contains(p))
  871. {
  872. selectedLandObjects.Add(p);
  873. }
  874. }
  875. }
  876. }
  877. ILandObject masterLandObject = selectedLandObjects[0];
  878. selectedLandObjects.RemoveAt(0);
  879. if (selectedLandObjects.Count < 1)
  880. {
  881. return;
  882. }
  883. if (!m_scene.Permissions.CanEditParcelProperties(attempting_user_id, masterLandObject, GroupPowers.LandDivideJoin))
  884. {
  885. return;
  886. }
  887. foreach (ILandObject p in selectedLandObjects)
  888. {
  889. if (p.LandData.OwnerID != masterLandObject.LandData.OwnerID)
  890. {
  891. return;
  892. }
  893. }
  894. lock (m_landList)
  895. {
  896. foreach (ILandObject slaveLandObject in selectedLandObjects)
  897. {
  898. m_landList[masterLandObject.LandData.LocalID].SetLandBitmap(
  899. slaveLandObject.MergeLandBitmaps(masterLandObject.GetLandBitmap(), slaveLandObject.GetLandBitmap()));
  900. performFinalLandJoin(masterLandObject, slaveLandObject);
  901. }
  902. }
  903. masterLandObject.SendLandUpdateToAvatarsOverMe();
  904. }
  905. public void Join(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  906. {
  907. join(start_x, start_y, end_x, end_y, attempting_user_id);
  908. }
  909. public void Subdivide(int start_x, int start_y, int end_x, int end_y, UUID attempting_user_id)
  910. {
  911. subdivide(start_x, start_y, end_x, end_y, attempting_user_id);
  912. }
  913. #endregion
  914. #region Parcel Updating
  915. /// <summary>
  916. /// Where we send the ParcelOverlay packet to the client
  917. /// </summary>
  918. /// <param name="remote_client">The object representing the client</param>
  919. public void SendParcelOverlay(IClientAPI remote_client)
  920. {
  921. const int LAND_BLOCKS_PER_PACKET = 1024;
  922. byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  923. int byteArrayCount = 0;
  924. int sequenceID = 0;
  925. int blockmeters = 4 * (int) Constants.RegionSize/(int)Constants.TerrainPatchSize;
  926. for (int y = 0; y < blockmeters; y++)
  927. {
  928. for (int x = 0; x < blockmeters; x++)
  929. {
  930. byte tempByte = 0; //This represents the byte for the current 4x4
  931. ILandObject currentParcelBlock = GetLandObject(x * 4, y * 4);
  932. if (currentParcelBlock != null)
  933. {
  934. if (currentParcelBlock.LandData.OwnerID == remote_client.AgentId)
  935. {
  936. //Owner Flag
  937. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_REQUESTER);
  938. }
  939. else if (currentParcelBlock.LandData.SalePrice > 0 &&
  940. (currentParcelBlock.LandData.AuthBuyerID == UUID.Zero ||
  941. currentParcelBlock.LandData.AuthBuyerID == remote_client.AgentId))
  942. {
  943. //Sale Flag
  944. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_IS_FOR_SALE);
  945. }
  946. else if (currentParcelBlock.LandData.OwnerID == UUID.Zero)
  947. {
  948. //Public Flag
  949. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_PUBLIC);
  950. }
  951. else
  952. {
  953. //Other Flag
  954. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_TYPE_OWNED_BY_OTHER);
  955. }
  956. //Now for border control
  957. ILandObject westParcel = null;
  958. ILandObject southParcel = null;
  959. if (x > 0)
  960. {
  961. westParcel = GetLandObject((x - 1) * 4, y * 4);
  962. }
  963. if (y > 0)
  964. {
  965. southParcel = GetLandObject(x * 4, (y - 1) * 4);
  966. }
  967. if (x == 0)
  968. {
  969. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  970. }
  971. else if (westParcel != null && westParcel != currentParcelBlock)
  972. {
  973. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_WEST);
  974. }
  975. if (y == 0)
  976. {
  977. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  978. }
  979. else if (southParcel != null && southParcel != currentParcelBlock)
  980. {
  981. tempByte = Convert.ToByte(tempByte | LandChannel.LAND_FLAG_PROPERTY_BORDER_SOUTH);
  982. }
  983. byteArray[byteArrayCount] = tempByte;
  984. byteArrayCount++;
  985. if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
  986. {
  987. remote_client.SendLandParcelOverlay(byteArray, sequenceID);
  988. byteArrayCount = 0;
  989. sequenceID++;
  990. byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  991. }
  992. }
  993. }
  994. }
  995. }
  996. public void ClientOnParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
  997. bool snap_selection, IClientAPI remote_client)
  998. {
  999. //Get the land objects within the bounds
  1000. List<ILandObject> temp = new List<ILandObject>();
  1001. int inc_x = end_x - start_x;
  1002. int inc_y = end_y - start_y;
  1003. for (int x = 0; x < inc_x; x++)
  1004. {
  1005. for (int y = 0; y < inc_y; y++)
  1006. {
  1007. ILandObject currentParcel = GetLandObject(start_x + x, start_y + y);
  1008. if (currentParcel != null)
  1009. {
  1010. if (!temp.Contains(currentParcel))
  1011. {
  1012. currentParcel.ForceUpdateLandInfo();
  1013. temp.Add(currentParcel);
  1014. }
  1015. }
  1016. }
  1017. }
  1018. int requestResult = LandChannel.LAND_RESULT_SINGLE;
  1019. if (temp.Count > 1)
  1020. {
  1021. requestResult = LandChannel.LAND_RESULT_MULTIPLE;
  1022. }
  1023. for (int i = 0; i < temp.Count; i++)
  1024. {
  1025. temp[i].SendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
  1026. }
  1027. SendParcelOverlay(remote_client);
  1028. }
  1029. public void ClientOnParcelPropertiesUpdateRequest(LandUpdateArgs args, int localID, IClientAPI remote_client)
  1030. {
  1031. ILandObject land;
  1032. lock (m_landList)
  1033. {
  1034. m_landList.TryGetValue(localID, out land);
  1035. }
  1036. if (land != null)
  1037. {
  1038. land.UpdateLandProperties(args, remote_client);
  1039. m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(args, localID, remote_client);
  1040. }
  1041. }
  1042. public void ClientOnParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
  1043. {
  1044. subdivide(west, south, east, north, remote_client.AgentId);
  1045. }
  1046. public void ClientOnParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
  1047. {
  1048. join(west, south, east, north, remote_client.AgentId);
  1049. }
  1050. public void ClientOnParcelSelectObjects(int local_id, int request_type,
  1051. List<UUID> returnIDs, IClientAPI remote_client)
  1052. {
  1053. m_landList[local_id].SendForceObjectSelect(local_id, request_type, returnIDs, remote_client);
  1054. }
  1055. public void ClientOnParcelObjectOwnerRequest(int local_id, IClientAPI remote_client)
  1056. {
  1057. ILandObject land;
  1058. lock (m_landList)
  1059. {
  1060. m_landList.TryGetValue(local_id, out land);
  1061. }
  1062. if (land != null)
  1063. {
  1064. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  1065. m_landList[local_id].SendLandObjectOwners(remote_client);
  1066. }
  1067. else
  1068. {
  1069. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Invalid land object {0} passed for parcel object owner request", local_id);
  1070. }
  1071. }
  1072. public void ClientOnParcelGodForceOwner(int local_id, UUID ownerID, IClientAPI remote_client)
  1073. {
  1074. ILandObject land;
  1075. lock (m_landList)
  1076. {
  1077. m_landList.TryGetValue(local_id, out land);
  1078. }
  1079. if (land != null)
  1080. {
  1081. if (m_scene.Permissions.IsGod(remote_client.AgentId))
  1082. {
  1083. land.LandData.OwnerID = ownerID;
  1084. land.LandData.GroupID = UUID.Zero;
  1085. land.LandData.IsGroupOwned = false;
  1086. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1087. m_scene.ForEachClient(SendParcelOverlay);
  1088. land.SendLandUpdateToClient(true, remote_client);
  1089. }
  1090. }
  1091. }
  1092. public void ClientOnParcelAbandonRequest(int local_id, IClientAPI remote_client)
  1093. {
  1094. ILandObject land;
  1095. lock (m_landList)
  1096. {
  1097. m_landList.TryGetValue(local_id, out land);
  1098. }
  1099. if (land != null)
  1100. {
  1101. if (m_scene.Permissions.CanAbandonParcel(remote_client.AgentId, land))
  1102. {
  1103. land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  1104. land.LandData.GroupID = UUID.Zero;
  1105. land.LandData.IsGroupOwned = false;
  1106. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1107. m_scene.ForEachClient(SendParcelOverlay);
  1108. land.SendLandUpdateToClient(true, remote_client);
  1109. }
  1110. }
  1111. }
  1112. public void ClientOnParcelReclaim(int local_id, IClientAPI remote_client)
  1113. {
  1114. ILandObject land;
  1115. lock (m_landList)
  1116. {
  1117. m_landList.TryGetValue(local_id, out land);
  1118. }
  1119. if (land != null)
  1120. {
  1121. if (m_scene.Permissions.CanReclaimParcel(remote_client.AgentId, land))
  1122. {
  1123. land.LandData.OwnerID = m_scene.RegionInfo.EstateSettings.EstateOwner;
  1124. land.LandData.ClaimDate = Util.UnixTimeSinceEpoch();
  1125. land.LandData.GroupID = UUID.Zero;
  1126. land.LandData.IsGroupOwned = false;
  1127. land.LandData.SalePrice = 0;
  1128. land.LandData.AuthBuyerID = UUID.Zero;
  1129. land.LandData.Flags &= ~(uint) (ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects | ParcelFlags.ShowDirectory);
  1130. m_scene.ForEachClient(SendParcelOverlay);
  1131. land.SendLandUpdateToClient(true, remote_client);
  1132. }
  1133. }
  1134. }
  1135. #endregion
  1136. // If the economy has been validated by the economy module,
  1137. // and land has been validated as well, this method transfers
  1138. // the land ownership
  1139. public void EventManagerOnLandBuy(Object o, EventManager.LandBuyArgs e)
  1140. {
  1141. if (e.economyValidated && e.landValidated)
  1142. {
  1143. ILandObject land;
  1144. lock (m_landList)
  1145. {
  1146. m_landList.TryGetValue(e.parcelLocalID, out land);
  1147. }
  1148. if (land != null)
  1149. {
  1150. land.UpdateLandSold(e.agentId, e.groupId, e.groupOwned, (uint)e.transactionID, e.parcelPrice, e.parcelArea);
  1151. }
  1152. }
  1153. }
  1154. // After receiving a land buy packet, first the data needs to
  1155. // be validated. This method validates the right to buy the
  1156. // parcel
  1157. public void EventManagerOnValidateLandBuy(Object o, EventManager.LandBuyArgs e)
  1158. {
  1159. if (e.landValidated == false)
  1160. {
  1161. ILandObject lob = null;
  1162. lock (m_landList)
  1163. {
  1164. m_landList.TryGetValue(e.parcelLocalID, out lob);
  1165. }
  1166. if (lob != null)
  1167. {
  1168. UUID AuthorizedID = lob.LandData.AuthBuyerID;
  1169. int saleprice = lob.LandData.SalePrice;
  1170. UUID pOwnerID = lob.LandData.OwnerID;
  1171. bool landforsale = ((lob.LandData.Flags &
  1172. (uint)(ParcelFlags.ForSale | ParcelFlags.ForSaleObjects | ParcelFlags.SellParcelObjects)) != 0);
  1173. if ((AuthorizedID == UUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
  1174. {
  1175. // TODO I don't think we have to lock it here, no?
  1176. //lock (e)
  1177. //{
  1178. e.parcelOwnerID = pOwnerID;
  1179. e.landValidated = true;
  1180. //}
  1181. }
  1182. }
  1183. }
  1184. }
  1185. void ClientOnParcelDeedToGroup(int parcelLocalID, UUID groupID, IClientAPI remote_client)
  1186. {
  1187. ILandObject land;
  1188. lock (m_landList)
  1189. {
  1190. m_landList.TryGetValue(parcelLocalID, out land);
  1191. }
  1192. if (!m_scene.Permissions.CanDeedParcel(remote_client.AgentId, land))
  1193. return;
  1194. if (land != null)
  1195. {
  1196. land.DeedToGroup(groupID);
  1197. }
  1198. }
  1199. #region Land Object From Storage Functions
  1200. public void EventManagerOnIncomingLandDataFromStorage(List<LandData> data)
  1201. {
  1202. // m_log.DebugFormat(
  1203. // "[LAND MANAGMENT MODULE]: Processing {0} incoming parcels on {1}", data.Count, m_scene.Name);
  1204. for (int i = 0; i < data.Count; i++)
  1205. IncomingLandObjectFromStorage(data[i]);
  1206. }
  1207. public void IncomingLandObjectFromStorage(LandData data)
  1208. {
  1209. ILandObject new_land = new LandObject(data.OwnerID, data.IsGroupOwned, m_scene);
  1210. new_land.LandData = data.Copy();
  1211. new_land.SetLandBitmapFromByteArray();
  1212. AddLandObject(new_land);
  1213. }
  1214. public void ReturnObjectsInParcel(int localID, uint returnType, UUID[] agentIDs, UUID[] taskIDs, IClientAPI remoteClient)
  1215. {
  1216. if (localID != -1)
  1217. {
  1218. ILandObject selectedParcel = null;
  1219. lock (m_landList)
  1220. {
  1221. m_landList.TryGetValue(localID, out selectedParcel);
  1222. }
  1223. if (selectedParcel == null)
  1224. return;
  1225. selectedParcel.ReturnLandObjects(returnType, agentIDs, taskIDs, remoteClient);
  1226. }
  1227. else
  1228. {
  1229. if (returnType != 1)
  1230. {
  1231. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown return type {0}", returnType);
  1232. return;
  1233. }
  1234. // We get here when the user returns objects from the list of Top Colliders or Top Scripts.
  1235. // In that case we receive specific object UUID's, but no parcel ID.
  1236. Dictionary<UUID, HashSet<SceneObjectGroup>> returns = new Dictionary<UUID, HashSet<SceneObjectGroup>>();
  1237. foreach (UUID groupID in taskIDs)
  1238. {
  1239. SceneObjectGroup obj = m_scene.GetSceneObjectGroup(groupID);
  1240. if (obj != null)
  1241. {
  1242. if (!returns.ContainsKey(obj.OwnerID))
  1243. returns[obj.OwnerID] = new HashSet<SceneObjectGroup>();
  1244. returns[obj.OwnerID].Add(obj);
  1245. }
  1246. else
  1247. {
  1248. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: unknown object {0}", groupID);
  1249. }
  1250. }
  1251. int num = 0;
  1252. foreach (HashSet<SceneObjectGroup> objs in returns.Values)
  1253. num += objs.Count;
  1254. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Returning {0} specific object(s)", num);
  1255. foreach (HashSet<SceneObjectGroup> objs in returns.Values)
  1256. {
  1257. List<SceneObjectGroup> objs2 = new List<SceneObjectGroup>(objs);
  1258. if (m_scene.Permissions.CanReturnObjects(null, remoteClient.AgentId, objs2))
  1259. {
  1260. m_scene.returnObjects(objs2.ToArray(), remoteClient.AgentId);
  1261. }
  1262. else
  1263. {
  1264. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: ReturnObjectsInParcel: not permitted to return {0} object(s) belonging to user {1}",
  1265. objs2.Count, objs2[0].OwnerID);
  1266. }
  1267. }
  1268. }
  1269. }
  1270. public void EventManagerOnNoLandDataFromStorage()
  1271. {
  1272. ResetSimLandObjects();
  1273. CreateDefaultParcel();
  1274. }
  1275. #endregion
  1276. public void setParcelObjectMaxOverride(overrideParcelMaxPrimCountDelegate overrideDel)
  1277. {
  1278. lock (m_landList)
  1279. {
  1280. foreach (LandObject obj in m_landList.Values)
  1281. {
  1282. obj.SetParcelObjectMaxOverride(overrideDel);
  1283. }
  1284. }
  1285. }
  1286. public void setSimulatorObjectMaxOverride(overrideSimulatorMaxPrimCountDelegate overrideDel)
  1287. {
  1288. }
  1289. #region CAPS handler
  1290. private void EventManagerOnRegisterCaps(UUID agentID, Caps caps)
  1291. {
  1292. string capsBase = "/CAPS/" + caps.CapsObjectPath;
  1293. caps.RegisterHandler(
  1294. "RemoteParcelRequest",
  1295. new RestStreamHandler(
  1296. "POST",
  1297. capsBase + remoteParcelRequestPath,
  1298. (request, path, param, httpRequest, httpResponse)
  1299. => RemoteParcelRequest(request, path, param, agentID, caps),
  1300. "RemoteParcelRequest",
  1301. agentID.ToString()));
  1302. UUID parcelCapID = UUID.Random();
  1303. caps.RegisterHandler(
  1304. "ParcelPropertiesUpdate",
  1305. new RestStreamHandler(
  1306. "POST",
  1307. "/CAPS/" + parcelCapID,
  1308. (request, path, param, httpRequest, httpResponse)
  1309. => ProcessPropertiesUpdate(request, path, param, agentID, caps),
  1310. "ParcelPropertiesUpdate",
  1311. agentID.ToString()));
  1312. }
  1313. private string ProcessPropertiesUpdate(string request, string path, string param, UUID agentID, Caps caps)
  1314. {
  1315. IClientAPI client;
  1316. if (!m_scene.TryGetClient(agentID, out client))
  1317. {
  1318. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to retrieve IClientAPI for {0}", agentID);
  1319. return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
  1320. }
  1321. ParcelPropertiesUpdateMessage properties = new ParcelPropertiesUpdateMessage();
  1322. OpenMetaverse.StructuredData.OSDMap args = (OpenMetaverse.StructuredData.OSDMap) OSDParser.DeserializeLLSDXml(request);
  1323. properties.Deserialize(args);
  1324. LandUpdateArgs land_update = new LandUpdateArgs();
  1325. int parcelID = properties.LocalID;
  1326. land_update.AuthBuyerID = properties.AuthBuyerID;
  1327. land_update.Category = properties.Category;
  1328. land_update.Desc = properties.Desc;
  1329. land_update.GroupID = properties.GroupID;
  1330. land_update.LandingType = (byte) properties.Landing;
  1331. land_update.MediaAutoScale = (byte) Convert.ToInt32(properties.MediaAutoScale);
  1332. land_update.MediaID = properties.MediaID;
  1333. land_update.MediaURL = properties.MediaURL;
  1334. land_update.MusicURL = properties.MusicURL;
  1335. land_update.Name = properties.Name;
  1336. land_update.ParcelFlags = (uint) properties.ParcelFlags;
  1337. land_update.PassHours = (int) properties.PassHours;
  1338. land_update.PassPrice = (int) properties.PassPrice;
  1339. land_update.SalePrice = (int) properties.SalePrice;
  1340. land_update.SnapshotID = properties.SnapshotID;
  1341. land_update.UserLocation = properties.UserLocation;
  1342. land_update.UserLookAt = properties.UserLookAt;
  1343. land_update.MediaDescription = properties.MediaDesc;
  1344. land_update.MediaType = properties.MediaType;
  1345. land_update.MediaWidth = properties.MediaWidth;
  1346. land_update.MediaHeight = properties.MediaHeight;
  1347. land_update.MediaLoop = properties.MediaLoop;
  1348. land_update.ObscureMusic = properties.ObscureMusic;
  1349. land_update.ObscureMedia = properties.ObscureMedia;
  1350. ILandObject land;
  1351. lock (m_landList)
  1352. {
  1353. m_landList.TryGetValue(parcelID, out land);
  1354. }
  1355. if (land != null)
  1356. {
  1357. land.UpdateLandProperties(land_update, client);
  1358. m_scene.EventManager.TriggerOnParcelPropertiesUpdateRequest(land_update, parcelID, client);
  1359. }
  1360. else
  1361. {
  1362. m_log.WarnFormat("[LAND MANAGEMENT MODULE]: Unable to find parcelID {0}", parcelID);
  1363. }
  1364. return LLSDHelpers.SerialiseLLSDReply(new LLSDEmpty());
  1365. }
  1366. // we cheat here: As we don't have (and want) a grid-global parcel-store, we can't return the
  1367. // "real" parcelID, because we wouldn't be able to map that to the region the parcel belongs to.
  1368. // So, we create a "fake" parcelID by using the regionHandle (64 bit), and the local (integer) x
  1369. // and y coordinate (each 8 bit), encoded in a UUID (128 bit).
  1370. //
  1371. // Request format:
  1372. // <llsd>
  1373. // <map>
  1374. // <key>location</key>
  1375. // <array>
  1376. // <real>1.23</real>
  1377. // <real>45..6</real>
  1378. // <real>78.9</real>
  1379. // </array>
  1380. // <key>region_id</key>
  1381. // <uuid>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</uuid>
  1382. // </map>
  1383. // </llsd>
  1384. private string RemoteParcelRequest(string request, string path, string param, UUID agentID, Caps caps)
  1385. {
  1386. UUID parcelID = UUID.Zero;
  1387. try
  1388. {
  1389. Hashtable hash = new Hashtable();
  1390. hash = (Hashtable)LLSD.LLSDDeserialize(Utils.StringToBytes(request));
  1391. if (hash.ContainsKey("region_id") && hash.ContainsKey("location"))
  1392. {
  1393. UUID regionID = (UUID)hash["region_id"];
  1394. ArrayList list = (ArrayList)hash["location"];
  1395. uint x = (uint)(double)list[0];
  1396. uint y = (uint)(double)list[1];
  1397. if (hash.ContainsKey("region_handle"))
  1398. {
  1399. // if you do a "About Landmark" on a landmark a second time, the viewer sends the
  1400. // region_handle it got earlier via RegionHandleRequest
  1401. ulong regionHandle = Util.BytesToUInt64Big((byte[])hash["region_handle"]);
  1402. parcelID = Util.BuildFakeParcelID(regionHandle, x, y);
  1403. }
  1404. else if (regionID == m_scene.RegionInfo.RegionID)
  1405. {
  1406. // a parcel request for a local parcel => no need to query the grid
  1407. parcelID = Util.BuildFakeParcelID(m_scene.RegionInfo.RegionHandle, x, y);
  1408. }
  1409. else
  1410. {
  1411. // a parcel request for a parcel in another region. Ask the grid about the region
  1412. GridRegion info = m_scene.GridService.GetRegionByUUID(UUID.Zero, regionID);
  1413. if (info != null)
  1414. parcelID = Util.BuildFakeParcelID(info.RegionHandle, x, y);
  1415. }
  1416. }
  1417. }
  1418. catch (LLSD.LLSDParseException e)
  1419. {
  1420. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Fetch error: {0}", e.Message);
  1421. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: ... in request {0}", request);
  1422. }
  1423. catch (InvalidCastException)
  1424. {
  1425. m_log.ErrorFormat("[LAND MANAGEMENT MODULE]: Wrong type in request {0}", request);
  1426. }
  1427. LLSDRemoteParcelResponse response = new LLSDRemoteParcelResponse();
  1428. response.parcel_id = parcelID;
  1429. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelID {0}", parcelID);
  1430. return LLSDHelpers.SerialiseLLSDReply(response);
  1431. }
  1432. #endregion
  1433. private void ClientOnParcelInfoRequest(IClientAPI remoteClient, UUID parcelID)
  1434. {
  1435. if (parcelID == UUID.Zero)
  1436. return;
  1437. ExtendedLandData data = (ExtendedLandData)parcelInfoCache.Get(parcelID.ToString(),
  1438. delegate(string id)
  1439. {
  1440. UUID parcel = UUID.Zero;
  1441. UUID.TryParse(id, out parcel);
  1442. // assume we've got the parcelID we just computed in RemoteParcelRequest
  1443. ExtendedLandData extLandData = new ExtendedLandData();
  1444. Util.ParseFakeParcelID(parcel, out extLandData.RegionHandle,
  1445. out extLandData.X, out extLandData.Y);
  1446. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: Got parcelinfo request for regionHandle {0}, x/y {1}/{2}",
  1447. extLandData.RegionHandle, extLandData.X, extLandData.Y);
  1448. // for this region or for somewhere else?
  1449. if (extLandData.RegionHandle == m_scene.RegionInfo.RegionHandle)
  1450. {
  1451. extLandData.LandData = this.GetLandObject(extLandData.X, extLandData.Y).LandData;
  1452. extLandData.RegionAccess = m_scene.RegionInfo.AccessLevel;
  1453. }
  1454. else
  1455. {
  1456. ILandService landService = m_scene.RequestModuleInterface<ILandService>();
  1457. extLandData.LandData = landService.GetLandData(m_scene.RegionInfo.ScopeID,
  1458. extLandData.RegionHandle,
  1459. extLandData.X,
  1460. extLandData.Y,
  1461. out extLandData.RegionAccess);
  1462. if (extLandData.LandData == null)
  1463. {
  1464. // we didn't find the region/land => don't cache
  1465. return null;
  1466. }
  1467. }
  1468. return extLandData;
  1469. });
  1470. if (data != null) // if we found some data, send it
  1471. {
  1472. GridRegion info;
  1473. if (data.RegionHandle == m_scene.RegionInfo.RegionHandle)
  1474. {
  1475. info = new GridRegion(m_scene.RegionInfo);
  1476. }
  1477. else
  1478. {
  1479. // most likely still cached from building the extLandData entry
  1480. uint x = 0, y = 0;
  1481. Utils.LongToUInts(data.RegionHandle, out x, out y);
  1482. info = m_scene.GridService.GetRegionByPosition(m_scene.RegionInfo.ScopeID, (int)x, (int)y);
  1483. }
  1484. // we need to transfer the fake parcelID, not the one in landData, so the viewer can match it to the landmark.
  1485. m_log.DebugFormat("[LAND MANAGEMENT MODULE]: got parcelinfo for parcel {0} in region {1}; sending...",
  1486. data.LandData.Name, data.RegionHandle);
  1487. // HACK for now
  1488. RegionInfo r = new RegionInfo();
  1489. r.RegionName = info.RegionName;
  1490. r.RegionLocX = (uint)info.RegionLocX;
  1491. r.RegionLocY = (uint)info.RegionLocY;
  1492. r.RegionSettings.Maturity = (int)Util.ConvertAccessLevelToMaturity(data.RegionAccess);
  1493. remoteClient.SendParcelInfo(r, data.LandData, parcelID, data.X, data.Y);
  1494. }
  1495. else
  1496. m_log.Debug("[LAND MANAGEMENT MODULE]: got no parcelinfo; not sending");
  1497. }
  1498. public void setParcelOtherCleanTime(IClientAPI remoteClient, int localID, int otherCleanTime)
  1499. {
  1500. ILandObject land;
  1501. lock (m_landList)
  1502. {
  1503. m_landList.TryGetValue(localID, out land);
  1504. }
  1505. if (land == null) return;
  1506. if (!m_scene.Permissions.CanEditParcelProperties(remoteClient.AgentId, land, GroupPowers.LandOptions))
  1507. return;
  1508. land.LandData.OtherCleanTime = otherCleanTime;
  1509. UpdateLandObject(localID, land.LandData);
  1510. }
  1511. Dictionary<UUID, System.Threading.Timer> Timers = new Dictionary<UUID, System.Threading.Timer>();
  1512. public void ClientOnParcelFreezeUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
  1513. {
  1514. ScenePresence targetAvatar = null;
  1515. ((Scene)client.Scene).TryGetScenePresence(target, out targetAvatar);
  1516. ScenePresence parcelManager = null;
  1517. ((Scene)client.Scene).TryGetScenePresence(client.AgentId, out parcelManager);
  1518. System.Threading.Timer Timer;
  1519. if (targetAvatar.UserLevel == 0)
  1520. {
  1521. ILandObject land = ((Scene)client.Scene).LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
  1522. if (!((Scene)client.Scene).Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze))
  1523. return;
  1524. if (flags == 0)
  1525. {
  1526. targetAvatar.AllowMovement = false;
  1527. targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has frozen you for 30 seconds. You cannot move or interact with the world.");
  1528. parcelManager.ControllingClient.SendAlertMessage("Avatar Frozen.");
  1529. System.Threading.TimerCallback timeCB = new System.Threading.TimerCallback(OnEndParcelFrozen);
  1530. Timer = new System.Threading.Timer(timeCB, targetAvatar, 30000, 0);
  1531. Timers.Add(targetAvatar.UUID, Timer);
  1532. }
  1533. else
  1534. {
  1535. targetAvatar.AllowMovement = true;
  1536. targetAvatar.ControllingClient.SendAlertMessage(parcelManager.Firstname + " " + parcelManager.Lastname + " has unfrozen you.");
  1537. parcelManager.ControllingClient.SendAlertMessage("Avatar Unfrozen.");
  1538. Timers.TryGetValue(targetAvatar.UUID, out Timer);
  1539. Timers.Remove(targetAvatar.UUID);
  1540. Timer.Dispose();
  1541. }
  1542. }
  1543. }
  1544. private void OnEndParcelFrozen(object avatar)
  1545. {
  1546. ScenePresence targetAvatar = (ScenePresence)avatar;
  1547. targetAvatar.AllowMovement = true;
  1548. System.Threading.Timer Timer;
  1549. Timers.TryGetValue(targetAvatar.UUID, out Timer);
  1550. Timers.Remove(targetAvatar.UUID);
  1551. targetAvatar.ControllingClient.SendAgentAlertMessage("The freeze has worn off; you may go about your business.", false);
  1552. }
  1553. public void ClientOnParcelEjectUser(IClientAPI client, UUID parcelowner, uint flags, UUID target)
  1554. {
  1555. ScenePresence targetAvatar = null;
  1556. ScenePresence parcelManager = null;
  1557. // Must have presences
  1558. if (!m_scene.TryGetScenePresence(target, out targetAvatar) ||
  1559. !m_scene.TryGetScenePresence(client.AgentId, out parcelManager))
  1560. return;
  1561. // Cannot eject estate managers or gods
  1562. if (m_scene.Permissions.IsAdministrator(target))
  1563. return;
  1564. // Check if you even have permission to do this
  1565. ILandObject land = m_scene.LandChannel.GetLandObject(targetAvatar.AbsolutePosition.X, targetAvatar.AbsolutePosition.Y);
  1566. if (!m_scene.Permissions.CanEditParcelProperties(client.AgentId, land, GroupPowers.LandEjectAndFreeze) &&
  1567. !m_scene.Permissions.IsAdministrator(client.AgentId))
  1568. return;
  1569. Vector3 pos = m_scene.GetNearestAllowedPosition(targetAvatar, land);
  1570. targetAvatar.TeleportWithMomentum(pos, null);
  1571. targetAvatar.ControllingClient.SendAlertMessage("You have been ejected by " + parcelManager.Firstname + " " + parcelManager.Lastname);
  1572. parcelManager.ControllingClient.SendAlertMessage("Avatar Ejected.");
  1573. if ((flags & 1) != 0) // Ban TODO: Remove magic number
  1574. {
  1575. LandAccessEntry entry = new LandAccessEntry();
  1576. entry.AgentID = targetAvatar.UUID;
  1577. entry.Flags = AccessList.Ban;
  1578. entry.Expires = 0; // Perm
  1579. land.LandData.ParcelAccessList.Add(entry);
  1580. }
  1581. }
  1582. /// <summary>
  1583. /// Sets the Home Point. The LoginService uses this to know where to put a user when they log-in
  1584. /// </summary>
  1585. /// <param name="remoteClient"></param>
  1586. /// <param name="regionHandle"></param>
  1587. /// <param name="position"></param>
  1588. /// <param name="lookAt"></param>
  1589. /// <param name="flags"></param>
  1590. public virtual void ClientOnSetHome(IClientAPI remoteClient, ulong regionHandle, Vector3 position, Vector3 lookAt, uint flags)
  1591. {
  1592. // Let's find the parcel in question
  1593. ILandObject land = landChannel.GetLandObject(position);
  1594. if (land == null || m_scene.GridUserService == null)
  1595. {
  1596. m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
  1597. return;
  1598. }
  1599. // Gather some data
  1600. ulong gpowers = remoteClient.GetGroupPowers(land.LandData.GroupID);
  1601. SceneObjectGroup telehub = null;
  1602. if (m_scene.RegionInfo.RegionSettings.TelehubObject != UUID.Zero)
  1603. // Does the telehub exist in the scene?
  1604. telehub = m_scene.GetSceneObjectGroup(m_scene.RegionInfo.RegionSettings.TelehubObject);
  1605. // Can the user set home here?
  1606. if (// (a) gods and land managers can set home
  1607. m_scene.Permissions.IsAdministrator(remoteClient.AgentId) ||
  1608. m_scene.Permissions.IsGod(remoteClient.AgentId) ||
  1609. // (b) land owners can set home
  1610. remoteClient.AgentId == land.LandData.OwnerID ||
  1611. // (c) members of the land-associated group in roles that can set home
  1612. ((gpowers & (ulong)GroupPowers.AllowSetHome) == (ulong)GroupPowers.AllowSetHome) ||
  1613. // (d) parcels with telehubs can be the home of anyone
  1614. (telehub != null && land.ContainsPoint((int)telehub.AbsolutePosition.X, (int)telehub.AbsolutePosition.Y)))
  1615. {
  1616. if (m_scene.GridUserService.SetHome(remoteClient.AgentId.ToString(), land.RegionUUID, position, lookAt))
  1617. // FUBAR ALERT: this needs to be "Home position set." so the viewer saves a home-screenshot.
  1618. m_Dialog.SendAlertToUser(remoteClient, "Home position set.");
  1619. else
  1620. m_Dialog.SendAlertToUser(remoteClient, "Set Home request failed.");
  1621. }
  1622. else
  1623. m_Dialog.SendAlertToUser(remoteClient, "You are not allowed to set your home location in this parcel.");
  1624. }
  1625. protected void RegisterCommands()
  1626. {
  1627. ICommands commands = MainConsole.Instance.Commands;
  1628. commands.AddCommand(
  1629. "Land", false, "land clear",
  1630. "land clear",
  1631. "Clear all the parcels from the region.",
  1632. "Command will ask for confirmation before proceeding.",
  1633. HandleClearCommand);
  1634. commands.AddCommand(
  1635. "Land", false, "land show",
  1636. "land show [<local-land-id>]",
  1637. "Show information about the parcels on the region.",
  1638. "If no local land ID is given, then summary information about all the parcels is shown.\n"
  1639. + "If a local land ID is given then full information about that parcel is shown.",
  1640. HandleShowCommand);
  1641. }
  1642. protected void HandleClearCommand(string module, string[] args)
  1643. {
  1644. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  1645. return;
  1646. string response = MainConsole.Instance.CmdPrompt(
  1647. string.Format(
  1648. "Are you sure that you want to clear all land parcels from {0} (y or n)", m_scene.Name),
  1649. "n");
  1650. if (response.ToLower() == "y")
  1651. {
  1652. Clear(true);
  1653. MainConsole.Instance.OutputFormat("Cleared all parcels from {0}", m_scene.Name);
  1654. }
  1655. else
  1656. {
  1657. MainConsole.Instance.OutputFormat("Aborting clear of all parcels from {0}", m_scene.Name);
  1658. }
  1659. }
  1660. protected void HandleShowCommand(string module, string[] args)
  1661. {
  1662. if (!(MainConsole.Instance.ConsoleScene == null || MainConsole.Instance.ConsoleScene == m_scene))
  1663. return;
  1664. StringBuilder report = new StringBuilder();
  1665. if (args.Length <= 2)
  1666. {
  1667. AppendParcelsSummaryReport(report);
  1668. }
  1669. else
  1670. {
  1671. int landLocalId;
  1672. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[2], out landLocalId))
  1673. return;
  1674. ILandObject lo;
  1675. lock (m_landList)
  1676. {
  1677. if (!m_landList.TryGetValue(landLocalId, out lo))
  1678. {
  1679. MainConsole.Instance.OutputFormat("No parcel found with local ID {0}", landLocalId);
  1680. return;
  1681. }
  1682. }
  1683. AppendParcelReport(report, lo);
  1684. }
  1685. MainConsole.Instance.Output(report.ToString());
  1686. }
  1687. private void AppendParcelsSummaryReport(StringBuilder report)
  1688. {
  1689. report.AppendFormat("Land information for {0}\n", m_scene.RegionInfo.RegionName);
  1690. report.AppendFormat(
  1691. "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n",
  1692. "Parcel Name",
  1693. "Local ID",
  1694. "Area",
  1695. "Starts",
  1696. "Ends",
  1697. "Owner");
  1698. lock (m_landList)
  1699. {
  1700. foreach (ILandObject lo in m_landList.Values)
  1701. {
  1702. LandData ld = lo.LandData;
  1703. report.AppendFormat(
  1704. "{0,-20} {1,-10} {2,-9} {3,-18} {4,-18} {5,-20}\n",
  1705. ld.Name, ld.LocalID, ld.Area, lo.StartPoint, lo.EndPoint, m_userManager.GetUserName(ld.OwnerID));
  1706. }
  1707. }
  1708. }
  1709. private void AppendParcelReport(StringBuilder report, ILandObject lo)
  1710. {
  1711. LandData ld = lo.LandData;
  1712. ConsoleDisplayList cdl = new ConsoleDisplayList();
  1713. cdl.AddRow("Parcel name", ld.Name);
  1714. cdl.AddRow("Local ID", ld.LocalID);
  1715. cdl.AddRow("Description", ld.Description);
  1716. cdl.AddRow("Snapshot ID", ld.SnapshotID);
  1717. cdl.AddRow("Area", ld.Area);
  1718. cdl.AddRow("Starts", lo.StartPoint);
  1719. cdl.AddRow("Ends", lo.EndPoint);
  1720. cdl.AddRow("AABB Min", ld.AABBMin);
  1721. cdl.AddRow("AABB Max", ld.AABBMax);
  1722. cdl.AddRow("Owner", m_userManager.GetUserName(ld.OwnerID));
  1723. cdl.AddRow("Is group owned?", ld.IsGroupOwned);
  1724. cdl.AddRow("GroupID", ld.GroupID);
  1725. cdl.AddRow("Status", ld.Status);
  1726. cdl.AddRow("Flags", (ParcelFlags)ld.Flags);
  1727. cdl.AddRow("Landing Type", (LandingType)ld.LandingType);
  1728. cdl.AddRow("User Location", ld.UserLocation);
  1729. cdl.AddRow("User look at", ld.UserLookAt);
  1730. cdl.AddRow("Other clean time", ld.OtherCleanTime);
  1731. cdl.AddRow("Max Prims", lo.GetParcelMaxPrimCount());
  1732. IPrimCounts pc = lo.PrimCounts;
  1733. cdl.AddRow("Owner Prims", pc.Owner);
  1734. cdl.AddRow("Group Prims", pc.Group);
  1735. cdl.AddRow("Other Prims", pc.Others);
  1736. cdl.AddRow("Selected Prims", pc.Selected);
  1737. cdl.AddRow("Total Prims", pc.Total);
  1738. cdl.AddRow("Music URL", ld.MusicURL);
  1739. cdl.AddRow("Obscure Music", ld.ObscureMusic);
  1740. cdl.AddRow("Media ID", ld.MediaID);
  1741. cdl.AddRow("Media Autoscale", Convert.ToBoolean(ld.MediaAutoScale));
  1742. cdl.AddRow("Media URL", ld.MediaURL);
  1743. cdl.AddRow("Media Type", ld.MediaType);
  1744. cdl.AddRow("Media Description", ld.MediaDescription);
  1745. cdl.AddRow("Media Width", ld.MediaWidth);
  1746. cdl.AddRow("Media Height", ld.MediaHeight);
  1747. cdl.AddRow("Media Loop", ld.MediaLoop);
  1748. cdl.AddRow("Obscure Media", ld.ObscureMedia);
  1749. cdl.AddRow("Parcel Category", ld.Category);
  1750. cdl.AddRow("Claim Date", ld.ClaimDate);
  1751. cdl.AddRow("Claim Price", ld.ClaimPrice);
  1752. cdl.AddRow("Pass Hours", ld.PassHours);
  1753. cdl.AddRow("Pass Price", ld.PassPrice);
  1754. cdl.AddRow("Auction ID", ld.AuctionID);
  1755. cdl.AddRow("Authorized Buyer ID", ld.AuthBuyerID);
  1756. cdl.AddRow("Sale Price", ld.SalePrice);
  1757. cdl.AddToStringBuilder(report);
  1758. }
  1759. }
  1760. }