LandChannel.cs 35 KB

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