EstateManagementModule.cs 60 KB

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