EstateManagementModule.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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 System.IO;
  30. using System.Reflection;
  31. using System.Security;
  32. using log4net;
  33. using Nini.Config;
  34. using OpenMetaverse;
  35. using OpenSim.Framework;
  36. using OpenSim.Region.CoreModules.World.Terrain;
  37. using OpenSim.Region.Framework.Interfaces;
  38. using OpenSim.Region.Framework.Scenes;
  39. namespace OpenSim.Region.CoreModules.World.Estate
  40. {
  41. public class EstateManagementModule : IEstateModule
  42. {
  43. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  44. private delegate void LookupUUIDS(List<UUID> uuidLst);
  45. private Scene m_scene;
  46. private EstateTerrainXferHandler TerrainUploader = null;
  47. #region Packet Data Responders
  48. private void sendDetailedEstateData(IClientAPI remote_client, UUID invoice)
  49. {
  50. uint sun = 0;
  51. if (!m_scene.RegionInfo.EstateSettings.UseGlobalTime)
  52. sun=(uint)(m_scene.RegionInfo.EstateSettings.SunPosition*1024.0) + 0x1800;
  53. UUID estateOwner;
  54. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  55. estateOwner = m_scene.RegionInfo.EstateSettings.EstateOwner;
  56. else
  57. estateOwner = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  58. if (m_scene.Permissions.IsGod(remote_client.AgentId))
  59. estateOwner = remote_client.AgentId;
  60. remote_client.SendDetailedEstateData(invoice,
  61. m_scene.RegionInfo.EstateSettings.EstateName,
  62. m_scene.RegionInfo.EstateSettings.EstateID,
  63. m_scene.RegionInfo.EstateSettings.ParentEstateID,
  64. GetEstateFlags(),
  65. sun,
  66. m_scene.RegionInfo.RegionSettings.Covenant,
  67. m_scene.RegionInfo.EstateSettings.AbuseEmail,
  68. estateOwner);
  69. remote_client.SendEstateManagersList(invoice,
  70. m_scene.RegionInfo.EstateSettings.EstateManagers,
  71. m_scene.RegionInfo.EstateSettings.EstateID);
  72. remote_client.SendBannedUserList(invoice,
  73. m_scene.RegionInfo.EstateSettings.EstateBans,
  74. m_scene.RegionInfo.EstateSettings.EstateID);
  75. }
  76. private void estateSetRegionInfoHandler(bool blockTerraform, bool noFly, bool allowDamage, bool blockLandResell, int maxAgents, float objectBonusFactor,
  77. int matureLevel, bool restrictPushObject, bool allowParcelChanges)
  78. {
  79. if (blockTerraform)
  80. m_scene.RegionInfo.RegionSettings.BlockTerraform = true;
  81. else
  82. m_scene.RegionInfo.RegionSettings.BlockTerraform = false;
  83. if (noFly)
  84. m_scene.RegionInfo.RegionSettings.BlockFly = true;
  85. else
  86. m_scene.RegionInfo.RegionSettings.BlockFly = false;
  87. if (allowDamage)
  88. m_scene.RegionInfo.RegionSettings.AllowDamage = true;
  89. else
  90. m_scene.RegionInfo.RegionSettings.AllowDamage = false;
  91. if (blockLandResell)
  92. m_scene.RegionInfo.RegionSettings.AllowLandResell = false;
  93. else
  94. m_scene.RegionInfo.RegionSettings.AllowLandResell = true;
  95. m_scene.RegionInfo.RegionSettings.AgentLimit = (byte) maxAgents;
  96. m_scene.RegionInfo.RegionSettings.ObjectBonus = objectBonusFactor;
  97. if (matureLevel <= 13)
  98. m_scene.RegionInfo.RegionSettings.Maturity = 0;
  99. else
  100. m_scene.RegionInfo.RegionSettings.Maturity = 1;
  101. if (restrictPushObject)
  102. m_scene.RegionInfo.RegionSettings.RestrictPushing = true;
  103. else
  104. m_scene.RegionInfo.RegionSettings.RestrictPushing = false;
  105. if (allowParcelChanges)
  106. m_scene.RegionInfo.RegionSettings.AllowLandJoinDivide = true;
  107. else
  108. m_scene.RegionInfo.RegionSettings.AllowLandJoinDivide = false;
  109. m_scene.RegionInfo.RegionSettings.Save();
  110. sendRegionInfoPacketToAll();
  111. }
  112. public void setEstateTerrainBaseTexture(IClientAPI remoteClient, int corner, UUID texture)
  113. {
  114. if (texture == UUID.Zero)
  115. return;
  116. switch (corner)
  117. {
  118. case 0:
  119. m_scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  120. break;
  121. case 1:
  122. m_scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  123. break;
  124. case 2:
  125. m_scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  126. break;
  127. case 3:
  128. m_scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  129. break;
  130. }
  131. m_scene.RegionInfo.RegionSettings.Save();
  132. }
  133. public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue)
  134. {
  135. switch (corner)
  136. {
  137. case 0:
  138. m_scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  139. m_scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  140. break;
  141. case 1:
  142. m_scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  143. m_scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  144. break;
  145. case 2:
  146. m_scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  147. m_scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  148. break;
  149. case 3:
  150. m_scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  151. m_scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  152. break;
  153. }
  154. m_scene.RegionInfo.RegionSettings.Save();
  155. }
  156. private void handleCommitEstateTerrainTextureRequest(IClientAPI remoteClient)
  157. {
  158. sendRegionHandshakeToAll();
  159. }
  160. public void setRegionTerrainSettings(float WaterHeight,
  161. float TerrainRaiseLimit, float TerrainLowerLimit,
  162. bool UseEstateSun, bool UseFixedSun, float SunHour,
  163. bool UseGlobal, bool EstateFixedSun, float EstateSunHour)
  164. {
  165. // Water Height
  166. m_scene.RegionInfo.RegionSettings.WaterHeight = WaterHeight;
  167. // Terraforming limits
  168. m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit = TerrainRaiseLimit;
  169. m_scene.RegionInfo.RegionSettings.TerrainLowerLimit = TerrainLowerLimit;
  170. // Time of day / fixed sun
  171. m_scene.RegionInfo.RegionSettings.UseEstateSun = UseEstateSun;
  172. m_scene.RegionInfo.RegionSettings.FixedSun = UseFixedSun;
  173. m_scene.RegionInfo.RegionSettings.SunPosition = SunHour;
  174. m_scene.EventManager.TriggerEstateToolsTimeUpdate(m_scene.RegionInfo.RegionHandle, UseFixedSun, UseEstateSun, SunHour);
  175. //m_log.Debug("[ESTATE]: UFS: " + UseFixedSun.ToString());
  176. //m_log.Debug("[ESTATE]: SunHour: " + SunHour.ToString());
  177. sendRegionInfoPacketToAll();
  178. m_scene.RegionInfo.RegionSettings.Save();
  179. }
  180. private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds)
  181. {
  182. m_scene.Restart(timeInSeconds);
  183. }
  184. private void handleChangeEstateCovenantRequest(IClientAPI remoteClient, UUID estateCovenantID)
  185. {
  186. m_scene.RegionInfo.RegionSettings.Covenant = estateCovenantID;
  187. m_scene.RegionInfo.RegionSettings.Save();
  188. }
  189. private void handleEstateAccessDeltaRequest(IClientAPI remote_client, UUID invoice, int estateAccessType, UUID user)
  190. {
  191. // EstateAccessDelta handles Estate Managers, Sim Access, Sim Banlist, allowed Groups.. etc.
  192. if (user == m_scene.RegionInfo.EstateSettings.EstateOwner)
  193. return; // never process EO
  194. if (user == m_scene.RegionInfo.MasterAvatarAssignedUUID)
  195. return; // never process owner
  196. switch (estateAccessType)
  197. {
  198. case 64:
  199. if (m_scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, false) || m_scene.Permissions.BypassPermissions())
  200. {
  201. EstateBan[] banlistcheck = m_scene.RegionInfo.EstateSettings.EstateBans;
  202. bool alreadyInList = false;
  203. for (int i = 0; i < banlistcheck.Length; i++)
  204. {
  205. if (user == banlistcheck[i].BannedUserID)
  206. {
  207. alreadyInList = true;
  208. break;
  209. }
  210. }
  211. if (!alreadyInList)
  212. {
  213. EstateBan item = new EstateBan();
  214. item.BannedUserID = user;
  215. item.EstateID = m_scene.RegionInfo.EstateSettings.EstateID;
  216. item.BannedHostAddress = "0.0.0.0";
  217. item.BannedHostIPMask = "0.0.0.0";
  218. m_scene.RegionInfo.EstateSettings.AddBan(item);
  219. m_scene.RegionInfo.EstateSettings.Save();
  220. ScenePresence s = m_scene.GetScenePresence(user);
  221. if (s != null)
  222. {
  223. if (!s.IsChildAgent)
  224. {
  225. s.ControllingClient.SendTeleportLocationStart();
  226. m_scene.TeleportClientHome(user, s.ControllingClient);
  227. }
  228. }
  229. }
  230. else
  231. {
  232. remote_client.SendAlertMessage("User is already on the region ban list");
  233. }
  234. //m_scene.RegionInfo.regionBanlist.Add(Manager(user);
  235. remote_client.SendBannedUserList(invoice, m_scene.RegionInfo.EstateSettings.EstateBans, m_scene.RegionInfo.EstateSettings.EstateID);
  236. }
  237. else
  238. {
  239. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  240. }
  241. break;
  242. case 128:
  243. if (m_scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, false) || m_scene.Permissions.BypassPermissions())
  244. {
  245. EstateBan[] banlistcheck = m_scene.RegionInfo.EstateSettings.EstateBans;
  246. bool alreadyInList = false;
  247. EstateBan listitem = null;
  248. for (int i = 0; i < banlistcheck.Length; i++)
  249. {
  250. if (user == banlistcheck[i].BannedUserID)
  251. {
  252. alreadyInList = true;
  253. listitem = banlistcheck[i];
  254. break;
  255. }
  256. }
  257. if (alreadyInList && listitem != null)
  258. {
  259. m_scene.RegionInfo.EstateSettings.RemoveBan(listitem.BannedUserID);
  260. m_scene.RegionInfo.EstateSettings.Save();
  261. }
  262. else
  263. {
  264. remote_client.SendAlertMessage("User is not on the region ban list");
  265. }
  266. //m_scene.RegionInfo.regionBanlist.Add(Manager(user);
  267. remote_client.SendBannedUserList(invoice, m_scene.RegionInfo.EstateSettings.EstateBans, m_scene.RegionInfo.EstateSettings.EstateID);
  268. }
  269. else
  270. {
  271. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  272. }
  273. break;
  274. case 256:
  275. if (m_scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true) || m_scene.Permissions.BypassPermissions())
  276. {
  277. m_scene.RegionInfo.EstateSettings.AddEstateManager(user);
  278. m_scene.RegionInfo.EstateSettings.Save();
  279. remote_client.SendEstateManagersList(invoice, m_scene.RegionInfo.EstateSettings.EstateManagers, m_scene.RegionInfo.EstateSettings.EstateID);
  280. }
  281. else
  282. {
  283. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  284. }
  285. break;
  286. case 512:
  287. if (m_scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true) || m_scene.Permissions.BypassPermissions())
  288. {
  289. m_scene.RegionInfo.EstateSettings.RemoveEstateManager(user);
  290. m_scene.RegionInfo.EstateSettings.Save();
  291. remote_client.SendEstateManagersList(invoice, m_scene.RegionInfo.EstateSettings.EstateManagers, m_scene.RegionInfo.EstateSettings.EstateID);
  292. }
  293. else
  294. {
  295. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  296. }
  297. break;
  298. default:
  299. m_log.ErrorFormat("EstateOwnerMessage: Unknown EstateAccessType requested in estateAccessDelta: {0}", estateAccessType.ToString());
  300. break;
  301. }
  302. }
  303. private void SendSimulatorBlueBoxMessage(
  304. IClientAPI remote_client, UUID invoice, UUID senderID, UUID sessionID, string senderName, string message)
  305. {
  306. IDialogModule dm = m_scene.RequestModuleInterface<IDialogModule>();
  307. if (dm != null)
  308. dm.SendNotificationToUsersInRegion(senderID, senderName, message);
  309. }
  310. private void SendEstateBlueBoxMessage(
  311. IClientAPI remote_client, UUID invoice, UUID senderID, UUID sessionID, string senderName, string message)
  312. {
  313. IDialogModule dm = m_scene.RequestModuleInterface<IDialogModule>();
  314. if (dm != null)
  315. dm.SendNotificationToUsersInEstate(senderID, senderName, message);
  316. }
  317. private void handleEstateDebugRegionRequest(IClientAPI remote_client, UUID invoice, UUID senderID, bool scripted, bool collisionEvents, bool physics)
  318. {
  319. if (physics)
  320. m_scene.RegionInfo.RegionSettings.DisablePhysics = true;
  321. else
  322. m_scene.RegionInfo.RegionSettings.DisablePhysics = false;
  323. if (scripted)
  324. m_scene.RegionInfo.RegionSettings.DisableScripts = true;
  325. else
  326. m_scene.RegionInfo.RegionSettings.DisableScripts = false;
  327. if (collisionEvents)
  328. m_scene.RegionInfo.RegionSettings.DisableCollisions = true;
  329. else
  330. m_scene.RegionInfo.RegionSettings.DisableCollisions = false;
  331. m_scene.RegionInfo.RegionSettings.Save();
  332. m_scene.SetSceneCoreDebug(scripted, collisionEvents, physics);
  333. }
  334. private void handleEstateTeleportOneUserHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID, UUID prey)
  335. {
  336. if (prey != UUID.Zero)
  337. {
  338. ScenePresence s = m_scene.GetScenePresence(prey);
  339. if (s != null)
  340. {
  341. s.ControllingClient.SendTeleportLocationStart();
  342. m_scene.TeleportClientHome(prey, s.ControllingClient);
  343. }
  344. }
  345. }
  346. private void handleEstateTeleportAllUsersHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID)
  347. {
  348. // Get a fresh list that will not change as people get teleported away
  349. List<ScenePresence> prescences = m_scene.GetScenePresences();
  350. foreach (ScenePresence p in prescences)
  351. {
  352. if (p.UUID != senderID)
  353. {
  354. // make sure they are still there, we could be working down a long list
  355. ScenePresence s = m_scene.GetScenePresence(p.UUID);
  356. if (s != null)
  357. {
  358. // Also make sure they are actually in the region
  359. if (!s.IsChildAgent)
  360. {
  361. s.ControllingClient.SendTeleportLocationStart();
  362. m_scene.TeleportClientHome(s.UUID, s.ControllingClient);
  363. }
  364. }
  365. }
  366. }
  367. }
  368. private void AbortTerrainXferHandler(IClientAPI remoteClient, ulong XferID)
  369. {
  370. if (TerrainUploader != null)
  371. {
  372. lock (TerrainUploader)
  373. {
  374. if (XferID == TerrainUploader.XferID)
  375. {
  376. remoteClient.OnXferReceive -= TerrainUploader.XferReceive;
  377. remoteClient.OnAbortXfer -= AbortTerrainXferHandler;
  378. TerrainUploader.TerrainUploadDone -= HandleTerrainApplication;
  379. TerrainUploader = null;
  380. remoteClient.SendAlertMessage("Terrain Upload aborted by the client");
  381. }
  382. }
  383. }
  384. }
  385. private void HandleTerrainApplication(string filename, byte[] terrainData, IClientAPI remoteClient)
  386. {
  387. lock (TerrainUploader)
  388. {
  389. remoteClient.OnXferReceive -= TerrainUploader.XferReceive;
  390. remoteClient.OnAbortXfer -= AbortTerrainXferHandler;
  391. TerrainUploader.TerrainUploadDone -= HandleTerrainApplication;
  392. TerrainUploader = null;
  393. }
  394. remoteClient.SendAlertMessage("Terrain Upload Complete. Loading....");
  395. ITerrainModule terr = m_scene.RequestModuleInterface<ITerrainModule>();
  396. if (terr != null)
  397. {
  398. m_log.Warn("[CLIENT]: Got Request to Send Terrain in region " + m_scene.RegionInfo.RegionName);
  399. if (File.Exists(Util.dataDir() + "/terrain.raw"))
  400. {
  401. File.Delete(Util.dataDir() + "/terrain.raw");
  402. }
  403. try
  404. {
  405. FileStream input = new FileStream(Util.dataDir() + "/terrain.raw", FileMode.CreateNew);
  406. input.Write(terrainData, 0, terrainData.Length);
  407. input.Close();
  408. }
  409. catch (IOException e)
  410. {
  411. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  412. remoteClient.SendAlertMessage("There was an IO Exception loading your terrain. Please check free space");
  413. return;
  414. }
  415. catch (SecurityException e)
  416. {
  417. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  418. remoteClient.SendAlertMessage("There was a security Exception loading your terrain. Please check the security on the simulator drive");
  419. return;
  420. }
  421. catch (UnauthorizedAccessException e)
  422. {
  423. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  424. remoteClient.SendAlertMessage("There was a security Exception loading your terrain. Please check the security on the simulator drive");
  425. return;
  426. }
  427. try
  428. {
  429. terr.LoadFromFile(Util.dataDir() + "/terrain.raw");
  430. remoteClient.SendAlertMessage("Your terrain was loaded. Give it a minute or two to apply");
  431. }
  432. catch (Exception e)
  433. {
  434. m_log.ErrorFormat("[TERRAIN]: Error loading a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  435. remoteClient.SendAlertMessage("There was a general error loading your terrain. Please fix the terrain file and try again");
  436. }
  437. }
  438. else
  439. {
  440. remoteClient.SendAlertMessage("Unable to apply terrain. Cannot get an instance of the terrain module");
  441. }
  442. }
  443. private void handleUploadTerrain(IClientAPI remote_client, string clientFileName)
  444. {
  445. if (TerrainUploader == null)
  446. {
  447. TerrainUploader = new EstateTerrainXferHandler(remote_client, clientFileName);
  448. lock (TerrainUploader)
  449. {
  450. remote_client.OnXferReceive += TerrainUploader.XferReceive;
  451. remote_client.OnAbortXfer += AbortTerrainXferHandler;
  452. TerrainUploader.TerrainUploadDone += HandleTerrainApplication;
  453. }
  454. TerrainUploader.RequestStartXfer(remote_client);
  455. }
  456. else
  457. {
  458. remote_client.SendAlertMessage("Another Terrain Upload is in progress. Please wait your turn!");
  459. }
  460. }
  461. private void handleTerrainRequest(IClientAPI remote_client, string clientFileName)
  462. {
  463. // Save terrain here
  464. ITerrainModule terr = m_scene.RequestModuleInterface<ITerrainModule>();
  465. if (terr != null)
  466. {
  467. m_log.Warn("[CLIENT]: Got Request to Send Terrain in region " + m_scene.RegionInfo.RegionName);
  468. if (File.Exists(Util.dataDir() + "/terrain.raw"))
  469. {
  470. File.Delete(Util.dataDir() + "/terrain.raw");
  471. }
  472. terr.SaveToFile(Util.dataDir() + "/terrain.raw");
  473. FileStream input = new FileStream(Util.dataDir() + "/terrain.raw", FileMode.Open);
  474. byte[] bdata = new byte[input.Length];
  475. input.Read(bdata, 0, (int)input.Length);
  476. remote_client.SendAlertMessage("Terrain file written, starting download...");
  477. m_scene.XferManager.AddNewFile("terrain.raw", bdata);
  478. // Tell client about it
  479. m_log.Warn("[CLIENT]: Sending Terrain to " + remote_client.Name);
  480. remote_client.SendInitiateDownload("terrain.raw", clientFileName);
  481. }
  482. }
  483. private void HandleRegionInfoRequest(IClientAPI remote_client)
  484. {
  485. RegionInfoForEstateMenuArgs args = new RegionInfoForEstateMenuArgs();
  486. args.billableFactor = m_scene.RegionInfo.EstateSettings.BillableFactor;
  487. args.estateID = m_scene.RegionInfo.EstateSettings.EstateID;
  488. args.maxAgents = (byte)m_scene.RegionInfo.RegionSettings.AgentLimit;
  489. args.objectBonusFactor = (float)m_scene.RegionInfo.RegionSettings.ObjectBonus;
  490. args.parentEstateID = m_scene.RegionInfo.EstateSettings.ParentEstateID;
  491. args.pricePerMeter = m_scene.RegionInfo.EstateSettings.PricePerMeter;
  492. args.redirectGridX = m_scene.RegionInfo.EstateSettings.RedirectGridX;
  493. args.redirectGridY = m_scene.RegionInfo.EstateSettings.RedirectGridY;
  494. args.regionFlags = GetRegionFlags();
  495. byte mature = 13;
  496. if (m_scene.RegionInfo.RegionSettings.Maturity == 1)
  497. mature = 21;
  498. args.simAccess = mature;
  499. args.sunHour = (float)m_scene.RegionInfo.RegionSettings.SunPosition;
  500. args.terrainLowerLimit = (float)m_scene.RegionInfo.RegionSettings.TerrainLowerLimit;
  501. args.terrainRaiseLimit = (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
  502. args.useEstateSun = m_scene.RegionInfo.RegionSettings.UseEstateSun;
  503. args.waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
  504. args.simName = m_scene.RegionInfo.RegionName;
  505. remote_client.SendRegionInfoToEstateMenu(args);
  506. }
  507. private void HandleEstateCovenantRequest(IClientAPI remote_client)
  508. {
  509. remote_client.SendEstateCovenantInformation(m_scene.RegionInfo.RegionSettings.Covenant);
  510. }
  511. private void HandleLandStatRequest(int parcelID, uint reportType, uint requestFlags, string filter, IClientAPI remoteClient)
  512. {
  513. Dictionary<uint, float> SceneData = new Dictionary<uint,float>();
  514. List<UUID> uuidNameLookupList = new List<UUID>();
  515. if (reportType == 1)
  516. {
  517. SceneData = m_scene.PhysicsScene.GetTopColliders();
  518. }
  519. else if (reportType == 0)
  520. {
  521. SceneData = m_scene.SceneGraph.GetTopScripts();
  522. }
  523. List<LandStatReportItem> SceneReport = new List<LandStatReportItem>();
  524. lock (SceneData)
  525. {
  526. foreach (uint obj in SceneData.Keys)
  527. {
  528. SceneObjectPart prt = m_scene.GetSceneObjectPart(obj);
  529. if (prt != null)
  530. {
  531. if (prt.ParentGroup != null)
  532. {
  533. SceneObjectGroup sog = prt.ParentGroup;
  534. if (sog != null)
  535. {
  536. LandStatReportItem lsri = new LandStatReportItem();
  537. lsri.LocationX = sog.AbsolutePosition.X;
  538. lsri.LocationY = sog.AbsolutePosition.Y;
  539. lsri.LocationZ = sog.AbsolutePosition.Z;
  540. lsri.Score = SceneData[obj];
  541. lsri.TaskID = sog.UUID;
  542. lsri.TaskLocalID = sog.LocalId;
  543. lsri.TaskName = sog.GetPartName(obj);
  544. if (m_scene.CommsManager.UUIDNameCachedTest(sog.OwnerID))
  545. {
  546. lsri.OwnerName = m_scene.CommsManager.UUIDNameRequestString(sog.OwnerID);
  547. }
  548. else
  549. {
  550. lsri.OwnerName = "waiting";
  551. lock (uuidNameLookupList)
  552. uuidNameLookupList.Add(sog.OwnerID);
  553. }
  554. if (filter.Length != 0)
  555. {
  556. if ((lsri.OwnerName.Contains(filter) || lsri.TaskName.Contains(filter)))
  557. {
  558. }
  559. else
  560. {
  561. continue;
  562. }
  563. }
  564. SceneReport.Add(lsri);
  565. }
  566. }
  567. }
  568. }
  569. }
  570. remoteClient.SendLandStatReply(reportType, requestFlags, (uint)SceneReport.Count,SceneReport.ToArray());
  571. if (uuidNameLookupList.Count > 0)
  572. LookupUUID(uuidNameLookupList);
  573. }
  574. private void LookupUUIDSCompleted(IAsyncResult iar)
  575. {
  576. LookupUUIDS icon = (LookupUUIDS)iar.AsyncState;
  577. icon.EndInvoke(iar);
  578. }
  579. private void LookupUUID(List<UUID> uuidLst)
  580. {
  581. LookupUUIDS d = LookupUUIDsAsync;
  582. d.BeginInvoke(uuidLst,
  583. LookupUUIDSCompleted,
  584. d);
  585. }
  586. private void LookupUUIDsAsync(List<UUID> uuidLst)
  587. {
  588. UUID[] uuidarr = new UUID[0];
  589. lock (uuidLst)
  590. {
  591. uuidarr = uuidLst.ToArray();
  592. }
  593. for (int i = 0; i < uuidarr.Length; i++)
  594. {
  595. // string lookupname = m_scene.CommsManager.UUIDNameRequestString(uuidarr[i]);
  596. m_scene.CommsManager.UUIDNameRequestString(uuidarr[i]);
  597. // we drop it. It gets cached though... so we're ready for the next request.
  598. }
  599. }
  600. #endregion
  601. #region Outgoing Packets
  602. public void sendRegionInfoPacketToAll()
  603. {
  604. List<ScenePresence> avatars = m_scene.GetAvatars();
  605. for (int i = 0; i < avatars.Count; i++)
  606. {
  607. HandleRegionInfoRequest(avatars[i].ControllingClient); ;
  608. }
  609. }
  610. public void sendRegionHandshake(IClientAPI remoteClient)
  611. {
  612. RegionHandshakeArgs args = new RegionHandshakeArgs();
  613. args.isEstateManager = m_scene.RegionInfo.EstateSettings.IsEstateManager(remoteClient.AgentId);
  614. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero && m_scene.RegionInfo.EstateSettings.EstateOwner == remoteClient.AgentId)
  615. args.isEstateManager = true;
  616. args.billableFactor = m_scene.RegionInfo.EstateSettings.BillableFactor;
  617. args.terrainStartHeight0 = (float)m_scene.RegionInfo.RegionSettings.Elevation1SW;
  618. args.terrainHeightRange0 = (float)m_scene.RegionInfo.RegionSettings.Elevation2SW;
  619. args.terrainStartHeight1 = (float)m_scene.RegionInfo.RegionSettings.Elevation1NW;
  620. args.terrainHeightRange1 = (float)m_scene.RegionInfo.RegionSettings.Elevation2NW;
  621. args.terrainStartHeight2 = (float)m_scene.RegionInfo.RegionSettings.Elevation1SE;
  622. args.terrainHeightRange2 = (float)m_scene.RegionInfo.RegionSettings.Elevation2SE;
  623. args.terrainStartHeight3 = (float)m_scene.RegionInfo.RegionSettings.Elevation1NE;
  624. args.terrainHeightRange3 = (float)m_scene.RegionInfo.RegionSettings.Elevation2NE;
  625. byte mature = 13;
  626. if (m_scene.RegionInfo.RegionSettings.Maturity == 1)
  627. mature = 21;
  628. args.simAccess = mature;
  629. args.waterHeight = (float)m_scene.RegionInfo.RegionSettings.WaterHeight;
  630. args.regionFlags = GetRegionFlags();
  631. args.regionName = m_scene.RegionInfo.RegionName;
  632. if (m_scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero)
  633. args.SimOwner = m_scene.RegionInfo.EstateSettings.EstateOwner;
  634. else
  635. args.SimOwner = m_scene.RegionInfo.MasterAvatarAssignedUUID;
  636. // Fudge estate owner
  637. //if (m_scene.Permissions.IsGod(remoteClient.AgentId))
  638. // args.SimOwner = remoteClient.AgentId;
  639. args.terrainBase0 = UUID.Zero;
  640. args.terrainBase1 = UUID.Zero;
  641. args.terrainBase2 = UUID.Zero;
  642. args.terrainBase3 = UUID.Zero;
  643. args.terrainDetail0 = m_scene.RegionInfo.RegionSettings.TerrainTexture1;
  644. args.terrainDetail1 = m_scene.RegionInfo.RegionSettings.TerrainTexture2;
  645. args.terrainDetail2 = m_scene.RegionInfo.RegionSettings.TerrainTexture3;
  646. args.terrainDetail3 = m_scene.RegionInfo.RegionSettings.TerrainTexture4;
  647. remoteClient.SendRegionHandshake(m_scene.RegionInfo,args);
  648. }
  649. public void sendRegionHandshakeToAll()
  650. {
  651. m_scene.Broadcast(sendRegionHandshake);
  652. }
  653. public void handleEstateChangeInfo(IClientAPI remoteClient, UUID invoice, UUID senderID, UInt32 parms1, UInt32 parms2)
  654. {
  655. if (parms2 == 0)
  656. {
  657. m_scene.RegionInfo.EstateSettings.UseGlobalTime = true;
  658. m_scene.RegionInfo.EstateSettings.SunPosition = 0.0;
  659. }
  660. else
  661. {
  662. m_scene.RegionInfo.EstateSettings.UseGlobalTime = false;
  663. m_scene.RegionInfo.EstateSettings.SunPosition = (double)(parms2 - 0x1800)/1024.0;
  664. }
  665. if ((parms1 & 0x00000010) != 0)
  666. m_scene.RegionInfo.EstateSettings.FixedSun = true;
  667. else
  668. m_scene.RegionInfo.EstateSettings.FixedSun = false;
  669. if ((parms1 & 0x00008000) != 0)
  670. m_scene.RegionInfo.EstateSettings.PublicAccess = true;
  671. else
  672. m_scene.RegionInfo.EstateSettings.PublicAccess = false;
  673. if ((parms1 & 0x10000000) != 0)
  674. m_scene.RegionInfo.EstateSettings.AllowVoice = true;
  675. else
  676. m_scene.RegionInfo.EstateSettings.AllowVoice = false;
  677. if ((parms1 & 0x00100000) != 0)
  678. m_scene.RegionInfo.EstateSettings.AllowDirectTeleport = true;
  679. else
  680. m_scene.RegionInfo.EstateSettings.AllowDirectTeleport = false;
  681. if ((parms1 & 0x00800000) != 0)
  682. m_scene.RegionInfo.EstateSettings.DenyAnonymous = true;
  683. else
  684. m_scene.RegionInfo.EstateSettings.DenyAnonymous = false;
  685. if ((parms1 & 0x01000000) != 0)
  686. m_scene.RegionInfo.EstateSettings.DenyIdentified = true;
  687. else
  688. m_scene.RegionInfo.EstateSettings.DenyIdentified = false;
  689. if ((parms1 & 0x02000000) != 0)
  690. m_scene.RegionInfo.EstateSettings.DenyTransacted = true;
  691. else
  692. m_scene.RegionInfo.EstateSettings.DenyTransacted = false;
  693. if ((parms1 & 0x40000000) != 0)
  694. m_scene.RegionInfo.EstateSettings.DenyMinors = true;
  695. else
  696. m_scene.RegionInfo.EstateSettings.DenyMinors = false;
  697. m_scene.RegionInfo.EstateSettings.Save();
  698. float sun = (float)m_scene.RegionInfo.RegionSettings.SunPosition;
  699. if (m_scene.RegionInfo.RegionSettings.UseEstateSun)
  700. {
  701. sun = (float)m_scene.RegionInfo.EstateSettings.SunPosition;
  702. if (m_scene.RegionInfo.EstateSettings.UseGlobalTime)
  703. sun = m_scene.EventManager.GetSunLindenHour();
  704. }
  705. m_scene.EventManager.TriggerEstateToolsTimeUpdate(
  706. m_scene.RegionInfo.RegionHandle,
  707. m_scene.RegionInfo.EstateSettings.FixedSun ||
  708. m_scene.RegionInfo.RegionSettings.FixedSun,
  709. m_scene.RegionInfo.RegionSettings.UseEstateSun, sun);
  710. sendDetailedEstateData(remoteClient, invoice);
  711. }
  712. #endregion
  713. #region IRegionModule Members
  714. public void Initialise(Scene scene, IConfigSource source)
  715. {
  716. m_scene = scene;
  717. m_scene.RegisterModuleInterface<IEstateModule>(this);
  718. m_scene.EventManager.OnNewClient += EventManager_OnNewClient;
  719. m_scene.EventManager.OnRequestChangeWaterHeight += changeWaterHeight;
  720. }
  721. public void PostInitialise()
  722. {
  723. }
  724. public void Close()
  725. {
  726. }
  727. public string Name
  728. {
  729. get { return "EstateManagementModule"; }
  730. }
  731. public bool IsSharedModule
  732. {
  733. get { return false; }
  734. }
  735. #endregion
  736. #region Other Functions
  737. public void changeWaterHeight(float height)
  738. {
  739. setRegionTerrainSettings(height,
  740. (float)m_scene.RegionInfo.RegionSettings.TerrainRaiseLimit,
  741. (float)m_scene.RegionInfo.RegionSettings.TerrainLowerLimit,
  742. m_scene.RegionInfo.RegionSettings.UseEstateSun,
  743. m_scene.RegionInfo.RegionSettings.FixedSun,
  744. (float)m_scene.RegionInfo.RegionSettings.SunPosition,
  745. m_scene.RegionInfo.EstateSettings.UseGlobalTime,
  746. m_scene.RegionInfo.EstateSettings.FixedSun,
  747. (float)m_scene.RegionInfo.EstateSettings.SunPosition);
  748. sendRegionInfoPacketToAll();
  749. }
  750. #endregion
  751. private void EventManager_OnNewClient(IClientAPI client)
  752. {
  753. client.OnDetailedEstateDataRequest += sendDetailedEstateData;
  754. client.OnSetEstateFlagsRequest += estateSetRegionInfoHandler;
  755. // client.OnSetEstateTerrainBaseTexture += setEstateTerrainBaseTexture;
  756. client.OnSetEstateTerrainDetailTexture += setEstateTerrainBaseTexture;
  757. client.OnSetEstateTerrainTextureHeights += setEstateTerrainTextureHeights;
  758. client.OnCommitEstateTerrainTextureRequest += handleCommitEstateTerrainTextureRequest;
  759. client.OnSetRegionTerrainSettings += setRegionTerrainSettings;
  760. client.OnEstateRestartSimRequest += handleEstateRestartSimRequest;
  761. client.OnEstateChangeCovenantRequest += handleChangeEstateCovenantRequest;
  762. client.OnEstateChangeInfo += handleEstateChangeInfo;
  763. client.OnUpdateEstateAccessDeltaRequest += handleEstateAccessDeltaRequest;
  764. client.OnSimulatorBlueBoxMessageRequest += SendSimulatorBlueBoxMessage;
  765. client.OnEstateBlueBoxMessageRequest += SendEstateBlueBoxMessage;
  766. client.OnEstateDebugRegionRequest += handleEstateDebugRegionRequest;
  767. client.OnEstateTeleportOneUserHomeRequest += handleEstateTeleportOneUserHomeRequest;
  768. client.OnEstateTeleportAllUsersHomeRequest += handleEstateTeleportAllUsersHomeRequest;
  769. client.OnRequestTerrain += handleTerrainRequest;
  770. client.OnUploadTerrain += handleUploadTerrain;
  771. client.OnRegionInfoRequest += HandleRegionInfoRequest;
  772. client.OnEstateCovenantRequest += HandleEstateCovenantRequest;
  773. client.OnLandStatRequest += HandleLandStatRequest;
  774. sendRegionHandshake(client);
  775. }
  776. public uint GetRegionFlags()
  777. {
  778. RegionFlags flags = RegionFlags.None;
  779. // Fully implemented
  780. //
  781. if (m_scene.RegionInfo.RegionSettings.AllowDamage)
  782. flags |= RegionFlags.AllowDamage;
  783. if (m_scene.RegionInfo.RegionSettings.BlockTerraform)
  784. flags |= RegionFlags.BlockTerraform;
  785. if (!m_scene.RegionInfo.RegionSettings.AllowLandResell)
  786. flags |= RegionFlags.BlockLandResell;
  787. if (m_scene.RegionInfo.RegionSettings.DisableCollisions)
  788. flags |= RegionFlags.SkipCollisions;
  789. if (m_scene.RegionInfo.RegionSettings.DisableScripts)
  790. flags |= RegionFlags.SkipScripts;
  791. if (m_scene.RegionInfo.RegionSettings.DisablePhysics)
  792. flags |= RegionFlags.SkipPhysics;
  793. if (m_scene.RegionInfo.RegionSettings.BlockFly)
  794. flags |= RegionFlags.NoFly;
  795. if (m_scene.RegionInfo.RegionSettings.RestrictPushing)
  796. flags |= RegionFlags.RestrictPushObject;
  797. if (m_scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
  798. flags |= RegionFlags.AllowParcelChanges;
  799. if (m_scene.RegionInfo.RegionSettings.BlockShowInSearch)
  800. flags |= (RegionFlags)(1 << 29);
  801. if (m_scene.RegionInfo.RegionSettings.FixedSun)
  802. flags |= RegionFlags.SunFixed;
  803. if (m_scene.RegionInfo.RegionSettings.Sandbox)
  804. flags |= RegionFlags.Sandbox;
  805. // Fudge these to always on, so the menu options activate
  806. //
  807. flags |= RegionFlags.AllowLandmark;
  808. flags |= RegionFlags.AllowSetHome;
  809. // TODO: SkipUpdateInterestList
  810. // Omitted
  811. //
  812. // Omitted: NullLayer (what is that?)
  813. // Omitted: SkipAgentAction (what does it do?)
  814. return (uint)flags;
  815. }
  816. public uint GetEstateFlags()
  817. {
  818. RegionFlags flags = RegionFlags.None;
  819. if (m_scene.RegionInfo.EstateSettings.FixedSun)
  820. flags |= RegionFlags.SunFixed;
  821. if (m_scene.RegionInfo.EstateSettings.PublicAccess)
  822. flags |= (RegionFlags.PublicAllowed |
  823. RegionFlags.ExternallyVisible);
  824. if (m_scene.RegionInfo.EstateSettings.AllowVoice)
  825. flags |= RegionFlags.AllowVoice;
  826. if (m_scene.RegionInfo.EstateSettings.AllowDirectTeleport)
  827. flags |= RegionFlags.AllowDirectTeleport;
  828. if (m_scene.RegionInfo.EstateSettings.DenyAnonymous)
  829. flags |= RegionFlags.DenyAnonymous;
  830. if (m_scene.RegionInfo.EstateSettings.DenyIdentified)
  831. flags |= RegionFlags.DenyIdentified;
  832. if (m_scene.RegionInfo.EstateSettings.DenyTransacted)
  833. flags |= RegionFlags.DenyTransacted;
  834. if (m_scene.RegionInfo.EstateSettings.AbuseEmailToEstateOwner)
  835. flags |= RegionFlags.AbuseEmailToEstateOwner;
  836. if (m_scene.RegionInfo.EstateSettings.BlockDwell)
  837. flags |= RegionFlags.BlockDwell;
  838. if (m_scene.RegionInfo.EstateSettings.EstateSkipScripts)
  839. flags |= RegionFlags.EstateSkipScripts;
  840. if (m_scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
  841. flags |= RegionFlags.ResetHomeOnTeleport;
  842. if (m_scene.RegionInfo.EstateSettings.TaxFree)
  843. flags |= RegionFlags.TaxFree;
  844. if (m_scene.RegionInfo.EstateSettings.DenyMinors)
  845. flags |= (RegionFlags)(1 << 30);
  846. return (uint)flags;
  847. }
  848. public bool IsManager(UUID avatarID)
  849. {
  850. if (avatarID == m_scene.RegionInfo.MasterAvatarAssignedUUID)
  851. return true;
  852. if (avatarID == m_scene.RegionInfo.EstateSettings.EstateOwner)
  853. return true;
  854. List<UUID> ems = new List<UUID>(m_scene.RegionInfo.EstateSettings.EstateManagers);
  855. if (ems.Contains(avatarID))
  856. return true;
  857. return false;
  858. }
  859. }
  860. }