EstateManagementModule.cs 44 KB

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