EstateManagementModule.cs 44 KB

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