EstateManagementModule.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  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;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.Linq;
  32. using System.Reflection;
  33. using System.Security;
  34. using System.Timers;
  35. using log4net;
  36. using Mono.Addins;
  37. using Nini.Config;
  38. using OpenMetaverse;
  39. using OpenSim.Framework;
  40. using OpenSim.Region.Framework.Interfaces;
  41. using OpenSim.Region.Framework.Scenes;
  42. using RegionFlags = OpenMetaverse.RegionFlags;
  43. namespace OpenSim.Region.CoreModules.World.Estate
  44. {
  45. [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "EstateManagementModule")]
  46. public class EstateManagementModule : IEstateModule, INonSharedRegionModule
  47. {
  48. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  49. private Timer m_regionChangeTimer = new Timer();
  50. public Scene Scene { get; private set; }
  51. public IUserManagement UserManager { get; private set; }
  52. protected EstateManagementCommands m_commands;
  53. /// <summary>
  54. /// If false, region restart requests from the client are blocked even if they are otherwise legitimate.
  55. /// </summary>
  56. public bool AllowRegionRestartFromClient { get; set; }
  57. private EstateTerrainXferHandler TerrainUploader;
  58. public TelehubManager m_Telehub;
  59. public event ChangeDelegate OnRegionInfoChange;
  60. public event ChangeDelegate OnEstateInfoChange;
  61. public event MessageDelegate OnEstateMessage;
  62. private int m_delayCount = 0;
  63. #region Region Module interface
  64. public string Name { get { return "EstateManagementModule"; } }
  65. public Type ReplaceableInterface { get { return null; } }
  66. public void Initialise(IConfigSource source)
  67. {
  68. AllowRegionRestartFromClient = true;
  69. IConfig config = source.Configs["EstateManagement"];
  70. if (config != null)
  71. AllowRegionRestartFromClient = config.GetBoolean("AllowRegionRestartFromClient", true);
  72. }
  73. public void AddRegion(Scene scene)
  74. {
  75. Scene = scene;
  76. Scene.RegisterModuleInterface<IEstateModule>(this);
  77. Scene.EventManager.OnNewClient += EventManager_OnNewClient;
  78. Scene.EventManager.OnRequestChangeWaterHeight += changeWaterHeight;
  79. m_Telehub = new TelehubManager(scene);
  80. m_commands = new EstateManagementCommands(this);
  81. m_commands.Initialise();
  82. }
  83. public void RemoveRegion(Scene scene) {}
  84. public void RegionLoaded(Scene scene)
  85. {
  86. // Sets up the sun module based no the saved Estate and Region Settings
  87. // DO NOT REMOVE or the sun will stop working
  88. scene.TriggerEstateSunUpdate();
  89. UserManager = scene.RequestModuleInterface<IUserManagement>();
  90. }
  91. public void Close()
  92. {
  93. m_commands.Close();
  94. }
  95. #endregion
  96. #region Packet Data Responders
  97. private void clientSendDetailedEstateData(IClientAPI remote_client, UUID invoice)
  98. {
  99. sendDetailedEstateData(remote_client, invoice);
  100. sendEstateLists(remote_client, invoice);
  101. }
  102. private void sendDetailedEstateData(IClientAPI remote_client, UUID invoice)
  103. {
  104. uint sun = 0;
  105. if (Scene.RegionInfo.EstateSettings.FixedSun)
  106. sun = (uint)(Scene.RegionInfo.EstateSettings.SunPosition * 1024.0) + 0x1800;
  107. UUID estateOwner;
  108. estateOwner = Scene.RegionInfo.EstateSettings.EstateOwner;
  109. if (Scene.Permissions.IsGod(remote_client.AgentId))
  110. estateOwner = remote_client.AgentId;
  111. remote_client.SendDetailedEstateData(invoice,
  112. Scene.RegionInfo.EstateSettings.EstateName,
  113. Scene.RegionInfo.EstateSettings.EstateID,
  114. Scene.RegionInfo.EstateSettings.ParentEstateID,
  115. GetEstateFlags(),
  116. sun,
  117. Scene.RegionInfo.RegionSettings.Covenant,
  118. (uint) Scene.RegionInfo.RegionSettings.CovenantChangedDateTime,
  119. Scene.RegionInfo.EstateSettings.AbuseEmail,
  120. estateOwner);
  121. }
  122. private void sendEstateLists(IClientAPI remote_client, UUID invoice)
  123. {
  124. remote_client.SendEstateList(invoice,
  125. (int)Constants.EstateAccessCodex.EstateManagers,
  126. Scene.RegionInfo.EstateSettings.EstateManagers,
  127. Scene.RegionInfo.EstateSettings.EstateID);
  128. remote_client.SendEstateList(invoice,
  129. (int)Constants.EstateAccessCodex.AccessOptions,
  130. Scene.RegionInfo.EstateSettings.EstateAccess,
  131. Scene.RegionInfo.EstateSettings.EstateID);
  132. remote_client.SendEstateList(invoice,
  133. (int)Constants.EstateAccessCodex.AllowedGroups,
  134. Scene.RegionInfo.EstateSettings.EstateGroups,
  135. Scene.RegionInfo.EstateSettings.EstateID);
  136. remote_client.SendBannedUserList(invoice,
  137. Scene.RegionInfo.EstateSettings.EstateBans,
  138. Scene.RegionInfo.EstateSettings.EstateID);
  139. }
  140. private void estateSetRegionInfoHandler(bool blockTerraform, bool noFly, bool allowDamage, bool blockLandResell, int maxAgents, float objectBonusFactor,
  141. int matureLevel, bool restrictPushObject, bool allowParcelChanges)
  142. {
  143. if (blockTerraform)
  144. Scene.RegionInfo.RegionSettings.BlockTerraform = true;
  145. else
  146. Scene.RegionInfo.RegionSettings.BlockTerraform = false;
  147. if (noFly)
  148. Scene.RegionInfo.RegionSettings.BlockFly = true;
  149. else
  150. Scene.RegionInfo.RegionSettings.BlockFly = false;
  151. if (allowDamage)
  152. Scene.RegionInfo.RegionSettings.AllowDamage = true;
  153. else
  154. Scene.RegionInfo.RegionSettings.AllowDamage = false;
  155. if (blockLandResell)
  156. Scene.RegionInfo.RegionSettings.AllowLandResell = false;
  157. else
  158. Scene.RegionInfo.RegionSettings.AllowLandResell = true;
  159. if((byte)maxAgents <= Scene.RegionInfo.AgentCapacity)
  160. Scene.RegionInfo.RegionSettings.AgentLimit = (byte) maxAgents;
  161. else
  162. Scene.RegionInfo.RegionSettings.AgentLimit = Scene.RegionInfo.AgentCapacity;
  163. Scene.RegionInfo.RegionSettings.ObjectBonus = objectBonusFactor;
  164. if (matureLevel <= 13)
  165. Scene.RegionInfo.RegionSettings.Maturity = 0;
  166. else if (matureLevel <= 21)
  167. Scene.RegionInfo.RegionSettings.Maturity = 1;
  168. else
  169. Scene.RegionInfo.RegionSettings.Maturity = 2;
  170. if (restrictPushObject)
  171. Scene.RegionInfo.RegionSettings.RestrictPushing = true;
  172. else
  173. Scene.RegionInfo.RegionSettings.RestrictPushing = false;
  174. if (allowParcelChanges)
  175. Scene.RegionInfo.RegionSettings.AllowLandJoinDivide = true;
  176. else
  177. Scene.RegionInfo.RegionSettings.AllowLandJoinDivide = false;
  178. Scene.RegionInfo.RegionSettings.Save();
  179. TriggerRegionInfoChange();
  180. sendRegionInfoPacketToAll();
  181. }
  182. public void setEstateTerrainBaseTexture(int level, UUID texture)
  183. {
  184. setEstateTerrainBaseTexture(null, level, texture);
  185. sendRegionHandshakeToAll();
  186. }
  187. public void setEstateTerrainBaseTexture(IClientAPI remoteClient, int level, UUID texture)
  188. {
  189. if (texture == UUID.Zero)
  190. return;
  191. switch (level)
  192. {
  193. case 0:
  194. Scene.RegionInfo.RegionSettings.TerrainTexture1 = texture;
  195. break;
  196. case 1:
  197. Scene.RegionInfo.RegionSettings.TerrainTexture2 = texture;
  198. break;
  199. case 2:
  200. Scene.RegionInfo.RegionSettings.TerrainTexture3 = texture;
  201. break;
  202. case 3:
  203. Scene.RegionInfo.RegionSettings.TerrainTexture4 = texture;
  204. break;
  205. }
  206. Scene.RegionInfo.RegionSettings.Save();
  207. TriggerRegionInfoChange();
  208. sendRegionInfoPacketToAll();
  209. }
  210. public void setEstateTerrainTextureHeights(int corner, float lowValue, float highValue)
  211. {
  212. setEstateTerrainTextureHeights(null, corner, lowValue, highValue);
  213. }
  214. public void setEstateTerrainTextureHeights(IClientAPI client, int corner, float lowValue, float highValue)
  215. {
  216. switch (corner)
  217. {
  218. case 0:
  219. Scene.RegionInfo.RegionSettings.Elevation1SW = lowValue;
  220. Scene.RegionInfo.RegionSettings.Elevation2SW = highValue;
  221. break;
  222. case 1:
  223. Scene.RegionInfo.RegionSettings.Elevation1NW = lowValue;
  224. Scene.RegionInfo.RegionSettings.Elevation2NW = highValue;
  225. break;
  226. case 2:
  227. Scene.RegionInfo.RegionSettings.Elevation1SE = lowValue;
  228. Scene.RegionInfo.RegionSettings.Elevation2SE = highValue;
  229. break;
  230. case 3:
  231. Scene.RegionInfo.RegionSettings.Elevation1NE = lowValue;
  232. Scene.RegionInfo.RegionSettings.Elevation2NE = highValue;
  233. break;
  234. }
  235. Scene.RegionInfo.RegionSettings.Save();
  236. TriggerRegionInfoChange();
  237. sendRegionHandshakeToAll();
  238. sendRegionInfoPacketToAll();
  239. }
  240. private void handleCommitEstateTerrainTextureRequest(IClientAPI remoteClient)
  241. {
  242. // sendRegionHandshakeToAll();
  243. }
  244. public void setRegionTerrainSettings(float WaterHeight,
  245. float TerrainRaiseLimit, float TerrainLowerLimit,
  246. bool UseEstateSun, bool UseFixedSun, float SunHour,
  247. bool UseGlobal, bool EstateFixedSun, float EstateSunHour)
  248. {
  249. // Water Height
  250. Scene.RegionInfo.RegionSettings.WaterHeight = WaterHeight;
  251. // Terraforming limits
  252. Scene.RegionInfo.RegionSettings.TerrainRaiseLimit = TerrainRaiseLimit;
  253. Scene.RegionInfo.RegionSettings.TerrainLowerLimit = TerrainLowerLimit;
  254. // Time of day / fixed sun
  255. Scene.RegionInfo.RegionSettings.UseEstateSun = UseEstateSun;
  256. Scene.RegionInfo.RegionSettings.FixedSun = UseFixedSun;
  257. Scene.RegionInfo.RegionSettings.SunPosition = SunHour;
  258. Scene.TriggerEstateSunUpdate();
  259. //m_log.Debug("[ESTATE]: UFS: " + UseFixedSun.ToString());
  260. //m_log.Debug("[ESTATE]: SunHour: " + SunHour.ToString());
  261. sendRegionInfoPacketToAll();
  262. Scene.RegionInfo.RegionSettings.Save();
  263. TriggerRegionInfoChange();
  264. }
  265. private void handleEstateRestartSimRequest(IClientAPI remoteClient, int timeInSeconds)
  266. {
  267. if (!AllowRegionRestartFromClient)
  268. {
  269. remoteClient.SendAlertMessage("Region restart has been disabled on this simulator.");
  270. return;
  271. }
  272. IRestartModule restartModule = Scene.RequestModuleInterface<IRestartModule>();
  273. if (restartModule != null)
  274. {
  275. List<int> times = new List<int>();
  276. while (timeInSeconds > 0)
  277. {
  278. times.Add(timeInSeconds);
  279. if (timeInSeconds > 300)
  280. timeInSeconds -= 120;
  281. else if (timeInSeconds > 30)
  282. timeInSeconds -= 30;
  283. else
  284. timeInSeconds -= 15;
  285. }
  286. restartModule.ScheduleRestart(UUID.Zero, "Region will restart in {0}", times.ToArray(), false);
  287. m_log.InfoFormat(
  288. "User {0} requested restart of region {1} in {2} seconds",
  289. remoteClient.Name, Scene.Name, times.Count != 0 ? times[0] : 0);
  290. }
  291. }
  292. private void handleChangeEstateCovenantRequest(IClientAPI remoteClient, UUID estateCovenantID)
  293. {
  294. // m_log.DebugFormat(
  295. // "[ESTATE MANAGEMENT MODULE]: Handling request from {0} to change estate covenant to {1}",
  296. // remoteClient.Name, estateCovenantID);
  297. Scene.RegionInfo.RegionSettings.Covenant = estateCovenantID;
  298. Scene.RegionInfo.RegionSettings.CovenantChangedDateTime = Util.UnixTimeSinceEpoch();
  299. Scene.RegionInfo.RegionSettings.Save();
  300. TriggerRegionInfoChange();
  301. }
  302. private void handleEstateAccessDeltaRequest(IClientAPI remote_client, UUID invoice, int estateAccessType, UUID user)
  303. {
  304. // EstateAccessDelta handles Estate Managers, Sim Access, Sim Banlist, allowed Groups.. etc.
  305. if (user == Scene.RegionInfo.EstateSettings.EstateOwner)
  306. return; // never process EO
  307. if ((estateAccessType & 4) != 0) // User add
  308. {
  309. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  310. {
  311. if ((estateAccessType & 1) != 0) // All estates
  312. {
  313. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  314. EstateSettings estateSettings;
  315. foreach (int estateID in estateIDs)
  316. {
  317. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  318. {
  319. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  320. estateSettings.AddEstateUser(user);
  321. estateSettings.Save();
  322. }
  323. }
  324. }
  325. Scene.RegionInfo.EstateSettings.AddEstateUser(user);
  326. Scene.RegionInfo.EstateSettings.Save();
  327. TriggerEstateInfoChange();
  328. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.AccessOptions, Scene.RegionInfo.EstateSettings.EstateAccess, Scene.RegionInfo.EstateSettings.EstateID);
  329. }
  330. else
  331. {
  332. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  333. }
  334. }
  335. if ((estateAccessType & 8) != 0) // User remove
  336. {
  337. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  338. {
  339. if ((estateAccessType & 1) != 0) // All estates
  340. {
  341. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  342. EstateSettings estateSettings;
  343. foreach (int estateID in estateIDs)
  344. {
  345. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  346. {
  347. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  348. estateSettings.RemoveEstateUser(user);
  349. estateSettings.Save();
  350. }
  351. }
  352. }
  353. Scene.RegionInfo.EstateSettings.RemoveEstateUser(user);
  354. Scene.RegionInfo.EstateSettings.Save();
  355. TriggerEstateInfoChange();
  356. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.AccessOptions, Scene.RegionInfo.EstateSettings.EstateAccess, Scene.RegionInfo.EstateSettings.EstateID);
  357. }
  358. else
  359. {
  360. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  361. }
  362. }
  363. if ((estateAccessType & 16) != 0) // Group add
  364. {
  365. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  366. {
  367. if ((estateAccessType & 1) != 0) // All estates
  368. {
  369. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  370. EstateSettings estateSettings;
  371. foreach (int estateID in estateIDs)
  372. {
  373. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  374. {
  375. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  376. estateSettings.AddEstateGroup(user);
  377. estateSettings.Save();
  378. }
  379. }
  380. }
  381. Scene.RegionInfo.EstateSettings.AddEstateGroup(user);
  382. Scene.RegionInfo.EstateSettings.Save();
  383. TriggerEstateInfoChange();
  384. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.AllowedGroups, Scene.RegionInfo.EstateSettings.EstateGroups, Scene.RegionInfo.EstateSettings.EstateID);
  385. }
  386. else
  387. {
  388. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  389. }
  390. }
  391. if ((estateAccessType & 32) != 0) // Group remove
  392. {
  393. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  394. {
  395. if ((estateAccessType & 1) != 0) // All estates
  396. {
  397. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  398. EstateSettings estateSettings;
  399. foreach (int estateID in estateIDs)
  400. {
  401. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  402. {
  403. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  404. estateSettings.RemoveEstateGroup(user);
  405. estateSettings.Save();
  406. }
  407. }
  408. }
  409. Scene.RegionInfo.EstateSettings.RemoveEstateGroup(user);
  410. Scene.RegionInfo.EstateSettings.Save();
  411. TriggerEstateInfoChange();
  412. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.AllowedGroups, Scene.RegionInfo.EstateSettings.EstateGroups, Scene.RegionInfo.EstateSettings.EstateID);
  413. }
  414. else
  415. {
  416. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  417. }
  418. }
  419. if ((estateAccessType & 64) != 0) // Ban add
  420. {
  421. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, false))
  422. {
  423. EstateBan[] banlistcheck = Scene.RegionInfo.EstateSettings.EstateBans;
  424. bool alreadyInList = false;
  425. for (int i = 0; i < banlistcheck.Length; i++)
  426. {
  427. if (user == banlistcheck[i].BannedUserID)
  428. {
  429. alreadyInList = true;
  430. break;
  431. }
  432. }
  433. if (!alreadyInList)
  434. {
  435. if ((estateAccessType & 1) != 0) // All estates
  436. {
  437. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  438. EstateSettings estateSettings;
  439. foreach (int estateID in estateIDs)
  440. {
  441. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  442. {
  443. EstateBan bitem = new EstateBan();
  444. bitem.BannedUserID = user;
  445. bitem.EstateID = (uint)estateID;
  446. bitem.BannedHostAddress = "0.0.0.0";
  447. bitem.BannedHostIPMask = "0.0.0.0";
  448. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  449. estateSettings.AddBan(bitem);
  450. estateSettings.Save();
  451. }
  452. }
  453. }
  454. EstateBan item = new EstateBan();
  455. item.BannedUserID = user;
  456. item.EstateID = Scene.RegionInfo.EstateSettings.EstateID;
  457. item.BannedHostAddress = "0.0.0.0";
  458. item.BannedHostIPMask = "0.0.0.0";
  459. Scene.RegionInfo.EstateSettings.AddBan(item);
  460. Scene.RegionInfo.EstateSettings.Save();
  461. TriggerEstateInfoChange();
  462. ScenePresence s = Scene.GetScenePresence(user);
  463. if (s != null)
  464. {
  465. if (!s.IsChildAgent)
  466. {
  467. if (!Scene.TeleportClientHome(user, s.ControllingClient))
  468. {
  469. s.ControllingClient.Kick("Your access to the region was revoked and TP home failed - you have been logged out.");
  470. Scene.IncomingCloseAgent(s.UUID, false);
  471. }
  472. }
  473. }
  474. }
  475. else
  476. {
  477. remote_client.SendAlertMessage("User is already on the region ban list");
  478. }
  479. //Scene.RegionInfo.regionBanlist.Add(Manager(user);
  480. remote_client.SendBannedUserList(invoice, Scene.RegionInfo.EstateSettings.EstateBans, Scene.RegionInfo.EstateSettings.EstateID);
  481. }
  482. else
  483. {
  484. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  485. }
  486. }
  487. if ((estateAccessType & 128) != 0) // Ban remove
  488. {
  489. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, false))
  490. {
  491. EstateBan[] banlistcheck = Scene.RegionInfo.EstateSettings.EstateBans;
  492. bool alreadyInList = false;
  493. EstateBan listitem = null;
  494. for (int i = 0; i < banlistcheck.Length; i++)
  495. {
  496. if (user == banlistcheck[i].BannedUserID)
  497. {
  498. alreadyInList = true;
  499. listitem = banlistcheck[i];
  500. break;
  501. }
  502. }
  503. if (alreadyInList && listitem != null)
  504. {
  505. if ((estateAccessType & 1) != 0) // All estates
  506. {
  507. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  508. EstateSettings estateSettings;
  509. foreach (int estateID in estateIDs)
  510. {
  511. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  512. {
  513. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  514. estateSettings.RemoveBan(user);
  515. estateSettings.Save();
  516. }
  517. }
  518. }
  519. Scene.RegionInfo.EstateSettings.RemoveBan(listitem.BannedUserID);
  520. Scene.RegionInfo.EstateSettings.Save();
  521. TriggerEstateInfoChange();
  522. }
  523. else
  524. {
  525. remote_client.SendAlertMessage("User is not on the region ban list");
  526. }
  527. //Scene.RegionInfo.regionBanlist.Add(Manager(user);
  528. remote_client.SendBannedUserList(invoice, Scene.RegionInfo.EstateSettings.EstateBans, Scene.RegionInfo.EstateSettings.EstateID);
  529. }
  530. else
  531. {
  532. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  533. }
  534. }
  535. if ((estateAccessType & 256) != 0) // Manager add
  536. {
  537. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  538. {
  539. if ((estateAccessType & 1) != 0) // All estates
  540. {
  541. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  542. EstateSettings estateSettings;
  543. foreach (int estateID in estateIDs)
  544. {
  545. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  546. {
  547. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  548. estateSettings.AddEstateManager(user);
  549. estateSettings.Save();
  550. }
  551. }
  552. }
  553. Scene.RegionInfo.EstateSettings.AddEstateManager(user);
  554. Scene.RegionInfo.EstateSettings.Save();
  555. TriggerEstateInfoChange();
  556. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.EstateManagers, Scene.RegionInfo.EstateSettings.EstateManagers, Scene.RegionInfo.EstateSettings.EstateID);
  557. }
  558. else
  559. {
  560. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  561. }
  562. }
  563. if ((estateAccessType & 512) != 0) // Manager remove
  564. {
  565. if (Scene.Permissions.CanIssueEstateCommand(remote_client.AgentId, true))
  566. {
  567. if ((estateAccessType & 1) != 0) // All estates
  568. {
  569. List<int> estateIDs = Scene.EstateDataService.GetEstatesByOwner(Scene.RegionInfo.EstateSettings.EstateOwner);
  570. EstateSettings estateSettings;
  571. foreach (int estateID in estateIDs)
  572. {
  573. if (estateID != Scene.RegionInfo.EstateSettings.EstateID)
  574. {
  575. estateSettings = Scene.EstateDataService.LoadEstateSettings(estateID);
  576. estateSettings.RemoveEstateManager(user);
  577. estateSettings.Save();
  578. }
  579. }
  580. }
  581. Scene.RegionInfo.EstateSettings.RemoveEstateManager(user);
  582. Scene.RegionInfo.EstateSettings.Save();
  583. TriggerEstateInfoChange();
  584. remote_client.SendEstateList(invoice, (int)Constants.EstateAccessCodex.EstateManagers, Scene.RegionInfo.EstateSettings.EstateManagers, Scene.RegionInfo.EstateSettings.EstateID);
  585. }
  586. else
  587. {
  588. remote_client.SendAlertMessage("Method EstateAccessDelta Failed, you don't have permissions");
  589. }
  590. }
  591. }
  592. public void handleOnEstateManageTelehub(IClientAPI client, UUID invoice, UUID senderID, string cmd, uint param1)
  593. {
  594. SceneObjectPart part;
  595. switch (cmd)
  596. {
  597. case "info ui":
  598. break;
  599. case "connect":
  600. // Add the Telehub
  601. part = Scene.GetSceneObjectPart((uint)param1);
  602. if (part == null)
  603. return;
  604. SceneObjectGroup grp = part.ParentGroup;
  605. m_Telehub.Connect(grp);
  606. break;
  607. case "delete":
  608. // Disconnect Telehub
  609. m_Telehub.Disconnect();
  610. break;
  611. case "spawnpoint add":
  612. // Add SpawnPoint to the Telehub
  613. part = Scene.GetSceneObjectPart((uint)param1);
  614. if (part == null)
  615. return;
  616. m_Telehub.AddSpawnPoint(part.AbsolutePosition);
  617. break;
  618. case "spawnpoint remove":
  619. // Remove SpawnPoint from Telehub
  620. m_Telehub.RemoveSpawnPoint((int)param1);
  621. break;
  622. default:
  623. break;
  624. }
  625. SendTelehubInfo(client);
  626. }
  627. private void SendSimulatorBlueBoxMessage(
  628. IClientAPI remote_client, UUID invoice, UUID senderID, UUID sessionID, string senderName, string message)
  629. {
  630. IDialogModule dm = Scene.RequestModuleInterface<IDialogModule>();
  631. if (dm != null)
  632. dm.SendNotificationToUsersInRegion(senderID, senderName, message);
  633. }
  634. private void SendEstateBlueBoxMessage(
  635. IClientAPI remote_client, UUID invoice, UUID senderID, UUID sessionID, string senderName, string message)
  636. {
  637. TriggerEstateMessage(senderID, senderName, message);
  638. }
  639. private void handleEstateDebugRegionRequest(
  640. IClientAPI remote_client, UUID invoice, UUID senderID,
  641. bool disableScripts, bool disableCollisions, bool disablePhysics)
  642. {
  643. Scene.RegionInfo.RegionSettings.DisablePhysics = disablePhysics;
  644. Scene.RegionInfo.RegionSettings.DisableScripts = disableScripts;
  645. Scene.RegionInfo.RegionSettings.DisableCollisions = disableCollisions;
  646. Scene.RegionInfo.RegionSettings.Save();
  647. TriggerRegionInfoChange();
  648. ISceneCommandsModule scm = Scene.RequestModuleInterface<ISceneCommandsModule>();
  649. if (scm != null)
  650. {
  651. scm.SetSceneDebugOptions(
  652. new Dictionary<string, string>() {
  653. { "scripting", (!disableScripts).ToString() },
  654. { "collisions", (!disableCollisions).ToString() },
  655. { "physics", (!disablePhysics).ToString() }
  656. }
  657. );
  658. }
  659. }
  660. private void handleEstateTeleportOneUserHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID, UUID prey)
  661. {
  662. if (!Scene.Permissions.CanIssueEstateCommand(remover_client.AgentId, false))
  663. return;
  664. if (prey != UUID.Zero)
  665. {
  666. ScenePresence s = Scene.GetScenePresence(prey);
  667. if (s != null)
  668. {
  669. if (!Scene.TeleportClientHome(prey, s.ControllingClient))
  670. {
  671. s.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out.");
  672. Scene.IncomingCloseAgent(s.UUID, false);
  673. }
  674. }
  675. }
  676. }
  677. private void handleEstateTeleportAllUsersHomeRequest(IClientAPI remover_client, UUID invoice, UUID senderID)
  678. {
  679. if (!Scene.Permissions.CanIssueEstateCommand(remover_client.AgentId, false))
  680. return;
  681. Scene.ForEachRootClient(delegate(IClientAPI client)
  682. {
  683. if (client.AgentId != senderID)
  684. {
  685. // make sure they are still there, we could be working down a long list
  686. // Also make sure they are actually in the region
  687. ScenePresence p;
  688. if(Scene.TryGetScenePresence(client.AgentId, out p))
  689. {
  690. if (!Scene.TeleportClientHome(p.UUID, p.ControllingClient))
  691. {
  692. p.ControllingClient.Kick("You were teleported home by the region owner, but the TP failed - you have been logged out.");
  693. Scene.IncomingCloseAgent(p.UUID, false);
  694. }
  695. }
  696. }
  697. });
  698. }
  699. private void AbortTerrainXferHandler(IClientAPI remoteClient, ulong XferID)
  700. {
  701. if (TerrainUploader != null)
  702. {
  703. lock (TerrainUploader)
  704. {
  705. if (XferID == TerrainUploader.XferID)
  706. {
  707. remoteClient.OnXferReceive -= TerrainUploader.XferReceive;
  708. remoteClient.OnAbortXfer -= AbortTerrainXferHandler;
  709. TerrainUploader.TerrainUploadDone -= HandleTerrainApplication;
  710. TerrainUploader = null;
  711. remoteClient.SendAlertMessage("Terrain Upload aborted by the client");
  712. }
  713. }
  714. }
  715. }
  716. private void HandleTerrainApplication(string filename, byte[] terrainData, IClientAPI remoteClient)
  717. {
  718. lock (TerrainUploader)
  719. {
  720. remoteClient.OnXferReceive -= TerrainUploader.XferReceive;
  721. remoteClient.OnAbortXfer -= AbortTerrainXferHandler;
  722. TerrainUploader.TerrainUploadDone -= HandleTerrainApplication;
  723. TerrainUploader = null;
  724. }
  725. remoteClient.SendAlertMessage("Terrain Upload Complete. Loading....");
  726. ITerrainModule terr = Scene.RequestModuleInterface<ITerrainModule>();
  727. if (terr != null)
  728. {
  729. m_log.Warn("[CLIENT]: Got Request to Send Terrain in region " + Scene.RegionInfo.RegionName);
  730. try
  731. {
  732. MemoryStream terrainStream = new MemoryStream(terrainData);
  733. terr.LoadFromStream(filename, terrainStream);
  734. terrainStream.Close();
  735. FileInfo x = new FileInfo(filename);
  736. remoteClient.SendAlertMessage("Your terrain was loaded as a " + x.Extension + " file. It may take a few moments to appear.");
  737. }
  738. catch (IOException e)
  739. {
  740. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  741. remoteClient.SendAlertMessage("There was an IO Exception loading your terrain. Please check free space.");
  742. return;
  743. }
  744. catch (SecurityException e)
  745. {
  746. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  747. remoteClient.SendAlertMessage("There was a security Exception loading your terrain. Please check the security on the simulator drive");
  748. return;
  749. }
  750. catch (UnauthorizedAccessException e)
  751. {
  752. m_log.ErrorFormat("[TERRAIN]: Error Saving a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  753. remoteClient.SendAlertMessage("There was a security Exception loading your terrain. Please check the security on the simulator drive");
  754. return;
  755. }
  756. catch (Exception e)
  757. {
  758. m_log.ErrorFormat("[TERRAIN]: Error loading a terrain file uploaded via the estate tools. It gave us the following error: {0}", e.ToString());
  759. remoteClient.SendAlertMessage("There was a general error loading your terrain. Please fix the terrain file and try again");
  760. }
  761. }
  762. else
  763. {
  764. remoteClient.SendAlertMessage("Unable to apply terrain. Cannot get an instance of the terrain module");
  765. }
  766. }
  767. private void handleUploadTerrain(IClientAPI remote_client, string clientFileName)
  768. {
  769. if (TerrainUploader == null)
  770. {
  771. TerrainUploader = new EstateTerrainXferHandler(remote_client, clientFileName);
  772. lock (TerrainUploader)
  773. {
  774. remote_client.OnXferReceive += TerrainUploader.XferReceive;
  775. remote_client.OnAbortXfer += AbortTerrainXferHandler;
  776. TerrainUploader.TerrainUploadDone += HandleTerrainApplication;
  777. }
  778. TerrainUploader.RequestStartXfer(remote_client);
  779. }
  780. else
  781. {
  782. remote_client.SendAlertMessage("Another Terrain Upload is in progress. Please wait your turn!");
  783. }
  784. }
  785. private void handleTerrainRequest(IClientAPI remote_client, string clientFileName)
  786. {
  787. // Save terrain here
  788. ITerrainModule terr = Scene.RequestModuleInterface<ITerrainModule>();
  789. if (terr != null)
  790. {
  791. m_log.Warn("[CLIENT]: Got Request to Send Terrain in region " + Scene.RegionInfo.RegionName);
  792. if (File.Exists(Util.dataDir() + "/terrain.raw"))
  793. {
  794. File.Delete(Util.dataDir() + "/terrain.raw");
  795. }
  796. terr.SaveToFile(Util.dataDir() + "/terrain.raw");
  797. FileStream input = new FileStream(Util.dataDir() + "/terrain.raw", FileMode.Open);
  798. byte[] bdata = new byte[input.Length];
  799. input.Read(bdata, 0, (int)input.Length);
  800. remote_client.SendAlertMessage("Terrain file written, starting download...");
  801. Scene.XferManager.AddNewFile("terrain.raw", bdata);
  802. // Tell client about it
  803. m_log.Warn("[CLIENT]: Sending Terrain to " + remote_client.Name);
  804. remote_client.SendInitiateDownload("terrain.raw", clientFileName);
  805. }
  806. }
  807. private void HandleRegionInfoRequest(IClientAPI remote_client)
  808. {
  809. RegionInfoForEstateMenuArgs args = new RegionInfoForEstateMenuArgs();
  810. args.billableFactor = Scene.RegionInfo.EstateSettings.BillableFactor;
  811. args.estateID = Scene.RegionInfo.EstateSettings.EstateID;
  812. args.maxAgents = (byte)Scene.RegionInfo.RegionSettings.AgentLimit;
  813. args.objectBonusFactor = (float)Scene.RegionInfo.RegionSettings.ObjectBonus;
  814. args.parentEstateID = Scene.RegionInfo.EstateSettings.ParentEstateID;
  815. args.pricePerMeter = Scene.RegionInfo.EstateSettings.PricePerMeter;
  816. args.redirectGridX = Scene.RegionInfo.EstateSettings.RedirectGridX;
  817. args.redirectGridY = Scene.RegionInfo.EstateSettings.RedirectGridY;
  818. args.regionFlags = GetRegionFlags();
  819. args.simAccess = Scene.RegionInfo.AccessLevel;
  820. args.sunHour = (float)Scene.RegionInfo.RegionSettings.SunPosition;
  821. args.terrainLowerLimit = (float)Scene.RegionInfo.RegionSettings.TerrainLowerLimit;
  822. args.terrainRaiseLimit = (float)Scene.RegionInfo.RegionSettings.TerrainRaiseLimit;
  823. args.useEstateSun = Scene.RegionInfo.RegionSettings.UseEstateSun;
  824. args.waterHeight = (float)Scene.RegionInfo.RegionSettings.WaterHeight;
  825. args.simName = Scene.RegionInfo.RegionName;
  826. args.regionType = Scene.RegionInfo.RegionType;
  827. remote_client.SendRegionInfoToEstateMenu(args);
  828. }
  829. private void HandleEstateCovenantRequest(IClientAPI remote_client)
  830. {
  831. remote_client.SendEstateCovenantInformation(Scene.RegionInfo.RegionSettings.Covenant);
  832. }
  833. private void HandleLandStatRequest(int parcelID, uint reportType, uint requestFlags, string filter, IClientAPI remoteClient)
  834. {
  835. if (!Scene.Permissions.CanIssueEstateCommand(remoteClient.AgentId, false))
  836. return;
  837. Dictionary<uint, float> sceneData = null;
  838. if (reportType == 1)
  839. {
  840. sceneData = Scene.PhysicsScene.GetTopColliders();
  841. }
  842. else if (reportType == 0)
  843. {
  844. IScriptModule scriptModule = Scene.RequestModuleInterface<IScriptModule>();
  845. if (scriptModule != null)
  846. sceneData = scriptModule.GetObjectScriptsExecutionTimes();
  847. }
  848. List<LandStatReportItem> SceneReport = new List<LandStatReportItem>();
  849. if (sceneData != null)
  850. {
  851. var sortedSceneData
  852. = sceneData.Select(
  853. item => new { Measurement = item.Value, Part = Scene.GetSceneObjectPart(item.Key) });
  854. sortedSceneData.OrderBy(item => item.Measurement);
  855. int items = 0;
  856. foreach (var entry in sortedSceneData)
  857. {
  858. // The object may have been deleted since we received the data.
  859. if (entry.Part == null)
  860. continue;
  861. // Don't show scripts that haven't executed or where execution time is below one microsecond in
  862. // order to produce a more readable report.
  863. if (entry.Measurement < 0.001)
  864. continue;
  865. items++;
  866. SceneObjectGroup so = entry.Part.ParentGroup;
  867. LandStatReportItem lsri = new LandStatReportItem();
  868. lsri.LocationX = so.AbsolutePosition.X;
  869. lsri.LocationY = so.AbsolutePosition.Y;
  870. lsri.LocationZ = so.AbsolutePosition.Z;
  871. lsri.Score = entry.Measurement;
  872. lsri.TaskID = so.UUID;
  873. lsri.TaskLocalID = so.LocalId;
  874. lsri.TaskName = entry.Part.Name;
  875. lsri.OwnerName = UserManager.GetUserName(so.OwnerID);
  876. if (filter.Length != 0)
  877. {
  878. if ((lsri.OwnerName.Contains(filter) || lsri.TaskName.Contains(filter)))
  879. {
  880. }
  881. else
  882. {
  883. continue;
  884. }
  885. }
  886. SceneReport.Add(lsri);
  887. if (items >= 100)
  888. break;
  889. }
  890. }
  891. remoteClient.SendLandStatReply(reportType, requestFlags, (uint)SceneReport.Count,SceneReport.ToArray());
  892. }
  893. #endregion
  894. #region Outgoing Packets
  895. public void sendRegionInfoPacketToAll()
  896. {
  897. Scene.ForEachRootClient(delegate(IClientAPI client)
  898. {
  899. HandleRegionInfoRequest(client);
  900. });
  901. }
  902. public void sendRegionHandshake(IClientAPI remoteClient)
  903. {
  904. RegionHandshakeArgs args = new RegionHandshakeArgs();
  905. args.isEstateManager = Scene.RegionInfo.EstateSettings.IsEstateManagerOrOwner(remoteClient.AgentId);
  906. if (Scene.RegionInfo.EstateSettings.EstateOwner != UUID.Zero && Scene.RegionInfo.EstateSettings.EstateOwner == remoteClient.AgentId)
  907. args.isEstateManager = true;
  908. args.billableFactor = Scene.RegionInfo.EstateSettings.BillableFactor;
  909. args.terrainStartHeight0 = (float)Scene.RegionInfo.RegionSettings.Elevation1SW;
  910. args.terrainHeightRange0 = (float)Scene.RegionInfo.RegionSettings.Elevation2SW;
  911. args.terrainStartHeight1 = (float)Scene.RegionInfo.RegionSettings.Elevation1NW;
  912. args.terrainHeightRange1 = (float)Scene.RegionInfo.RegionSettings.Elevation2NW;
  913. args.terrainStartHeight2 = (float)Scene.RegionInfo.RegionSettings.Elevation1SE;
  914. args.terrainHeightRange2 = (float)Scene.RegionInfo.RegionSettings.Elevation2SE;
  915. args.terrainStartHeight3 = (float)Scene.RegionInfo.RegionSettings.Elevation1NE;
  916. args.terrainHeightRange3 = (float)Scene.RegionInfo.RegionSettings.Elevation2NE;
  917. args.simAccess = Scene.RegionInfo.AccessLevel;
  918. args.waterHeight = (float)Scene.RegionInfo.RegionSettings.WaterHeight;
  919. args.regionFlags = GetRegionFlags();
  920. args.regionName = Scene.RegionInfo.RegionName;
  921. args.SimOwner = Scene.RegionInfo.EstateSettings.EstateOwner;
  922. args.terrainBase0 = UUID.Zero;
  923. args.terrainBase1 = UUID.Zero;
  924. args.terrainBase2 = UUID.Zero;
  925. args.terrainBase3 = UUID.Zero;
  926. args.terrainDetail0 = Scene.RegionInfo.RegionSettings.TerrainTexture1;
  927. args.terrainDetail1 = Scene.RegionInfo.RegionSettings.TerrainTexture2;
  928. args.terrainDetail2 = Scene.RegionInfo.RegionSettings.TerrainTexture3;
  929. args.terrainDetail3 = Scene.RegionInfo.RegionSettings.TerrainTexture4;
  930. // m_log.DebugFormat("[ESTATE MANAGEMENT MODULE]: Sending terrain texture 1 {0} for region {1}", args.terrainDetail0, Scene.RegionInfo.RegionName);
  931. // m_log.DebugFormat("[ESTATE MANAGEMENT MODULE]: Sending terrain texture 2 {0} for region {1}", args.terrainDetail1, Scene.RegionInfo.RegionName);
  932. // m_log.DebugFormat("[ESTATE MANAGEMENT MODULE]: Sending terrain texture 3 {0} for region {1}", args.terrainDetail2, Scene.RegionInfo.RegionName);
  933. // m_log.DebugFormat("[ESTATE MANAGEMENT MODULE]: Sending terrain texture 4 {0} for region {1}", args.terrainDetail3, Scene.RegionInfo.RegionName);
  934. remoteClient.SendRegionHandshake(Scene.RegionInfo,args);
  935. }
  936. public void sendRegionHandshakeToAll()
  937. {
  938. Scene.ForEachClient(sendRegionHandshake);
  939. }
  940. public void handleEstateChangeInfo(IClientAPI remoteClient, UUID invoice, UUID senderID, UInt32 parms1, UInt32 parms2)
  941. {
  942. if (parms2 == 0)
  943. {
  944. Scene.RegionInfo.EstateSettings.UseGlobalTime = true;
  945. Scene.RegionInfo.EstateSettings.SunPosition = 0.0;
  946. }
  947. else
  948. {
  949. Scene.RegionInfo.EstateSettings.UseGlobalTime = false;
  950. Scene.RegionInfo.EstateSettings.SunPosition = (parms2 - 0x1800)/1024.0;
  951. // Warning: FixedSun should be set to True, otherwise this sun position won't be used.
  952. }
  953. if ((parms1 & 0x00000010) != 0)
  954. Scene.RegionInfo.EstateSettings.FixedSun = true;
  955. else
  956. Scene.RegionInfo.EstateSettings.FixedSun = false;
  957. if ((parms1 & 0x00008000) != 0)
  958. Scene.RegionInfo.EstateSettings.PublicAccess = true;
  959. else
  960. Scene.RegionInfo.EstateSettings.PublicAccess = false;
  961. if ((parms1 & 0x10000000) != 0)
  962. Scene.RegionInfo.EstateSettings.AllowVoice = true;
  963. else
  964. Scene.RegionInfo.EstateSettings.AllowVoice = false;
  965. if ((parms1 & 0x00100000) != 0)
  966. Scene.RegionInfo.EstateSettings.AllowDirectTeleport = true;
  967. else
  968. Scene.RegionInfo.EstateSettings.AllowDirectTeleport = false;
  969. if ((parms1 & 0x00800000) != 0)
  970. Scene.RegionInfo.EstateSettings.DenyAnonymous = true;
  971. else
  972. Scene.RegionInfo.EstateSettings.DenyAnonymous = false;
  973. if ((parms1 & 0x01000000) != 0)
  974. Scene.RegionInfo.EstateSettings.DenyIdentified = true;
  975. else
  976. Scene.RegionInfo.EstateSettings.DenyIdentified = false;
  977. if ((parms1 & 0x02000000) != 0)
  978. Scene.RegionInfo.EstateSettings.DenyTransacted = true;
  979. else
  980. Scene.RegionInfo.EstateSettings.DenyTransacted = false;
  981. if ((parms1 & 0x40000000) != 0)
  982. Scene.RegionInfo.EstateSettings.DenyMinors = true;
  983. else
  984. Scene.RegionInfo.EstateSettings.DenyMinors = false;
  985. Scene.RegionInfo.EstateSettings.Save();
  986. TriggerEstateInfoChange();
  987. Scene.TriggerEstateSunUpdate();
  988. sendDetailedEstateData(remoteClient, invoice);
  989. }
  990. #endregion
  991. #region Other Functions
  992. public void changeWaterHeight(float height)
  993. {
  994. setRegionTerrainSettings(height,
  995. (float)Scene.RegionInfo.RegionSettings.TerrainRaiseLimit,
  996. (float)Scene.RegionInfo.RegionSettings.TerrainLowerLimit,
  997. Scene.RegionInfo.RegionSettings.UseEstateSun,
  998. Scene.RegionInfo.RegionSettings.FixedSun,
  999. (float)Scene.RegionInfo.RegionSettings.SunPosition,
  1000. Scene.RegionInfo.EstateSettings.UseGlobalTime,
  1001. Scene.RegionInfo.EstateSettings.FixedSun,
  1002. (float)Scene.RegionInfo.EstateSettings.SunPosition);
  1003. sendRegionInfoPacketToAll();
  1004. }
  1005. #endregion
  1006. private void EventManager_OnNewClient(IClientAPI client)
  1007. {
  1008. client.OnDetailedEstateDataRequest += clientSendDetailedEstateData;
  1009. client.OnSetEstateFlagsRequest += estateSetRegionInfoHandler;
  1010. // client.OnSetEstateTerrainBaseTexture += setEstateTerrainBaseTexture;
  1011. client.OnSetEstateTerrainDetailTexture += setEstateTerrainBaseTexture;
  1012. client.OnSetEstateTerrainTextureHeights += setEstateTerrainTextureHeights;
  1013. client.OnCommitEstateTerrainTextureRequest += handleCommitEstateTerrainTextureRequest;
  1014. client.OnSetRegionTerrainSettings += setRegionTerrainSettings;
  1015. client.OnEstateRestartSimRequest += handleEstateRestartSimRequest;
  1016. client.OnEstateChangeCovenantRequest += handleChangeEstateCovenantRequest;
  1017. client.OnEstateChangeInfo += handleEstateChangeInfo;
  1018. client.OnEstateManageTelehub += handleOnEstateManageTelehub;
  1019. client.OnUpdateEstateAccessDeltaRequest += handleEstateAccessDeltaRequest;
  1020. client.OnSimulatorBlueBoxMessageRequest += SendSimulatorBlueBoxMessage;
  1021. client.OnEstateBlueBoxMessageRequest += SendEstateBlueBoxMessage;
  1022. client.OnEstateDebugRegionRequest += handleEstateDebugRegionRequest;
  1023. client.OnEstateTeleportOneUserHomeRequest += handleEstateTeleportOneUserHomeRequest;
  1024. client.OnEstateTeleportAllUsersHomeRequest += handleEstateTeleportAllUsersHomeRequest;
  1025. client.OnRequestTerrain += handleTerrainRequest;
  1026. client.OnUploadTerrain += handleUploadTerrain;
  1027. client.OnRegionInfoRequest += HandleRegionInfoRequest;
  1028. client.OnEstateCovenantRequest += HandleEstateCovenantRequest;
  1029. client.OnLandStatRequest += HandleLandStatRequest;
  1030. sendRegionHandshake(client);
  1031. }
  1032. public uint GetRegionFlags()
  1033. {
  1034. RegionFlags flags = RegionFlags.None;
  1035. // Fully implemented
  1036. //
  1037. if (Scene.RegionInfo.RegionSettings.AllowDamage)
  1038. flags |= RegionFlags.AllowDamage;
  1039. if (Scene.RegionInfo.RegionSettings.BlockTerraform)
  1040. flags |= RegionFlags.BlockTerraform;
  1041. if (!Scene.RegionInfo.RegionSettings.AllowLandResell)
  1042. flags |= RegionFlags.BlockLandResell;
  1043. if (Scene.RegionInfo.RegionSettings.DisableCollisions)
  1044. flags |= RegionFlags.SkipCollisions;
  1045. if (Scene.RegionInfo.RegionSettings.DisableScripts)
  1046. flags |= RegionFlags.SkipScripts;
  1047. if (Scene.RegionInfo.RegionSettings.DisablePhysics)
  1048. flags |= RegionFlags.SkipPhysics;
  1049. if (Scene.RegionInfo.RegionSettings.BlockFly)
  1050. flags |= RegionFlags.NoFly;
  1051. if (Scene.RegionInfo.RegionSettings.RestrictPushing)
  1052. flags |= RegionFlags.RestrictPushObject;
  1053. if (Scene.RegionInfo.RegionSettings.AllowLandJoinDivide)
  1054. flags |= RegionFlags.AllowParcelChanges;
  1055. if (Scene.RegionInfo.RegionSettings.BlockShowInSearch)
  1056. flags |= RegionFlags.BlockParcelSearch;
  1057. if (Scene.RegionInfo.RegionSettings.FixedSun)
  1058. flags |= RegionFlags.SunFixed;
  1059. if (Scene.RegionInfo.RegionSettings.Sandbox)
  1060. flags |= RegionFlags.Sandbox;
  1061. if (Scene.RegionInfo.EstateSettings.AllowVoice)
  1062. flags |= RegionFlags.AllowVoice;
  1063. if (Scene.RegionInfo.EstateSettings.AllowLandmark)
  1064. flags |= RegionFlags.AllowLandmark;
  1065. if (Scene.RegionInfo.EstateSettings.AllowSetHome)
  1066. flags |= RegionFlags.AllowSetHome;
  1067. if (Scene.RegionInfo.EstateSettings.BlockDwell)
  1068. flags |= RegionFlags.BlockDwell;
  1069. if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
  1070. flags |= RegionFlags.ResetHomeOnTeleport;
  1071. // TODO: SkipUpdateInterestList
  1072. // Omitted
  1073. //
  1074. // Omitted: NullLayer (what is that?)
  1075. // Omitted: SkipAgentAction (what does it do?)
  1076. return (uint)flags;
  1077. }
  1078. public uint GetEstateFlags()
  1079. {
  1080. RegionFlags flags = RegionFlags.None;
  1081. if (Scene.RegionInfo.EstateSettings.FixedSun)
  1082. flags |= RegionFlags.SunFixed;
  1083. if (Scene.RegionInfo.EstateSettings.PublicAccess)
  1084. flags |= (RegionFlags.PublicAllowed |
  1085. RegionFlags.ExternallyVisible);
  1086. if (Scene.RegionInfo.EstateSettings.AllowVoice)
  1087. flags |= RegionFlags.AllowVoice;
  1088. if (Scene.RegionInfo.EstateSettings.AllowDirectTeleport)
  1089. flags |= RegionFlags.AllowDirectTeleport;
  1090. if (Scene.RegionInfo.EstateSettings.DenyAnonymous)
  1091. flags |= RegionFlags.DenyAnonymous;
  1092. if (Scene.RegionInfo.EstateSettings.DenyIdentified)
  1093. flags |= RegionFlags.DenyIdentified;
  1094. if (Scene.RegionInfo.EstateSettings.DenyTransacted)
  1095. flags |= RegionFlags.DenyTransacted;
  1096. if (Scene.RegionInfo.EstateSettings.AbuseEmailToEstateOwner)
  1097. flags |= RegionFlags.AbuseEmailToEstateOwner;
  1098. if (Scene.RegionInfo.EstateSettings.BlockDwell)
  1099. flags |= RegionFlags.BlockDwell;
  1100. if (Scene.RegionInfo.EstateSettings.EstateSkipScripts)
  1101. flags |= RegionFlags.EstateSkipScripts;
  1102. if (Scene.RegionInfo.EstateSettings.ResetHomeOnTeleport)
  1103. flags |= RegionFlags.ResetHomeOnTeleport;
  1104. if (Scene.RegionInfo.EstateSettings.TaxFree)
  1105. flags |= RegionFlags.TaxFree;
  1106. if (Scene.RegionInfo.EstateSettings.AllowLandmark)
  1107. flags |= RegionFlags.AllowLandmark;
  1108. if (Scene.RegionInfo.EstateSettings.AllowParcelChanges)
  1109. flags |= RegionFlags.AllowParcelChanges;
  1110. if (Scene.RegionInfo.EstateSettings.AllowSetHome)
  1111. flags |= RegionFlags.AllowSetHome;
  1112. if (Scene.RegionInfo.EstateSettings.DenyMinors)
  1113. flags |= (RegionFlags)(1 << 30);
  1114. return (uint)flags;
  1115. }
  1116. public bool IsManager(UUID avatarID)
  1117. {
  1118. if (avatarID == Scene.RegionInfo.EstateSettings.EstateOwner)
  1119. return true;
  1120. List<UUID> ems = new List<UUID>(Scene.RegionInfo.EstateSettings.EstateManagers);
  1121. if (ems.Contains(avatarID))
  1122. return true;
  1123. return false;
  1124. }
  1125. public void TriggerRegionInfoChange()
  1126. {
  1127. m_regionChangeTimer.Stop();
  1128. m_regionChangeTimer.Start();
  1129. }
  1130. protected void RaiseRegionInfoChange(object sender, ElapsedEventArgs e)
  1131. {
  1132. ChangeDelegate change = OnRegionInfoChange;
  1133. if (change != null)
  1134. change(Scene.RegionInfo.RegionID);
  1135. }
  1136. public void TriggerEstateInfoChange()
  1137. {
  1138. ChangeDelegate change = OnEstateInfoChange;
  1139. if (change != null)
  1140. change(Scene.RegionInfo.RegionID);
  1141. }
  1142. public void TriggerEstateMessage(UUID fromID, string fromName, string message)
  1143. {
  1144. MessageDelegate onmessage = OnEstateMessage;
  1145. if (onmessage != null)
  1146. onmessage(Scene.RegionInfo.RegionID, fromID, fromName, message);
  1147. }
  1148. private void SendTelehubInfo(IClientAPI client)
  1149. {
  1150. RegionSettings settings =
  1151. this.Scene.RegionInfo.RegionSettings;
  1152. SceneObjectGroup telehub = null;
  1153. if (settings.TelehubObject != UUID.Zero &&
  1154. (telehub = Scene.GetSceneObjectGroup(settings.TelehubObject)) != null)
  1155. {
  1156. List<Vector3> spawnPoints = new List<Vector3>();
  1157. foreach (SpawnPoint sp in settings.SpawnPoints())
  1158. {
  1159. spawnPoints.Add(sp.GetLocation(Vector3.Zero, Quaternion.Identity));
  1160. }
  1161. client.SendTelehubInfo(settings.TelehubObject,
  1162. telehub.Name,
  1163. telehub.AbsolutePosition,
  1164. telehub.GroupRotation,
  1165. spawnPoints);
  1166. }
  1167. else
  1168. {
  1169. client.SendTelehubInfo(UUID.Zero,
  1170. String.Empty,
  1171. Vector3.Zero,
  1172. Quaternion.Identity,
  1173. new List<Vector3>());
  1174. }
  1175. }
  1176. }
  1177. }