LandManagementModule.cs 80 KB

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