LandChannel.cs 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000
  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 OpenSim Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using Axiom.Math;
  30. using libsecondlife;
  31. using libsecondlife.Packets;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Environment.Interfaces;
  34. using OpenSim.Region.Environment.Scenes;
  35. using OpenSim.Region.Physics.Manager;
  36. namespace OpenSim.Region.Environment.Modules.World.Land
  37. {
  38. public class LandChannel : ILandChannel
  39. {
  40. #region Constants
  41. //Land types set with flags in ParcelOverlay.
  42. //Only one of these can be used.
  43. public const float BAN_LINE_SAFETY_HIEGHT = 100;
  44. public const byte LAND_FLAG_PROPERTY_BORDER_SOUTH = (byte) 128; //Equals 10000000
  45. public const byte LAND_FLAG_PROPERTY_BORDER_WEST = (byte) 64; //Equals 01000000
  46. //RequestResults (I think these are right, they seem to work):
  47. public const int LAND_RESULT_MULTIPLE = 1; // The request they made contained more than a single peice of land
  48. public const int LAND_RESULT_SINGLE = 0; // The request they made contained only a single piece of land
  49. //ParcelSelectObjects
  50. public const int LAND_SELECT_OBJECTS_GROUP = 4;
  51. public const int LAND_SELECT_OBJECTS_OTHER = 8;
  52. public const int LAND_SELECT_OBJECTS_OWNER = 2;
  53. public const byte LAND_TYPE_IS_BEING_AUCTIONED = (byte) 5; //Equals 00000101
  54. public const byte LAND_TYPE_IS_FOR_SALE = (byte) 4; //Equals 00000100
  55. public const byte LAND_TYPE_OWNED_BY_GROUP = (byte) 2; //Equals 00000010
  56. public const byte LAND_TYPE_OWNED_BY_OTHER = (byte) 1; //Equals 00000001
  57. public const byte LAND_TYPE_OWNED_BY_REQUESTER = (byte) 3; //Equals 00000011
  58. public const byte LAND_TYPE_PUBLIC = (byte) 0; //Equals 00000000
  59. //These are other constants. Yay!
  60. public const int START_LAND_LOCAL_ID = 1;
  61. #endregion
  62. private int[,] landIDList = new int[64,64];
  63. private Dictionary<int, ILandObject> landList = new Dictionary<int, ILandObject>();
  64. private bool landPrimCountTainted = false;
  65. private int lastLandLocalID = START_LAND_LOCAL_ID - 1;
  66. private bool m_allowedForcefulBans = true;
  67. private Scene m_scene;
  68. public LandChannel(Scene scene)
  69. {
  70. m_scene = scene;
  71. landIDList.Initialize();
  72. }
  73. #region Land Object From Storage Functions
  74. public void IncomingLandObjectsFromStorage(List<LandData> data)
  75. {
  76. for (int i = 0; i < data.Count; i++)
  77. {
  78. //try
  79. //{
  80. IncomingLandObjectFromStorage(data[i]);
  81. //}
  82. //catch (Exception ex)
  83. //{
  84. //m_log.Error("[LandManager]: IncomingLandObjectsFromStorage: Exception: " + ex.ToString());
  85. //throw ex;
  86. //}
  87. }
  88. //foreach (LandData parcel in data)
  89. //{
  90. // IncomingLandObjectFromStorage(parcel);
  91. //}
  92. }
  93. public void IncomingLandObjectFromStorage(LandData data)
  94. {
  95. ILandObject new_land = new LandObject(data.ownerID, data.isGroupOwned, m_scene);
  96. new_land.landData = data.Copy();
  97. new_land.setLandBitmapFromByteArray();
  98. addLandObject(new_land);
  99. }
  100. public void NoLandDataFromStorage()
  101. {
  102. resetSimLandObjects();
  103. }
  104. #endregion
  105. #region Parcel Add/Remove/Get/Create
  106. public void updateLandObject(int local_id, LandData newData)
  107. {
  108. if (landList.ContainsKey(local_id))
  109. {
  110. landList[local_id].landData = newData.Copy();
  111. m_scene.EventManager.TriggerLandObjectUpdated((uint) local_id, landList[local_id]);
  112. }
  113. }
  114. /// <summary>
  115. /// Get the land object at the specified point
  116. /// </summary>
  117. /// <param name="x">Value between 0 - 256 on the x axis of the point</param>
  118. /// <param name="y">Value between 0 - 256 on the y axis of the point</param>
  119. /// <returns>Land object at the point supplied</returns>
  120. public ILandObject getLandObject(float x_float, float y_float)
  121. {
  122. int x;
  123. int y;
  124. try
  125. {
  126. x = Convert.ToInt32(Math.Floor(Convert.ToDouble(x_float) / Convert.ToDouble(4.0)));
  127. y = Convert.ToInt32(Math.Floor(Convert.ToDouble(y_float) / Convert.ToDouble(4.0)));
  128. }
  129. catch (OverflowException)
  130. {
  131. return null;
  132. }
  133. if (x >= 64 || y >= 64 || x < 0 || y < 0)
  134. {
  135. return null;
  136. }
  137. else
  138. {
  139. return landList[landIDList[x, y]];
  140. }
  141. }
  142. public ILandObject getLandObject(int x, int y)
  143. {
  144. if (x >= Convert.ToInt32(Constants.RegionSize) || y >= Convert.ToInt32(Constants.RegionSize) || x < 0 || y < 0)
  145. {
  146. // These exceptions here will cause a lot of complaints from the users specifically because
  147. // they happen every time at border crossings
  148. throw new Exception("Error: Parcel not found at point " + x + ", " + y);
  149. }
  150. else
  151. {
  152. return landList[landIDList[x / 4, y / 4]];
  153. }
  154. }
  155. /// <summary>
  156. /// Creates a basic Parcel object without an owner (a zeroed key)
  157. /// </summary>
  158. /// <returns></returns>
  159. public ILandObject createBaseLand()
  160. {
  161. return new LandObject(LLUUID.Zero, false, m_scene);
  162. }
  163. /// <summary>
  164. /// Adds a land object to the stored list and adds them to the landIDList to what they own
  165. /// </summary>
  166. /// <param name="new_land">The land object being added</param>
  167. public ILandObject addLandObject(ILandObject new_land)
  168. {
  169. lastLandLocalID++;
  170. new_land.landData.localID = lastLandLocalID;
  171. landList.Add(lastLandLocalID, (LandObject) new_land.Copy());
  172. bool[,] landBitmap = new_land.getLandBitmap();
  173. int x, y;
  174. for (x = 0; x < 64; x++)
  175. {
  176. for (y = 0; y < 64; y++)
  177. {
  178. if (landBitmap[x, y])
  179. {
  180. landIDList[x, y] = lastLandLocalID;
  181. }
  182. }
  183. }
  184. landList[lastLandLocalID].forceUpdateLandInfo();
  185. m_scene.EventManager.TriggerLandObjectAdded(new_land);
  186. return new_land;
  187. }
  188. /// <summary>
  189. /// Removes a land object from the list. Will not remove if local_id is still owning an area in landIDList
  190. /// </summary>
  191. /// <param name="local_id">Land.localID of the peice of land to remove.</param>
  192. public void removeLandObject(int local_id)
  193. {
  194. int x, y;
  195. for (x = 0; x < 64; x++)
  196. {
  197. for (y = 0; y < 64; y++)
  198. {
  199. if (landIDList[x, y] == local_id)
  200. {
  201. return;
  202. //throw new Exception("Could not remove land object. Still being used at " + x + ", " + y);
  203. }
  204. }
  205. }
  206. m_scene.EventManager.TriggerLandObjectRemoved(landList[local_id].landData.globalID);
  207. landList.Remove(local_id);
  208. }
  209. private void performFinalLandJoin(ILandObject master, ILandObject slave)
  210. {
  211. int x, y;
  212. bool[,] landBitmapSlave = slave.getLandBitmap();
  213. for (x = 0; x < 64; x++)
  214. {
  215. for (y = 0; y < 64; y++)
  216. {
  217. if (landBitmapSlave[x, y])
  218. {
  219. landIDList[x, y] = master.landData.localID;
  220. }
  221. }
  222. }
  223. removeLandObject(slave.landData.localID);
  224. updateLandObject(master.landData.localID, master.landData);
  225. }
  226. public ILandObject getLandObject(int parcelLocalID)
  227. {
  228. lock (landList)
  229. {
  230. if (landList.ContainsKey(parcelLocalID))
  231. {
  232. return landList[parcelLocalID];
  233. }
  234. }
  235. return null;
  236. }
  237. #endregion
  238. #region Parcel Modification
  239. public void resetAllLandPrimCounts()
  240. {
  241. foreach (LandObject p in landList.Values)
  242. {
  243. p.resetLandPrimCounts();
  244. }
  245. }
  246. public void setPrimsTainted()
  247. {
  248. landPrimCountTainted = true;
  249. }
  250. public bool isLandPrimCountTainted()
  251. {
  252. return landPrimCountTainted;
  253. }
  254. public void addPrimToLandPrimCounts(SceneObjectGroup obj)
  255. {
  256. LLVector3 position = obj.AbsolutePosition;
  257. ILandObject landUnderPrim = getLandObject(position.X, position.Y);
  258. if (landUnderPrim != null)
  259. {
  260. landUnderPrim.addPrimToCount(obj);
  261. }
  262. }
  263. public void removePrimFromLandPrimCounts(SceneObjectGroup obj)
  264. {
  265. foreach (LandObject p in landList.Values)
  266. {
  267. p.removePrimFromCount(obj);
  268. }
  269. }
  270. public void finalizeLandPrimCountUpdate()
  271. {
  272. //Get Simwide prim count for owner
  273. Dictionary<LLUUID, List<LandObject>> landOwnersAndParcels = new Dictionary<LLUUID, List<LandObject>>();
  274. foreach (LandObject p in landList.Values)
  275. {
  276. if (!landOwnersAndParcels.ContainsKey(p.landData.ownerID))
  277. {
  278. List<LandObject> tempList = new List<LandObject>();
  279. tempList.Add(p);
  280. landOwnersAndParcels.Add(p.landData.ownerID, tempList);
  281. }
  282. else
  283. {
  284. landOwnersAndParcels[p.landData.ownerID].Add(p);
  285. }
  286. }
  287. foreach (LLUUID owner in landOwnersAndParcels.Keys)
  288. {
  289. int simArea = 0;
  290. int simPrims = 0;
  291. foreach (LandObject p in landOwnersAndParcels[owner])
  292. {
  293. simArea += p.landData.area;
  294. simPrims += p.landData.ownerPrims + p.landData.otherPrims + p.landData.groupPrims +
  295. p.landData.selectedPrims;
  296. }
  297. foreach (LandObject p in landOwnersAndParcels[owner])
  298. {
  299. p.landData.simwideArea = simArea;
  300. p.landData.simwidePrims = simPrims;
  301. }
  302. }
  303. }
  304. public void updateLandPrimCounts()
  305. {
  306. foreach (EntityBase obj in m_scene.Entities.Values)
  307. {
  308. if (obj is SceneObjectGroup)
  309. {
  310. m_scene.EventManager.TriggerParcelPrimCountAdd((SceneObjectGroup) obj);
  311. }
  312. }
  313. }
  314. public void performParcelPrimCountUpdate()
  315. {
  316. resetAllLandPrimCounts();
  317. m_scene.EventManager.TriggerParcelPrimCountUpdate();
  318. finalizeLandPrimCountUpdate();
  319. landPrimCountTainted = false;
  320. }
  321. /// <summary>
  322. /// Subdivides a piece of land
  323. /// </summary>
  324. /// <param name="start_x">West Point</param>
  325. /// <param name="start_y">South Point</param>
  326. /// <param name="end_x">East Point</param>
  327. /// <param name="end_y">North Point</param>
  328. /// <param name="attempting_user_id">LLUUID of user who is trying to subdivide</param>
  329. /// <returns>Returns true if successful</returns>
  330. private bool subdivide(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
  331. {
  332. //First, lets loop through the points and make sure they are all in the same peice of land
  333. //Get the land object at start
  334. ILandObject startLandObject = null;
  335. try
  336. {
  337. startLandObject = getLandObject(start_x, start_y);
  338. }
  339. catch (Exception)
  340. {
  341. //m_log.Error("[LAND]: " + "Unable to get land object for subdivision at x: " + start_x + " y:" + start_y);
  342. }
  343. if (startLandObject == null) return false; //No such land object at the beginning
  344. //Loop through the points
  345. try
  346. {
  347. int totalX = end_x - start_x;
  348. int totalY = end_y - start_y;
  349. int x, y;
  350. for (y = 0; y < totalY; y++)
  351. {
  352. for (x = 0; x < totalX; x++)
  353. {
  354. ILandObject tempLandObject = getLandObject(start_x + x, start_y + y);
  355. if (tempLandObject == null) return false; //No such land object at that point
  356. if (tempLandObject != startLandObject) return false; //Subdividing over 2 land objects; no-no
  357. }
  358. }
  359. }
  360. catch (Exception)
  361. {
  362. return false; //Exception. For now, lets skip subdivision
  363. }
  364. //If we are still here, then they are subdividing within one piece of land
  365. //Check owner
  366. if (startLandObject.landData.ownerID != attempting_user_id)
  367. {
  368. return false; //They cant do this!
  369. }
  370. //Lets create a new land object with bitmap activated at that point (keeping the old land objects info)
  371. ILandObject newLand = startLandObject.Copy();
  372. newLand.landData.landName = "Subdivision of " + newLand.landData.landName;
  373. newLand.landData.globalID = LLUUID.Random();
  374. newLand.setLandBitmap(newLand.getSquareLandBitmap(start_x, start_y, end_x, end_y));
  375. //Now, lets set the subdivision area of the original to false
  376. int startLandObjectIndex = startLandObject.landData.localID;
  377. landList[startLandObjectIndex].setLandBitmap(
  378. newLand.modifyLandBitmapSquare(startLandObject.getLandBitmap(), start_x, start_y, end_x, end_y, false));
  379. landList[startLandObjectIndex].forceUpdateLandInfo();
  380. setPrimsTainted();
  381. //Now add the new land object
  382. ILandObject result = addLandObject(newLand);
  383. updateLandObject(startLandObject.landData.localID, startLandObject.landData);
  384. result.sendLandUpdateToAvatarsOverMe();
  385. return true;
  386. }
  387. /// <summary>
  388. /// Join 2 land objects together
  389. /// </summary>
  390. /// <param name="start_x">x value in first piece of land</param>
  391. /// <param name="start_y">y value in first piece of land</param>
  392. /// <param name="end_x">x value in second peice of land</param>
  393. /// <param name="end_y">y value in second peice of land</param>
  394. /// <param name="attempting_user_id">LLUUID of the avatar trying to join the land objects</param>
  395. /// <returns>Returns true if successful</returns>
  396. private bool join(int start_x, int start_y, int end_x, int end_y, LLUUID attempting_user_id)
  397. {
  398. end_x -= 4;
  399. end_y -= 4;
  400. List<ILandObject> selectedLandObjects = new List<ILandObject>();
  401. int stepXSelected = 0;
  402. int stepYSelected = 0;
  403. for (stepYSelected = start_y; stepYSelected <= end_y; stepYSelected += 4)
  404. {
  405. for (stepXSelected = start_x; stepXSelected <= end_x; stepXSelected += 4)
  406. {
  407. ILandObject p = null;
  408. try
  409. {
  410. p = getLandObject(stepXSelected, stepYSelected);
  411. }
  412. catch (Exception)
  413. {
  414. //m_log.Error("[LAND]: " + "Unable to get land object for subdivision at x: " + stepXSelected + " y:" + stepYSelected);
  415. }
  416. if (p != null)
  417. {
  418. if (!selectedLandObjects.Contains(p))
  419. {
  420. selectedLandObjects.Add(p);
  421. }
  422. }
  423. }
  424. }
  425. ILandObject masterLandObject = selectedLandObjects[0];
  426. selectedLandObjects.RemoveAt(0);
  427. if (selectedLandObjects.Count < 1)
  428. {
  429. return false; //Only one piece of land selected
  430. }
  431. if (masterLandObject.landData.ownerID != attempting_user_id)
  432. {
  433. return false; //Not the same owner
  434. }
  435. foreach (ILandObject p in selectedLandObjects)
  436. {
  437. if (p.landData.ownerID != masterLandObject.landData.ownerID)
  438. {
  439. return false; //Over multiple users. TODO: make this just ignore this piece of land?
  440. }
  441. }
  442. foreach (ILandObject slaveLandObject in selectedLandObjects)
  443. {
  444. landList[masterLandObject.landData.localID].setLandBitmap(
  445. slaveLandObject.mergeLandBitmaps(masterLandObject.getLandBitmap(), slaveLandObject.getLandBitmap()));
  446. performFinalLandJoin(masterLandObject, slaveLandObject);
  447. }
  448. setPrimsTainted();
  449. masterLandObject.sendLandUpdateToAvatarsOverMe();
  450. return true;
  451. }
  452. #endregion
  453. #region Parcel Updating
  454. /// <summary>
  455. /// Where we send the ParcelOverlay packet to the client
  456. /// </summary>
  457. /// <param name="remote_client">The object representing the client</param>
  458. public void sendParcelOverlay(IClientAPI remote_client)
  459. {
  460. const int LAND_BLOCKS_PER_PACKET = 1024;
  461. int x, y = 0;
  462. byte[] byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  463. int byteArrayCount = 0;
  464. int sequenceID = 0;
  465. ParcelOverlayPacket packet;
  466. for (y = 0; y < 64; y++)
  467. {
  468. for (x = 0; x < 64; x++)
  469. {
  470. byte tempByte = (byte) 0; //This represents the byte for the current 4x4
  471. ILandObject currentParcelBlock = null;
  472. try
  473. {
  474. currentParcelBlock = getLandObject(x * 4, y * 4);
  475. }
  476. catch (Exception)
  477. {
  478. //m_log.Warn("[LAND]: " + "unable to get land at x: " + (x * 4) + " y: " + (y * 4));
  479. }
  480. if (currentParcelBlock != null)
  481. {
  482. if (currentParcelBlock.landData.ownerID == remote_client.AgentId)
  483. {
  484. //Owner Flag
  485. tempByte = Convert.ToByte(tempByte | LAND_TYPE_OWNED_BY_REQUESTER);
  486. }
  487. else if (currentParcelBlock.landData.salePrice > 0 &&
  488. (currentParcelBlock.landData.authBuyerID == LLUUID.Zero ||
  489. currentParcelBlock.landData.authBuyerID == remote_client.AgentId))
  490. {
  491. //Sale Flag
  492. tempByte = Convert.ToByte(tempByte | LAND_TYPE_IS_FOR_SALE);
  493. }
  494. else if (currentParcelBlock.landData.ownerID == LLUUID.Zero)
  495. {
  496. //Public Flag
  497. tempByte = Convert.ToByte(tempByte | LAND_TYPE_PUBLIC);
  498. }
  499. else
  500. {
  501. //Other Flag
  502. tempByte = Convert.ToByte(tempByte | LAND_TYPE_OWNED_BY_OTHER);
  503. }
  504. //Now for border control
  505. try
  506. {
  507. ILandObject westParcel = null;
  508. ILandObject southParcel = null;
  509. if (x > 0)
  510. {
  511. westParcel = getLandObject((x - 1) * 4, y * 4);
  512. }
  513. if (y > 0)
  514. {
  515. southParcel = getLandObject(x * 4, (y - 1) * 4);
  516. }
  517. if (x == 0)
  518. {
  519. tempByte = Convert.ToByte(tempByte | LAND_FLAG_PROPERTY_BORDER_WEST);
  520. }
  521. else if (westParcel != null && westParcel != currentParcelBlock)
  522. {
  523. tempByte = Convert.ToByte(tempByte | LAND_FLAG_PROPERTY_BORDER_WEST);
  524. }
  525. if (y == 0)
  526. {
  527. tempByte = Convert.ToByte(tempByte | LAND_FLAG_PROPERTY_BORDER_SOUTH);
  528. }
  529. else if (southParcel != null && southParcel != currentParcelBlock)
  530. {
  531. tempByte = Convert.ToByte(tempByte | LAND_FLAG_PROPERTY_BORDER_SOUTH);
  532. }
  533. byteArray[byteArrayCount] = tempByte;
  534. byteArrayCount++;
  535. if (byteArrayCount >= LAND_BLOCKS_PER_PACKET)
  536. {
  537. byteArrayCount = 0;
  538. packet = (ParcelOverlayPacket) PacketPool.Instance.GetPacket(PacketType.ParcelOverlay);
  539. packet.ParcelData.Data = byteArray;
  540. packet.ParcelData.SequenceID = sequenceID;
  541. remote_client.OutPacket((Packet) packet, ThrottleOutPacketType.Task);
  542. sequenceID++;
  543. byteArray = new byte[LAND_BLOCKS_PER_PACKET];
  544. }
  545. }
  546. catch (Exception)
  547. {
  548. //m_log.Debug("[LAND]: Skipped Land checks because avatar is out of bounds: " + e.Message);
  549. }
  550. }
  551. }
  552. }
  553. }
  554. public void handleParcelPropertiesRequest(int start_x, int start_y, int end_x, int end_y, int sequence_id,
  555. bool snap_selection, IClientAPI remote_client)
  556. {
  557. //Get the land objects within the bounds
  558. List<ILandObject> temp = new List<ILandObject>();
  559. int x, y, i;
  560. int inc_x = end_x - start_x;
  561. int inc_y = end_y - start_y;
  562. for (x = 0; x < inc_x; x++)
  563. {
  564. for (y = 0; y < inc_y; y++)
  565. {
  566. ILandObject currentParcel = null;
  567. try
  568. {
  569. currentParcel = getLandObject(start_x + x, start_y + y);
  570. }
  571. catch (Exception)
  572. {
  573. //m_log.Warn("[LAND]: " + "unable to get land at x: " + (start_x + x) + " y: " + (start_y + y));
  574. }
  575. if (currentParcel != null)
  576. {
  577. if (!temp.Contains(currentParcel))
  578. {
  579. currentParcel.forceUpdateLandInfo();
  580. temp.Add(currentParcel);
  581. }
  582. }
  583. }
  584. }
  585. int requestResult = LAND_RESULT_SINGLE;
  586. if (temp.Count > 1)
  587. {
  588. requestResult = LAND_RESULT_MULTIPLE;
  589. }
  590. for (i = 0; i < temp.Count; i++)
  591. {
  592. temp[i].sendLandProperties(sequence_id, snap_selection, requestResult, remote_client);
  593. }
  594. sendParcelOverlay(remote_client);
  595. }
  596. public void handleParcelPropertiesUpdateRequest(ParcelPropertiesUpdatePacket packet, IClientAPI remote_client)
  597. {
  598. if (landList.ContainsKey(packet.ParcelData.LocalID))
  599. {
  600. landList[packet.ParcelData.LocalID].updateLandProperties(packet, remote_client);
  601. }
  602. }
  603. public void handleParcelDivideRequest(int west, int south, int east, int north, IClientAPI remote_client)
  604. {
  605. subdivide(west, south, east, north, remote_client.AgentId);
  606. }
  607. public void handleParcelJoinRequest(int west, int south, int east, int north, IClientAPI remote_client)
  608. {
  609. join(west, south, east, north, remote_client.AgentId);
  610. }
  611. public void handleParcelSelectObjectsRequest(int local_id, int request_type, IClientAPI remote_client)
  612. {
  613. landList[local_id].sendForceObjectSelect(local_id, request_type, remote_client);
  614. }
  615. public void handleParcelObjectOwnersRequest(int local_id, IClientAPI remote_client)
  616. {
  617. landList[local_id].sendLandObjectOwners(remote_client);
  618. }
  619. #endregion
  620. #region ILandChannel Members
  621. public bool allowedForcefulBans
  622. {
  623. get { return m_allowedForcefulBans; }
  624. set { m_allowedForcefulBans = value; }
  625. }
  626. /// <summary>
  627. /// Resets the sim to the default land object (full sim piece of land owned by the default user)
  628. /// </summary>
  629. public void resetSimLandObjects()
  630. {
  631. //Remove all the land objects in the sim and add a blank, full sim land object set to public
  632. landList.Clear();
  633. lastLandLocalID = START_LAND_LOCAL_ID - 1;
  634. landIDList.Initialize();
  635. ILandObject fullSimParcel = new LandObject(LLUUID.Zero, false, m_scene);
  636. fullSimParcel.setLandBitmap(fullSimParcel.getSquareLandBitmap(0, 0, (int) Constants.RegionSize, (int) Constants.RegionSize));
  637. fullSimParcel.landData.ownerID = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  638. addLandObject(fullSimParcel);
  639. }
  640. public List<ILandObject> parcelsNearPoint(LLVector3 position)
  641. {
  642. List<ILandObject> parcelsNear = new List<ILandObject>();
  643. int x, y;
  644. for (x = -4; x <= 4; x += 4)
  645. {
  646. for (y = -4; y <= 4; y += 4)
  647. {
  648. ILandObject check = getLandObject(position.X + x, position.Y + y);
  649. if (check != null)
  650. {
  651. if (!parcelsNear.Contains(check))
  652. {
  653. parcelsNear.Add(check);
  654. }
  655. }
  656. }
  657. }
  658. return parcelsNear;
  659. }
  660. public void sendYouAreBannedNotice(ScenePresence avatar)
  661. {
  662. if (allowedForcefulBans)
  663. {
  664. avatar.ControllingClient.SendAlertMessage(
  665. "You are not allowed on this parcel because you are banned. Please go away. <3 OpenSim Developers");
  666. avatar.PhysicsActor.Position =
  667. new PhysicsVector(avatar.lastKnownAllowedPosition.x, avatar.lastKnownAllowedPosition.y,
  668. avatar.lastKnownAllowedPosition.z);
  669. avatar.PhysicsActor.Velocity = new PhysicsVector(0, 0, 0);
  670. }
  671. else
  672. {
  673. avatar.ControllingClient.SendAlertMessage(
  674. "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! <3 OpenSim Developers");
  675. }
  676. }
  677. public void handleAvatarChangingParcel(ScenePresence avatar, int localLandID, LLUUID regionID)
  678. {
  679. if (m_scene.RegionInfo.RegionID == regionID)
  680. {
  681. if (landList[localLandID] != null)
  682. {
  683. ILandObject parcelAvatarIsEntering = landList[localLandID];
  684. if (avatar.AbsolutePosition.Z < BAN_LINE_SAFETY_HIEGHT)
  685. {
  686. if (parcelAvatarIsEntering.isBannedFromLand(avatar.UUID))
  687. {
  688. sendYouAreBannedNotice(avatar);
  689. }
  690. else if (parcelAvatarIsEntering.isRestrictedFromLand(avatar.UUID))
  691. {
  692. avatar.ControllingClient.SendAlertMessage(
  693. "You are not allowed on this parcel because the land owner has restricted access. For now, you can enter, but please respect the land owner's decisions (or he can ban you!). <3 OpenSim Developers");
  694. }
  695. else
  696. {
  697. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  698. }
  699. }
  700. else
  701. {
  702. avatar.sentMessageAboutRestrictedParcelFlyingDown = true;
  703. }
  704. }
  705. }
  706. }
  707. public void sendOutNearestBanLine(IClientAPI avatar)
  708. {
  709. List<ScenePresence> avatars = m_scene.GetAvatars();
  710. foreach (ScenePresence presence in avatars)
  711. {
  712. if (presence.UUID == avatar.AgentId)
  713. {
  714. List<ILandObject> checkLandParcels = parcelsNearPoint(presence.AbsolutePosition);
  715. foreach (ILandObject checkBan in checkLandParcels)
  716. {
  717. if (checkBan.isBannedFromLand(avatar.AgentId))
  718. {
  719. checkBan.sendLandProperties(-30000, false, (int) ParcelManager.ParcelResult.Single, avatar);
  720. return; //Only send one
  721. }
  722. else if (checkBan.isRestrictedFromLand(avatar.AgentId))
  723. {
  724. checkBan.sendLandProperties(-40000, false, (int) ParcelManager.ParcelResult.Single, avatar);
  725. return; //Only send one
  726. }
  727. }
  728. return;
  729. }
  730. }
  731. }
  732. public void sendLandUpdate(ScenePresence avatar, bool force)
  733. {
  734. ILandObject over = null;
  735. try
  736. {
  737. over = getLandObject((int) Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.X))),
  738. (int) Math.Min(255, Math.Max(0, Math.Round(avatar.AbsolutePosition.Y))));
  739. }
  740. catch (Exception)
  741. {
  742. //m_log.Warn("[LAND]: " + "unable to get land at x: " + Math.Round(avatar.AbsolutePosition.X) + " y: " + Math.Round(avatar.AbsolutePosition.Y));
  743. }
  744. if (over != null)
  745. {
  746. if (force)
  747. {
  748. if (!avatar.IsChildAgent)
  749. {
  750. over.sendLandUpdateToClient(avatar.ControllingClient);
  751. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.localID,
  752. m_scene.RegionInfo.RegionID);
  753. }
  754. }
  755. if (avatar.currentParcelUUID != over.landData.globalID)
  756. {
  757. if (!avatar.IsChildAgent)
  758. {
  759. over.sendLandUpdateToClient(avatar.ControllingClient);
  760. avatar.currentParcelUUID = over.landData.globalID;
  761. m_scene.EventManager.TriggerAvatarEnteringNewParcel(avatar, over.landData.localID,
  762. m_scene.RegionInfo.RegionID);
  763. }
  764. }
  765. }
  766. }
  767. public void sendLandUpdate(ScenePresence avatar)
  768. {
  769. sendLandUpdate(avatar, false);
  770. }
  771. public void handleSignificantClientMovement(IClientAPI remote_client)
  772. {
  773. ScenePresence clientAvatar = m_scene.GetScenePresence(remote_client.AgentId);
  774. if (clientAvatar != null)
  775. {
  776. sendLandUpdate(clientAvatar);
  777. sendOutNearestBanLine(remote_client);
  778. ILandObject parcel = getLandObject(clientAvatar.AbsolutePosition.X, clientAvatar.AbsolutePosition.Y);
  779. if (parcel != null)
  780. {
  781. if (clientAvatar.AbsolutePosition.Z < BAN_LINE_SAFETY_HIEGHT &&
  782. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown)
  783. {
  784. handleAvatarChangingParcel(clientAvatar, parcel.landData.localID, m_scene.RegionInfo.RegionID);
  785. //They are going below the safety line!
  786. if (!parcel.isBannedFromLand(clientAvatar.UUID))
  787. {
  788. clientAvatar.sentMessageAboutRestrictedParcelFlyingDown = false;
  789. }
  790. }
  791. else if (clientAvatar.AbsolutePosition.Z < BAN_LINE_SAFETY_HIEGHT &&
  792. parcel.isBannedFromLand(clientAvatar.UUID))
  793. {
  794. sendYouAreBannedNotice(clientAvatar);
  795. }
  796. }
  797. }
  798. }
  799. public void handleAnyClientMovement(ScenePresence avatar)
  800. //Like handleSignificantClientMovement, but called with an AgentUpdate regardless of distance.
  801. {
  802. ILandObject over = getLandObject(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y);
  803. if (over != null)
  804. {
  805. if (!over.isBannedFromLand(avatar.UUID) || avatar.AbsolutePosition.Z >= BAN_LINE_SAFETY_HIEGHT)
  806. {
  807. avatar.lastKnownAllowedPosition =
  808. new Vector3(avatar.AbsolutePosition.X, avatar.AbsolutePosition.Y, avatar.AbsolutePosition.Z);
  809. }
  810. }
  811. }
  812. public void handleParcelAccessRequest(LLUUID agentID, LLUUID sessionID, uint flags, int sequenceID,
  813. int landLocalID, IClientAPI remote_client)
  814. {
  815. if (landList.ContainsKey(landLocalID))
  816. {
  817. landList[landLocalID].sendAccessList(agentID, sessionID, flags, sequenceID, remote_client);
  818. }
  819. }
  820. public void handleParcelAccessUpdateRequest(LLUUID agentID, LLUUID sessionID, uint flags, int landLocalID,
  821. List<ParcelManager.ParcelAccessEntry> entries,
  822. IClientAPI remote_client)
  823. {
  824. if (landList.ContainsKey(landLocalID))
  825. {
  826. if (agentID == landList[landLocalID].landData.ownerID)
  827. {
  828. landList[landLocalID].updateAccessList(flags, entries, remote_client);
  829. }
  830. }
  831. else
  832. {
  833. Console.WriteLine("INVALID LOCAL LAND ID");
  834. }
  835. }
  836. #endregion
  837. // If the economy has been validated by the economy module,
  838. // and land has been validated as well, this method transfers
  839. // the land ownership
  840. public void handleLandBuyRequest(Object o, EventManager.LandBuyArgs e)
  841. {
  842. if (e.economyValidated && e.landValidated)
  843. {
  844. lock (landList)
  845. {
  846. if (landList.ContainsKey(e.parcelLocalID))
  847. {
  848. landList[e.parcelLocalID].updateLandSold(e.agentId, e.groupId, e.groupOwned, (uint) e.transactionID, e.parcelPrice, e.parcelArea);
  849. return;
  850. }
  851. }
  852. }
  853. }
  854. // After receiving a land buy packet, first the data needs to
  855. // be validated. This method validates the right to buy the
  856. // parcel
  857. public void handleLandValidationRequest(Object o, EventManager.LandBuyArgs e)
  858. {
  859. if (e.landValidated == false)
  860. {
  861. ILandObject lob = null;
  862. lock (landList)
  863. {
  864. if (landList.ContainsKey(e.parcelLocalID))
  865. {
  866. lob = landList[e.parcelLocalID];
  867. }
  868. }
  869. if (lob != null)
  870. {
  871. LLUUID AuthorizedID = lob.landData.authBuyerID;
  872. int saleprice = lob.landData.salePrice;
  873. LLUUID pOwnerID = lob.landData.ownerID;
  874. bool landforsale = ((lob.landData.landFlags &
  875. (uint) (Parcel.ParcelFlags.ForSale | Parcel.ParcelFlags.ForSaleObjects | Parcel.ParcelFlags.SellParcelObjects)) != 0);
  876. if ((AuthorizedID == LLUUID.Zero || AuthorizedID == e.agentId) && e.parcelPrice >= saleprice && landforsale)
  877. {
  878. lock (e)
  879. {
  880. e.parcelOwnerID = pOwnerID;
  881. e.landValidated = true;
  882. }
  883. }
  884. }
  885. }
  886. }
  887. }
  888. }