EstateManagementModule.cs 67 KB

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