EstateManagementModule.cs 44 KB

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