EstateManagementModule.cs 68 KB

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